From 816a1ee8b43333e6f9bd3a47a77c3b1655187c6d Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Sat, 6 Sep 2008 13:36:31 -0800 Subject: [PATCH] Auto-remove point-on-line constraints when at-midpoint constraints are added. There was already precedent for that, since I auto-remove horiz/vert constraints when symmetry constraints are added. [git-p4: depot-paths = "//depot/solvespace/": change = 1875] --- constraint.cpp | 47 ++++++++++++++++++++++++++++++++--------------- sketch.h | 2 ++ 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/constraint.cpp b/constraint.cpp index e34e0b6..a84e9ed 100644 --- a/constraint.cpp +++ b/constraint.cpp @@ -44,6 +44,29 @@ char *Constraint::DescriptionString(void) { return ret; } +//----------------------------------------------------------------------------- +// Delete all constraints with the specified type, entityA, ptA. We use this +// when auto-removing constraints that would become redundant. +//----------------------------------------------------------------------------- +void Constraint::DeleteAllConstraintsFor(int type, hEntity entityA, hEntity ptA) +{ + SS.constraint.ClearTags(); + for(int i = 0; i < SS.constraint.n; i++) { + Constraint *ct = &(SS.constraint.elem[i]); + if(ct->type != type) continue; + + if(ct->entityA.v != entityA.v) continue; + if(ct->ptA.v != ptA.v) continue; + ct->tag = 1; + } + SS.constraint.RemoveTagged(); + // And no need to do anything special, since nothing + // ever depends on a constraint. But do clear the + // hover, in case the just-deleted constraint was + // hovered. + SS.GW.hover.Clear(); +} + void Constraint::AddConstraint(Constraint *c) { AddConstraint(c, true); } @@ -270,6 +293,10 @@ void Constraint::MenuConstrain(int id) { c.type = AT_MIDPOINT; c.entityA = gs.entity[0]; c.ptA = gs.point[0]; + + // If a point is at-midpoint, then no reason to also constrain + // it on-line; so auto-remove that. + DeleteAllConstraintsFor(PT_ON_LINE, c.entityA, c.ptA); } else if(gs.lineSegments == 1 && gs.workplanes == 1 && gs.n == 2) { c.type = AT_MIDPOINT; int i = SS.GetEntity(gs.entity[0])->IsWorkplane() ? 1 : 0; @@ -360,21 +387,11 @@ void Constraint::MenuConstrain(int id) { if(gs.lineSegments == 1) { // If this line segment is already constrained horiz or // vert, then auto-remove that redundant constraint. - SS.constraint.ClearTags(); - for(int i = 0; i < SS.constraint.n; i++) { - Constraint *ct = &(SS.constraint.elem[i]); - if(ct->type != HORIZONTAL && ct->type != VERTICAL) { - continue; - } - if(ct->entityA.v != (gs.entity[0]).v) continue; - ct->tag = 1; - } - SS.constraint.RemoveTagged(); - // And no need to do anything special, since nothing - // ever depends on a constraint. But do clear the - // hover, in case the just-deleted constraint was - // hovered. - SS.GW.hover.Clear(); + DeleteAllConstraintsFor(HORIZONTAL, (gs.entity[0]), + Entity::NO_ENTITY); + DeleteAllConstraintsFor(VERTICAL, (gs.entity[0]), + Entity::NO_ENTITY); + } } else { // Symmetry with a symmetry plane specified explicitly. diff --git a/sketch.h b/sketch.h index a1181ad..cd2fedb 100644 --- a/sketch.h +++ b/sketch.h @@ -508,6 +508,8 @@ public: static void AddConstraint(Constraint *c, bool rememberForUndo); static void AddConstraint(Constraint *c); static void MenuConstrain(int id); + + static void DeleteAllConstraintsFor(int type, hEntity entityA, hEntity ptA); struct { bool drawing;