Skip to content

Commit 406c55e

Browse files
committedMay 24, 2019
Instead of creating an exact copy of existing constraint, select it.
1 parent 09ca442 commit 406c55e

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed
 

‎CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ New constraint features:
3535
in the text window.
3636
* Distance constraint labels can now be formatted to use SI prefixes.
3737
Values are edited in the configured unit regardless of label format.
38+
* When creating a constraint, if an exactly identical constraint already
39+
exists, it is now selected instead of adding a redundant constraint.
3840
* It is now possible to turn off automatic creation of horizontal/vertical
3941
constraints on line segments.
4042
* Automatic creation of constraints no longer happens if the constraint

‎src/constraint.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,17 @@ void Constraint::MenuConstrain(Command id) {
745745
default: ssassert(false, "Unexpected menu ID");
746746
}
747747

748+
for(const Constraint &cc : SK.constraint) {
749+
if(c.h.v != cc.h.v && c.Equals(cc)) {
750+
// Oops, we already have this exact constraint. Remove the one we just added.
751+
SK.constraint.RemoveById(c.h);
752+
SS.GW.ClearSelection();
753+
// And now select the old one, to give feedback.
754+
SS.GW.MakeSelected(cc.h);
755+
return;
756+
}
757+
}
758+
748759
if(SK.constraint.FindByIdNoOops(c.h)) {
749760
Constraint *constraint = SK.GetConstraint(c.h);
750761
if(SS.TestRankForGroup(c.group) == SolveResult::REDUNDANT_OKAY &&
@@ -755,7 +766,6 @@ void Constraint::MenuConstrain(Command id) {
755766
}
756767

757768
SS.GW.ClearSelection();
758-
SS.GW.Invalidate();
759769
}
760770

761771
#endif /* ! LIBRARY */

‎src/sketch.h

+9
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,15 @@ class ConstraintBase {
655655
bool reference; // a ref dimension, that generates no eqs
656656
std::string comment; // since comments are represented as constraints
657657

658+
bool Equals(const ConstraintBase &c) const {
659+
return type == c.type && group.v == c.group.v && workplane.v == c.workplane.v &&
660+
valA == c.valA && valP.v == c.valP.v && ptA.v == c.ptA.v && ptB.v == c.ptB.v &&
661+
entityA.v == c.entityA.v && entityB.v == c.entityB.v &&
662+
entityC.v == c.entityC.v && entityD.v == c.entityD.v &&
663+
other == c.other && other2 == c.other2 && reference == c.reference &&
664+
comment == c.comment;
Has comments. Original line has comments.
665+
}
666+
658667
bool HasLabel() const;
659668

660669
void Generate(IdList<Param, hParam> *param);

0 commit comments

Comments
 (0)
Please sign in to comment.