diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index 6fc7f6b1d2..87c2e257d1 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -138,7 +138,8 @@ void finishDatumConstraint(Gui::Command* cmd, if (lastConstraintType == Radius || lastConstraintType == Diameter) { const Part::Geometry* geo = sketch->getGeometry(ConStr[i]->First); - if (geo && geo->getTypeId() == Part::GeomCircle::getClassTypeId()) { + + if (geo && isCircle(*geo)) { ConStr[i]->LabelPosition = labelPosition; } } @@ -182,13 +183,7 @@ void showNoConstraintBetweenFixedGeometry(const App::DocumentObject* obj) bool isGeoConcentricCompatible(const Part::Geometry* geo) { - if (geo->getTypeId() == Part::GeomEllipse::getClassTypeId() - || geo->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() - || geo->getTypeId() == Part::GeomCircle::getClassTypeId() - || geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - return true; - } - return false; + return (isEllipse(*geo) || isArcOfEllipse(*geo) || isCircle(*geo) || isArcOfCircle(*geo)); } /// Makes a simple tangency constraint using extra point + tangent via point @@ -213,16 +208,16 @@ void SketcherGui::makeTangentToEllipseviaNewPoint(Sketcher::SketchObject* Obj, Base::Vector3d center2; - if (geom2->getTypeId() == Part::GeomEllipse::getClassTypeId()) { + if (isEllipse(*geom2)) { center2 = (static_cast(geom2))->getCenter(); } - else if (geom2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()) { + else if (isArcOfEllipse(*geom2)) { center2 = (static_cast(geom2))->getCenter(); } - else if (geom2->getTypeId() == Part::GeomCircle::getClassTypeId()) { + else if (isCircle(*geom2)) { center2 = (static_cast(geom2))->getCenter(); } - else if (geom2->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { + else if (isArcOfCircle(*geom2)) { center2 = (static_cast(geom2))->getCenter(); } @@ -296,13 +291,13 @@ void SketcherGui::makeTangentToArcOfEllipseviaNewPoint(Sketcher::SketchObject* O Base::Vector3d center2; - if (geom2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()) { + if (isArcOfEllipse(*geom2)) { center2 = (static_cast(geom2))->getCenter(); } - else if (geom2->getTypeId() == Part::GeomCircle::getClassTypeId()) { + else if (isCircle(*geom2)) { center2 = (static_cast(geom2))->getCenter(); } - else if (geom2->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { + else if (isArcOfCircle(*geom2)) { center2 = (static_cast(geom2))->getCenter(); } @@ -379,28 +374,28 @@ void SketcherGui::makeTangentToArcOfHyperbolaviaNewPoint(Sketcher::SketchObject* Base::Vector3d center2; - if (geom2->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId()) { - const Part::GeomArcOfHyperbola* aoh2 = static_cast(geom2); + if (isArcOfHyperbola(*geom2)) { + auto aoh2 = static_cast(geom2); Base::Vector3d dirmaj2 = aoh2->getMajorAxisDir(); double majord2 = aoh2->getMajorRadius(); double minord2 = aoh2->getMinorRadius(); double df2 = sqrt(majord2 * majord2 + minord2 * minord2); center2 = aoh2->getCenter() + df2 * dirmaj2;// positive focus } - else if (geom2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()) { + else if (isArcOfEllipse(*geom2)) { center2 = (static_cast(geom2))->getCenter(); } - else if (geom2->getTypeId() == Part::GeomEllipse::getClassTypeId()) { + else if (isEllipse(*geom2)) { center2 = (static_cast(geom2))->getCenter(); } - else if (geom2->getTypeId() == Part::GeomCircle::getClassTypeId()) { + else if (isCircle(*geom2)) { center2 = (static_cast(geom2))->getCenter(); } - else if (geom2->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { + else if (isArcOfCircle(*geom2)) { center2 = (static_cast(geom2))->getCenter(); } - else if (geom2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment* l2 = static_cast(geom2); + else if (isLineSegment(*geom2)) { + auto l2 = static_cast(geom2); center2 = (l2->getStartPoint() + l2->getEndPoint()) / 2; } @@ -470,31 +465,31 @@ void SketcherGui::makeTangentToArcOfParabolaviaNewPoint(Sketcher::SketchObject* Base::Vector3d center2; - if (geom2->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { + if (isArcOfParabola(*geom2)) { center2 = (static_cast(geom2))->getFocus(); } - else if (geom2->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId()) { - const Part::GeomArcOfHyperbola* aoh2 = static_cast(geom2); + else if (isArcOfHyperbola(*geom2)) { + auto aoh2 = static_cast(geom2); Base::Vector3d dirmaj2 = aoh2->getMajorAxisDir(); double majord2 = aoh2->getMajorRadius(); double minord2 = aoh2->getMinorRadius(); double df2 = sqrt(majord2 * majord2 + minord2 * minord2); center2 = aoh2->getCenter() + df2 * dirmaj2;// positive focus } - else if (geom2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()) { + else if (isArcOfEllipse(*geom2)) { center2 = (static_cast(geom2))->getCenter(); } - else if (geom2->getTypeId() == Part::GeomEllipse::getClassTypeId()) { + else if (isEllipse(*geom2)) { center2 = (static_cast(geom2))->getCenter(); } - else if (geom2->getTypeId() == Part::GeomCircle::getClassTypeId()) { + else if (isCircle(*geom2)) { center2 = (static_cast(geom2))->getCenter(); } - else if (geom2->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { + else if (isArcOfCircle(*geom2)) { center2 = (static_cast(geom2))->getCenter(); } - else if (geom2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment* l2 = static_cast(geom2); + else if (isLineSegment(*geom2)) { + auto l2 = static_cast(geom2); center2 = (l2->getStartPoint() + l2->getEndPoint()) / 2; } @@ -552,11 +547,8 @@ void SketcherGui::doEndpointTangency(Sketcher::SketchObject* Obj, const Part::Geometry* geom1 = Obj->getGeometry(GeoId1); const Part::Geometry* geom2 = Obj->getGeometry(GeoId2); - if (geom1 && geom2 - && (geom1->getTypeId() == Part::GeomBSplineCurve::getClassTypeId() - || geom2->getTypeId() == Part::GeomBSplineCurve::getClassTypeId())) { - - if (geom1->getTypeId() != Part::GeomBSplineCurve::getClassTypeId()) { + if (geom1 && geom2 && (isBSplineCurve(*geom1) || isBSplineCurve(*geom2))) { + if (! isBSplineCurve(*geom1)) { std::swap(GeoId1, GeoId2); std::swap(PosId1, PosId2); } @@ -1114,7 +1106,6 @@ public: s_pts(s_pts), s_lns(s_lns), s_cir(s_cir), s_ell(s_ell) {} ~GeomSelectionSizes() {} - bool hasPoints() const { return s_pts > 0; } bool hasLines() const { return s_lns > 0; } bool hasCirclesOrArcs() const { return s_cir > 0; } @@ -1332,7 +1323,6 @@ public: } } - if (selIdPair.GeoId == GeoEnum::GeoUndef) { // If mouse is released on "blank" space, finalize and start over finalizeCommand(); @@ -1568,6 +1558,7 @@ protected: availableConstraint = AvailableConstraint::RESET; } } + void makeCts_2Point(bool& selAllowed, Base::Vector2d onSketchPos) { //distance, horizontal, vertical @@ -1586,6 +1577,7 @@ protected: availableConstraint = AvailableConstraint::RESET; } } + void makeCts_1Point1Line(bool& selAllowed, Base::Vector2d onSketchPos) { //distance, Symmetry @@ -1600,6 +1592,7 @@ protected: availableConstraint = AvailableConstraint::RESET; } } + void makeCts_3Point(bool& selAllowed, size_t s_pts) { //Horizontal, vertical, symmetry @@ -1622,6 +1615,7 @@ protected: availableConstraint = AvailableConstraint::RESET; } } + void makeCts_4MorePoint(bool& selAllowed, size_t s_pts) { //Horizontal, vertical @@ -1640,6 +1634,7 @@ protected: availableConstraint = AvailableConstraint::RESET; } } + void makeCts_2Point1Line(bool& selAllowed, Base::Vector2d onSketchPos, size_t s_pts) { //symmetry, distances @@ -1656,6 +1651,7 @@ protected: availableConstraint = AvailableConstraint::RESET; } } + void makeCts_3MorePoint1Line(bool& selAllowed, Base::Vector2d onSketchPos, size_t s_pts) { //distances @@ -1668,17 +1664,20 @@ protected: availableConstraint = AvailableConstraint::RESET; } } + void makeCts_1Point1Circle(bool& selAllowed, Base::Vector2d onSketchPos) { //Distance. For now only circles not arcs! const Part::Geometry* geom = Obj->getGeometry(selCircleArc[0].GeoId); - if (availableConstraint == AvailableConstraint::FIRST && geom->getTypeId() == Part::GeomCircle::getClassTypeId()) { + + if (availableConstraint == AvailableConstraint::FIRST && isCircle(*geom)) { restartCommand(QT_TRANSLATE_NOOP("Command", "Add length constraint")); createDistanceConstrain(selPoints[0].GeoId, selPoints[0].PosId, selCircleArc[0].GeoId, selCircleArc[0].PosId, onSketchPos); selAllowed = true; availableConstraint = AvailableConstraint::RESET; } } + void makeCts_1MorePoint1Ellipse(bool& selAllowed) { Q_UNUSED(selAllowed) @@ -1724,6 +1723,7 @@ protected: selAllowed = true; } } + void makeCts_2Line(bool& selAllowed, Base::Vector2d onSketchPos) { //angle (if parallel: Distance (see in createAngleConstrain)), equal. @@ -1743,8 +1743,8 @@ protected: } availableConstraint = AvailableConstraint::RESET; } - } + void makeCts_3MoreLine(bool& selAllowed, size_t s_lns) { //equality. @@ -1757,17 +1757,20 @@ protected: availableConstraint = AvailableConstraint::RESET; } } + void makeCts_1Line1Circle(bool& selAllowed, Base::Vector2d onSketchPos) { //Distance. For now only circles not arcs! const Part::Geometry* geom = Obj->getGeometry(selCircleArc[0].GeoId); - if (availableConstraint == AvailableConstraint::FIRST && geom->getTypeId() == Part::GeomCircle::getClassTypeId()) { + + if (availableConstraint == AvailableConstraint::FIRST && isCircle(*geom)) { restartCommand(QT_TRANSLATE_NOOP("Command", "Add length constraint")); createDistanceConstrain(selCircleArc[0].GeoId, selCircleArc[0].PosId, selLine[0].GeoId, selLine[0].PosId, onSketchPos); //Line second parameter selAllowed = true; availableConstraint = AvailableConstraint::RESET; } } + void makeCts_1Line2Circle(bool& selAllowed) { //symmetry. @@ -1778,6 +1781,7 @@ protected: availableConstraint = AvailableConstraint::RESET; } } + void makeCts_1Line1Ellipse(bool& selAllowed) { Q_UNUSED(selAllowed) @@ -1795,6 +1799,7 @@ protected: createRadiusDiameterConstrain(selCircleArc[0].GeoId, onSketchPos); selAllowed = true; } + void makeCts_2Circle(bool& selAllowed, Base::Vector2d onSketchPos) { //Distance, radial distance, equality @@ -1802,7 +1807,7 @@ protected: const Part::Geometry* geom = Obj->getGeometry(selCircleArc[0].GeoId); const Part::Geometry* geom2 = Obj->getGeometry(selCircleArc[1].GeoId); if (availableConstraint == AvailableConstraint::FIRST) { - if (geom->getTypeId() == Part::GeomCircle::getClassTypeId() && geom2->getTypeId() == Part::GeomCircle::getClassTypeId()) { + if (isCircle(*geom) && isCircle(*geom2)) { restartCommand(QT_TRANSLATE_NOOP("Command", "Add length constraint")); createDistanceConstrain(selCircleArc[0].GeoId, selCircleArc[0].PosId, selCircleArc[1].GeoId, selCircleArc[1].PosId, onSketchPos); } @@ -1826,8 +1831,8 @@ protected: createEqualityConstrain(selCircleArc[0].GeoId, selCircleArc[1].GeoId); availableConstraint = AvailableConstraint::RESET; } - } + void makeCts_3MoreCircle(bool& selAllowed, size_t s_cir) { //equality. @@ -1840,6 +1845,7 @@ protected: availableConstraint = AvailableConstraint::RESET; } } + void makeCts_1Circle1Ellipse(bool& selAllowed) { Q_UNUSED(selAllowed) @@ -1855,6 +1861,7 @@ protected: //One ellipse or arc of ellipse/hyperbola/parabola - no constrain to attribute selAllowed = true; } + void makeCts_2MoreEllipse(bool& selAllowed, size_t s_ell) { //only ellipse or arc of of same kind, then equality of all radius. @@ -1889,15 +1896,16 @@ protected: Base::Vector3d pnt = Obj->getPoint(GeoId1, PosId1); double ActDist = 0.; const Part::Geometry* geom = Obj->getGeometry(GeoId2); - if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment* lineSeg = static_cast(geom); + + if (isLineSegment(*geom)) { + auto lineSeg = static_cast(geom); Base::Vector3d pnt1 = lineSeg->getStartPoint(); Base::Vector3d pnt2 = lineSeg->getEndPoint(); Base::Vector3d d = pnt2 - pnt1; ActDist = std::abs(-pnt.x * d.y + pnt.y * d.x + pnt1.x * pnt2.y - pnt2.x * pnt1.y) / d.Length(); } - else if (geom->getTypeId() == Part::GeomCircle::getClassTypeId()) { - const Part::GeomCircle* circle = static_cast(geom); + else if (isCircle(*geom)) { + auto circle = static_cast(geom); Base::Vector3d ct = circle->getCenter(); Base::Vector3d di = ct - pnt; ActDist = std::abs(di.Length() - circle->getRadius()); @@ -1910,8 +1918,7 @@ protected: const Part::Geometry* geo1 = Obj->getGeometry(GeoId1); const Part::Geometry* geo2 = Obj->getGeometry(GeoId2); - if (geo1->getTypeId() == Part::GeomCircle::getClassTypeId() - && geo2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { // Circle - line case + if (isCircle(*geo1) && isLineSegment(*geo2)) { // Circle - line case auto circleSeg = static_cast(geo1); double radius = circleSeg->getRadius(); Base::Vector3d center = circleSeg->getCenter(); @@ -1928,8 +1935,7 @@ protected: Gui::cmdAppObjectArgs(Obj, "addConstraint(Sketcher.Constraint('Distance',%d,%d,%f))", GeoId1, GeoId2, ActDist); } - else if (geo1->getTypeId() == Part::GeomCircle::getClassTypeId() - && geo2->getTypeId() == Part::GeomCircle::getClassTypeId()) { // Circle - circle case + else if (isCircle(*geo1) && isCircle(*geo2)) { // Circle - circle case auto circleSeg1 = static_cast(geo1); double radius1 = circleSeg1->getRadius(); Base::Vector3d center1 = circleSeg1->getCenter(); @@ -2017,16 +2023,17 @@ protected: void createRadiusDiameterConstrain(int GeoId, Base::Vector2d onSketchPos) { double radius = 0.0; - bool isCircle = true; + bool isCircleGeom = true; const Part::Geometry* geom = Obj->getGeometry(GeoId); - if (geom && geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle* arc = static_cast(geom); + + if (geom && isArcOfCircle(*geom)) { + auto arc = static_cast(geom); radius = arc->getRadius(); - isCircle = false; + isCircleGeom = false; } - else if (geom && geom->getTypeId() == Part::GeomCircle::getClassTypeId()) { - const Part::GeomCircle* circle = static_cast(geom); + else if (geom && isCircle(*geom)) { + auto circle = static_cast(geom); radius = circle->getRadius(); } @@ -2047,8 +2054,8 @@ protected: if ((firstCstr && dimensioningRadius && !dimensioningDiameter) || (!firstCstr && !dimensioningRadius && dimensioningDiameter) || - (firstCstr && dimensioningRadius && dimensioningDiameter && !isCircle) || - (!firstCstr && dimensioningRadius && dimensioningDiameter && isCircle) ) { + (firstCstr && dimensioningRadius && dimensioningDiameter && !isCircleGeom) || + (!firstCstr && dimensioningRadius && dimensioningDiameter && isCircleGeom) ) { Gui::cmdAppObjectArgs(Obj, "addConstraint(Sketcher.Constraint('Radius',%d,%f)) ", GeoId, radius); } @@ -2096,14 +2103,12 @@ protected: const Part::Geometry* geo1 = Obj->getGeometry(GeoId1); const Part::Geometry* geo2 = Obj->getGeometry(GeoId2); - if ((geo1->getTypeId() == Part::GeomLineSegment::getClassTypeId() && geo2->getTypeId() != Part::GeomLineSegment::getClassTypeId()) || - (geo1->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId() && geo2->getTypeId() != Part::GeomArcOfHyperbola::getClassTypeId()) || - (geo1->getTypeId() == Part::GeomArcOfParabola::getClassTypeId() && geo2->getTypeId() != Part::GeomArcOfParabola::getClassTypeId()) || - (isBsplinePole(geo1) && !isBsplinePole(geo2)) || - ((geo1->getTypeId() == Part::GeomCircle::getClassTypeId() || geo1->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) && - !(geo2->getTypeId() == Part::GeomCircle::getClassTypeId() || geo2->getTypeId() == Part::GeomArcOfCircle::getClassTypeId())) || - ((geo1->getTypeId() == Part::GeomEllipse::getClassTypeId() || geo1->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()) && - !(geo2->getTypeId() == Part::GeomEllipse::getClassTypeId() || geo2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()))) { + if ((isLineSegment(*geo1) && ! isLineSegment(*geo2)) + || (isArcOfHyperbola(*geo1) && ! isArcOfHyperbola(*geo2)) + || (isArcOfParabola(*geo1) && ! isArcOfParabola(*geo2)) + || (isBsplinePole(geo1) && !isBsplinePole(geo2)) + || ((isCircle(*geo1) || isArcOfCircle(*geo1)) && !(isCircle(*geo2) || isArcOfCircle(*geo2))) + || ((isEllipse(*geo1) || isArcOfEllipse(*geo1)) && !(isEllipse(*geo2) || isArcOfEllipse(*geo2)))) { Gui::TranslatedUserWarning(Obj, QObject::tr("Wrong selection"), @@ -2119,10 +2124,10 @@ protected: void createAngleConstrain(int GeoId1, int GeoId2, Base::Vector2d onSketchPos) { const Part::Geometry* geom1 = Obj->getGeometry(GeoId1); const Part::Geometry* geom2 = Obj->getGeometry(GeoId2); - if (geom1->getTypeId() == Part::GeomLineSegment::getClassTypeId() && - geom2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment* lineSeg1 = static_cast(geom1); - const Part::GeomLineSegment* lineSeg2 = static_cast(geom2); + + if (isLineSegment(*geom1) && isLineSegment(*geom2)) { + auto lineSeg1 = static_cast(geom1); + auto lineSeg2 = static_cast(geom2); // find the two closest line ends Sketcher::PointPos PosId1 = Sketcher::PointPos::none; @@ -2211,7 +2216,6 @@ protected: void createVerticalConstrain(int GeoId1, Sketcher::PointPos PosId1, int GeoId2, Sketcher::PointPos PosId2) { if (selLine.size() == 1) { Gui::cmdAppObjectArgs(sketchgui->getObject(), "addConstraint(Sketcher.Constraint('Vertical',%d)) ", GeoId1); - } else { //2points if (areBothPointsOrSegmentsFixed(Obj, GeoId1, GeoId2)) { @@ -2237,12 +2241,14 @@ protected: numberOfConstraintsCreated++; tryAutoRecompute(Obj); } + void createBlockConstrain(int GeoId) { Gui::cmdAppObjectArgs(sketchgui->getObject(), "addConstraint(Sketcher.Constraint('Block',%d)) ", GeoId); numberOfConstraintsCreated++; tryAutoRecompute(Obj); } + bool isHorizontalVerticalBlock(int GeoId) { const std::vector< Sketcher::Constraint* >& vals = Obj->Constraints.getValues(); @@ -2272,7 +2278,8 @@ protected: } const Part::Geometry* geom = Obj->getGeometry(GeoId3); - if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + + if (isLineSegment(*geom)) { if (GeoId1 == GeoId2 && GeoId2 == GeoId3) { Gui::TranslatedUserWarning(Obj, QObject::tr("Wrong selection"), @@ -2373,7 +2380,6 @@ protected: else { createDistanceConstrain(selPoints[0].GeoId, selPoints[0].PosId, selPoints[1].GeoId, selPoints[1].PosId, onSketchPos); } - } if (addedOrigin) { @@ -2525,10 +2531,10 @@ void CmdSketcherConstrainHorizontal::activated(int iMsg) Sketcher::PointPos PosId; getIdsFromName((*it), Obj, GeoId, PosId); - if (isEdge(GeoId, PosId)) {// it is an edge const Part::Geometry* geo = Obj->getGeometry(GeoId); - if (geo->getTypeId() != Part::GeomLineSegment::getClassTypeId()) { + + if (! isLineSegment(*geo)) { Gui::TranslatedUserWarning(Obj, QObject::tr("Impossible constraint"), QObject::tr("The selected edge is not a line segment.")); @@ -2646,7 +2652,8 @@ void CmdSketcherConstrainHorizontal::applyConstraint(std::vector& sel int CrvId = selSeq.front().GeoId; if (CrvId != -1) { const Part::Geometry* geo = Obj->getGeometry(CrvId); - if (geo->getTypeId() != Part::GeomLineSegment::getClassTypeId()) { + + if (! isLineSegment(*geo)) { Gui::TranslatedUserWarning( Obj, QObject::tr("Impossible constraint"), @@ -2812,10 +2819,10 @@ void CmdSketcherConstrainVertical::activated(int iMsg) Sketcher::PointPos PosId; getIdsFromName((*it), Obj, GeoId, PosId); - if (isEdge(GeoId, PosId)) {// it is an edge const Part::Geometry* geo = Obj->getGeometry(GeoId); - if (geo->getTypeId() != Part::GeomLineSegment::getClassTypeId()) { + + if (! isLineSegment(*geo)) { Gui::TranslatedUserWarning(Obj, QObject::tr("Impossible constraint"), QObject::tr("The selected edge is not a line segment.")); @@ -2933,7 +2940,8 @@ void CmdSketcherConstrainVertical::applyConstraint(std::vector& selSe int CrvId = selSeq.front().GeoId; if (CrvId != -1) { const Part::Geometry* geo = Obj->getGeometry(CrvId); - if (geo->getTypeId() != Part::GeomLineSegment::getClassTypeId()) { + + if (! isLineSegment(*geo)) { Gui::TranslatedUserWarning( Obj, QObject::tr("Impossible constraint"), @@ -3575,7 +3583,6 @@ public: return true; } - if (GeoId1 == GeoEnum::GeoUndef) { GeoId1 = GeoId_temp; PosId1 = PosId_temp; @@ -3743,7 +3750,6 @@ bool CmdSketcherConstrainCoincident::substituteConstraintCombinations(SketchObje } } - return false; } @@ -4099,9 +4105,9 @@ void CmdSketcherConstrainDistance::activated(int iMsg) } Base::Vector3d pnt = Obj->getPoint(GeoId1, PosId1); const Part::Geometry* geom = Obj->getGeometry(GeoId2); - if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment* lineSeg; - lineSeg = static_cast(geom); + + if (isLineSegment(*geom)) { + auto lineSeg = static_cast(geom); Base::Vector3d pnt1 = lineSeg->getStartPoint(); Base::Vector3d pnt2 = lineSeg->getEndPoint(); Base::Vector3d d = pnt2 - pnt1; @@ -4134,9 +4140,8 @@ void CmdSketcherConstrainDistance::activated(int iMsg) return; } - else if (geom->getTypeId() == Part::GeomCircle::getClassTypeId()) { - const Part::GeomCircle* circleSeg; - circleSeg = static_cast(geom); + else if (isCircle(*geom)) { + auto circleSeg = static_cast(geom); Base::Vector3d ct = circleSeg->getCenter(); Base::Vector3d d = ct - pnt; double ActDist = std::abs(d.Length() - circleSeg->getRadius()); @@ -4170,9 +4175,8 @@ void CmdSketcherConstrainDistance::activated(int iMsg) else if (isEdge(GeoId1, PosId1) && isEdge(GeoId2, PosId2)) { const Part::Geometry* geom1 = Obj->getGeometry(GeoId1); const Part::Geometry* geom2 = Obj->getGeometry(GeoId2); - if (geom1->getTypeId() == Part::GeomCircle::getClassTypeId() - && geom2->getTypeId() - == Part::GeomCircle::getClassTypeId()) {// circle to circle distance + + if (isCircle(*geom1) && isCircle(*geom2)) {// circle to circle distance auto circleSeg1 = static_cast(geom1); double radius1 = circleSeg1->getRadius(); Base::Vector3d center1 = circleSeg1->getCenter(); @@ -4221,13 +4225,10 @@ void CmdSketcherConstrainDistance::activated(int iMsg) return; } - else if ((geom1->getTypeId() == Part::GeomCircle::getClassTypeId() - && geom2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) - || (geom1->getTypeId() == Part::GeomLineSegment::getClassTypeId() - && geom2->getTypeId() - == Part::GeomCircle::getClassTypeId())) {// circle to line distance + else if ((isCircle(*geom1) && isLineSegment(*geom2)) + || (isLineSegment(*geom1) && isCircle(*geom2))) {// circle to line distance - if (geom1->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + if (isLineSegment(*geom1)) { std::swap(geom1, geom2);// Assume circle is first std::swap(GeoId1, GeoId2); } @@ -4281,9 +4282,9 @@ void CmdSketcherConstrainDistance::activated(int iMsg) arebothpointsorsegmentsfixed = isPointOrSegmentFixed(Obj, GeoId1); const Part::Geometry* geom = Obj->getGeometry(GeoId1); - if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment* lineSeg; - lineSeg = static_cast(geom); + + if (isLineSegment(*geom)) { + auto lineSeg = static_cast(geom); double ActLength = (lineSeg->getEndPoint() - lineSeg->getStartPoint()).Length(); openCommand(QT_TRANSLATE_NOOP("Command", "Add length constraint")); @@ -4405,9 +4406,9 @@ void CmdSketcherConstrainDistance::applyConstraint(std::vector& selSe arebothpointsorsegmentsfixed = isPointOrSegmentFixed(Obj, GeoId1); const Part::Geometry* geom = Obj->getGeometry(GeoId1); - if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment* lineSeg; - lineSeg = static_cast(geom); + + if (isLineSegment(*geom)) { + auto lineSeg = static_cast(geom); double ActLength = (lineSeg->getEndPoint() - lineSeg->getStartPoint()).Length(); openCommand(QT_TRANSLATE_NOOP("Command", "Add length constraint")); @@ -4428,7 +4429,7 @@ void CmdSketcherConstrainDistance::applyConstraint(std::vector& selSe finishDatumConstraint(this, Obj, true); } } - else if (geom->getTypeId() == Part::GeomCircle::getClassTypeId()) { + else if (isCircle(*geom)) { // allow this selection but do nothing as it needs 2 circles or 1 circle and 1 line } else { @@ -4452,9 +4453,9 @@ void CmdSketcherConstrainDistance::applyConstraint(std::vector& selSe Base::Vector3d pnt = Obj->getPoint(GeoId1, PosId1); const Part::Geometry* geom = Obj->getGeometry(GeoId2); - if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment* lineSeg; - lineSeg = static_cast(geom); + + if (isLineSegment(*geom)) { + auto lineSeg = static_cast(geom); Base::Vector3d pnt1 = lineSeg->getStartPoint(); Base::Vector3d pnt2 = lineSeg->getEndPoint(); Base::Vector3d d = pnt2 - pnt1; @@ -4490,9 +4491,8 @@ void CmdSketcherConstrainDistance::applyConstraint(std::vector& selSe GeoId2 = selSeq.at(1).GeoId; const Part::Geometry* geom1 = Obj->getGeometry(GeoId1); const Part::Geometry* geom2 = Obj->getGeometry(GeoId2); - if (geom1->getTypeId() == Part::GeomCircle::getClassTypeId() - && geom2->getTypeId() - == Part::GeomCircle::getClassTypeId()) {// circle to circle distance + + if (isCircle(*geom1) && isCircle(*geom2)) {// circle to circle distance auto circleSeg1 = static_cast(geom1); double radius1 = circleSeg1->getRadius(); Base::Vector3d center1 = circleSeg1->getCenter(); @@ -4947,7 +4947,8 @@ void CmdSketcherConstrainDistanceX::activated(int iMsg) arebothpointsorsegmentsfixed = isPointOrSegmentFixed(Obj, GeoId1); const Part::Geometry* geom = Obj->getGeometry(GeoId1); - if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + + if (isLineSegment(*geom)) { // convert to as if two endpoints of the line have been selected PosId1 = Sketcher::PointPos::start; GeoId2 = GeoId1; @@ -5017,7 +5018,6 @@ void CmdSketcherConstrainDistanceX::activated(int iMsg) static_cast(PosId1), ActX); - if (arebothpointsorsegmentsfixed || constraintCreationMode == Reference) { // it is a constraint on a external line, make it non-driving const std::vector& ConStr = Obj->Constraints.getValues(); @@ -5039,7 +5039,6 @@ void CmdSketcherConstrainDistanceX::activated(int iMsg) Obj, QObject::tr("Wrong selection"), QObject::tr("Select exactly one line or up to two points from the sketch.")); - return; } @@ -5070,7 +5069,8 @@ void CmdSketcherConstrainDistanceX::applyConstraint(std::vector& selS PosId2 = Sketcher::PointPos::end; const Part::Geometry* geom = Obj->getGeometry(GeoId1); - if (geom->getTypeId() != Part::GeomLineSegment::getClassTypeId()) { + + if (! isLineSegment(*geom)) { Gui::TranslatedUserWarning( Obj, QObject::tr("Wrong selection"), @@ -5248,7 +5248,8 @@ void CmdSketcherConstrainDistanceY::activated(int iMsg) arebothpointsorsegmentsfixed = isPointOrSegmentFixed(Obj, GeoId1); const Part::Geometry* geom = Obj->getGeometry(GeoId1); - if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + + if (isLineSegment(*geom)) { // convert to as if two endpoints of the line have been selected PosId1 = Sketcher::PointPos::start; GeoId2 = GeoId1; @@ -5339,7 +5340,6 @@ void CmdSketcherConstrainDistanceY::activated(int iMsg) Obj, QObject::tr("Wrong selection"), QObject::tr("Select exactly one line or up to two points from the sketch.")); - return; } @@ -5370,7 +5370,8 @@ void CmdSketcherConstrainDistanceY::applyConstraint(std::vector& selS PosId2 = Sketcher::PointPos::end; const Part::Geometry* geom = Obj->getGeometry(GeoId1); - if (geom->getTypeId() != Part::GeomLineSegment::getClassTypeId()) { + + if (! isLineSegment(*geom)) { Gui::TranslatedUserWarning( Obj, QObject::tr("Wrong selection"), @@ -5541,11 +5542,11 @@ void CmdSketcherConstrainParallel::activated(int iMsg) // Check that the curve is a line segment const Part::Geometry* geo = Obj->getGeometry(GeoId); - if (geo->getTypeId() != Part::GeomLineSegment::getClassTypeId()) { + + if (! isLineSegment(*geo)) { Gui::TranslatedUserWarning(Obj, QObject::tr("Wrong selection"), QObject::tr("The selected edge is not a valid line.")); - return; } ids.push_back(GeoId); @@ -5583,9 +5584,7 @@ void CmdSketcherConstrainParallel::applyConstraint(std::vector& selSe int GeoId1 = selSeq.at(0).GeoId, GeoId2 = selSeq.at(1).GeoId; // Check that the curves are line segments - if (Obj->getGeometry(GeoId1)->getTypeId() != Part::GeomLineSegment::getClassTypeId() - || Obj->getGeometry(GeoId2)->getTypeId() - != Part::GeomLineSegment::getClassTypeId()) { + if (! isLineSegment(*(Obj->getGeometry(GeoId1))) || ! isLineSegment(*(Obj->getGeometry(GeoId2)))) { Gui::TranslatedUserWarning(Obj, QObject::tr("Wrong selection"), QObject::tr("The selected edge is not a valid line.")); @@ -5801,7 +5800,6 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) QObject::tr("With 3 objects, there must be 2 curves and 1 point.")); } else if (SubNames.size() == 2) { - if (isVertex(GeoId1, PosId1) && isVertex(GeoId2, PosId2)) {// endpoint-to-endpoint perpendicularity @@ -5818,11 +5816,8 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) const Part::Geometry* geom1 = Obj->getGeometry(GeoId1); const Part::Geometry* geom2 = Obj->getGeometry(GeoId2); - if (geom1 && geom2 - && (geom1->getTypeId() == Part::GeomBSplineCurve::getClassTypeId() - || geom2->getTypeId() == Part::GeomBSplineCurve::getClassTypeId())) { - - if (geom1->getTypeId() != Part::GeomBSplineCurve::getClassTypeId()) { + if (geom1 && geom2 && (isBSplineCurve(*geom1) || isBSplineCurve(*geom2))) { + if (! isBSplineCurve(*geom1)) { std::swap(GeoId1, GeoId2); std::swap(PosId1, PosId2); } @@ -5860,7 +5855,7 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) const Part::Geometry* geom2 = Obj->getGeometry(GeoId2); - if (geom2 && geom2->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) { + if (geom2 && isBSplineCurve(*geom2)) { // unsupported until normal to B-spline at any point implemented. Gui::TranslatedUserWarning( Obj, @@ -5898,8 +5893,7 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) return; } - if (geo1->getTypeId() != Part::GeomLineSegment::getClassTypeId() - && geo2->getTypeId() != Part::GeomLineSegment::getClassTypeId()) { + if (! isLineSegment(*geo1) && ! isLineSegment(*geo2)) { Gui::TranslatedUserWarning( Obj, QObject::tr("Wrong selection"), @@ -5907,9 +5901,7 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) return; } - if (geo1->getTypeId() == Part::GeomBSplineCurve::getClassTypeId() - || geo2->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) { - + if (isBSplineCurve(*geo1) || isBSplineCurve(*geo2)) { // unsupported until tangent to B-spline at any point implemented. Gui::TranslatedUserWarning( Obj, @@ -5918,7 +5910,7 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) return; } - if (geo1->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + if (isLineSegment(*geo1)) { std::swap(GeoId1, GeoId2); } @@ -5934,11 +5926,7 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) geo1 = Obj->getGeometry(GeoId1); geo2 = Obj->getGeometry(GeoId2); - if (geo1->getTypeId() == Part::GeomEllipse::getClassTypeId() - || geo1->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() - || geo1->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId() - || geo1->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { - + if (isEllipse(*geo1) || isArcOfEllipse(*geo1) || isArcOfHyperbola(*geo1) || isArcOfParabola(*geo1)) { Base::Vector3d center; Base::Vector3d majdir; Base::Vector3d focus; @@ -5946,39 +5934,32 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) double minord = 0; double phi = 0; - if (geo1->getTypeId() == Part::GeomEllipse::getClassTypeId()) { - const Part::GeomEllipse* ellipse = static_cast(geo1); - + if (isEllipse(*geo1)) { + auto ellipse = static_cast(geo1); center = ellipse->getCenter(); majord = ellipse->getMajorRadius(); minord = ellipse->getMinorRadius(); majdir = ellipse->getMajorAxisDir(); phi = atan2(majdir.y, majdir.x); } - else if (geo1->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()) { - const Part::GeomArcOfEllipse* aoe = - static_cast(geo1); - + else if (isArcOfEllipse(*geo1)) { + auto aoe = static_cast(geo1); center = aoe->getCenter(); majord = aoe->getMajorRadius(); minord = aoe->getMinorRadius(); majdir = aoe->getMajorAxisDir(); phi = atan2(majdir.y, majdir.x); } - else if (geo1->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId()) { - const Part::GeomArcOfHyperbola* aoh = - static_cast(geo1); - + else if (isArcOfHyperbola(*geo1)) { + auto aoh = static_cast(geo1); center = aoh->getCenter(); majord = aoh->getMajorRadius(); minord = aoh->getMinorRadius(); majdir = aoh->getMajorAxisDir(); phi = atan2(majdir.y, majdir.x); } - else if (geo1->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { - const Part::GeomArcOfParabola* aop = - static_cast(geo1); - + else if (isArcOfParabola(*geo1)) { + auto aop = static_cast(geo1); center = aop->getCenter(); focus = aop->getFocus(); } @@ -5988,7 +5969,7 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) Base::Vector3d point1 = line->getStartPoint(); Base::Vector3d PoO; - if (geo1->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId()) { + if (isArcOfHyperbola(*geo1)) { double df = sqrt(majord * majord + minord * minord); Base::Vector3d direction = point1 - (center + majdir * df);// towards the focus double tapprox = atan2(direction.y, direction.x) - phi; @@ -5999,7 +5980,7 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) + minord * sinh(tapprox) * cos(phi), 0); } - else if (geo1->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { + else if (isArcOfParabola(*geo1)) { Base::Vector3d direction = point1 - focus;// towards the focus PoO = point1 + direction / 2; @@ -6039,7 +6020,6 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) GeoIdPoint, static_cast(Sketcher::PointPos::start), GeoId2); - // add constraint: Perpendicular-via-point Gui::cmdAppObjectArgs( Obj, @@ -6114,8 +6094,7 @@ void CmdSketcherConstrainPerpendicular::applyConstraint(std::vector& return; } - if (geo1->getTypeId() != Part::GeomLineSegment::getClassTypeId() - && geo2->getTypeId() != Part::GeomLineSegment::getClassTypeId()) { + if (! isLineSegment(*geo1) && ! isLineSegment(*geo2)) { Gui::TranslatedUserWarning( Obj, QObject::tr("Wrong selection"), @@ -6123,19 +6102,16 @@ void CmdSketcherConstrainPerpendicular::applyConstraint(std::vector& return; } - if (geo1->getTypeId() == Part::GeomBSplineCurve::getClassTypeId() - || geo2->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) { - + if (isBSplineCurve(*geo1) || isBSplineCurve(*geo2)) { // unsupported until tangent to B-spline at any point implemented. Gui::TranslatedUserWarning( Obj, QObject::tr("Wrong selection"), QObject::tr("Perpendicular to B-spline edge currently unsupported.")); - return; } - if (geo1->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + if (isLineSegment(*geo1)) { std::swap(GeoId1, GeoId2); } @@ -6151,11 +6127,7 @@ void CmdSketcherConstrainPerpendicular::applyConstraint(std::vector& geo1 = Obj->getGeometry(GeoId1); geo2 = Obj->getGeometry(GeoId2); - if (geo1->getTypeId() == Part::GeomEllipse::getClassTypeId() - || geo1->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() - || geo1->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId() - || geo1->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { - + if (isEllipse(*geo1) || isArcOfEllipse(*geo1) || isArcOfHyperbola(*geo1) || isArcOfParabola(*geo1)) { Base::Vector3d center; Base::Vector3d majdir; Base::Vector3d focus; @@ -6163,39 +6135,32 @@ void CmdSketcherConstrainPerpendicular::applyConstraint(std::vector& double minord = 0; double phi = 0; - if (geo1->getTypeId() == Part::GeomEllipse::getClassTypeId()) { - const Part::GeomEllipse* ellipse = static_cast(geo1); - + if (isEllipse(*geo1)) { + auto ellipse = static_cast(geo1); center = ellipse->getCenter(); majord = ellipse->getMajorRadius(); minord = ellipse->getMinorRadius(); majdir = ellipse->getMajorAxisDir(); phi = atan2(majdir.y, majdir.x); } - else if (geo1->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()) { - const Part::GeomArcOfEllipse* aoe = - static_cast(geo1); - + else if (isArcOfEllipse(*geo1)) { + auto aoe = static_cast(geo1); center = aoe->getCenter(); majord = aoe->getMajorRadius(); minord = aoe->getMinorRadius(); majdir = aoe->getMajorAxisDir(); phi = atan2(majdir.y, majdir.x); } - else if (geo1->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId()) { - const Part::GeomArcOfHyperbola* aoh = - static_cast(geo1); - + else if (isArcOfHyperbola(*geo1)) { + auto aoh = static_cast(geo1); center = aoh->getCenter(); majord = aoh->getMajorRadius(); minord = aoh->getMinorRadius(); majdir = aoh->getMajorAxisDir(); phi = atan2(majdir.y, majdir.x); } - else if (geo1->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { - const Part::GeomArcOfParabola* aop = - static_cast(geo1); - + else if (isArcOfParabola(*geo1)) { + auto aop = static_cast(geo1); center = aop->getCenter(); focus = aop->getFocus(); } @@ -6205,7 +6170,7 @@ void CmdSketcherConstrainPerpendicular::applyConstraint(std::vector& Base::Vector3d point1 = line->getStartPoint(); Base::Vector3d PoO; - if (geo1->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId()) { + if (isArcOfHyperbola(*geo1)) { double df = sqrt(majord * majord + minord * minord); Base::Vector3d direction = point1 - (center + majdir * df);// towards the focus double tapprox = atan2(direction.y, direction.x) - phi; @@ -6216,7 +6181,7 @@ void CmdSketcherConstrainPerpendicular::applyConstraint(std::vector& + minord * sinh(tapprox) * cos(phi), 0); } - else if (geo1->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { + else if (isArcOfParabola(*geo1)) { Base::Vector3d direction = point1 - focus;// towards the focus PoO = point1 + direction / 2; @@ -6275,7 +6240,6 @@ void CmdSketcherConstrainPerpendicular::applyConstraint(std::vector& Gui::Command::abortCommand(); } - tryAutoRecompute(Obj); getSelection().clearSelection(); @@ -6335,7 +6299,6 @@ void CmdSketcherConstrainPerpendicular::applyConstraint(std::vector& Obj, QObject::tr("Wrong selection"), QObject::tr("Select an edge that is not a B-spline weight.")); - return; } @@ -6557,7 +6520,6 @@ void CmdSketcherConstrainTangent::activated(int iMsg) Gui::TranslatedUserWarning(Obj, QObject::tr("Wrong selection"), QObject::tr("Wrong number of selected objects!")); - return; } @@ -6592,7 +6554,6 @@ void CmdSketcherConstrainTangent::activated(int iMsg) Obj, QObject::tr("Wrong selection"), QObject::tr("Select an edge that is not a B-spline weight.")); - return; } @@ -6671,13 +6632,13 @@ void CmdSketcherConstrainTangent::activated(int iMsg) if (isBsplineKnot(Obj, GeoId1)) { const Part::Geometry* geom2 = Obj->getGeometry(GeoId2); - if (!geom2 || geom2->getTypeId() != Part::GeomLineSegment::getClassTypeId()) { + + if (! geom2 || ! isLineSegment(*geom2)) { Gui::TranslatedUserWarning( Obj, QObject::tr("Wrong selection"), QObject::tr("Tangent constraint at B-spline knot is only supported " "with lines!")); - return; } } @@ -6686,7 +6647,6 @@ void CmdSketcherConstrainTangent::activated(int iMsg) Obj, QObject::tr("Wrong selection"), QObject::tr("Cannot add a tangency constraint at an unconnected point!")); - return; } } @@ -6710,7 +6670,8 @@ void CmdSketcherConstrainTangent::activated(int iMsg) if (isSimpleVertex(Obj, GeoId1, PosId1)) { if (isBsplineKnot(Obj, GeoId1)) { const Part::Geometry* geom2 = Obj->getGeometry(GeoId2); - if (!geom2 || geom2->getTypeId() != Part::GeomLineSegment::getClassTypeId()) { + + if (!geom2 || ! isLineSegment(*geom2)) { Gui::TranslatedUserWarning( Obj, QObject::tr("Wrong selection"), @@ -6724,20 +6685,18 @@ void CmdSketcherConstrainTangent::activated(int iMsg) Obj, QObject::tr("Wrong selection"), QObject::tr("Cannot add a tangency constraint at an unconnected point!")); - return; } } const Part::Geometry* geom2 = Obj->getGeometry(GeoId2); - if (geom2 && geom2->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) { + if (geom2 && isBSplineCurve(*geom2)) { // unsupported until tangent to B-spline at any point implemented. Gui::TranslatedUserWarning( Obj, QObject::tr("Wrong selection"), QObject::tr("Tangency to B-spline edge currently unsupported.")); - return; } @@ -6746,7 +6705,6 @@ void CmdSketcherConstrainTangent::activated(int iMsg) Obj, QObject::tr("Wrong selection"), QObject::tr("Select an edge that is not a B-spline weight.")); - return; } @@ -6768,16 +6726,12 @@ void CmdSketcherConstrainTangent::activated(int iMsg) const Part::Geometry* geom1 = Obj->getGeometry(GeoId1); const Part::Geometry* geom2 = Obj->getGeometry(GeoId2); - if (geom1 && geom2 - && (geom1->getTypeId() == Part::GeomBSplineCurve::getClassTypeId() - || geom2->getTypeId() == Part::GeomBSplineCurve::getClassTypeId())) { - + if (geom1 && geom2 && (isBSplineCurve(*geom1) || isBSplineCurve(*geom2))) { // unsupported until tangent to B-spline at any point implemented. Gui::TranslatedUserWarning( Obj, QObject::tr("Wrong selection"), QObject::tr("Tangency to B-spline edge currently unsupported.")); - return; } @@ -6786,7 +6740,6 @@ void CmdSketcherConstrainTangent::activated(int iMsg) Obj, QObject::tr("Wrong selection"), QObject::tr("Select an edge that is not a B-spline weight.")); - return; } @@ -6798,11 +6751,8 @@ void CmdSketcherConstrainTangent::activated(int iMsg) return; } - if (geom1 && geom2 - && (geom1->getTypeId() == Part::GeomEllipse::getClassTypeId() - || geom2->getTypeId() == Part::GeomEllipse::getClassTypeId())) { - - if (geom1->getTypeId() != Part::GeomEllipse::getClassTypeId()) { + if (geom1 && geom2 && (isEllipse(*geom1) || isEllipse(*geom2))) { + if (! isEllipse(*geom1)) { std::swap(GeoId1, GeoId2); } @@ -6810,11 +6760,7 @@ void CmdSketcherConstrainTangent::activated(int iMsg) geom1 = Obj->getGeometry(GeoId1); geom2 = Obj->getGeometry(GeoId2); - if (geom2->getTypeId() == Part::GeomEllipse::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() - || geom2->getTypeId() == Part::GeomCircle::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - + if (isEllipse(*geom2) || isArcOfEllipse(*geom2) || isCircle(*geom2) || isArcOfCircle(*geom2)) { Gui::Command::openCommand( QT_TRANSLATE_NOOP("Command", "Add tangent constraint point")); makeTangentToEllipseviaNewPoint(Obj, @@ -6825,7 +6771,7 @@ void CmdSketcherConstrainTangent::activated(int iMsg) getSelection().clearSelection(); return; } - else if (geom2->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId()) { + else if (isArcOfHyperbola(*geom2)) { Gui::Command::openCommand( QT_TRANSLATE_NOOP("Command", "Add tangent constraint point")); makeTangentToArcOfHyperbolaviaNewPoint( @@ -6837,7 +6783,7 @@ void CmdSketcherConstrainTangent::activated(int iMsg) getSelection().clearSelection(); return; } - else if (geom2->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { + else if (isArcOfParabola(*geom2)) { Gui::Command::openCommand( QT_TRANSLATE_NOOP("Command", "Add tangent constraint point")); makeTangentToArcOfParabolaviaNewPoint( @@ -6850,11 +6796,8 @@ void CmdSketcherConstrainTangent::activated(int iMsg) return; } } - else if (geom1 && geom2 - && (geom1->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId())) { - - if (geom1->getTypeId() != Part::GeomArcOfEllipse::getClassTypeId()) { + else if (geom1 && geom2 && (isArcOfEllipse(*geom1) || isArcOfEllipse(*geom2))) { + if (! isArcOfEllipse(*geom1)) { std::swap(GeoId1, GeoId2); } @@ -6862,11 +6805,8 @@ void CmdSketcherConstrainTangent::activated(int iMsg) geom1 = Obj->getGeometry(GeoId1); geom2 = Obj->getGeometry(GeoId2); - if (geom2->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() - || geom2->getTypeId() == Part::GeomCircle::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfCircle::getClassTypeId() - || geom2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + if (isArcOfHyperbola(*geom2) || isArcOfEllipse(*geom2) + || isCircle(*geom2) || isArcOfCircle(*geom2) || isLineSegment(*geom2)) { Gui::Command::openCommand( QT_TRANSLATE_NOOP("Command", "Add tangent constraint point")); @@ -6880,7 +6820,7 @@ void CmdSketcherConstrainTangent::activated(int iMsg) getSelection().clearSelection(); return; } - else if (geom2->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { + else if (isArcOfParabola(*geom2)) { Gui::Command::openCommand( QT_TRANSLATE_NOOP("Command", "Add tangent constraint point")); makeTangentToArcOfParabolaviaNewPoint( @@ -6893,11 +6833,8 @@ void CmdSketcherConstrainTangent::activated(int iMsg) return; } } - else if (geom1 && geom2 - && (geom1->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId())) { - - if (geom1->getTypeId() != Part::GeomArcOfHyperbola::getClassTypeId()) { + else if (geom1 && geom2 && (isArcOfHyperbola(*geom1) || isArcOfHyperbola(*geom2))) { + if (! isArcOfHyperbola(*geom1)) { std::swap(GeoId1, GeoId2); } @@ -6905,11 +6842,8 @@ void CmdSketcherConstrainTangent::activated(int iMsg) geom1 = Obj->getGeometry(GeoId1); geom2 = Obj->getGeometry(GeoId2); - if (geom2->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() - || geom2->getTypeId() == Part::GeomCircle::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfCircle::getClassTypeId() - || geom2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + if (isArcOfHyperbola(*geom2) || isArcOfEllipse(*geom2) || isCircle(*geom2) + || isArcOfCircle(*geom2) || isLineSegment(*geom2)) { Gui::Command::openCommand( QT_TRANSLATE_NOOP("Command", "Add tangent constraint point")); @@ -6922,7 +6856,7 @@ void CmdSketcherConstrainTangent::activated(int iMsg) getSelection().clearSelection(); return; } - else if (geom2->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { + else if (isArcOfParabola(*geom2)) { Gui::Command::openCommand( QT_TRANSLATE_NOOP("Command", "Add tangent constraint point")); makeTangentToArcOfParabolaviaNewPoint( @@ -6935,11 +6869,8 @@ void CmdSketcherConstrainTangent::activated(int iMsg) return; } } - else if (geom1 && geom2 - && (geom1->getTypeId() == Part::GeomArcOfParabola::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfParabola::getClassTypeId())) { - - if (geom1->getTypeId() != Part::GeomArcOfParabola::getClassTypeId()) { + else if (geom1 && geom2 && (isArcOfParabola(*geom1) || isArcOfParabola(*geom2))) { + if (! isArcOfParabola(*geom1)) { std::swap(GeoId1, GeoId2); } @@ -6947,12 +6878,9 @@ void CmdSketcherConstrainTangent::activated(int iMsg) geom1 = Obj->getGeometry(GeoId1); geom2 = Obj->getGeometry(GeoId2); - if (geom2->getTypeId() == Part::GeomArcOfParabola::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() - || geom2->getTypeId() == Part::GeomCircle::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfCircle::getClassTypeId() - || geom2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + if (isArcOfParabola(*geom2) || isArcOfHyperbola(*geom2) + || isArcOfEllipse(*geom2) || isCircle(*geom2) + || isArcOfCircle(*geom2) || isLineSegment(*geom2)) { Gui::Command::openCommand( QT_TRANSLATE_NOOP("Command", "Add tangent constraint point")); @@ -7011,16 +6939,12 @@ void CmdSketcherConstrainTangent::applyConstraint(std::vector& selSeq const Part::Geometry* geom1 = Obj->getGeometry(GeoId1); const Part::Geometry* geom2 = Obj->getGeometry(GeoId2); - if (geom1 && geom2 - && (geom1->getTypeId() == Part::GeomBSplineCurve::getClassTypeId() - || geom2->getTypeId() == Part::GeomBSplineCurve::getClassTypeId())) { - + if (geom1 && geom2 && (isBSplineCurve(*geom1) || isBSplineCurve(*geom2))) { // unsupported until tangent to B-spline at any point implemented. Gui::TranslatedUserWarning( Obj, QObject::tr("Wrong selection"), QObject::tr("Tangency to B-spline edge currently unsupported.")); - return; } @@ -7029,7 +6953,6 @@ void CmdSketcherConstrainTangent::applyConstraint(std::vector& selSeq Obj, QObject::tr("Wrong selection"), QObject::tr("Select an edge that is not a B-spline weight.")); - return; } @@ -7041,11 +6964,8 @@ void CmdSketcherConstrainTangent::applyConstraint(std::vector& selSeq return; } - if (geom1 && geom2 - && (geom1->getTypeId() == Part::GeomEllipse::getClassTypeId() - || geom2->getTypeId() == Part::GeomEllipse::getClassTypeId())) { - - if (geom1->getTypeId() != Part::GeomEllipse::getClassTypeId()) { + if (geom1 && geom2 && (isEllipse(*geom1) || isEllipse(*geom2))) { + if (! isEllipse(*geom1)) { std::swap(GeoId1, GeoId2); } @@ -7053,10 +6973,8 @@ void CmdSketcherConstrainTangent::applyConstraint(std::vector& selSeq geom1 = Obj->getGeometry(GeoId1); geom2 = Obj->getGeometry(GeoId2); - if (geom2->getTypeId() == Part::GeomEllipse::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() - || geom2->getTypeId() == Part::GeomCircle::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { + if (isEllipse(*geom2) || isArcOfEllipse(*geom2) + || isCircle(*geom2) || isArcOfCircle(*geom2)) { Gui::Command::openCommand( QT_TRANSLATE_NOOP("Command", "Add tangent constraint point")); @@ -7068,7 +6986,7 @@ void CmdSketcherConstrainTangent::applyConstraint(std::vector& selSeq getSelection().clearSelection(); return; } - else if (geom2->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId()) { + else if (isArcOfHyperbola(*geom2)) { Gui::Command::openCommand( QT_TRANSLATE_NOOP("Command", "Add tangent constraint point")); makeTangentToArcOfHyperbolaviaNewPoint( @@ -7080,7 +6998,7 @@ void CmdSketcherConstrainTangent::applyConstraint(std::vector& selSeq getSelection().clearSelection(); return; } - else if (geom2->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { + else if (isArcOfParabola(*geom2)) { Gui::Command::openCommand( QT_TRANSLATE_NOOP("Command", "Add tangent constraint point")); makeTangentToArcOfParabolaviaNewPoint( @@ -7093,11 +7011,8 @@ void CmdSketcherConstrainTangent::applyConstraint(std::vector& selSeq return; } } - else if (geom1 && geom2 - && (geom1->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId())) { - - if (geom1->getTypeId() != Part::GeomArcOfHyperbola::getClassTypeId()) { + else if (geom1 && geom2 && (isArcOfHyperbola(*geom1) || isArcOfHyperbola(*geom2))) { + if (! isArcOfHyperbola(*geom1)) { std::swap(GeoId1, GeoId2); } @@ -7105,11 +7020,8 @@ void CmdSketcherConstrainTangent::applyConstraint(std::vector& selSeq geom1 = Obj->getGeometry(GeoId1); geom2 = Obj->getGeometry(GeoId2); - if (geom2->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() - || geom2->getTypeId() == Part::GeomCircle::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfCircle::getClassTypeId() - || geom2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + if (isArcOfHyperbola(*geom2) || isArcOfEllipse(*geom2) || isCircle(*geom2) + || isArcOfCircle(*geom2) || isLineSegment(*geom2)) { Gui::Command::openCommand( QT_TRANSLATE_NOOP("Command", "Add tangent constraint point")); @@ -7122,7 +7034,7 @@ void CmdSketcherConstrainTangent::applyConstraint(std::vector& selSeq getSelection().clearSelection(); return; } - else if (geom2->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { + else if (isArcOfParabola(*geom2)) { Gui::Command::openCommand( QT_TRANSLATE_NOOP("Command", "Add tangent constraint point")); makeTangentToArcOfParabolaviaNewPoint( @@ -7135,11 +7047,8 @@ void CmdSketcherConstrainTangent::applyConstraint(std::vector& selSeq return; } } - else if (geom1 && geom2 - && (geom1->getTypeId() == Part::GeomArcOfParabola::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfParabola::getClassTypeId())) { - - if (geom1->getTypeId() != Part::GeomArcOfParabola::getClassTypeId()) { + else if (geom1 && geom2 && (isArcOfParabola(*geom1) || isArcOfParabola(*geom2))) { + if (! isArcOfParabola(*geom1)) { std::swap(GeoId1, GeoId2); } @@ -7147,12 +7056,8 @@ void CmdSketcherConstrainTangent::applyConstraint(std::vector& selSeq geom1 = Obj->getGeometry(GeoId1); geom2 = Obj->getGeometry(GeoId2); - if (geom2->getTypeId() == Part::GeomArcOfParabola::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() - || geom2->getTypeId() == Part::GeomCircle::getClassTypeId() - || geom2->getTypeId() == Part::GeomArcOfCircle::getClassTypeId() - || geom2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + if (isArcOfParabola(*geom2) || isArcOfHyperbola(*geom2) || isArcOfEllipse(*geom2) + || isCircle(*geom2) || isArcOfCircle(*geom2) || isLineSegment(*geom2)) { Gui::Command::openCommand( QT_TRANSLATE_NOOP("Command", "Add tangent constraint point")); @@ -7222,7 +7127,6 @@ void CmdSketcherConstrainTangent::applyConstraint(std::vector& selSeq Obj, QObject::tr("Wrong selection"), QObject::tr("Cannot add a tangency constraint at an unconnected point!")); - return; } @@ -7230,11 +7134,8 @@ void CmdSketcherConstrainTangent::applyConstraint(std::vector& selSeq const Part::Geometry* geom1 = Obj->getGeometry(GeoId1); const Part::Geometry* geom2 = Obj->getGeometry(GeoId2); - if (geom1 && geom2 - && (geom1->getTypeId() == Part::GeomBSplineCurve::getClassTypeId() - || geom2->getTypeId() == Part::GeomBSplineCurve::getClassTypeId())) { - - if (geom1->getTypeId() != Part::GeomBSplineCurve::getClassTypeId()) { + if (geom1 && geom2 && (isBSplineCurve(*geom1) || isBSplineCurve(*geom2))) { + if (! isBSplineCurve(*geom1)) { std::swap(GeoId1, GeoId2); std::swap(PosId1, PosId2); } @@ -7271,7 +7172,6 @@ void CmdSketcherConstrainTangent::applyConstraint(std::vector& selSeq Obj, QObject::tr("Wrong selection"), QObject::tr("Select an edge that is not a B-spline weight.")); - return; } @@ -7432,8 +7332,8 @@ void CmdSketcherConstrainRadius::activated(int iMsg) const Part::Geometry* geom = Obj->getGeometry(GeoId); - if (geom && geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle* arc = static_cast(geom); + if (geom && isArcOfCircle(*geom)) { + auto arc = static_cast(geom); double radius = arc->getRadius(); if (issegmentfixed) { @@ -7445,8 +7345,8 @@ void CmdSketcherConstrainRadius::activated(int iMsg) nonpoles = true; } - else if (geom && geom->getTypeId() == Part::GeomCircle::getClassTypeId()) { - const Part::GeomCircle* circle = static_cast(geom); + else if (geom && isCircle(*geom)) { + auto circle = static_cast(geom); double radius = circle->getRadius(); if (issegmentfixed) { @@ -7470,7 +7370,6 @@ void CmdSketcherConstrainRadius::activated(int iMsg) Obj, QObject::tr("Wrong selection"), QObject::tr("Select one or more arcs or circles from the sketch.")); - return; } @@ -7480,7 +7379,6 @@ void CmdSketcherConstrainRadius::activated(int iMsg) QObject::tr("Wrong selection"), QObject::tr("Select either only one or more B-Spline poles or only one or more arcs or " "circles from the sketch, but not mixed.")); - return; } @@ -7521,7 +7419,6 @@ void CmdSketcherConstrainRadius::activated(int iMsg) "False"); } - finishDatumConstraint(this, Obj, false, externalGeoIdRadiusMap.size()); commitNeeded = true; @@ -7623,12 +7520,13 @@ void CmdSketcherConstrainRadius::applyConstraint(std::vector& selSeq, case 1:// {SelExternalEdge} { const Part::Geometry* geom = Obj->getGeometry(GeoId); - if (geom && geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle* arc = static_cast(geom); + + if (geom && isArcOfCircle(*geom)) { + auto arc = static_cast(geom); radius = arc->getRadius(); } - else if (geom && geom->getTypeId() == Part::GeomCircle::getClassTypeId()) { - const Part::GeomCircle* circle = static_cast(geom); + else if (geom && isCircle(*geom)) { + auto circle = static_cast(geom); radius = circle->getRadius(); } else { @@ -7636,7 +7534,6 @@ void CmdSketcherConstrainRadius::applyConstraint(std::vector& selSeq, Obj, QObject::tr("Wrong selection"), QObject::tr("Constraint only applies to arcs or circles.")); - return; } @@ -7770,7 +7667,6 @@ void CmdSketcherConstrainDiameter::activated(int iMsg) Obj, QObject::tr("Wrong selection"), QObject::tr("Select one or more arcs or circles from the sketch.")); - return; } @@ -7797,8 +7693,8 @@ void CmdSketcherConstrainDiameter::activated(int iMsg) const Part::Geometry* geom = Obj->getGeometry(GeoId); - if (geom && geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle* arc = static_cast(geom); + if (geom && isArcOfCircle(*geom)) { + auto arc = static_cast(geom); double radius = arc->getRadius(); if (issegmentfixed) { @@ -7808,8 +7704,8 @@ void CmdSketcherConstrainDiameter::activated(int iMsg) geoIdDiameterMap.emplace_back(GeoId, 2 * radius); } } - else if (geom && geom->getTypeId() == Part::GeomCircle::getClassTypeId()) { - const Part::GeomCircle* circle = static_cast(geom); + else if (geom && isCircle(*geom)) { + auto circle = static_cast(geom); double radius = circle->getRadius(); if (isBsplinePole(geom)) { @@ -7835,7 +7731,6 @@ void CmdSketcherConstrainDiameter::activated(int iMsg) Obj, QObject::tr("Wrong selection"), QObject::tr("Select one or more arcs or circles from the sketch.")); - return; } @@ -7866,7 +7761,6 @@ void CmdSketcherConstrainDiameter::activated(int iMsg) finishDatumConstraint(this, Obj, false, externalGeoIdDiameterMap.size()); - commitNeeded = true; updateNeeded = true; } @@ -7949,12 +7843,13 @@ void CmdSketcherConstrainDiameter::applyConstraint(std::vector& selSe case 1:// {SelExternalEdge} { const Part::Geometry* geom = Obj->getGeometry(GeoId); - if (geom && geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle* arc = static_cast(geom); + + if (geom && isArcOfCircle(*geom)) { + auto arc = static_cast(geom); diameter = 2 * arc->getRadius(); } - else if (geom && geom->getTypeId() == Part::GeomCircle::getClassTypeId()) { - const Part::GeomCircle* circle = static_cast(geom); + else if (geom && isCircle(*geom)) { + auto circle = static_cast(geom); diameter = 2 * circle->getRadius(); } else { @@ -7962,7 +7857,6 @@ void CmdSketcherConstrainDiameter::applyConstraint(std::vector& selSe Obj, QObject::tr("Wrong selection"), QObject::tr("Constraint only applies to arcs or circles.")); - return; } @@ -7971,7 +7865,6 @@ void CmdSketcherConstrainDiameter::applyConstraint(std::vector& selSe Obj, QObject::tr("Wrong selection"), QObject::tr("Select an edge that is not a B-spline weight.")); - return; } @@ -8094,7 +7987,6 @@ void CmdSketcherConstrainRadiam::activated(int iMsg) Obj, QObject::tr("Wrong selection"), QObject::tr("Select one or more arcs or circles from the sketch.")); - return; } @@ -8125,13 +8017,13 @@ void CmdSketcherConstrainRadiam::activated(int iMsg) const Part::Geometry* geom = Obj->getGeometry(GeoId); double radius; - if (geom && geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle* arcir = static_cast(geom); + if (geom && isArcOfCircle(*geom)) { + auto arcir = static_cast(geom); radius = arcir->getRadius(); nonpoles = true; } - else if (geom && geom->getTypeId() == Part::GeomCircle::getClassTypeId()) { - const Part::GeomCircle* arcir = static_cast(geom); + else if (geom && isCircle(*geom)) { + auto arcir = static_cast(geom); radius = arcir->getRadius(); if (isBsplinePole(geom)) { poles = true; @@ -8157,7 +8049,6 @@ void CmdSketcherConstrainRadiam::activated(int iMsg) Obj, QObject::tr("Wrong selection"), QObject::tr("Select one or more arcs or circles from the sketch.")); - return; } @@ -8167,7 +8058,6 @@ void CmdSketcherConstrainRadiam::activated(int iMsg) QObject::tr("Wrong selection"), QObject::tr("Select either only one or more B-Spline poles or only one or more arcs or " "circles from the sketch, but not mixed.")); - return; } @@ -8184,8 +8074,7 @@ void CmdSketcherConstrainRadiam::activated(int iMsg) for (std::vector>::iterator it = externalGeoIdRadiamMap.begin(); it != externalGeoIdRadiamMap.end(); ++it) { - if (Obj->getGeometry(it->first)->getTypeId() - == Part::GeomArcOfCircle::getClassTypeId()) { + if (isArcOfCircle(*(Obj->getGeometry(it->first)))) { if (nonpoles) { Gui::cmdAppObjectArgs(Obj, "addConstraint(Sketcher.Constraint('Radius',%d,%f))", @@ -8245,8 +8134,7 @@ void CmdSketcherConstrainRadiam::activated(int iMsg) refGeoId, radiam); } - else if (Obj->getGeometry(refGeoId)->getTypeId() - == Part::GeomCircle::getClassTypeId()) { + else if (isCircle(*(Obj->getGeometry(refGeoId)))) { Gui::cmdAppObjectArgs(Obj, "addConstraint(Sketcher.Constraint('Diameter',%d,%f))", refGeoId, @@ -8273,8 +8161,7 @@ void CmdSketcherConstrainRadiam::activated(int iMsg) it->first, it->second); } - else if (Obj->getGeometry(it->first)->getTypeId() - == Part::GeomCircle::getClassTypeId()) { + else if (isCircle(*(Obj->getGeometry(it->first)))){ Gui::cmdAppObjectArgs(Obj, "addConstraint(Sketcher.Constraint('Diameter',%d,%f))", it->first, @@ -8322,7 +8209,7 @@ void CmdSketcherConstrainRadiam::applyConstraint(std::vector& selSeq, bool updateNeeded = false; - bool isCircle = false; + bool isCircleGeom = false; bool isPole = false; switch (seqIndex) { @@ -8330,14 +8217,15 @@ void CmdSketcherConstrainRadiam::applyConstraint(std::vector& selSeq, case 1:// {SelExternalEdge} { const Part::Geometry* geom = Obj->getGeometry(GeoId); - if (geom && geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle* arc = static_cast(geom); + + if (geom && isArcOfCircle(*geom)) { + auto arc = static_cast(geom); radiam = arc->getRadius(); } - else if (geom && geom->getTypeId() == Part::GeomCircle::getClassTypeId()) { - const Part::GeomCircle* circle = static_cast(geom); + else if (geom && isCircle(*geom)) { + auto circle = static_cast(geom); radiam = circle->getRadius(); - isCircle = true; + isCircleGeom= true; if (isBsplinePole(geom)) { isPole = true; } @@ -8347,7 +8235,6 @@ void CmdSketcherConstrainRadiam::applyConstraint(std::vector& selSeq, Obj, QObject::tr("Wrong selection"), QObject::tr("Constraint only applies to arcs or circles.")); - return; } @@ -8360,7 +8247,7 @@ void CmdSketcherConstrainRadiam::applyConstraint(std::vector& selSeq, GeoId, radiam); } - else if (isCircle) { + else if (isCircleGeom) { Gui::cmdAppObjectArgs(Obj, "addConstraint(Sketcher.Constraint('Diameter',%d,%f))", GeoId, @@ -8645,11 +8532,9 @@ void CmdSketcherConstrainAngle::activated(int iMsg) QObject::tr("Wrong selection"), QObject::tr( "Select one or two lines from the sketch. Or select two edges and a point.")); - return; } - int GeoId1, GeoId2 = GeoEnum::GeoUndef, GeoId3 = GeoEnum::GeoUndef; Sketcher::PointPos PosId1, PosId2 = Sketcher::PointPos::none, PosId3 = Sketcher::PointPos::none; getIdsFromName(SubNames[0], Obj, GeoId1, PosId1); @@ -8774,7 +8659,6 @@ void CmdSketcherConstrainAngle::activated(int iMsg) Obj, QObject::tr("Wrong selection"), QObject::tr("Select an edge that is not a B-spline weight.")); - return; } @@ -8782,12 +8666,10 @@ void CmdSketcherConstrainAngle::activated(int iMsg) const Part::Geometry* geom1 = Obj->getGeometry(GeoId1); const Part::Geometry* geom2 = Obj->getGeometry(GeoId2); - if (geom1->getTypeId() == Part::GeomLineSegment::getClassTypeId() - && geom2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment* lineSeg1 = - static_cast(geom1); - const Part::GeomLineSegment* lineSeg2 = - static_cast(geom2); + + if (isLineSegment(*geom1) && isLineSegment(*geom2)) { + auto lineSeg1 = static_cast(geom1); + auto lineSeg2 = static_cast(geom2); // find the two closest line ends Sketcher::PointPos PosId1 = Sketcher::PointPos::none; @@ -8851,7 +8733,6 @@ void CmdSketcherConstrainAngle::activated(int iMsg) QObject::tr("Parallel lines"), QObject::tr( "An angle constraint cannot be set for two parallel lines.")); - return; } } @@ -8897,14 +8778,13 @@ void CmdSketcherConstrainAngle::activated(int iMsg) Obj, QObject::tr("Wrong selection"), QObject::tr("Cannot add an angle constraint on an axis!")); - return; } const Part::Geometry* geom = Obj->getGeometry(GeoId1); - if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment* lineSeg; - lineSeg = static_cast(geom); + + if (isLineSegment(*geom)) { + auto lineSeg = static_cast(geom); Base::Vector3d dir = lineSeg->getEndPoint() - lineSeg->getStartPoint(); double ActAngle = atan2(dir.y, dir.x); @@ -8930,9 +8810,8 @@ void CmdSketcherConstrainAngle::activated(int iMsg) return; } - else if (geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle* arc; - arc = static_cast(geom); + else if (isArcOfCircle(*geom)) { + auto arc = static_cast(geom); double startangle, endangle; arc->getRange(startangle, endangle, /*EmulateCCWXY=*/true); double angle = endangle - startangle; @@ -8966,7 +8845,6 @@ void CmdSketcherConstrainAngle::activated(int iMsg) Obj, QObject::tr("Wrong selection"), QObject::tr("Select one or two lines from the sketch. Or select two edges and a point.")); - return; } @@ -8992,12 +8870,10 @@ void CmdSketcherConstrainAngle::applyConstraint(std::vector& selSeq, const Part::Geometry* geom1 = Obj->getGeometry(GeoId1); const Part::Geometry* geom2 = Obj->getGeometry(GeoId2); - if (geom1->getTypeId() == Part::GeomLineSegment::getClassTypeId() - && geom2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment* lineSeg1 = - static_cast(geom1); - const Part::GeomLineSegment* lineSeg2 = - static_cast(geom2); + + if (isLineSegment(*geom1) && isLineSegment(*geom2)) { + auto lineSeg1 = static_cast(geom1); + auto lineSeg2 = static_cast(geom2); // find the two closest line ends Sketcher::PointPos PosId1 = Sketcher::PointPos::none; @@ -9061,7 +8937,6 @@ void CmdSketcherConstrainAngle::applyConstraint(std::vector& selSeq, QObject::tr("Parallel lines"), QObject::tr( "An angle constraint cannot be set for two parallel lines.")); - return; } } @@ -9125,7 +9000,6 @@ void CmdSketcherConstrainAngle::applyConstraint(std::vector& selSeq, } } - bool bothexternal = areBothPointsOrSegmentsFixed(Obj, GeoId1, GeoId2); if (isEdge(GeoId1, PosId1) && isEdge(GeoId2, PosId2) && isVertex(GeoId3, PosId3)) { @@ -9135,7 +9009,6 @@ void CmdSketcherConstrainAngle::applyConstraint(std::vector& selSeq, Obj, QObject::tr("Wrong selection"), QObject::tr("Select an edge that is not a B-spline weight.")); - return; } @@ -9293,7 +9166,6 @@ void CmdSketcherConstrainEqual::activated(int iMsg) Gui::TranslatedUserWarning(Obj, QObject::tr("Wrong selection"), QObject::tr("Select at least two lines from the sketch.")); - return; } @@ -9313,7 +9185,6 @@ void CmdSketcherConstrainEqual::activated(int iMsg) Gui::TranslatedUserWarning(Obj, QObject::tr("Wrong selection"), QObject::tr("Select two or more compatible edges.")); - return; } else if (GeoId == Sketcher::GeoEnum::HAxis || GeoId == Sketcher::GeoEnum::VAxis) { @@ -9321,7 +9192,6 @@ void CmdSketcherConstrainEqual::activated(int iMsg) Obj, QObject::tr("Wrong selection"), QObject::tr("Sketch axes cannot be used in equality constraints.")); - return; } else if (isPointOrSegmentFixed(Obj, GeoId)) { @@ -9337,23 +9207,22 @@ void CmdSketcherConstrainEqual::activated(int iMsg) const Part::Geometry* geo = Obj->getGeometry(GeoId); - if (geo->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) { + if (isBSplineCurve(*geo)) { // unsupported as they are generally hereogeneus shapes Gui::TranslatedUserWarning( Obj, QObject::tr("Wrong selection"), QObject::tr("Equality for B-spline edge currently unsupported.")); - return; } - if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + if (isLineSegment(*geo)) { lineSel = true; } - else if (geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { + else if (isArcOfCircle(*geo)) { arcSel = true; } - else if (geo->getTypeId() == Part::GeomCircle::getClassTypeId()) { + else if (isCircle(*geo)) { if (isBsplinePole(geo)) { weightSel = true; } @@ -9361,23 +9230,22 @@ void CmdSketcherConstrainEqual::activated(int iMsg) circSel = true; } } - else if (geo->getTypeId() == Part::GeomEllipse::getClassTypeId()) { + else if (isEllipse(*geo)) { ellipsSel = true; } - else if (geo->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()) { + else if (isArcOfEllipse(*geo)) { arcEllipsSel = true; } - else if (geo->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId()) { + else if (isArcOfHyperbola(*geo)) { hyperbSel = true; } - else if (geo->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { + else if (isArcOfParabola(*geo)) { parabSel = true; } else { Gui::TranslatedUserWarning(Obj, QObject::tr("Wrong selection"), QObject::tr("Select two or more edges of similar type.")); - return; } @@ -9386,17 +9254,14 @@ void CmdSketcherConstrainEqual::activated(int iMsg) // Check for heterogeneous groups in selection if ((lineSel - && ((arcSel || circSel) || (ellipsSel || arcEllipsSel) || hyperbSel || parabSel - || weightSel)) - || ((arcSel || circSel) - && ((ellipsSel || arcEllipsSel) || hyperbSel || parabSel || weightSel)) + && ((arcSel || circSel) || (ellipsSel || arcEllipsSel) || hyperbSel || parabSel || weightSel)) + || ((arcSel || circSel) && ((ellipsSel || arcEllipsSel) || hyperbSel || parabSel || weightSel)) || ((ellipsSel || arcEllipsSel) && (hyperbSel || parabSel || weightSel)) || (hyperbSel && (parabSel || weightSel)) || (parabSel && weightSel)) { Gui::TranslatedUserWarning(Obj, QObject::tr("Wrong selection"), QObject::tr("Select two or more edges of similar type.")); - return; } @@ -9441,27 +9306,17 @@ void CmdSketcherConstrainEqual::applyConstraint(std::vector& selSeq, const Part::Geometry* geo1 = Obj->getGeometry(GeoId1); const Part::Geometry* geo2 = Obj->getGeometry(GeoId2); - if ((geo1->getTypeId() == Part::GeomLineSegment::getClassTypeId() - && geo2->getTypeId() != Part::GeomLineSegment::getClassTypeId()) - || (geo1->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId() - && geo2->getTypeId() != Part::GeomArcOfHyperbola::getClassTypeId()) - || (geo1->getTypeId() == Part::GeomArcOfParabola::getClassTypeId() - && geo2->getTypeId() != Part::GeomArcOfParabola::getClassTypeId()) + if ((isLineSegment(*geo1) && ! isLineSegment(*geo2)) + || (isArcOfHyperbola(*geo1) && ! isArcOfHyperbola(*geo2)) + || (isArcOfParabola(*geo1) && ! isArcOfParabola(*geo2)) || (isBsplinePole(geo1) && !isBsplinePole(geo2)) - || ((geo1->getTypeId() == Part::GeomCircle::getClassTypeId() - || geo1->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) - && !(geo2->getTypeId() == Part::GeomCircle::getClassTypeId() - || geo2->getTypeId() == Part::GeomArcOfCircle::getClassTypeId())) - || ((geo1->getTypeId() == Part::GeomEllipse::getClassTypeId() - || geo1->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()) - && !(geo2->getTypeId() == Part::GeomEllipse::getClassTypeId() - || geo2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()))) { + || ((isCircle(*geo1) || isArcOfCircle(*geo1)) && !(isCircle(*geo2) || isArcOfCircle(*geo2))) + || ((isEllipse(*geo1) || isArcOfEllipse(*geo1)) && !(isEllipse(*geo2) || isArcOfEllipse(*geo2)))) { Gui::TranslatedUserWarning( Obj, QObject::tr("Wrong selection"), QObject::tr("Select two or more edges of similar type.")); - return; } @@ -9570,7 +9425,6 @@ void CmdSketcherConstrainSymmetric::activated(int iMsg) QObject::tr("Select two points and a symmetry line, " "two points and a symmetry point " "or a line and a symmetry point from the sketch.")); - return; } @@ -9590,13 +9444,13 @@ void CmdSketcherConstrainSymmetric::activated(int iMsg) } if (isEdge(GeoId1, PosId1) && isVertex(GeoId2, PosId2)) { const Part::Geometry* geom = Obj->getGeometry(GeoId1); - if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + + if (isLineSegment(*geom)) { if (GeoId1 == GeoId2) { Gui::TranslatedUserWarning(Obj, QObject::tr("Wrong selection"), QObject::tr("Cannot add a symmetry constraint " "between a line and its end points.")); - return; } @@ -9627,7 +9481,6 @@ void CmdSketcherConstrainSymmetric::activated(int iMsg) QObject::tr("Select two points and a symmetry line, " "two points and a symmetry point " "or a line and a symmetry point from the sketch.")); - return; } @@ -9648,16 +9501,15 @@ void CmdSketcherConstrainSymmetric::activated(int iMsg) } if (isVertex(GeoId1, PosId1) && isVertex(GeoId2, PosId2)) { - if (isEdge(GeoId3, PosId3)) { const Part::Geometry* geom = Obj->getGeometry(GeoId3); - if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + + if (isLineSegment(*geom)) { if (GeoId1 == GeoId2 && GeoId2 == GeoId3) { Gui::TranslatedUserWarning(Obj, QObject::tr("Wrong selection"), QObject::tr("Cannot add a symmetry constraint " "between a line and its end points!")); - return; } @@ -9737,7 +9589,6 @@ void CmdSketcherConstrainSymmetric::applyConstraint(std::vector& selS QObject::tr("Wrong selection"), QObject::tr( "Cannot add a symmetry constraint between a line and its end points!")); - return; } @@ -9780,13 +9631,13 @@ void CmdSketcherConstrainSymmetric::applyConstraint(std::vector& selS } const Part::Geometry* geom = Obj->getGeometry(GeoId3); - if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + + if (isLineSegment(*geom)) { if (GeoId1 == GeoId2 && GeoId2 == GeoId3) { Gui::TranslatedUserWarning(Obj, QObject::tr("Wrong selection"), QObject::tr("Cannot add a symmetry constraint " "between a line and its end points.")); - return; } @@ -9813,7 +9664,6 @@ void CmdSketcherConstrainSymmetric::applyConstraint(std::vector& selS "two points and a symmetry point " "or a line and a symmetry point from the sketch.")); } - return; } case 12:// {SelVertex, SelVertexOrRoot, SelVertex} @@ -9882,7 +9732,6 @@ void CmdSketcherConstrainSnellsLaw::activated(int iMsg) { Q_UNUSED(iMsg); - // get the selection std::vector selection = getSelection().getSelectionEx(); @@ -9916,7 +9765,6 @@ void CmdSketcherConstrainSnellsLaw::activated(int iMsg) Gui::TranslatedUserWarning(Obj, QObject::tr("Wrong selection"), QObject::tr("Number of selected objects is not 3")); - return; } @@ -9942,7 +9790,6 @@ void CmdSketcherConstrainSnellsLaw::activated(int iMsg) Obj, QObject::tr("Wrong selection"), QObject::tr("Cannot create constraint with external geometry only.")); - return; } @@ -9953,19 +9800,17 @@ void CmdSketcherConstrainSnellsLaw::activated(int iMsg) Gui::TranslatedUserWarning(Obj, QObject::tr("Wrong selection"), QObject::tr("Incompatible geometry is selected.")); - return; }; const Part::Geometry* geo = Obj->getGeometry(GeoId3); - if (geo && geo->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) { + if (geo && isBSplineCurve(*geo)) { // unsupported until normal to B-spline at any point implemented. Gui::TranslatedUserWarning( Obj, QObject::tr("Wrong selection"), QObject::tr("SnellsLaw on B-spline edge is currently unsupported.")); - return; } @@ -9973,7 +9818,6 @@ void CmdSketcherConstrainSnellsLaw::activated(int iMsg) Gui::TranslatedUserWarning(Obj, QObject::tr("Wrong selection"), QObject::tr("Select an edge that is not a B-spline weight.")); - return; } @@ -10130,7 +9974,6 @@ void CmdSketcherToggleDrivingConstraint::activated(int iMsg) Gui::TranslatedUserWarning(Obj, QObject::tr("Wrong selection"), QObject::tr("Select constraints from the sketch.")); - return; } @@ -10168,7 +10011,6 @@ void CmdSketcherToggleDrivingConstraint::activated(int iMsg) Gui::TranslatedUserWarning(Obj, QObject::tr("Wrong selection"), QObject::tr("Select constraints from the sketch.")); - return; } @@ -10258,7 +10100,6 @@ void CmdSketcherToggleActiveConstraint::activated(int iMsg) Gui::TranslatedUserWarning(Obj, QObject::tr("Wrong selection"), QObject::tr("Select constraints from the sketch.")); - return; } @@ -10301,7 +10142,6 @@ bool CmdSketcherToggleActiveConstraint::isActive() return isCreateConstraintActive(getActiveGuiDocument()); } - void CreateSketcherCommandsConstraints() { Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager();