From b95713599a66ec18e55f2ef944cd3472336f1757 Mon Sep 17 00:00:00 2001 From: Paddle Date: Sat, 26 Aug 2023 19:47:23 +0200 Subject: [PATCH] refactor Sketcher Dimension releaseButton --- src/Mod/Sketcher/Gui/CommandConstraints.cpp | 135 ++++++++++---------- 1 file changed, 67 insertions(+), 68 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index b804bc787d..d2549a2ee9 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -1178,62 +1178,14 @@ public: if (selIdPair.GeoId == GeoEnum::GeoUndef) { // If mouse is released on "blank" space, finalize and start over - // Ask for the value of datum constraints - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); - bool show = hGrp->GetBool("ShowDialogOnDistanceConstraint", true); - const std::vector& ConStr = Obj->Constraints.getValues(); - - bool commandHandledInEditDatum = false; - for (int i = numberOfConstraintsCreated - 1; i >= 0; i--) { - if (show && ConStr[ConStr.size() - 1 - i]->isDimensional() && ConStr[ConStr.size() - 1 - i]->isDriving) { - commandHandledInEditDatum = true; - EditDatumDialog editDatumDialog(sketchgui, ConStr.size() - 1 - i); - editDatumDialog.exec(); - if (!editDatumDialog.isSuccess()) { - break; - } - } - } - - if (!commandHandledInEditDatum) - Gui::Command::commitCommand(); - - // This code enables the continuous creation mode. - bool continuousMode = hGrp->GetBool("ContinuousCreationMode", true); - if (continuousMode) { - Gui::Selection().clearSelection(); - Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Dimension")); - numberOfConstraintsCreated = 0; - specialConstraint = SpecialConstraint::None; - previousOnSketchPos = Base::Vector2d(0.f, 0.f); - selPoints.clear(); - selLine.clear(); - selCircleArc.clear(); - selEllipseAndCo.clear(); - } - else { - sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider - } + finalizeCommand(); } else if (notSelectedYet(selIdPair)) { + std::vector& selVector = getSelectionVector(newselGeoType); + //add the geometry to its type vector. Temporarily if not selAllowed - if (newselGeoType == Part::GeomPoint::getClassTypeId()) { - selPoints.push_back(selIdPair); - } - else if (newselGeoType == Part::GeomLineSegment::getClassTypeId()) { - selLine.push_back(selIdPair); - } - else if (newselGeoType == Part::GeomArcOfCircle::getClassTypeId() - || newselGeoType == Part::GeomCircle::getClassTypeId()) { - selCircleArc.push_back(selIdPair); - } - else if (newselGeoType == Part::GeomEllipse::getClassTypeId() - || newselGeoType == Part::GeomArcOfEllipse::getClassTypeId() - || newselGeoType == Part::GeomArcOfHyperbola::getClassTypeId() - || newselGeoType == Part::GeomArcOfParabola::getClassTypeId()) { - selEllipseAndCo.push_back(selIdPair); - } + selVector.push_back(selIdPair); bool selAllowed = makeAppropriateConstraint(onSketchPos); @@ -1245,22 +1197,7 @@ public: sketchgui->draw(false, false); // Redraw } else { - if (newselGeoType == Part::GeomPoint::getClassTypeId()) { - selPoints.pop_back(); - } - else if (newselGeoType == Part::GeomLineSegment::getClassTypeId()) { - selLine.pop_back(); - } - else if (newselGeoType == Part::GeomArcOfCircle::getClassTypeId() - || newselGeoType == Part::GeomCircle::getClassTypeId()) { - selCircleArc.pop_back(); - } - else if (newselGeoType == Part::GeomEllipse::getClassTypeId() - || newselGeoType == Part::GeomArcOfEllipse::getClassTypeId() - || newselGeoType == Part::GeomArcOfHyperbola::getClassTypeId() - || newselGeoType == Part::GeomArcOfParabola::getClassTypeId()) { - selEllipseAndCo.pop_back(); - } + selVector.pop_back(); } } return true; @@ -1280,6 +1217,68 @@ protected: Sketcher::SketchObject* Obj; + void finalizeCommand() + { + // Ask for the value of datum constraints + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool show = hGrp->GetBool("ShowDialogOnDistanceConstraint", true); + const std::vector& ConStr = Obj->Constraints.getValues(); + + bool commandHandledInEditDatum = false; + for (int i = numberOfConstraintsCreated - 1; i >= 0; i--) { + if (show && ConStr[ConStr.size() - 1 - i]->isDimensional() && ConStr[ConStr.size() - 1 - i]->isDriving) { + commandHandledInEditDatum = true; + EditDatumDialog editDatumDialog(sketchgui, ConStr.size() - 1 - i); + editDatumDialog.exec(); + if (!editDatumDialog.isSuccess()) { + break; + } + } + } + + if (!commandHandledInEditDatum) + Gui::Command::commitCommand(); + + // This code enables the continuous creation mode. + bool continuousMode = hGrp->GetBool("ContinuousCreationMode", true); + if (continuousMode) { + Gui::Selection().clearSelection(); + Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Dimension")); + numberOfConstraintsCreated = 0; + specialConstraint = SpecialConstraint::None; + previousOnSketchPos = Base::Vector2d(0.f, 0.f); + selPoints.clear(); + selLine.clear(); + selCircleArc.clear(); + selEllipseAndCo.clear(); + } + else { + sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + } + } + + std::vector& getSelectionVector(Base::Type selGeoType) { + if (selGeoType == Part::GeomPoint::getClassTypeId()) { + return selPoints; + } + else if (selGeoType == Part::GeomLineSegment::getClassTypeId()) { + return selLine; + } + else if (selGeoType == Part::GeomArcOfCircle::getClassTypeId() || + selGeoType == Part::GeomCircle::getClassTypeId()) { + return selCircleArc; + } + else if (selGeoType == Part::GeomEllipse::getClassTypeId() || + selGeoType == Part::GeomArcOfEllipse::getClassTypeId() || + selGeoType == Part::GeomArcOfHyperbola::getClassTypeId() || + selGeoType == Part::GeomArcOfParabola::getClassTypeId()) { + return selEllipseAndCo; + } + + static std::vector emptyVector; + return emptyVector; + } + bool notSelectedYet(const SelIdPair& elem) { auto contains = [&](const std::vector& vec, const SelIdPair& elem) {