2013-07-28 22:08:34 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Entry point in to the program, our registry-stored settings and top-level
|
|
|
|
// housekeeping when we open, save, and create new files.
|
|
|
|
//
|
|
|
|
// Copyright 2008-2013 Jonathan Westhues.
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-03-25 10:02:13 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
|
2015-03-27 15:31:23 +00:00
|
|
|
SolveSpaceUI SolveSpace::SS = {};
|
|
|
|
Sketch SolveSpace::SK = {};
|
2008-03-25 10:02:13 +00:00
|
|
|
|
2015-12-27 01:03:24 +00:00
|
|
|
std::string SolveSpace::RecentFile[MAX_RECENT] = {};
|
|
|
|
|
2015-03-24 06:45:53 +00:00
|
|
|
void SolveSpaceUI::Init() {
|
2010-05-16 16:36:23 +00:00
|
|
|
SS.tangentArcRadius = 10.0;
|
|
|
|
|
2008-02-09 13:52:01 +00:00
|
|
|
// Then, load the registry settings.
|
2008-06-11 04:22:52 +00:00
|
|
|
int i;
|
|
|
|
// Default list of colors for the model material
|
2013-12-02 06:25:09 +00:00
|
|
|
modelColor[0] = CnfThawColor(RGBi(150, 150, 150), "ModelColor_0");
|
|
|
|
modelColor[1] = CnfThawColor(RGBi(100, 100, 100), "ModelColor_1");
|
|
|
|
modelColor[2] = CnfThawColor(RGBi( 30, 30, 30), "ModelColor_2");
|
|
|
|
modelColor[3] = CnfThawColor(RGBi(150, 0, 0), "ModelColor_3");
|
|
|
|
modelColor[4] = CnfThawColor(RGBi( 0, 100, 0), "ModelColor_4");
|
|
|
|
modelColor[5] = CnfThawColor(RGBi( 0, 80, 80), "ModelColor_5");
|
|
|
|
modelColor[6] = CnfThawColor(RGBi( 0, 0, 130), "ModelColor_6");
|
|
|
|
modelColor[7] = CnfThawColor(RGBi( 80, 0, 80), "ModelColor_7");
|
2008-06-11 04:22:52 +00:00
|
|
|
// Light intensities
|
2008-07-08 07:41:29 +00:00
|
|
|
lightIntensity[0] = CnfThawFloat(1.0f, "LightIntensity_0");
|
|
|
|
lightIntensity[1] = CnfThawFloat(0.5f, "LightIntensity_1");
|
2009-03-17 16:33:46 +00:00
|
|
|
ambientIntensity = 0.3; // no setting for that yet
|
2008-06-11 04:22:52 +00:00
|
|
|
// Light positions
|
2008-07-08 07:41:29 +00:00
|
|
|
lightDir[0].x = CnfThawFloat(-1.0f, "LightDir_0_Right" );
|
|
|
|
lightDir[0].y = CnfThawFloat( 1.0f, "LightDir_0_Up" );
|
|
|
|
lightDir[0].z = CnfThawFloat( 0.0f, "LightDir_0_Forward" );
|
|
|
|
lightDir[1].x = CnfThawFloat( 1.0f, "LightDir_1_Right" );
|
|
|
|
lightDir[1].y = CnfThawFloat( 0.0f, "LightDir_1_Up" );
|
|
|
|
lightDir[1].z = CnfThawFloat( 0.0f, "LightDir_1_Forward" );
|
2016-01-27 04:07:54 +00:00
|
|
|
|
|
|
|
exportMode = false;
|
2008-07-10 05:26:08 +00:00
|
|
|
// Chord tolerance
|
Use relative chord tolerance instead of absolute.
Commit 89eb208 has improved the overall situation with chord
tolerance, but it changed the display chord tolerance to use
an absolute value in millimeters as a stopgap measure.
This commit changes the display chord tolerance to be specified
in percents of entity bounding box instead of millimeters.
As a result, the linearized curves are both zoom level and sketch
scale independent.
In order to compute the bounding box, all entities are generated
twice. However, this shouldn't result in a noticeable slowdown,
since the bounding box calculation does not need the expensive
triangle mesh generation and the solver will converge immediately
on the second run.
Since the meaning of the preference has changed, a new name is
used (ChordTolerancePct instead of ChordTolerance), so that it
would be reset to the default value after updating SolveSpace.
The default value, 0.5%, was selected using trial and error by
judging whether cylinders of moderate dimensions were looking
aesthetically pleasing enough.
After this change, the only real function of the spacebar
shortcut is to reload imported groups, since manual regeneration
should not change anything anymore unless there is a bug.
2016-01-29 10:33:56 +00:00
|
|
|
chordTol = CnfThawFloat(0.5f, "ChordTolerancePct");
|
2008-02-12 13:00:26 +00:00
|
|
|
// Max pwl segments to generate
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
maxSegments = CnfThawInt(10, "MaxSegments");
|
2016-01-27 04:07:54 +00:00
|
|
|
// Chord tolerance
|
|
|
|
exportChordTol = CnfThawFloat(0.1f, "ExportChordTolerance");
|
|
|
|
// Max pwl segments to generate
|
|
|
|
exportMaxSegments = CnfThawInt(64, "ExportMaxSegments");
|
2008-06-14 09:51:25 +00:00
|
|
|
// View units
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
viewUnits = (Unit)CnfThawInt((uint32_t)UNIT_MM, "ViewUnits");
|
2010-09-24 02:58:34 +00:00
|
|
|
// Number of digits after the decimal point
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
afterDecimalMm = CnfThawInt(2, "AfterDecimalMm");
|
|
|
|
afterDecimalInch = CnfThawInt(3, "AfterDecimalInch");
|
2008-06-17 19:12:25 +00:00
|
|
|
// Camera tangent (determines perspective)
|
2010-05-16 18:46:10 +00:00
|
|
|
cameraTangent = CnfThawFloat(0.3f/1e3f, "CameraTangent");
|
2009-09-29 11:35:19 +00:00
|
|
|
// Grid spacing
|
|
|
|
gridSpacing = CnfThawFloat(5.0f, "GridSpacing");
|
2008-07-08 07:41:29 +00:00
|
|
|
// Export scale factor
|
|
|
|
exportScale = CnfThawFloat(1.0f, "ExportScale");
|
2008-08-14 08:28:25 +00:00
|
|
|
// Export offset (cutter radius comp)
|
|
|
|
exportOffset = CnfThawFloat(0.0f, "ExportOffset");
|
2009-09-22 05:46:30 +00:00
|
|
|
// Rewrite exported colors close to white into black (assuming white bg)
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
fixExportColors = CnfThawBool(true, "FixExportColors");
|
2008-08-11 10:56:08 +00:00
|
|
|
// Draw back faces of triangles (when mesh is leaky/self-intersecting)
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
drawBackFaces = CnfThawBool(true, "DrawBackFaces");
|
2009-10-01 10:35:11 +00:00
|
|
|
// Check that contours are closed and not self-intersecting
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
checkClosedContour = CnfThawBool(true, "CheckClosedContour");
|
2009-03-18 04:26:04 +00:00
|
|
|
// Export shaded triangles in a 2d view
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
exportShadedTriangles = CnfThawBool(true, "ExportShadedTriangles");
|
2009-04-14 04:19:23 +00:00
|
|
|
// Export pwl curves (instead of exact) always
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
exportPwlCurves = CnfThawBool(false, "ExportPwlCurves");
|
2009-09-18 08:14:15 +00:00
|
|
|
// Background color on-screen
|
2013-12-02 06:25:09 +00:00
|
|
|
backgroundColor = CnfThawColor(RGBi(0, 0, 0), "BackgroundColor");
|
2009-09-03 08:13:09 +00:00
|
|
|
// Whether export canvas size is fixed or derived from bbox
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
exportCanvasSizeAuto = CnfThawBool(true, "ExportCanvasSizeAuto");
|
2009-09-03 08:13:09 +00:00
|
|
|
// Margins for automatic canvas size
|
|
|
|
exportMargin.left = CnfThawFloat(5.0f, "ExportMargin_Left");
|
|
|
|
exportMargin.right = CnfThawFloat(5.0f, "ExportMargin_Right");
|
|
|
|
exportMargin.bottom = CnfThawFloat(5.0f, "ExportMargin_Bottom");
|
|
|
|
exportMargin.top = CnfThawFloat(5.0f, "ExportMargin_Top");
|
|
|
|
// Dimensions for fixed canvas size
|
|
|
|
exportCanvas.width = CnfThawFloat(100.0f, "ExportCanvas_Width");
|
|
|
|
exportCanvas.height = CnfThawFloat(100.0f, "ExportCanvas_Height");
|
|
|
|
exportCanvas.dx = CnfThawFloat( 5.0f, "ExportCanvas_Dx");
|
|
|
|
exportCanvas.dy = CnfThawFloat( 5.0f, "ExportCanvas_Dy");
|
2010-01-14 04:47:17 +00:00
|
|
|
// Extra parameters when exporting G code
|
|
|
|
gCode.depth = CnfThawFloat(10.0f, "GCode_Depth");
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
gCode.passes = CnfThawInt(1, "GCode_Passes");
|
2010-01-14 04:47:17 +00:00
|
|
|
gCode.feed = CnfThawFloat(10.0f, "GCode_Feed");
|
|
|
|
gCode.plungeFeed = CnfThawFloat(10.0f, "GCode_PlungeFeed");
|
2009-01-02 10:38:36 +00:00
|
|
|
// Show toolbar in the graphics window
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
showToolbar = CnfThawBool(true, "ShowToolbar");
|
2008-06-11 04:22:52 +00:00
|
|
|
// Recent files menus
|
|
|
|
for(i = 0; i < MAX_RECENT; i++) {
|
2015-12-27 01:03:24 +00:00
|
|
|
RecentFile[i] = CnfThawString("", "RecentFile_" + std::to_string(i));
|
2008-06-11 04:22:52 +00:00
|
|
|
}
|
|
|
|
RefreshRecentMenus();
|
2015-03-29 04:46:57 +00:00
|
|
|
// Autosave timer
|
|
|
|
autosaveInterval = CnfThawInt(5, "AutosaveInterval");
|
2008-06-11 04:22:52 +00:00
|
|
|
|
2009-09-17 07:32:36 +00:00
|
|
|
// The default styles (colors, line widths, etc.) are also stored in the
|
|
|
|
// configuration file, but we will automatically load those as we need
|
|
|
|
// them.
|
|
|
|
|
2015-03-29 04:46:57 +00:00
|
|
|
SetAutosaveTimerFor(autosaveInterval);
|
|
|
|
|
2008-05-29 10:10:12 +00:00
|
|
|
NewFile();
|
|
|
|
AfterNewFile();
|
2015-03-24 06:45:53 +00:00
|
|
|
}
|
|
|
|
|
2015-12-27 01:03:24 +00:00
|
|
|
bool SolveSpaceUI::LoadAutosaveFor(const std::string &filename) {
|
|
|
|
std::string autosaveFile = filename + AUTOSAVE_SUFFIX;
|
2015-03-29 04:46:57 +00:00
|
|
|
|
2015-12-27 08:09:00 +00:00
|
|
|
FILE *f = ssfopen(autosaveFile, "rb");
|
2015-03-29 04:46:57 +00:00
|
|
|
if(!f)
|
|
|
|
return false;
|
|
|
|
fclose(f);
|
|
|
|
|
2016-01-11 12:18:18 +00:00
|
|
|
if(LoadAutosaveYesNo() == DIALOG_YES) {
|
2015-03-29 04:46:57 +00:00
|
|
|
unsaved = true;
|
|
|
|
return LoadFromFile(autosaveFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-27 01:03:24 +00:00
|
|
|
bool SolveSpaceUI::OpenFile(const std::string &filename) {
|
2015-03-29 04:46:57 +00:00
|
|
|
bool autosaveLoaded = LoadAutosaveFor(filename);
|
2016-01-11 12:18:18 +00:00
|
|
|
bool fileLoaded = autosaveLoaded || LoadFromFile(filename);
|
|
|
|
if(fileLoaded)
|
|
|
|
saveFile = filename;
|
|
|
|
bool success = fileLoaded && ReloadAllImported(/*canCancel=*/true);
|
2015-03-24 06:45:53 +00:00
|
|
|
if(success) {
|
2015-03-29 04:46:57 +00:00
|
|
|
RemoveAutosave();
|
2015-03-24 06:45:53 +00:00
|
|
|
AddToRecentList(filename);
|
|
|
|
} else {
|
2016-01-11 12:18:18 +00:00
|
|
|
saveFile = "";
|
2015-03-24 06:45:53 +00:00
|
|
|
NewFile();
|
2008-04-24 06:22:16 +00:00
|
|
|
}
|
2008-05-28 10:10:31 +00:00
|
|
|
AfterNewFile();
|
2015-03-29 04:46:57 +00:00
|
|
|
unsaved = autosaveLoaded;
|
2015-03-24 06:45:53 +00:00
|
|
|
return success;
|
2008-05-28 10:10:31 +00:00
|
|
|
}
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::Exit(void) {
|
2008-06-11 04:22:52 +00:00
|
|
|
// Recent files
|
2015-12-27 01:03:24 +00:00
|
|
|
for(int i = 0; i < MAX_RECENT; i++)
|
|
|
|
CnfFreezeString(RecentFile[i], "RecentFile_" + std::to_string(i));
|
2008-06-11 04:22:52 +00:00
|
|
|
// Model colors
|
2015-12-27 01:03:24 +00:00
|
|
|
for(int i = 0; i < MODEL_COLORS; i++)
|
|
|
|
CnfFreezeColor(modelColor[i], "ModelColor_" + std::to_string(i));
|
2008-06-11 04:22:52 +00:00
|
|
|
// Light intensities
|
2008-07-08 07:41:29 +00:00
|
|
|
CnfFreezeFloat((float)lightIntensity[0], "LightIntensity_0");
|
|
|
|
CnfFreezeFloat((float)lightIntensity[1], "LightIntensity_1");
|
2008-06-11 04:30:18 +00:00
|
|
|
// Light directions
|
2008-07-08 07:41:29 +00:00
|
|
|
CnfFreezeFloat((float)lightDir[0].x, "LightDir_0_Right");
|
|
|
|
CnfFreezeFloat((float)lightDir[0].y, "LightDir_0_Up");
|
|
|
|
CnfFreezeFloat((float)lightDir[0].z, "LightDir_0_Forward");
|
|
|
|
CnfFreezeFloat((float)lightDir[1].x, "LightDir_1_Right");
|
|
|
|
CnfFreezeFloat((float)lightDir[1].y, "LightDir_1_Up");
|
|
|
|
CnfFreezeFloat((float)lightDir[1].z, "LightDir_1_Forward");
|
2008-07-10 05:26:08 +00:00
|
|
|
// Chord tolerance
|
Use relative chord tolerance instead of absolute.
Commit 89eb208 has improved the overall situation with chord
tolerance, but it changed the display chord tolerance to use
an absolute value in millimeters as a stopgap measure.
This commit changes the display chord tolerance to be specified
in percents of entity bounding box instead of millimeters.
As a result, the linearized curves are both zoom level and sketch
scale independent.
In order to compute the bounding box, all entities are generated
twice. However, this shouldn't result in a noticeable slowdown,
since the bounding box calculation does not need the expensive
triangle mesh generation and the solver will converge immediately
on the second run.
Since the meaning of the preference has changed, a new name is
used (ChordTolerancePct instead of ChordTolerance), so that it
would be reset to the default value after updating SolveSpace.
The default value, 0.5%, was selected using trial and error by
judging whether cylinders of moderate dimensions were looking
aesthetically pleasing enough.
After this change, the only real function of the spacebar
shortcut is to reload imported groups, since manual regeneration
should not change anything anymore unless there is a bug.
2016-01-29 10:33:56 +00:00
|
|
|
CnfFreezeFloat((float)chordTol, "ChordTolerancePct");
|
2008-02-12 13:00:26 +00:00
|
|
|
// Max pwl segments to generate
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
CnfFreezeInt((uint32_t)maxSegments, "MaxSegments");
|
2016-01-27 04:07:54 +00:00
|
|
|
// Export Chord tolerance
|
|
|
|
CnfFreezeFloat((float)exportChordTol, "ExportChordTolerance");
|
|
|
|
// Export Max pwl segments to generate
|
|
|
|
CnfFreezeInt((uint32_t)exportMaxSegments, "ExportMaxSegments");
|
2010-09-24 02:58:34 +00:00
|
|
|
// View units
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
CnfFreezeInt((uint32_t)viewUnits, "ViewUnits");
|
2010-09-24 02:58:34 +00:00
|
|
|
// Number of digits after the decimal point
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
CnfFreezeInt((uint32_t)afterDecimalMm, "AfterDecimalMm");
|
|
|
|
CnfFreezeInt((uint32_t)afterDecimalInch, "AfterDecimalInch");
|
2008-06-17 19:12:25 +00:00
|
|
|
// Camera tangent (determines perspective)
|
2008-07-08 07:41:29 +00:00
|
|
|
CnfFreezeFloat((float)cameraTangent, "CameraTangent");
|
2009-09-29 11:35:19 +00:00
|
|
|
// Grid spacing
|
|
|
|
CnfFreezeFloat(gridSpacing, "GridSpacing");
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
// Export scale
|
2008-07-08 07:41:29 +00:00
|
|
|
CnfFreezeFloat(exportScale, "ExportScale");
|
2008-08-14 08:28:25 +00:00
|
|
|
// Export offset (cutter radius comp)
|
|
|
|
CnfFreezeFloat(exportOffset, "ExportOffset");
|
2009-09-22 05:46:30 +00:00
|
|
|
// Rewrite exported colors close to white into black (assuming white bg)
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
CnfFreezeBool(fixExportColors, "FixExportColors");
|
2008-08-11 10:56:08 +00:00
|
|
|
// Draw back faces of triangles (when mesh is leaky/self-intersecting)
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
CnfFreezeBool(drawBackFaces, "DrawBackFaces");
|
2009-10-01 10:35:11 +00:00
|
|
|
// Check that contours are closed and not self-intersecting
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
CnfFreezeBool(checkClosedContour, "CheckClosedContour");
|
2009-03-18 04:26:04 +00:00
|
|
|
// Export shaded triangles in a 2d view
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
CnfFreezeBool(exportShadedTriangles, "ExportShadedTriangles");
|
2009-04-14 04:19:23 +00:00
|
|
|
// Export pwl curves (instead of exact) always
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
CnfFreezeBool(exportPwlCurves, "ExportPwlCurves");
|
2009-09-18 08:14:15 +00:00
|
|
|
// Background color on-screen
|
Replaced RGB-color integers with dedicated data structure
RGB colors were represented using a uint32_t with the red, green and blue
values stuffed into the lower three octets (i.e. 0x00BBGGRR), like
Microsoft's COLORREF. This approach did not lend itself to type safety,
however, so this change replaces it with an RgbColor class that provides
the same infomation plus a handful of useful methods to work with it. (Note
that sizeof(RgbColor) == sizeof(uint32_t), so this change should not lead
to memory bloat.)
Some of the new methods/fields replace what were previously macro calls;
e.g. RED(c) is now c.red, REDf(c) is now c.redF(). The .Equals() method is
now used instead of == to compare colors.
RGB colors still need to be represented as packed integers in file I/O and
preferences, so the methods .FromPackedInt() and .ToPackedInt() are
provided. Also implemented are Cnf{Freeze,Thaw}Color(), type-safe wrappers
around Cnf{Freeze,Thaw}Int() that facilitate I/O with preferences.
(Cnf{Freeze,Thaw}Color() are defined outside of the system-dependent code
to minimize the footprint of the latter; because the same can be done with
Cnf{Freeze,Thaw}Bool(), those are also moved out of the system code with
this commit.)
Color integers were being OR'ed with 0x80000000 in some places for two
distinct purposes: One, to indicate use of a default color in
glxFillMesh(); this has been replaced by use of the .UseDefault() method.
Two, to indicate to TextWindow::Printf() that the format argument of a
"%Bp"/"%Fp" specifier is an RGB color rather than a color "code" from
TextWindow::bgColors[] or TextWindow::fgColors[] (as the specifier can
accept either); instead, we define a new flag "z" (as in "%Bz" or "%Fz") to
indicate an RGBcolor pointer, leaving "%Bp"/"%Fp" to indicate a color code
exclusively.
(This also allows TextWindow::meta[][].bg to be a char instead of an int,
partly compensating for the new .bgRgb field added immediately after.)
In array declarations, RGB colors could previously be specified as 0 (often
in a terminating element). As that no longer works, we define NULL_COLOR,
which serves much the same purpose for RgbColor variables as NULL serves
for pointers.
2013-10-16 20:00:58 +00:00
|
|
|
CnfFreezeColor(backgroundColor, "BackgroundColor");
|
2009-09-03 08:13:09 +00:00
|
|
|
// Whether export canvas size is fixed or derived from bbox
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
CnfFreezeBool(exportCanvasSizeAuto, "ExportCanvasSizeAuto");
|
2009-09-03 08:13:09 +00:00
|
|
|
// Margins for automatic canvas size
|
|
|
|
CnfFreezeFloat(exportMargin.left, "ExportMargin_Left");
|
|
|
|
CnfFreezeFloat(exportMargin.right, "ExportMargin_Right");
|
|
|
|
CnfFreezeFloat(exportMargin.bottom, "ExportMargin_Bottom");
|
|
|
|
CnfFreezeFloat(exportMargin.top, "ExportMargin_Top");
|
|
|
|
// Dimensions for fixed canvas size
|
|
|
|
CnfFreezeFloat(exportCanvas.width, "ExportCanvas_Width");
|
|
|
|
CnfFreezeFloat(exportCanvas.height, "ExportCanvas_Height");
|
|
|
|
CnfFreezeFloat(exportCanvas.dx, "ExportCanvas_Dx");
|
|
|
|
CnfFreezeFloat(exportCanvas.dy, "ExportCanvas_Dy");
|
2010-01-14 04:47:17 +00:00
|
|
|
// Extra parameters when exporting G code
|
|
|
|
CnfFreezeFloat(gCode.depth, "GCode_Depth");
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
CnfFreezeInt(gCode.passes, "GCode_Passes");
|
2010-01-14 04:47:17 +00:00
|
|
|
CnfFreezeFloat(gCode.feed, "GCode_Feed");
|
|
|
|
CnfFreezeFloat(gCode.plungeFeed, "GCode_PlungeFeed");
|
2009-01-02 10:38:36 +00:00
|
|
|
// Show toolbar in the graphics window
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
CnfFreezeBool(showToolbar, "ShowToolbar");
|
2015-03-29 04:46:57 +00:00
|
|
|
// Autosave timer
|
|
|
|
CnfFreezeInt(autosaveInterval, "AutosaveInterval");
|
2008-07-08 07:41:29 +00:00
|
|
|
|
2009-09-17 07:32:36 +00:00
|
|
|
// And the default styles, colors and line widths and such.
|
|
|
|
Style::FreezeDefaultStyles();
|
|
|
|
|
2015-03-29 04:46:57 +00:00
|
|
|
// Exiting cleanly.
|
|
|
|
RemoveAutosave();
|
|
|
|
|
2008-06-11 04:22:52 +00:00
|
|
|
ExitNow();
|
|
|
|
}
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::ScheduleGenerateAll() {
|
2015-03-18 17:02:11 +00:00
|
|
|
if(!later.scheduled) ScheduleLater();
|
|
|
|
later.scheduled = true;
|
|
|
|
later.generateAll = true;
|
|
|
|
}
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::ScheduleShowTW() {
|
2015-03-18 17:02:11 +00:00
|
|
|
if(!later.scheduled) ScheduleLater();
|
|
|
|
later.scheduled = true;
|
|
|
|
later.showTW = true;
|
|
|
|
}
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::DoLater(void) {
|
2008-06-03 18:28:41 +00:00
|
|
|
if(later.generateAll) GenerateAll();
|
|
|
|
if(later.showTW) TW.Show();
|
2015-03-27 15:31:23 +00:00
|
|
|
later = {};
|
2008-06-03 18:28:41 +00:00
|
|
|
}
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
double SolveSpaceUI::MmPerUnit(void) {
|
2010-01-04 00:35:28 +00:00
|
|
|
if(viewUnits == UNIT_INCHES) {
|
|
|
|
return 25.4;
|
|
|
|
} else {
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
}
|
2015-03-23 17:49:04 +00:00
|
|
|
const char *SolveSpaceUI::UnitName(void) {
|
2010-01-04 00:35:28 +00:00
|
|
|
if(viewUnits == UNIT_INCHES) {
|
|
|
|
return "inch";
|
|
|
|
} else {
|
|
|
|
return "mm";
|
|
|
|
}
|
|
|
|
}
|
2015-11-06 08:40:12 +00:00
|
|
|
std::string SolveSpaceUI::MmToString(double v) {
|
2008-06-14 09:51:25 +00:00
|
|
|
if(viewUnits == UNIT_INCHES) {
|
2015-11-06 08:40:12 +00:00
|
|
|
return ssprintf("%.*f", afterDecimalInch, v/25.4);
|
2008-06-14 09:51:25 +00:00
|
|
|
} else {
|
2015-11-06 08:40:12 +00:00
|
|
|
return ssprintf("%.*f", afterDecimalMm, v);
|
2008-06-14 09:51:25 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-23 17:49:04 +00:00
|
|
|
double SolveSpaceUI::ExprToMm(Expr *e) {
|
2010-01-04 00:35:28 +00:00
|
|
|
return (e->Eval()) * MmPerUnit();
|
2008-06-14 09:51:25 +00:00
|
|
|
}
|
2015-11-06 08:40:12 +00:00
|
|
|
double SolveSpaceUI::StringToMm(const std::string &str) {
|
|
|
|
return std::stod(str) * MmPerUnit();
|
2008-07-20 11:27:22 +00:00
|
|
|
}
|
2015-03-23 17:49:04 +00:00
|
|
|
double SolveSpaceUI::ChordTolMm(void) {
|
2016-01-27 04:07:54 +00:00
|
|
|
if(exportMode) return ExportChordTolMm();
|
Use relative chord tolerance instead of absolute.
Commit 89eb208 has improved the overall situation with chord
tolerance, but it changed the display chord tolerance to use
an absolute value in millimeters as a stopgap measure.
This commit changes the display chord tolerance to be specified
in percents of entity bounding box instead of millimeters.
As a result, the linearized curves are both zoom level and sketch
scale independent.
In order to compute the bounding box, all entities are generated
twice. However, this shouldn't result in a noticeable slowdown,
since the bounding box calculation does not need the expensive
triangle mesh generation and the solver will converge immediately
on the second run.
Since the meaning of the preference has changed, a new name is
used (ChordTolerancePct instead of ChordTolerance), so that it
would be reset to the default value after updating SolveSpace.
The default value, 0.5%, was selected using trial and error by
judging whether cylinders of moderate dimensions were looking
aesthetically pleasing enough.
After this change, the only real function of the spacebar
shortcut is to reload imported groups, since manual regeneration
should not change anything anymore unless there is a bug.
2016-01-29 10:33:56 +00:00
|
|
|
return chordTolCalculated;
|
2016-01-27 04:07:54 +00:00
|
|
|
}
|
|
|
|
double SolveSpaceUI::ExportChordTolMm(void) {
|
|
|
|
return exportChordTol / exportScale;
|
|
|
|
}
|
|
|
|
int SolveSpaceUI::GetMaxSegments(void) {
|
|
|
|
if(exportMode) return exportMaxSegments;
|
|
|
|
return maxSegments;
|
2009-03-08 10:59:57 +00:00
|
|
|
}
|
2015-03-23 17:49:04 +00:00
|
|
|
int SolveSpaceUI::UnitDigitsAfterDecimal(void) {
|
2010-09-24 02:58:34 +00:00
|
|
|
return (viewUnits == UNIT_INCHES) ? afterDecimalInch : afterDecimalMm;
|
|
|
|
}
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::SetUnitDigitsAfterDecimal(int v) {
|
2010-09-24 02:58:34 +00:00
|
|
|
if(viewUnits == UNIT_INCHES) {
|
|
|
|
afterDecimalInch = v;
|
|
|
|
} else {
|
|
|
|
afterDecimalMm = v;
|
|
|
|
}
|
|
|
|
}
|
2008-06-14 09:51:25 +00:00
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
double SolveSpaceUI::CameraTangent(void) {
|
2010-05-03 05:15:28 +00:00
|
|
|
if(!usePerspectiveProj) {
|
2009-09-29 11:35:19 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return cameraTangent;
|
|
|
|
}
|
|
|
|
}
|
2008-06-14 09:51:25 +00:00
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::AfterNewFile(void) {
|
2008-07-20 11:27:22 +00:00
|
|
|
// Clear out the traced point, which is no longer valid
|
|
|
|
traced.point = Entity::NO_ENTITY;
|
|
|
|
traced.path.l.Clear();
|
2009-01-25 09:19:59 +00:00
|
|
|
// and the naked edges
|
|
|
|
nakedEdges.Clear();
|
2008-07-20 11:27:22 +00:00
|
|
|
|
2009-06-04 03:59:40 +00:00
|
|
|
// GenerateAll() expects the view to be valid, because it uses that to
|
|
|
|
// fill in default values for extrusion depths etc. (which won't matter
|
|
|
|
// here, but just don't let it work on garbage)
|
|
|
|
SS.GW.offset = Vector::From(0, 0, 0);
|
|
|
|
SS.GW.projRight = Vector::From(1, 0, 0);
|
|
|
|
SS.GW.projUp = Vector::From(0, 1, 0);
|
|
|
|
|
2016-01-27 09:09:45 +00:00
|
|
|
GenerateAll(GENERATE_REGEN);
|
2008-05-25 13:11:44 +00:00
|
|
|
|
2008-04-13 10:57:41 +00:00
|
|
|
TW.Init();
|
|
|
|
GW.Init();
|
|
|
|
|
2008-06-03 18:28:41 +00:00
|
|
|
unsaved = false;
|
2008-06-12 07:31:41 +00:00
|
|
|
|
|
|
|
int w, h;
|
|
|
|
GetGraphicsWindowSize(&w, &h);
|
|
|
|
GW.width = w;
|
|
|
|
GW.height = h;
|
2008-06-21 10:18:20 +00:00
|
|
|
|
|
|
|
// The triangles haven't been generated yet, but zoom to fit the entities
|
2009-05-29 05:40:17 +00:00
|
|
|
// roughly in the window, since that sets the mesh tolerance. Consider
|
|
|
|
// invisible entities, so we still get something reasonable if the only
|
|
|
|
// thing visible is the not-yet-generated surfaces.
|
|
|
|
GW.ZoomToFit(true);
|
2008-06-12 08:58:58 +00:00
|
|
|
|
2016-01-27 09:09:45 +00:00
|
|
|
GenerateAll(GENERATE_ALL);
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2008-06-21 10:18:20 +00:00
|
|
|
// Then zoom to fit again, to fit the triangles
|
2009-05-29 05:40:17 +00:00
|
|
|
GW.ZoomToFit(false);
|
2008-07-08 08:02:22 +00:00
|
|
|
|
2009-09-18 08:14:15 +00:00
|
|
|
// Create all the default styles; they'll get created on the fly anyways,
|
|
|
|
// but can't hurt to do it now.
|
|
|
|
Style::CreateAllDefaultStyles();
|
|
|
|
|
2008-07-08 08:02:22 +00:00
|
|
|
UpdateWindowTitle();
|
2008-04-08 12:54:53 +00:00
|
|
|
}
|
|
|
|
|
2015-12-27 01:03:24 +00:00
|
|
|
void SolveSpaceUI::RemoveFromRecentList(const std::string &filename) {
|
2008-05-28 10:10:31 +00:00
|
|
|
int src, dest;
|
|
|
|
dest = 0;
|
|
|
|
for(src = 0; src < MAX_RECENT; src++) {
|
2015-12-27 01:03:24 +00:00
|
|
|
if(filename != RecentFile[src]) {
|
|
|
|
if(src != dest) RecentFile[dest] = RecentFile[src];
|
2008-05-28 10:10:31 +00:00
|
|
|
dest++;
|
|
|
|
}
|
|
|
|
}
|
2015-12-27 01:03:24 +00:00
|
|
|
while(dest < MAX_RECENT) RecentFile[dest++].clear();
|
2008-05-28 10:10:31 +00:00
|
|
|
RefreshRecentMenus();
|
|
|
|
}
|
2015-12-27 01:03:24 +00:00
|
|
|
void SolveSpaceUI::AddToRecentList(const std::string &filename) {
|
|
|
|
RemoveFromRecentList(filename);
|
2008-05-28 10:10:31 +00:00
|
|
|
|
|
|
|
int src;
|
|
|
|
for(src = MAX_RECENT - 2; src >= 0; src--) {
|
2015-12-27 01:03:24 +00:00
|
|
|
RecentFile[src+1] = RecentFile[src];
|
2008-05-28 10:10:31 +00:00
|
|
|
}
|
2015-12-27 01:03:24 +00:00
|
|
|
RecentFile[0] = filename;
|
2008-05-28 10:10:31 +00:00
|
|
|
RefreshRecentMenus();
|
|
|
|
}
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
bool SolveSpaceUI::GetFilenameAndSave(bool saveAs) {
|
2015-12-27 01:03:24 +00:00
|
|
|
std::string prevSaveFile = saveFile;
|
2009-06-10 06:57:27 +00:00
|
|
|
|
2015-12-27 01:03:24 +00:00
|
|
|
if(saveAs || saveFile.empty()) {
|
2016-01-11 08:44:56 +00:00
|
|
|
if(!GetSaveFile(saveFile, "", SLVS_PATTERN)) return false;
|
2015-05-21 12:26:29 +00:00
|
|
|
// need to get new filename directly into saveFile, since that
|
|
|
|
// determines impFileRel path
|
2008-06-03 18:28:41 +00:00
|
|
|
}
|
|
|
|
|
2015-05-21 12:26:29 +00:00
|
|
|
if(SaveToFile(saveFile)) {
|
|
|
|
AddToRecentList(saveFile);
|
2015-03-29 04:46:57 +00:00
|
|
|
RemoveAutosave();
|
2008-06-03 18:28:41 +00:00
|
|
|
unsaved = false;
|
|
|
|
return true;
|
|
|
|
} else {
|
2015-05-21 12:26:29 +00:00
|
|
|
// don't store an invalid save filename
|
2015-12-27 01:03:24 +00:00
|
|
|
saveFile = prevSaveFile;
|
2008-06-03 18:28:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-29 04:46:57 +00:00
|
|
|
bool SolveSpaceUI::Autosave()
|
|
|
|
{
|
|
|
|
SetAutosaveTimerFor(autosaveInterval);
|
|
|
|
|
2015-12-27 01:03:24 +00:00
|
|
|
if(!saveFile.empty() && unsaved)
|
|
|
|
return SaveToFile(saveFile + AUTOSAVE_SUFFIX);
|
2015-03-29 04:46:57 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SolveSpaceUI::RemoveAutosave()
|
|
|
|
{
|
2015-12-27 01:03:24 +00:00
|
|
|
std::string autosaveFile = saveFile + AUTOSAVE_SUFFIX;
|
2016-02-14 20:13:40 +00:00
|
|
|
ssremove(autosaveFile);
|
2015-03-29 04:46:57 +00:00
|
|
|
}
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
bool SolveSpaceUI::OkayToStartNewFile(void) {
|
2008-06-03 18:28:41 +00:00
|
|
|
if(!unsaved) return true;
|
|
|
|
|
|
|
|
switch(SaveFileYesNoCancel()) {
|
2016-01-11 12:18:18 +00:00
|
|
|
case DIALOG_YES:
|
2008-06-03 18:28:41 +00:00
|
|
|
return GetFilenameAndSave(false);
|
|
|
|
|
2016-01-11 12:18:18 +00:00
|
|
|
case DIALOG_NO:
|
2008-06-03 18:28:41 +00:00
|
|
|
return true;
|
|
|
|
|
2016-01-11 12:18:18 +00:00
|
|
|
case DIALOG_CANCEL:
|
2008-06-03 18:28:41 +00:00
|
|
|
return false;
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2013-09-18 20:49:32 +00:00
|
|
|
default: oops(); break;
|
2008-06-03 18:28:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::UpdateWindowTitle(void) {
|
2015-12-27 01:03:24 +00:00
|
|
|
SetCurrentFilename(saveFile);
|
2008-07-08 08:02:22 +00:00
|
|
|
}
|
|
|
|
|
2015-12-27 01:03:24 +00:00
|
|
|
static std::string Extension(const std::string &filename) {
|
2015-03-22 22:24:32 +00:00
|
|
|
int dot = filename.rfind('.');
|
|
|
|
if(dot >= 0)
|
|
|
|
return filename.substr(dot + 1, filename.length());
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::MenuFile(int id) {
|
2008-05-28 10:10:31 +00:00
|
|
|
if(id >= RECENT_OPEN && id < (RECENT_OPEN+MAX_RECENT)) {
|
2008-07-10 06:11:56 +00:00
|
|
|
if(!SS.OkayToStartNewFile()) return;
|
|
|
|
|
2015-12-27 01:03:24 +00:00
|
|
|
std::string newFile = RecentFile[id - RECENT_OPEN];
|
2015-03-29 04:46:57 +00:00
|
|
|
SS.OpenFile(newFile);
|
2008-05-28 10:10:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-18 11:11:48 +00:00
|
|
|
switch(id) {
|
|
|
|
case GraphicsWindow::MNU_NEW:
|
2008-06-03 18:28:41 +00:00
|
|
|
if(!SS.OkayToStartNewFile()) break;
|
|
|
|
|
2015-12-27 01:03:24 +00:00
|
|
|
SS.saveFile = "";
|
2008-04-24 06:22:16 +00:00
|
|
|
SS.NewFile();
|
2008-05-28 10:10:31 +00:00
|
|
|
SS.AfterNewFile();
|
2008-04-24 06:22:16 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-28 10:10:31 +00:00
|
|
|
case GraphicsWindow::MNU_OPEN: {
|
2008-06-03 18:28:41 +00:00
|
|
|
if(!SS.OkayToStartNewFile()) break;
|
|
|
|
|
2015-12-27 01:03:24 +00:00
|
|
|
std::string newFile;
|
2016-01-11 08:44:56 +00:00
|
|
|
if(GetOpenFile(newFile, "", SLVS_PATTERN)) {
|
2015-03-29 04:46:57 +00:00
|
|
|
SS.OpenFile(newFile);
|
2008-05-28 10:10:31 +00:00
|
|
|
}
|
2008-04-24 06:22:16 +00:00
|
|
|
break;
|
2008-05-28 10:10:31 +00:00
|
|
|
}
|
2008-04-18 11:11:48 +00:00
|
|
|
|
|
|
|
case GraphicsWindow::MNU_SAVE:
|
2008-06-03 18:28:41 +00:00
|
|
|
SS.GetFilenameAndSave(false);
|
|
|
|
break;
|
2008-04-18 11:11:48 +00:00
|
|
|
|
2008-06-03 18:28:41 +00:00
|
|
|
case GraphicsWindow::MNU_SAVE_AS:
|
|
|
|
SS.GetFilenameAndSave(true);
|
2008-04-18 11:11:48 +00:00
|
|
|
break;
|
|
|
|
|
2008-06-18 08:35:14 +00:00
|
|
|
case GraphicsWindow::MNU_EXPORT_PNG: {
|
2015-12-27 01:03:24 +00:00
|
|
|
std::string exportFile;
|
2016-01-11 08:44:56 +00:00
|
|
|
if(!GetSaveFile(exportFile, "", PNG_PATTERN)) break;
|
2015-03-29 00:30:52 +00:00
|
|
|
SS.ExportAsPngTo(exportFile);
|
2008-06-18 08:35:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-01-14 05:10:42 +00:00
|
|
|
case GraphicsWindow::MNU_EXPORT_VIEW: {
|
2016-01-11 08:23:51 +00:00
|
|
|
std::string exportFile;
|
2016-01-11 08:44:56 +00:00
|
|
|
if(!GetSaveFile(exportFile, CnfThawString("", "ViewExportFormat"),
|
|
|
|
VEC_PATTERN)) break;
|
2016-01-11 08:23:51 +00:00
|
|
|
CnfFreezeString(Extension(exportFile), "ViewExportFormat");
|
2010-01-14 04:47:17 +00:00
|
|
|
|
|
|
|
// If the user is exporting something where it would be
|
|
|
|
// inappropriate to include the constraints, then warn.
|
|
|
|
if(SS.GW.showConstraints &&
|
2015-12-27 01:03:24 +00:00
|
|
|
(FilenameHasExtension(exportFile, ".txt") ||
|
2010-01-14 04:47:17 +00:00
|
|
|
fabs(SS.exportOffset) > LENGTH_EPS))
|
|
|
|
{
|
|
|
|
Message("Constraints are currently shown, and will be exported "
|
|
|
|
"in the toolpath. This is probably not what you want; "
|
|
|
|
"hide them by clicking the link at the top of the "
|
|
|
|
"text window.");
|
|
|
|
}
|
|
|
|
|
2015-03-29 00:30:52 +00:00
|
|
|
SS.ExportViewOrWireframeTo(exportFile, false);
|
2009-10-12 10:40:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GraphicsWindow::MNU_EXPORT_WIREFRAME: {
|
2015-12-27 01:03:24 +00:00
|
|
|
std::string exportFile;
|
2016-01-11 08:44:56 +00:00
|
|
|
if(!GetSaveFile(exportFile, CnfThawString("", "WireframeExportFormat"),
|
|
|
|
V3D_PATTERN)) break;
|
2016-01-11 08:23:51 +00:00
|
|
|
CnfFreezeString(Extension(exportFile), "WireframeExportFormat");
|
|
|
|
|
2015-03-29 00:30:52 +00:00
|
|
|
SS.ExportViewOrWireframeTo(exportFile, true);
|
2009-01-14 05:10:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GraphicsWindow::MNU_EXPORT_SECTION: {
|
2015-12-27 01:03:24 +00:00
|
|
|
std::string exportFile;
|
2016-01-11 08:44:56 +00:00
|
|
|
if(!GetSaveFile(exportFile, CnfThawString("", "SectionExportFormat"),
|
|
|
|
VEC_PATTERN)) break;
|
2016-01-11 08:23:51 +00:00
|
|
|
CnfFreezeString(Extension(exportFile), "SectionExportFormat");
|
|
|
|
|
2015-03-29 00:30:52 +00:00
|
|
|
SS.ExportSectionTo(exportFile);
|
2008-07-08 06:30:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-07-06 09:24:31 +00:00
|
|
|
case GraphicsWindow::MNU_EXPORT_MESH: {
|
2015-12-27 01:03:24 +00:00
|
|
|
std::string exportFile;
|
2016-01-11 08:44:56 +00:00
|
|
|
if(!GetSaveFile(exportFile, CnfThawString("", "MeshExportFormat"),
|
|
|
|
MESH_PATTERN)) break;
|
2016-01-11 08:23:51 +00:00
|
|
|
CnfFreezeString(Extension(exportFile), "MeshExportFormat");
|
|
|
|
|
2015-03-29 00:30:52 +00:00
|
|
|
SS.ExportMeshTo(exportFile);
|
2008-07-06 09:24:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-06-08 06:50:16 +00:00
|
|
|
case GraphicsWindow::MNU_EXPORT_SURFACES: {
|
2015-12-27 01:03:24 +00:00
|
|
|
std::string exportFile;
|
2016-01-11 08:44:56 +00:00
|
|
|
if(!GetSaveFile(exportFile, CnfThawString("", "SurfacesExportFormat"),
|
|
|
|
SRF_PATTERN)) break;
|
2016-01-11 08:23:51 +00:00
|
|
|
CnfFreezeString(Extension(exportFile), "SurfacesExportFormat");
|
|
|
|
|
2015-03-27 15:31:23 +00:00
|
|
|
StepFileWriter sfw = {};
|
2015-03-29 00:30:52 +00:00
|
|
|
sfw.ExportSurfacesTo(exportFile);
|
2009-06-08 06:50:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-18 11:11:48 +00:00
|
|
|
case GraphicsWindow::MNU_EXIT:
|
2008-06-03 18:28:41 +00:00
|
|
|
if(!SS.OkayToStartNewFile()) break;
|
2008-06-11 04:22:52 +00:00
|
|
|
SS.Exit();
|
2008-04-18 11:11:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: oops();
|
|
|
|
}
|
2008-07-08 08:02:22 +00:00
|
|
|
|
|
|
|
SS.UpdateWindowTitle();
|
2008-04-18 11:11:48 +00:00
|
|
|
}
|
2008-07-20 11:27:22 +00:00
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::MenuAnalyze(int id) {
|
2008-07-20 11:27:22 +00:00
|
|
|
SS.GW.GroupSelection();
|
|
|
|
#define gs (SS.GW.gs)
|
|
|
|
|
|
|
|
switch(id) {
|
|
|
|
case GraphicsWindow::MNU_STEP_DIM:
|
|
|
|
if(gs.constraints == 1 && gs.n == 0) {
|
2009-04-19 05:53:16 +00:00
|
|
|
Constraint *c = SK.GetConstraint(gs.constraint[0]);
|
2008-07-20 11:27:22 +00:00
|
|
|
if(c->HasLabel() && !c->reference) {
|
|
|
|
SS.TW.shown.dimFinish = c->valA;
|
|
|
|
SS.TW.shown.dimSteps = 10;
|
|
|
|
SS.TW.shown.dimIsDistance =
|
|
|
|
(c->type != Constraint::ANGLE) &&
|
2015-10-27 10:28:33 +00:00
|
|
|
(c->type != Constraint::LENGTH_RATIO) &&
|
|
|
|
(c->type != Constraint::LENGTH_DIFFERENCE);
|
2008-07-20 11:27:22 +00:00
|
|
|
SS.TW.shown.constraint = c->h;
|
|
|
|
SS.TW.shown.screen = TextWindow::SCREEN_STEP_DIMENSION;
|
|
|
|
|
2008-09-17 10:13:37 +00:00
|
|
|
// The step params are specified in the text window,
|
|
|
|
// so force that to be shown.
|
|
|
|
SS.GW.ForceTextWindowShown();
|
|
|
|
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2008-07-20 11:27:22 +00:00
|
|
|
SS.GW.ClearSelection();
|
|
|
|
} else {
|
|
|
|
Error("Constraint must have a label, and must not be "
|
|
|
|
"a reference dimension.");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Error("Bad selection for step dimension; select a constraint.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-01-19 10:37:10 +00:00
|
|
|
case GraphicsWindow::MNU_NAKED_EDGES: {
|
2009-01-25 09:19:59 +00:00
|
|
|
SS.nakedEdges.Clear();
|
|
|
|
|
2009-06-07 23:00:57 +00:00
|
|
|
Group *g = SK.GetGroup(SS.GW.activeGroup);
|
|
|
|
SMesh *m = &(g->displayMesh);
|
2009-01-25 09:19:59 +00:00
|
|
|
SKdNode *root = SKdNode::From(m);
|
2009-01-28 07:09:01 +00:00
|
|
|
bool inters, leaks;
|
2015-03-29 00:30:52 +00:00
|
|
|
root->MakeCertainEdgesInto(&(SS.nakedEdges),
|
2009-05-29 05:40:17 +00:00
|
|
|
SKdNode::NAKED_OR_SELF_INTER_EDGES, true, &inters, &leaks);
|
|
|
|
|
2009-01-25 09:19:59 +00:00
|
|
|
InvalidateGraphics();
|
|
|
|
|
2013-08-26 18:58:35 +00:00
|
|
|
const char *intersMsg = inters ?
|
2009-01-28 07:09:01 +00:00
|
|
|
"The mesh is self-intersecting (NOT okay, invalid)." :
|
|
|
|
"The mesh is not self-intersecting (okay, valid).";
|
2013-08-26 18:58:35 +00:00
|
|
|
const char *leaksMsg = leaks ?
|
2009-01-28 07:09:01 +00:00
|
|
|
"The mesh has naked edges (NOT okay, invalid)." :
|
|
|
|
"The mesh is watertight (okay, valid).";
|
|
|
|
|
2016-01-27 05:13:04 +00:00
|
|
|
std::string cntMsg = ssprintf("\n\nThe model contains %d triangles, from "
|
|
|
|
"%d surfaces.", g->displayMesh.l.n, g->runningShell.surface.n);
|
2009-06-07 23:00:57 +00:00
|
|
|
|
2009-01-25 09:19:59 +00:00
|
|
|
if(SS.nakedEdges.l.n == 0) {
|
2010-01-16 18:15:40 +00:00
|
|
|
Message("%s\n\n%s\n\nZero problematic edges, good.%s",
|
2016-01-27 05:13:04 +00:00
|
|
|
intersMsg, leaksMsg, cntMsg.c_str());
|
2009-01-25 09:19:59 +00:00
|
|
|
} else {
|
2010-01-16 18:15:40 +00:00
|
|
|
Error("%s\n\n%s\n\n%d problematic edges, bad.%s",
|
2016-01-27 05:13:04 +00:00
|
|
|
intersMsg, leaksMsg, SS.nakedEdges.l.n, cntMsg.c_str());
|
2009-01-25 09:19:59 +00:00
|
|
|
}
|
2009-01-19 10:37:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-05-22 10:02:02 +00:00
|
|
|
case GraphicsWindow::MNU_INTERFERENCE: {
|
|
|
|
SS.nakedEdges.Clear();
|
|
|
|
|
|
|
|
SMesh *m = &(SK.GetGroup(SS.GW.activeGroup)->displayMesh);
|
|
|
|
SKdNode *root = SKdNode::From(m);
|
|
|
|
bool inters, leaks;
|
2009-05-29 05:40:17 +00:00
|
|
|
root->MakeCertainEdgesInto(&(SS.nakedEdges),
|
2009-06-06 09:44:58 +00:00
|
|
|
SKdNode::SELF_INTER_EDGES, false, &inters, &leaks);
|
2009-05-29 05:40:17 +00:00
|
|
|
|
2009-05-22 10:02:02 +00:00
|
|
|
InvalidateGraphics();
|
|
|
|
|
|
|
|
if(inters) {
|
|
|
|
Error("%d edges interfere with other triangles, bad.",
|
|
|
|
SS.nakedEdges.l.n);
|
|
|
|
} else {
|
|
|
|
Message("The assembly does not interfere, good.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-02-07 09:53:52 +00:00
|
|
|
case GraphicsWindow::MNU_VOLUME: {
|
2009-05-21 09:06:26 +00:00
|
|
|
SMesh *m = &(SK.GetGroup(SS.GW.activeGroup)->displayMesh);
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2008-02-07 09:53:52 +00:00
|
|
|
double vol = 0;
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < m->l.n; i++) {
|
|
|
|
STriangle tr = m->l.elem[i];
|
|
|
|
|
|
|
|
// Translate to place vertex A at (x, y, 0)
|
|
|
|
Vector trans = Vector::From(tr.a.x, tr.a.y, 0);
|
|
|
|
tr.a = (tr.a).Minus(trans);
|
|
|
|
tr.b = (tr.b).Minus(trans);
|
|
|
|
tr.c = (tr.c).Minus(trans);
|
|
|
|
|
|
|
|
// Rotate to place vertex B on the y-axis. Depending on
|
|
|
|
// whether the triangle is CW or CCW, C is either to the
|
|
|
|
// right or to the left of the y-axis. This handles the
|
|
|
|
// sign of our normal.
|
|
|
|
Vector u = Vector::From(-tr.b.y, tr.b.x, 0);
|
|
|
|
u = u.WithMagnitude(1);
|
|
|
|
Vector v = Vector::From(tr.b.x, tr.b.y, 0);
|
|
|
|
v = v.WithMagnitude(1);
|
|
|
|
Vector n = Vector::From(0, 0, 1);
|
|
|
|
|
|
|
|
tr.a = (tr.a).DotInToCsys(u, v, n);
|
|
|
|
tr.b = (tr.b).DotInToCsys(u, v, n);
|
|
|
|
tr.c = (tr.c).DotInToCsys(u, v, n);
|
|
|
|
|
|
|
|
n = tr.Normal().WithMagnitude(1);
|
|
|
|
|
|
|
|
// Triangles on edge don't contribute
|
|
|
|
if(fabs(n.z) < LENGTH_EPS) continue;
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2008-02-07 09:53:52 +00:00
|
|
|
// The plane has equation p dot n = a dot n
|
|
|
|
double d = (tr.a).Dot(n);
|
|
|
|
// nx*x + ny*y + nz*z = d
|
|
|
|
// nz*z = d - nx*x - ny*y
|
|
|
|
double A = -n.x/n.z, B = -n.y/n.z, C = d/n.z;
|
|
|
|
|
|
|
|
double mac = tr.c.y/tr.c.x, mbc = (tr.c.y - tr.b.y)/tr.c.x;
|
|
|
|
double xc = tr.c.x, yb = tr.b.y;
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2008-02-07 09:53:52 +00:00
|
|
|
// I asked Maple for
|
|
|
|
// int(int(A*x + B*y +C, y=mac*x..(mbc*x + yb)), x=0..xc);
|
2015-03-29 00:30:52 +00:00
|
|
|
double integral =
|
2008-02-07 09:53:52 +00:00
|
|
|
(1.0/3)*(
|
|
|
|
A*(mbc-mac)+
|
|
|
|
(1.0/2)*B*(mbc*mbc-mac*mac)
|
|
|
|
)*(xc*xc*xc)+
|
|
|
|
(1.0/2)*(A*yb+B*yb*mbc+C*(mbc-mac))*xc*xc+
|
|
|
|
C*yb*xc+
|
|
|
|
(1.0/2)*B*yb*yb*xc;
|
|
|
|
|
|
|
|
vol += integral;
|
|
|
|
}
|
2010-03-01 17:23:57 +00:00
|
|
|
|
2016-01-27 05:13:04 +00:00
|
|
|
std::string msg = ssprintf("The volume of the solid model is:\n\n"" %.3f %s^3",
|
2010-03-01 17:23:57 +00:00
|
|
|
vol / pow(SS.MmPerUnit(), 3),
|
|
|
|
SS.UnitName());
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
if(SS.viewUnits == SolveSpaceUI::UNIT_MM) {
|
2016-01-27 05:13:04 +00:00
|
|
|
msg += ssprintf("\n %.2f mL", vol/(10*10*10));
|
2010-03-01 17:23:57 +00:00
|
|
|
}
|
2016-01-27 05:13:04 +00:00
|
|
|
msg += "\n\nCurved surfaces have been approximated as triangles.\n"
|
|
|
|
"This introduces error, typically of around 1%.";
|
|
|
|
Message("%s", msg.c_str());
|
2010-03-01 17:23:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GraphicsWindow::MNU_AREA: {
|
|
|
|
Group *g = SK.GetGroup(SS.GW.activeGroup);
|
|
|
|
if(g->polyError.how != Group::POLY_GOOD) {
|
|
|
|
Error("This group does not contain a correctly-formed "
|
|
|
|
"2d closed area. It is open, not coplanar, or self-"
|
|
|
|
"intersecting.");
|
|
|
|
break;
|
|
|
|
}
|
2015-03-27 15:31:23 +00:00
|
|
|
SEdgeList sel = {};
|
2010-03-01 17:23:57 +00:00
|
|
|
g->polyLoops.MakeEdgesInto(&sel);
|
2015-03-27 15:31:23 +00:00
|
|
|
SPolygon sp = {};
|
2010-03-01 17:23:57 +00:00
|
|
|
sel.AssemblePolygon(&sp, NULL, true);
|
|
|
|
sp.normal = sp.ComputeNormal();
|
|
|
|
sp.FixContourDirections();
|
|
|
|
double area = sp.SignedArea();
|
|
|
|
double scale = SS.MmPerUnit();
|
|
|
|
Message("The area of the region sketched in this group is:\n\n"
|
|
|
|
" %.3f %s^2\n\n"
|
|
|
|
"Curves have been approximated as piecewise linear.\n"
|
|
|
|
"This introduces error, typically of around 1%%.",
|
|
|
|
area / (scale*scale),
|
|
|
|
SS.UnitName());
|
|
|
|
sel.Clear();
|
|
|
|
sp.Clear();
|
2008-07-20 11:27:22 +00:00
|
|
|
break;
|
2008-02-07 09:53:52 +00:00
|
|
|
}
|
2008-07-20 11:27:22 +00:00
|
|
|
|
2009-01-04 12:01:46 +00:00
|
|
|
case GraphicsWindow::MNU_SHOW_DOF:
|
|
|
|
// This works like a normal solve, except that it calculates
|
|
|
|
// which variables are free/bound at the same time.
|
2016-01-27 09:09:45 +00:00
|
|
|
SS.GenerateAll(SolveSpaceUI::GENERATE_ALL, true);
|
2009-01-04 12:01:46 +00:00
|
|
|
break;
|
|
|
|
|
2008-07-20 11:27:22 +00:00
|
|
|
case GraphicsWindow::MNU_TRACE_PT:
|
|
|
|
if(gs.points == 1 && gs.n == 1) {
|
|
|
|
SS.traced.point = gs.point[0];
|
|
|
|
SS.GW.ClearSelection();
|
|
|
|
} else {
|
|
|
|
Error("Bad selection for trace; select a single point.");
|
|
|
|
}
|
|
|
|
break;
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2008-07-20 11:27:22 +00:00
|
|
|
case GraphicsWindow::MNU_STOP_TRACING: {
|
2015-12-27 01:03:24 +00:00
|
|
|
std::string exportFile;
|
2016-01-11 08:44:56 +00:00
|
|
|
if(GetSaveFile(exportFile, "", CSV_PATTERN)) {
|
2015-12-27 08:09:00 +00:00
|
|
|
FILE *f = ssfopen(exportFile, "wb");
|
2008-07-20 11:27:22 +00:00
|
|
|
if(f) {
|
|
|
|
int i;
|
|
|
|
SContour *sc = &(SS.traced.path);
|
|
|
|
for(i = 0; i < sc->l.n; i++) {
|
|
|
|
Vector p = sc->l.elem[i].p;
|
|
|
|
double s = SS.exportScale;
|
2008-02-09 13:52:01 +00:00
|
|
|
fprintf(f, "%.10f, %.10f, %.10f\r\n",
|
2008-07-20 11:27:22 +00:00
|
|
|
p.x/s, p.y/s, p.z/s);
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
} else {
|
2015-12-27 01:03:24 +00:00
|
|
|
Error("Couldn't write to '%s'", exportFile.c_str());
|
2008-07-20 11:27:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Clear the trace, and stop tracing
|
|
|
|
SS.traced.point = Entity::NO_ENTITY;
|
|
|
|
SS.traced.path.l.Clear();
|
|
|
|
InvalidateGraphics();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: oops();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::MenuHelp(int id) {
|
2008-02-09 13:52:01 +00:00
|
|
|
switch(id) {
|
|
|
|
case GraphicsWindow::MNU_WEBSITE:
|
2009-10-01 10:35:11 +00:00
|
|
|
OpenWebsite("http://solvespace.com/helpmenu");
|
2008-02-09 13:52:01 +00:00
|
|
|
break;
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2008-02-09 13:52:01 +00:00
|
|
|
case GraphicsWindow::MNU_ABOUT:
|
2013-09-22 10:50:59 +00:00
|
|
|
Message(
|
2013-10-28 05:28:42 +00:00
|
|
|
"This is SolveSpace version " PACKAGE_VERSION ".\n"
|
2013-09-22 10:50:59 +00:00
|
|
|
"\n"
|
|
|
|
"Built " __TIME__ " " __DATE__ ".\n"
|
|
|
|
"\n"
|
|
|
|
"For more information, see http://solvespace.com/\n"
|
|
|
|
"\n"
|
|
|
|
"SolveSpace is free software: you are free to modify\n"
|
|
|
|
"and/or redistribute it under the terms of the GNU\n"
|
|
|
|
"General Public License (GPL) version 3 or later.\n"
|
|
|
|
"\n"
|
|
|
|
"There is NO WARRANTY, to the extent permitted by\n"
|
|
|
|
"law. For details, visit http://gnu.org/licenses/\n"
|
|
|
|
"\n"
|
2015-12-28 03:33:04 +00:00
|
|
|
"© 2008-2013 Jonathan Westhues and other authors.\n"
|
2013-09-22 10:50:59 +00:00
|
|
|
);
|
2008-02-09 13:52:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: oops();
|
|
|
|
}
|
|
|
|
}
|
2013-09-19 04:33:12 +00:00
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::Clear(void) {
|
2013-09-19 04:33:12 +00:00
|
|
|
sys.Clear();
|
|
|
|
for(int i = 0; i < MAX_UNDO; i++) {
|
|
|
|
if(i < undo.cnt) undo.d[i].Clear();
|
|
|
|
if(i < redo.cnt) redo.d[i].Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sketch::Clear(void) {
|
|
|
|
group.Clear();
|
|
|
|
constraint.Clear();
|
|
|
|
request.Clear();
|
|
|
|
style.Clear();
|
|
|
|
entity.Clear();
|
|
|
|
param.Clear();
|
|
|
|
}
|
2016-01-23 08:05:02 +00:00
|
|
|
|
|
|
|
BBox Sketch::CalculateEntityBBox(bool includingInvisible) {
|
|
|
|
BBox box;
|
|
|
|
bool first = true;
|
|
|
|
for(int i = 0; i < entity.n; i++) {
|
|
|
|
Entity *e = (Entity *)&entity.elem[i];
|
|
|
|
if(!(e->IsVisible() || includingInvisible)) continue;
|
|
|
|
|
|
|
|
Vector point;
|
|
|
|
double r = 0.0;
|
|
|
|
if(e->IsPoint()) {
|
|
|
|
point = e->PointGetNum();
|
|
|
|
} else {
|
|
|
|
switch(e->type) {
|
|
|
|
case Entity::ARC_OF_CIRCLE:
|
|
|
|
case Entity::CIRCLE:
|
|
|
|
r = e->CircleGetRadiusNum();
|
|
|
|
point = GetEntity(e->point[0])->PointGetNum();
|
|
|
|
break;
|
|
|
|
default: continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(first) {
|
|
|
|
box.minp = point;
|
|
|
|
box.maxp = point;
|
|
|
|
box.Include(point, r);
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
box.Include(point, r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return box;
|
|
|
|
}
|