feat: Make rectangle corners snappable
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -1293,6 +1293,46 @@ void ViewportWidget::mouseMoveEvent(QMouseEvent *event)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isClose) {
|
||||||
|
m_isSnappingVertex = true;
|
||||||
|
m_snapVertex = vertex;
|
||||||
|
goto end_snap_check;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (obj->type() == SketchObject::ObjectType::Rectangle) {
|
||||||
|
auto rect = static_cast<const SketchRectangle*>(obj);
|
||||||
|
const auto& p1 = rect->corner1();
|
||||||
|
const auto& p3 = rect->corner2();
|
||||||
|
gp_Pnt p2, p4;
|
||||||
|
|
||||||
|
if (sketch->plane() == SketchFeature::SketchPlane::XY) {
|
||||||
|
p2.SetCoord(p3.X(), p1.Y(), p1.Z());
|
||||||
|
p4.SetCoord(p1.X(), p1.Y(), p3.Z());
|
||||||
|
} else if (sketch->plane() == SketchFeature::SketchPlane::XZ) {
|
||||||
|
p2.SetCoord(p3.X(), p1.Y(), p1.Z());
|
||||||
|
p4.SetCoord(p1.X(), p3.Y(), p1.Z());
|
||||||
|
} else if (sketch->plane() == SketchFeature::SketchPlane::YZ) {
|
||||||
|
p2.SetCoord(p1.X(), p3.Y(), p1.Z());
|
||||||
|
p4.SetCoord(p1.X(), p1.Y(), p3.Z());
|
||||||
|
}
|
||||||
|
|
||||||
|
const gp_Pnt vertices[] = {p1, p2, p3, p4};
|
||||||
|
for (const auto& vertex : vertices) {
|
||||||
|
bool isClose = false;
|
||||||
|
switch (m_currentPlane) {
|
||||||
|
case SketchPlane::XY:
|
||||||
|
isClose = qAbs(worldPos.x() - vertex.X()) < snapRectHalfSize && qAbs(worldPos.z() - vertex.Z()) < snapRectHalfSize;
|
||||||
|
break;
|
||||||
|
case SketchPlane::XZ:
|
||||||
|
isClose = qAbs(worldPos.x() - vertex.X()) < snapRectHalfSize && qAbs(worldPos.y() - vertex.Y()) < snapRectHalfSize;
|
||||||
|
break;
|
||||||
|
case SketchPlane::YZ:
|
||||||
|
isClose = qAbs(worldPos.y() - vertex.Y()) < snapRectHalfSize && qAbs(worldPos.z() - vertex.Z()) < snapRectHalfSize;
|
||||||
|
break;
|
||||||
|
case SketchPlane::NONE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (isClose) {
|
if (isClose) {
|
||||||
m_isSnappingVertex = true;
|
m_isSnappingVertex = true;
|
||||||
m_snapVertex = vertex;
|
m_snapVertex = vertex;
|
||||||
|
|||||||
Reference in New Issue
Block a user