From 4de52e52696a7422a319438a29ec87ee7cd7b396 Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Sat, 3 Feb 2024 17:12:49 +0530 Subject: [PATCH] [Sketcher] Handle spline selection in Dimension tool --- src/Mod/Sketcher/Gui/CommandConstraints.cpp | 72 +++++++++++++-------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index 73fae676e8..fa5e13c066 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -1300,41 +1300,43 @@ public: class GeomSelectionSizes { public: - GeomSelectionSizes(size_t s_pts, size_t s_lns, size_t s_cir, size_t s_ell) : - s_pts(s_pts), s_lns(s_lns), s_cir(s_cir), s_ell(s_ell) {} + GeomSelectionSizes(size_t s_pts, size_t s_lns, size_t s_cir, size_t s_ell, size_t s_spl) : + s_pts(s_pts), s_lns(s_lns), s_cir(s_cir), s_ell(s_ell), s_spl(s_spl) {} ~GeomSelectionSizes() {} bool hasPoints() const { return s_pts > 0; } bool hasLines() const { return s_lns > 0; } bool hasCirclesOrArcs() const { return s_cir > 0; } bool hasEllipseAndCo() const { return s_ell > 0; } + bool hasSplineAndCo() const { return s_spl > 0; } - bool has1Point() const { return s_pts == 1 && s_lns == 0 && s_cir == 0 && s_ell == 0; } - bool has2Points() const { return s_pts == 2 && s_lns == 0 && s_cir == 0 && s_ell == 0; } - bool has1Point1Line() const { return s_pts == 1 && s_lns == 1 && s_cir == 0 && s_ell == 0; } - bool has3Points() const { return s_pts == 3 && s_lns == 0 && s_cir == 0 && s_ell == 0; } - bool has4MorePoints() const { return s_pts >= 4 && s_lns == 0 && s_cir == 0 && s_ell == 0; } - bool has2Points1Line() const { return s_pts == 2 && s_lns == 1 && s_cir == 0 && s_ell == 0; } - bool has3MorePoints1Line() const { return s_pts >= 3 && s_lns == 1 && s_cir == 0 && s_ell == 0; } - bool has1Point1Circle() const { return s_pts == 1 && s_lns == 0 && s_cir == 1 && s_ell == 0; } - bool has1MorePoint1Ellipse() const { return s_pts >= 1 && s_lns == 0 && s_cir == 0 && s_ell == 1; } + bool has1Point() const { return s_pts == 1 && s_lns == 0 && s_cir == 0 && s_ell == 0 && s_spl == 0; } + bool has2Points() const { return s_pts == 2 && s_lns == 0 && s_cir == 0 && s_ell == 0 && s_spl == 0; } + bool has1Point1Line() const { return s_pts == 1 && s_lns == 1 && s_cir == 0 && s_ell == 0 && s_spl == 0; } + bool has3Points() const { return s_pts == 3 && s_lns == 0 && s_cir == 0 && s_ell == 0 && s_spl == 0; } + bool has4MorePoints() const { return s_pts >= 4 && s_lns == 0 && s_cir == 0 && s_ell == 0 && s_spl == 0; } + bool has2Points1Line() const { return s_pts == 2 && s_lns == 1 && s_cir == 0 && s_ell == 0 && s_spl == 0; } + bool has3MorePoints1Line() const { return s_pts >= 3 && s_lns == 1 && s_cir == 0 && s_ell == 0 && s_spl == 0; } + bool has1Point1Circle() const { return s_pts == 1 && s_lns == 0 && s_cir == 1 && s_ell == 0 && s_spl == 0; } + bool has1MorePoint1Ellipse() const { return s_pts >= 1 && s_lns == 0 && s_cir == 0 && s_ell == 1 && s_spl == 0; } - bool has1Line() const { return s_pts == 0 && s_lns == 1 && s_cir == 0 && s_ell == 0; } - bool has2Lines() const { return s_pts == 0 && s_lns == 2 && s_cir == 0 && s_ell == 0; } - bool has3MoreLines() const { return s_pts == 0 && s_lns >= 3 && s_cir == 0 && s_ell == 0; } - bool has1Line1Circle() const { return s_pts == 0 && s_lns == 1 && s_cir == 1 && s_ell == 0; } - bool has1Line2Circles() const { return s_pts == 0 && s_lns == 1 && s_cir == 2 && s_ell == 0; } - bool has1Line1Ellipse() const { return s_pts == 0 && s_lns == 1 && s_cir == 0 && s_ell == 1; } + bool has1Line() const { return s_pts == 0 && s_lns == 1 && s_cir == 0 && s_ell == 0 && s_spl == 0; } + bool has2Lines() const { return s_pts == 0 && s_lns == 2 && s_cir == 0 && s_ell == 0 && s_spl == 0; } + bool has3MoreLines() const { return s_pts == 0 && s_lns >= 3 && s_cir == 0 && s_ell == 0 && s_spl == 0; } + bool has1Line1Circle() const { return s_pts == 0 && s_lns == 1 && s_cir == 1 && s_ell == 0 && s_spl == 0; } + bool has1Line2Circles() const { return s_pts == 0 && s_lns == 1 && s_cir == 2 && s_ell == 0 && s_spl == 0; } + bool has1Line1Ellipse() const { return s_pts == 0 && s_lns == 1 && s_cir == 0 && s_ell == 1 && s_spl == 0; } - bool has1Circle() const { return s_pts == 0 && s_lns == 0 && s_cir == 1 && s_ell == 0; } - bool has2Circles() const { return s_pts == 0 && s_lns == 0 && s_cir == 2 && s_ell == 0; } - bool has3MoreCircles() const { return s_pts == 0 && s_lns == 0 && s_cir >= 3 && s_ell == 0; } - bool has1Circle1Ellipse() const { return s_pts == 0 && s_lns == 0 && s_cir == 1 && s_ell == 1; } + bool has1Circle() const { return s_pts == 0 && s_lns == 0 && s_cir == 1 && s_ell == 0 && s_spl == 0; } + bool has2Circles() const { return s_pts == 0 && s_lns == 0 && s_cir == 2 && s_ell == 0 && s_spl == 0; } + bool has3MoreCircles() const { return s_pts == 0 && s_lns == 0 && s_cir >= 3 && s_ell == 0 && s_spl == 0; } + bool has1Circle1Ellipse() const { return s_pts == 0 && s_lns == 0 && s_cir == 1 && s_ell == 1 && s_spl == 0; } - bool has1Ellipse() const { return s_pts == 0 && s_lns == 0 && s_cir == 0 && s_ell == 1; } - bool has2MoreEllipses() const { return s_pts == 0 && s_lns == 0 && s_cir == 0 && s_ell >= 2; } + bool has1Ellipse() const { return s_pts == 0 && s_lns == 0 && s_cir == 0 && s_ell == 1 && s_spl == 0; } + bool has2MoreEllipses() const { return s_pts == 0 && s_lns == 0 && s_cir == 0 && s_ell >= 2 && s_spl == 0; } + bool has1Point1Spline1MoreEdge() const { return s_pts == 1 && s_spl >= 1 && (s_lns + s_cir + s_ell + s_spl) == 2; } - size_t s_pts, s_lns, s_cir, s_ell; + size_t s_pts, s_lns, s_cir, s_ell, s_spl; }; class DrawSketchHandlerDimension : public DrawSketchHandler @@ -1580,6 +1582,7 @@ protected: std::vector selLine; std::vector selCircleArc; std::vector selEllipseAndCo; + std::vector selSplineAndCo; std::vector initialSelection; @@ -1623,6 +1626,7 @@ protected: selLine.clear(); selCircleArc.clear(); selEllipseAndCo.clear(); + selSplineAndCo.clear(); } } @@ -1666,7 +1670,8 @@ protected: } } - std::vector& getSelectionVector(Base::Type selGeoType) { + std::vector& getSelectionVector(Base::Type selGeoType) + { if (selGeoType == Part::GeomPoint::getClassTypeId()) { return selPoints; } @@ -1683,6 +1688,9 @@ protected: selGeoType == Part::GeomArcOfParabola::getClassTypeId()) { return selEllipseAndCo; } + else if (selGeoType == Part::GeomBSplineCurve::getClassTypeId()) { + return selSplineAndCo; + } static std::vector emptyVector; return emptyVector; @@ -1713,12 +1721,13 @@ protected: bool makeAppropriateConstraint(Base::Vector2d onSketchPos) { bool selAllowed = false; - GeomSelectionSizes selection(selPoints.size(), selLine.size(), selCircleArc.size(), selEllipseAndCo.size()); + GeomSelectionSizes selection(selPoints.size(), selLine.size(), selCircleArc.size(), selEllipseAndCo.size(), selSplineAndCo.size()); if (selection.hasPoints()) { if (selection.has1Point()) { makeCts_1Point(selAllowed, onSketchPos); } else if (selection.has2Points()) { makeCts_2Point(selAllowed, onSketchPos); } else if (selection.has1Point1Line()) { makeCts_1Point1Line(selAllowed, onSketchPos); } + else if (selection.has1Point1Spline1MoreEdge()) { makeCts_1Point1Spline1MoreEdge(selAllowed);} else if (selection.has3Points()) { makeCts_3Point(selAllowed, selection.s_pts); } else if (selection.has4MorePoints()) { makeCts_4MorePoint(selAllowed, selection.s_pts); } else if (selection.has2Points1Line()) { makeCts_2Point1Line(selAllowed, onSketchPos, selection.s_pts); } @@ -1821,6 +1830,17 @@ protected: } } + void makeCts_1Point1Spline1MoreEdge(bool& /*selAllowed*/) + { + //angle + if (availableConstraint == AvailableConstraint::FIRST) { + // FIXME: Once everything is implemented uncomment restartCommand and setAllowed + // restartCommand(QT_TRANSLATE_NOOP("Command", "Add 'Angle' constraint")); + // TODO: Find the appropriate geoids and call createAngleConstrain + // selAllowed = true; + } + } + void makeCts_4MorePoint(bool& selAllowed, size_t s_pts) { //Horizontal, vertical