Fix issue161 and 174. Use the same logic for selction and dragging, but ignore entites that are inherently undraggable.

This allows the selection to reach through entities to their corresponding ones on the underlying sketch which can be dragged if they are not fully constrained. This is decided in a new function Entity::CanBeDragged().
This commit is contained in:
phkahler 2020-08-07 16:59:25 -04:00
parent 575ddb5aaa
commit f9529916c4
3 changed files with 44 additions and 8 deletions

View File

@ -353,18 +353,34 @@ GraphicsWindow::Selection GraphicsWindow::ChooseFromHoverToSelect() {
return sel;
}
// This uses the same logic as hovering and static entity selection
// but ignores points known not to be draggable
GraphicsWindow::Selection GraphicsWindow::ChooseFromHoverToDrag() {
Selection sel = {};
for(const Hover &hov : hoverList) {
if(hov.selection.entity.v == 0) continue;
if(!hov.selection.entity.isFromRequest()) continue;
sel = hov.selection;
break;
}
if(!sel.IsEmpty()) {
if(hoverList.IsEmpty())
return sel;
Group *activeGroup = SK.GetGroup(SS.GW.activeGroup);
int bestOrder = -1;
int bestZIndex = 0;
for(const Hover &hov : hoverList) {
hGroup hg = {};
if(hov.selection.entity.v != 0) {
Entity *e = SK.GetEntity(hov.selection.entity);
if (!e->CanBeDragged()) continue;
hg = e->group;
} else if(hov.selection.constraint.v != 0) {
hg = SK.GetConstraint(hov.selection.constraint)->group;
}
Group *g = SK.GetGroup(hg);
if(g->order > activeGroup->order) continue;
if(bestOrder != -1 && (bestOrder >= g->order || bestZIndex > hov.zIndex)) continue;
bestOrder = g->order;
bestZIndex = hov.zIndex;
sel = hov.selection;
}
return ChooseFromHoverToSelect();
return sel;
}
void GraphicsWindow::HitTestMakeSelection(Point2d mp) {

View File

@ -180,6 +180,25 @@ bool Entity::IsVisible() const {
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_TRANS) ||
(type == Entity::Type::POINT_N_ROT_AXIS_TRANS))
&& (timesApplied == 0)) 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();
}
// if we're not certain it can't be dragged then default to true
return true;
}
void Entity::CalculateNumerical(bool forExport) {
if(IsPoint()) actPoint = PointGetNum();
if(IsNormal()) actNormal = NormalGetNum();

View File

@ -566,6 +566,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);