From de723238fa0ef271c78e8e07d71caeba9b7d277d Mon Sep 17 00:00:00 2001 From: wandererfan Date: Mon, 30 Jan 2023 12:41:13 -0500 Subject: [PATCH] [Sketcher]fix cursor display of angles --- src/Mod/Sketcher/Gui/CommandSketcherTools.cpp | 1272 +++++++++-------- src/Mod/Sketcher/Gui/Utils.cpp | 316 ++-- 2 files changed, 870 insertions(+), 718 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp b/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp index d18c92d50b..7cdbc0fefd 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp @@ -22,13 +22,13 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include -# include -# include +#include +#include -# include +#include #endif #include @@ -60,17 +60,18 @@ using namespace Sketcher; DEF_STD_CMD_A(CmdSketcherSelectConstraints) CmdSketcherSelectConstraints::CmdSketcherSelectConstraints() - :Command("Sketcher_SelectConstraints") + : Command("Sketcher_SelectConstraints") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Select associated constraints"); - sToolTipText = QT_TR_NOOP("Select the constraints associated with the selected geometrical elements"); - sWhatsThis = "Sketcher_SelectConstraints"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_SelectConstraints"; - sAccel = "Z, K"; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Select associated constraints"); + sToolTipText = + QT_TR_NOOP("Select the constraints associated with the selected geometrical elements"); + sWhatsThis = "Sketcher_SelectConstraints"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_SelectConstraints"; + sAccel = "Z, K"; + eType = ForEdit; } void CmdSketcherSelectConstraints::activated(int iMsg) @@ -87,15 +88,16 @@ void CmdSketcherSelectConstraints::activated(int iMsg) // only one sketch with its subelements are allowed to be selected if (selection.size() != 1) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select elements from a single sketch.")); + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("Wrong selection"), + QObject::tr("Select elements from a single sketch.")); return; } // get the needed lists and objects - const std::vector &SubNames = selection[0].getSubNames(); + const std::vector& SubNames = selection[0].getSubNames(); Sketcher::SketchObject* Obj = static_cast(selection[0].getObject()); - const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues(); + const std::vector& vals = Obj->Constraints.getValues(); std::string doc_name = Obj->getDocument()->getName(); std::string obj_name = Obj->getNameInDocument(); @@ -104,26 +106,27 @@ void CmdSketcherSelectConstraints::activated(int iMsg) std::vector constraintSubNames; // go through the selected subelements - for (std::vector::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) { + for (std::vector::const_iterator it = SubNames.begin(); it != SubNames.end(); + ++it) { // only handle edges - if (it->size() > 4 && it->substr(0,4) == "Edge") { - int GeoId = std::atoi(it->substr(4,4000).c_str()) - 1; + if (it->size() > 4 && it->substr(0, 4) == "Edge") { + int GeoId = std::atoi(it->substr(4, 4000).c_str()) - 1; // push all the constraints int i = 0; - for (std::vector< Sketcher::Constraint * >::const_iterator it= vals.begin(); - it != vals.end(); ++it,++i) - { + for (std::vector::const_iterator it = vals.begin(); + it != vals.end(); + ++it, ++i) { if ((*it)->First == GeoId || (*it)->Second == GeoId || (*it)->Third == GeoId) { - constraintSubNames.push_back(Sketcher::PropertyConstraintList::getConstraintName(i)); + constraintSubNames.push_back( + Sketcher::PropertyConstraintList::getConstraintName(i)); } } } } - if(!constraintSubNames.empty()) + if (!constraintSubNames.empty()) Gui::Selection().addSelections(doc_name.c_str(), obj_name.c_str(), constraintSubNames); - } bool CmdSketcherSelectConstraints::isActive() @@ -137,28 +140,29 @@ bool CmdSketcherSelectConstraints::isActive() DEF_STD_CMD_A(CmdSketcherSelectOrigin) CmdSketcherSelectOrigin::CmdSketcherSelectOrigin() - :Command("Sketcher_SelectOrigin") + : Command("Sketcher_SelectOrigin") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Select origin"); - sToolTipText = QT_TR_NOOP("Select the local origin point of the sketch"); - sWhatsThis = "Sketcher_SelectOrigin"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_SelectOrigin"; - sAccel = "Z, O"; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Select origin"); + sToolTipText = QT_TR_NOOP("Select the local origin point of the sketch"); + sWhatsThis = "Sketcher_SelectOrigin"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_SelectOrigin"; + sAccel = "Z, O"; + eType = ForEdit; } void CmdSketcherSelectOrigin::activated(int iMsg) { Q_UNUSED(iMsg); - Gui::Document * doc= getActiveGuiDocument(); + Gui::Document* doc = getActiveGuiDocument(); ReleaseHandler(doc); - SketcherGui::ViewProviderSketch* vp = static_cast(doc->getInEdit()); - Sketcher::SketchObject* Obj= vp->getSketchObject(); -// ViewProviderSketch * vp = static_cast(Gui::Application::Instance->getViewProvider(docobj)); -// Sketcher::SketchObject* Obj = vp->getSketchObject(); + SketcherGui::ViewProviderSketch* vp = + static_cast(doc->getInEdit()); + Sketcher::SketchObject* Obj = vp->getSketchObject(); + // ViewProviderSketch * vp = static_cast(Gui::Application::Instance->getViewProvider(docobj)); + // Sketcher::SketchObject* Obj = vp->getSketchObject(); std::string doc_name = Obj->getDocument()->getName(); std::string obj_name = Obj->getNameInDocument(); @@ -166,7 +170,7 @@ void CmdSketcherSelectOrigin::activated(int iMsg) ss << "RootPoint"; - if(Gui::Selection().isSelected(doc_name.c_str(), obj_name.c_str(), ss.str().c_str())) + if (Gui::Selection().isSelected(doc_name.c_str(), obj_name.c_str(), ss.str().c_str())) Gui::Selection().rmvSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); else Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); @@ -183,26 +187,27 @@ bool CmdSketcherSelectOrigin::isActive() DEF_STD_CMD_A(CmdSketcherSelectVerticalAxis) CmdSketcherSelectVerticalAxis::CmdSketcherSelectVerticalAxis() - :Command("Sketcher_SelectVerticalAxis") + : Command("Sketcher_SelectVerticalAxis") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Select vertical axis"); - sToolTipText = QT_TR_NOOP("Select the local vertical axis of the sketch"); - sWhatsThis = "Sketcher_SelectVerticalAxis"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_SelectVerticalAxis"; - sAccel = "Z, V"; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Select vertical axis"); + sToolTipText = QT_TR_NOOP("Select the local vertical axis of the sketch"); + sWhatsThis = "Sketcher_SelectVerticalAxis"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_SelectVerticalAxis"; + sAccel = "Z, V"; + eType = ForEdit; } void CmdSketcherSelectVerticalAxis::activated(int iMsg) { Q_UNUSED(iMsg); - Gui::Document * doc= getActiveGuiDocument(); + Gui::Document* doc = getActiveGuiDocument(); ReleaseHandler(doc); - SketcherGui::ViewProviderSketch* vp = static_cast(doc->getInEdit()); - Sketcher::SketchObject* Obj= vp->getSketchObject(); + SketcherGui::ViewProviderSketch* vp = + static_cast(doc->getInEdit()); + Sketcher::SketchObject* Obj = vp->getSketchObject(); std::string doc_name = Obj->getDocument()->getName(); std::string obj_name = Obj->getNameInDocument(); @@ -210,10 +215,10 @@ void CmdSketcherSelectVerticalAxis::activated(int iMsg) ss << "V_Axis"; - if(Gui::Selection().isSelected(doc_name.c_str(), obj_name.c_str(), ss.str().c_str())) - Gui::Selection().rmvSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); + if (Gui::Selection().isSelected(doc_name.c_str(), obj_name.c_str(), ss.str().c_str())) + Gui::Selection().rmvSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); else - Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); + Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); } bool CmdSketcherSelectVerticalAxis::isActive() @@ -227,26 +232,27 @@ bool CmdSketcherSelectVerticalAxis::isActive() DEF_STD_CMD_A(CmdSketcherSelectHorizontalAxis) CmdSketcherSelectHorizontalAxis::CmdSketcherSelectHorizontalAxis() - :Command("Sketcher_SelectHorizontalAxis") + : Command("Sketcher_SelectHorizontalAxis") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Select horizontal axis"); - sToolTipText = QT_TR_NOOP("Select the local horizontal axis of the sketch"); - sWhatsThis = "Sketcher_SelectHorizontalAxis"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_SelectHorizontalAxis"; - sAccel = "Z, H"; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Select horizontal axis"); + sToolTipText = QT_TR_NOOP("Select the local horizontal axis of the sketch"); + sWhatsThis = "Sketcher_SelectHorizontalAxis"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_SelectHorizontalAxis"; + sAccel = "Z, H"; + eType = ForEdit; } void CmdSketcherSelectHorizontalAxis::activated(int iMsg) { Q_UNUSED(iMsg); - Gui::Document * doc= getActiveGuiDocument(); + Gui::Document* doc = getActiveGuiDocument(); ReleaseHandler(doc); - SketcherGui::ViewProviderSketch* vp = static_cast(doc->getInEdit()); - Sketcher::SketchObject* Obj= vp->getSketchObject(); + SketcherGui::ViewProviderSketch* vp = + static_cast(doc->getInEdit()); + Sketcher::SketchObject* Obj = vp->getSketchObject(); std::string doc_name = Obj->getDocument()->getName(); std::string obj_name = Obj->getNameInDocument(); @@ -254,10 +260,10 @@ void CmdSketcherSelectHorizontalAxis::activated(int iMsg) ss << "H_Axis"; - if(Gui::Selection().isSelected(doc_name.c_str(), obj_name.c_str(), ss.str().c_str())) - Gui::Selection().rmvSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); + if (Gui::Selection().isSelected(doc_name.c_str(), obj_name.c_str(), ss.str().c_str())) + Gui::Selection().rmvSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); else - Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); + Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); } bool CmdSketcherSelectHorizontalAxis::isActive() @@ -270,33 +276,34 @@ bool CmdSketcherSelectHorizontalAxis::isActive() DEF_STD_CMD_A(CmdSketcherSelectRedundantConstraints) CmdSketcherSelectRedundantConstraints::CmdSketcherSelectRedundantConstraints() - :Command("Sketcher_SelectRedundantConstraints") + : Command("Sketcher_SelectRedundantConstraints") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Select redundant constraints"); - sToolTipText = QT_TR_NOOP("Select redundant constraints"); - sWhatsThis = "Sketcher_SelectRedundantConstraints"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_SelectRedundantConstraints"; - sAccel = "Z, P, R"; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Select redundant constraints"); + sToolTipText = QT_TR_NOOP("Select redundant constraints"); + sWhatsThis = "Sketcher_SelectRedundantConstraints"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_SelectRedundantConstraints"; + sAccel = "Z, P, R"; + eType = ForEdit; } void CmdSketcherSelectRedundantConstraints::activated(int iMsg) { Q_UNUSED(iMsg); - Gui::Document * doc= getActiveGuiDocument(); + Gui::Document* doc = getActiveGuiDocument(); ReleaseHandler(doc); - SketcherGui::ViewProviderSketch* vp = static_cast(doc->getInEdit()); - Sketcher::SketchObject* Obj= vp->getSketchObject(); + SketcherGui::ViewProviderSketch* vp = + static_cast(doc->getInEdit()); + Sketcher::SketchObject* Obj = vp->getSketchObject(); std::string doc_name = Obj->getDocument()->getName(); std::string obj_name = Obj->getNameInDocument(); // get the needed lists and objects - const std::vector< int > &solverredundant = vp->getSketchObject()->getLastRedundant(); - const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues(); + const std::vector& solverredundant = vp->getSketchObject()->getLastRedundant(); + const std::vector& vals = Obj->Constraints.getValues(); getSelection().clearSelection(); @@ -304,16 +311,20 @@ void CmdSketcherSelectRedundantConstraints::activated(int iMsg) std::vector constraintSubNames; int i = 0; - for (std::vector< Sketcher::Constraint * >::const_iterator it= vals.begin();it != vals.end(); ++it,++i) { - for(std::vector< int >::const_iterator itc= solverredundant.begin();itc != solverredundant.end(); ++itc) { + for (std::vector::const_iterator it = vals.begin(); it != vals.end(); + ++it, ++i) { + for (std::vector::const_iterator itc = solverredundant.begin(); + itc != solverredundant.end(); + ++itc) { if ((*itc) - 1 == i) { - constraintSubNames.push_back(Sketcher::PropertyConstraintList::getConstraintName(i)); + constraintSubNames.push_back( + Sketcher::PropertyConstraintList::getConstraintName(i)); break; } } } - if(!constraintSubNames.empty()) + if (!constraintSubNames.empty()) Gui::Selection().addSelections(doc_name.c_str(), obj_name.c_str(), constraintSubNames); } @@ -327,49 +338,54 @@ bool CmdSketcherSelectRedundantConstraints::isActive() DEF_STD_CMD_A(CmdSketcherSelectMalformedConstraints) CmdSketcherSelectMalformedConstraints::CmdSketcherSelectMalformedConstraints() - :Command("Sketcher_SelectMalformedConstraints") + : Command("Sketcher_SelectMalformedConstraints") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Select malformed constraints"); - sToolTipText = QT_TR_NOOP("Select malformed constraints"); - sWhatsThis = "Sketcher_SelectMalformedConstraints"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_SelectMalformedConstraints"; - sAccel = "Z, P, M"; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Select malformed constraints"); + sToolTipText = QT_TR_NOOP("Select malformed constraints"); + sWhatsThis = "Sketcher_SelectMalformedConstraints"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_SelectMalformedConstraints"; + sAccel = "Z, P, M"; + eType = ForEdit; } void CmdSketcherSelectMalformedConstraints::activated(int iMsg) { Q_UNUSED(iMsg); - Gui::Document * doc= getActiveGuiDocument(); + Gui::Document* doc = getActiveGuiDocument(); ReleaseHandler(doc); - SketcherGui::ViewProviderSketch* vp = static_cast(doc->getInEdit()); - Sketcher::SketchObject* Obj= vp->getSketchObject(); + SketcherGui::ViewProviderSketch* vp = + static_cast(doc->getInEdit()); + Sketcher::SketchObject* Obj = vp->getSketchObject(); std::string doc_name = Obj->getDocument()->getName(); std::string obj_name = Obj->getNameInDocument(); // get the needed lists and objects - const std::vector< int > &solvermalformed = vp->getSketchObject()->getLastMalformedConstraints(); - const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues(); + const std::vector& solvermalformed = vp->getSketchObject()->getLastMalformedConstraints(); + const std::vector& vals = Obj->Constraints.getValues(); getSelection().clearSelection(); // push the constraints std::vector constraintSubNames; int i = 0; - for (std::vector< Sketcher::Constraint * >::const_iterator it= vals.begin();it != vals.end(); ++it,++i) { - for(std::vector< int >::const_iterator itc= solvermalformed.begin();itc != solvermalformed.end(); ++itc) { + for (std::vector::const_iterator it = vals.begin(); it != vals.end(); + ++it, ++i) { + for (std::vector::const_iterator itc = solvermalformed.begin(); + itc != solvermalformed.end(); + ++itc) { if ((*itc) - 1 == i) { - constraintSubNames.push_back(Sketcher::PropertyConstraintList::getConstraintName(i)); + constraintSubNames.push_back( + Sketcher::PropertyConstraintList::getConstraintName(i)); break; } } } - if(!constraintSubNames.empty()) + if (!constraintSubNames.empty()) Gui::Selection().addSelections(doc_name.c_str(), obj_name.c_str(), constraintSubNames); } @@ -383,49 +399,55 @@ bool CmdSketcherSelectMalformedConstraints::isActive() DEF_STD_CMD_A(CmdSketcherSelectPartiallyRedundantConstraints) CmdSketcherSelectPartiallyRedundantConstraints::CmdSketcherSelectPartiallyRedundantConstraints() - :Command("Sketcher_SelectPartiallyRedundantConstraints") + : Command("Sketcher_SelectPartiallyRedundantConstraints") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Select partially redundant constraints"); - sToolTipText = QT_TR_NOOP("Select partially redundant constraints"); - sWhatsThis = "Sketcher_SelectPartiallyRedundantConstraints"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_SelectPartiallyRedundantConstraints"; - sAccel = "Z, P, P"; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Select partially redundant constraints"); + sToolTipText = QT_TR_NOOP("Select partially redundant constraints"); + sWhatsThis = "Sketcher_SelectPartiallyRedundantConstraints"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_SelectPartiallyRedundantConstraints"; + sAccel = "Z, P, P"; + eType = ForEdit; } void CmdSketcherSelectPartiallyRedundantConstraints::activated(int iMsg) { Q_UNUSED(iMsg); - Gui::Document * doc= getActiveGuiDocument(); + Gui::Document* doc = getActiveGuiDocument(); ReleaseHandler(doc); - SketcherGui::ViewProviderSketch* vp = static_cast(doc->getInEdit()); - Sketcher::SketchObject* Obj= vp->getSketchObject(); + SketcherGui::ViewProviderSketch* vp = + static_cast(doc->getInEdit()); + Sketcher::SketchObject* Obj = vp->getSketchObject(); std::string doc_name = Obj->getDocument()->getName(); std::string obj_name = Obj->getNameInDocument(); // get the needed lists and objects - const std::vector< int > &solverpartiallyredundant = vp->getSketchObject()->getLastPartiallyRedundant(); - const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues(); + const std::vector& solverpartiallyredundant = + vp->getSketchObject()->getLastPartiallyRedundant(); + const std::vector& vals = Obj->Constraints.getValues(); getSelection().clearSelection(); // push the constraints std::vector constraintSubNames; int i = 0; - for (std::vector< Sketcher::Constraint * >::const_iterator it= vals.begin();it != vals.end(); ++it,++i) { - for(std::vector< int >::const_iterator itc= solverpartiallyredundant.begin();itc != solverpartiallyredundant.end(); ++itc) { + for (std::vector::const_iterator it = vals.begin(); it != vals.end(); + ++it, ++i) { + for (std::vector::const_iterator itc = solverpartiallyredundant.begin(); + itc != solverpartiallyredundant.end(); + ++itc) { if ((*itc) - 1 == i) { - constraintSubNames.push_back(Sketcher::PropertyConstraintList::getConstraintName(i)); + constraintSubNames.push_back( + Sketcher::PropertyConstraintList::getConstraintName(i)); break; } } } - if(!constraintSubNames.empty()) + if (!constraintSubNames.empty()) Gui::Selection().addSelections(doc_name.c_str(), obj_name.c_str(), constraintSubNames); } @@ -439,48 +461,53 @@ bool CmdSketcherSelectPartiallyRedundantConstraints::isActive() DEF_STD_CMD_A(CmdSketcherSelectConflictingConstraints) CmdSketcherSelectConflictingConstraints::CmdSketcherSelectConflictingConstraints() - :Command("Sketcher_SelectConflictingConstraints") + : Command("Sketcher_SelectConflictingConstraints") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Select conflicting constraints"); - sToolTipText = QT_TR_NOOP("Select conflicting constraints"); - sWhatsThis = "Sketcher_SelectConflictingConstraints"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_SelectConflictingConstraints"; - sAccel = "Z, P, C"; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Select conflicting constraints"); + sToolTipText = QT_TR_NOOP("Select conflicting constraints"); + sWhatsThis = "Sketcher_SelectConflictingConstraints"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_SelectConflictingConstraints"; + sAccel = "Z, P, C"; + eType = ForEdit; } void CmdSketcherSelectConflictingConstraints::activated(int iMsg) { Q_UNUSED(iMsg); - Gui::Document * doc= getActiveGuiDocument(); + Gui::Document* doc = getActiveGuiDocument(); ReleaseHandler(doc); - SketcherGui::ViewProviderSketch* vp = static_cast(doc->getInEdit()); - Sketcher::SketchObject* Obj= vp->getSketchObject(); + SketcherGui::ViewProviderSketch* vp = + static_cast(doc->getInEdit()); + Sketcher::SketchObject* Obj = vp->getSketchObject(); std::string doc_name = Obj->getDocument()->getName(); std::string obj_name = Obj->getNameInDocument(); // get the needed lists and objects - const std::vector< int > &solverconflicting = vp->getSketchObject()->getLastConflicting(); - const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues(); + const std::vector& solverconflicting = vp->getSketchObject()->getLastConflicting(); + const std::vector& vals = Obj->Constraints.getValues(); getSelection().clearSelection(); // push the constraints std::vector constraintSubNames; int i = 0; - for (std::vector< Sketcher::Constraint * >::const_iterator it= vals.begin();it != vals.end(); ++it,++i) { - for (std::vector< int >::const_iterator itc= solverconflicting.begin();itc != solverconflicting.end(); ++itc) { + for (std::vector::const_iterator it = vals.begin(); it != vals.end(); + ++it, ++i) { + for (std::vector::const_iterator itc = solverconflicting.begin(); + itc != solverconflicting.end(); + ++itc) { if ((*itc) - 1 == i) { - constraintSubNames.push_back(Sketcher::PropertyConstraintList::getConstraintName(i)); + constraintSubNames.push_back( + Sketcher::PropertyConstraintList::getConstraintName(i)); break; } } } - if(!constraintSubNames.empty()) + if (!constraintSubNames.empty()) Gui::Selection().addSelections(doc_name.c_str(), obj_name.c_str(), constraintSubNames); } @@ -493,31 +520,34 @@ bool CmdSketcherSelectConflictingConstraints::isActive() DEF_STD_CMD_A(CmdSketcherSelectElementsAssociatedWithConstraints) -CmdSketcherSelectElementsAssociatedWithConstraints::CmdSketcherSelectElementsAssociatedWithConstraints() - :Command("Sketcher_SelectElementsAssociatedWithConstraints") +CmdSketcherSelectElementsAssociatedWithConstraints:: + CmdSketcherSelectElementsAssociatedWithConstraints() + : Command("Sketcher_SelectElementsAssociatedWithConstraints") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Select associated geometry"); - sToolTipText = QT_TR_NOOP("Select the geometrical elements associated with the selected constraints"); - sWhatsThis = "Sketcher_SelectElementsAssociatedWithConstraints"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_SelectElementsAssociatedWithConstraints"; - sAccel = "Z, E"; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Select associated geometry"); + sToolTipText = + QT_TR_NOOP("Select the geometrical elements associated with the selected constraints"); + sWhatsThis = "Sketcher_SelectElementsAssociatedWithConstraints"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_SelectElementsAssociatedWithConstraints"; + sAccel = "Z, E"; + eType = ForEdit; } void CmdSketcherSelectElementsAssociatedWithConstraints::activated(int iMsg) { Q_UNUSED(iMsg); std::vector selection = Gui::Selection().getSelectionEx(); - Gui::Document * doc= getActiveGuiDocument(); + Gui::Document* doc = getActiveGuiDocument(); ReleaseHandler(doc); - SketcherGui::ViewProviderSketch* vp = static_cast(doc->getInEdit()); - Sketcher::SketchObject* Obj= vp->getSketchObject(); + SketcherGui::ViewProviderSketch* vp = + static_cast(doc->getInEdit()); + Sketcher::SketchObject* Obj = vp->getSketchObject(); - const std::vector &SubNames = selection[0].getSubNames(); - const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues(); + const std::vector& SubNames = selection[0].getSubNames(); + const std::vector& vals = Obj->Constraints.getValues(); getSelection().clearSelection(); @@ -527,44 +557,45 @@ void CmdSketcherSelectElementsAssociatedWithConstraints::activated(int iMsg) std::vector elementSubNames; // go through the selected subelements - for (std::vector::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) { + for (std::vector::const_iterator it = SubNames.begin(); it != SubNames.end(); + ++it) { // only handle constraints - if (it->size() > 10 && it->substr(0,10) == "Constraint") { + if (it->size() > 10 && it->substr(0, 10) == "Constraint") { int ConstrId = Sketcher::PropertyConstraintList::getIndexFromConstraintName(*it); - if(ConstrId < static_cast(vals.size())){ - if(vals[ConstrId]->First!=GeoEnum::GeoUndef){ + if (ConstrId < static_cast(vals.size())) { + if (vals[ConstrId]->First != GeoEnum::GeoUndef) { ss.str(std::string()); - switch(vals[ConstrId]->FirstPos) - { + switch (vals[ConstrId]->FirstPos) { case Sketcher::PointPos::none: ss << "Edge" << vals[ConstrId]->First + 1; break; case Sketcher::PointPos::start: case Sketcher::PointPos::end: case Sketcher::PointPos::mid: - int vertex = Obj->getVertexIndexGeoPos(vals[ConstrId]->First,vals[ConstrId]->FirstPos); - if(vertex>-1) - ss << "Vertex" << vertex + 1; + int vertex = Obj->getVertexIndexGeoPos(vals[ConstrId]->First, + vals[ConstrId]->FirstPos); + if (vertex > -1) + ss << "Vertex" << vertex + 1; break; } elementSubNames.push_back(ss.str()); } - if(vals[ConstrId]->Second!=GeoEnum::GeoUndef){ + if (vals[ConstrId]->Second != GeoEnum::GeoUndef) { ss.str(std::string()); - switch(vals[ConstrId]->SecondPos) - { + switch (vals[ConstrId]->SecondPos) { case Sketcher::PointPos::none: ss << "Edge" << vals[ConstrId]->Second + 1; break; case Sketcher::PointPos::start: case Sketcher::PointPos::end: case Sketcher::PointPos::mid: - int vertex = Obj->getVertexIndexGeoPos(vals[ConstrId]->Second,vals[ConstrId]->SecondPos); - if(vertex>-1) + int vertex = Obj->getVertexIndexGeoPos(vals[ConstrId]->Second, + vals[ConstrId]->SecondPos); + if (vertex > -1) ss << "Vertex" << vertex + 1; break; } @@ -572,20 +603,20 @@ void CmdSketcherSelectElementsAssociatedWithConstraints::activated(int iMsg) elementSubNames.push_back(ss.str()); } - if(vals[ConstrId]->Third!=GeoEnum::GeoUndef){ + if (vals[ConstrId]->Third != GeoEnum::GeoUndef) { ss.str(std::string()); - switch(vals[ConstrId]->ThirdPos) - { + switch (vals[ConstrId]->ThirdPos) { case Sketcher::PointPos::none: ss << "Edge" << vals[ConstrId]->Third + 1; break; case Sketcher::PointPos::start: case Sketcher::PointPos::end: case Sketcher::PointPos::mid: - int vertex = Obj->getVertexIndexGeoPos(vals[ConstrId]->Third,vals[ConstrId]->ThirdPos); - if(vertex>-1) - ss << "Vertex" << vertex + 1; + int vertex = Obj->getVertexIndexGeoPos(vals[ConstrId]->Third, + vals[ConstrId]->ThirdPos); + if (vertex > -1) + ss << "Vertex" << vertex + 1; break; } @@ -596,13 +627,13 @@ void CmdSketcherSelectElementsAssociatedWithConstraints::activated(int iMsg) } if (elementSubNames.empty()) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No constraint selected"), + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("No constraint selected"), QObject::tr("At least one constraint must be selected")); } else { Gui::Selection().addSelections(doc_name.c_str(), obj_name.c_str(), elementSubNames); } - } bool CmdSketcherSelectElementsAssociatedWithConstraints::isActive() @@ -615,27 +646,29 @@ bool CmdSketcherSelectElementsAssociatedWithConstraints::isActive() DEF_STD_CMD_A(CmdSketcherSelectElementsWithDoFs) CmdSketcherSelectElementsWithDoFs::CmdSketcherSelectElementsWithDoFs() -:Command("Sketcher_SelectElementsWithDoFs") + : Command("Sketcher_SelectElementsWithDoFs") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Select unconstrained DoF"); - sToolTipText = QT_TR_NOOP("Select geometrical elements where the solver still detects unconstrained degrees of freedom."); - sWhatsThis = "Sketcher_SelectElementsWithDoFs"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_SelectElementsWithDoFs"; - sAccel = "Z, F"; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Select unconstrained DoF"); + sToolTipText = QT_TR_NOOP("Select geometrical elements where the solver still detects " + "unconstrained degrees of freedom."); + sWhatsThis = "Sketcher_SelectElementsWithDoFs"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_SelectElementsWithDoFs"; + sAccel = "Z, F"; + eType = ForEdit; } void CmdSketcherSelectElementsWithDoFs::activated(int iMsg) { Q_UNUSED(iMsg); getSelection().clearSelection(); - Gui::Document * doc= getActiveGuiDocument(); + Gui::Document* doc = getActiveGuiDocument(); ReleaseHandler(doc); - SketcherGui::ViewProviderSketch* vp = static_cast(doc->getInEdit()); - Sketcher::SketchObject* Obj= vp->getSketchObject(); + SketcherGui::ViewProviderSketch* vp = + static_cast(doc->getInEdit()); + Sketcher::SketchObject* Obj = vp->getSketchObject(); std::string doc_name = Obj->getDocument()->getName(); std::string obj_name = Obj->getNameInDocument(); @@ -650,7 +683,7 @@ void CmdSketcherSelectElementsWithDoFs::activated(int iMsg) int vertex = Obj->getVertexIndexGeoPos(geoId, pos); if (vertex > -1) { - ss << "Vertex" << vertex + 1; + ss << "Vertex" << vertex + 1; elementSubNames.push_back(ss.str()); } @@ -659,20 +692,21 @@ void CmdSketcherSelectElementsWithDoFs::activated(int iMsg) auto testselectedge = [&ss, &elementSubNames](int geoId) { ss.str(std::string()); - ss << "Edge" << geoId + 1; + ss << "Edge" << geoId + 1; elementSubNames.push_back(ss.str()); }; int geoid = 0; for (auto geo : geos) { - if(geo) { - if(geo->hasExtension(Sketcher::SolverGeometryExtension::getClassTypeId())) { + if (geo) { + if (geo->hasExtension(Sketcher::SolverGeometryExtension::getClassTypeId())) { auto solvext = std::static_pointer_cast( - geo->getExtension(Sketcher::SolverGeometryExtension::getClassTypeId()).lock()); + geo->getExtension(Sketcher::SolverGeometryExtension::getClassTypeId()).lock()); - if (solvext->getGeometry() == Sketcher::SolverGeometryExtension::NotFullyConstraint) { + if (solvext->getGeometry() + == Sketcher::SolverGeometryExtension::NotFullyConstraint) { // Coded for consistency with getGeometryWithDependentParameters, read the comments // on that function if (solvext->getEdge() == SolverGeometryExtension::Dependent) @@ -693,7 +727,6 @@ void CmdSketcherSelectElementsWithDoFs::activated(int iMsg) if (!elementSubNames.empty()) { Gui::Selection().addSelections(doc_name.c_str(), obj_name.c_str(), elementSubNames); } - } bool CmdSketcherSelectElementsWithDoFs::isActive() @@ -706,17 +739,17 @@ bool CmdSketcherSelectElementsWithDoFs::isActive() DEF_STD_CMD_A(CmdSketcherRestoreInternalAlignmentGeometry) CmdSketcherRestoreInternalAlignmentGeometry::CmdSketcherRestoreInternalAlignmentGeometry() - :Command("Sketcher_RestoreInternalAlignmentGeometry") + : Command("Sketcher_RestoreInternalAlignmentGeometry") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Show/hide internal geometry"); - sToolTipText = QT_TR_NOOP("Show all internal geometry or hide unused internal geometry"); - sWhatsThis = "Sketcher_RestoreInternalAlignmentGeometry"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_Element_Ellipse_All"; - sAccel = "Z, I"; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Show/hide internal geometry"); + sToolTipText = QT_TR_NOOP("Show all internal geometry or hide unused internal geometry"); + sWhatsThis = "Sketcher_RestoreInternalAlignmentGeometry"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_Element_Ellipse_All"; + sAccel = "Z, I"; + eType = ForEdit; } void CmdSketcherRestoreInternalAlignmentGeometry::activated(int iMsg) @@ -740,7 +773,7 @@ void CmdSketcherRestoreInternalAlignmentGeometry::activated(int iMsg) } // get the needed lists and objects - const std::vector &SubNames = selection[0].getSubNames(); + const std::vector& SubNames = selection[0].getSubNames(); Sketcher::SketchObject* Obj = static_cast(selection[0].getObject()); getSelection().clearSelection(); @@ -758,14 +791,14 @@ void CmdSketcherRestoreInternalAlignmentGeometry::activated(int iMsg) // Tells if the geometry with given GeoId has internal geometry auto noInternalGeo = [&Obj](const auto& GeoId) { - const Part::Geometry *geo = Obj->getGeometry(GeoId); - bool hasInternalGeo = geo && - (geo->getTypeId() == Part::GeomEllipse::getClassTypeId() || - geo->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() || - geo->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId() || - geo->getTypeId() == Part::GeomArcOfParabola::getClassTypeId() || - geo->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()); - return !hasInternalGeo; // so it's removed + const Part::Geometry* geo = Obj->getGeometry(GeoId); + bool hasInternalGeo = geo + && (geo->getTypeId() == Part::GeomEllipse::getClassTypeId() + || geo->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() + || geo->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId() + || geo->getTypeId() == Part::GeomArcOfParabola::getClassTypeId() + || geo->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()); + return !hasInternalGeo;// so it's removed }; std::vector SubGeoIds(SubNames.size()); @@ -791,7 +824,7 @@ void CmdSketcherRestoreInternalAlignmentGeometry::activated(int iMsg) int aftergeoid = Obj->getHighestCurveIndex(); - if(aftergeoid == currentgeoid) { // if we did not expose anything, deleteunused + if (aftergeoid == currentgeoid) {// if we did not expose anything, deleteunused Gui::cmdAppObjectArgs(Obj, "deleteUnusedInternalGeometry(%d)", GeoId); } } @@ -799,13 +832,13 @@ void CmdSketcherRestoreInternalAlignmentGeometry::activated(int iMsg) Base::Console().Error("%s\n", e.what()); Gui::Command::abortCommand(); - tryAutoRecomputeIfNotSolve(static_cast(Obj)); + tryAutoRecomputeIfNotSolve(static_cast(Obj)); return; } Gui::Command::commitCommand(); - tryAutoRecomputeIfNotSolve(static_cast(Obj)); + tryAutoRecomputeIfNotSolve(static_cast(Obj)); } } @@ -819,17 +852,18 @@ bool CmdSketcherRestoreInternalAlignmentGeometry::isActive() DEF_STD_CMD_A(CmdSketcherSymmetry) CmdSketcherSymmetry::CmdSketcherSymmetry() - :Command("Sketcher_Symmetry") + : Command("Sketcher_Symmetry") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Symmetry"); - sToolTipText = QT_TR_NOOP("Creates symmetric geometry with respect to the last selected line or point"); - sWhatsThis = "Sketcher_Symmetry"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_Symmetry"; - sAccel = "Z, S"; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Symmetry"); + sToolTipText = + QT_TR_NOOP("Creates symmetric geometry with respect to the last selected line or point"); + sWhatsThis = "Sketcher_Symmetry"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_Symmetry"; + sAccel = "Z, S"; + eType = ForEdit; } void CmdSketcherSymmetry::activated(int iMsg) @@ -846,16 +880,18 @@ void CmdSketcherSymmetry::activated(int iMsg) // only one sketch with its subelements are allowed to be selected if (selection.size() != 1) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select elements from a single sketch.")); + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("Wrong selection"), + QObject::tr("Select elements from a single sketch.")); return; } // get the needed lists and objects - const std::vector &SubNames = selection[0].getSubNames(); + const std::vector& SubNames = selection[0].getSubNames(); if (SubNames.empty()) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select elements from a single sketch.")); + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("Wrong selection"), + QObject::tr("Select elements from a single sketch.")); return; } @@ -864,7 +900,7 @@ void CmdSketcherSymmetry::activated(int iMsg) int LastGeoId = 0; Sketcher::PointPos LastPointPos = Sketcher::PointPos::none; - const Part::Geometry *LastGeo; + const Part::Geometry* LastGeo; using GeoType = enum { invalid = -1, line = 0, point = 1 }; GeoType lastgeotype = invalid; @@ -873,17 +909,18 @@ void CmdSketcherSymmetry::activated(int iMsg) std::stringstream stream; int geoids = 0; - for (std::vector::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) { + for (std::vector::const_iterator it = SubNames.begin(); it != SubNames.end(); + ++it) { // only handle non-external edges - if ((it->size() > 4 && it->substr(0,4) == "Edge") || - (it->size() > 12 && it->substr(0,12) == "ExternalEdge")) { + if ((it->size() > 4 && it->substr(0, 4) == "Edge") + || (it->size() > 12 && it->substr(0, 12) == "ExternalEdge")) { - if (it->substr(0,4) == "Edge") { - LastGeoId = std::atoi(it->substr(4,4000).c_str()) - 1; + if (it->substr(0, 4) == "Edge") { + LastGeoId = std::atoi(it->substr(4, 4000).c_str()) - 1; LastPointPos = Sketcher::PointPos::none; } else { - LastGeoId = -std::atoi(it->substr(12,4000).c_str()) - 2; + LastGeoId = -std::atoi(it->substr(12, 4000).c_str()) - 2; LastPointPos = Sketcher::PointPos::none; } @@ -901,9 +938,9 @@ void CmdSketcherSymmetry::activated(int iMsg) stream << LastGeoId << ","; } } - else if (it->size() > 6 && it->substr(0,6) == "Vertex") { + else if (it->size() > 6 && it->substr(0, 6) == "Vertex") { // only if it is a GeomPoint - int VtId = std::atoi(it->substr(6,4000).c_str()) - 1; + int VtId = std::atoi(it->substr(6, 4000).c_str()) - 1; int GeoId; Sketcher::PointPos PosId; Obj->getGeoVertexIndex(VtId, GeoId, PosId); @@ -924,8 +961,8 @@ void CmdSketcherSymmetry::activated(int iMsg) bool lastvertexoraxis = false; // check if last selected element is a Vertex, not being a GeomPoint - if (SubNames.rbegin()->size() > 6 && SubNames.rbegin()->substr(0,6) == "Vertex") { - int VtId = std::atoi(SubNames.rbegin()->substr(6,4000).c_str()) - 1; + if (SubNames.rbegin()->size() > 6 && SubNames.rbegin()->substr(0, 6) == "Vertex") { + int VtId = std::atoi(SubNames.rbegin()->substr(6, 4000).c_str()) - 1; int GeoId; Sketcher::PointPos PosId; Obj->getGeoVertexIndex(VtId, GeoId, PosId); @@ -937,21 +974,21 @@ void CmdSketcherSymmetry::activated(int iMsg) } } // check if last selected element is horizontal axis - else if (SubNames.rbegin()->size() == 6 && SubNames.rbegin()->substr(0,6) == "H_Axis") { + else if (SubNames.rbegin()->size() == 6 && SubNames.rbegin()->substr(0, 6) == "H_Axis") { LastGeoId = Sketcher::GeoEnum::HAxis; LastPointPos = Sketcher::PointPos::none; lastgeotype = line; lastvertexoraxis = true; } // check if last selected element is vertical axis - else if (SubNames.rbegin()->size() == 6 && SubNames.rbegin()->substr(0,6) == "V_Axis") { + else if (SubNames.rbegin()->size() == 6 && SubNames.rbegin()->substr(0, 6) == "V_Axis") { LastGeoId = Sketcher::GeoEnum::VAxis; LastPointPos = Sketcher::PointPos::none; lastgeotype = line; lastvertexoraxis = true; } // check if last selected element is the root point - else if (SubNames.rbegin()->size() == 9 && SubNames.rbegin()->substr(0,9) == "RootPoint") { + else if (SubNames.rbegin()->size() == 9 && SubNames.rbegin()->substr(0, 9) == "RootPoint") { LastGeoId = Sketcher::GeoEnum::RtPnt; LastPointPos = Sketcher::PointPos::start; lastgeotype = point; @@ -959,19 +996,21 @@ void CmdSketcherSymmetry::activated(int iMsg) } if (geoids == 0 || (geoids == 1 && LastGeoId >= 0 && !lastvertexoraxis)) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("A symmetric construction requires " - "at least two geometric elements, " - "the last geometric element being the reference " - "for the symmetry construction.")); + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("Wrong selection"), + QObject::tr("A symmetric construction requires " + "at least two geometric elements, " + "the last geometric element being the reference " + "for the symmetry construction.")); return; } if (lastgeotype == invalid) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("The last element must be a point " - "or a line serving as reference " - "for the symmetry construction.")); + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("Wrong selection"), + QObject::tr("The last element must be a point " + "or a line serving as reference " + "for the symmetry construction.")); return; } @@ -985,7 +1024,7 @@ void CmdSketcherSymmetry::activated(int iMsg) if (LastGeoId >= 0 && !lastvertexoraxis) { // if LastGeoId was added remove the last element int index = geoIdList.rfind(','); - index = geoIdList.rfind(',', index-1); + index = geoIdList.rfind(',', index - 1); geoIdList.resize(index); } else { @@ -998,10 +1037,12 @@ void CmdSketcherSymmetry::activated(int iMsg) Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create symmetric geometry")); - try{ + try { Gui::cmdAppObjectArgs(Obj, "addSymmetric(%s, %d, %d)", - geoIdList.c_str(), LastGeoId, static_cast(LastPointPos)); + geoIdList.c_str(), + LastGeoId, + static_cast(LastPointPos)); Gui::Command::commitCommand(); } catch (const Base::Exception& e) { @@ -1018,9 +1059,11 @@ bool CmdSketcherSymmetry::isActive() // ================================================================================ -class SketcherCopy : public Gui::Command { +class SketcherCopy: public Gui::Command +{ public: - enum Op { + enum Op + { Copy, Clone, Move @@ -1031,70 +1074,70 @@ public: }; // TODO: replace XPM cursor with SVG file -static const char *cursor_createcopy[]={ - "32 32 3 1", - "+ c white", - "# c red", - ". c None", - "................................", - ".......+........................", - ".......+........................", - ".......+........................", - ".......+........................", - ".......+........................", - "................................", - ".+++++...+++++..................", - "................................", - ".......+........................", - ".......+..............###.......", - ".......+..............###.......", - ".......+..............###.......", - ".......+..............###.......", - "......................###.......", - ".....###..............###.......", - ".....###..............###.......", - ".....###..............###.......", - ".....###..............###.......", - ".....###..............###.......", - ".....###..............###.......", - ".....###..............###.......", - ".....###..............###.......", - ".....###..............###.......", - ".....###........................", - ".....###........................", - ".....###........................", - ".....###........................", - "................................", - "................................", - "................................", - "................................"}; +static const char* cursor_createcopy[] = {"32 32 3 1", + "+ c white", + "# c red", + ". c None", + "................................", + ".......+........................", + ".......+........................", + ".......+........................", + ".......+........................", + ".......+........................", + "................................", + ".+++++...+++++..................", + "................................", + ".......+........................", + ".......+..............###.......", + ".......+..............###.......", + ".......+..............###.......", + ".......+..............###.......", + "......................###.......", + ".....###..............###.......", + ".....###..............###.......", + ".....###..............###.......", + ".....###..............###.......", + ".....###..............###.......", + ".....###..............###.......", + ".....###..............###.......", + ".....###..............###.......", + ".....###..............###.......", + ".....###........................", + ".....###........................", + ".....###........................", + ".....###........................", + "................................", + "................................", + "................................", + "................................"}; class DrawSketchHandlerCopy: public DrawSketchHandler { public: - DrawSketchHandlerCopy(string geoidlist, int origingeoid, - Sketcher::PointPos originpos, int nelements, - SketcherCopy::Op op) - : Mode(STATUS_SEEK_First) - , snapMode(SnapMode::Free) - , geoIdList(geoidlist) - , Origin() - , OriginGeoId(origingeoid) - , OriginPos(originpos) - , nElements(nelements) - , Op(op) - , EditCurve(2) - { - } + DrawSketchHandlerCopy(string geoidlist, int origingeoid, Sketcher::PointPos originpos, + int nelements, SketcherCopy::Op op) + : Mode(STATUS_SEEK_First), + snapMode(SnapMode::Free), + geoIdList(geoidlist), + Origin(), + OriginGeoId(origingeoid), + OriginPos(originpos), + nElements(nelements), + Op(op), + EditCurve(2) + {} - ~DrawSketchHandlerCopy() override{} + ~DrawSketchHandlerCopy() override + {} /// mode table - enum SelectMode { - STATUS_SEEK_First, /**< enum value ----. */ + enum SelectMode + { + STATUS_SEEK_First, /**< enum value ----. */ STATUS_End }; - enum class SnapMode { + enum class SnapMode + { Free, Snap5Degree }; @@ -1103,10 +1146,10 @@ public: { if (Mode == STATUS_SEEK_First) { - if(QApplication::keyboardModifiers() == Qt::ControlModifier) - snapMode = SnapMode::Snap5Degree; - else - snapMode = SnapMode::Free; + if (QApplication::keyboardModifiers() == Qt::ControlModifier) + snapMode = SnapMode::Snap5Degree; + else + snapMode = SnapMode::Free; float length = (onSketchPos - EditCurve[0]).Length(); float angle = (onSketchPos - EditCurve[0]).Angle(); @@ -1114,15 +1157,15 @@ public: Base::Vector2d endpoint = onSketchPos; if (snapMode == SnapMode::Snap5Degree) { - angle = round(angle / (M_PI/36)) * M_PI/36; - endpoint = EditCurve[0] + length * Base::Vector2d(cos(angle),sin(angle)); + angle = round(angle / (M_PI / 36)) * M_PI / 36; + endpoint = EditCurve[0] + length * Base::Vector2d(cos(angle), sin(angle)); } if (showCursorCoords()) { SbString text; std::string lengthString = lengthToDisplayFormat(length, 1); std::string angleString = angleToDisplayFormat(angle * 180.0 / M_PI, 1); - text.sprintf(" (%s, %.s°)", lengthString.c_str(), angleString.c_str()); + text.sprintf(" (%s, %s)", lengthString.c_str(), angleString.c_str()); setPositionText(endpoint, text); } @@ -1144,25 +1187,28 @@ public: bool releaseButton(Base::Vector2d onSketchPos) override { Q_UNUSED(onSketchPos); - if (Mode == STATUS_End) - { + if (Mode == STATUS_End) { Base::Vector2d vector = EditCurve[1] - EditCurve[0]; unsetCursor(); resetPositionText(); Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Copy/clone/move geometry")); - try{ + try { if (Op != SketcherCopy::Move) { Gui::cmdAppObjectArgs(sketchgui->getObject(), "addCopy(%s, App.Vector(%f, %f, 0), %s)", - geoIdList.c_str(), vector.x, vector.y, + geoIdList.c_str(), + vector.x, + vector.y, (Op == SketcherCopy::Clone ? "True" : "False")); } else { Gui::cmdAppObjectArgs(sketchgui->getObject(), "addMove(%s, App.Vector(%f, %f, 0))", - geoIdList.c_str(), vector.x, vector.y); + geoIdList.c_str(), + vector.x, + vector.y); } Gui::Command::commitCommand(); } @@ -1171,7 +1217,8 @@ public: Gui::Command::abortCommand(); } - tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); + tryAutoRecomputeIfNotSolve( + static_cast(sketchgui->getObject())); EditCurve.clear(); drawEdit(EditCurve); @@ -1180,13 +1227,16 @@ public: } return true; } + private: void activated() override { setCursor(QPixmap(cursor_createcopy), 7, 7); - Origin = static_cast(sketchgui->getObject())->getPoint(OriginGeoId, OriginPos); + Origin = static_cast(sketchgui->getObject()) + ->getPoint(OriginGeoId, OriginPos); EditCurve[0] = Base::Vector2d(Origin.x, Origin.y); } + protected: SelectMode Mode; SnapMode snapMode; @@ -1201,7 +1251,8 @@ protected: }; /*---- SketcherCopy definition ----*/ -SketcherCopy::SketcherCopy(const char* name): Command(name) +SketcherCopy::SketcherCopy(const char* name) + : Command(name) {} void SketcherCopy::activate(SketcherCopy::Op op) @@ -1218,7 +1269,7 @@ void SketcherCopy::activate(SketcherCopy::Op op) } // get the needed lists and objects - const std::vector &SubNames = selection[0].getSubNames(); + const std::vector& SubNames = selection[0].getSubNames(); if (SubNames.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), @@ -1231,15 +1282,16 @@ void SketcherCopy::activate(SketcherCopy::Op op) int LastGeoId = 0; Sketcher::PointPos LastPointPos = Sketcher::PointPos::none; - const Part::Geometry *LastGeo = nullptr; + const Part::Geometry* LastGeo = nullptr; // create python command with list of elements std::stringstream stream; int geoids = 0; - for (std::vector::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) { + for (std::vector::const_iterator it = SubNames.begin(); it != SubNames.end(); + ++it) { // only handle non-external edges - if (it->size() > 4 && it->substr(0,4) == "Edge") { - LastGeoId = std::atoi(it->substr(4,4000).c_str()) - 1; + if (it->size() > 4 && it->substr(0, 4) == "Edge") { + LastGeoId = std::atoi(it->substr(4, 4000).c_str()) - 1; LastPointPos = Sketcher::PointPos::none; LastGeo = Obj->getGeometry(LastGeoId); // lines to copy @@ -1248,9 +1300,9 @@ void SketcherCopy::activate(SketcherCopy::Op op) stream << LastGeoId << ","; } } - else if (it->size() > 6 && it->substr(0,6) == "Vertex") { + else if (it->size() > 6 && it->substr(0, 6) == "Vertex") { // only if it is a GeomPoint - int VtId = std::atoi(it->substr(6,4000).c_str()) - 1; + int VtId = std::atoi(it->substr(6, 4000).c_str()) - 1; int GeoId; Sketcher::PointPos PosId; Obj->getGeoVertexIndex(VtId, GeoId, PosId); @@ -1267,8 +1319,8 @@ void SketcherCopy::activate(SketcherCopy::Op op) } // check if last selected element is a Vertex, not being a GeomPoint - if (SubNames.rbegin()->size() > 6 && SubNames.rbegin()->substr(0,6) == "Vertex") { - int VtId = std::atoi(SubNames.rbegin()->substr(6,4000).c_str()) - 1; + if (SubNames.rbegin()->size() > 6 && SubNames.rbegin()->substr(0, 6) == "Vertex") { + int VtId = std::atoi(SubNames.rbegin()->substr(6, 4000).c_str()) - 1; int GeoId; Sketcher::PointPos PosId; Obj->getGeoVertexIndex(VtId, GeoId, PosId); @@ -1279,9 +1331,10 @@ void SketcherCopy::activate(SketcherCopy::Op op) } if (geoids < 1) { - QMessageBox::warning(Gui::getMainWindow(), - QObject::tr("Wrong selection"), - QObject::tr("A copy requires at least one selected non-external geometric element")); + QMessageBox::warning( + Gui::getMainWindow(), + QObject::tr("Wrong selection"), + QObject::tr("A copy requires at least one selected non-external geometric element")); return; } @@ -1296,8 +1349,8 @@ void SketcherCopy::activate(SketcherCopy::Op op) // if the last element is not a point serving as a reference for the copy process // then make the start point of the last element the copy reference (if it exists, if not the center point) if (LastPointPos == Sketcher::PointPos::none) { - if (LastGeo->getTypeId() == Part::GeomCircle::getClassTypeId() || - LastGeo->getTypeId() == Part::GeomEllipse::getClassTypeId()) { + if (LastGeo->getTypeId() == Part::GeomCircle::getClassTypeId() + || LastGeo->getTypeId() == Part::GeomEllipse::getClassTypeId()) { LastPointPos = Sketcher::PointPos::mid; } else { @@ -1306,7 +1359,7 @@ void SketcherCopy::activate(SketcherCopy::Op op) } // Ask the user if they want to clone or to simple copy -/* + /* int ret = QMessageBox::question(Gui::getMainWindow(), QObject::tr("Dimensional/Geometric constraints"), QObject::tr("Do you want to clone the object, i.e. substitute dimensional constraints by geometric constraints?"), QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel); @@ -1321,35 +1374,40 @@ void SketcherCopy::activate(SketcherCopy::Op op) */ ActivateHandler(getActiveGuiDocument(), - new DrawSketchHandlerCopy(geoIdList, LastGeoId, LastPointPos, geoids, op)); + new DrawSketchHandlerCopy(geoIdList, LastGeoId, LastPointPos, geoids, op)); } -class CmdSketcherCopy : public SketcherCopy +class CmdSketcherCopy: public SketcherCopy { public: CmdSketcherCopy(); - ~CmdSketcherCopy() override{} + ~CmdSketcherCopy() override + {} const char* className() const override - { return "CmdSketcherCopy"; } + { + return "CmdSketcherCopy"; + } void activate() override; + protected: void activated(int iMsg) override; bool isActive() override; }; CmdSketcherCopy::CmdSketcherCopy() - :SketcherCopy("Sketcher_Copy") + : SketcherCopy("Sketcher_Copy") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Copy"); - sToolTipText = QT_TR_NOOP("Creates a simple copy of the geometry taking as reference the last selected point"); - sWhatsThis = "Sketcher_Copy"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_Copy"; - sAccel = "Z, C"; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Copy"); + sToolTipText = QT_TR_NOOP( + "Creates a simple copy of the geometry taking as reference the last selected point"); + sWhatsThis = "Sketcher_Copy"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_Copy"; + sAccel = "Z, C"; + eType = ForEdit; } void CmdSketcherCopy::activated(int iMsg) @@ -1371,31 +1429,36 @@ bool CmdSketcherCopy::isActive() // ================================================================================ -class CmdSketcherClone : public SketcherCopy +class CmdSketcherClone: public SketcherCopy { public: CmdSketcherClone(); - ~CmdSketcherClone() override{} + ~CmdSketcherClone() override + {} const char* className() const override - { return "CmdSketcherClone"; } + { + return "CmdSketcherClone"; + } void activate() override; + protected: void activated(int iMsg) override; bool isActive() override; }; CmdSketcherClone::CmdSketcherClone() - :SketcherCopy("Sketcher_Clone") + : SketcherCopy("Sketcher_Clone") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Clone"); - sToolTipText = QT_TR_NOOP("Creates a clone of the geometry taking as reference the last selected point"); - sWhatsThis = "Sketcher_Clone"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_Clone"; - sAccel = "Z, L"; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Clone"); + sToolTipText = + QT_TR_NOOP("Creates a clone of the geometry taking as reference the last selected point"); + sWhatsThis = "Sketcher_Clone"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_Clone"; + sAccel = "Z, L"; + eType = ForEdit; } void CmdSketcherClone::activated(int iMsg) @@ -1414,31 +1477,35 @@ bool CmdSketcherClone::isActive() return isCommandActive(getActiveGuiDocument(), true); } -class CmdSketcherMove : public SketcherCopy +class CmdSketcherMove: public SketcherCopy { public: CmdSketcherMove(); - ~CmdSketcherMove() override{} + ~CmdSketcherMove() override + {} const char* className() const override - { return "CmdSketcherMove"; } + { + return "CmdSketcherMove"; + } void activate() override; + protected: void activated(int iMsg) override; bool isActive() override; }; CmdSketcherMove::CmdSketcherMove() - :SketcherCopy("Sketcher_Move") + : SketcherCopy("Sketcher_Move") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Move"); - sToolTipText = QT_TR_NOOP("Moves the geometry taking as reference the last selected point"); - sWhatsThis = "Sketcher_Move"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_Move"; - sAccel = "Z, M"; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Move"); + sToolTipText = QT_TR_NOOP("Moves the geometry taking as reference the last selected point"); + sWhatsThis = "Sketcher_Move"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_Move"; + sAccel = "Z, M"; + eType = ForEdit; } void CmdSketcherMove::activated(int iMsg) @@ -1464,19 +1531,20 @@ DEF_STD_CMD_ACL(CmdSketcherCompCopy) CmdSketcherCompCopy::CmdSketcherCompCopy() : Command("Sketcher_CompCopy") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Clone"); - sToolTipText = QT_TR_NOOP("Creates a clone of the geometry taking as reference the last selected point"); - sWhatsThis = "Sketcher_CompCopy"; - sStatusTip = sToolTipText; - sAccel = ""; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Clone"); + sToolTipText = + QT_TR_NOOP("Creates a clone of the geometry taking as reference the last selected point"); + sWhatsThis = "Sketcher_CompCopy"; + sStatusTip = sToolTipText; + sAccel = ""; + eType = ForEdit; } void CmdSketcherCompCopy::activated(int iMsg) { - if (iMsg<0 || iMsg>2) + if (iMsg < 0 || iMsg > 2) return; // Since the default icon is reset when enabling/disabling the command we have @@ -1487,7 +1555,7 @@ void CmdSketcherCompCopy::activated(int iMsg) assert(iMsg < a.size()); pcAction->setIcon(a[iMsg]->icon()); - if (iMsg == 0){ + if (iMsg == 0) { CmdSketcherClone sc; sc.activate(); pcAction->setShortcut(QString::fromLatin1(this->getAccel())); @@ -1504,7 +1572,7 @@ void CmdSketcherCompCopy::activated(int iMsg) } } -Gui::Action * CmdSketcherCompCopy::createAction() +Gui::Action* CmdSketcherCompCopy::createAction() { Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); pcAction->setDropDownMenu(true); @@ -1539,65 +1607,74 @@ void CmdSketcherCompCopy::languageChange() QList a = pcAction->actions(); QAction* clone = a[0]; - clone->setText(QApplication::translate("Sketcher_CompCopy","Clone")); - clone->setToolTip(QApplication::translate("Sketcher_Clone","Creates a clone of the geometry taking as reference the last selected point")); - clone->setStatusTip(QApplication::translate("Sketcher_Clone","Creates a clone of the geometry taking as reference the last selected point")); + clone->setText(QApplication::translate("Sketcher_CompCopy", "Clone")); + clone->setToolTip(QApplication::translate( + "Sketcher_Clone", + "Creates a clone of the geometry taking as reference the last selected point")); + clone->setStatusTip(QApplication::translate( + "Sketcher_Clone", + "Creates a clone of the geometry taking as reference the last selected point")); QAction* copy = a[1]; - copy->setText(QApplication::translate("Sketcher_CompCopy","Copy")); - copy->setToolTip(QApplication::translate("Sketcher_Copy","Creates a simple copy of the geometry taking as reference the last selected point")); - copy->setStatusTip(QApplication::translate("Sketcher_Copy","Creates a simple copy of the geometry taking as reference the last selected point")); + copy->setText(QApplication::translate("Sketcher_CompCopy", "Copy")); + copy->setToolTip(QApplication::translate( + "Sketcher_Copy", + "Creates a simple copy of the geometry taking as reference the last selected point")); + copy->setStatusTip(QApplication::translate( + "Sketcher_Copy", + "Creates a simple copy of the geometry taking as reference the last selected point")); QAction* move = a[2]; - move->setText(QApplication::translate("Sketcher_CompCopy","Move")); - move->setToolTip(QApplication::translate("Sketcher_Move","Moves the geometry taking as reference the last selected point")); - move->setStatusTip(QApplication::translate("Sketcher_Move","Moves the geometry taking as reference the last selected point")); + move->setText(QApplication::translate("Sketcher_CompCopy", "Move")); + move->setToolTip(QApplication::translate( + "Sketcher_Move", "Moves the geometry taking as reference the last selected point")); + move->setStatusTip(QApplication::translate( + "Sketcher_Move", "Moves the geometry taking as reference the last selected point")); } bool CmdSketcherCompCopy::isActive() { - return isCommandActive( getActiveGuiDocument(), true ); + return isCommandActive(getActiveGuiDocument(), true); } // ================================================================================ // TODO: replace XPM cursor with SVG file /* XPM */ -static const char *cursor_createrectangulararray[]={ - "32 32 3 1", - "+ c white", - "# c red", - ". c None", - "................................", - ".......+........................", - ".......+........................", - ".......+........................", - ".......+........................", - ".......+........................", - "................................", - ".+++++...+++++..................", - ".......................###......", - ".......+...............###......", - ".......+...............###......", - ".......+...............###......", - ".......+......###......###......", - ".......+......###......###......", - "..............###......###......", - "..............###......###......", - ".....###......###......###......", - ".....###......###......###......", - ".....###......###......###......", - ".....###......###......###......", - ".....###......###......###......", - ".....###......###......###......", - ".....###......###...............", - ".....###......###...............", - ".....###......###...............", - ".....###......###...............", - ".....###........................", - ".....###........................", - ".....###........................", - ".....###........................", - "................................", - "................................"}; +static const char* cursor_createrectangulararray[] = {"32 32 3 1", + "+ c white", + "# c red", + ". c None", + "................................", + ".......+........................", + ".......+........................", + ".......+........................", + ".......+........................", + ".......+........................", + "................................", + ".+++++...+++++..................", + ".......................###......", + ".......+...............###......", + ".......+...............###......", + ".......+...............###......", + ".......+......###......###......", + ".......+......###......###......", + "..............###......###......", + "..............###......###......", + ".....###......###......###......", + ".....###......###......###......", + ".....###......###......###......", + ".....###......###......###......", + ".....###......###......###......", + ".....###......###......###......", + ".....###......###...............", + ".....###......###...............", + ".....###......###...............", + ".....###......###...............", + ".....###........................", + ".....###........................", + ".....###........................", + ".....###........................", + "................................", + "................................"}; class DrawSketchHandlerRectangularArray: public DrawSketchHandler { @@ -1606,41 +1683,43 @@ public: Sketcher::PointPos originpos, int nelements, bool clone, int rows, int cols, bool constraintSeparation, bool equalVerticalHorizontalSpacing) - : Mode(STATUS_SEEK_First) - , snapMode(SnapMode::Free) - , geoIdList(geoidlist) - , OriginGeoId(origingeoid) - , OriginPos(originpos) - , nElements(nelements) - , Clone(clone) - , Rows(rows) - , Cols(cols) - , ConstraintSeparation(constraintSeparation) - , EqualVerticalHorizontalSpacing(equalVerticalHorizontalSpacing) - , EditCurve(2) - { - } + : Mode(STATUS_SEEK_First), + snapMode(SnapMode::Free), + geoIdList(geoidlist), + OriginGeoId(origingeoid), + OriginPos(originpos), + nElements(nelements), + Clone(clone), + Rows(rows), + Cols(cols), + ConstraintSeparation(constraintSeparation), + EqualVerticalHorizontalSpacing(equalVerticalHorizontalSpacing), + EditCurve(2) + {} - ~DrawSketchHandlerRectangularArray() override{} + ~DrawSketchHandlerRectangularArray() override + {} /// mode table - enum SelectMode { - STATUS_SEEK_First, /**< enum value ----. */ + enum SelectMode + { + STATUS_SEEK_First, /**< enum value ----. */ STATUS_End }; - enum class SnapMode { + enum class SnapMode + { Free, Snap5Degree }; void mouseMove(Base::Vector2d onSketchPos) override { - if (Mode==STATUS_SEEK_First) { + if (Mode == STATUS_SEEK_First) { - if(QApplication::keyboardModifiers() == Qt::ControlModifier) - snapMode = SnapMode::Snap5Degree; - else - snapMode = SnapMode::Free; + if (QApplication::keyboardModifiers() == Qt::ControlModifier) + snapMode = SnapMode::Snap5Degree; + else + snapMode = SnapMode::Free; float length = (onSketchPos - EditCurve[0]).Length(); float angle = (onSketchPos - EditCurve[0]).Angle(); @@ -1648,26 +1727,25 @@ public: Base::Vector2d endpoint = onSketchPos; if (snapMode == SnapMode::Snap5Degree) { - angle = round(angle / (M_PI/36)) * M_PI/36; - endpoint = EditCurve[0] + length * Base::Vector2d(cos(angle),sin(angle)); + angle = round(angle / (M_PI / 36)) * M_PI / 36; + endpoint = EditCurve[0] + length * Base::Vector2d(cos(angle), sin(angle)); } if (showCursorCoords()) { SbString text; std::string lengthString = lengthToDisplayFormat(length, 1); - std::string angleString = angleToDisplayFormat(angle *180.0 / M_PI, 1); + std::string angleString = angleToDisplayFormat(angle * 180.0 / M_PI, 1); text.sprintf(" (%s, %s)", lengthString.c_str(), angleString.c_str()); setPositionText(endpoint, text); } EditCurve[1] = endpoint; drawEdit(EditCurve); - if (seekAutoConstraint(sugConstr1, endpoint, Base::Vector2d(0.0, 0.0), AutoConstraint::VERTEX)) - { + if (seekAutoConstraint( + sugConstr1, endpoint, Base::Vector2d(0.0, 0.0), AutoConstraint::VERTEX)) { renderSuggestConstraintsCursor(sugConstr1); return; } - } applyCursor(); } @@ -1692,13 +1770,17 @@ public: Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create copy of geometry")); try { - Gui::cmdAppObjectArgs(sketchgui->getObject(), - "addRectangularArray(%s, App.Vector(%f, %f, 0), %s, %d, %d, %s, %f)", - geoIdList.c_str(), vector.x, vector.y, - (Clone ? "True" : "False"), - Cols, Rows, - (ConstraintSeparation ? "True" : "False"), - (EqualVerticalHorizontalSpacing ? 1.0 : 0.5)); + Gui::cmdAppObjectArgs( + sketchgui->getObject(), + "addRectangularArray(%s, App.Vector(%f, %f, 0), %s, %d, %d, %s, %f)", + geoIdList.c_str(), + vector.x, + vector.y, + (Clone ? "True" : "False"), + Cols, + Rows, + (ConstraintSeparation ? "True" : "False"), + (EqualVerticalHorizontalSpacing ? 1.0 : 0.5)); Gui::Command::commitCommand(); } catch (const Base::Exception& e) { @@ -1708,10 +1790,11 @@ public: // add auto constraints for the destination copy if (!sugConstr1.empty()) { - createAutoConstraints(sugConstr1, OriginGeoId+nElements, OriginPos); + createAutoConstraints(sugConstr1, OriginGeoId + nElements, OriginPos); sugConstr1.clear(); } - tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); + tryAutoRecomputeIfNotSolve( + static_cast(sketchgui->getObject())); EditCurve.clear(); drawEdit(EditCurve); @@ -1721,13 +1804,16 @@ public: } return true; } + private: void activated() override { setCursor(QPixmap(cursor_createrectangulararray), 7, 7); - Origin = static_cast(sketchgui->getObject())->getPoint(OriginGeoId, OriginPos); + Origin = static_cast(sketchgui->getObject()) + ->getPoint(OriginGeoId, OriginPos); EditCurve[0] = Base::Vector2d(Origin.x, Origin.y); } + protected: SelectMode Mode; SnapMode snapMode; @@ -1748,17 +1834,18 @@ protected: DEF_STD_CMD_A(CmdSketcherRectangularArray) CmdSketcherRectangularArray::CmdSketcherRectangularArray() - :Command("Sketcher_RectangularArray") + : Command("Sketcher_RectangularArray") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Rectangular array"); - sToolTipText = QT_TR_NOOP("Creates a rectangular array pattern of the geometry taking as reference the last selected point"); - sWhatsThis = "Sketcher_RectangularArray"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_RectangularArray"; - sAccel = "Z, A"; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Rectangular array"); + sToolTipText = QT_TR_NOOP("Creates a rectangular array pattern of the geometry taking as " + "reference the last selected point"); + sWhatsThis = "Sketcher_RectangularArray"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_RectangularArray"; + sAccel = "Z, A"; + eType = ForEdit; } void CmdSketcherRectangularArray::activated(int iMsg) @@ -1777,7 +1864,7 @@ void CmdSketcherRectangularArray::activated(int iMsg) } // get the needed lists and objects - const std::vector &SubNames = selection[0].getSubNames(); + const std::vector& SubNames = selection[0].getSubNames(); if (SubNames.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), @@ -1791,16 +1878,17 @@ void CmdSketcherRectangularArray::activated(int iMsg) int LastGeoId = 0; Sketcher::PointPos LastPointPos = Sketcher::PointPos::none; - const Part::Geometry *LastGeo = nullptr; + const Part::Geometry* LastGeo = nullptr; // create python command with list of elements std::stringstream stream; int geoids = 0; - for (std::vector::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) { + for (std::vector::const_iterator it = SubNames.begin(); it != SubNames.end(); + ++it) { // only handle non-external edges - if (it->size() > 4 && it->substr(0,4) == "Edge") { - LastGeoId = std::atoi(it->substr(4,4000).c_str()) - 1; + if (it->size() > 4 && it->substr(0, 4) == "Edge") { + LastGeoId = std::atoi(it->substr(4, 4000).c_str()) - 1; LastPointPos = Sketcher::PointPos::none; LastGeo = Obj->getGeometry(LastGeoId); @@ -1810,9 +1898,9 @@ void CmdSketcherRectangularArray::activated(int iMsg) stream << LastGeoId << ","; } } - else if (it->size() > 6 && it->substr(0,6) == "Vertex") { + else if (it->size() > 6 && it->substr(0, 6) == "Vertex") { // only if it is a GeomPoint - int VtId = std::atoi(it->substr(6,4000).c_str()) - 1; + int VtId = std::atoi(it->substr(6, 4000).c_str()) - 1; int GeoId; Sketcher::PointPos PosId; Obj->getGeoVertexIndex(VtId, GeoId, PosId); @@ -1829,8 +1917,8 @@ void CmdSketcherRectangularArray::activated(int iMsg) } // check if last selected element is a Vertex, not being a GeomPoint - if (SubNames.rbegin()->size() > 6 && SubNames.rbegin()->substr(0,6) == "Vertex") { - int VtId = std::atoi(SubNames.rbegin()->substr(6,4000).c_str()) - 1; + if (SubNames.rbegin()->size() > 6 && SubNames.rbegin()->substr(0, 6) == "Vertex") { + int VtId = std::atoi(SubNames.rbegin()->substr(6, 4000).c_str()) - 1; int GeoId; Sketcher::PointPos PosId; Obj->getGeoVertexIndex(VtId, GeoId, PosId); @@ -1841,9 +1929,10 @@ void CmdSketcherRectangularArray::activated(int iMsg) } if (geoids < 1) { - QMessageBox::warning(Gui::getMainWindow(), - QObject::tr("Wrong selection"), - QObject::tr("A copy requires at least one selected non-external geometric element")); + QMessageBox::warning( + Gui::getMainWindow(), + QObject::tr("Wrong selection"), + QObject::tr("A copy requires at least one selected non-external geometric element")); return; } @@ -1858,8 +1947,8 @@ void CmdSketcherRectangularArray::activated(int iMsg) // if the last element is not a point serving as a reference for the copy process // then make the start point of the last element the copy reference (if it exists, if not the center point) if (LastPointPos == Sketcher::PointPos::none) { - if (LastGeo->getTypeId() == Part::GeomCircle::getClassTypeId() || - LastGeo->getTypeId() == Part::GeomEllipse::getClassTypeId()) { + if (LastGeo->getTypeId() == Part::GeomCircle::getClassTypeId() + || LastGeo->getTypeId() == Part::GeomEllipse::getClassTypeId()) { LastPointPos = Sketcher::PointPos::mid; } else { @@ -1872,9 +1961,15 @@ void CmdSketcherRectangularArray::activated(int iMsg) if (slad.exec() == QDialog::Accepted) { ActivateHandler(getActiveGuiDocument(), - new DrawSketchHandlerRectangularArray(geoIdList, LastGeoId, LastPointPos, geoids, slad.Clone, - slad.Rows, slad.Cols, slad.ConstraintSeparation, - slad.EqualVerticalHorizontalSpacing)); + new DrawSketchHandlerRectangularArray(geoIdList, + LastGeoId, + LastPointPos, + geoids, + slad.Clone, + slad.Rows, + slad.Cols, + slad.ConstraintSeparation, + slad.EqualVerticalHorizontalSpacing)); } } @@ -1888,34 +1983,38 @@ bool CmdSketcherRectangularArray::isActive() DEF_STD_CMD_A(CmdSketcherDeleteAllGeometry) CmdSketcherDeleteAllGeometry::CmdSketcherDeleteAllGeometry() - :Command("Sketcher_DeleteAllGeometry") + : Command("Sketcher_DeleteAllGeometry") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Delete all geometry"); - sToolTipText = QT_TR_NOOP("Delete all geometry and constraints in the current sketch, " - "with the exception of external geometry"); - sWhatsThis = "Sketcher_DeleteAllGeometry"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_DeleteGeometry"; - sAccel = ""; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Delete all geometry"); + sToolTipText = QT_TR_NOOP("Delete all geometry and constraints in the current sketch, " + "with the exception of external geometry"); + sWhatsThis = "Sketcher_DeleteAllGeometry"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_DeleteGeometry"; + sAccel = ""; + eType = ForEdit; } void CmdSketcherDeleteAllGeometry::activated(int iMsg) { Q_UNUSED(iMsg); - int ret = QMessageBox::question(Gui::getMainWindow(), QObject::tr("Delete All Geometry"), - QObject::tr("Are you really sure you want to delete all geometry and constraints?"), - QMessageBox::Yes, QMessageBox::Cancel); + int ret = QMessageBox::question( + Gui::getMainWindow(), + QObject::tr("Delete All Geometry"), + QObject::tr("Are you really sure you want to delete all geometry and constraints?"), + QMessageBox::Yes, + QMessageBox::Cancel); // use an equality constraint if (ret == QMessageBox::Yes) { getSelection().clearSelection(); - Gui::Document * doc= getActiveGuiDocument(); + Gui::Document* doc = getActiveGuiDocument(); ReleaseHandler(doc); - SketcherGui::ViewProviderSketch* vp = static_cast(doc->getInEdit()); - Sketcher::SketchObject* Obj= vp->getSketchObject(); + SketcherGui::ViewProviderSketch* vp = + static_cast(doc->getInEdit()); + Sketcher::SketchObject* Obj = vp->getSketchObject(); try { Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Delete all geometry")); @@ -1927,7 +2026,8 @@ void CmdSketcherDeleteAllGeometry::activated(int iMsg) Gui::Command::abortCommand(); } - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/Mod/Sketcher"); bool autoRecompute = hGrp->GetBool("AutoRecompute", false); if (autoRecompute) @@ -1951,33 +2051,37 @@ bool CmdSketcherDeleteAllGeometry::isActive() DEF_STD_CMD_A(CmdSketcherDeleteAllConstraints) CmdSketcherDeleteAllConstraints::CmdSketcherDeleteAllConstraints() - :Command("Sketcher_DeleteAllConstraints") + : Command("Sketcher_DeleteAllConstraints") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Delete all constraints"); - sToolTipText = QT_TR_NOOP("Delete all constraints in the sketch"); - sWhatsThis = "Sketcher_DeleteAllConstraints"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_DeleteConstraints"; - sAccel = ""; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Delete all constraints"); + sToolTipText = QT_TR_NOOP("Delete all constraints in the sketch"); + sWhatsThis = "Sketcher_DeleteAllConstraints"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_DeleteConstraints"; + sAccel = ""; + eType = ForEdit; } void CmdSketcherDeleteAllConstraints::activated(int iMsg) { Q_UNUSED(iMsg); - int ret = QMessageBox::question(Gui::getMainWindow(), QObject::tr("Delete All Constraints"), - QObject::tr("Are you really sure you want to delete all the constraints?"), - QMessageBox::Yes, QMessageBox::Cancel); + int ret = QMessageBox::question( + Gui::getMainWindow(), + QObject::tr("Delete All Constraints"), + QObject::tr("Are you really sure you want to delete all the constraints?"), + QMessageBox::Yes, + QMessageBox::Cancel); if (ret == QMessageBox::Yes) { getSelection().clearSelection(); - Gui::Document * doc= getActiveGuiDocument(); + Gui::Document* doc = getActiveGuiDocument(); ReleaseHandler(doc); - SketcherGui::ViewProviderSketch* vp = static_cast(doc->getInEdit()); - Sketcher::SketchObject* Obj= vp->getSketchObject(); + SketcherGui::ViewProviderSketch* vp = + static_cast(doc->getInEdit()); + Sketcher::SketchObject* Obj = vp->getSketchObject(); try { Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Delete All Constraints")); @@ -1989,8 +2093,9 @@ void CmdSketcherDeleteAllConstraints::activated(int iMsg) Gui::Command::abortCommand(); } - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); - bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute", false); if (autoRecompute) Gui::Command::updateActive(); @@ -2001,7 +2106,6 @@ void CmdSketcherDeleteAllConstraints::activated(int iMsg) // do nothing return; } - } bool CmdSketcherDeleteAllConstraints::isActive() @@ -2015,17 +2119,18 @@ bool CmdSketcherDeleteAllConstraints::isActive() DEF_STD_CMD_A(CmdSketcherRemoveAxesAlignment) CmdSketcherRemoveAxesAlignment::CmdSketcherRemoveAxesAlignment() - :Command("Sketcher_RemoveAxesAlignment") + : Command("Sketcher_RemoveAxesAlignment") { - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Remove axes alignment"); - sToolTipText = QT_TR_NOOP("Modifies constraints to remove axes alignment while trying to preserve the constraint relationship of the selection"); - sWhatsThis = "Sketcher_RemoveAxesAlignment"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_RemoveAxesAlignment"; - sAccel = "Z, R"; - eType = ForEdit; + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Remove axes alignment"); + sToolTipText = QT_TR_NOOP("Modifies constraints to remove axes alignment while trying to " + "preserve the constraint relationship of the selection"); + sWhatsThis = "Sketcher_RemoveAxesAlignment"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_RemoveAxesAlignment"; + sAccel = "Z, R"; + eType = ForEdit; } void CmdSketcherRemoveAxesAlignment::activated(int iMsg) @@ -2044,7 +2149,7 @@ void CmdSketcherRemoveAxesAlignment::activated(int iMsg) } // get the needed lists and objects - const std::vector &SubNames = selection[0].getSubNames(); + const std::vector& SubNames = selection[0].getSubNames(); if (SubNames.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), @@ -2062,10 +2167,11 @@ void CmdSketcherRemoveAxesAlignment::activated(int iMsg) std::stringstream stream; int geoids = 0; - for (std::vector::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) { + for (std::vector::const_iterator it = SubNames.begin(); it != SubNames.end(); + ++it) { // only handle non-external edges - if (it->size() > 4 && it->substr(0,4) == "Edge") { - LastGeoId = std::atoi(it->substr(4,4000).c_str()) - 1; + if (it->size() > 4 && it->substr(0, 4) == "Edge") { + LastGeoId = std::atoi(it->substr(4, 4000).c_str()) - 1; // lines to copy if (LastGeoId >= 0) { @@ -2073,9 +2179,9 @@ void CmdSketcherRemoveAxesAlignment::activated(int iMsg) stream << LastGeoId << ","; } } - else if (it->size() > 6 && it->substr(0,6) == "Vertex") { + else if (it->size() > 6 && it->substr(0, 6) == "Vertex") { // only if it is a GeomPoint - int VtId = std::atoi(it->substr(6,4000).c_str()) - 1; + int VtId = std::atoi(it->substr(6, 4000).c_str()) - 1; int GeoId; Sketcher::PointPos PosId; Obj->getGeoVertexIndex(VtId, GeoId, PosId); @@ -2093,7 +2199,8 @@ void CmdSketcherRemoveAxesAlignment::activated(int iMsg) if (geoids < 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Removal of axes alignment requires at least one selected non-external geometric element")); + QObject::tr("Removal of axes alignment requires at least one selected " + "non-external geometric element")); return; } @@ -2108,9 +2215,7 @@ void CmdSketcherRemoveAxesAlignment::activated(int iMsg) Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Remove Axes Alignment")); try { - Gui::cmdAppObjectArgs( Obj, - "removeAxesAlignment(%s)", - geoIdList.c_str()); + Gui::cmdAppObjectArgs(Obj, "removeAxesAlignment(%s)", geoIdList.c_str()); Gui::Command::commitCommand(); } catch (const Base::Exception& e) { @@ -2118,8 +2223,7 @@ void CmdSketcherRemoveAxesAlignment::activated(int iMsg) Gui::Command::abortCommand(); } - tryAutoRecomputeIfNotSolve(static_cast(Obj)); - + tryAutoRecomputeIfNotSolve(static_cast(Obj)); } bool CmdSketcherRemoveAxesAlignment::isActive() @@ -2129,7 +2233,7 @@ bool CmdSketcherRemoveAxesAlignment::isActive() void CreateSketcherCommandsConstraintAccel() { - Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); + Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager(); rcCmdMgr.addCommand(new CmdSketcherSelectConstraints()); rcCmdMgr.addCommand(new CmdSketcherSelectOrigin()); diff --git a/src/Mod/Sketcher/Gui/Utils.cpp b/src/Mod/Sketcher/Gui/Utils.cpp index c7220f9c3f..9e1efb3ed0 100644 --- a/src/Mod/Sketcher/Gui/Utils.cpp +++ b/src/Mod/Sketcher/Gui/Utils.cpp @@ -22,11 +22,11 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include -# include -# include -# include +#include +#include +#include #endif #include @@ -39,8 +39,8 @@ #include #include -#include "Utils.h" #include "DrawSketchHandler.h" +#include "Utils.h" #include "ViewProviderSketch.h" @@ -48,18 +48,19 @@ using namespace std; using namespace SketcherGui; using namespace Sketcher; -bool SketcherGui::tryAutoRecompute(Sketcher::SketchObject* obj, bool &autoremoveredundants) +bool SketcherGui::tryAutoRecompute(Sketcher::SketchObject* obj, bool& autoremoveredundants) { - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); - bool autoRecompute = hGrp->GetBool("AutoRecompute",false); - bool autoRemoveRedundants = hGrp->GetBool("AutoRemoveRedundants",false); + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute", false); + bool autoRemoveRedundants = hGrp->GetBool("AutoRemoveRedundants", false); // We need to make sure the solver has right redundancy information before trying to remove the redundants. // for example if a non-driving constraint has been added. - if(autoRemoveRedundants && autoRecompute) + if (autoRemoveRedundants && autoRecompute) obj->solve(); - if(autoRemoveRedundants) + if (autoRemoveRedundants) obj->autoRemoveRedundants(); if (autoRecompute) @@ -74,17 +75,17 @@ bool SketcherGui::tryAutoRecompute(Sketcher::SketchObject* obj) { bool autoremoveredundants; - return tryAutoRecompute(obj,autoremoveredundants); + return tryAutoRecompute(obj, autoremoveredundants); } void SketcherGui::tryAutoRecomputeIfNotSolve(Sketcher::SketchObject* obj) { bool autoremoveredundants; - if(!tryAutoRecompute(obj,autoremoveredundants)) { + if (!tryAutoRecompute(obj, autoremoveredundants)) { obj->solve(); - if(autoremoveredundants) { + if (autoremoveredundants) { obj->autoRemoveRedundants(); } } @@ -94,20 +95,23 @@ std::string SketcherGui::getStrippedPythonExceptionString(const Base::Exception& { std::string msg = e.what(); - if( msg.length() > 26 && msg.substr(0,26) == "FreeCAD exception thrown (") { - return msg.substr(26, msg.length()-27); + if (msg.length() > 26 && msg.substr(0, 26) == "FreeCAD exception thrown (") { + return msg.substr(26, msg.length() - 27); } else return msg; } -bool SketcherGui::ReleaseHandler(Gui::Document* doc) { +bool SketcherGui::ReleaseHandler(Gui::Document* doc) +{ if (doc) { - if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { - SketcherGui::ViewProviderSketch* vp = static_cast (doc->getInEdit()); + if (doc->getInEdit() + && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { + SketcherGui::ViewProviderSketch* vp = + static_cast(doc->getInEdit()); - if (static_cast(doc->getInEdit()) - ->getSketchMode() == ViewProviderSketch::STATUS_SKETCH_UseHandler) { + if (static_cast(doc->getInEdit())->getSketchMode() + == ViewProviderSketch::STATUS_SKETCH_UseHandler) { vp->purgeHandler(); return true; @@ -117,28 +121,28 @@ bool SketcherGui::ReleaseHandler(Gui::Document* doc) { return false; } -void SketcherGui::getIdsFromName(const std::string &name, const Sketcher::SketchObject* Obj, - int &GeoId, PointPos &PosId) +void SketcherGui::getIdsFromName(const std::string& name, const Sketcher::SketchObject* Obj, + int& GeoId, PointPos& PosId) { GeoId = GeoEnum::GeoUndef; PosId = Sketcher::PointPos::none; - if (name.size() > 4 && name.substr(0,4) == "Edge") { - GeoId = std::atoi(name.substr(4,4000).c_str()) - 1; + if (name.size() > 4 && name.substr(0, 4) == "Edge") { + GeoId = std::atoi(name.substr(4, 4000).c_str()) - 1; } - else if (name.size() == 9 && name.substr(0,9) == "RootPoint") { + else if (name.size() == 9 && name.substr(0, 9) == "RootPoint") { GeoId = Sketcher::GeoEnum::RtPnt; PosId = Sketcher::PointPos::start; } - else if (name.size() == 6 && name.substr(0,6) == "H_Axis") + else if (name.size() == 6 && name.substr(0, 6) == "H_Axis") GeoId = Sketcher::GeoEnum::HAxis; - else if (name.size() == 6 && name.substr(0,6) == "V_Axis") + else if (name.size() == 6 && name.substr(0, 6) == "V_Axis") GeoId = Sketcher::GeoEnum::VAxis; - else if (name.size() > 12 && name.substr(0,12) == "ExternalEdge") - GeoId = Sketcher::GeoEnum::RefExt + 1 - std::atoi(name.substr(12,4000).c_str()); - else if (name.size() > 6 && name.substr(0,6) == "Vertex") { - int VtId = std::atoi(name.substr(6,4000).c_str()) - 1; - Obj->getGeoVertexIndex(VtId,GeoId,PosId); + else if (name.size() > 12 && name.substr(0, 12) == "ExternalEdge") + GeoId = Sketcher::GeoEnum::RefExt + 1 - std::atoi(name.substr(12, 4000).c_str()); + else if (name.size() > 6 && name.substr(0, 6) == "Vertex") { + int VtId = std::atoi(name.substr(6, 4000).c_str()) - 1; + Obj->getGeoVertexIndex(VtId, GeoId, PosId); } } @@ -152,42 +156,51 @@ bool SketcherGui::checkBothExternal(int GeoId1, int GeoId2) bool SketcherGui::isPointOrSegmentFixed(const Sketcher::SketchObject* Obj, int GeoId) { - const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues(); + const std::vector& vals = Obj->Constraints.getValues(); if (GeoId == GeoEnum::GeoUndef) return false; else - return checkConstraint(vals, Sketcher::Block, GeoId, Sketcher::PointPos::none) || GeoId <= Sketcher::GeoEnum::RtPnt; + return checkConstraint(vals, Sketcher::Block, GeoId, Sketcher::PointPos::none) + || GeoId <= Sketcher::GeoEnum::RtPnt; } -bool SketcherGui::areBothPointsOrSegmentsFixed(const Sketcher::SketchObject* Obj, int GeoId1, int GeoId2) +bool SketcherGui::areBothPointsOrSegmentsFixed(const Sketcher::SketchObject* Obj, int GeoId1, + int GeoId2) { - const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues(); + const std::vector& vals = Obj->Constraints.getValues(); if (GeoId1 == GeoEnum::GeoUndef || GeoId2 == GeoEnum::GeoUndef) return false; else - return ((checkConstraint(vals, Sketcher::Block, GeoId1, Sketcher::PointPos::none) || GeoId1 <= Sketcher::GeoEnum::RtPnt) && - (checkConstraint(vals, Sketcher::Block, GeoId2, Sketcher::PointPos::none) || GeoId2 <= Sketcher::GeoEnum::RtPnt)); + return ((checkConstraint(vals, Sketcher::Block, GeoId1, Sketcher::PointPos::none) + || GeoId1 <= Sketcher::GeoEnum::RtPnt) + && (checkConstraint(vals, Sketcher::Block, GeoId2, Sketcher::PointPos::none) + || GeoId2 <= Sketcher::GeoEnum::RtPnt)); } -bool SketcherGui::areAllPointsOrSegmentsFixed(const Sketcher::SketchObject* Obj, int GeoId1, int GeoId2, int GeoId3) +bool SketcherGui::areAllPointsOrSegmentsFixed(const Sketcher::SketchObject* Obj, int GeoId1, + int GeoId2, int GeoId3) { - const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues(); + const std::vector& vals = Obj->Constraints.getValues(); if (GeoId1 == GeoEnum::GeoUndef || GeoId2 == GeoEnum::GeoUndef || GeoId3 == GeoEnum::GeoUndef) return false; else - return ((checkConstraint(vals, Sketcher::Block, GeoId1, Sketcher::PointPos::none) || GeoId1 <= Sketcher::GeoEnum::RtPnt) && - (checkConstraint(vals, Sketcher::Block, GeoId2, Sketcher::PointPos::none) || GeoId2 <= Sketcher::GeoEnum::RtPnt) && - (checkConstraint(vals, Sketcher::Block, GeoId3, Sketcher::PointPos::none) || GeoId3 <= Sketcher::GeoEnum::RtPnt)); + return ((checkConstraint(vals, Sketcher::Block, GeoId1, Sketcher::PointPos::none) + || GeoId1 <= Sketcher::GeoEnum::RtPnt) + && (checkConstraint(vals, Sketcher::Block, GeoId2, Sketcher::PointPos::none) + || GeoId2 <= Sketcher::GeoEnum::RtPnt) + && (checkConstraint(vals, Sketcher::Block, GeoId3, Sketcher::PointPos::none) + || GeoId3 <= Sketcher::GeoEnum::RtPnt)); } bool SketcherGui::isSimpleVertex(const Sketcher::SketchObject* Obj, int GeoId, PointPos PosId) { - if (PosId == Sketcher::PointPos::start && (GeoId == Sketcher::GeoEnum::HAxis || GeoId == Sketcher::GeoEnum::VAxis)) + if (PosId == Sketcher::PointPos::start + && (GeoId == Sketcher::GeoEnum::HAxis || GeoId == Sketcher::GeoEnum::VAxis)) return true; - const Part::Geometry *geo = Obj->getGeometry(GeoId); + const Part::Geometry* geo = Obj->getGeometry(GeoId); if (geo->getTypeId() == Part::GeomPoint::getClassTypeId()) return true; else if (PosId == Sketcher::PointPos::mid) @@ -202,22 +215,24 @@ bool SketcherGui::isBsplineKnot(const Sketcher::SketchObject* Obj, int GeoId) return (gf && gf->getInternalType() == Sketcher::InternalType::BSplineKnotPoint); } -bool SketcherGui::isBsplineKnotOrEndPoint(const Sketcher::SketchObject* Obj, int GeoId, Sketcher::PointPos PosId) +bool SketcherGui::isBsplineKnotOrEndPoint(const Sketcher::SketchObject* Obj, int GeoId, + Sketcher::PointPos PosId) { // check first using geometry facade if (isBsplineKnot(Obj, GeoId)) return true; - const Part::Geometry *geo = Obj->getGeometry(GeoId); + const Part::Geometry* geo = Obj->getGeometry(GeoId); // end points of B-Splines are also knots - if (geo->getTypeId() == Part::GeomBSplineCurve::getClassTypeId() && - (PosId == Sketcher::PointPos::start || PosId == Sketcher::PointPos::end)) + if (geo->getTypeId() == Part::GeomBSplineCurve::getClassTypeId() + && (PosId == Sketcher::PointPos::start || PosId == Sketcher::PointPos::end)) return true; return false; } -bool SketcherGui::IsPointAlreadyOnCurve(int GeoIdCurve, int GeoIdPoint, Sketcher::PointPos PosIdPoint, Sketcher::SketchObject* Obj) +bool SketcherGui::IsPointAlreadyOnCurve(int GeoIdCurve, int GeoIdPoint, + Sketcher::PointPos PosIdPoint, Sketcher::SketchObject* Obj) { //This func is a "smartness" behind three-element tangent-, perp.- and angle-via-point. //We want to find out, if the point supplied by user is already on @@ -230,13 +245,12 @@ bool SketcherGui::IsPointAlreadyOnCurve(int GeoIdCurve, int GeoIdPoint, Sketcher // too much trouble, IMO(DeepSOIC). // One exception: check for knots on their B-splines, at least until point on B-spline is implemented. (Ajinkya) if (isBsplineKnot(Obj, GeoIdPoint)) { - const Part::Geometry *geoCurve = Obj->getGeometry(GeoIdCurve); + const Part::Geometry* geoCurve = Obj->getGeometry(GeoIdCurve); if (geoCurve->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) { - const std::vector &constraints = Obj->Constraints.getValues(); - for (const auto& constraint: constraints) { - if (constraint->Type == Sketcher::ConstraintType::InternalAlignment && - constraint->First == GeoIdPoint && - constraint->Second == GeoIdCurve) + const std::vector& constraints = Obj->Constraints.getValues(); + for (const auto& constraint : constraints) { + if (constraint->Type == Sketcher::ConstraintType::InternalAlignment + && constraint->First == GeoIdPoint && constraint->Second == GeoIdCurve) return true; } } @@ -246,11 +260,11 @@ bool SketcherGui::IsPointAlreadyOnCurve(int GeoIdCurve, int GeoIdPoint, Sketcher return Obj->isPointOnCurve(GeoIdCurve, p.x, p.y); } -bool SketcherGui::isBsplinePole(const Part::Geometry * geo) +bool SketcherGui::isBsplinePole(const Part::Geometry* geo) { auto gf = GeometryFacade::getFacade(geo); - if(gf) + if (gf) return gf->getInternalType() == InternalType::BSplineControlPoint; THROWM(Base::ValueError, "Null geometry in isBsplinePole - please report") @@ -264,10 +278,12 @@ bool SketcherGui::isBsplinePole(const Sketcher::SketchObject* Obj, int GeoId) return isBsplinePole(geom); } -bool SketcherGui::checkConstraint(const std::vector< Sketcher::Constraint * > &vals, ConstraintType type, int geoid, PointPos pos) +bool SketcherGui::checkConstraint(const std::vector& vals, + ConstraintType type, int geoid, PointPos pos) { - for (std::vector< Sketcher::Constraint * >::const_iterator itc= vals.begin(); itc != vals.end(); ++itc) { - if ((*itc)->Type == type && (*itc)->First == geoid && (*itc)->FirstPos == pos){ + for (std::vector::const_iterator itc = vals.begin(); itc != vals.end(); + ++itc) { + if ((*itc)->Type == type && (*itc)->First == geoid && (*itc)->FirstPos == pos) { return true; } } @@ -278,37 +294,42 @@ bool SketcherGui::checkConstraint(const std::vector< Sketcher::Constraint * > &v /* helper functions ======================================================*/ // Return counter-clockwise angle from horizontal out of p1 to p2 in radians. -double SketcherGui::GetPointAngle (const Base::Vector2d &p1, const Base::Vector2d &p2) +double SketcherGui::GetPointAngle(const Base::Vector2d& p1, const Base::Vector2d& p2) { - double dX = p2.x - p1.x; - double dY = p2.y - p1.y; - return dY >= 0 ? atan2(dY, dX) : atan2(dY, dX) + 2*M_PI; + double dX = p2.x - p1.x; + double dY = p2.y - p1.y; + return dY >= 0 ? atan2(dY, dX) : atan2(dY, dX) + 2 * M_PI; } -void SketcherGui::ActivateHandler(Gui::Document *doc, DrawSketchHandler *handler) +void SketcherGui::ActivateHandler(Gui::Document* doc, DrawSketchHandler* handler) { std::unique_ptr ptr(handler); if (doc) { - if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { - SketcherGui::ViewProviderSketch* vp = static_cast (doc->getInEdit()); + if (doc->getInEdit() + && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { + SketcherGui::ViewProviderSketch* vp = + static_cast(doc->getInEdit()); vp->purgeHandler(); vp->activateHandler(ptr.release()); } } } -bool SketcherGui::isCommandActive(Gui::Document *doc, bool actsOnSelection) +bool SketcherGui::isCommandActive(Gui::Document* doc, bool actsOnSelection) { if (doc) { // checks if a Sketch Viewprovider is in Edit and is in no special mode - if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { - auto mode = static_cast(doc->getInEdit()) - ->getSketchMode(); - if (mode == ViewProviderSketch::STATUS_NONE || - mode == ViewProviderSketch::STATUS_SKETCH_UseHandler) { + if (doc->getInEdit() + && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { + auto mode = + static_cast(doc->getInEdit())->getSketchMode(); + if (mode == ViewProviderSketch::STATUS_NONE + || mode == ViewProviderSketch::STATUS_SKETCH_UseHandler) { if (!actsOnSelection) return true; - else if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) > 0) + else if (Gui::Selection().countObjectsOfType( + Sketcher::SketchObject::getClassTypeId()) + > 0) return true; } } @@ -317,19 +338,19 @@ bool SketcherGui::isCommandActive(Gui::Document *doc, bool actsOnSelection) return false; } -SketcherGui::ViewProviderSketch* SketcherGui::getSketchViewprovider(Gui::Document *doc) +SketcherGui::ViewProviderSketch* SketcherGui::getSketchViewprovider(Gui::Document* doc) { if (doc) { - if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom - (SketcherGui::ViewProviderSketch::getClassTypeId()) ) + if (doc->getInEdit() + && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) return dynamic_cast(doc->getInEdit()); } return nullptr; } void SketcherGui::removeRedundantHorizontalVertical(Sketcher::SketchObject* psketch, - std::vector &sug1, - std::vector &sug2) + std::vector& sug1, + std::vector& sug2) { if (!sug1.empty() && !sug2.empty()) { @@ -338,8 +359,10 @@ void SketcherGui::removeRedundantHorizontalVertical(Sketcher::SketchObject* pske // we look for: // 1. Coincident to external on both endpoints // 2. Coincident in one endpoint to origin and pointonobject/tangent to an axis on the other - auto detectredundant = [psketch](std::vector &sug, bool &ext, bool &orig, bool &axis) { - + auto detectredundant = [psketch](std::vector& sug, + bool& ext, + bool& orig, + bool& axis) { ext = false; orig = false; axis = false; @@ -347,9 +370,10 @@ void SketcherGui::removeRedundantHorizontalVertical(Sketcher::SketchObject* pske for (std::vector::const_iterator it = sug.begin(); it != sug.end(); ++it) { if ((*it).Type == Sketcher::Coincident && !ext) { - const std::map coincidents = psketch->getAllCoincidentPoints((*it).GeoId, (*it).PosId); + const std::map coincidents = + psketch->getAllCoincidentPoints((*it).GeoId, (*it).PosId); - if(!coincidents.empty()) { + if (!coincidents.empty()) { // the keys are ordered, so if the first is negative, it is coincident with external ext = coincidents.begin()->first < 0; @@ -357,12 +381,12 @@ void SketcherGui::removeRedundantHorizontalVertical(Sketcher::SketchObject* pske geoId1iterator = coincidents.find(-1); - if( geoId1iterator != coincidents.end()) { - if( (*geoId1iterator).second == Sketcher::PointPos::start ) + if (geoId1iterator != coincidents.end()) { + if ((*geoId1iterator).second == Sketcher::PointPos::start) orig = true; } } - else { // it may be that there is no constraint at all, but there is external geometry + else {// it may be that there is no constraint at all, but there is external geometry ext = (*it).GeoId < 0; orig = ((*it).GeoId == -1 && (*it).PosId == Sketcher::PointPos::start); } @@ -371,52 +395,69 @@ void SketcherGui::removeRedundantHorizontalVertical(Sketcher::SketchObject* pske axis = (((*it).GeoId == -1 && (*it).PosId == Sketcher::PointPos::none) || ((*it).GeoId == -2 && (*it).PosId == Sketcher::PointPos::none)); } - } }; - bool firstext = false, secondext = false, firstorig = false, secondorig = false, firstaxis = false, secondaxis = false; + bool firstext = false, secondext = false, firstorig = false, secondorig = false, + firstaxis = false, secondaxis = false; detectredundant(sug1, firstext, firstorig, firstaxis); detectredundant(sug2, secondext, secondorig, secondaxis); - rmvhorvert = ((firstext && secondext) || // coincident with external on both endpoints - (firstorig && secondaxis) || // coincident origin and point on object on other + rmvhorvert = ((firstext && secondext) || // coincident with external on both endpoints + (firstorig && secondaxis) ||// coincident origin and point on object on other (secondorig && firstaxis)); - if(rmvhorvert) { - for(std::vector::reverse_iterator it = sug2.rbegin(); it!=sug2.rend(); ++it) { - if( (*it).Type == Sketcher::Horizontal || (*it).Type == Sketcher::Vertical) { + if (rmvhorvert) { + for (std::vector::reverse_iterator it = sug2.rbegin(); + it != sug2.rend(); + ++it) { + if ((*it).Type == Sketcher::Horizontal || (*it).Type == Sketcher::Vertical) { sug2.erase(std::next(it).base()); - it = sug2.rbegin(); // erase invalidates the iterator + it = sug2.rbegin();// erase invalidates the iterator } } } } } -void SketcherGui::ConstraintToAttachment(Sketcher::GeoElementId element, Sketcher::GeoElementId attachment, double distance, App::DocumentObject* obj) { +void SketcherGui::ConstraintToAttachment(Sketcher::GeoElementId element, + Sketcher::GeoElementId attachment, double distance, + App::DocumentObject* obj) +{ if (distance == 0.) { - if(attachment.isCurve()) { - Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", - element.GeoId, element.posIdAsInt(), attachment.GeoId); - + if (attachment.isCurve()) { + Gui::cmdAppObjectArgs(obj, + "addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + element.GeoId, + element.posIdAsInt(), + attachment.GeoId); } else { - Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('Coincident',%d,%d,%d,%d)) ", - element.GeoId, element.posIdAsInt(), attachment.GeoId, attachment.posIdAsInt()); + Gui::cmdAppObjectArgs(obj, + "addConstraint(Sketcher.Constraint('Coincident',%d,%d,%d,%d)) ", + element.GeoId, + element.posIdAsInt(), + attachment.GeoId, + attachment.posIdAsInt()); } } else { - if(attachment == Sketcher::GeoElementId::VAxis) { - Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%f)) ", - element.GeoId, element.posIdAsInt(), distance); + if (attachment == Sketcher::GeoElementId::VAxis) { + Gui::cmdAppObjectArgs(obj, + "addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%f)) ", + element.GeoId, + element.posIdAsInt(), + distance); } - else if(attachment == Sketcher::GeoElementId::HAxis) { - Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%f)) ", - element.GeoId, element.posIdAsInt(), distance); + else if (attachment == Sketcher::GeoElementId::HAxis) { + Gui::cmdAppObjectArgs(obj, + "addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%f)) ", + element.GeoId, + element.posIdAsInt(), + distance); } } } @@ -425,25 +466,31 @@ void SketcherGui::ConstraintToAttachment(Sketcher::GeoElementId element, Sketche //convenience functions for cursor display bool SketcherGui::hideUnits() { - Base::Reference hGrp = App::GetApplication().GetUserParameter(). - GetGroup("BaseApp")->GetGroup("Preferences")-> - GetGroup("Mod/Sketcher"); + Base::Reference hGrp = App::GetApplication() + .GetUserParameter() + .GetGroup("BaseApp") + ->GetGroup("Preferences") + ->GetGroup("Mod/Sketcher"); return hGrp->GetBool("HideUnits", false); } bool SketcherGui::showCursorCoords() { - Base::Reference hGrp = App::GetApplication().GetUserParameter(). - GetGroup("BaseApp")->GetGroup("Preferences")-> - GetGroup("Mod/Sketcher"); - return hGrp->GetBool("ShowCursorCoords", true); //true for testing. set to false for prod. + Base::Reference hGrp = App::GetApplication() + .GetUserParameter() + .GetGroup("BaseApp") + ->GetGroup("Preferences") + ->GetGroup("Mod/Sketcher"); + return hGrp->GetBool("ShowCursorCoords", true);//true for testing. set to false for prod. } bool SketcherGui::useSystemDecimals() { - Base::Reference hGrp = App::GetApplication().GetUserParameter(). - GetGroup("BaseApp")->GetGroup("Preferences")-> - GetGroup("Mod/Sketcher"); + Base::Reference hGrp = App::GetApplication() + .GetUserParameter() + .GetGroup("BaseApp") + ->GetGroup("Preferences") + ->GetGroup("Mod/Sketcher"); return hGrp->GetBool("UseSystemDecimals", true); } @@ -459,8 +506,7 @@ std::string SketcherGui::lengthToDisplayFormat(double value, int digits) asQuantity.setValue(value); asQuantity.setUnit(Base::Unit::Length); QString qUserString = asQuantity.getUserString(); - if ( Base::UnitsApi::isMultiUnitLength() || - (!hideUnits() && useSystemDecimals()) ) { + if (Base::UnitsApi::isMultiUnitLength() || (!hideUnits() && useSystemDecimals())) { //just return the user string return Base::Tools::toStdString(qUserString); } @@ -472,26 +518,27 @@ std::string SketcherGui::lengthToDisplayFormat(double value, int digits) QString unitPart = QString::fromUtf8(" ") + qUnitString; //get the numeric part of the user string - QRegularExpression rxNoUnits(QString::fromUtf8("(.*) \\D*$")); // text before space + any non digits at end of string + QRegularExpression rxNoUnits( + QString::fromUtf8("(.*) \\D*$"));// text before space + any non digits at end of string QRegularExpressionMatch match = rxNoUnits.match(qUserString); if (!match.hasMatch()) { //no units in userString? return Base::Tools::toStdString(qUserString); } - QString matched = match.captured(1); //matched is the numeric part of user string + QString matched = match.captured(1);//matched is the numeric part of user string int dpPos = matched.indexOf(QLocale().decimalPoint()); if (dpPos < 0) { //no decimal separator (ie an integer), return all the digits if (hideUnits()) { return Base::Tools::toStdString(matched); - } else { + } + else { return Base::Tools::toStdString(matched + unitPart); } } //real number - if (useSystemDecimals() && - hideUnits() ) { + if (useSystemDecimals() && hideUnits()) { //return just the numeric part of the user string return Base::Tools::toStdString(matched); } @@ -520,13 +567,13 @@ std::string SketcherGui::angleToDisplayFormat(double value, int digits) asQuantity.setValue(value); asQuantity.setUnit(Base::Unit::Angle); QString qUserString = asQuantity.getUserString(); - if ( Base::UnitsApi::isMultiUnitAngle() ) { + if (Base::UnitsApi::isMultiUnitAngle()) { //just return the user string //Coin SbString doesn't handle utf8 well, so we convert to ascii - QString schemeMinute = QString::fromUtf8("\xE2\x80\xB2"); //prime symbol - QString schemeSecond = QString::fromUtf8("\xE2\x80\xB3"); //double prime symbol - QString escapeMinute = QString::fromLatin1("\'"); //substitute ascii single quote - QString escapeSecond = QString::fromLatin1("\""); //substitute ascii double quote + QString schemeMinute = QString::fromUtf8("\xE2\x80\xB2");//prime symbol + QString schemeSecond = QString::fromUtf8("\xE2\x80\xB3");//double prime symbol + QString escapeMinute = QString::fromLatin1("\'"); //substitute ascii single quote + QString escapeSecond = QString::fromLatin1("\""); //substitute ascii double quote QString displayString = qUserString.replace(schemeMinute, escapeMinute); displayString = displayString.replace(schemeSecond, escapeSecond); return Base::Tools::toStdString(displayString); @@ -537,13 +584,14 @@ std::string SketcherGui::angleToDisplayFormat(double value, int digits) QString qUnitString = QString::fromUtf8("°"); //get the numeric part of the user string - QRegularExpression rxNoUnits(QString::fromUtf8("(.*)\\D*$")); // text before any non digits at end of string + QRegularExpression rxNoUnits( + QString::fromUtf8("(\\d*\\.?\\d*)(\\D*)$"));// number + non digits at end of string QRegularExpressionMatch match = rxNoUnits.match(qUserString); if (!match.hasMatch()) { //no units in userString? return Base::Tools::toStdString(qUserString); } - QString matched = match.captured(1); //matched is the numeric part of user string + QString matched = match.captured(1);//matched is the numeric part of user string int dpPos = matched.indexOf(QLocale().decimalPoint()); if (dpPos < 0) { //no decimal separator (ie an integer), return all the digits @@ -551,7 +599,7 @@ std::string SketcherGui::angleToDisplayFormat(double value, int digits) } //real number - if (useSystemDecimals() ) { + if (useSystemDecimals()) { //return just the numeric part of the user string + degree symbol return Base::Tools::toStdString(matched + qUnitString); }