2013-07-28 22:08:34 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// The user-visible undo/redo operation; whenever they change something, we
|
|
|
|
// record our state and push it on a stack, and we pop the stack when they
|
|
|
|
// select undo.
|
|
|
|
//
|
|
|
|
// Copyright 2008-2013 Jonathan Westhues.
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-06-04 10:22:30 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void SolveSpaceUI::UndoRemember() {
|
2008-06-30 09:09:17 +00:00
|
|
|
unsaved = true;
|
2008-06-04 10:22:30 +00:00
|
|
|
PushFromCurrentOnto(&undo);
|
|
|
|
UndoClearStack(&redo);
|
|
|
|
UndoEnableMenus();
|
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void SolveSpaceUI::UndoUndo() {
|
2008-06-04 10:22:30 +00:00
|
|
|
if(undo.cnt <= 0) return;
|
|
|
|
|
|
|
|
PushFromCurrentOnto(&redo);
|
|
|
|
PopOntoCurrentFrom(&undo);
|
|
|
|
UndoEnableMenus();
|
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void SolveSpaceUI::UndoRedo() {
|
2008-06-04 10:22:30 +00:00
|
|
|
if(redo.cnt <= 0) return;
|
|
|
|
|
|
|
|
PushFromCurrentOnto(&undo);
|
|
|
|
PopOntoCurrentFrom(&redo);
|
|
|
|
UndoEnableMenus();
|
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void SolveSpaceUI::UndoEnableMenus() {
|
2018-07-11 10:48:38 +00:00
|
|
|
SS.GW.undoMenuItem->SetEnabled(undo.cnt > 0);
|
|
|
|
SS.GW.redoMenuItem->SetEnabled(redo.cnt > 0);
|
2008-06-04 10:22:30 +00:00
|
|
|
}
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::PushFromCurrentOnto(UndoStack *uk) {
|
2008-06-04 10:22:30 +00:00
|
|
|
if(uk->cnt == MAX_UNDO) {
|
|
|
|
UndoClearState(&(uk->d[uk->write]));
|
|
|
|
// And then write in to this one again
|
|
|
|
} else {
|
|
|
|
(uk->cnt)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
UndoState *ut = &(uk->d[uk->write]);
|
2015-03-27 15:31:23 +00:00
|
|
|
*ut = {};
|
2016-10-24 15:28:44 +00:00
|
|
|
ut->group.ReserveMore(SK.group.n);
|
2018-01-04 01:42:38 +00:00
|
|
|
for(Group &src : SK.group) {
|
|
|
|
// Shallow copy
|
|
|
|
Group dest(src);
|
2008-06-04 10:22:30 +00:00
|
|
|
// And then clean up all the stuff that needs to be a deep copy,
|
|
|
|
// and zero out all the dynamic stuff that will get regenerated.
|
|
|
|
dest.clean = false;
|
2015-03-27 15:31:23 +00:00
|
|
|
dest.solved = {};
|
|
|
|
dest.polyLoops = {};
|
|
|
|
dest.bezierLoops = {};
|
|
|
|
dest.bezierOpens = {};
|
|
|
|
dest.polyError = {};
|
|
|
|
dest.thisMesh = {};
|
|
|
|
dest.runningMesh = {};
|
|
|
|
dest.thisShell = {};
|
|
|
|
dest.runningShell = {};
|
|
|
|
dest.displayMesh = {};
|
2016-03-14 16:14:24 +00:00
|
|
|
dest.displayOutlines = {};
|
2015-03-27 15:31:23 +00:00
|
|
|
|
2018-01-04 01:42:38 +00:00
|
|
|
dest.remap = src.remap;
|
2008-06-04 10:22:30 +00:00
|
|
|
|
2015-03-27 15:31:23 +00:00
|
|
|
dest.impMesh = {};
|
|
|
|
dest.impShell = {};
|
|
|
|
dest.impEntity = {};
|
2008-06-04 10:22:30 +00:00
|
|
|
ut->group.Add(&dest);
|
|
|
|
}
|
2018-01-04 01:42:38 +00:00
|
|
|
for(auto &src : SK.groupOrder) { ut->groupOrder.Add(&src); }
|
2016-10-24 15:28:44 +00:00
|
|
|
ut->request.ReserveMore(SK.request.n);
|
2018-01-04 01:42:38 +00:00
|
|
|
for(auto &src : SK.request) { ut->request.Add(&src); }
|
2016-10-24 15:28:44 +00:00
|
|
|
ut->constraint.ReserveMore(SK.constraint.n);
|
2018-01-04 01:42:38 +00:00
|
|
|
for(auto &src : SK.constraint) {
|
|
|
|
// Shallow copy
|
|
|
|
Constraint dest(src);
|
2008-06-04 10:22:30 +00:00
|
|
|
ut->constraint.Add(&dest);
|
|
|
|
}
|
2016-10-24 15:28:44 +00:00
|
|
|
ut->param.ReserveMore(SK.param.n);
|
2018-01-04 01:42:38 +00:00
|
|
|
for(auto &src : SK.param) { ut->param.Add(&src); }
|
2016-10-24 15:28:44 +00:00
|
|
|
ut->style.ReserveMore(SK.style.n);
|
2018-01-04 01:42:38 +00:00
|
|
|
for(auto &src : SK.style) { ut->style.Add(&src); }
|
2008-06-04 10:22:30 +00:00
|
|
|
ut->activeGroup = SS.GW.activeGroup;
|
|
|
|
|
|
|
|
uk->write = WRAP(uk->write + 1, MAX_UNDO);
|
|
|
|
}
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::PopOntoCurrentFrom(UndoStack *uk) {
|
2016-05-18 22:51:36 +00:00
|
|
|
ssassert(uk->cnt > 0, "Cannot pop from empty undo stack");
|
2008-06-04 10:22:30 +00:00
|
|
|
(uk->cnt)--;
|
|
|
|
uk->write = WRAP(uk->write - 1, MAX_UNDO);
|
|
|
|
|
|
|
|
UndoState *ut = &(uk->d[uk->write]);
|
|
|
|
|
|
|
|
// Free everything in the main copy of the program before replacing it
|
2018-01-04 01:42:38 +00:00
|
|
|
for(hGroup hg : SK.groupOrder) {
|
|
|
|
Group *g = SK.GetGroup(hg);
|
2010-02-28 19:23:01 +00:00
|
|
|
g->Clear();
|
2008-06-04 10:22:30 +00:00
|
|
|
}
|
2009-04-19 05:53:16 +00:00
|
|
|
SK.group.Clear();
|
2016-02-17 10:03:07 +00:00
|
|
|
SK.groupOrder.Clear();
|
2009-04-19 05:53:16 +00:00
|
|
|
SK.request.Clear();
|
|
|
|
SK.constraint.Clear();
|
|
|
|
SK.param.Clear();
|
2009-09-17 07:32:36 +00:00
|
|
|
SK.style.Clear();
|
2008-06-04 10:22:30 +00:00
|
|
|
|
|
|
|
// And then do a shallow copy of the state from the undo list
|
2009-04-19 05:53:16 +00:00
|
|
|
ut->group.MoveSelfInto(&(SK.group));
|
2018-01-04 01:42:38 +00:00
|
|
|
for(auto &gh : ut->groupOrder) { SK.groupOrder.Add(&gh); }
|
2009-04-19 05:53:16 +00:00
|
|
|
ut->request.MoveSelfInto(&(SK.request));
|
|
|
|
ut->constraint.MoveSelfInto(&(SK.constraint));
|
|
|
|
ut->param.MoveSelfInto(&(SK.param));
|
2009-09-17 07:32:36 +00:00
|
|
|
ut->style.MoveSelfInto(&(SK.style));
|
2008-06-04 10:22:30 +00:00
|
|
|
SS.GW.activeGroup = ut->activeGroup;
|
|
|
|
|
|
|
|
// No need to free it, since a shallow copy was made above
|
2015-03-27 15:31:23 +00:00
|
|
|
*ut = {};
|
2008-06-04 10:22:30 +00:00
|
|
|
|
|
|
|
// And reset the state everywhere else in the program, since the
|
|
|
|
// sketch just changed a lot.
|
|
|
|
SS.GW.ClearSuper();
|
|
|
|
SS.TW.ClearSuper();
|
2016-11-29 16:49:20 +00:00
|
|
|
SS.ReloadAllLinked(SS.saveFile);
|
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::ALL);
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2015-11-01 16:26:55 +00:00
|
|
|
|
|
|
|
// Activate the group that was active before.
|
2016-02-17 10:03:07 +00:00
|
|
|
Group *activeGroup = SK.GetGroup(SS.GW.activeGroup);
|
2015-11-01 16:26:55 +00:00
|
|
|
activeGroup->Activate();
|
2008-06-04 10:22:30 +00:00
|
|
|
}
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::UndoClearStack(UndoStack *uk) {
|
2008-06-04 10:22:30 +00:00
|
|
|
while(uk->cnt > 0) {
|
|
|
|
uk->write = WRAP(uk->write - 1, MAX_UNDO);
|
|
|
|
(uk->cnt)--;
|
|
|
|
UndoClearState(&(uk->d[uk->write]));
|
|
|
|
}
|
2015-03-27 15:31:23 +00:00
|
|
|
*uk = {}; // for good measure
|
2008-06-04 10:22:30 +00:00
|
|
|
}
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::UndoClearState(UndoState *ut) {
|
2018-01-04 01:42:38 +00:00
|
|
|
for(auto &g : ut->group) { g.remap.clear(); }
|
2008-06-04 10:22:30 +00:00
|
|
|
ut->group.Clear();
|
|
|
|
ut->request.Clear();
|
|
|
|
ut->constraint.Clear();
|
|
|
|
ut->param.Clear();
|
2009-09-17 07:32:36 +00:00
|
|
|
ut->style.Clear();
|
2015-03-27 15:31:23 +00:00
|
|
|
*ut = {};
|
2008-06-04 10:22:30 +00:00
|
|
|
}
|
|
|
|
|