From 3553d8ed3ad2e360a2a0303ce512a8423b98cfda Mon Sep 17 00:00:00 2001 From: 0penBrain <48731257+0penBrain@users.noreply.github.com> Date: Thu, 22 Jul 2021 12:42:03 +0200 Subject: [PATCH] [Sketcher] Code simplification by systematically using 'finishDistance' to determine label distance --- src/Mod/Sketcher/Gui/CommandConstraints.cpp | 146 +------------------- 1 file changed, 6 insertions(+), 140 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index 189b0a68a9..757394a3b4 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -5017,23 +5017,7 @@ void CmdSketcherConstrainRadius::activated(int iMsg) Gui::cmdAppObjectArgs(selection[0].getObject(),"setDriving(%i,%s)", constrSize-1,"False"); } - const std::vector &ConStr = Obj->Constraints.getValues(); - - std::size_t indexConstr = constrSize - externalGeoIdRadiusMap.size(); - - // Guess some reasonable distance for placing the datum text - Gui::Document *doc = getActiveGuiDocument(); - float sf = 1.f; - if (doc && doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { - SketcherGui::ViewProviderSketch *vp = static_cast(doc->getInEdit()); - sf = vp->getScaleFactor(); - - for (std::size_t i=0; iLabelDistance = 2. * sf; - } - vp->draw(false,false); // Redraw - } + finishDistanceConstraint(this, Obj, false); commitNeeded=true; updateNeeded=true; @@ -5082,23 +5066,6 @@ void CmdSketcherConstrainRadius::activated(int iMsg) } } - const std::vector &ConStr = Obj->Constraints.getValues(); - std::size_t indexConstr = ConStr.size() - geoIdRadiusMap.size(); - - // Guess some reasonable distance for placing the datum text - Gui::Document *doc = getActiveGuiDocument(); - float sf = 1.f; - if (doc && doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { - SketcherGui::ViewProviderSketch *vp = static_cast(doc->getInEdit()); - sf = vp->getScaleFactor(); - - for (std::size_t i=0; iLabelDistance = 2. * sf; - } - vp->draw(false,false); // Redraw - } - finishDistanceConstraint(this, Obj, constraintCreationMode==Driving); //updateActive(); @@ -5165,20 +5132,7 @@ void CmdSketcherConstrainRadius::applyConstraint(std::vector &selSeq, updateNeeded=true; // We do need to update the solver DoF after setting the constraint driving. } - // Guess some reasonable distance for placing the datum text - Gui::Document *doc = getActiveGuiDocument(); - float sf = 1.f; - if (doc && doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { - SketcherGui::ViewProviderSketch *vp = static_cast(doc->getInEdit()); - sf = vp->getScaleFactor(); - - Sketcher::Constraint *constr = ConStr[ConStr.size()-1]; - constr->LabelDistance = 2. * sf; - vp->draw(); // Redraw - } - - if(!fixed) - finishDistanceConstraint(this, Obj, constraintCreationMode==Driving); + finishDistanceConstraint(this, Obj, constraintCreationMode==Driving && !fixed); //updateActive(); getSelection().clearSelection(); @@ -5348,23 +5302,7 @@ void CmdSketcherConstrainDiameter::activated(int iMsg) Gui::cmdAppObjectArgs(Obj,"setDriving(%i,%s)",constrSize-1,"False"); } - const std::vector &ConStr = Obj->Constraints.getValues(); - - std::size_t indexConstr = constrSize - externalGeoIdDiameterMap.size(); - - // Guess some reasonable distance for placing the datum text - Gui::Document *doc = getActiveGuiDocument(); - float sf = 1.f; - if (doc && doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { - SketcherGui::ViewProviderSketch *vp = static_cast(doc->getInEdit()); - sf = vp->getScaleFactor(); - - for (std::size_t i=0; iLabelDistance = 2. * sf; - } - vp->draw(false,false); // Redraw - } + finishDistanceConstraint(this, Obj, false); commitNeeded=true; updateNeeded=true; @@ -5406,22 +5344,6 @@ void CmdSketcherConstrainDiameter::activated(int iMsg) } } - const std::vector &ConStr = Obj->Constraints.getValues(); - std::size_t indexConstr = ConStr.size() - geoIdDiameterMap.size(); - - // Guess some reasonable distance for placing the datum text - Gui::Document *doc = getActiveGuiDocument(); - float sf = 1.f; - if (doc && doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { - SketcherGui::ViewProviderSketch *vp = static_cast(doc->getInEdit()); - sf = vp->getScaleFactor(); - - for (std::size_t i=0; iLabelDistance = 2. * sf; - } - vp->draw(false,false); // Redraw - } finishDistanceConstraint(this, Obj, constraintCreationMode==Driving); //updateActive(); @@ -5485,19 +5407,7 @@ void CmdSketcherConstrainDiameter::applyConstraint(std::vector &selSe updateNeeded=true; // We do need to update the solver DoF after setting the constraint driving. } - // Guess some reasonable distance for placing the datum text - Gui::Document *doc = getActiveGuiDocument(); - float sf = 1.f; - if (doc && doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { - SketcherGui::ViewProviderSketch *vp = static_cast(doc->getInEdit()); - sf = vp->getScaleFactor(); - - Sketcher::Constraint *constr = ConStr[ConStr.size()-1]; - constr->LabelDistance = 2. * sf; - vp->draw(); // Redraw - } - if(!fixed) - finishDistanceConstraint(this, Obj, constraintCreationMode==Driving); + finishDistanceConstraint(this, Obj, constraintCreationMode==Driving && !fixed); //updateActive(); getSelection().clearSelection(); @@ -5682,23 +5592,7 @@ void CmdSketcherConstrainRadiam::activated(int iMsg) Gui::cmdAppObjectArgs(Obj,"setDriving(%i,%s)",constrSize-1,"False"); } - const std::vector &ConStr = Obj->Constraints.getValues(); - - std::size_t indexConstr = constrSize - externalGeoIdRadiamMap.size(); - - // Guess some reasonable distance for placing the datum text - Gui::Document *doc = getActiveGuiDocument(); - float sf = 1.f; - if (doc && doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { - SketcherGui::ViewProviderSketch *vp = static_cast(doc->getInEdit()); - sf = vp->getScaleFactor(); - - for (std::size_t i=0; iLabelDistance = 2. * sf; - } - vp->draw(false,false); // Redraw - } + finishDistanceConstraint(this, Obj, false); commitNeeded=true; updateNeeded=true; @@ -5757,22 +5651,6 @@ void CmdSketcherConstrainRadiam::activated(int iMsg) } } - const std::vector &ConStr = Obj->Constraints.getValues(); - std::size_t indexConstr = ConStr.size() - geoIdRadiamMap.size(); - - // Guess some reasonable distance for placing the datum text - Gui::Document *doc = getActiveGuiDocument(); - float sf = 1.f; - if (doc && doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { - SketcherGui::ViewProviderSketch *vp = static_cast(doc->getInEdit()); - sf = vp->getScaleFactor(); - - for (std::size_t i=0; iLabelDistance = 2. * sf; - } - vp->draw(false,false); // Redraw - } finishDistanceConstraint(this, Obj, constraintCreationMode==Driving); //updateActive(); @@ -5844,19 +5722,7 @@ void CmdSketcherConstrainRadiam::applyConstraint(std::vector &selSeq, updateNeeded=true; // We do need to update the solver DoF after setting the constraint driving. } - // Guess some reasonable distance for placing the datum text - Gui::Document *doc = getActiveGuiDocument(); - float sf = 1.f; - if (doc && doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { - SketcherGui::ViewProviderSketch *vp = static_cast(doc->getInEdit()); - sf = vp->getScaleFactor(); - - Sketcher::Constraint *constr = ConStr[ConStr.size()-1]; - constr->LabelDistance = 2. * sf; - vp->draw(); // Redraw - } - if(!fixed) - finishDistanceConstraint(this, Obj, constraintCreationMode==Driving); + finishDistanceConstraint(this, Obj, constraintCreationMode==Driving && !fixed); //updateActive(); getSelection().clearSelection();