Use an enum to select the mode of operation for GenerateAll.

This commit is contained in:
EvilSpirit 2016-01-27 15:09:45 +06:00 committed by whitequark
parent 2f734d9cfa
commit b28fa34e4a
10 changed files with 30 additions and 14 deletions

View File

@ -150,7 +150,7 @@ void GraphicsWindow::PasteClipboard(Vector trans, double theta, double scale) {
r->construction = cr->construction; r->construction = cr->construction;
// Need to regen to get the right number of points, if extraPoints // Need to regen to get the right number of points, if extraPoints
// changed. // changed.
SS.GenerateAll(-1, -1); SS.GenerateAll(SolveSpaceUI::GENERATE_REGEN);
SS.MarkGroupDirty(r->group); SS.MarkGroupDirty(r->group);
bool hasDistance; bool hasDistance;
int i, pts; int i, pts;

View File

@ -313,12 +313,12 @@ bool TextWindow::EditControlDoneForConfiguration(const char *s) {
} }
case EDIT_CHORD_TOLERANCE: { case EDIT_CHORD_TOLERANCE: {
SS.chordTol = min(10.0, max(0.1, atof(s))); SS.chordTol = min(10.0, max(0.1, atof(s)));
SS.GenerateAll(0, INT_MAX); SS.GenerateAll(SolveSpaceUI::GENERATE_ALL);
break; break;
} }
case EDIT_MAX_SEGMENTS: { case EDIT_MAX_SEGMENTS: {
SS.maxSegments = min(1000, max(7, atoi(s))); SS.maxSegments = min(1000, max(7, atoi(s)));
SS.GenerateAll(0, INT_MAX); SS.GenerateAll(SolveSpaceUI::GENERATE_ALL);
break; break;
} }
case EDIT_CAMERA_TANGENT: { case EDIT_CAMERA_TANGENT: {

View File

@ -255,7 +255,7 @@ bool SolveSpaceUI::SaveToFile(const std::string &filename) {
// the impFileRel for our possibly-new filename. // the impFileRel for our possibly-new filename.
SS.ScheduleShowTW(); SS.ScheduleShowTW();
SS.ReloadAllImported(); SS.ReloadAllImported();
SS.GenerateAll(0, INT_MAX); SS.GenerateAll(SolveSpaceUI::GENERATE_ALL);
fh = ssfopen(filename, "wb"); fh = ssfopen(filename, "wb");
if(!fh) { if(!fh) {

View File

@ -158,13 +158,22 @@ void SolveSpaceUI::GenerateAll(void) {
} }
if(firstDirty == INT_MAX || lastVisible == 0) { if(firstDirty == INT_MAX || lastVisible == 0) {
// All clean; so just regenerate the entities, and don't solve anything. // All clean; so just regenerate the entities, and don't solve anything.
GenerateAll(-1, -1); GenerateAll(GENERATE_REGEN);
} else { } else {
SS.nakedEdges.Clear(); SS.nakedEdges.Clear();
GenerateAll(firstDirty, lastVisible); 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) { void SolveSpaceUI::GenerateAll(int first, int last, bool andFindFree) {
int i, j; int i, j;

View File

@ -678,7 +678,7 @@ void GraphicsWindow::DeleteTaggedRequests(void) {
ClearSuper(); ClearSuper();
// And regenerate to get rid of what it generates, plus anything // And regenerate to get rid of what it generates, plus anything
// that references it (since the regen code checks for that). // that references it (since the regen code checks for that).
SS.GenerateAll(0, INT_MAX); SS.GenerateAll(SolveSpaceUI::GENERATE_ALL);
EnsureValidActives(); EnsureValidActives();
SS.ScheduleShowTW(); SS.ScheduleShowTW();
} }
@ -886,7 +886,7 @@ void GraphicsWindow::MenuEdit(int id) {
case MNU_REGEN_ALL: case MNU_REGEN_ALL:
SS.ReloadAllImported(); SS.ReloadAllImported();
SS.GenerateAll(0, -2); SS.GenerateAll(SolveSpaceUI::GENERATE_UNTIL_ACTIVE);
SS.ScheduleShowTW(); SS.ScheduleShowTW();
break; break;

View File

@ -743,7 +743,7 @@ hRequest GraphicsWindow::AddRequest(int type, bool rememberForUndo) {
// place this request's entities where the mouse is can do so. But // 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 // we mustn't try to solve until reasonable values have been supplied
// for these new parameters, or else we'll get a numerical blowup. // 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); SS.MarkGroupDirty(r.group);
return r.h; return r.h;
} }
@ -1006,7 +1006,7 @@ void GraphicsWindow::MouseLeftDown(double mx, double my) {
} }
(SK.GetRequest(hr)->extraPoints)++; (SK.GetRequest(hr)->extraPoints)++;
SS.GenerateAll(-1, -1); SS.GenerateAll(SolveSpaceUI::GENERATE_REGEN);
int ep = r->extraPoints; int ep = r->extraPoints;
Vector last = SK.GetEntity(hr.entity(3+ep))->PointGetNum(); Vector last = SK.GetEntity(hr.entity(3+ep))->PointGetNum();

View File

@ -294,7 +294,7 @@ void SolveSpaceUI::AfterNewFile(void) {
SS.GW.projRight = Vector::From(1, 0, 0); SS.GW.projRight = Vector::From(1, 0, 0);
SS.GW.projUp = Vector::From(0, 1, 0); SS.GW.projUp = Vector::From(0, 1, 0);
GenerateAll(-1, -1); GenerateAll(GENERATE_REGEN);
TW.Init(); TW.Init();
GW.Init(); GW.Init();
@ -312,7 +312,7 @@ void SolveSpaceUI::AfterNewFile(void) {
// thing visible is the not-yet-generated surfaces. // thing visible is the not-yet-generated surfaces.
GW.ZoomToFit(true); GW.ZoomToFit(true);
GenerateAll(0, INT_MAX); GenerateAll(GENERATE_ALL);
SS.ScheduleShowTW(); SS.ScheduleShowTW();
// Then zoom to fit again, to fit the triangles // Then zoom to fit again, to fit the triangles
GW.ZoomToFit(false); GW.ZoomToFit(false);
@ -713,7 +713,7 @@ void SolveSpaceUI::MenuAnalyze(int id) {
case GraphicsWindow::MNU_SHOW_DOF: case GraphicsWindow::MNU_SHOW_DOF:
// This works like a normal solve, except that it calculates // This works like a normal solve, except that it calculates
// which variables are free/bound at the same time. // which variables are free/bound at the same time.
SS.GenerateAll(0, INT_MAX, true); SS.GenerateAll(SolveSpaceUI::GENERATE_ALL, true);
break; break;
case GraphicsWindow::MNU_TRACE_PT: case GraphicsWindow::MNU_TRACE_PT:

View File

@ -926,6 +926,13 @@ public:
bool PruneRequests(hGroup hg); bool PruneRequests(hGroup hg);
bool PruneConstraints(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(void);
void GenerateAll(int first, int last, bool andFindFree=false); void GenerateAll(int first, int last, bool andFindFree=false);
void SolveGroup(hGroup hg, bool andFindFree); void SolveGroup(hGroup hg, bool andFindFree);

View File

@ -266,7 +266,7 @@ void TextWindow::ScreenDeleteGroup(int link, uint32_t v) {
// This is a major change, so let's re-solve everything. // This is a major change, so let's re-solve everything.
SS.TW.ClearSuper(); SS.TW.ClearSuper();
SS.GW.ClearSuper(); SS.GW.ClearSuper();
SS.GenerateAll(0, INT_MAX); SS.GenerateAll(SolveSpaceUI::GENERATE_ALL);
} }
void TextWindow::ShowGroupInfo(void) { void TextWindow::ShowGroupInfo(void) {
Group *g = SK.group.FindById(shown.group); Group *g = SK.group.FindById(shown.group);

View File

@ -127,7 +127,7 @@ void SolveSpaceUI::PopOntoCurrentFrom(UndoStack *uk) {
SS.GW.ClearSuper(); SS.GW.ClearSuper();
SS.TW.ClearSuper(); SS.TW.ClearSuper();
SS.ReloadAllImported(); SS.ReloadAllImported();
SS.GenerateAll(0, INT_MAX); SS.GenerateAll(SolveSpaceUI::GENERATE_ALL);
SS.ScheduleShowTW(); SS.ScheduleShowTW();
// Activate the group that was active before. // Activate the group that was active before.