diff --git a/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp b/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp index 53c2b750ae..38e1053232 100644 --- a/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp +++ b/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp @@ -120,11 +120,11 @@ void CmdSketcherToggleConstruction::activated(int iMsg) Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager(); - if (geometryCreationMode == Construction) { - geometryCreationMode = Normal; + if (geometryCreationMode == GeometryCreationMode::Construction) { + geometryCreationMode = GeometryCreationMode::Normal; } else { - geometryCreationMode = Construction; + geometryCreationMode = GeometryCreationMode::Construction; } rcCmdMgr.updateCommands("ToggleConstruction", static_cast(geometryCreationMode)); diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index bbb90b79ed..2f5643f144 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -82,11 +82,11 @@ using namespace SketcherGui; { \ auto act = getAction(); \ if (act) { \ - switch (mode) { \ - case Normal: \ + switch (static_cast(mode)) { \ + case GeometryCreationMode::Normal: \ act->setIcon(Gui::BitmapFactory().iconFromTheme(ICON)); \ break; \ - case Construction: \ + case GeometryCreationMode::Construction: \ act->setIcon(Gui::BitmapFactory().iconFromTheme(ICON "_Constr")); \ break; \ } \ @@ -95,7 +95,7 @@ using namespace SketcherGui; namespace SketcherGui { -GeometryCreationMode geometryCreationMode = Normal; +GeometryCreationMode geometryCreationMode = GeometryCreationMode::Normal; } /* Sketch commands =======================================================*/ @@ -298,14 +298,14 @@ void CmdSketcherCompCreateRectangles::updateAction(int mode) QList a = pcAction->actions(); int index = pcAction->property("defaultAction").toInt(); - switch (mode) { - case Normal: + switch (static_cast(mode)) { + case GeometryCreationMode::Normal: a[0]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateRectangle")); a[1]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateRectangle_Center")); a[2]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateOblong")); getAction()->setIcon(a[index]->icon()); break; - case Construction: + case GeometryCreationMode::Construction: a[0]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateRectangle_Constr")); a[1]->setIcon( Gui::BitmapFactory().iconFromTheme("Sketcher_CreateRectangle_Center_Constr")); @@ -510,13 +510,13 @@ void CmdSketcherCompCreateArc::updateAction(int mode) QList a = pcAction->actions(); int index = pcAction->property("defaultAction").toInt(); - switch (mode) { - case Normal: + switch (static_cast(mode)) { + case GeometryCreationMode::Normal: a[0]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateArc")); a[1]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_Create3PointArc")); getAction()->setIcon(a[index]->icon()); break; - case Construction: + case GeometryCreationMode::Construction: a[0]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateArc_Constr")); a[1]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_Create3PointArc_Constr")); getAction()->setIcon(a[index]->icon()); @@ -834,8 +834,8 @@ void CmdSketcherCompCreateConic::updateAction(int mode) QList a = pcAction->actions(); int index = pcAction->property("defaultAction").toInt(); - switch (mode) { - case Normal: + switch (static_cast(mode)) { + case GeometryCreationMode::Normal: a[0]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateEllipseByCenter")); a[1]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateEllipse_3points")); a[2]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateElliptical_Arc")); @@ -843,7 +843,7 @@ void CmdSketcherCompCreateConic::updateAction(int mode) a[4]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateParabolic_Arc")); getAction()->setIcon(a[index]->icon()); break; - case Construction: + case GeometryCreationMode::Construction: a[0]->setIcon( Gui::BitmapFactory().iconFromTheme("Sketcher_CreateEllipseByCenter_Constr")); a[1]->setIcon( @@ -1144,8 +1144,8 @@ void CmdSketcherCompCreateBSpline::updateAction(int mode) QList a = pcAction->actions(); int index = pcAction->property("defaultAction").toInt(); - switch (mode) { - case Normal: + switch (static_cast(mode)) { + case GeometryCreationMode::Normal: a[0]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateBSpline")); a[1]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_Create_Periodic_BSpline")); a[2]->setIcon( @@ -1154,7 +1154,7 @@ void CmdSketcherCompCreateBSpline::updateAction(int mode) "Sketcher_Create_Periodic_BSplineByInterpolation")); getAction()->setIcon(a[index]->icon()); break; - case Construction: + case GeometryCreationMode::Construction: a[0]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateBSpline_Constr")); a[1]->setIcon( Gui::BitmapFactory().iconFromTheme("Sketcher_Create_Periodic_BSpline_Constr")); @@ -1315,13 +1315,13 @@ void CmdSketcherCompCreateCircle::updateAction(int mode) QList a = pcAction->actions(); int index = pcAction->property("defaultAction").toInt(); - switch (mode) { - case Normal: + switch (static_cast(mode)) { + case GeometryCreationMode::Normal: a[0]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateCircle")); a[1]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_Create3PointCircle")); getAction()->setIcon(a[index]->icon()); break; - case Construction: + case GeometryCreationMode::Construction: a[0]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateCircle_Constr")); a[1]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_Create3PointCircle_Constr")); getAction()->setIcon(a[index]->icon()); @@ -2056,8 +2056,8 @@ void CmdSketcherCompCreateRegularPolygon::updateAction(int mode) QList a = pcAction->actions(); int index = pcAction->property("defaultAction").toInt(); - switch (mode) { - case Normal: + switch (static_cast(mode)) { + case GeometryCreationMode::Normal: a[0]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateTriangle")); a[1]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateSquare")); a[2]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreatePentagon")); @@ -2067,7 +2067,7 @@ void CmdSketcherCompCreateRegularPolygon::updateAction(int mode) a[6]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateRegularPolygon")); getAction()->setIcon(a[index]->icon()); break; - case Construction: + case GeometryCreationMode::Construction: a[0]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateTriangle_Constr")); a[1]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateSquare_Constr")); a[2]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreatePentagon_Constr")); diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h index edd742d5a7..eeb28b6e6a 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h @@ -189,8 +189,7 @@ public: sqrt(rx * rx + ry * ry), startAngle, endAngle, - geometryCreationMode == Construction ? "True" - : "False"); // arcAngle > 0 ? 0 : 1); + constructionModeAsBooleanText()); // arcAngle > 0 ? 0 : 1); Gui::Command::commitCommand(); } @@ -465,7 +464,7 @@ public: radius, startAngle, endAngle, - geometryCreationMode == Construction ? "True" : "False"); + constructionModeAsBooleanText()); Gui::Command::commitCommand(); } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h index 697d8c6fce..8139f19729 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h @@ -314,7 +314,7 @@ public: centerPoint.y, startAngle, endAngle, - geometryCreationMode == Construction ? "True" : "False"); + constructionModeAsBooleanText()); currentgeoid++; diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h index 87107cdc82..61e65b93d6 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h @@ -319,7 +319,7 @@ public: centerPoint.y, startAngle, endAngle, - geometryCreationMode == Construction ? "True" : "False"); + constructionModeAsBooleanText()); currentgeoid++; diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfParabola.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfParabola.h index 3b820e8aac..544fb912c6 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfParabola.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfParabola.h @@ -246,7 +246,7 @@ public: axisPoint.y, startAngle, endAngle, - geometryCreationMode == Construction ? "True" : "False"); + constructionModeAsBooleanText()); currentgeoid++; diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h index 72c7694f11..4e36c1abe8 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h @@ -472,7 +472,7 @@ private: controlpoints.c_str(), ConstrMethod == 0 ? "False" : "True", std::min(maxDegree, SplineDegree), - geometryCreationMode == Construction ? "True" : "False"); + constructionModeAsBooleanText()); currentgeoid++; diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerBSplineByInterpolation.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerBSplineByInterpolation.h index ac3440f8b9..1401e08edc 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerBSplineByInterpolation.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerBSplineByInterpolation.h @@ -542,7 +542,7 @@ private: "(_finalbsp_poles,_finalbsp_mults,_finalbsp_knots,%s,%d,None,False),%s)", ConstrMethod == 0 ? "False" : "True", myDegree, - geometryCreationMode == Construction ? "True" : "False"); + constructionModeAsBooleanText()); currentgeoid++; // TODO: Confirm we do not need to delete individual elements diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerCarbonCopy.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerCarbonCopy.h index 14c1b44243..e7d39a912c 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerCarbonCopy.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerCarbonCopy.h @@ -154,7 +154,7 @@ public: Gui::cmdAppObjectArgs(sketchgui->getObject(), "carbonCopy(\"%s\",%s)", msg.pObjectName, - geometryCreationMode == Construction ? "True" : "False"); + constructionModeAsBooleanText()); Gui::Command::commitCommand(); diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerCircle.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerCircle.h index efae776701..1443b8ecd0 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerCircle.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerCircle.h @@ -120,7 +120,7 @@ public: EditCurve[0].x, EditCurve[0].y, sqrt(rx * rx + ry * ry), - geometryCreationMode == Construction ? "True" : "False"); + constructionModeAsBooleanText()); Gui::Command::commitCommand(); } @@ -314,7 +314,7 @@ public: CenterPoint.x, CenterPoint.y, radius, - geometryCreationMode == Construction ? "True" : "False"); + constructionModeAsBooleanText()); Gui::Command::commitCommand(); } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerEllipse.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerEllipse.h index c463e67e15..81859cef74 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerEllipse.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerEllipse.h @@ -799,7 +799,7 @@ private: positiveB.y, centroid.x, centroid.y, - geometryCreationMode == Construction ? "True" : "False"); + constructionModeAsBooleanText()); currentgeoid++; diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h index f025cacbc0..9cff7bca47 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h @@ -456,7 +456,7 @@ public: EditCurve[0].y, EditCurve[1].x, EditCurve[1].y, - geometryCreationMode == Construction ? "True" : "False"); + constructionModeAsBooleanText()); } catch (const Base::Exception&) { addedGeometry = false; @@ -486,7 +486,7 @@ public: std::abs(arcRadius), std::min(startAngle, endAngle), std::max(startAngle, endAngle), - geometryCreationMode == Construction ? "True" : "False"); + constructionModeAsBooleanText()); } catch (const Base::Exception&) { addedGeometry = false; diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h index ee8df3500a..bf30778f0b 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h @@ -131,7 +131,7 @@ public: StartPos.y, EditCurve[0].x, EditCurve[0].y, - geometryCreationMode == Construction ? "True" : "False"); + constructionModeAsBooleanText()); Gui::Command::commitCommand(); diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h index 2658e4efdd..32c903d3ae 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h @@ -275,9 +275,7 @@ public: EditCurve[34].x, EditCurve[34].y, // line2 Gui::Command::getObjectCmd(sketchgui->getObject()).c_str(), // the sketch - geometryCreationMode == Construction - ? "True" - : "False", // geometry as construction or not + constructionModeAsBooleanText(), // geometry as construction or not firstCurve, firstCurve + 2, // tangent1 firstCurve + 2, diff --git a/src/Mod/Sketcher/Gui/GeometryCreationMode.h b/src/Mod/Sketcher/Gui/GeometryCreationMode.h index 940f341bcc..20c6fc7f40 100644 --- a/src/Mod/Sketcher/Gui/GeometryCreationMode.h +++ b/src/Mod/Sketcher/Gui/GeometryCreationMode.h @@ -26,10 +26,10 @@ /***** Creation Mode ************/ namespace SketcherGui { -enum GeometryCreationMode +enum class GeometryCreationMode { - Normal, - Construction + Normal = 0, + Construction = 1 }; } diff --git a/src/Mod/Sketcher/Gui/Utils.h b/src/Mod/Sketcher/Gui/Utils.h index f191c8171b..6f2cd126f0 100644 --- a/src/Mod/Sketcher/Gui/Utils.h +++ b/src/Mod/Sketcher/Gui/Utils.h @@ -30,6 +30,7 @@ #include "AutoConstraint.h" #include "ViewProviderSketchGeometryExtension.h" +#include "GeometryCreationMode.h" namespace App @@ -146,6 +147,17 @@ inline bool isEdge(int GeoId, Sketcher::PointPos PosId) return (GeoId != Sketcher::GeoEnum::GeoUndef && PosId == Sketcher::PointPos::none); } +extern GeometryCreationMode geometryCreationMode; // defined in CommandCreateGeo.cpp + +inline bool isConstructionMode() +{ + return geometryCreationMode == GeometryCreationMode::Construction; +} + +inline const char* constructionModeAsBooleanText() +{ + return geometryCreationMode == GeometryCreationMode::Construction ? "True" : "False"; +} /* helper functions ======================================================*/