Skip to content

Commit

Permalink
Instead of creating an exact copy of existing constraint, select it.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed May 24, 2019
1 parent 09ca442 commit 406c55e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -35,6 +35,8 @@ New constraint features:
in the text window.
* Distance constraint labels can now be formatted to use SI prefixes.
Values are edited in the configured unit regardless of label format.
* When creating a constraint, if an exactly identical constraint already
exists, it is now selected instead of adding a redundant constraint.
* It is now possible to turn off automatic creation of horizontal/vertical
constraints on line segments.
* Automatic creation of constraints no longer happens if the constraint
Expand Down
12 changes: 11 additions & 1 deletion src/constraint.cpp
Expand Up @@ -745,6 +745,17 @@ void Constraint::MenuConstrain(Command id) {
default: ssassert(false, "Unexpected menu ID");
}

for(const Constraint &cc : SK.constraint) {
if(c.h.v != cc.h.v && c.Equals(cc)) {
// Oops, we already have this exact constraint. Remove the one we just added.
SK.constraint.RemoveById(c.h);
SS.GW.ClearSelection();
// And now select the old one, to give feedback.
SS.GW.MakeSelected(cc.h);
return;
}
}

if(SK.constraint.FindByIdNoOops(c.h)) {
Constraint *constraint = SK.GetConstraint(c.h);
if(SS.TestRankForGroup(c.group) == SolveResult::REDUNDANT_OKAY &&
Expand All @@ -755,7 +766,6 @@ void Constraint::MenuConstrain(Command id) {
}

SS.GW.ClearSelection();
SS.GW.Invalidate();
}

#endif /* ! LIBRARY */
9 changes: 9 additions & 0 deletions src/sketch.h
Expand Up @@ -655,6 +655,15 @@ class ConstraintBase {
bool reference; // a ref dimension, that generates no eqs
std::string comment; // since comments are represented as constraints

bool Equals(const ConstraintBase &c) const {
return type == c.type && group.v == c.group.v && workplane.v == c.workplane.v &&
valA == c.valA && valP.v == c.valP.v && ptA.v == c.ptA.v && ptB.v == c.ptB.v &&
entityA.v == c.entityA.v && entityB.v == c.entityB.v &&
entityC.v == c.entityC.v && entityD.v == c.entityD.v &&
other == c.other && other2 == c.other2 && reference == c.reference &&
comment == c.comment;

This comment has been minimized.

Copy link
@Evil-Spirit

Evil-Spirit May 24, 2019

Collaborator

Can we create two comments with the same text after this commit?

This comment has been minimized.

Copy link
@whitequark

whitequark May 24, 2019

Author Contributor

Yes. Comments are added in a different code path. I checked, of course :)

}

bool HasLabel() const;

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

0 comments on commit 406c55e

Please sign in to comment.