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"
|
2016-04-23 23:00:16 +00:00
|
|
|
#include "config.h"
|
2008-03-25 10:02:13 +00:00
|
|
|
|
2015-03-27 15:31:23 +00:00
|
|
|
SolveSpaceUI SolveSpace::SS = {};
|
|
|
|
Sketch SolveSpace::SK = {};
|
2008-03-25 10:02:13 +00:00
|
|
|
|
2015-03-24 06:45:53 +00:00
|
|
|
void SolveSpaceUI::Init() {
|
2016-07-25 19:37:48 +00:00
|
|
|
#if !defined(HEADLESS)
|
Implement a resource system.
Currently, icons, fonts, etc are converted to C structures at compile
time and are hardcoded to the binary. This presents several problems:
* Cross-compilation is complicated. Right now, it is necessary
to be able to run executables for the target platform; this
happens to work with wine-binfmt installed, but is rather ugly.
* Icons can only have one resolution. On OS X, modern software is
expected to take advantage of high-DPI ("Retina") screens and
use so-called @2x assets when ran in high-DPI mode.
* Localization is complicated. Win32 and OS X provide built-in
support for loading the resource appropriate for the user's
locale.
* Embedding strings can only be done as raw strings, using C++'s
R"(...)" literals. This precludes embedding sizable strings,
e.g. JavaScript libraries as used in Three.js export, and makes
git history less useful. Not embedding the libraries means we
have to rely on external CDNs, which requires an Internet
connection and adds a glaring point of failure.
* Linux distribution guidelines are violated. All architecture-
independent data, especially large data such as fonts, is
expected to be in /usr/share, not in the binary.
* Customization is impossible without recompilation. Minor
modifications like adding a few missing vector font characters
or adjusting localization require a complete development
environment, which is unreasonable to expect from users of
a mechanical CAD.
As such, this commit adds a resource system that bundles (and
sometimes builds) resources with the executable. Where they go is
platform-dependent:
* on Win32: into resources of the executable, which allows us to
keep distributing one file;
* on OS X: into the app bundle;
* on other *nix: into /usr/share/solvespace/ or ../res/ (relative
to the executable path), the latter allowing us to run freshly
built executables without installation.
It also subsides the platform-specific resources that are in src/.
The resource system is not yet used for anything; this will be added
in later commits.
2016-04-21 15:54:18 +00:00
|
|
|
// Check that the resource system works.
|
|
|
|
dbp("%s", LoadString("banner.txt").data());
|
2016-07-25 19:37:48 +00:00
|
|
|
#endif
|
Implement a resource system.
Currently, icons, fonts, etc are converted to C structures at compile
time and are hardcoded to the binary. This presents several problems:
* Cross-compilation is complicated. Right now, it is necessary
to be able to run executables for the target platform; this
happens to work with wine-binfmt installed, but is rather ugly.
* Icons can only have one resolution. On OS X, modern software is
expected to take advantage of high-DPI ("Retina") screens and
use so-called @2x assets when ran in high-DPI mode.
* Localization is complicated. Win32 and OS X provide built-in
support for loading the resource appropriate for the user's
locale.
* Embedding strings can only be done as raw strings, using C++'s
R"(...)" literals. This precludes embedding sizable strings,
e.g. JavaScript libraries as used in Three.js export, and makes
git history less useful. Not embedding the libraries means we
have to rely on external CDNs, which requires an Internet
connection and adds a glaring point of failure.
* Linux distribution guidelines are violated. All architecture-
independent data, especially large data such as fonts, is
expected to be in /usr/share, not in the binary.
* Customization is impossible without recompilation. Minor
modifications like adding a few missing vector font characters
or adjusting localization require a complete development
environment, which is unreasonable to expect from users of
a mechanical CAD.
As such, this commit adds a resource system that bundles (and
sometimes builds) resources with the executable. Where they go is
platform-dependent:
* on Win32: into resources of the executable, which allows us to
keep distributing one file;
* on OS X: into the app bundle;
* on other *nix: into /usr/share/solvespace/ or ../res/ (relative
to the executable path), the latter allowing us to run freshly
built executables without installation.
It also subsides the platform-specific resources that are in src/.
The resource system is not yet used for anything; this will be added
in later commits.
2016-04-21 15:54:18 +00:00
|
|
|
|
2018-07-16 10:37:41 +00:00
|
|
|
Platform::SettingsRef settings = Platform::GetSettings();
|
|
|
|
|
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
|
|
|
// Default list of colors for the model material
|
2018-07-16 10:37:41 +00:00
|
|
|
modelColor[0] = settings->ThawColor("ModelColor_0", RGBi(150, 150, 150));
|
|
|
|
modelColor[1] = settings->ThawColor("ModelColor_1", RGBi(100, 100, 100));
|
|
|
|
modelColor[2] = settings->ThawColor("ModelColor_2", RGBi( 30, 30, 30));
|
|
|
|
modelColor[3] = settings->ThawColor("ModelColor_3", RGBi(150, 0, 0));
|
|
|
|
modelColor[4] = settings->ThawColor("ModelColor_4", RGBi( 0, 100, 0));
|
|
|
|
modelColor[5] = settings->ThawColor("ModelColor_5", RGBi( 0, 80, 80));
|
|
|
|
modelColor[6] = settings->ThawColor("ModelColor_6", RGBi( 0, 0, 130));
|
|
|
|
modelColor[7] = settings->ThawColor("ModelColor_7", RGBi( 80, 0, 80));
|
2008-06-11 04:22:52 +00:00
|
|
|
// Light intensities
|
2018-07-18 01:13:05 +00:00
|
|
|
lightIntensity[0] = settings->ThawFloat("LightIntensity_0", 1.0);
|
|
|
|
lightIntensity[1] = settings->ThawFloat("LightIntensity_1", 0.5);
|
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
|
2018-07-18 01:13:05 +00:00
|
|
|
lightDir[0].x = settings->ThawFloat("LightDir_0_Right", -1.0);
|
|
|
|
lightDir[0].y = settings->ThawFloat("LightDir_0_Up", 1.0);
|
|
|
|
lightDir[0].z = settings->ThawFloat("LightDir_0_Forward", 0.0);
|
|
|
|
lightDir[1].x = settings->ThawFloat("LightDir_1_Right", 1.0);
|
|
|
|
lightDir[1].y = settings->ThawFloat("LightDir_1_Up", 0.0);
|
|
|
|
lightDir[1].z = settings->ThawFloat("LightDir_1_Forward", 0.0);
|
2016-01-27 04:07:54 +00:00
|
|
|
|
|
|
|
exportMode = false;
|
2008-07-10 05:26:08 +00:00
|
|
|
// Chord tolerance
|
2018-07-18 01:13:05 +00:00
|
|
|
chordTol = settings->ThawFloat("ChordTolerancePct", 0.5);
|
2008-02-12 13:00:26 +00:00
|
|
|
// Max pwl segments to generate
|
2018-07-16 10:37:41 +00:00
|
|
|
maxSegments = settings->ThawInt("MaxSegments", 10);
|
2016-01-27 04:07:54 +00:00
|
|
|
// Chord tolerance
|
2018-07-18 01:13:05 +00:00
|
|
|
exportChordTol = settings->ThawFloat("ExportChordTolerance", 0.1);
|
2016-01-27 04:07:54 +00:00
|
|
|
// Max pwl segments to generate
|
2018-07-16 10:37:41 +00:00
|
|
|
exportMaxSegments = settings->ThawInt("ExportMaxSegments", 64);
|
2008-06-14 09:51:25 +00:00
|
|
|
// View units
|
2018-07-16 10:37:41 +00:00
|
|
|
viewUnits = (Unit)settings->ThawInt("ViewUnits", (uint32_t)Unit::MM);
|
2010-09-24 02:58:34 +00:00
|
|
|
// Number of digits after the decimal point
|
2018-07-16 10:37:41 +00:00
|
|
|
afterDecimalMm = settings->ThawInt("AfterDecimalMm", 2);
|
|
|
|
afterDecimalInch = settings->ThawInt("AfterDecimalInch", 3);
|
2008-06-17 19:12:25 +00:00
|
|
|
// Camera tangent (determines perspective)
|
2018-07-18 01:13:05 +00:00
|
|
|
cameraTangent = settings->ThawFloat("CameraTangent", 0.3f/1e3);
|
2009-09-29 11:35:19 +00:00
|
|
|
// Grid spacing
|
2018-07-18 01:13:05 +00:00
|
|
|
gridSpacing = settings->ThawFloat("GridSpacing", 5.0);
|
2008-07-08 07:41:29 +00:00
|
|
|
// Export scale factor
|
2018-07-18 01:13:05 +00:00
|
|
|
exportScale = settings->ThawFloat("ExportScale", 1.0);
|
2008-08-14 08:28:25 +00:00
|
|
|
// Export offset (cutter radius comp)
|
2018-07-18 01:13:05 +00:00
|
|
|
exportOffset = settings->ThawFloat("ExportOffset", 0.0);
|
2009-09-22 05:46:30 +00:00
|
|
|
// Rewrite exported colors close to white into black (assuming white bg)
|
2018-07-16 10:37:41 +00:00
|
|
|
fixExportColors = settings->ThawBool("FixExportColors", true);
|
2008-08-11 10:56:08 +00:00
|
|
|
// Draw back faces of triangles (when mesh is leaky/self-intersecting)
|
2018-07-16 10:37:41 +00:00
|
|
|
drawBackFaces = settings->ThawBool("DrawBackFaces", true);
|
2016-12-29 14:34:30 +00:00
|
|
|
// Use turntable mouse navigation
|
|
|
|
turntableNav = settings->ThawBool("TurntableNav", false);
|
2009-10-01 10:35:11 +00:00
|
|
|
// Check that contours are closed and not self-intersecting
|
2018-07-16 10:37:41 +00:00
|
|
|
checkClosedContour = settings->ThawBool("CheckClosedContour", true);
|
2018-04-20 14:43:49 +00:00
|
|
|
// Enable automatic constrains for lines
|
|
|
|
automaticLineConstraints = settings->ThawBool("AutomaticLineConstraints", true);
|
2017-03-30 14:39:42 +00:00
|
|
|
// Draw closed polygons areas
|
2018-07-16 10:37:41 +00:00
|
|
|
showContourAreas = settings->ThawBool("ShowContourAreas", false);
|
2009-03-18 04:26:04 +00:00
|
|
|
// Export shaded triangles in a 2d view
|
2018-07-16 10:37:41 +00:00
|
|
|
exportShadedTriangles = settings->ThawBool("ExportShadedTriangles", true);
|
2009-04-14 04:19:23 +00:00
|
|
|
// Export pwl curves (instead of exact) always
|
2018-07-16 10:37:41 +00:00
|
|
|
exportPwlCurves = settings->ThawBool("ExportPwlCurves", false);
|
2009-09-18 08:14:15 +00:00
|
|
|
// Background color on-screen
|
2018-07-16 10:37:41 +00:00
|
|
|
backgroundColor = settings->ThawColor("BackgroundColor", RGBi(0, 0, 0));
|
2009-09-03 08:13:09 +00:00
|
|
|
// Whether export canvas size is fixed or derived from bbox
|
2018-07-16 10:37:41 +00:00
|
|
|
exportCanvasSizeAuto = settings->ThawBool("ExportCanvasSizeAuto", true);
|
2009-09-03 08:13:09 +00:00
|
|
|
// Margins for automatic canvas size
|
2018-07-18 01:13:05 +00:00
|
|
|
exportMargin.left = settings->ThawFloat("ExportMargin_Left", 5.0);
|
|
|
|
exportMargin.right = settings->ThawFloat("ExportMargin_Right", 5.0);
|
|
|
|
exportMargin.bottom = settings->ThawFloat("ExportMargin_Bottom", 5.0);
|
|
|
|
exportMargin.top = settings->ThawFloat("ExportMargin_Top", 5.0);
|
2009-09-03 08:13:09 +00:00
|
|
|
// Dimensions for fixed canvas size
|
2018-07-18 01:13:05 +00:00
|
|
|
exportCanvas.width = settings->ThawFloat("ExportCanvas_Width", 100.0);
|
|
|
|
exportCanvas.height = settings->ThawFloat("ExportCanvas_Height", 100.0);
|
|
|
|
exportCanvas.dx = settings->ThawFloat("ExportCanvas_Dx", 5.0);
|
|
|
|
exportCanvas.dy = settings->ThawFloat("ExportCanvas_Dy", 5.0);
|
2010-01-14 04:47:17 +00:00
|
|
|
// Extra parameters when exporting G code
|
2018-07-18 01:13:05 +00:00
|
|
|
gCode.depth = settings->ThawFloat("GCode_Depth", 10.0);
|
2018-07-16 10:37:41 +00:00
|
|
|
gCode.passes = settings->ThawInt("GCode_Passes", 1);
|
2018-07-18 01:13:05 +00:00
|
|
|
gCode.feed = settings->ThawFloat("GCode_Feed", 10.0);
|
|
|
|
gCode.plungeFeed = settings->ThawFloat("GCode_PlungeFeed", 10.0);
|
2009-01-02 10:38:36 +00:00
|
|
|
// Show toolbar in the graphics window
|
2018-07-16 10:37:41 +00:00
|
|
|
showToolbar = settings->ThawBool("ShowToolbar", true);
|
2008-06-11 04:22:52 +00:00
|
|
|
// Recent files menus
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
for(size_t i = 0; i < MAX_RECENT; i++) {
|
2018-07-16 10:37:41 +00:00
|
|
|
std::string rawPath = settings->ThawString("RecentFile_" + std::to_string(i), "");
|
2018-07-11 10:48:38 +00:00
|
|
|
if(rawPath.empty()) continue;
|
|
|
|
recentFiles.push_back(Platform::Path::From(rawPath));
|
2008-06-11 04:22:52 +00:00
|
|
|
}
|
2015-03-29 04:46:57 +00:00
|
|
|
// Autosave timer
|
2018-07-16 10:37:41 +00:00
|
|
|
autosaveInterval = settings->ThawInt("AutosaveInterval", 5);
|
2017-01-05 10:39:08 +00:00
|
|
|
// Locale
|
2018-07-16 10:37:41 +00:00
|
|
|
std::string locale = settings->ThawString("Locale", "");
|
2017-01-05 10:39:08 +00:00
|
|
|
if(!locale.empty()) {
|
|
|
|
SetLocale(locale);
|
|
|
|
}
|
2008-06-11 04:22:52 +00:00
|
|
|
|
Eliminate imperative redraws.
This commit removes Platform::Window::Redraw function, and rewrites
its uses to run on timer events. Most UI toolkits have obscure issues
with recursive event handling loops, and Emscripten is purely event-
driven and cannot handle imperative redraws at all.
As a part of this change, the Platform::Timer::WindUp function
is split into three to make the interpretation of its argument
less magical. The new functions are RunAfter (a regular timeout,
setTimeout in browser terms), RunAfterNextFrame (an animation
request, requestAnimationFrame in browser terms), and
RunAfterProcessingEvents (a request to run something after all
events for the current frame are processed, used for coalescing
expensive operations in face of input event queues).
This commit changes two uses of Redraw(): the AnimateOnto() and
ScreenStepDimGo() functions. The latter was actually broken in that
on small sketches, it would run very quickly and not animate
the dimension change at all; this has been fixed.
While we're at it, get rid of unused Platform::Window::NativePtr
function as well.
2018-07-18 23:11:49 +00:00
|
|
|
generateAllTimer = Platform::CreateTimer();
|
|
|
|
generateAllTimer->onTimeout = std::bind(&SolveSpaceUI::GenerateAll, &SS, Generate::DIRTY,
|
2018-07-11 05:35:31 +00:00
|
|
|
/*andFindFree=*/false, /*genForBBox=*/false);
|
|
|
|
|
Eliminate imperative redraws.
This commit removes Platform::Window::Redraw function, and rewrites
its uses to run on timer events. Most UI toolkits have obscure issues
with recursive event handling loops, and Emscripten is purely event-
driven and cannot handle imperative redraws at all.
As a part of this change, the Platform::Timer::WindUp function
is split into three to make the interpretation of its argument
less magical. The new functions are RunAfter (a regular timeout,
setTimeout in browser terms), RunAfterNextFrame (an animation
request, requestAnimationFrame in browser terms), and
RunAfterProcessingEvents (a request to run something after all
events for the current frame are processed, used for coalescing
expensive operations in face of input event queues).
This commit changes two uses of Redraw(): the AnimateOnto() and
ScreenStepDimGo() functions. The latter was actually broken in that
on small sketches, it would run very quickly and not animate
the dimension change at all; this has been fixed.
While we're at it, get rid of unused Platform::Window::NativePtr
function as well.
2018-07-18 23:11:49 +00:00
|
|
|
showTWTimer = Platform::CreateTimer();
|
|
|
|
showTWTimer->onTimeout = std::bind(&TextWindow::Show, &TW);
|
2018-07-11 05:35:31 +00:00
|
|
|
|
Eliminate imperative redraws.
This commit removes Platform::Window::Redraw function, and rewrites
its uses to run on timer events. Most UI toolkits have obscure issues
with recursive event handling loops, and Emscripten is purely event-
driven and cannot handle imperative redraws at all.
As a part of this change, the Platform::Timer::WindUp function
is split into three to make the interpretation of its argument
less magical. The new functions are RunAfter (a regular timeout,
setTimeout in browser terms), RunAfterNextFrame (an animation
request, requestAnimationFrame in browser terms), and
RunAfterProcessingEvents (a request to run something after all
events for the current frame are processed, used for coalescing
expensive operations in face of input event queues).
This commit changes two uses of Redraw(): the AnimateOnto() and
ScreenStepDimGo() functions. The latter was actually broken in that
on small sketches, it would run very quickly and not animate
the dimension change at all; this has been fixed.
While we're at it, get rid of unused Platform::Window::NativePtr
function as well.
2018-07-18 23:11:49 +00:00
|
|
|
autosaveTimer = Platform::CreateTimer();
|
|
|
|
autosaveTimer->onTimeout = std::bind(&SolveSpaceUI::Autosave, &SS);
|
2018-07-11 05:35:31 +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.
|
|
|
|
|
2018-07-11 05:35:31 +00:00
|
|
|
ScheduleAutosave();
|
2015-03-29 04:46:57 +00:00
|
|
|
|
2008-05-29 10:10:12 +00:00
|
|
|
NewFile();
|
|
|
|
AfterNewFile();
|
2018-07-12 19:29:44 +00:00
|
|
|
|
|
|
|
if(TW.window && GW.window) {
|
2018-07-16 10:37:41 +00:00
|
|
|
TW.window->ThawPosition(settings, "TextWindow");
|
|
|
|
GW.window->ThawPosition(settings, "GraphicsWindow");
|
2018-07-12 19:29:44 +00:00
|
|
|
TW.window->SetVisible(true);
|
|
|
|
GW.window->SetVisible(true);
|
|
|
|
GW.window->Focus();
|
2018-07-18 00:48:49 +00:00
|
|
|
|
|
|
|
// Do this once the window is created.
|
|
|
|
Request3DConnexionEventsForWindow(GW.window);
|
2018-07-12 19:29:44 +00:00
|
|
|
}
|
2015-03-24 06:45:53 +00:00
|
|
|
}
|
|
|
|
|
2017-03-11 14:43:21 +00:00
|
|
|
bool SolveSpaceUI::LoadAutosaveFor(const Platform::Path &filename) {
|
|
|
|
Platform::Path autosaveFile = filename.WithExtension(AUTOSAVE_EXT);
|
2015-03-29 04:46:57 +00:00
|
|
|
|
2017-03-11 14:43:21 +00:00
|
|
|
FILE *f = OpenFile(autosaveFile, "rb");
|
2015-03-29 04:46:57 +00:00
|
|
|
if(!f)
|
|
|
|
return false;
|
|
|
|
fclose(f);
|
|
|
|
|
2018-07-17 15:00:46 +00:00
|
|
|
Platform::MessageDialogRef dialog = CreateMessageDialog(GW.window);
|
|
|
|
|
|
|
|
using Platform::MessageDialog;
|
|
|
|
dialog->SetType(MessageDialog::Type::QUESTION);
|
|
|
|
dialog->SetTitle(C_("title", "Autosave Available"));
|
|
|
|
dialog->SetMessage(C_("dialog", "An autosave file is available for this sketch."));
|
|
|
|
dialog->SetDescription(C_("dialog", "Do you want to load the autosave file instead?"));
|
|
|
|
dialog->AddButton(C_("button", "&Load autosave"), MessageDialog::Response::YES,
|
|
|
|
/*isDefault=*/true);
|
|
|
|
dialog->AddButton(C_("button", "Do&n't Load"), MessageDialog::Response::NO);
|
|
|
|
|
Eliminate blocking in Error() and Message() calls.
This serves two purposes.
First, we want to (some day) convert these messages into a less
obtrustive form, something like toaster notifications, such that they
don't interrupt workflow as harshly. That would, of course, be
nonblocking.
Second, some platforms, like Emscripten, do not support nested event
loops, and it's not possible to display a modal dialog on them
synchronously.
When making this commit, I've reviewed all Error() and Message()
calls to ensure that only some of the following is true for all
of them:
* The call is followed a break or return statement that exits
an UI entry point (e.g. an MenuX function);
* The call is followed by cleanup (in fact, in this case the new
behavior is better, since even with a synchronous modal dialog
we have to be reentrant);
* The message is an informational message only and nothing
unexpected will happen if the operation proceeds in background.
In general, all Error() calls already satisfied the above conditions,
although in some cases I changed control flow aroudn them to more
clearly show that. The Message() calls that didn't satisfy these
conditions were reworked into an asynchronous form.
There are three explicit RunModal() calls left that need to be
reworked into an async form.
2018-07-19 21:54:05 +00:00
|
|
|
// FIXME(async): asyncify this call
|
2018-07-17 15:00:46 +00:00
|
|
|
if(dialog->RunModal() == MessageDialog::Response::YES) {
|
2015-03-29 04:46:57 +00:00
|
|
|
unsaved = true;
|
2016-11-28 16:20:59 +00:00
|
|
|
return LoadFromFile(autosaveFile, /*canCancel=*/true);
|
2015-03-29 04:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-11 14:43:21 +00:00
|
|
|
bool SolveSpaceUI::Load(const Platform::Path &filename) {
|
2015-03-29 04:46:57 +00:00
|
|
|
bool autosaveLoaded = LoadAutosaveFor(filename);
|
2016-11-28 16:20:59 +00:00
|
|
|
bool fileLoaded = autosaveLoaded || LoadFromFile(filename, /*canCancel=*/true);
|
|
|
|
if(fileLoaded) {
|
2016-01-11 12:18:18 +00:00
|
|
|
saveFile = filename;
|
2015-03-24 06:45:53 +00:00
|
|
|
AddToRecentList(filename);
|
|
|
|
} else {
|
2017-03-11 14:43:21 +00:00
|
|
|
saveFile.Clear();
|
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;
|
2016-11-28 16:20:59 +00:00
|
|
|
return fileLoaded;
|
2008-05-28 10:10:31 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void SolveSpaceUI::Exit() {
|
2018-07-16 10:37:41 +00:00
|
|
|
Platform::SettingsRef settings = Platform::GetSettings();
|
|
|
|
|
|
|
|
GW.window->FreezePosition(settings, "GraphicsWindow");
|
|
|
|
TW.window->FreezePosition(settings, "TextWindow");
|
2018-07-12 19:29:44 +00:00
|
|
|
|
2008-06-11 04:22:52 +00:00
|
|
|
// Recent files
|
2018-07-11 10:48:38 +00:00
|
|
|
for(size_t i = 0; i < MAX_RECENT; i++) {
|
|
|
|
std::string rawPath;
|
|
|
|
if(recentFiles.size() > i) {
|
|
|
|
rawPath = recentFiles[i].raw;
|
|
|
|
}
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeString("RecentFile_" + std::to_string(i), rawPath);
|
2018-07-11 10:48:38 +00:00
|
|
|
}
|
2008-06-11 04:22:52 +00:00
|
|
|
// Model colors
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
for(size_t i = 0; i < MODEL_COLORS; i++)
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeColor("ModelColor_" + std::to_string(i), modelColor[i]);
|
2008-06-11 04:22:52 +00:00
|
|
|
// Light intensities
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeFloat("LightIntensity_0", (float)lightIntensity[0]);
|
|
|
|
settings->FreezeFloat("LightIntensity_1", (float)lightIntensity[1]);
|
2008-06-11 04:30:18 +00:00
|
|
|
// Light directions
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeFloat("LightDir_0_Right", (float)lightDir[0].x);
|
|
|
|
settings->FreezeFloat("LightDir_0_Up", (float)lightDir[0].y);
|
|
|
|
settings->FreezeFloat("LightDir_0_Forward", (float)lightDir[0].z);
|
|
|
|
settings->FreezeFloat("LightDir_1_Right", (float)lightDir[1].x);
|
|
|
|
settings->FreezeFloat("LightDir_1_Up", (float)lightDir[1].y);
|
|
|
|
settings->FreezeFloat("LightDir_1_Forward", (float)lightDir[1].z);
|
2008-07-10 05:26:08 +00:00
|
|
|
// Chord tolerance
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeFloat("ChordTolerancePct", (float)chordTol);
|
2008-02-12 13:00:26 +00:00
|
|
|
// Max pwl segments to generate
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeInt("MaxSegments", (uint32_t)maxSegments);
|
2016-01-27 04:07:54 +00:00
|
|
|
// Export Chord tolerance
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeFloat("ExportChordTolerance", (float)exportChordTol);
|
2016-01-27 04:07:54 +00:00
|
|
|
// Export Max pwl segments to generate
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeInt("ExportMaxSegments", (uint32_t)exportMaxSegments);
|
2010-09-24 02:58:34 +00:00
|
|
|
// View units
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeInt("ViewUnits", (uint32_t)viewUnits);
|
2010-09-24 02:58:34 +00:00
|
|
|
// Number of digits after the decimal point
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeInt("AfterDecimalMm", (uint32_t)afterDecimalMm);
|
|
|
|
settings->FreezeInt("AfterDecimalInch", (uint32_t)afterDecimalInch);
|
2008-06-17 19:12:25 +00:00
|
|
|
// Camera tangent (determines perspective)
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeFloat("CameraTangent", (float)cameraTangent);
|
2009-09-29 11:35:19 +00:00
|
|
|
// Grid spacing
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeFloat("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
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeFloat("ExportScale", exportScale);
|
2008-08-14 08:28:25 +00:00
|
|
|
// Export offset (cutter radius comp)
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeFloat("ExportOffset", exportOffset);
|
2009-09-22 05:46:30 +00:00
|
|
|
// Rewrite exported colors close to white into black (assuming white bg)
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeBool("FixExportColors", fixExportColors);
|
2008-08-11 10:56:08 +00:00
|
|
|
// Draw back faces of triangles (when mesh is leaky/self-intersecting)
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeBool("DrawBackFaces", drawBackFaces);
|
2017-03-30 14:39:42 +00:00
|
|
|
// Draw closed polygons areas
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeBool("ShowContourAreas", showContourAreas);
|
2009-10-01 10:35:11 +00:00
|
|
|
// Check that contours are closed and not self-intersecting
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeBool("CheckClosedContour", checkClosedContour);
|
2016-12-29 14:34:30 +00:00
|
|
|
// Use turntable mouse navigation
|
|
|
|
settings->FreezeBool("TurntableNav", turntableNav);
|
2018-04-20 14:43:49 +00:00
|
|
|
// Enable automatic constrains for lines
|
|
|
|
settings->FreezeBool("AutomaticLineConstraints", automaticLineConstraints);
|
2009-03-18 04:26:04 +00:00
|
|
|
// Export shaded triangles in a 2d view
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeBool("ExportShadedTriangles", exportShadedTriangles);
|
2009-04-14 04:19:23 +00:00
|
|
|
// Export pwl curves (instead of exact) always
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeBool("ExportPwlCurves", exportPwlCurves);
|
2009-09-18 08:14:15 +00:00
|
|
|
// Background color on-screen
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeColor("BackgroundColor", backgroundColor);
|
2009-09-03 08:13:09 +00:00
|
|
|
// Whether export canvas size is fixed or derived from bbox
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeBool("ExportCanvasSizeAuto", exportCanvasSizeAuto);
|
2009-09-03 08:13:09 +00:00
|
|
|
// Margins for automatic canvas size
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeFloat("ExportMargin_Left", exportMargin.left);
|
|
|
|
settings->FreezeFloat("ExportMargin_Right", exportMargin.right);
|
|
|
|
settings->FreezeFloat("ExportMargin_Bottom", exportMargin.bottom);
|
|
|
|
settings->FreezeFloat("ExportMargin_Top", exportMargin.top);
|
2009-09-03 08:13:09 +00:00
|
|
|
// Dimensions for fixed canvas size
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeFloat("ExportCanvas_Width", exportCanvas.width);
|
|
|
|
settings->FreezeFloat("ExportCanvas_Height", exportCanvas.height);
|
|
|
|
settings->FreezeFloat("ExportCanvas_Dx", exportCanvas.dx);
|
|
|
|
settings->FreezeFloat("ExportCanvas_Dy", exportCanvas.dy);
|
2010-01-14 04:47:17 +00:00
|
|
|
// Extra parameters when exporting G code
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeFloat("GCode_Depth", gCode.depth);
|
|
|
|
settings->FreezeInt("GCode_Passes", gCode.passes);
|
|
|
|
settings->FreezeFloat("GCode_Feed", gCode.feed);
|
|
|
|
settings->FreezeFloat("GCode_PlungeFeed", gCode.plungeFeed);
|
2009-01-02 10:38:36 +00:00
|
|
|
// Show toolbar in the graphics window
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeBool("ShowToolbar", showToolbar);
|
2015-03-29 04:46:57 +00:00
|
|
|
// Autosave timer
|
2018-07-16 10:37:41 +00:00
|
|
|
settings->FreezeInt("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.
|
2018-07-16 10:37:41 +00:00
|
|
|
Style::FreezeDefaultStyles(settings);
|
2009-09-17 07:32:36 +00:00
|
|
|
|
2018-07-18 02:20:25 +00:00
|
|
|
Platform::ExitGui();
|
2008-06-11 04:22:52 +00:00
|
|
|
}
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::ScheduleGenerateAll() {
|
Eliminate imperative redraws.
This commit removes Platform::Window::Redraw function, and rewrites
its uses to run on timer events. Most UI toolkits have obscure issues
with recursive event handling loops, and Emscripten is purely event-
driven and cannot handle imperative redraws at all.
As a part of this change, the Platform::Timer::WindUp function
is split into three to make the interpretation of its argument
less magical. The new functions are RunAfter (a regular timeout,
setTimeout in browser terms), RunAfterNextFrame (an animation
request, requestAnimationFrame in browser terms), and
RunAfterProcessingEvents (a request to run something after all
events for the current frame are processed, used for coalescing
expensive operations in face of input event queues).
This commit changes two uses of Redraw(): the AnimateOnto() and
ScreenStepDimGo() functions. The latter was actually broken in that
on small sketches, it would run very quickly and not animate
the dimension change at all; this has been fixed.
While we're at it, get rid of unused Platform::Window::NativePtr
function as well.
2018-07-18 23:11:49 +00:00
|
|
|
generateAllTimer->RunAfterProcessingEvents();
|
2015-03-18 17:02:11 +00:00
|
|
|
}
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::ScheduleShowTW() {
|
Eliminate imperative redraws.
This commit removes Platform::Window::Redraw function, and rewrites
its uses to run on timer events. Most UI toolkits have obscure issues
with recursive event handling loops, and Emscripten is purely event-
driven and cannot handle imperative redraws at all.
As a part of this change, the Platform::Timer::WindUp function
is split into three to make the interpretation of its argument
less magical. The new functions are RunAfter (a regular timeout,
setTimeout in browser terms), RunAfterNextFrame (an animation
request, requestAnimationFrame in browser terms), and
RunAfterProcessingEvents (a request to run something after all
events for the current frame are processed, used for coalescing
expensive operations in face of input event queues).
This commit changes two uses of Redraw(): the AnimateOnto() and
ScreenStepDimGo() functions. The latter was actually broken in that
on small sketches, it would run very quickly and not animate
the dimension change at all; this has been fixed.
While we're at it, get rid of unused Platform::Window::NativePtr
function as well.
2018-07-18 23:11:49 +00:00
|
|
|
showTWTimer->RunAfterProcessingEvents();
|
2015-03-18 17:02:11 +00:00
|
|
|
}
|
|
|
|
|
2018-07-11 05:35:31 +00:00
|
|
|
void SolveSpaceUI::ScheduleAutosave() {
|
Eliminate imperative redraws.
This commit removes Platform::Window::Redraw function, and rewrites
its uses to run on timer events. Most UI toolkits have obscure issues
with recursive event handling loops, and Emscripten is purely event-
driven and cannot handle imperative redraws at all.
As a part of this change, the Platform::Timer::WindUp function
is split into three to make the interpretation of its argument
less magical. The new functions are RunAfter (a regular timeout,
setTimeout in browser terms), RunAfterNextFrame (an animation
request, requestAnimationFrame in browser terms), and
RunAfterProcessingEvents (a request to run something after all
events for the current frame are processed, used for coalescing
expensive operations in face of input event queues).
This commit changes two uses of Redraw(): the AnimateOnto() and
ScreenStepDimGo() functions. The latter was actually broken in that
on small sketches, it would run very quickly and not animate
the dimension change at all; this has been fixed.
While we're at it, get rid of unused Platform::Window::NativePtr
function as well.
2018-07-18 23:11:49 +00:00
|
|
|
autosaveTimer->RunAfter(autosaveInterval * 60 * 1000);
|
2008-06-03 18:28:41 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
double SolveSpaceUI::MmPerUnit() {
|
2017-03-30 02:24:06 +00:00
|
|
|
switch(viewUnits) {
|
|
|
|
case Unit::INCHES: return 25.4;
|
|
|
|
case Unit::METERS: return 1000.0;
|
|
|
|
case Unit::MM: return 1.0;
|
2010-01-04 00:35:28 +00:00
|
|
|
}
|
2017-03-30 02:24:06 +00:00
|
|
|
return 1.0;
|
2010-01-04 00:35:28 +00:00
|
|
|
}
|
2016-05-05 05:54:05 +00:00
|
|
|
const char *SolveSpaceUI::UnitName() {
|
2017-03-30 02:24:06 +00:00
|
|
|
switch(viewUnits) {
|
|
|
|
case Unit::INCHES: return "inch";
|
|
|
|
case Unit::METERS: return "m";
|
|
|
|
case Unit::MM: return "mm";
|
2010-01-04 00:35:28 +00:00
|
|
|
}
|
2017-03-30 02:24:06 +00:00
|
|
|
return "";
|
2010-01-04 00:35:28 +00:00
|
|
|
}
|
2017-03-30 02:24:06 +00:00
|
|
|
|
2015-11-06 08:40:12 +00:00
|
|
|
std::string SolveSpaceUI::MmToString(double v) {
|
2017-03-30 02:24:06 +00:00
|
|
|
switch(viewUnits) {
|
|
|
|
case Unit::INCHES: return ssprintf("%.*f", afterDecimalInch, v / 25.4);
|
|
|
|
case Unit::METERS: return ssprintf("%.*f", afterDecimalMm, v / 1000.0);
|
|
|
|
case Unit::MM: return ssprintf("%.*f", afterDecimalMm, v);
|
2008-06-14 09:51:25 +00:00
|
|
|
}
|
2017-03-30 02:24:06 +00:00
|
|
|
return "";
|
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
|
|
|
}
|
2016-05-05 05:54:05 +00:00
|
|
|
double SolveSpaceUI::ChordTolMm() {
|
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
|
|
|
}
|
2016-05-05 05:54:05 +00:00
|
|
|
double SolveSpaceUI::ExportChordTolMm() {
|
2016-01-27 04:07:54 +00:00
|
|
|
return exportChordTol / exportScale;
|
|
|
|
}
|
2016-05-05 05:54:05 +00:00
|
|
|
int SolveSpaceUI::GetMaxSegments() {
|
2016-01-27 04:07:54 +00:00
|
|
|
if(exportMode) return exportMaxSegments;
|
|
|
|
return maxSegments;
|
2009-03-08 10:59:57 +00:00
|
|
|
}
|
2016-05-05 05:54:05 +00:00
|
|
|
int SolveSpaceUI::UnitDigitsAfterDecimal() {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
return (viewUnits == Unit::INCHES) ? afterDecimalInch : afterDecimalMm;
|
2010-09-24 02:58:34 +00:00
|
|
|
}
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::SetUnitDigitsAfterDecimal(int v) {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
if(viewUnits == Unit::INCHES) {
|
2010-09-24 02:58:34 +00:00
|
|
|
afterDecimalInch = v;
|
|
|
|
} else {
|
|
|
|
afterDecimalMm = v;
|
|
|
|
}
|
|
|
|
}
|
2008-06-14 09:51:25 +00:00
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
double SolveSpaceUI::CameraTangent() {
|
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
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void SolveSpaceUI::AfterNewFile() {
|
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
|
|
|
|
2016-04-16 09:05:12 +00:00
|
|
|
// Quit export mode
|
|
|
|
justExportedInfo.draw = false;
|
2017-01-17 16:57:27 +00:00
|
|
|
centerOfMass.draw = false;
|
2016-04-16 09:05:12 +00:00
|
|
|
exportMode = false;
|
|
|
|
|
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-10-12 23:15:15 +00:00
|
|
|
GenerateAll(Generate::ALL);
|
2008-05-25 13:11:44 +00:00
|
|
|
|
2008-04-13 10:57:41 +00:00
|
|
|
GW.Init();
|
2018-07-12 19:29:44 +00:00
|
|
|
TW.Init();
|
2008-04-13 10:57:41 +00:00
|
|
|
|
2008-06-03 18:28:41 +00:00
|
|
|
unsaved = false;
|
2008-06-12 07:31:41 +00:00
|
|
|
|
2018-07-12 19:29:44 +00:00
|
|
|
GW.ZoomToFit();
|
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();
|
|
|
|
|
2018-07-12 19:29:44 +00:00
|
|
|
UpdateWindowTitles();
|
2008-04-08 12:54:53 +00:00
|
|
|
}
|
|
|
|
|
2017-03-11 14:43:21 +00:00
|
|
|
void SolveSpaceUI::AddToRecentList(const Platform::Path &filename) {
|
2018-07-11 10:48:38 +00:00
|
|
|
auto it = std::find_if(recentFiles.begin(), recentFiles.end(),
|
|
|
|
[&](const Platform::Path &p) { return p.Equals(filename); });
|
|
|
|
if(it != recentFiles.end()) {
|
|
|
|
recentFiles.erase(it);
|
|
|
|
}
|
2008-05-28 10:10:31 +00:00
|
|
|
|
2018-07-11 10:48:38 +00:00
|
|
|
if(recentFiles.size() > MAX_RECENT) {
|
|
|
|
recentFiles.erase(recentFiles.begin() + MAX_RECENT);
|
2008-05-28 10:10:31 +00:00
|
|
|
}
|
2018-07-11 10:48:38 +00:00
|
|
|
|
|
|
|
recentFiles.insert(recentFiles.begin(), filename);
|
|
|
|
GW.PopulateRecentFiles();
|
2008-05-28 10:10:31 +00:00
|
|
|
}
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
bool SolveSpaceUI::GetFilenameAndSave(bool saveAs) {
|
2018-07-17 18:51:00 +00:00
|
|
|
Platform::SettingsRef settings = Platform::GetSettings();
|
2017-03-11 14:43:21 +00:00
|
|
|
Platform::Path newSaveFile = saveFile;
|
2009-06-10 06:57:27 +00:00
|
|
|
|
2017-03-11 14:43:21 +00:00
|
|
|
if(saveAs || saveFile.IsEmpty()) {
|
2018-07-17 18:51:00 +00:00
|
|
|
Platform::FileDialogRef dialog = Platform::CreateSaveFileDialog(GW.window);
|
|
|
|
dialog->AddFilter(C_("file-type", "SolveSpace models"), { "slvs" });
|
|
|
|
dialog->ThawChoices(settings, "Sketch");
|
|
|
|
if(!newSaveFile.IsEmpty()) {
|
|
|
|
dialog->SetFilename(newSaveFile);
|
|
|
|
}
|
|
|
|
if(dialog->RunModal()) {
|
|
|
|
dialog->FreezeChoices(settings, "Sketch");
|
|
|
|
newSaveFile = dialog->GetFilename();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2008-06-03 18:28:41 +00:00
|
|
|
}
|
|
|
|
|
2017-03-11 14:43:21 +00:00
|
|
|
if(SaveToFile(newSaveFile)) {
|
|
|
|
AddToRecentList(newSaveFile);
|
2015-03-29 04:46:57 +00:00
|
|
|
RemoveAutosave();
|
2017-03-11 14:43:21 +00:00
|
|
|
saveFile = newSaveFile;
|
2008-06-03 18:28:41 +00:00
|
|
|
unsaved = false;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-11 05:35:31 +00:00
|
|
|
void SolveSpaceUI::Autosave()
|
2015-03-29 04:46:57 +00:00
|
|
|
{
|
2018-07-11 05:35:31 +00:00
|
|
|
ScheduleAutosave();
|
2015-03-29 04:46:57 +00:00
|
|
|
|
2018-07-11 05:35:31 +00:00
|
|
|
if(!saveFile.IsEmpty() && unsaved) {
|
|
|
|
SaveToFile(saveFile.WithExtension(AUTOSAVE_EXT));
|
|
|
|
}
|
2015-03-29 04:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SolveSpaceUI::RemoveAutosave()
|
|
|
|
{
|
2017-03-11 14:43:21 +00:00
|
|
|
Platform::Path autosaveFile = saveFile.WithExtension(AUTOSAVE_EXT);
|
|
|
|
RemoveFile(autosaveFile);
|
2015-03-29 04:46:57 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
bool SolveSpaceUI::OkayToStartNewFile() {
|
2008-06-03 18:28:41 +00:00
|
|
|
if(!unsaved) return true;
|
|
|
|
|
2018-07-17 15:00:46 +00:00
|
|
|
Platform::MessageDialogRef dialog = CreateMessageDialog(GW.window);
|
|
|
|
|
|
|
|
using Platform::MessageDialog;
|
|
|
|
dialog->SetType(MessageDialog::Type::QUESTION);
|
|
|
|
dialog->SetTitle(C_("title", "Modified File"));
|
|
|
|
if(!SolveSpace::SS.saveFile.IsEmpty()) {
|
|
|
|
dialog->SetMessage(ssprintf(C_("dialog", "Do you want to save the changes you made to "
|
|
|
|
"the sketch “%s”?"), saveFile.raw.c_str()));
|
|
|
|
} else {
|
|
|
|
dialog->SetMessage(C_("dialog", "Do you want to save the changes you made to "
|
|
|
|
"the new sketch?"));
|
|
|
|
}
|
|
|
|
dialog->SetDescription(C_("dialog", "Your changes will be lost if you don't save them."));
|
|
|
|
dialog->AddButton(C_("button", "&Save"), MessageDialog::Response::YES,
|
|
|
|
/*isDefault=*/true);
|
|
|
|
dialog->AddButton(C_("button", "Do&n't Save"), MessageDialog::Response::NO);
|
|
|
|
dialog->AddButton(C_("button", "&Cancel"), MessageDialog::Response::CANCEL);
|
|
|
|
|
Eliminate blocking in Error() and Message() calls.
This serves two purposes.
First, we want to (some day) convert these messages into a less
obtrustive form, something like toaster notifications, such that they
don't interrupt workflow as harshly. That would, of course, be
nonblocking.
Second, some platforms, like Emscripten, do not support nested event
loops, and it's not possible to display a modal dialog on them
synchronously.
When making this commit, I've reviewed all Error() and Message()
calls to ensure that only some of the following is true for all
of them:
* The call is followed a break or return statement that exits
an UI entry point (e.g. an MenuX function);
* The call is followed by cleanup (in fact, in this case the new
behavior is better, since even with a synchronous modal dialog
we have to be reentrant);
* The message is an informational message only and nothing
unexpected will happen if the operation proceeds in background.
In general, all Error() calls already satisfied the above conditions,
although in some cases I changed control flow aroudn them to more
clearly show that. The Message() calls that didn't satisfy these
conditions were reworked into an asynchronous form.
There are three explicit RunModal() calls left that need to be
reworked into an async form.
2018-07-19 21:54:05 +00:00
|
|
|
// FIXME(async): asyncify this call
|
2018-07-17 15:00:46 +00:00
|
|
|
switch(dialog->RunModal()) {
|
|
|
|
case MessageDialog::Response::YES:
|
2016-05-25 12:08:19 +00:00
|
|
|
return GetFilenameAndSave(/*saveAs=*/false);
|
2008-06-03 18:28:41 +00:00
|
|
|
|
2018-07-17 15:00:46 +00:00
|
|
|
case MessageDialog::Response::NO:
|
2016-06-23 02:50:25 +00:00
|
|
|
RemoveAutosave();
|
2008-06-03 18:28:41 +00:00
|
|
|
return true;
|
|
|
|
|
2018-07-17 15:00:46 +00:00
|
|
|
default:
|
2008-06-03 18:28:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-12 19:29:44 +00:00
|
|
|
void SolveSpaceUI::UpdateWindowTitles() {
|
|
|
|
if(!GW.window || !TW.window) return;
|
|
|
|
|
|
|
|
if(saveFile.IsEmpty()) {
|
|
|
|
GW.window->SetTitle(C_("title", "(new sketch)"));
|
|
|
|
} else {
|
|
|
|
if(!GW.window->SetTitleForFilename(saveFile)) {
|
|
|
|
GW.window->SetTitle(saveFile.raw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TW.window->SetTitle(C_("title", "Property Browser"));
|
2008-07-08 08:02:22 +00:00
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
void SolveSpaceUI::MenuFile(Command id) {
|
2018-07-16 10:37:41 +00:00
|
|
|
Platform::SettingsRef settings = Platform::GetSettings();
|
|
|
|
|
2008-04-18 11:11:48 +00:00
|
|
|
switch(id) {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::NEW:
|
2008-06-03 18:28:41 +00:00
|
|
|
if(!SS.OkayToStartNewFile()) break;
|
|
|
|
|
2017-03-11 14:43:21 +00:00
|
|
|
SS.saveFile.Clear();
|
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;
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::OPEN: {
|
2008-06-03 18:28:41 +00:00
|
|
|
if(!SS.OkayToStartNewFile()) break;
|
|
|
|
|
2018-07-17 18:51:00 +00:00
|
|
|
Platform::FileDialogRef dialog = Platform::CreateOpenFileDialog(SS.GW.window);
|
|
|
|
dialog->AddFilters(Platform::SolveSpaceModelFileFilters);
|
|
|
|
dialog->ThawChoices(settings, "Sketch");
|
|
|
|
if(dialog->RunModal()) {
|
|
|
|
dialog->FreezeChoices(settings, "Sketch");
|
|
|
|
SS.Load(dialog->GetFilename());
|
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
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::SAVE:
|
2016-05-25 12:08:19 +00:00
|
|
|
SS.GetFilenameAndSave(/*saveAs=*/false);
|
2008-06-03 18:28:41 +00:00
|
|
|
break;
|
2008-04-18 11:11:48 +00:00
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::SAVE_AS:
|
2016-05-25 12:08:19 +00:00
|
|
|
SS.GetFilenameAndSave(/*saveAs=*/true);
|
2008-04-18 11:11:48 +00:00
|
|
|
break;
|
|
|
|
|
2018-07-17 18:51:00 +00:00
|
|
|
case Command::EXPORT_IMAGE: {
|
|
|
|
Platform::FileDialogRef dialog = Platform::CreateSaveFileDialog(SS.GW.window);
|
|
|
|
dialog->AddFilters(Platform::RasterFileFilters);
|
|
|
|
dialog->ThawChoices(settings, "ExportImage");
|
|
|
|
if(dialog->RunModal()) {
|
|
|
|
dialog->FreezeChoices(settings, "ExportImage");
|
|
|
|
SS.ExportAsPngTo(dialog->GetFilename());
|
|
|
|
}
|
2008-06-18 08:35:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::EXPORT_VIEW: {
|
2018-07-17 18:51:00 +00:00
|
|
|
Platform::FileDialogRef dialog = Platform::CreateSaveFileDialog(SS.GW.window);
|
|
|
|
dialog->AddFilters(Platform::VectorFileFilters);
|
|
|
|
dialog->ThawChoices(settings, "ExportView");
|
|
|
|
if(!dialog->RunModal()) break;
|
|
|
|
dialog->FreezeChoices(settings, "ExportView");
|
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 &&
|
2018-07-17 18:51:00 +00:00
|
|
|
(dialog->GetFilename().HasExtension("txt") ||
|
2010-01-14 04:47:17 +00:00
|
|
|
fabs(SS.exportOffset) > LENGTH_EPS))
|
|
|
|
{
|
2017-01-07 06:41:13 +00:00
|
|
|
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."));
|
2010-01-14 04:47:17 +00:00
|
|
|
}
|
|
|
|
|
2018-07-17 18:51:00 +00:00
|
|
|
SS.ExportViewOrWireframeTo(dialog->GetFilename(), /*exportWireframe=*/false);
|
2009-10-12 10:40:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::EXPORT_WIREFRAME: {
|
2018-07-17 18:51:00 +00:00
|
|
|
Platform::FileDialogRef dialog = Platform::CreateSaveFileDialog(SS.GW.window);
|
|
|
|
dialog->AddFilters(Platform::Vector3dFileFilters);
|
|
|
|
dialog->ThawChoices(settings, "ExportWireframe");
|
|
|
|
if(!dialog->RunModal()) break;
|
|
|
|
dialog->FreezeChoices(settings, "ExportWireframe");
|
2016-01-11 08:23:51 +00:00
|
|
|
|
2018-07-17 18:51:00 +00:00
|
|
|
SS.ExportViewOrWireframeTo(dialog->GetFilename(), /*exportWireframe*/true);
|
2009-01-14 05:10:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::EXPORT_SECTION: {
|
2018-07-17 18:51:00 +00:00
|
|
|
Platform::FileDialogRef dialog = Platform::CreateSaveFileDialog(SS.GW.window);
|
|
|
|
dialog->AddFilters(Platform::VectorFileFilters);
|
|
|
|
dialog->ThawChoices(settings, "ExportSection");
|
|
|
|
if(!dialog->RunModal()) break;
|
|
|
|
dialog->FreezeChoices(settings, "ExportSection");
|
2016-01-11 08:23:51 +00:00
|
|
|
|
2018-07-17 18:51:00 +00:00
|
|
|
SS.ExportSectionTo(dialog->GetFilename());
|
2008-07-08 06:30:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::EXPORT_MESH: {
|
2018-07-17 18:51:00 +00:00
|
|
|
Platform::FileDialogRef dialog = Platform::CreateSaveFileDialog(SS.GW.window);
|
|
|
|
dialog->AddFilters(Platform::MeshFileFilters);
|
|
|
|
dialog->ThawChoices(settings, "ExportMesh");
|
|
|
|
if(!dialog->RunModal()) break;
|
|
|
|
dialog->FreezeChoices(settings, "ExportMesh");
|
2016-01-11 08:23:51 +00:00
|
|
|
|
2018-07-17 18:51:00 +00:00
|
|
|
SS.ExportMeshTo(dialog->GetFilename());
|
2008-07-06 09:24:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::EXPORT_SURFACES: {
|
2018-07-17 18:51:00 +00:00
|
|
|
Platform::FileDialogRef dialog = Platform::CreateSaveFileDialog(SS.GW.window);
|
|
|
|
dialog->AddFilters(Platform::SurfaceFileFilters);
|
|
|
|
dialog->ThawChoices(settings, "ExportSurfaces");
|
|
|
|
if(!dialog->RunModal()) break;
|
|
|
|
dialog->FreezeChoices(settings, "ExportSurfaces");
|
2016-01-11 08:23:51 +00:00
|
|
|
|
2015-03-27 15:31:23 +00:00
|
|
|
StepFileWriter sfw = {};
|
2018-07-17 18:51:00 +00:00
|
|
|
sfw.ExportSurfacesTo(dialog->GetFilename());
|
2009-06-08 06:50:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::IMPORT: {
|
2018-07-17 18:51:00 +00:00
|
|
|
Platform::FileDialogRef dialog = Platform::CreateOpenFileDialog(SS.GW.window);
|
|
|
|
dialog->AddFilters(Platform::ImportFileFilters);
|
|
|
|
dialog->ThawChoices(settings, "Import");
|
|
|
|
if(!dialog->RunModal()) break;
|
|
|
|
dialog->FreezeChoices(settings, "Import");
|
2016-04-13 08:43:06 +00:00
|
|
|
|
2018-07-17 18:51:00 +00:00
|
|
|
Platform::Path importFile = dialog->GetFilename();
|
2017-03-11 14:43:21 +00:00
|
|
|
if(importFile.HasExtension("dxf")) {
|
2016-05-07 05:17:23 +00:00
|
|
|
ImportDxf(importFile);
|
2017-03-11 14:43:21 +00:00
|
|
|
} else if(importFile.HasExtension("dwg")) {
|
2016-05-07 05:17:23 +00:00
|
|
|
ImportDwg(importFile);
|
2016-11-17 05:24:02 +00:00
|
|
|
} else {
|
2018-07-19 21:51:17 +00:00
|
|
|
Error(_("Can't identify file type from file extension of "
|
|
|
|
"filename '%s'; try .dxf or .dwg."), importFile.raw.c_str());
|
|
|
|
break;
|
2016-11-17 05:24:02 +00:00
|
|
|
}
|
2016-05-09 12:43:52 +00:00
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
SS.GenerateAll(SolveSpaceUI::Generate::UNTIL_ACTIVE);
|
2016-05-09 12:43:52 +00:00
|
|
|
SS.ScheduleShowTW();
|
2016-04-13 08:43:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::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;
|
|
|
|
|
2016-05-18 22:51:36 +00:00
|
|
|
default: ssassert(false, "Unexpected menu ID");
|
2008-04-18 11:11:48 +00:00
|
|
|
}
|
2008-07-08 08:02:22 +00:00
|
|
|
|
2018-07-12 19:29:44 +00:00
|
|
|
SS.UpdateWindowTitles();
|
2008-04-18 11:11:48 +00:00
|
|
|
}
|
2008-07-20 11:27:22 +00:00
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
void SolveSpaceUI::MenuAnalyze(Command id) {
|
2018-07-17 18:51:00 +00:00
|
|
|
Platform::SettingsRef settings = Platform::GetSettings();
|
|
|
|
|
2008-07-20 11:27:22 +00:00
|
|
|
SS.GW.GroupSelection();
|
2016-10-10 12:34:10 +00:00
|
|
|
auto const &gs = SS.GW.gs;
|
2008-07-20 11:27:22 +00:00
|
|
|
|
|
|
|
switch(id) {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::STEP_DIM:
|
2008-07-20 11:27:22 +00:00
|
|
|
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) {
|
Eliminate imperative redraws.
This commit removes Platform::Window::Redraw function, and rewrites
its uses to run on timer events. Most UI toolkits have obscure issues
with recursive event handling loops, and Emscripten is purely event-
driven and cannot handle imperative redraws at all.
As a part of this change, the Platform::Timer::WindUp function
is split into three to make the interpretation of its argument
less magical. The new functions are RunAfter (a regular timeout,
setTimeout in browser terms), RunAfterNextFrame (an animation
request, requestAnimationFrame in browser terms), and
RunAfterProcessingEvents (a request to run something after all
events for the current frame are processed, used for coalescing
expensive operations in face of input event queues).
This commit changes two uses of Redraw(): the AnimateOnto() and
ScreenStepDimGo() functions. The latter was actually broken in that
on small sketches, it would run very quickly and not animate
the dimension change at all; this has been fixed.
While we're at it, get rid of unused Platform::Window::NativePtr
function as well.
2018-07-18 23:11:49 +00:00
|
|
|
SS.TW.stepDim.finish = c->valA;
|
|
|
|
SS.TW.stepDim.steps = 10;
|
|
|
|
SS.TW.stepDim.isDistance =
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
(c->type != Constraint::Type::ANGLE) &&
|
|
|
|
(c->type != Constraint::Type::LENGTH_RATIO) &&
|
|
|
|
(c->type != Constraint::Type::LENGTH_DIFFERENCE);
|
2008-07-20 11:27:22 +00:00
|
|
|
SS.TW.shown.constraint = c->h;
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
SS.TW.shown.screen = TextWindow::Screen::STEP_DIMENSION;
|
2008-07-20 11:27:22 +00:00
|
|
|
|
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 {
|
2017-01-07 06:41:13 +00:00
|
|
|
Error(_("Constraint must have a label, and must not be "
|
|
|
|
"a reference dimension."));
|
2008-07-20 11:27:22 +00:00
|
|
|
}
|
|
|
|
} else {
|
2017-01-07 06:41:13 +00:00
|
|
|
Error(_("Bad selection for step dimension; select a constraint."));
|
2008-07-20 11:27:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::NAKED_EDGES: {
|
2016-11-14 15:16:50 +00:00
|
|
|
ShowNakedEdges(/*reportOnlyWhenNotOkay=*/false);
|
2009-01-19 10:37:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::INTERFERENCE: {
|
2009-05-22 10:02:02 +00:00
|
|
|
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),
|
2016-05-25 12:08:19 +00:00
|
|
|
EdgeKind::SELF_INTER, /*coplanarIsInter=*/false, &inters, &leaks);
|
2009-05-29 05:40:17 +00:00
|
|
|
|
2018-07-12 19:29:44 +00:00
|
|
|
SS.GW.Invalidate();
|
2009-05-22 10:02:02 +00:00
|
|
|
|
|
|
|
if(inters) {
|
|
|
|
Error("%d edges interfere with other triangles, bad.",
|
|
|
|
SS.nakedEdges.l.n);
|
|
|
|
} else {
|
2017-01-07 06:41:13 +00:00
|
|
|
Message(_("The assembly does not interfere, good."));
|
2009-05-22 10:02:02 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-01-17 16:57:27 +00:00
|
|
|
case Command::CENTER_OF_MASS: {
|
|
|
|
SS.UpdateCenterOfMass();
|
|
|
|
SS.centerOfMass.draw = true;
|
2018-07-12 19:29:44 +00:00
|
|
|
SS.GW.Invalidate();
|
2017-01-17 16:57:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::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
|
|
|
|
2018-07-19 21:51:17 +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());
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
if(SS.viewUnits == 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
|
|
|
}
|
2018-07-19 21:51:17 +00:00
|
|
|
msg += _("\n\nCurved surfaces have been approximated as triangles.\n"
|
|
|
|
"This introduces error, typically of around 1%.");
|
2016-01-27 05:13:04 +00:00
|
|
|
Message("%s", msg.c_str());
|
2010-03-01 17:23:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::AREA: {
|
2010-03-01 17:23:57 +00:00
|
|
|
Group *g = SK.GetGroup(SS.GW.activeGroup);
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
if(g->polyError.how != PolyError::GOOD) {
|
2017-01-07 06:41:13 +00:00
|
|
|
Error(_("This group does not contain a correctly-formed "
|
|
|
|
"2d closed area. It is open, not coplanar, or self-"
|
|
|
|
"intersecting."));
|
2010-03-01 17:23:57 +00:00
|
|
|
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 = {};
|
2016-05-25 12:08:19 +00:00
|
|
|
sel.AssemblePolygon(&sp, NULL, /*keepDir=*/true);
|
2010-03-01 17:23:57 +00:00
|
|
|
sp.normal = sp.ComputeNormal();
|
|
|
|
sp.FixContourDirections();
|
|
|
|
double area = sp.SignedArea();
|
|
|
|
double scale = SS.MmPerUnit();
|
2018-07-19 21:51:17 +00:00
|
|
|
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%%."),
|
2010-03-01 17:23:57 +00:00
|
|
|
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
|
|
|
|
2016-08-01 13:18:58 +00:00
|
|
|
case Command::PERIMETER: {
|
|
|
|
if(gs.n > 0 && gs.n == gs.entities) {
|
|
|
|
double perimeter = 0.0;
|
|
|
|
for(int i = 0; i < gs.entities; i++) {
|
|
|
|
Entity *e = SK.entity.FindById(gs.entity[i]);
|
|
|
|
SEdgeList *el = e->GetOrGenerateEdges();
|
|
|
|
for(const SEdge &e : el->l) {
|
|
|
|
perimeter += e.b.Minus(e.a).Magnitude();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double scale = SS.MmPerUnit();
|
2018-07-19 21:51:17 +00:00
|
|
|
Message(_("The total length of the selected entities is:\n\n"
|
|
|
|
" %.3f %s\n\n"
|
|
|
|
"Curves have been approximated as piecewise linear.\n"
|
|
|
|
"This introduces error, typically of around 1%%."),
|
2016-08-01 13:18:58 +00:00
|
|
|
perimeter / scale,
|
|
|
|
SS.UnitName());
|
|
|
|
} else {
|
2017-01-07 06:41:13 +00:00
|
|
|
Error(_("Bad selection for perimeter; select line segments, arcs, and curves."));
|
2016-08-01 13:18:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::SHOW_DOF:
|
2009-01-04 12:01:46 +00:00
|
|
|
// This works like a normal solve, except that it calculates
|
|
|
|
// which variables are free/bound at the same time.
|
2016-12-26 02:09:45 +00:00
|
|
|
SS.GenerateAll(SolveSpaceUI::Generate::ALL, /*andFindFree=*/true);
|
2009-01-04 12:01:46 +00:00
|
|
|
break;
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::TRACE_PT:
|
2008-07-20 11:27:22 +00:00
|
|
|
if(gs.points == 1 && gs.n == 1) {
|
|
|
|
SS.traced.point = gs.point[0];
|
|
|
|
SS.GW.ClearSelection();
|
|
|
|
} else {
|
2017-01-07 06:41:13 +00:00
|
|
|
Error(_("Bad selection for trace; select a single point."));
|
2008-07-20 11:27:22 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-03-29 00:30:52 +00:00
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::STOP_TRACING: {
|
2018-07-17 18:51:00 +00:00
|
|
|
Platform::FileDialogRef dialog = Platform::CreateSaveFileDialog(SS.GW.window);
|
|
|
|
dialog->AddFilters(Platform::CsvFileFilters);
|
|
|
|
dialog->ThawChoices(settings, "Trace");
|
|
|
|
if(dialog->RunModal()) {
|
|
|
|
dialog->FreezeChoices(settings, "Trace");
|
|
|
|
|
|
|
|
FILE *f = OpenFile(dialog->GetFilename(), "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 {
|
2018-07-19 21:51:17 +00:00
|
|
|
Error(_("Couldn't write to '%s'"), dialog->GetFilename().raw.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();
|
2018-07-12 19:29:44 +00:00
|
|
|
SS.GW.Invalidate();
|
2008-07-20 11:27:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-05-18 22:51:36 +00:00
|
|
|
default: ssassert(false, "Unexpected menu ID");
|
2008-07-20 11:27:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-14 15:16:50 +00:00
|
|
|
void SolveSpaceUI::ShowNakedEdges(bool reportOnlyWhenNotOkay) {
|
|
|
|
SS.nakedEdges.Clear();
|
|
|
|
|
|
|
|
Group *g = SK.GetGroup(SS.GW.activeGroup);
|
|
|
|
SMesh *m = &(g->displayMesh);
|
|
|
|
SKdNode *root = SKdNode::From(m);
|
|
|
|
bool inters, leaks;
|
|
|
|
root->MakeCertainEdgesInto(&(SS.nakedEdges),
|
|
|
|
EdgeKind::NAKED_OR_SELF_INTER, /*coplanarIsInter=*/true, &inters, &leaks);
|
|
|
|
|
|
|
|
if(reportOnlyWhenNotOkay && !inters && !leaks && SS.nakedEdges.l.n == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-12 19:29:44 +00:00
|
|
|
SS.GW.Invalidate();
|
2016-11-14 15:16:50 +00:00
|
|
|
|
|
|
|
const char *intersMsg = inters ?
|
2018-07-19 21:51:17 +00:00
|
|
|
_("The mesh is self-intersecting (NOT okay, invalid).") :
|
|
|
|
_("The mesh is not self-intersecting (okay, valid).");
|
2016-11-14 15:16:50 +00:00
|
|
|
const char *leaksMsg = leaks ?
|
2018-07-19 21:51:17 +00:00
|
|
|
_("The mesh has naked edges (NOT okay, invalid).") :
|
|
|
|
_("The mesh is watertight (okay, valid).");
|
2016-11-14 15:16:50 +00:00
|
|
|
|
2018-07-19 21:51:17 +00:00
|
|
|
std::string cntMsg = ssprintf(
|
|
|
|
_("\n\nThe model contains %d triangles, from %d surfaces."),
|
|
|
|
g->displayMesh.l.n, g->runningShell.surface.n);
|
2016-11-14 15:16:50 +00:00
|
|
|
|
|
|
|
if(SS.nakedEdges.l.n == 0) {
|
2018-07-19 21:51:17 +00:00
|
|
|
Message(_("%s\n\n%s\n\nZero problematic edges, good.%s"),
|
2016-11-14 15:16:50 +00:00
|
|
|
intersMsg, leaksMsg, cntMsg.c_str());
|
|
|
|
} else {
|
2018-07-19 21:51:17 +00:00
|
|
|
Error(_("%s\n\n%s\n\n%d problematic edges, bad.%s"),
|
2016-11-14 15:16:50 +00:00
|
|
|
intersMsg, leaksMsg, SS.nakedEdges.l.n, cntMsg.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
void SolveSpaceUI::MenuHelp(Command id) {
|
2008-02-09 13:52:01 +00:00
|
|
|
switch(id) {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::WEBSITE:
|
2018-07-18 02:20:25 +00:00
|
|
|
Platform::OpenInBrowser("http://solvespace.com/helpmenu");
|
2008-02-09 13:52:01 +00:00
|
|
|
break;
|
2015-03-29 00:30:52 +00:00
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::ABOUT:
|
2018-07-19 21:51:17 +00:00
|
|
|
Message(_(
|
2019-05-23 07:43:29 +00:00
|
|
|
"This is SolveSpace version %s.\n"
|
2013-09-22 10:50:59 +00:00
|
|
|
"\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"
|
2019-05-23 07:43:29 +00:00
|
|
|
"© 2008-%d Jonathan Westhues and other authors.\n"),
|
|
|
|
PACKAGE_VERSION, 2019);
|
2008-02-09 13:52:01 +00:00
|
|
|
break;
|
|
|
|
|
2016-05-18 22:51:36 +00:00
|
|
|
default: ssassert(false, "Unexpected menu ID");
|
2008-02-09 13:52:01 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-19 04:33:12 +00:00
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void SolveSpaceUI::Clear() {
|
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();
|
|
|
|
}
|
2018-07-12 19:29:44 +00:00
|
|
|
TW.window = NULL;
|
|
|
|
GW.openRecentMenu = NULL;
|
|
|
|
GW.linkRecentMenu = NULL;
|
|
|
|
GW.showGridMenuItem = NULL;
|
|
|
|
GW.perspectiveProjMenuItem = NULL;
|
|
|
|
GW.showToolbarMenuItem = NULL;
|
|
|
|
GW.showTextWndMenuItem = NULL;
|
|
|
|
GW.fullScreenMenuItem = NULL;
|
|
|
|
GW.unitsMmMenuItem = NULL;
|
|
|
|
GW.unitsMetersMenuItem = NULL;
|
|
|
|
GW.unitsInchesMenuItem = NULL;
|
|
|
|
GW.inWorkplaneMenuItem = NULL;
|
|
|
|
GW.in3dMenuItem = NULL;
|
|
|
|
GW.undoMenuItem = NULL;
|
|
|
|
GW.redoMenuItem = NULL;
|
|
|
|
GW.window = NULL;
|
2013-09-19 04:33:12 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void Sketch::Clear() {
|
2013-09-19 04:33:12 +00:00
|
|
|
group.Clear();
|
2016-02-17 10:03:07 +00:00
|
|
|
groupOrder.Clear();
|
2013-09-19 04:33:12 +00:00
|
|
|
constraint.Clear();
|
|
|
|
request.Clear();
|
|
|
|
style.Clear();
|
|
|
|
entity.Clear();
|
|
|
|
param.Clear();
|
|
|
|
}
|
2016-01-23 08:05:02 +00:00
|
|
|
|
|
|
|
BBox Sketch::CalculateEntityBBox(bool includingInvisible) {
|
2016-02-18 09:53:31 +00:00
|
|
|
BBox box = {};
|
2016-01-23 08:05:02 +00:00
|
|
|
bool first = true;
|
|
|
|
|
2016-10-30 10:26:31 +00:00
|
|
|
auto includePoint = [&](const Vector &point) {
|
2016-01-23 08:05:02 +00:00
|
|
|
if(first) {
|
|
|
|
box.minp = point;
|
|
|
|
box.maxp = point;
|
|
|
|
first = false;
|
|
|
|
} else {
|
2016-10-30 10:26:31 +00:00
|
|
|
box.Include(point);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for(const Entity &e : entity) {
|
|
|
|
if(e.construction) continue;
|
|
|
|
if(!(includingInvisible || e.IsVisible())) continue;
|
|
|
|
|
2019-05-23 16:06:24 +00:00
|
|
|
// arc center point shouldn't be included in bounding box calculation
|
|
|
|
if(e.IsPoint() && e.h.isFromRequest()) {
|
|
|
|
Request *r = SK.GetRequest(e.h.request());
|
|
|
|
if(r->type == Request::Type::ARC_OF_CIRCLE && e.h.v == r->h.entity(1).v) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-30 10:26:31 +00:00
|
|
|
if(e.IsPoint()) {
|
|
|
|
includePoint(e.PointGetNum());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(e.type) {
|
|
|
|
// Circles and arcs are special cases. We calculate their bounds
|
|
|
|
// based on Bezier curve bounds. This is not exact for arcs,
|
|
|
|
// but the implementation is rather simple.
|
|
|
|
case Entity::Type::CIRCLE:
|
|
|
|
case Entity::Type::ARC_OF_CIRCLE: {
|
|
|
|
SBezierList sbl = {};
|
|
|
|
e.GenerateBezierCurves(&sbl);
|
|
|
|
|
|
|
|
for(const SBezier &sb : sbl.l) {
|
|
|
|
for(int j = 0; j <= sb.deg; j++) {
|
|
|
|
includePoint(sb.ctrl[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sbl.Clear();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
continue;
|
2016-01-23 08:05:02 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-30 10:26:31 +00:00
|
|
|
|
2016-01-23 08:05:02 +00:00
|
|
|
return box;
|
|
|
|
}
|
2016-04-02 13:34:17 +00:00
|
|
|
|
2016-04-10 11:25:26 +00:00
|
|
|
Group *Sketch::GetRunningMeshGroupFor(hGroup h) {
|
|
|
|
Group *g = GetGroup(h);
|
2016-04-02 13:34:17 +00:00
|
|
|
while(g != NULL) {
|
|
|
|
if(g->IsMeshGroup()) {
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
g = g->PreviousGroup();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|