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.

pull/1333/head
phkahler 2023-01-16 13:35:09 -05:00 committed by Paul Kahler
parent b4be656f25
commit 4a34253a37
2 changed files with 33 additions and 9 deletions

View File

@ -180,19 +180,43 @@ bool Entity::IsVisible() const {
return true; 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 // entities that were created via some copy types will not be
// draggable with the mouse. We identify the undraggables here // draggable with the mouse. We identify the undraggables here
bool Entity::CanBeDragged() const { bool Entity::CanBeDragged() const {
// a numeric copy can not move if(IsPoint()) {
if(type == Entity::Type::POINT_N_COPY) return false; if(!PtCanDrag(h))
// these transforms applied zero times can not be moved return false;
if(((type == Entity::Type::POINT_N_TRANS) || // are we constrained pt-on-point from a previous group?
(type == Entity::Type::POINT_N_ROT_AA) || for(const Constraint &cc : SK.constraint) {
(type == Entity::Type::POINT_N_ROT_AXIS_TRANS)) if(cc.group == group && cc.type == ConstraintBase::Type::POINTS_COINCIDENT) {
&& (timesApplied == 0)) return false; 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 // for these types of entities the first point will indicate draggability
if(HasEndpoints() || type == Entity::Type::CIRCLE) { 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 // if we're not certain it can't be dragged then default to true
return true; return true;

View File

@ -576,7 +576,7 @@ public:
bool IsStylable() const; bool IsStylable() const;
bool IsVisible() const; bool IsVisible() const;
bool CanBeDragged() const; bool CanBeDragged() const;
enum class DrawAs { DEFAULT, OVERLAY, HIDDEN, HOVERED, SELECTED }; enum class DrawAs { DEFAULT, OVERLAY, HIDDEN, HOVERED, SELECTED };
void Draw(DrawAs how, Canvas *canvas); void Draw(DrawAs how, Canvas *canvas);
void GetReferencePoints(std::vector<Vector> *refs); void GetReferencePoints(std::vector<Vector> *refs);