From 79fdfb2cad559b807f47d193b2858aff14991348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Br=C3=A6strup=20Sayoc?= Date: Thu, 30 Jan 2025 22:46:13 +0100 Subject: [PATCH] Remove magic number and hard type enums in CenterLine.h - Remove currently present magic numbers - Hard type enums, so magic numbers can no longer be introduced. We don't want people to introduce magic numbers. --- src/Mod/TechDraw/App/CenterLine.cpp | 68 ++++++++++---------- src/Mod/TechDraw/App/CenterLine.h | 40 ++++++++---- src/Mod/TechDraw/App/CenterLinePyImp.cpp | 10 +-- src/Mod/TechDraw/App/DrawViewPartPyImp.cpp | 2 +- src/Mod/TechDraw/Gui/TaskCenterLine.cpp | 72 +++++++++++----------- src/Mod/TechDraw/Gui/TaskCenterLine.h | 10 +-- 6 files changed, 109 insertions(+), 93 deletions(-) diff --git a/src/Mod/TechDraw/App/CenterLine.cpp b/src/Mod/TechDraw/App/CenterLine.cpp index 8ccfee8677..5f3f48627b 100644 --- a/src/Mod/TechDraw/App/CenterLine.cpp +++ b/src/Mod/TechDraw/App/CenterLine.cpp @@ -54,12 +54,12 @@ CenterLine::CenterLine() { m_start = Base::Vector3d(0.0, 0.0, 0.0); m_end = Base::Vector3d(0.0, 0.0, 0.0); - m_mode = CLMODE::VERTICAL; + m_mode = Mode::VERTICAL; m_hShift = 0.0; m_vShift = 0.0; m_rotate = 0.0; m_extendBy = 0.0; - m_type = CLTYPE::FACE; + m_type = Type::FACE; m_flip2Line = false; m_geometry = std::make_shared (); @@ -85,7 +85,7 @@ CenterLine::CenterLine(const TechDraw::CenterLine* cl) } CenterLine::CenterLine(const TechDraw::BaseGeomPtr& bg, - const int m, + const Mode m, const double h, const double v, const double r, @@ -98,7 +98,7 @@ CenterLine::CenterLine(const TechDraw::BaseGeomPtr& bg, m_vShift = v; m_rotate = r; m_extendBy = x; - m_type = CLTYPE::FACE; + m_type = Type::FACE; m_flip2Line = false; m_geometry = bg; @@ -108,7 +108,7 @@ CenterLine::CenterLine(const TechDraw::BaseGeomPtr& bg, CenterLine::CenterLine(const Base::Vector3d& pt1, const Base::Vector3d& pt2, - const int m, + const Mode m, const double h, const double v, const double r, @@ -121,7 +121,7 @@ CenterLine::CenterLine(const Base::Vector3d& pt1, m_vShift = v; m_rotate = r; m_extendBy = x; - m_type = CLTYPE::FACE; + m_type = Type::FACE; m_flip2Line = false; m_geometry = BaseGeomPtrFromVectors(pt1, pt2); @@ -159,7 +159,7 @@ TechDraw::BaseGeomPtr CenterLine::BaseGeomPtrFromVectors(Base::Vector3d pt1, Bas CenterLine* CenterLine::CenterLineBuilder(const DrawViewPart* partFeat, const std::vector& subNames, - const int mode, + const Mode mode, const bool flip) { // Base::Console().Message("CL::CLBuilder()\n - subNames: %d\n", subNames.size()); @@ -169,9 +169,9 @@ CenterLine* CenterLine::CenterLineBuilder(const DrawViewPart* partFeat, std::vector verts; std::string geomType = TechDraw::DrawUtil::getGeomTypeFromName(subNames.front()); - int type = CLTYPE::FACE; + Type type = Type::FACE; if (geomType == "Face") { - type = CLTYPE::FACE; + type = Type::FACE; ends = TechDraw::CenterLine::calcEndPoints(partFeat, subNames, mode, @@ -179,7 +179,7 @@ CenterLine* CenterLine::CenterLineBuilder(const DrawViewPart* partFeat, 0.0, 0.0, 0.0); faces = subNames; } else if (geomType == "Edge") { - type = CLTYPE::EDGE; + type = Type::EDGE; ends = TechDraw::CenterLine::calcEndPoints2Lines(partFeat, subNames, mode, @@ -187,7 +187,7 @@ CenterLine* CenterLine::CenterLineBuilder(const DrawViewPart* partFeat, 0.0, 0.0, 0.0, flip); edges = subNames; } else if (geomType == "Vertex") { - type = CLTYPE::VERTEX; + type = Type::VERTEX; ends = TechDraw::CenterLine::calcEndPoints2Points(partFeat, subNames, mode, @@ -229,18 +229,18 @@ TechDraw::BaseGeomPtr CenterLine::scaledGeometry(const TechDraw::DrawViewPart* p //CenterLine was created by points without a geometry reference, ends = calcEndPointsNoRef(m_start, m_end, scale, m_extendBy, m_hShift, m_vShift, m_rotate, viewAngleDeg); - } else if (m_type == CLTYPE::FACE) { + } else if (m_type == Type::FACE) { ends = calcEndPoints(partFeat, m_faces, m_mode, m_extendBy, m_hShift, m_vShift, m_rotate); - } else if (m_type == CLTYPE::EDGE) { + } else if (m_type == Type::EDGE) { ends = calcEndPoints2Lines(partFeat, m_edges, m_mode, m_extendBy, m_hShift, m_vShift, m_rotate, m_flip2Line); - } else if (m_type == CLTYPE::VERTEX) { + } else if (m_type == Type::VERTEX) { ends = calcEndPoints2Points(partFeat, m_verts, m_mode, @@ -291,18 +291,18 @@ TechDraw::BaseGeomPtr CenterLine::scaledAndRotatedGeometry(TechDraw::DrawViewPar //CenterLine was created by points without a geometry reference, ends = calcEndPointsNoRef(m_start, m_end, scale, m_extendBy, m_hShift, m_vShift, m_rotate, viewAngleDeg); - } else if (m_type == CLTYPE::FACE) { + } else if (m_type == Type::FACE) { ends = calcEndPoints(partFeat, m_faces, m_mode, m_extendBy, m_hShift, m_vShift, m_rotate); - } else if (m_type == CLTYPE::EDGE) { + } else if (m_type == Type::EDGE) { ends = calcEndPoints2Lines(partFeat, m_edges, m_mode, m_extendBy, m_hShift, m_vShift, m_rotate, m_flip2Line); - } else if (m_type == CLTYPE::VERTEX) { + } else if (m_type == Type::VERTEX) { ends = calcEndPoints2Points(partFeat, m_verts, m_mode, @@ -326,7 +326,7 @@ TechDraw::BaseGeomPtr CenterLine::scaledAndRotatedGeometry(TechDraw::DrawViewPar } TopoDS_Edge newEdge; - if (getType() == CLTYPE::FACE ) { + if (getType() == Type::FACE ) { gp_Pnt gp1(DU::to(p1)); gp_Pnt gp2(DU::to(p2)); TopoDS_Edge e = BRepBuilderAPI_MakeEdge(gp1, gp2); @@ -335,8 +335,8 @@ TechDraw::BaseGeomPtr CenterLine::scaledAndRotatedGeometry(TechDraw::DrawViewPar // rotate using OXYZ as the coordinate system s = ShapeUtils::rotateShape(s, gp_Ax2(), - partFeat->Rotation.getValue()); newEdge = TopoDS::Edge(s); - } else if (getType() == CLTYPE::EDGE || - getType() == CLTYPE::VERTEX) { + } else if (getType() == Type::EDGE || + getType() == Type::VERTEX) { gp_Pnt gp1(DU::to(DU::invertY(p1 * scale))); gp_Pnt gp2(DU::to(DU::invertY(p2 * scale))); newEdge = BRepBuilderAPI_MakeEdge(gp1, gp2); @@ -464,7 +464,7 @@ std::pair CenterLine::calcEndPointsNoRef(const B //end points for face centerline std::pair CenterLine::calcEndPoints(const DrawViewPart* partFeat, const std::vector& faceNames, - const int mode, + const CenterLine::Mode mode, const double ext, const double hShift, const double vShift, @@ -534,13 +534,13 @@ std::pair CenterLine::calcEndPoints(const DrawVi Ymin = Ymid - Yspan; Base::Vector3d p1, p2; - if (mode == CenterLine::VERTICAL) { //vertical + if (mode == Mode::VERTICAL) { //vertical p1 = Base::Vector3d(Xmid, Ymax, 0.0); p2 = Base::Vector3d(Xmid, Ymin, 0.0); - } else if (mode == CenterLine::HORIZONTAL) { //horizontal + } else if (mode == Mode::HORIZONTAL) { //horizontal p1 = Base::Vector3d(Xmin, Ymid, 0.0); p2 = Base::Vector3d(Xmax, Ymid, 0.0); - } else { //vert == CenterLine::ALIGNED //aligned, but aligned doesn't make sense for face(s) bbox + } else { //vert == Mode::ALIGNED //aligned, but aligned doesn't make sense for face(s) bbox Base::Console().Message("CL::calcEndPoints - aligned is not applicable to Face center lines\n"); p1 = Base::Vector3d(Xmid, Ymax, 0.0); p2 = Base::Vector3d(Xmid, Ymin, 0.0); @@ -586,7 +586,7 @@ std::pair CenterLine::calcEndPoints(const DrawVi std::pair CenterLine::calcEndPoints2Lines(const DrawViewPart* partFeat, const std::vector& edgeNames, - const int mode, + const Mode mode, const double ext, const double hShift, const double vShift, @@ -663,13 +663,13 @@ std::pair CenterLine::calcEndPoints2Lines(const //orientation if (partFeat->Rotation.getValue() == 0.0) { // if the view is rotated, then horizontal and vertical lose their meaning - if (mode == 0 && !inhibitVertical) { //Vertical + if (mode == CenterLine::Mode::VERTICAL && !inhibitVertical) { p1.x = mid.x; p2.x = mid.x; - } else if (mode == 1 && !inhibitHorizontal) { //Horizontal + } else if (mode == CenterLine::Mode::HORIZONTAL && !inhibitHorizontal) { p1.y = mid.y; p2.y = mid.y; - } else if (mode == 2) { //Aligned + } else if (mode == CenterLine::Mode::ALIGNED) { // no op } } @@ -706,7 +706,7 @@ std::pair CenterLine::calcEndPoints2Lines(const std::pair CenterLine::calcEndPoints2Points(const DrawViewPart* partFeat, const std::vector& vertNames, - const int mode, + const Mode mode, const double ext, const double hShift, const double vShift, @@ -760,15 +760,15 @@ std::pair CenterLine::calcEndPoints2Points(const //orientation if (partFeat->Rotation.getValue() == 0.0) { // if the view is rotated, then horizontal and vertical lose their meaning - if (mode == CenterLine::VERTICAL && !inhibitVertical) { + if (mode == Mode::VERTICAL && !inhibitVertical) { //Vertical v1.x = mid.x; v2.x = mid.x; - } else if (mode == CenterLine::HORIZONTAL && !inhibitHorizontal) { + } else if (mode == Mode::HORIZONTAL && !inhibitHorizontal) { //Horizontal v1.y = mid.y; v2.y = mid.y; - } else if (mode == CenterLine::ALIGNED) { //Aligned + } else if (mode == Mode::ALIGNED) { //Aligned // no op } } @@ -936,7 +936,7 @@ void CenterLine::Restore(Base::XMLReader &reader) m_end.z = reader.getAttributeAsFloat("Z"); reader.readElement("Mode"); - m_mode = reader.getAttributeAsInteger("value"); + m_mode = static_cast(reader.getAttributeAsInteger("value")); reader.readElement("HShift"); m_hShift = reader.getAttributeAsFloat("value"); @@ -947,7 +947,7 @@ void CenterLine::Restore(Base::XMLReader &reader) reader.readElement("Extend"); m_extendBy = reader.getAttributeAsFloat("value"); reader.readElement("Type"); - m_type = reader.getAttributeAsInteger("value"); + m_type = static_cast(reader.getAttributeAsInteger("value")); reader.readElement("Flip"); m_flip2Line = (bool)reader.getAttributeAsInteger("value")==0?false:true; diff --git a/src/Mod/TechDraw/App/CenterLine.h b/src/Mod/TechDraw/App/CenterLine.h index 98c0b4a3e0..2c54fb8b19 100644 --- a/src/Mod/TechDraw/App/CenterLine.h +++ b/src/Mod/TechDraw/App/CenterLine.h @@ -40,30 +40,44 @@ class TechDrawExport CenterLine: public Base::Persistence TYPESYSTEM_HEADER_WITH_OVERRIDE(); public: - enum CLMODE + enum class Mode { VERTICAL, HORIZONTAL, ALIGNED }; - enum CLTYPE + // TODO: when C++ 20 + // using Mode; + enum class Type { FACE, EDGE, VERTEX - }; + }; // TODO: Make this global + // TODO: when C++ 20 + // using Mode; + + template || + std::is_same_v, + bool + > =true> + friend std::ostream& operator<<(std::ostream& out, const U& type) { + out << static_cast(type); + return out; + } CenterLine(); CenterLine(const CenterLine* cl); //set m_faces after using next 3 ctors CenterLine(const TechDraw::BaseGeomPtr& bg, - const int m = CLMODE::VERTICAL, + const Mode m = Mode::VERTICAL, const double h = 0.0, const double v = 0.0, const double r = 0.0, const double x = 0.0); CenterLine(const Base::Vector3d& p1, const Base::Vector3d& p2, - const int m = CLMODE::VERTICAL, + const Mode m = Mode::VERTICAL, const double h = 0.0, const double v = 0.0, const double r = 0.0, @@ -85,7 +99,7 @@ public: static CenterLine* CenterLineBuilder(const TechDraw::DrawViewPart* partFeat, const std::vector& subs, - const int mode = 0, + const Mode mode = Mode::VERTICAL, const bool flip = false); TechDraw::BaseGeomPtr scaledGeometry(const TechDraw::DrawViewPart* partFeat); TechDraw::BaseGeomPtr scaledAndRotatedGeometry(TechDraw::DrawViewPart* partFeat); @@ -107,7 +121,7 @@ public: static std::pair calcEndPoints( const TechDraw::DrawViewPart* partFeat, const std::vector& faceNames, - const int mode, + const Mode mode, const double ext, const double m_hShift, const double m_vShift, @@ -115,7 +129,7 @@ public: static std::pair calcEndPoints2Lines( const TechDraw::DrawViewPart* partFeat, const std::vector& faceNames, - const int vert, + const Mode mode, const double ext, const double m_hShift, const double m_vShift, @@ -124,7 +138,7 @@ public: static std::pair calcEndPoints2Points( const TechDraw::DrawViewPart* partFeat, const std::vector& faceNames, - const int vert, + const Mode mode, const double ext, const double m_hShift, const double m_vShift, @@ -140,8 +154,8 @@ public: double getExtend() const; void setFlip(const bool f); bool getFlip() const; - void setType(const int type) { m_type = type; }; - int getType() const { return m_type; } + void setType(const Type type) { m_type = type; }; + Type getType() const { return m_type; } Base::Vector3d m_start; Base::Vector3d m_end; @@ -150,8 +164,8 @@ public: std::vector m_faces; std::vector m_edges; std::vector m_verts; - int m_type; // CLTYPE enum - int m_mode; // CLMODE enum + Type m_type; + Mode m_mode; double m_hShift; double m_vShift; double m_rotate; diff --git a/src/Mod/TechDraw/App/CenterLinePyImp.cpp b/src/Mod/TechDraw/App/CenterLinePyImp.cpp index 0af9035da7..6904e77c5e 100644 --- a/src/Mod/TechDraw/App/CenterLinePyImp.cpp +++ b/src/Mod/TechDraw/App/CenterLinePyImp.cpp @@ -153,20 +153,20 @@ Py::String CenterLinePy::getTag() const Py::Long CenterLinePy::getType() const { - int tmp = getCenterLinePtr()->m_type; - return Py::Long(tmp); + CenterLine::Type tmp = getCenterLinePtr()->m_type; + return Py::Long(static_cast(tmp)); } Py::Long CenterLinePy::getMode() const { - int tmp = getCenterLinePtr()->m_mode; - return Py::Long(tmp); + CenterLine::Mode tmp = getCenterLinePtr()->m_mode; + return Py::Long(static_cast(tmp)); } void CenterLinePy::setMode(Py::Long arg) { int temp = static_cast(arg); - getCenterLinePtr()->m_mode = temp; + getCenterLinePtr()->m_mode = static_cast(temp); } Py::Float CenterLinePy::getHorizShift() const diff --git a/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp b/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp index df140a5b13..a0fb6a91f5 100644 --- a/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp +++ b/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp @@ -658,7 +658,7 @@ PyObject* DrawViewPartPy::makeCenterLine(PyObject *args) { // Base::Console().Message("DVPPI::makeCenterLine()\n"); PyObject* pSubs; - int mode = 0; + CenterLine::Mode mode = CenterLine::Mode::VERTICAL; std::vector subs; if (!PyArg_ParseTuple(args, "O!i", &PyList_Type, &pSubs, &mode)) { diff --git a/src/Mod/TechDraw/Gui/TaskCenterLine.cpp b/src/Mod/TechDraw/Gui/TaskCenterLine.cpp index 903a13de81..6f20181c83 100644 --- a/src/Mod/TechDraw/Gui/TaskCenterLine.cpp +++ b/src/Mod/TechDraw/Gui/TaskCenterLine.cpp @@ -48,6 +48,8 @@ using namespace Gui; using namespace TechDraw; using namespace TechDrawGui; using DU = DrawUtil; +using Mode = CenterLine::Mode; +using Type = CenterLine::Type; //ctor for edit TaskCenterLine::TaskCenterLine(TechDraw::DrawViewPart* partFeat, @@ -61,8 +63,8 @@ TaskCenterLine::TaskCenterLine(TechDraw::DrawViewPart* partFeat, m_btnOK(nullptr), m_btnCancel(nullptr), m_edgeName(edgeName), - m_type(CenterLine::FACE), - m_mode(CenterLine::VERTICAL), + m_type(Type::FACE), + m_mode(Mode::VERTICAL), m_editMode(editMode) { ui->setupUi(this); @@ -97,8 +99,8 @@ TaskCenterLine::TaskCenterLine(TechDraw::DrawViewPart* partFeat, m_subNames(subNames), m_geomIndex(0), m_cl(nullptr), - m_type(CenterLine::FACE), - m_mode(CenterLine::VERTICAL), + m_type(Type::FACE), + m_mode(Mode::VERTICAL), m_editMode(editMode) { //existence of page and feature are checked by isActive method of calling command @@ -107,11 +109,11 @@ TaskCenterLine::TaskCenterLine(TechDraw::DrawViewPart* partFeat, std::string check = subNames.front(); std::string geomType = TechDraw::DrawUtil::getGeomTypeFromName(check); if (geomType == "Face") { - m_type = CenterLine::FACE; + m_type = Type::FACE; } else if (geomType == "Edge") { - m_type = CenterLine::EDGE; + m_type = Type::EDGE; } else if (geomType == "Vertex") { - m_type = CenterLine::VERTEX; + m_type = Type::VERTEX; } else { Base::Console().Error("TaskCenterLine - unknown geometry type: %s. Can not proceed.\n", geomType.c_str()); return; @@ -143,7 +145,7 @@ void TaskCenterLine::changeEvent(QEvent *event) void TaskCenterLine::setUiConnect() { // first enabling/disabling - if (m_type == CenterLine::FACE) // if face, then aligned is not possible + if (m_type == Type::FACE) // if face, then aligned is not possible ui->rbAligned->setEnabled(false); else ui->rbAligned->setEnabled(true); @@ -196,12 +198,12 @@ void TaskCenterLine::setUiPrimary() int precision = Base::UnitsApi::getDecimals(); ui->qsbRotate->setDecimals(precision); - if (m_type == CenterLine::EDGE) { - int orientation = checkPathologicalEdges(m_mode); + if (m_type == Type::EDGE) { + Mode orientation = checkPathologicalEdges(m_mode); setUiOrientation(orientation); } - if (m_type == CenterLine::VERTEX) { - int orientation = checkPathologicalVertices(m_mode); + if (m_type == Type::VERTEX) { + Mode orientation = checkPathologicalVertices(m_mode); setUiOrientation(orientation); } } @@ -226,11 +228,11 @@ void TaskCenterLine::setUiEdit() ui->rbVertical->setChecked(false); ui->rbHorizontal->setChecked(false); ui->rbAligned->setChecked(false); - if (m_cl->m_mode == CenterLine::VERTICAL) + if (m_cl->m_mode == Mode::VERTICAL) ui->rbVertical->setChecked(true); - else if (m_cl->m_mode == CenterLine::HORIZONTAL) + else if (m_cl->m_mode == Mode::HORIZONTAL) ui->rbHorizontal->setChecked(true); - else if (m_cl->m_mode == CenterLine::ALIGNED) + else if (m_cl->m_mode == Mode::ALIGNED) ui->rbAligned->setChecked(true); Base::Quantity qVal; @@ -256,14 +258,14 @@ void TaskCenterLine::onOrientationChanged() return; } if (ui->rbVertical->isChecked()) - m_cl->m_mode = CenterLine::CLMODE::VERTICAL; + m_cl->m_mode = Mode::VERTICAL; else if (ui->rbHorizontal->isChecked()) - m_cl->m_mode = CenterLine::CLMODE::HORIZONTAL; + m_cl->m_mode = Mode::HORIZONTAL; else if (ui->rbAligned->isChecked()) - m_cl->m_mode = CenterLine::CLMODE::ALIGNED; + m_cl->m_mode = Mode::ALIGNED; // for centerlines between 2 lines we cannot just recompute // because the new orientation might lead to an invalid centerline - if (m_type == CenterLine::EDGE) + if (m_type == Type::EDGE) updateOrientation(); else m_partFeat->recomputeFeature(); @@ -343,9 +345,9 @@ void TaskCenterLine::onStyleChanged() // check that we are not trying to create an impossible centerline (ex a vertical centerline // between 2 horizontal edges) -int TaskCenterLine::checkPathologicalEdges(int inMode) +Mode TaskCenterLine::checkPathologicalEdges(Mode inMode) { - if (m_type != CenterLine::EDGE) { + if (m_type != Type::EDGE) { // not an edge based centerline, this doesn't apply return inMode; } @@ -361,10 +363,10 @@ int TaskCenterLine::checkPathologicalEdges(int inMode) bool edge2Horizontal = DU::fpCompare(ends2.front().y, ends2.back().y, EWTOLERANCE); if (edge1Vertical && edge2Vertical) { - return CenterLine::CLMODE::VERTICAL; + return Mode::VERTICAL; } if (edge1Horizontal && edge2Horizontal) { - return CenterLine::CLMODE::HORIZONTAL; + return Mode::HORIZONTAL; } // not pathological case, just return the input mode @@ -373,9 +375,9 @@ int TaskCenterLine::checkPathologicalEdges(int inMode) // check that we are not trying to create an impossible centerline (ex a vertical centerline // between 2 vertices aligned vertically) -int TaskCenterLine::checkPathologicalVertices(int inMode) +Mode TaskCenterLine::checkPathologicalVertices(Mode inMode) { - if (m_type != CenterLine::VERTEX) { + if (m_type != Type::VERTEX) { // not a vertex based centerline, this doesn't apply return inMode; } @@ -387,12 +389,12 @@ int TaskCenterLine::checkPathologicalVertices(int inMode) if (DU::fpCompare(point1.x, point2.x, EWTOLERANCE)) { // points are aligned vertically, CL must be horizontal - return CenterLine::CLMODE::HORIZONTAL; + return Mode::HORIZONTAL; } if (DU::fpCompare(point1.y, point2.y, EWTOLERANCE)) { // points are aligned horizontally, CL must be vertical - return CenterLine::CLMODE::VERTICAL; + return Mode::VERTICAL; } // not pathological case, just return the input mode @@ -405,10 +407,10 @@ void TaskCenterLine::createCenterLine() Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Centerline")); // check for illogical parameters - if (m_type == CenterLine::EDGE) { + if (m_type == Type::EDGE) { // between lines m_mode = checkPathologicalEdges(m_mode); - } else if (m_type == CenterLine::VERTEX) { + } else if (m_type == Type::VERTEX) { // between points m_mode = checkPathologicalVertices(m_mode); } @@ -455,15 +457,15 @@ void TaskCenterLine::updateOrientation() // this can lead to a crash, see e.g. // https://forum.freecad.org/viewtopic.php?f=35&t=44255&start=20#p503220 // The centerline creation can fail if m_type is edge and both selected edges are vertical or horizontal. - int orientation = m_cl->m_mode; - if (m_type == CenterLine::EDGE) { + Mode orientation = m_cl->m_mode; + if (m_type == Type::EDGE) { // between lines if (!m_edgeName.empty() && !m_cl->m_edges.empty()) { // we have an existing centerline, not a freshly created one, and it is a centerline between edges m_subNames = m_cl->m_edges; orientation = checkPathologicalEdges(orientation); } - } else if (m_type == CenterLine::VERTEX) { + } else if (m_type == Type::VERTEX) { // between points if (!m_edgeName.empty() && !m_cl->m_verts.empty()) { // we have an existing centerline, not a freshly created one, and it is a centerline between points @@ -477,15 +479,15 @@ void TaskCenterLine::updateOrientation() m_partFeat->recomputeFeature(); } -void TaskCenterLine::setUiOrientation(int orientation) +void TaskCenterLine::setUiOrientation(Mode orientation) { ui->rbVertical->blockSignals(true); ui->rbVertical->blockSignals(true); - if (orientation == CenterLine::CLMODE::VERTICAL) { + if (orientation == Mode::VERTICAL) { ui->rbVertical->setChecked(true); ui->rbHorizontal->setChecked(false); - } else if (orientation == CenterLine::CLMODE::HORIZONTAL) { + } else if (orientation == Mode::HORIZONTAL) { ui->rbVertical->setChecked(false); ui->rbHorizontal->setChecked(true); } diff --git a/src/Mod/TechDraw/Gui/TaskCenterLine.h b/src/Mod/TechDraw/Gui/TaskCenterLine.h index 10ccb2715f..2515e97d5e 100644 --- a/src/Mod/TechDraw/Gui/TaskCenterLine.h +++ b/src/Mod/TechDraw/Gui/TaskCenterLine.h @@ -87,9 +87,9 @@ protected: QColor getCenterColor(); double getExtendBy(); - int checkPathologicalEdges(int inMode); - int checkPathologicalVertices(int inMode); - void setUiOrientation(int orientation); + TechDraw::CenterLine::Mode checkPathologicalEdges(TechDraw::CenterLine::Mode inMode); + TechDraw::CenterLine::Mode checkPathologicalVertices(TechDraw::CenterLine::Mode inMode); + void setUiOrientation(TechDraw::CenterLine::Mode orientation); private: std::unique_ptr ui; @@ -106,8 +106,8 @@ private: int m_geomIndex; TechDraw::CenterLine* m_cl; TechDraw::CenterLine orig_cl; - int m_type; - int m_mode; + TechDraw::CenterLine::Type m_type; + TechDraw::CenterLine::Mode m_mode; bool m_editMode; private Q_SLOTS: