From b28fa34e4a7a6ae619343e1a322ac3c88a97b0bc Mon Sep 17 00:00:00 2001 From: EvilSpirit Date: Wed, 27 Jan 2016 15:09:45 +0600 Subject: [PATCH] Use an enum to select the mode of operation for GenerateAll. --- src/clipboard.cpp | 2 +- src/confscreen.cpp | 4 ++-- src/file.cpp | 2 +- src/generate.cpp | 11 ++++++++++- src/graphicswin.cpp | 4 ++-- src/mouse.cpp | 4 ++-- src/solvespace.cpp | 6 +++--- src/solvespace.h | 7 +++++++ src/textscreens.cpp | 2 +- src/undoredo.cpp | 2 +- 10 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/clipboard.cpp b/src/clipboard.cpp index ad4bea3..d49f89e 100644 --- a/src/clipboard.cpp +++ b/src/clipboard.cpp @@ -150,7 +150,7 @@ void GraphicsWindow::PasteClipboard(Vector trans, double theta, double scale) { r->construction = cr->construction; // Need to regen to get the right number of points, if extraPoints // changed. - SS.GenerateAll(-1, -1); + SS.GenerateAll(SolveSpaceUI::GENERATE_REGEN); SS.MarkGroupDirty(r->group); bool hasDistance; int i, pts; diff --git a/src/confscreen.cpp b/src/confscreen.cpp index 9009df5..437f424 100644 --- a/src/confscreen.cpp +++ b/src/confscreen.cpp @@ -313,12 +313,12 @@ bool TextWindow::EditControlDoneForConfiguration(const char *s) { } case EDIT_CHORD_TOLERANCE: { SS.chordTol = min(10.0, max(0.1, atof(s))); - SS.GenerateAll(0, INT_MAX); + SS.GenerateAll(SolveSpaceUI::GENERATE_ALL); break; } case EDIT_MAX_SEGMENTS: { SS.maxSegments = min(1000, max(7, atoi(s))); - SS.GenerateAll(0, INT_MAX); + SS.GenerateAll(SolveSpaceUI::GENERATE_ALL); break; } case EDIT_CAMERA_TANGENT: { diff --git a/src/file.cpp b/src/file.cpp index ea3d84f..61d1c24 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -255,7 +255,7 @@ bool SolveSpaceUI::SaveToFile(const std::string &filename) { // the impFileRel for our possibly-new filename. SS.ScheduleShowTW(); SS.ReloadAllImported(); - SS.GenerateAll(0, INT_MAX); + SS.GenerateAll(SolveSpaceUI::GENERATE_ALL); fh = ssfopen(filename, "wb"); if(!fh) { diff --git a/src/generate.cpp b/src/generate.cpp index d4e45f0..6cd3579 100644 --- a/src/generate.cpp +++ b/src/generate.cpp @@ -158,13 +158,22 @@ void SolveSpaceUI::GenerateAll(void) { } if(firstDirty == INT_MAX || lastVisible == 0) { // All clean; so just regenerate the entities, and don't solve anything. - GenerateAll(-1, -1); + GenerateAll(GENERATE_REGEN); } else { SS.nakedEdges.Clear(); GenerateAll(firstDirty, lastVisible); } } +void SolveSpaceUI::GenerateAll(GenerateType type, bool andFindFree) { + switch(type) { + case GENERATE_ALL: GenerateAll(0, INT_MAX, andFindFree); break; + case GENERATE_REGEN: GenerateAll(-1, -1, andFindFree); break; + case GENERATE_UNTIL_ACTIVE: GenerateAll(0, -2, andFindFree); break; + default: oops(); + } +} + void SolveSpaceUI::GenerateAll(int first, int last, bool andFindFree) { int i, j; diff --git a/src/graphicswin.cpp b/src/graphicswin.cpp index 909da94..980d1be 100644 --- a/src/graphicswin.cpp +++ b/src/graphicswin.cpp @@ -678,7 +678,7 @@ void GraphicsWindow::DeleteTaggedRequests(void) { ClearSuper(); // And regenerate to get rid of what it generates, plus anything // that references it (since the regen code checks for that). - SS.GenerateAll(0, INT_MAX); + SS.GenerateAll(SolveSpaceUI::GENERATE_ALL); EnsureValidActives(); SS.ScheduleShowTW(); } @@ -886,7 +886,7 @@ void GraphicsWindow::MenuEdit(int id) { case MNU_REGEN_ALL: SS.ReloadAllImported(); - SS.GenerateAll(0, -2); + SS.GenerateAll(SolveSpaceUI::GENERATE_UNTIL_ACTIVE); SS.ScheduleShowTW(); break; diff --git a/src/mouse.cpp b/src/mouse.cpp index 240caf1..42ae6de 100644 --- a/src/mouse.cpp +++ b/src/mouse.cpp @@ -743,7 +743,7 @@ hRequest GraphicsWindow::AddRequest(int type, bool rememberForUndo) { // place this request's entities where the mouse is can do so. But // we mustn't try to solve until reasonable values have been supplied // for these new parameters, or else we'll get a numerical blowup. - SS.GenerateAll(-1, -1); + SS.GenerateAll(SolveSpaceUI::GENERATE_REGEN); SS.MarkGroupDirty(r.group); return r.h; } @@ -1006,7 +1006,7 @@ void GraphicsWindow::MouseLeftDown(double mx, double my) { } (SK.GetRequest(hr)->extraPoints)++; - SS.GenerateAll(-1, -1); + SS.GenerateAll(SolveSpaceUI::GENERATE_REGEN); int ep = r->extraPoints; Vector last = SK.GetEntity(hr.entity(3+ep))->PointGetNum(); diff --git a/src/solvespace.cpp b/src/solvespace.cpp index 5cc2055..609c474 100644 --- a/src/solvespace.cpp +++ b/src/solvespace.cpp @@ -294,7 +294,7 @@ void SolveSpaceUI::AfterNewFile(void) { SS.GW.projRight = Vector::From(1, 0, 0); SS.GW.projUp = Vector::From(0, 1, 0); - GenerateAll(-1, -1); + GenerateAll(GENERATE_REGEN); TW.Init(); GW.Init(); @@ -312,7 +312,7 @@ void SolveSpaceUI::AfterNewFile(void) { // thing visible is the not-yet-generated surfaces. GW.ZoomToFit(true); - GenerateAll(0, INT_MAX); + GenerateAll(GENERATE_ALL); SS.ScheduleShowTW(); // Then zoom to fit again, to fit the triangles GW.ZoomToFit(false); @@ -713,7 +713,7 @@ void SolveSpaceUI::MenuAnalyze(int id) { case GraphicsWindow::MNU_SHOW_DOF: // This works like a normal solve, except that it calculates // which variables are free/bound at the same time. - SS.GenerateAll(0, INT_MAX, true); + SS.GenerateAll(SolveSpaceUI::GENERATE_ALL, true); break; case GraphicsWindow::MNU_TRACE_PT: diff --git a/src/solvespace.h b/src/solvespace.h index 9f94a7b..fb91055 100644 --- a/src/solvespace.h +++ b/src/solvespace.h @@ -926,6 +926,13 @@ public: bool PruneRequests(hGroup hg); bool PruneConstraints(hGroup hg); + enum GenerateType { + GENERATE_ALL, + GENERATE_REGEN, + GENERATE_UNTIL_ACTIVE, + }; + + void GenerateAll(GenerateType type, bool andFindFree = false); void GenerateAll(void); void GenerateAll(int first, int last, bool andFindFree=false); void SolveGroup(hGroup hg, bool andFindFree); diff --git a/src/textscreens.cpp b/src/textscreens.cpp index 02ab543..07c28fd 100644 --- a/src/textscreens.cpp +++ b/src/textscreens.cpp @@ -266,7 +266,7 @@ void TextWindow::ScreenDeleteGroup(int link, uint32_t v) { // This is a major change, so let's re-solve everything. SS.TW.ClearSuper(); SS.GW.ClearSuper(); - SS.GenerateAll(0, INT_MAX); + SS.GenerateAll(SolveSpaceUI::GENERATE_ALL); } void TextWindow::ShowGroupInfo(void) { Group *g = SK.group.FindById(shown.group); diff --git a/src/undoredo.cpp b/src/undoredo.cpp index 7994775..63c89f1 100644 --- a/src/undoredo.cpp +++ b/src/undoredo.cpp @@ -127,7 +127,7 @@ void SolveSpaceUI::PopOntoCurrentFrom(UndoStack *uk) { SS.GW.ClearSuper(); SS.TW.ClearSuper(); SS.ReloadAllImported(); - SS.GenerateAll(0, INT_MAX); + SS.GenerateAll(SolveSpaceUI::GENERATE_ALL); SS.ScheduleShowTW(); // Activate the group that was active before.