From 9f7ff34b98492a86ddc3de5f1b99953842c8266b Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Sun, 9 May 2010 17:06:09 -0800 Subject: [PATCH] Add option to treat all dimensions as reference dimensions. This is useful because it makes it possible to add cosmetic dimensions to an existing model, without REF appended. [git-p4: depot-paths = "//depot/solvespace/": change = 2140] --- constrainteq.cpp | 18 ++++++++++++++++++ drawconstraint.cpp | 18 ------------------ file.cpp | 1 + generate.cpp | 2 +- sketch.h | 4 +++- system.cpp | 8 ++++++++ textscreens.cpp | 8 +++++++- textwin.cpp | 2 ++ wishlist.txt | 1 - 9 files changed, 40 insertions(+), 22 deletions(-) diff --git a/constrainteq.cpp b/constrainteq.cpp index d456cc8..3bba57e 100644 --- a/constrainteq.cpp +++ b/constrainteq.cpp @@ -2,6 +2,24 @@ const hConstraint ConstraintBase::NO_CONSTRAINT = { 0 }; +bool ConstraintBase::HasLabel(void) { + switch(type) { + case PT_LINE_DISTANCE: + case PT_PLANE_DISTANCE: + case PT_FACE_DISTANCE: + case PT_PT_DISTANCE: + case PROJ_PT_DISTANCE: + case DIAMETER: + case LENGTH_RATIO: + case ANGLE: + case COMMENT: + return true; + + default: + return false; + } +} + Expr *ConstraintBase::VectorsParallel(int eq, ExprVector a, ExprVector b) { ExprVector r = a.Cross(b); // Hairy ball theorem screws me here. There's no clean solution that I diff --git a/drawconstraint.cpp b/drawconstraint.cpp index a8a31e4..f3bebe9 100644 --- a/drawconstraint.cpp +++ b/drawconstraint.cpp @@ -1,23 +1,5 @@ #include "solvespace.h" -bool Constraint::HasLabel(void) { - switch(type) { - case PT_LINE_DISTANCE: - case PT_PLANE_DISTANCE: - case PT_FACE_DISTANCE: - case PT_PT_DISTANCE: - case PROJ_PT_DISTANCE: - case DIAMETER: - case LENGTH_RATIO: - case ANGLE: - case COMMENT: - return true; - - default: - return false; - } -} - void Constraint::LineDrawOrGetDistance(Vector a, Vector b) { if(dogd.drawing) { // Draw comments in the specified style, but everything else in the diff --git a/file.cpp b/file.cpp index 4a2f35c..79b76ba 100644 --- a/file.cpp +++ b/file.cpp @@ -107,6 +107,7 @@ const SolveSpace::SaveTable SolveSpace::SAVED[] = { { 'g', "Group.visible", 'b', &(SS.sv.g.visible) }, { 'g', "Group.suppress", 'b', &(SS.sv.g.suppress) }, { 'g', "Group.relaxConstraints", 'b', &(SS.sv.g.relaxConstraints) }, + { 'g', "Group.allDimsReference", 'b', &(SS.sv.g.allDimsReference) }, { 'g', "Group.scale", 'f', &(SS.sv.g.scale) }, { 'g', "Group.remap", 'M', &(SS.sv.g.remap) }, { 'g', "Group.impFile", 'P', &(SS.sv.g.impFile) }, diff --git a/generate.cpp b/generate.cpp index 2edec89..3030478 100644 --- a/generate.cpp +++ b/generate.cpp @@ -344,7 +344,7 @@ pruned: } void SolveSpace::ForceReferences(void) { - // Force the values of the paramters that define the three reference + // Force the values of the parameters that define the three reference // coordinate systems. static const struct { hRequest hr; diff --git a/sketch.h b/sketch.h index cb2bf79..7cc2209 100644 --- a/sketch.h +++ b/sketch.h @@ -100,6 +100,7 @@ public: bool visible; bool suppress; bool relaxConstraints; + bool allDimsReference; double scale; bool clean; @@ -561,6 +562,8 @@ public: bool reference; // a ref dimension, that generates no eqs NameStr comment; // since comments are represented as constraints + bool HasLabel(void); + void Generate(IdList *l); void GenerateReal(IdList *l); // Some helpers when generating symbolic constraint equations @@ -611,7 +614,6 @@ public: void DoEqualLenTicks(Vector a, Vector b, Vector gn); void DoEqualRadiusTicks(hEntity he); - bool HasLabel(void); char *DescriptionString(void); static void AddConstraint(Constraint *c, bool rememberForUndo); diff --git a/system.cpp b/system.cpp index 9a9accc..a9fa3c5 100644 --- a/system.cpp +++ b/system.cpp @@ -320,6 +320,14 @@ void System::WriteEquationsExceptFor(hConstraint hc, Group *g) { if(c->group.v != g->h.v) continue; if(c->h.v == hc.v) continue; + if(c->HasLabel() && c->type != Constraint::COMMENT && + g->allDimsReference) + { + // When all dimensions are reference, we adjust them to display + // the correct value, and then don't generate any equations. + c->ModifyToSatisfy(); + continue; + } if(g->relaxConstraints && c->type != Constraint::POINTS_COINCIDENT) { // When the constraints are relaxed, we keep only the point- // coincident constraints, and the constraints generated by diff --git a/textscreens.cpp b/textscreens.cpp index eb6df4d..9c13924 100644 --- a/textscreens.cpp +++ b/textscreens.cpp @@ -222,6 +222,8 @@ void TextWindow::ScreenChangeGroupOption(int link, DWORD v) { case 'r': g->relaxConstraints = !(g->relaxConstraints); break; + case 'd': g->allDimsReference = !(g->allDimsReference); break; + case 'f': g->forceToMesh = !(g->forceToMesh); break; } @@ -409,10 +411,14 @@ void TextWindow::ShowGroupInfo(void) { Printf(false, " (model already forced to triangle mesh)"); } - Printf(false, " %f%Lr%Fd%c relax constraints and dimensions", + Printf(true, " %f%Lr%Fd%c relax constraints and dimensions", &TextWindow::ScreenChangeGroupOption, g->relaxConstraints ? CHECK_TRUE : CHECK_FALSE); + Printf(false, " %f%Ld%Fd%c treat all dimensions as reference", + &TextWindow::ScreenChangeGroupOption, + g->allDimsReference ? CHECK_TRUE : CHECK_FALSE); + if(g->booleanFailed) { Printf(false, ""); Printf(false, "The Boolean operation failed. It may be "); diff --git a/textwin.cpp b/textwin.cpp index e73c3c4..3582572 100644 --- a/textwin.cpp +++ b/textwin.cpp @@ -387,6 +387,8 @@ void TextWindow::DrawOrHitTestIcons(int how, double mx, double my) } double ox = oldMousePos.x, oy = oldMousePos.y - LINE_HEIGHT; + ox += 3; + oy -= 3; int tw = (strlen(str) + 1)*CHAR_WIDTH; ox = min(ox, (width - 25) - tw); oy = max(oy, 5); diff --git a/wishlist.txt b/wishlist.txt index e08a215..4d6e80d 100644 --- a/wishlist.txt +++ b/wishlist.txt @@ -1,5 +1,4 @@ fix bug with rotation in plane where green line stays displayed -group option to make dimensions always reference? more tangencies, and rounding (of requests, not parametric) -----