From 4a34253a37e9b79e67818859032815798bbfbaa3 Mon Sep 17 00:00:00 2001 From: phkahler <14852918+phkahler@users.noreply.github.com> Date: Mon, 16 Jan 2023 13:35:09 -0500 Subject: [PATCH] Don't try to drag points with pt-coincident constraint to a previous group. Fixes #1012 and makes dragging as done in one of the tutorials possible again. --- src/drawentity.cpp | 40 ++++++++++++++++++++++++++++++++-------- src/sketch.h | 2 +- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/drawentity.cpp b/src/drawentity.cpp index d0092544..2dbbe541 100644 --- a/src/drawentity.cpp +++ b/src/drawentity.cpp @@ -180,19 +180,43 @@ bool Entity::IsVisible() const { return true; } +static bool PtCanDrag(hEntity pt) { + Entity* p = SK.GetEntity(pt); + // a numeric copy can not move + if(p->type == Entity::Type::POINT_N_COPY) return false; + // these transforms applied zero times can not be moved + if(((p->type == Entity::Type::POINT_N_TRANS) || + (p->type == Entity::Type::POINT_N_ROT_AA) || + (p->type == Entity::Type::POINT_N_ROT_AXIS_TRANS)) + && (p->timesApplied == 0)) return false; + return true; +} + // entities that were created via some copy types will not be // draggable with the mouse. We identify the undraggables here bool Entity::CanBeDragged() const { - // a numeric copy can not move - if(type == Entity::Type::POINT_N_COPY) return false; - // these transforms applied zero times can not be moved - if(((type == Entity::Type::POINT_N_TRANS) || - (type == Entity::Type::POINT_N_ROT_AA) || - (type == Entity::Type::POINT_N_ROT_AXIS_TRANS)) - && (timesApplied == 0)) return false; + if(IsPoint()) { + if(!PtCanDrag(h)) + return false; + // are we constrained pt-on-point from a previous group? + for(const Constraint &cc : SK.constraint) { + if(cc.group == group && cc.type == ConstraintBase::Type::POINTS_COINCIDENT) { + if(cc.ptA == h) { + if((SK.GetEntity(cc.ptB)->group < group) + || (!PtCanDrag(cc.ptB))) + return false; + } + if(cc.ptB == h) { + if((SK.GetEntity(cc.ptA)->group < group) + || (!PtCanDrag(cc.ptA))) + return false; + } + } + } + } // for these types of entities the first point will indicate draggability if(HasEndpoints() || type == Entity::Type::CIRCLE) { - return SK.GetEntity(point[0])->CanBeDragged(); + return PtCanDrag(point[0]); } // if we're not certain it can't be dragged then default to true return true; diff --git a/src/sketch.h b/src/sketch.h index 33853d96..020f4081 100644 --- a/src/sketch.h +++ b/src/sketch.h @@ -576,7 +576,7 @@ public: bool IsStylable() const; bool IsVisible() const; bool CanBeDragged() const; - + enum class DrawAs { DEFAULT, OVERLAY, HIDDEN, HOVERED, SELECTED }; void Draw(DrawAs how, Canvas *canvas); void GetReferencePoints(std::vector *refs);