Sketcher: Make GeometryConstructionMode an enum class
===================================================== Enforce strong typing to avoid all kinds of abusive implicit conversionsm, the corresponding associated bugs and make code more readable.
This commit is contained in:
committed by
abdullahtahiriyo
parent
82fed5bbfc
commit
3f1f1047b2
@@ -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<int>(geometryCreationMode));
|
||||
|
||||
@@ -82,11 +82,11 @@ using namespace SketcherGui;
|
||||
{ \
|
||||
auto act = getAction(); \
|
||||
if (act) { \
|
||||
switch (mode) { \
|
||||
case Normal: \
|
||||
switch (static_cast<GeometryCreationMode>(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<QAction*> a = pcAction->actions();
|
||||
int index = pcAction->property("defaultAction").toInt();
|
||||
switch (mode) {
|
||||
case Normal:
|
||||
switch (static_cast<GeometryCreationMode>(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<QAction*> a = pcAction->actions();
|
||||
int index = pcAction->property("defaultAction").toInt();
|
||||
switch (mode) {
|
||||
case Normal:
|
||||
switch (static_cast<GeometryCreationMode>(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<QAction*> a = pcAction->actions();
|
||||
int index = pcAction->property("defaultAction").toInt();
|
||||
switch (mode) {
|
||||
case Normal:
|
||||
switch (static_cast<GeometryCreationMode>(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<QAction*> a = pcAction->actions();
|
||||
int index = pcAction->property("defaultAction").toInt();
|
||||
switch (mode) {
|
||||
case Normal:
|
||||
switch (static_cast<GeometryCreationMode>(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<QAction*> a = pcAction->actions();
|
||||
int index = pcAction->property("defaultAction").toInt();
|
||||
switch (mode) {
|
||||
case Normal:
|
||||
switch (static_cast<GeometryCreationMode>(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<QAction*> a = pcAction->actions();
|
||||
int index = pcAction->property("defaultAction").toInt();
|
||||
switch (mode) {
|
||||
case Normal:
|
||||
switch (static_cast<GeometryCreationMode>(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"));
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ public:
|
||||
centerPoint.y,
|
||||
startAngle,
|
||||
endAngle,
|
||||
geometryCreationMode == Construction ? "True" : "False");
|
||||
constructionModeAsBooleanText());
|
||||
|
||||
currentgeoid++;
|
||||
|
||||
|
||||
@@ -319,7 +319,7 @@ public:
|
||||
centerPoint.y,
|
||||
startAngle,
|
||||
endAngle,
|
||||
geometryCreationMode == Construction ? "True" : "False");
|
||||
constructionModeAsBooleanText());
|
||||
|
||||
currentgeoid++;
|
||||
|
||||
|
||||
@@ -246,7 +246,7 @@ public:
|
||||
axisPoint.y,
|
||||
startAngle,
|
||||
endAngle,
|
||||
geometryCreationMode == Construction ? "True" : "False");
|
||||
constructionModeAsBooleanText());
|
||||
|
||||
currentgeoid++;
|
||||
|
||||
|
||||
@@ -472,7 +472,7 @@ private:
|
||||
controlpoints.c_str(),
|
||||
ConstrMethod == 0 ? "False" : "True",
|
||||
std::min(maxDegree, SplineDegree),
|
||||
geometryCreationMode == Construction ? "True" : "False");
|
||||
constructionModeAsBooleanText());
|
||||
|
||||
currentgeoid++;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -154,7 +154,7 @@ public:
|
||||
Gui::cmdAppObjectArgs(sketchgui->getObject(),
|
||||
"carbonCopy(\"%s\",%s)",
|
||||
msg.pObjectName,
|
||||
geometryCreationMode == Construction ? "True" : "False");
|
||||
constructionModeAsBooleanText());
|
||||
|
||||
Gui::Command::commitCommand();
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -799,7 +799,7 @@ private:
|
||||
positiveB.y,
|
||||
centroid.x,
|
||||
centroid.y,
|
||||
geometryCreationMode == Construction ? "True" : "False");
|
||||
constructionModeAsBooleanText());
|
||||
|
||||
currentgeoid++;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -131,7 +131,7 @@ public:
|
||||
StartPos.y,
|
||||
EditCurve[0].x,
|
||||
EditCurve[0].y,
|
||||
geometryCreationMode == Construction ? "True" : "False");
|
||||
constructionModeAsBooleanText());
|
||||
|
||||
Gui::Command::commitCommand();
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -26,10 +26,10 @@
|
||||
/***** Creation Mode ************/
|
||||
namespace SketcherGui
|
||||
{
|
||||
enum GeometryCreationMode
|
||||
enum class GeometryCreationMode
|
||||
{
|
||||
Normal,
|
||||
Construction
|
||||
Normal = 0,
|
||||
Construction = 1
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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 ======================================================*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user