From 791fe029341aa1dda42376620d52c67ecaca7eea Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sat, 2 Sep 2023 12:32:58 -0500 Subject: [PATCH] Sketcher: Reformat to current clang-format standard --- src/Mod/Sketcher/App/Analyse.h | 6 +- src/Mod/Sketcher/App/AppSketcher.cpp | 20 +- src/Mod/Sketcher/App/AppSketcherPy.cpp | 12 +- src/Mod/Sketcher/App/Constraint.cpp | 51 +++-- src/Mod/Sketcher/App/ConstraintPyImp.cpp | 52 +++-- .../App/ExternalGeometryExtensionPyImp.cpp | 6 +- .../Sketcher/App/ExternalGeometryFacade.cpp | 36 +-- src/Mod/Sketcher/App/ExternalGeometryFacade.h | 14 +- .../App/ExternalGeometryFacadePyImp.cpp | 23 +- src/Mod/Sketcher/App/GeoEnum.h | 12 +- src/Mod/Sketcher/App/GeoList.cpp | 161 +++++++++----- src/Mod/Sketcher/App/GeoList.h | 4 +- src/Mod/Sketcher/App/GeometryFacade.cpp | 37 ++-- src/Mod/Sketcher/App/GeometryFacade.h | 14 +- src/Mod/Sketcher/App/GeometryFacadePyImp.cpp | 20 +- .../Sketcher/App/PropertyConstraintList.cpp | 126 +++++++---- src/Mod/Sketcher/App/PythonConverter.cpp | 9 +- src/Mod/Sketcher/App/Sketch.h | 101 ++++++--- src/Mod/Sketcher/App/SketchAnalysis.cpp | 64 ++++-- src/Mod/Sketcher/App/SketchAnalysis.h | 3 +- .../Sketcher/App/SketchGeometryExtension.cpp | 18 +- .../App/SketchGeometryExtensionPyImp.cpp | 9 +- src/Mod/Sketcher/App/SketchObject.h | 144 ++++++++---- src/Mod/Sketcher/App/SketchObjectPyImp.cpp | 79 +++++-- src/Mod/Sketcher/App/SketchObjectSF.cpp | 3 +- src/Mod/Sketcher/App/SketchObjectSFPy.xml | 16 +- src/Mod/Sketcher/App/SketchPyImp.cpp | 29 ++- .../Sketcher/App/SolverGeometryExtension.cpp | 24 +- .../Sketcher/App/SolverGeometryExtension.h | 21 +- src/Mod/Sketcher/App/planegcs/SubSystem.cpp | 60 +++-- src/Mod/Sketcher/App/planegcs/qp_eq.cpp | 6 +- src/Mod/Sketcher/App/planegcs/qp_eq.h | 9 +- src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp | 5 +- src/Mod/Sketcher/Gui/CommandConstraints.h | 30 ++- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 208 +++++++++++------- .../Sketcher/Gui/CommandSketcherBSpline.cpp | 72 +++--- .../Sketcher/Gui/CommandSketcherOverlay.cpp | 21 +- .../Gui/CommandSketcherVirtualSpace.cpp | 15 +- src/Mod/Sketcher/Gui/ConstraintFilters.h | 57 +++-- src/Mod/Sketcher/Gui/DrawSketchHandler.cpp | 142 +++++++----- src/Mod/Sketcher/Gui/DrawSketchHandler.h | 20 +- src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h | 9 +- .../Gui/DrawSketchHandlerArcOfEllipse.h | 25 ++- .../Gui/DrawSketchHandlerArcOfHyperbola.h | 14 +- .../Gui/DrawSketchHandlerArcOfParabola.h | 5 +- .../Sketcher/Gui/DrawSketchHandlerBSpline.h | 32 ++- .../DrawSketchHandlerBSplineByInterpolation.h | 38 ++-- .../Gui/DrawSketchHandlerCarbonCopy.h | 6 +- .../Sketcher/Gui/DrawSketchHandlerCircle.h | 18 +- .../Sketcher/Gui/DrawSketchHandlerEllipse.h | 43 ++-- .../Sketcher/Gui/DrawSketchHandlerExtend.h | 15 +- .../Sketcher/Gui/DrawSketchHandlerExternal.h | 12 +- .../Sketcher/Gui/DrawSketchHandlerFillet.h | 43 ++-- src/Mod/Sketcher/Gui/DrawSketchHandlerLine.h | 8 +- .../Sketcher/Gui/DrawSketchHandlerLineSet.h | 127 +++++++---- .../Sketcher/Gui/DrawSketchHandlerPolygon.h | 10 +- .../Sketcher/Gui/DrawSketchHandlerRectangle.h | 36 +-- src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h | 39 ++-- .../Sketcher/Gui/DrawSketchHandlerSplitting.h | 12 +- .../Sketcher/Gui/DrawSketchHandlerTrimming.h | 18 +- src/Mod/Sketcher/Gui/EditDatumDialog.cpp | 31 ++- src/Mod/Sketcher/Gui/EditModeCoinManager.cpp | 101 ++++++--- .../Gui/EditModeCoinManagerParameters.cpp | 12 +- .../Gui/EditModeCoinManagerParameters.h | 7 +- .../Gui/EditModeConstraintCoinManager.h | 19 +- .../Gui/EditModeGeometryCoinConverter.cpp | 72 ++++-- .../Gui/EditModeGeometryCoinConverter.h | 3 +- .../Gui/EditModeGeometryCoinManager.cpp | 79 ++++--- .../Gui/EditModeGeometryCoinManager.h | 3 +- ...ditModeInformationOverlayCoinConverter.cpp | 72 ++++-- .../EditModeInformationOverlayCoinConverter.h | 3 +- .../Gui/PropertyConstraintListItem.cpp | 15 +- .../Sketcher/Gui/PropertyConstraintListItem.h | 4 +- .../Resources/translations/Sketcher_fil.ts | 4 +- .../Gui/Resources/translations/Sketcher_lt.ts | 2 +- .../Sketcher/Gui/SketchOrientationDialog.cpp | 18 +- src/Mod/Sketcher/Gui/SketcherSettings.cpp | 61 ++--- src/Mod/Sketcher/Gui/SnapManager.cpp | 3 +- src/Mod/Sketcher/Gui/TaskDlgEditSketch.cpp | 25 ++- src/Mod/Sketcher/Gui/TaskSketcherMessages.h | 4 +- .../Gui/TaskSketcherSolverAdvanced.cpp | 16 +- .../Sketcher/Gui/TaskSketcherValidation.cpp | 82 ++++--- src/Mod/Sketcher/Gui/Utils.cpp | 112 ++++++---- src/Mod/Sketcher/Gui/Utils.h | 33 ++- src/Mod/Sketcher/Gui/ViewProviderSketch.h | 35 +-- .../Gui/ViewProviderSketchCoinAttorney.h | 6 +- .../ViewProviderSketchGeometryExtension.cpp | 3 +- ...ewProviderSketchGeometryExtensionPyImp.cpp | 3 +- src/Mod/Sketcher/Gui/VisualLayer.h | 3 +- src/Mod/Sketcher/Gui/Workbench.cpp | 12 +- src/Mod/Sketcher/InitGui.py | 3 +- src/Mod/Sketcher/ProfileLib/Hexagon.py | 88 ++++---- src/Mod/Sketcher/ProfileLib/RegularPolygon.py | 108 +++++---- src/Mod/Sketcher/Profiles.py | 4 +- src/Mod/Sketcher/Templates/Sketch.skf | 1 - src/Mod/Sketcher/sketcher.dox | 1 - 96 files changed, 2132 insertions(+), 1185 deletions(-) diff --git a/src/Mod/Sketcher/App/Analyse.h b/src/Mod/Sketcher/App/Analyse.h index 3e558c3db0..90b8849ba3 100644 --- a/src/Mod/Sketcher/App/Analyse.h +++ b/src/Mod/Sketcher/App/Analyse.h @@ -53,11 +53,13 @@ struct Constraint_Equal bool operator()(const ConstraintIds& x) const { if (c.First == x.First && c.FirstPos == x.FirstPos && c.Second == x.Second - && c.SecondPos == x.SecondPos) + && c.SecondPos == x.SecondPos) { return true; + } if (c.Second == x.First && c.SecondPos == x.FirstPos && c.First == x.Second - && c.FirstPos == x.SecondPos) + && c.FirstPos == x.SecondPos) { return true; + } return false; } }; diff --git a/src/Mod/Sketcher/App/AppSketcher.cpp b/src/Mod/Sketcher/App/AppSketcher.cpp index 62f7b0dfa1..a1190b4c25 100644 --- a/src/Mod/Sketcher/App/AppSketcher.cpp +++ b/src/Mod/Sketcher/App/AppSketcher.cpp @@ -65,14 +65,18 @@ PyMOD_INIT_FUNC(Sketcher) // Add Types to module Base::Interpreter().addType(&Sketcher::ConstraintPy ::Type, sketcherModule, "Constraint"); Base::Interpreter().addType(&Sketcher::SketchPy ::Type, sketcherModule, "Sketch"); - Base::Interpreter().addType( - &Sketcher::ExternalGeometryExtensionPy ::Type, sketcherModule, "ExternalGeometryExtension"); - Base::Interpreter().addType( - &Sketcher::SketchGeometryExtensionPy ::Type, sketcherModule, "SketchGeometryExtension"); - Base::Interpreter().addType( - &Sketcher::GeometryFacadePy ::Type, sketcherModule, "GeometryFacade"); - Base::Interpreter().addType( - &Sketcher::ExternalGeometryFacadePy ::Type, sketcherModule, "ExternalGeometryFacade"); + Base::Interpreter().addType(&Sketcher::ExternalGeometryExtensionPy ::Type, + sketcherModule, + "ExternalGeometryExtension"); + Base::Interpreter().addType(&Sketcher::SketchGeometryExtensionPy ::Type, + sketcherModule, + "SketchGeometryExtension"); + Base::Interpreter().addType(&Sketcher::GeometryFacadePy ::Type, + sketcherModule, + "GeometryFacade"); + Base::Interpreter().addType(&Sketcher::ExternalGeometryFacadePy ::Type, + sketcherModule, + "ExternalGeometryFacade"); // NOTE: To finish the initialization of our own type objects we must diff --git a/src/Mod/Sketcher/App/AppSketcherPy.cpp b/src/Mod/Sketcher/App/AppSketcherPy.cpp index 406dcadb05..4991f0a0be 100644 --- a/src/Mod/Sketcher/App/AppSketcherPy.cpp +++ b/src/Mod/Sketcher/App/AppSketcherPy.cpp @@ -52,8 +52,9 @@ private: Py::Object open(const Py::Tuple& args) { char* Name; - if (!PyArg_ParseTuple(args.ptr(), "et", "utf-8", &Name)) + if (!PyArg_ParseTuple(args.ptr(), "et", "utf-8", &Name)) { throw Py::Exception(); + } std::string EncodedName = std::string(Name); PyMem_Free(Name); @@ -61,8 +62,9 @@ private: Base::FileInfo file(EncodedName.c_str()); // extract extension - if (file.extension().empty()) + if (file.extension().empty()) { throw Py::RuntimeError("No file extension"); + } throw Py::RuntimeError("Unknown file extension"); // return Py::None(); @@ -72,8 +74,9 @@ private: { char* Name; const char* DocName; - if (!PyArg_ParseTuple(args.ptr(), "ets", "utf-8", &Name, &DocName)) + if (!PyArg_ParseTuple(args.ptr(), "ets", "utf-8", &Name, &DocName)) { throw Py::Exception(); + } std::string EncodedName = std::string(Name); PyMem_Free(Name); @@ -82,8 +85,9 @@ private: Base::FileInfo file(EncodedName.c_str()); // extract extension - if (file.extension().empty()) + if (file.extension().empty()) { throw Py::RuntimeError("No file extension"); + } App::Document* pcDoc = App::GetApplication().getDocument(DocName); if (!pcDoc) { diff --git a/src/Mod/Sketcher/App/Constraint.cpp b/src/Mod/Sketcher/App/Constraint.cpp index 9e4bfd9cd2..ae8327a8b5 100644 --- a/src/Mod/Sketcher/App/Constraint.cpp +++ b/src/Mod/Sketcher/App/Constraint.cpp @@ -41,21 +41,21 @@ using namespace Base; TYPESYSTEM_SOURCE(Sketcher::Constraint, Base::Persistence) Constraint::Constraint() - : Value(0.0), - Type(None), - AlignmentType(Undef), - First(GeoEnum::GeoUndef), - FirstPos(PointPos::none), - Second(GeoEnum::GeoUndef), - SecondPos(PointPos::none), - Third(GeoEnum::GeoUndef), - ThirdPos(PointPos::none), - LabelDistance(10.f), - LabelPosition(0.f), - isDriving(true), - InternalAlignmentIndex(-1), - isInVirtualSpace(false), - isActive(true) + : Value(0.0) + , Type(None) + , AlignmentType(Undef) + , First(GeoEnum::GeoUndef) + , FirstPos(PointPos::none) + , Second(GeoEnum::GeoUndef) + , SecondPos(PointPos::none) + , Third(GeoEnum::GeoUndef) + , ThirdPos(PointPos::none) + , LabelDistance(10.f) + , LabelPosition(0.f) + , isDriving(true) + , InternalAlignmentIndex(-1) + , isInVirtualSpace(false) + , isActive(true) { // Initialize a random number generator, to avoid Valgrind false positives. static boost::mt19937 ran; @@ -147,9 +147,10 @@ void Constraint::Save(Writer& writer) const writer.Stream() << writer.ind() << "Type == InternalAlignment) + if (this->Type == InternalAlignment) { writer.Stream() << "InternalAlignmentType=\"" << (int)AlignmentType << "\" " << "InternalAlignmentIndex=\"" << InternalAlignmentIndex << "\" "; + } writer.Stream() << "Value=\"" << Value << "\" " << "First=\"" << First << "\" " << "FirstPos=\"" << (int)FirstPos << "\" " @@ -181,8 +182,9 @@ void Constraint::Restore(XMLReader& reader) AlignmentType = static_cast( reader.getAttributeAsInteger("InternalAlignmentType")); - if (reader.hasAttribute("InternalAlignmentIndex")) + if (reader.hasAttribute("InternalAlignmentIndex")) { InternalAlignmentIndex = reader.getAttributeAsInteger("InternalAlignmentIndex"); + } } else { AlignmentType = Undef; @@ -195,20 +197,25 @@ void Constraint::Restore(XMLReader& reader) } // Read the distance a constraint label has been moved - if (reader.hasAttribute("LabelDistance")) + if (reader.hasAttribute("LabelDistance")) { LabelDistance = (float)reader.getAttributeAsFloat("LabelDistance"); + } - if (reader.hasAttribute("LabelPosition")) + if (reader.hasAttribute("LabelPosition")) { LabelPosition = (float)reader.getAttributeAsFloat("LabelPosition"); + } - if (reader.hasAttribute("IsDriving")) + if (reader.hasAttribute("IsDriving")) { isDriving = reader.getAttributeAsInteger("IsDriving") ? true : false; + } - if (reader.hasAttribute("IsInVirtualSpace")) + if (reader.hasAttribute("IsInVirtualSpace")) { isInVirtualSpace = reader.getAttributeAsInteger("IsInVirtualSpace") ? true : false; + } - if (reader.hasAttribute("IsActive")) + if (reader.hasAttribute("IsActive")) { isActive = reader.getAttributeAsInteger("IsActive") ? true : false; + } } void Constraint::substituteIndex(int fromGeoId, int toGeoId) diff --git a/src/Mod/Sketcher/App/ConstraintPyImp.cpp b/src/Mod/Sketcher/App/ConstraintPyImp.cpp index d3ce49c2db..18b9c29605 100644 --- a/src/Mod/Sketcher/App/ConstraintPyImp.cpp +++ b/src/Mod/Sketcher/App/ConstraintPyImp.cpp @@ -110,10 +110,12 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) this->getConstraintPtr()->Type = InternalAlignment; valid = true; - if (strstr(ConstraintType, "EllipseMajorDiameter")) + if (strstr(ConstraintType, "EllipseMajorDiameter")) { this->getConstraintPtr()->AlignmentType = EllipseMajorDiameter; - else if (strstr(ConstraintType, "EllipseMinorDiameter")) + } + else if (strstr(ConstraintType, "EllipseMinorDiameter")) { this->getConstraintPtr()->AlignmentType = EllipseMinorDiameter; + } else { this->getConstraintPtr()->AlignmentType = Undef; valid = false; @@ -138,8 +140,9 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) if (PyObject_TypeCheck(index_or_value, &(Base::QuantityPy::Type))) { Base::Quantity q = *(static_cast(index_or_value)->getQuantityPtr()); - if (q.getUnit() == Base::Unit::Angle) + if (q.getUnit() == Base::Unit::Angle) { Value = q.getValueAs(Base::Quantity::Radian); + } } this->getConstraintPtr()->Type = Angle; valid = true; @@ -205,10 +208,12 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) valid = true; - if (strstr(ConstraintType, "EllipseFocus1")) + if (strstr(ConstraintType, "EllipseFocus1")) { this->getConstraintPtr()->AlignmentType = EllipseFocus1; - else if (strstr(ConstraintType, "EllipseFocus2")) + } + else if (strstr(ConstraintType, "EllipseFocus2")) { this->getConstraintPtr()->AlignmentType = EllipseFocus2; + } else { this->getConstraintPtr()->AlignmentType = Undef; valid = false; @@ -230,8 +235,9 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) if (PyObject_TypeCheck(index_or_value, &(Base::QuantityPy::Type))) { Base::Quantity q = *(static_cast(index_or_value)->getQuantityPtr()); - if (q.getUnit() == Base::Unit::Angle) + if (q.getUnit() == Base::Unit::Angle) { Value = q.getValueAs(Base::Quantity::Radian); + } } this->getConstraintPtr()->Type = Angle; this->getConstraintPtr()->First = FirstIndex; @@ -363,8 +369,14 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) } PyErr_Clear(); - if (PyArg_ParseTuple( - args, "siiiiO", &ConstraintType, &intArg1, &intArg2, &intArg3, &intArg4, &oNumArg5)) { + if (PyArg_ParseTuple(args, + "siiiiO", + &ConstraintType, + &intArg1, + &intArg2, + &intArg3, + &intArg4, + &oNumArg5)) { // ConstraintType, GeoIndex1, PosIndex1, GeoIndex2, PosIndex2, GeoIndex3 if (PyLong_Check(oNumArg5)) { intArg5 = PyLong_AsLong(oNumArg5); @@ -398,8 +410,9 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) if (PyObject_TypeCheck(oNumArg5, &(Base::QuantityPy::Type))) { Base::Quantity q = *(static_cast(oNumArg5)->getQuantityPtr()); - if (q.getUnit() == Base::Unit::Angle) + if (q.getUnit() == Base::Unit::Angle) { Value = q.getValueAs(Base::Quantity::Radian); + } } this->getConstraintPtr()->Type = Angle; valid = true; @@ -408,8 +421,9 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) if (PyObject_TypeCheck(oNumArg5, &(Base::QuantityPy::Type))) { Base::Quantity q = *(static_cast(oNumArg5)->getQuantityPtr()); - if (q.getUnit() == Base::Unit::Angle) + if (q.getUnit() == Base::Unit::Angle) { Value = q.getValueAs(Base::Quantity::Radian); + } } this->getConstraintPtr()->Type = Angle; // valid = true;//non-standard assignment @@ -525,25 +539,31 @@ std::string ConstraintPy::representation() const result << "'Parallel'>"; break; case Tangent: - if (this->getConstraintPtr()->Third == GeoEnum::GeoUndef) + if (this->getConstraintPtr()->Third == GeoEnum::GeoUndef) { result << "'Tangent'>"; - else + } + else { result << "'TangentViaPoint'>"; + } break; case Perpendicular: - if (this->getConstraintPtr()->Third == GeoEnum::GeoUndef) + if (this->getConstraintPtr()->Third == GeoEnum::GeoUndef) { result << "'Perpendicular'>"; - else + } + else { result << "'PerpendicularViaPoint'>"; + } break; case Distance: result << "'Distance'>"; break; case Angle: - if (this->getConstraintPtr()->Third == GeoEnum::GeoUndef) + if (this->getConstraintPtr()->Third == GeoEnum::GeoUndef) { result << "'Angle'>"; - else + } + else { result << "'AngleViaPoint'>"; + } break; case Symmetric: result << "'Symmetric'>"; diff --git a/src/Mod/Sketcher/App/ExternalGeometryExtensionPyImp.cpp b/src/Mod/Sketcher/App/ExternalGeometryExtensionPyImp.cpp index 5e28b559f7..c5acef78f8 100644 --- a/src/Mod/Sketcher/App/ExternalGeometryExtensionPyImp.cpp +++ b/src/Mod/Sketcher/App/ExternalGeometryExtensionPyImp.cpp @@ -39,8 +39,9 @@ std::string ExternalGeometryExtensionPy::representation() const str << "getName().empty()) + if (!getExternalGeometryExtensionPtr()->getName().empty()) { str << "\'" << getExternalGeometryExtensionPtr()->getName() << "\', "; + } str << "\"" << ref; @@ -102,9 +103,10 @@ PyObject* ExternalGeometryExtensionPy::testFlag(PyObject* args) ExternalGeometryExtension::Flag flagtype; - if (getExternalGeometryExtensionPtr()->getFlagsFromName(flag, flagtype)) + if (getExternalGeometryExtensionPtr()->getFlagsFromName(flag, flagtype)) { return new_reference_to( Py::Boolean(this->getExternalGeometryExtensionPtr()->testFlag(flagtype))); + } PyErr_SetString(PyExc_TypeError, "Flag string does not exist."); return nullptr; diff --git a/src/Mod/Sketcher/App/ExternalGeometryFacade.cpp b/src/Mod/Sketcher/App/ExternalGeometryFacade.cpp index 6149f72113..bfb4be0f82 100644 --- a/src/Mod/Sketcher/App/ExternalGeometryFacade.cpp +++ b/src/Mod/Sketcher/App/ExternalGeometryFacade.cpp @@ -36,45 +36,53 @@ using namespace Sketcher; TYPESYSTEM_SOURCE(Sketcher::ExternalGeometryFacade, Base::BaseClass) ExternalGeometryFacade::ExternalGeometryFacade() - : Geo(nullptr), - SketchGeoExtension(nullptr), - ExternalGeoExtension(nullptr) + : Geo(nullptr) + , SketchGeoExtension(nullptr) + , ExternalGeoExtension(nullptr) {} ExternalGeometryFacade::ExternalGeometryFacade(const Part::Geometry* geometry) : Geo(geometry) { - if (geometry) + if (geometry) { initExtensions(); - else + } + else { THROWM(Base::ValueError, "ExternalGeometryFacade initialized with Geometry null pointer"); + } } std::unique_ptr ExternalGeometryFacade::getFacade(Part::Geometry* geometry) { - if (geometry) + if (geometry) { return std::unique_ptr(new ExternalGeometryFacade(geometry)); - else + } + else { return std::unique_ptr(nullptr); + } } std::unique_ptr ExternalGeometryFacade::getFacade(const Part::Geometry* geometry) { - if (geometry) + if (geometry) { return std::unique_ptr(new ExternalGeometryFacade(geometry)); - else + } + else { return std::unique_ptr(nullptr); + } } void ExternalGeometryFacade::setGeometry(Part::Geometry* geometry) { Geo = geometry; - if (geometry) + if (geometry) { initExtensions(); - else + } + else { THROWM(Base::ValueError, "ExternalGeometryFacade initialized with Geometry null pointer"); + } } void ExternalGeometryFacade::initExtensions() @@ -105,13 +113,15 @@ void ExternalGeometryFacade::initExtensions() void ExternalGeometryFacade::initExtensions() const { - if (!Geo->hasExtension(SketchGeometryExtension::getClassTypeId())) + if (!Geo->hasExtension(SketchGeometryExtension::getClassTypeId())) { THROWM(Base::ValueError, "ExternalGeometryFacade for const::Geometry without SketchGeometryExtension"); + } - if (!Geo->hasExtension(ExternalGeometryExtension::getClassTypeId())) + if (!Geo->hasExtension(ExternalGeometryExtension::getClassTypeId())) { THROWM(Base::ValueError, "ExternalGeometryFacade for const::Geometry without ExternalGeometryExtension"); + } auto ext = std::static_pointer_cast( Geo->getExtension(SketchGeometryExtension::getClassTypeId()).lock()); diff --git a/src/Mod/Sketcher/App/ExternalGeometryFacade.h b/src/Mod/Sketcher/App/ExternalGeometryFacade.h index fbda7f3c6d..ccb44ac516 100644 --- a/src/Mod/Sketcher/App/ExternalGeometryFacade.h +++ b/src/Mod/Sketcher/App/ExternalGeometryFacade.h @@ -167,18 +167,20 @@ public: } // Geometry Element - template::type>::value>::type> + template< + typename GeometryT = Part::Geometry, + typename = typename std::enable_if< + std::is_base_of::type>::value>::type> GeometryT* getGeometry() { return dynamic_cast(const_cast(Geo)); } // Geometry Element - template::type>::value>::type> + template< + typename GeometryT = Part::Geometry, + typename = typename std::enable_if< + std::is_base_of::type>::value>::type> GeometryT* getGeometry() const { return dynamic_cast(Geo); diff --git a/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp b/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp index 2367f40269..b60c99275d 100644 --- a/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp +++ b/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp @@ -48,7 +48,8 @@ std::string ExternalGeometryFacadePy::representation() const return str.str(); } -PyObject* ExternalGeometryFacadePy::PyMake(struct _typeobject*, PyObject*, +PyObject* ExternalGeometryFacadePy::PyMake(struct _typeobject*, + PyObject*, PyObject*)// Python wrapper { // create a new instance of PointPy and the Twin object @@ -150,8 +151,9 @@ Py::String ExternalGeometryFacadePy::getInternalType() const { int internaltypeindex = (int)this->getExternalGeometryFacadePtr()->getInternalType(); - if (internaltypeindex >= InternalType::NumInternalGeometryType) + if (internaltypeindex >= InternalType::NumInternalGeometryType) { throw Py::NotImplementedError("String name of enum not implemented"); + } std::string typestr = SketchGeometryExtension::internaltype2str[internaltypeindex]; @@ -192,8 +194,12 @@ PyObject* ExternalGeometryFacadePy::mirror(PyObject* args) PyErr_Clear(); PyObject* axis; - if (PyArg_ParseTuple( - args, "O!O!", &(Base::VectorPy::Type), &o, &(Base::VectorPy::Type), &axis)) { + if (PyArg_ParseTuple(args, + "O!O!", + &(Base::VectorPy::Type), + &o, + &(Base::VectorPy::Type), + &axis)) { Base::Vector3d pnt = static_cast(o)->value(); Base::Vector3d dir = static_cast(axis)->value(); getExternalGeometryFacadePtr()->mirror(pnt, dir); @@ -208,8 +214,9 @@ PyObject* ExternalGeometryFacadePy::mirror(PyObject* args) PyObject* ExternalGeometryFacadePy::rotate(PyObject* args) { PyObject* o; - if (!PyArg_ParseTuple(args, "O!", &(Base::PlacementPy::Type), &o)) + if (!PyArg_ParseTuple(args, "O!", &(Base::PlacementPy::Type), &o)) { return nullptr; + } Base::Placement* plm = static_cast(o)->getPlacementPtr(); getExternalGeometryFacadePtr()->rotate(*plm); @@ -241,8 +248,9 @@ PyObject* ExternalGeometryFacadePy::scale(PyObject* args) PyObject* ExternalGeometryFacadePy::transform(PyObject* args) { PyObject* o; - if (!PyArg_ParseTuple(args, "O!", &(Base::MatrixPy::Type), &o)) + if (!PyArg_ParseTuple(args, "O!", &(Base::MatrixPy::Type), &o)) { return nullptr; + } Base::Matrix4D mat = static_cast(o)->value(); getExternalGeometryFacadePtr()->transform(mat); Py_Return; @@ -502,8 +510,9 @@ Py::Boolean ExternalGeometryFacadePy::getConstruction() const void ExternalGeometryFacadePy::setConstruction(Py::Boolean arg) { - if (getExternalGeometryFacadePtr()->getTypeId() != Part::GeomPoint::getClassTypeId()) + if (getExternalGeometryFacadePtr()->getTypeId() != Part::GeomPoint::getClassTypeId()) { getExternalGeometryFacadePtr()->setConstruction(arg); + } } Py::Long ExternalGeometryFacadePy::getGeometryLayerId() const diff --git a/src/Mod/Sketcher/App/GeoEnum.h b/src/Mod/Sketcher/App/GeoEnum.h index ea58f7164f..9ff55992a2 100644 --- a/src/Mod/Sketcher/App/GeoEnum.h +++ b/src/Mod/Sketcher/App/GeoEnum.h @@ -64,10 +64,10 @@ namespace Sketcher */ enum GeoEnum { - RtPnt = -1, // GeoId of the Root Point - HAxis = -1, // GeoId of the Horizontal Axis - VAxis = -2, // GeoId of the Vertical Axis - RefExt = -3,// Starting GeoID of external geometry ( negative geoIds starting at this index) + RtPnt = -1, // GeoId of the Root Point + HAxis = -1, // GeoId of the Horizontal Axis + VAxis = -2, // GeoId of the Vertical Axis + RefExt = -3, // Starting GeoID of external geometry ( negative geoIds starting at this index) GeoUndef = -2000// GeoId of an undefined Geometry (uninitialised or unused GeoId) }; @@ -139,8 +139,8 @@ public: // inline constexpr constructor inline constexpr GeoElementId::GeoElementId(int geoId, PointPos pos) - : GeoId(geoId), - Pos(pos) + : GeoId(geoId) + , Pos(pos) {} inline bool GeoElementId::isCurve() const diff --git a/src/Mod/Sketcher/App/GeoList.cpp b/src/Mod/Sketcher/App/GeoList.cpp index 199d7d7de9..47defaca56 100644 --- a/src/Mod/Sketcher/App/GeoList.cpp +++ b/src/Mod/Sketcher/App/GeoList.cpp @@ -39,34 +39,36 @@ using namespace Sketcher; // Vector is moved template GeoListModel::GeoListModel(std::vector&& geometrylist, int intgeocount, bool ownerT) - : geomlist(std::move(geometrylist)), - intGeoCount(intgeocount), - OwnerT(ownerT), - indexInit(false) + : geomlist(std::move(geometrylist)) + , intGeoCount(intgeocount) + , OwnerT(ownerT) + , indexInit(false) {} // Vector is shallow copied (copy constructed) template GeoListModel::GeoListModel(const std::vector& geometrylist, int intgeocount) - : geomlist(geometrylist),// copy constructed here - intGeoCount(intgeocount), - OwnerT(false), - indexInit(false) + : geomlist(geometrylist) + ,// copy constructed here + intGeoCount(intgeocount) + , OwnerT(false) + , indexInit(false) {} template GeoListModel::~GeoListModel() { if (OwnerT) { - for (auto& g : geomlist) + for (auto& g : geomlist) { delete g; + } } } template -GeoListModel GeoListModel::getGeoListModel(std::vector&& geometrylist, int intgeocount, - bool ownerT) +GeoListModel +GeoListModel::getGeoListModel(std::vector&& geometrylist, int intgeocount, bool ownerT) { return GeoListModel(std::move(geometrylist), intgeocount, ownerT); } @@ -84,10 +86,12 @@ int GeoListModel::getGeoIdFromGeomListIndex(int index) const { assert(index < int(geomlist.size())); - if (index < intGeoCount) + if (index < intGeoCount) { return index; - else + } + else { return (index - geomlist.size()); + } } template @@ -95,16 +99,20 @@ const Part::Geometry* GeoListModel::getGeometryFromGeoId(const std::vector int geoId) { if constexpr (std::is_same()) { - if (geoId >= 0) + if (geoId >= 0) { return geometrylist[geoId]; - else + } + else { return geometrylist[geometrylist.size() + geoId]; + } } else if constexpr (std::is_same()) { - if (geoId >= 0) + if (geoId >= 0) { return geometrylist[geoId]->getGeometry(); - else + } + else { return geometrylist[geometrylist.size() + geoId]->getGeometry(); + } } } @@ -113,16 +121,20 @@ const Sketcher::GeometryFacade* GeoListModel::getGeometryFacadeFromGeoId(const std::vector& geometrylist, int geoId) { if constexpr (std::is_same()) { - if (geoId >= 0) + if (geoId >= 0) { return GeometryFacade::getFacade(geometrylist[geoId]).release(); - else + } + else { return GeometryFacade::getFacade(geometrylist[geometrylist.size() + geoId]).release(); + } } else if constexpr (std::is_same()) { - if (geoId >= 0) + if (geoId >= 0) { return geometrylist[geoId].get(); - else + } + else { return geometrylist[geometrylist.size() + geoId].get(); + } } } @@ -161,68 +173,87 @@ Base::Vector3d GeoListModel::getPoint(const Part::Geometry* geo, Sketcher::Po if (geo->getTypeId() == Part::GeomPoint::getClassTypeId()) { const Part::GeomPoint* p = static_cast(geo); - if (pos == PointPos::start || pos == PointPos::mid || pos == PointPos::end) + if (pos == PointPos::start || pos == PointPos::mid || pos == PointPos::end) { return p->getPoint(); + } } else if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { const Part::GeomLineSegment* lineSeg = static_cast(geo); - if (pos == PointPos::start) + if (pos == PointPos::start) { return lineSeg->getStartPoint(); - else if (pos == PointPos::end) + } + else if (pos == PointPos::end) { return lineSeg->getEndPoint(); + } } else if (geo->getTypeId() == Part::GeomCircle::getClassTypeId()) { const Part::GeomCircle* circle = static_cast(geo); - if (pos == PointPos::mid) + if (pos == PointPos::mid) { return circle->getCenter(); + } } else if (geo->getTypeId() == Part::GeomEllipse::getClassTypeId()) { const Part::GeomEllipse* ellipse = static_cast(geo); - if (pos == PointPos::mid) + if (pos == PointPos::mid) { return ellipse->getCenter(); + } } else if (geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { const Part::GeomArcOfCircle* aoc = static_cast(geo); - if (pos == PointPos::start) + if (pos == PointPos::start) { return aoc->getStartPoint(/*emulateCCW=*/true); - else if (pos == PointPos::end) + } + else if (pos == PointPos::end) { return aoc->getEndPoint(/*emulateCCW=*/true); - else if (pos == PointPos::mid) + } + else if (pos == PointPos::mid) { return aoc->getCenter(); + } } else if (geo->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()) { const Part::GeomArcOfEllipse* aoc = static_cast(geo); - if (pos == PointPos::start) + if (pos == PointPos::start) { return aoc->getStartPoint(/*emulateCCW=*/true); - else if (pos == PointPos::end) + } + else if (pos == PointPos::end) { return aoc->getEndPoint(/*emulateCCW=*/true); - else if (pos == PointPos::mid) + } + else if (pos == PointPos::mid) { return aoc->getCenter(); + } } else if (geo->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId()) { const Part::GeomArcOfHyperbola* aoh = static_cast(geo); - if (pos == PointPos::start) + if (pos == PointPos::start) { return aoh->getStartPoint(); - else if (pos == PointPos::end) + } + else if (pos == PointPos::end) { return aoh->getEndPoint(); - else if (pos == PointPos::mid) + } + else if (pos == PointPos::mid) { return aoh->getCenter(); + } } else if (geo->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { const Part::GeomArcOfParabola* aop = static_cast(geo); - if (pos == PointPos::start) + if (pos == PointPos::start) { return aop->getStartPoint(); - else if (pos == PointPos::end) + } + else if (pos == PointPos::end) { return aop->getEndPoint(); - else if (pos == PointPos::mid) + } + else if (pos == PointPos::mid) { return aop->getCenter(); + } } else if (geo->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) { const Part::GeomBSplineCurve* bsp = static_cast(geo); - if (pos == PointPos::start) + if (pos == PointPos::start) { return bsp->getStartPoint(); - else if (pos == PointPos::end) + } + else if (pos == PointPos::end) { return bsp->getEndPoint(); + } } return Base::Vector3d(); @@ -244,19 +275,24 @@ void GeoListModel::rebuildVertexIndex() const std::forward_as_tuple(pointId++)); }; - if (geomlist.size() <= 2) + if (geomlist.size() <= 2) { return; + } for (auto it = geomlist.begin(); it != geomlist.end(); ++it, geoId++) { Base::Type type; - if constexpr (std::is_same::value) + if constexpr (std::is_same::value) { type = (*it)->getTypeId(); - else if constexpr (std::is_same>::value) + } + else if constexpr (std::is_same>::value) { type = (*it)->getGeometry()->getTypeId(); + } - if (geoId > getInternalCount()) + if (geoId > getInternalCount()) { geoId = -getExternalCount(); + } if (type == Part::GeomPoint::getClassTypeId()) { addGeoElement(geoId, PointPos::start); @@ -286,8 +322,9 @@ void GeoListModel::rebuildVertexIndex() const template Sketcher::GeoElementId GeoListModel::getGeoElementIdFromVertexId(int vertexId) { - if (!indexInit)// lazy initialised + if (!indexInit) {// lazy initialised rebuildVertexIndex(); + } return VertexId2GeoElementId[vertexId]; } @@ -295,14 +332,16 @@ Sketcher::GeoElementId GeoListModel::getGeoElementIdFromVertexId(int vertexId template int GeoListModel::getVertexIdFromGeoElementId(const Sketcher::GeoElementId& geoelementId) const { - if (!indexInit)// lazy initialised + if (!indexInit) {// lazy initialised rebuildVertexIndex(); + } auto found = std::find(VertexId2GeoElementId.begin(), VertexId2GeoElementId.end(), geoelementId); - if (found != VertexId2GeoElementId.end()) + if (found != VertexId2GeoElementId.end()) { return std::distance(found, VertexId2GeoElementId.begin()); + } THROWM(Base::IndexError, "GeoElementId not indexed"); } @@ -314,11 +353,13 @@ namespace Sketcher // Template specialisations template<> GeoListModel::GeoListModel( - std::vector&& geometrylist, int intgeocount, bool ownerT) - : geomlist(std::move(geometrylist)), - intGeoCount(intgeocount), - OwnerT(false), - indexInit(false) + std::vector&& geometrylist, + int intgeocount, + bool ownerT) + : geomlist(std::move(geometrylist)) + , intGeoCount(intgeocount) + , OwnerT(false) + , indexInit(false) { // GeometryFacades hold the responsibility for releasing the resources. // @@ -335,10 +376,11 @@ GeoListModel::GeoListModel( template<> GeoListModel::GeoListModel( - const std::vector& geometrylist, int intgeocount) - : intGeoCount(intgeocount), - OwnerT(false), - indexInit(false) + const std::vector& geometrylist, + int intgeocount) + : intGeoCount(intgeocount) + , OwnerT(false) + , indexInit(false) { // GeometryFacades are movable, but not copiable, so they need to be reconstructed (shallow copy // of vector) Under the Single Responsibility Principle, these will not take over a @@ -383,7 +425,9 @@ template SketcherExport Base::Vector3d GeoListModel::getPoint(const GeoElementId&) const; template SketcherExport GeoListModel GeoListModel::getGeoListModel( - std::vector&& geometrylist, int intgeocount, bool ownerT); + std::vector&& geometrylist, + int intgeocount, + bool ownerT); #endif @@ -394,8 +438,9 @@ GeoListFacade Sketcher::getGeoListFacade(const GeoList& geolist) std::vector> facade; facade.reserve(geolist.geomlist.size()); - for (auto geo : geolist.geomlist) + for (auto geo : geolist.geomlist) { facade.push_back(GeometryFacade::getFacade(geo)); + } auto geolistfacade = GeoListFacade::getGeoListModel(std::move(facade), geolist.getInternalCount()); diff --git a/src/Mod/Sketcher/App/GeoList.h b/src/Mod/Sketcher/App/GeoList.h index 74b8aa6525..949a094075 100644 --- a/src/Mod/Sketcher/App/GeoList.h +++ b/src/Mod/Sketcher/App/GeoList.h @@ -132,8 +132,8 @@ public: * assertion is raised if this happens. The ownership needs to be specified on the GeoListFacade * objects themselves (setOwner method). */ - static GeoListModel getGeoListModel(std::vector&& geometrylist, int intgeocount, - bool ownerT = false); + static GeoListModel + getGeoListModel(std::vector&& geometrylist, int intgeocount, bool ownerT = false); static const GeoListModel getGeoListModel(const std::vector& geometrylist, int intgeocount); diff --git a/src/Mod/Sketcher/App/GeometryFacade.cpp b/src/Mod/Sketcher/App/GeometryFacade.cpp index f8c770d8f0..2bc66ca727 100644 --- a/src/Mod/Sketcher/App/GeometryFacade.cpp +++ b/src/Mod/Sketcher/App/GeometryFacade.cpp @@ -34,14 +34,14 @@ using namespace Sketcher; TYPESYSTEM_SOURCE(Sketcher::GeometryFacade, Base::BaseClass) GeometryFacade::GeometryFacade() - : Geo(nullptr), - OwnerGeo(false), - SketchGeoExtension(nullptr) + : Geo(nullptr) + , OwnerGeo(false) + , SketchGeoExtension(nullptr) {} GeometryFacade::GeometryFacade(const Part::Geometry* geometry, bool owner) - : Geo(geometry), - OwnerGeo(owner) + : Geo(geometry) + , OwnerGeo(owner) { assert(geometry);// This should never be nullptr, as this constructor is protected @@ -50,26 +50,31 @@ GeometryFacade::GeometryFacade(const Part::Geometry* geometry, bool owner) GeometryFacade::~GeometryFacade() { - if (OwnerGeo && Geo) + if (OwnerGeo && Geo) { delete Geo; + } } std::unique_ptr GeometryFacade::getFacade(Part::Geometry* geometry, bool owner) { - if (geometry) + if (geometry) { return std::unique_ptr(new GeometryFacade(geometry, owner)); - else + } + else { return std::unique_ptr(nullptr); + } // make_unique has no access to private constructor // return std::make_unique(geometry); } std::unique_ptr GeometryFacade::getFacade(const Part::Geometry* geometry) { - if (geometry) + if (geometry) { return std::unique_ptr(new GeometryFacade(geometry)); - else + } + else { return std::unique_ptr(nullptr); + } // make_unique has no access to private constructor // return std::make_unique(geometry); } @@ -78,10 +83,12 @@ void GeometryFacade::setGeometry(Part::Geometry* geometry) { Geo = geometry; - if (geometry) + if (geometry) { initExtension(); - else + } + else { THROWM(Base::ValueError, "GeometryFacade initialized with Geometry null pointer"); + } } void GeometryFacade::initExtension() @@ -101,10 +108,11 @@ void GeometryFacade::initExtension() void GeometryFacade::initExtension() const { // const Geometry without SketchGeometryExtension cannot initialise a GeometryFacade - if (!Geo->hasExtension(SketchGeometryExtension::getClassTypeId())) + if (!Geo->hasExtension(SketchGeometryExtension::getClassTypeId())) { THROWM(Base::ValueError, "Cannot create a GeometryFacade out of a const Geometry pointer not having a " "SketchGeometryExtension!"); + } auto ext = std::static_pointer_cast( Geo->getExtension(SketchGeometryExtension::getClassTypeId()).lock()); @@ -114,8 +122,9 @@ void GeometryFacade::initExtension() const void GeometryFacade::throwOnNullPtr(const Part::Geometry* geo) { - if (!geo) + if (!geo) { THROWM(Base::ValueError, "Geometry is nullptr!"); + } } void GeometryFacade::ensureSketchGeometryExtension(Part::Geometry* geometry) diff --git a/src/Mod/Sketcher/App/GeometryFacade.h b/src/Mod/Sketcher/App/GeometryFacade.h index 4291ee6cd3..132fc8dc26 100644 --- a/src/Mod/Sketcher/App/GeometryFacade.h +++ b/src/Mod/Sketcher/App/GeometryFacade.h @@ -225,18 +225,20 @@ public: } // Geometry Element - template::type>::value>::type> + template< + typename GeometryT = Part::Geometry, + typename = typename std::enable_if< + std::is_base_of::type>::value>::type> GeometryT* getGeometry() { return dynamic_cast(const_cast(Geo)); } // Geometry Element - template::type>::value>::type> + template< + typename GeometryT = Part::Geometry, + typename = typename std::enable_if< + std::is_base_of::type>::value>::type> const GeometryT* getGeometry() const { return dynamic_cast(Geo); diff --git a/src/Mod/Sketcher/App/GeometryFacadePyImp.cpp b/src/Mod/Sketcher/App/GeometryFacadePyImp.cpp index 19a6c53903..bab4d0acd6 100644 --- a/src/Mod/Sketcher/App/GeometryFacadePyImp.cpp +++ b/src/Mod/Sketcher/App/GeometryFacadePyImp.cpp @@ -86,8 +86,9 @@ Py::String GeometryFacadePy::getInternalType() const { int internaltypeindex = (int)this->getGeometryFacadePtr()->getInternalType(); - if (internaltypeindex >= InternalType::NumInternalGeometryType) + if (internaltypeindex >= InternalType::NumInternalGeometryType) { throw Py::NotImplementedError("String name of enum not implemented"); + } std::string typestr = SketchGeometryExtension::internaltype2str[internaltypeindex]; @@ -124,8 +125,9 @@ PyObject* GeometryFacadePy::testGeometryMode(PyObject* args) GeometryMode::GeometryMode mode; - if (SketchGeometryExtension::getGeometryModeFromName(flag, mode)) + if (SketchGeometryExtension::getGeometryModeFromName(flag, mode)) { return new_reference_to(Py::Boolean(getGeometryFacadePtr()->testGeometryMode(mode))); + } PyErr_SetString(PyExc_TypeError, "Flag string does not exist."); return nullptr; @@ -168,8 +170,12 @@ PyObject* GeometryFacadePy::mirror(PyObject* args) PyErr_Clear(); PyObject* axis; - if (PyArg_ParseTuple( - args, "O!O!", &(Base::VectorPy::Type), &o, &(Base::VectorPy::Type), &axis)) { + if (PyArg_ParseTuple(args, + "O!O!", + &(Base::VectorPy::Type), + &o, + &(Base::VectorPy::Type), + &axis)) { Base::Vector3d pnt = static_cast(o)->value(); Base::Vector3d dir = static_cast(axis)->value(); getGeometryFacadePtr()->mirror(pnt, dir); @@ -184,8 +190,9 @@ PyObject* GeometryFacadePy::mirror(PyObject* args) PyObject* GeometryFacadePy::rotate(PyObject* args) { PyObject* o; - if (!PyArg_ParseTuple(args, "O!", &(Base::PlacementPy::Type), &o)) + if (!PyArg_ParseTuple(args, "O!", &(Base::PlacementPy::Type), &o)) { return nullptr; + } Base::Placement* plm = static_cast(o)->getPlacementPtr(); getGeometryFacadePtr()->rotate(*plm); @@ -217,8 +224,9 @@ PyObject* GeometryFacadePy::scale(PyObject* args) PyObject* GeometryFacadePy::transform(PyObject* args) { PyObject* o; - if (!PyArg_ParseTuple(args, "O!", &(Base::MatrixPy::Type), &o)) + if (!PyArg_ParseTuple(args, "O!", &(Base::MatrixPy::Type), &o)) { return nullptr; + } Base::Matrix4D mat = static_cast(o)->value(); getGeometryFacadePtr()->transform(mat); Py_Return; diff --git a/src/Mod/Sketcher/App/PropertyConstraintList.cpp b/src/Mod/Sketcher/App/PropertyConstraintList.cpp index a532faa1b7..0cc4fca622 100644 --- a/src/Mod/Sketcher/App/PropertyConstraintList.cpp +++ b/src/Mod/Sketcher/App/PropertyConstraintList.cpp @@ -52,17 +52,20 @@ TYPESYSTEM_SOURCE(Sketcher::PropertyConstraintList, App::PropertyLists) PropertyConstraintList::PropertyConstraintList() - : validGeometryKeys(0), - invalidGeometry(true), - restoreFromTransaction(false), - invalidIndices(false) + : validGeometryKeys(0) + , invalidGeometry(true) + , restoreFromTransaction(false) + , invalidIndices(false) {} PropertyConstraintList::~PropertyConstraintList() { - for (std::vector::iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) - if (*it) + for (std::vector::iterator it = _lValueList.begin(); it != _lValueList.end(); + ++it) { + if (*it) { delete *it; + } + } } App::ObjectIdentifier PropertyConstraintList::makeArrayPath(int idx) @@ -72,9 +75,9 @@ App::ObjectIdentifier PropertyConstraintList::makeArrayPath(int idx) App::ObjectIdentifier PropertyConstraintList::makeSimplePath(const Constraint* c) { - return App::ObjectIdentifier(*this) - << App::ObjectIdentifier::SimpleComponent(App::ObjectIdentifier::String( - c->Name, !ExpressionParser::isTokenAnIndentifier(c->Name))); + return App::ObjectIdentifier(*this) << App::ObjectIdentifier::SimpleComponent( + App::ObjectIdentifier::String(c->Name, + !ExpressionParser::isTokenAnIndentifier(c->Name))); } App::ObjectIdentifier PropertyConstraintList::makePath(int idx, const Constraint* c) @@ -93,12 +96,14 @@ void PropertyConstraintList::setSize(int newSize) } /* Signal removed elements */ - if (!removed.empty()) + if (!removed.empty()) { signalConstraintsRemoved(removed); + } /* Actually delete them */ - for (unsigned int i = newSize; i < _lValueList.size(); i++) + for (unsigned int i = newSize; i < _lValueList.size(); i++) { delete _lValueList[i]; + } /* Resize array to new size */ _lValueList.resize(newSize); @@ -120,8 +125,9 @@ void PropertyConstraintList::set1Value(const int idx, const Constraint* lValue) std::map renamed; renamed[makePath(idx, _lValueList[idx])] = makePath(idx, lValue); - if (!renamed.empty()) + if (!renamed.empty()) { signalConstraintsRenamed(renamed); + } } _lValueList[idx] = newVal; @@ -148,8 +154,9 @@ void PropertyConstraintList::setValue(const Constraint* lValue) } /* Signal rename changes */ - if (!renamed.empty()) + if (!renamed.empty()) { signalConstraintsRenamed(renamed); + } /* Collect info about removals */ for (unsigned int i = start; i < _lValueList.size(); i++) { @@ -158,12 +165,14 @@ void PropertyConstraintList::setValue(const Constraint* lValue) } /* Signal removes */ - if (!removed.empty()) + if (!removed.empty()) { signalConstraintsRemoved(removed); + } // Cleanup - for (unsigned int i = 0; i < _lValueList.size(); i++) + for (unsigned int i = 0; i < _lValueList.size(); i++) { delete _lValueList[i]; + } /* Set new data */ _lValueList.resize(1); @@ -176,8 +185,9 @@ void PropertyConstraintList::setValue(const Constraint* lValue) void PropertyConstraintList::setValues(const std::vector& lValue) { auto copy = lValue; - for (auto& cstr : copy) + for (auto& cstr : copy) { cstr = cstr->clone(); + } setValues(std::move(copy)); } @@ -217,48 +227,55 @@ void PropertyConstraintList::applyValues(std::vector&& lValue) } /* Collect info about removed elements */ - for (auto& v : valueMap) + for (auto& v : valueMap) { removed.insert(makePath(v.second, _lValueList[v.second])); + } /* Update value map with new tags from new array */ valueMap = std::move(newValueMap); /* Signal removes first, in case renamed values below have the same names as some of the removed * ones. */ - if (!removed.empty() && !restoreFromTransaction) + if (!removed.empty() && !restoreFromTransaction) { signalConstraintsRemoved(removed); + } /* Signal renames */ - if (!renamed.empty() && !restoreFromTransaction) + if (!renamed.empty() && !restoreFromTransaction) { signalConstraintsRenamed(renamed); + } _lValueList = std::move(lValue); /* Clean-up; remove old values */ - for (auto& v : oldVals) + for (auto& v : oldVals) { delete v; + } } PyObject* PropertyConstraintList::getPyObject() { PyObject* list = PyList_New(getSize()); - for (int i = 0; i < getSize(); i++) + for (int i = 0; i < getSize(); i++) { PyList_SetItem(list, i, _lValueList[i]->getPyObject()); + } return list; } bool PropertyConstraintList::getPyPathValue(const App::ObjectIdentifier& path, Py::Object& res) const { - if (path.numSubComponents() != 2 || path.getPropertyComponent(0).getName() != getName()) + if (path.numSubComponents() != 2 || path.getPropertyComponent(0).getName() != getName()) { return false; + } const ObjectIdentifier::Component& c1 = path.getPropertyComponent(1); const Constraint* cstr = nullptr; - if (c1.isArray()) + if (c1.isArray()) { cstr = _lValueList[c1.getIndex(_lValueList.size())]; + } else if (c1.isSimple()) { ObjectIdentifier::Component c1 = path.getPropertyComponent(1); for (auto c : _lValueList) { @@ -268,8 +285,9 @@ bool PropertyConstraintList::getPyPathValue(const App::ObjectIdentifier& path, } } } - if (!cstr) + if (!cstr) { return false; + } Quantity q = cstr->getPresentationValue(); res = new Base::QuantityPy(new Base::Quantity(q)); return true; @@ -310,8 +328,9 @@ void PropertyConstraintList::Save(Writer& writer) const { writer.Stream() << writer.ind() << "" << endl; writer.incInd(); - for (int i = 0; i < getSize(); i++) + for (int i = 0; i < getSize(); i++) { _lValueList[i]->Save(writer); + } writer.decInd(); writer.Stream() << writer.ind() << "" << endl; } @@ -362,8 +381,9 @@ void PropertyConstraintList::Paste(const Property& from) unsigned int PropertyConstraintList::getMemSize() const { int size = sizeof(PropertyConstraintList); - for (int i = 0; i < getSize(); i++) + for (int i = 0; i < getSize(); i++) { size += _lValueList[i]->getMemSize(); + } return size; } @@ -372,8 +392,9 @@ void PropertyConstraintList::acceptGeometry(const std::vector& aboutToSetValue(); validGeometryKeys.clear(); validGeometryKeys.reserve(GeoList.size()); - for (const auto& it : GeoList) + for (const auto& it : GeoList) { validGeometryKeys.push_back((it)->getTypeId().getKey()); + } invalidGeometry = false; hasSetValue(); } @@ -406,8 +427,9 @@ bool PropertyConstraintList::checkConstraintIndices(int geomax, int geomin) int maxinternalgeoid = GeoEnum::GeoUndef; auto cmin = [](int previousmin, int cindex) { - if (cindex == GeoEnum::GeoUndef) + if (cindex == GeoEnum::GeoUndef) { return previousmin; + } return (cindex < previousmin) ? cindex : previousmin; }; @@ -427,10 +449,12 @@ bool PropertyConstraintList::checkConstraintIndices(int geomax, int geomin) maxinternalgeoid = cmax(maxinternalgeoid, v->Third); } - if (maxinternalgeoid > geomax || mininternalgeoid < geomin) + if (maxinternalgeoid > geomax || mininternalgeoid < geomin) { invalidIndices = true; - else + } + else { invalidIndices = false; + } return invalidIndices; } @@ -460,10 +484,12 @@ bool PropertyConstraintList::scanGeometry(const std::vector& Ge string PropertyConstraintList::getConstraintName(const std::string& name, int i) { - if (!name.empty()) + if (!name.empty()) { return name; - else + } + else { return getConstraintName(i); + } } string PropertyConstraintList::getConstraintName(int i) @@ -491,24 +517,31 @@ int PropertyConstraintList::getIndexFromConstraintName(const string& name) void PropertyConstraintList::setPathValue(const ObjectIdentifier& path, const boost::any& value) { - if (path.numSubComponents() != 2 || path.getPropertyComponent(0).getName() != getName()) + if (path.numSubComponents() != 2 || path.getPropertyComponent(0).getName() != getName()) { FC_THROWM(Base::ValueError, "invalid constraint path " << path.toString()); + } const ObjectIdentifier::Component& c1 = path.getPropertyComponent(1); double dvalue; - if (value.type() == typeid(double)) + if (value.type() == typeid(double)) { dvalue = boost::any_cast(value); - else if (value.type() == typeid(float)) + } + else if (value.type() == typeid(float)) { dvalue = App::any_cast(value); - else if (value.type() == typeid(long)) + } + else if (value.type() == typeid(long)) { dvalue = App::any_cast(value); - else if (value.type() == typeid(int)) + } + else if (value.type() == typeid(int)) { dvalue = App::any_cast(value); - else if (value.type() == typeid(Quantity)) + } + else if (value.type() == typeid(Quantity)) { dvalue = (App::any_cast(value)).getValue(); - else + } + else { throw std::bad_cast(); + } if (c1.isArray()) { size_t index = c1.getIndex(_lValueList.size()); @@ -550,8 +583,9 @@ void PropertyConstraintList::setPathValue(const ObjectIdentifier& path, const bo const Constraint* PropertyConstraintList::getConstraint(const ObjectIdentifier& path) const { - if (path.numSubComponents() != 2 || path.getPropertyComponent(0).getName() != getName()) + if (path.numSubComponents() != 2 || path.getPropertyComponent(0).getName() != getName()) { FC_THROWM(Base::ValueError, "Invalid constraint path " << path.toString()); + } const ObjectIdentifier::Component& c1 = path.getPropertyComponent(1); @@ -564,8 +598,9 @@ const Constraint* PropertyConstraintList::getConstraint(const ObjectIdentifier& for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { - if ((*it)->Name == c1.getName()) + if ((*it)->Name == c1.getName()) { return *it; + } } } FC_THROWM(Base::ValueError, "Invalid constraint path " << path.toString()); @@ -578,16 +613,18 @@ const boost::any PropertyConstraintList::getPathValue(const ObjectIdentifier& pa ObjectIdentifier PropertyConstraintList::canonicalPath(const ObjectIdentifier& p) const { - if (p.numSubComponents() != 2 || p.getPropertyComponent(0).getName() != getName()) + if (p.numSubComponents() != 2 || p.getPropertyComponent(0).getName() != getName()) { FC_THROWM(Base::ValueError, "Invalid constraint path " << p.toString()); + } const ObjectIdentifier::Component& c1 = p.getPropertyComponent(1); if (c1.isArray()) { size_t idx = c1.getIndex(); - if (idx < _lValueList.size() && !_lValueList[idx]->Name.empty()) + if (idx < _lValueList.size() && !_lValueList[idx]->Name.empty()) { return ObjectIdentifier(*this) << ObjectIdentifier::SimpleComponent(_lValueList[idx]->Name); + } return p; } else if (c1.isSimple()) { @@ -600,9 +637,10 @@ void PropertyConstraintList::getPaths(std::vector& paths) cons { for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { - if (!(*it)->Name.empty()) + if (!(*it)->Name.empty()) { paths.push_back(ObjectIdentifier(*this) << ObjectIdentifier::SimpleComponent((*it)->Name)); + } } } diff --git a/src/Mod/Sketcher/App/PythonConverter.cpp b/src/Mod/Sketcher/App/PythonConverter.cpp index 803337746c..2c9b512b2a 100644 --- a/src/Mod/Sketcher/App/PythonConverter.cpp +++ b/src/Mod/Sketcher/App/PythonConverter.cpp @@ -62,8 +62,9 @@ std::string PythonConverter::convert(const Sketcher::Constraint* constraint) std::string PythonConverter::convert(const std::string& doc, const std::vector& geos) { - if (geos.empty()) + if (geos.empty()) { return std::string(); + } // Generates a list for consecutive geometries of construction type, or of normal type auto printGeoList = [&doc](const std::string& geolist, int ngeos, bool construction) { @@ -235,8 +236,9 @@ PythonConverter::SingleGeometry PythonConverter::process(const Part::Geometry* g auto result = converterMap.find(geo->getTypeId()); - if (result == converterMap.end()) + if (result == converterMap.end()) { THROWM(Base::ValueError, "PythonConverter: Geometry Type not supported") + } auto creator = result->second; @@ -484,8 +486,9 @@ std::string PythonConverter::process(const Sketcher::Constraint* constraint) auto result = converterMap.find(constraint->Type); - if (result == converterMap.end()) + if (result == converterMap.end()) { THROWM(Base::ValueError, "PythonConverter: Constraint Type not supported") + } auto creator = result->second; diff --git a/src/Mod/Sketcher/App/Sketch.h b/src/Mod/Sketcher/App/Sketch.h index ad13f7a73c..cbd7a32723 100644 --- a/src/Mod/Sketcher/App/Sketch.h +++ b/src/Mod/Sketcher/App/Sketch.h @@ -75,7 +75,8 @@ public: * constraints or may not */ int setUpSketch(const std::vector& GeoList, - const std::vector& ConstraintList, int extGeoCount = 0); + const std::vector& ConstraintList, + int extGeoCount = 0); /// return the actual geometry of the sketch a TopoShape Part::TopoShape toShape() const; /// add unspecified geometry @@ -165,7 +166,9 @@ public: /** Initializes a B-spline piece drag by setting the current * sketch status as a reference. Only moves piece around `firstPoint`. */ - int initBSplinePieceMove(int geoId, PointPos pos, const Base::Vector3d& firstPoint, + int initBSplinePieceMove(int geoId, + PointPos pos, + const Base::Vector3d& firstPoint, bool fine = true); /** Resets the initialization of a point or curve drag @@ -264,7 +267,11 @@ public: * constraint value and already inserted into either the FixParameters or * Parameters array, as the case may be. */ - int addDistanceXConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double* value, + int addDistanceXConstraint(int geoId1, + PointPos pos1, + int geoId2, + PointPos pos2, + double* value, bool driving = true); /** * add a vertical distance constraint to two points or line ends @@ -281,7 +288,11 @@ public: * constraint value and already inserted into either the FixParameters or * Parameters array, as the case may be. */ - int addDistanceYConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double* value, + int addDistanceYConstraint(int geoId1, + PointPos pos1, + int geoId2, + PointPos pos2, + double* value, bool driving = true); /// add a horizontal constraint to a geometry int addHorizontalConstraint(int geoId); @@ -306,7 +317,10 @@ public: * constraint value and already inserted into either the FixParameters or * Parameters array, as the case may be. */ - int addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, double* value, + int addDistanceConstraint(int geoId1, + PointPos pos1, + int geoId2, + double* value, bool driving = true); /** * add a length or distance constraint @@ -315,7 +329,11 @@ public: * constraint value and already inserted into either the FixParameters or * Parameters array, as the case may be. */ - int addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double* value, + int addDistanceConstraint(int geoId1, + PointPos pos1, + int geoId2, + PointPos pos2, + double* value, bool driving = true); /** * add a length or distance constraint @@ -332,13 +350,21 @@ public: int addPerpendicularConstraint(int geoId1, int geoId2); /// add a tangency constraint between two geometries int addTangentConstraint(int geoId1, int geoId2); - int addTangentLineAtBSplineKnotConstraint(int checkedlinegeoId, int checkedbsplinegeoId, + int addTangentLineAtBSplineKnotConstraint(int checkedlinegeoId, + int checkedbsplinegeoId, int checkedknotgeoid); - int addTangentLineEndpointAtBSplineKnotConstraint(int checkedlinegeoId, PointPos endpointPos, + int addTangentLineEndpointAtBSplineKnotConstraint(int checkedlinegeoId, + PointPos endpointPos, int checkedbsplinegeoId, int checkedknotgeoid); - int addAngleAtPointConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, int geoId3, - PointPos pos3, double* value, ConstraintType cTyp, + int addAngleAtPointConstraint(int geoId1, + PointPos pos1, + int geoId2, + PointPos pos2, + int geoId3, + PointPos pos3, + double* value, + ConstraintType cTyp, bool driving = true); /** * add a radius constraint on a circle or an arc @@ -379,7 +405,11 @@ public: * constraint value and already inserted into either the FixParameters or * Parameters array, as the case may be. */ - int addAngleConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double* value, + int addAngleConstraint(int geoId1, + PointPos pos1, + int geoId2, + PointPos pos2, + double* value, bool driving = true); /** * add angle-via-point constraint between any two curves @@ -388,20 +418,31 @@ public: * constraint value and already inserted into either the FixParameters or * Parameters array, as the case may be. */ - int addAngleViaPointConstraint(int geoId1, int geoId2, int geoId3, PointPos pos3, double value, + int addAngleViaPointConstraint(int geoId1, + int geoId2, + int geoId3, + PointPos pos3, + double value, bool driving = true); /// add an equal length or radius constraints between two lines or between circles and arcs int addEqualConstraint(int geoId1, int geoId2); /// add a point on line constraint int addPointOnObjectConstraint(int geoId1, PointPos pos1, int geoId2, bool driving = true); /// add a point on B-spline constraint: needs a parameter - int addPointOnObjectConstraint(int geoId1, PointPos pos1, int geoId2, double* pointparam, + int addPointOnObjectConstraint(int geoId1, + PointPos pos1, + int geoId2, + double* pointparam, bool driving = true); /// add a symmetric constraint between two points with respect to a line int addSymmetricConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, int geoId3); /// add a symmetric constraint between three points, the last point is in the middle of the /// first two - int addSymmetricConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, int geoId3, + int addSymmetricConstraint(int geoId1, + PointPos pos1, + int geoId2, + PointPos pos2, + int geoId3, PointPos pos3); /** * add a snell's law constraint @@ -414,8 +455,14 @@ public: * second may be initialized to any value, however the solver will * provide n1 in value and n2 in second. */ - int addSnellsLawConstraint(int geoIdRay1, PointPos posRay1, int geoIdRay2, PointPos posRay2, - int geoIdBnd, double* value, double* second, bool driving = true); + int addSnellsLawConstraint(int geoIdRay1, + PointPos posRay1, + int geoIdRay2, + PointPos posRay2, + int geoIdBnd, + double* value, + double* second, + bool driving = true); //@} /// Internal Alignment constraints @@ -486,13 +533,13 @@ protected: struct GeoDef { GeoDef() - : geo(nullptr), - type(None), - external(false), - index(-1), - startPointId(-1), - midPointId(-1), - endPointId(-1) + : geo(nullptr) + , type(None) + , external(false) + , index(-1) + , startPointId(-1) + , midPointId(-1) + , endPointId(-1) {} Part::Geometry* geo;// pointer to the geometry GeoType type; // type of the geometry @@ -506,10 +553,10 @@ protected: struct ConstrDef { ConstrDef() - : constr(nullptr), - driving(true), - value(nullptr), - secondvalue(nullptr) + : constr(nullptr) + , driving(true) + , value(nullptr) + , secondvalue(nullptr) {} Constraint* constr;// pointer to the constraint bool driving; diff --git a/src/Mod/Sketcher/App/SketchAnalysis.cpp b/src/Mod/Sketcher/App/SketchAnalysis.cpp index 84c530cb9c..b0ae379ba0 100644 --- a/src/Mod/Sketcher/App/SketchAnalysis.cpp +++ b/src/Mod/Sketcher/App/SketchAnalysis.cpp @@ -66,12 +66,15 @@ struct SketchAnalysis::Vertex_Less {} bool operator()(const VertexIds& x, const VertexIds& y) const { - if (fabs(x.v.x - y.v.x) > tolerance) + if (fabs(x.v.x - y.v.x) > tolerance) { return x.v.x < y.v.x; - if (fabs(x.v.y - y.v.y) > tolerance) + } + if (fabs(x.v.y - y.v.y) > tolerance) { return x.v.y < y.v.y; - if (fabs(x.v.z - y.v.z) > tolerance) + } + if (fabs(x.v.z - y.v.z) > tolerance) { return x.v.z < y.v.z; + } return false;// points are considered to be equal } @@ -121,8 +124,9 @@ struct SketchAnalysis::Edge_Less {} bool operator()(const EdgeIds& x, const EdgeIds& y) const { - if (fabs(x.l - y.l) > tolerance) + if (fabs(x.l - y.l) > tolerance) { return x.l < y.l; + } return false;// points are considered to be equal } @@ -157,8 +161,9 @@ int SketchAnalysis::detectMissingPointOnPointConstraints(double precision, for (std::size_t i = 0; i < geom.size(); i++) { auto gf = GeometryFacade::getFacade(geom[i]); - if (gf->getConstruction() && !includeconstruction) + if (gf->getConstruction() && !includeconstruction) { continue; + } if (gf->getGeometry()->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { const Part::GeomLineSegment* segm = @@ -321,16 +326,19 @@ int SketchAnalysis::detectMissingPointOnPointConstraints(double precision, for (std::set& grp : coincVertexGrps) { if ((grp.find(v1) != grp.end()) || (grp.find(v2) != grp.end())) { // If yes add them to the existing group - if (!nv1.empty()) + if (!nv1.empty()) { grp.insert(nv1.value()); - if (!nv2.empty()) + } + if (!nv2.empty()) { grp.insert(nv2.value()); + } continue; } } - if (nv1.empty() || nv2.empty()) + if (nv1.empty() || nv2.empty()) { continue; + } // If no, create a new group of coincident vertices std::set newGrp; @@ -479,8 +487,9 @@ void SketchAnalysis::makeMissingPointOnPointCoincident(bool onebyone) } } - if (!onebyone) + if (!onebyone) { sketch->addConstraints(constr); + } vertexConstraints.clear(); @@ -566,8 +575,9 @@ void SketchAnalysis::makeMissingVerticalHorizontal(bool onebyone) } } - if (!onebyone) + if (!onebyone) { sketch->addConstraints(constr); + } verthorizConstraints.clear(); @@ -735,8 +745,9 @@ void SketchAnalysis::makeMissingEquality(bool onebyone) std::vector constr; std::vector equalities(lineequalityConstraints); - equalities.insert( - equalities.end(), radiusequalityConstraints.begin(), radiusequalityConstraints.end()); + equalities.insert(equalities.end(), + radiusequalityConstraints.begin(), + radiusequalityConstraints.end()); for (std::vector::iterator it = equalities.begin(); it != equalities.end(); @@ -773,8 +784,9 @@ void SketchAnalysis::makeMissingEquality(bool onebyone) } } - if (!onebyone) + if (!onebyone) { sketch->addConstraints(constr); + } lineequalityConstraints.clear(); radiusequalityConstraints.clear(); @@ -789,10 +801,12 @@ void SketchAnalysis::solvesketch(int& status, int& dofs, bool updategeo) { status = sketch->solve(updategeo); - if (updategeo) + if (updategeo) { dofs = sketch->setUpSketch(); - else + } + else { dofs = sketch->getLastDoF(); + } if (sketch->getLastHasRedundancies()) {// redundant constraints status = -2; @@ -806,7 +820,8 @@ void SketchAnalysis::solvesketch(int& status, int& dofs, bool updategeo) } } -int SketchAnalysis::autoconstraint(double precision, double angleprecision, +int SketchAnalysis::autoconstraint(double precision, + double angleprecision, bool includeconstruction) { App::Document* doc = sketch->getDocument(); @@ -835,9 +850,10 @@ int SketchAnalysis::autoconstraint(double precision, double angleprecision, // as the solver may move the geometry in the meantime and prevent correct detection int nc = detectMissingPointOnPointConstraints(precision, includeconstruction); - if (nc - > 0)// STAGE 2a: Classify point-on-point into coincidents, endpoint perp, endpoint tangency + if (nc > 0) {// STAGE 2a: Classify point-on-point into coincidents, endpoint perp, endpoint + // tangency analyseMissingPointOnPointCoincident(angleprecision); + } // STAGE 3: Equality constraint detection int ne = detectMissingEqualityConstraints(precision); @@ -968,14 +984,16 @@ int SketchAnalysis::detectDegeneratedGeometries(double tolerance) for (std::size_t i = 0; i < geom.size(); i++) { auto gf = GeometryFacade::getFacade(geom[i]); - if (gf->getConstruction()) + if (gf->getConstruction()) { continue; + } if (gf->getGeometry()->getTypeId().isDerivedFrom(Part::GeomCurve::getClassTypeId())) { Part::GeomCurve* curve = static_cast(gf->getGeometry()); double len = curve->length(curve->getFirstParameter(), curve->getLastParameter()); - if (len < tolerance) + if (len < tolerance) { countDegenerated++; + } } } @@ -989,14 +1007,16 @@ int SketchAnalysis::removeDegeneratedGeometries(double tolerance) for (std::size_t i = 0; i < geom.size(); i++) { auto gf = GeometryFacade::getFacade(geom[i]); - if (gf->getConstruction()) + if (gf->getConstruction()) { continue; + } if (gf->getGeometry()->getTypeId().isDerivedFrom(Part::GeomCurve::getClassTypeId())) { Part::GeomCurve* curve = static_cast(gf->getGeometry()); double len = curve->length(curve->getFirstParameter(), curve->getLastParameter()); - if (len < tolerance) + if (len < tolerance) { delInternalGeometries.insert(static_cast(i)); + } } } diff --git a/src/Mod/Sketcher/App/SketchAnalysis.h b/src/Mod/Sketcher/App/SketchAnalysis.h index f246d3f5bb..964e418002 100644 --- a/src/Mod/Sketcher/App/SketchAnalysis.h +++ b/src/Mod/Sketcher/App/SketchAnalysis.h @@ -153,7 +153,8 @@ public: /// /// It applies coincidents - vertical/horizontal constraints and equality constraints. int autoconstraint(double precision = Precision::Confusion() * 1000, - double angleprecision = M_PI / 8, bool includeconstruction = true); + double angleprecision = M_PI / 8, + bool includeconstruction = true); // helper functions, which may be used by more complex methods, and/or called directly by user // space (python) methods diff --git a/src/Mod/Sketcher/App/SketchGeometryExtension.cpp b/src/Mod/Sketcher/App/SketchGeometryExtension.cpp index 8d2b9312f7..78ce37db64 100644 --- a/src/Mod/Sketcher/App/SketchGeometryExtension.cpp +++ b/src/Mod/Sketcher/App/SketchGeometryExtension.cpp @@ -43,15 +43,15 @@ TYPESYSTEM_SOURCE(Sketcher::SketchGeometryExtension, Part::GeometryPersistenceEx std::atomic SketchGeometryExtension::_GeometryID; SketchGeometryExtension::SketchGeometryExtension() - : Id(++SketchGeometryExtension::_GeometryID), - InternalGeometryType(InternalType::None), - GeometryLayer(0) + : Id(++SketchGeometryExtension::_GeometryID) + , InternalGeometryType(InternalType::None) + , GeometryLayer(0) {} SketchGeometryExtension::SketchGeometryExtension(long cid) - : Id(cid), - InternalGeometryType(InternalType::None), - GeometryLayer(0) + : Id(cid) + , InternalGeometryType(InternalType::None) + , GeometryLayer(0) {} void SketchGeometryExtension::copyAttributes(Part::GeometryExtension* cpy) const @@ -68,16 +68,18 @@ void SketchGeometryExtension::restoreAttributes(Base::XMLReader& reader) { Part::GeometryPersistenceExtension::restoreAttributes(reader); - if (reader.hasAttribute("id")) + if (reader.hasAttribute("id")) { Id = reader.getAttributeAsInteger("id"); + } InternalGeometryType = static_cast( reader.getAttributeAsInteger("internalGeometryType")); GeometryModeFlags = GeometryModeFlagType(reader.getAttribute("geometryModeFlags")); - if (reader.hasAttribute("geometryLayer")) + if (reader.hasAttribute("geometryLayer")) { GeometryLayer = reader.getAttributeAsInteger("geometryLayer"); + } } void SketchGeometryExtension::saveAttributes(Base::Writer& writer) const diff --git a/src/Mod/Sketcher/App/SketchGeometryExtensionPyImp.cpp b/src/Mod/Sketcher/App/SketchGeometryExtensionPyImp.cpp index e7c4de1a3b..9632229d21 100644 --- a/src/Mod/Sketcher/App/SketchGeometryExtensionPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchGeometryExtensionPyImp.cpp @@ -35,8 +35,9 @@ std::string SketchGeometryExtensionPy::representation() const std::stringstream str; str << "getName().empty()) + if (!getSketchGeometryExtensionPtr()->getName().empty()) { str << "\'" << getSketchGeometryExtensionPtr()->getName() << "\', "; + } str << "\""; @@ -89,8 +90,9 @@ Py::String SketchGeometryExtensionPy::getInternalType() const { int internaltypeindex = (int)this->getSketchGeometryExtensionPtr()->getInternalType(); - if (internaltypeindex >= InternalType::NumInternalGeometryType) + if (internaltypeindex >= InternalType::NumInternalGeometryType) { throw Py::NotImplementedError("String name of enum not implemented"); + } std::string typestr = this->getSketchGeometryExtensionPtr()->internaltype2str[internaltypeindex]; @@ -139,9 +141,10 @@ PyObject* SketchGeometryExtensionPy::testGeometryMode(PyObject* args) GeometryMode::GeometryMode mode; - if (getSketchGeometryExtensionPtr()->getGeometryModeFromName(flag, mode)) + if (getSketchGeometryExtensionPtr()->getGeometryModeFromName(flag, mode)) { return new_reference_to( Py::Boolean(getSketchGeometryExtensionPtr()->testGeometryMode(mode))); + } PyErr_SetString(PyExc_TypeError, "Flag string does not exist."); return nullptr; diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 5c48610ff3..fb363b25df 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -159,7 +159,10 @@ public: /// Deletes all constraints referencing an external geometry int delConstraintsToExternal(); /// transfers all constraints of a point to a new point - int transferConstraints(int fromGeoId, PointPos fromPosId, int toGeoId, PointPos toPosId, + int transferConstraints(int fromGeoId, + PointPos fromPosId, + int toGeoId, + PointPos toPosId, bool doNotTransformTangencies = false); /// Carbon copy another sketch geometry and constraints @@ -181,9 +184,10 @@ public: * id==-2 for the vertical sketch axis * id<=-3 for user defined projected external geometries, */ - template::type>::value>::type> + template< + typename GeometryT = Part::Geometry, + typename = typename std::enable_if< + std::is_base_of::type>::value>::type> const GeometryT* getGeometry(int GeoId) const; std::unique_ptr getGeometryFacade(int GeoId) const; @@ -270,10 +274,13 @@ public: /// toggle the driving status of this constraint int toggleVirtualSpace(int ConstrId); /// move this point to a new location and solve - int movePoint(int GeoId, PointPos PosId, const Base::Vector3d& toPoint, bool relative = false, + int movePoint(int GeoId, + PointPos PosId, + const Base::Vector3d& toPoint, + bool relative = false, bool updateGeoBeforeMoving = false); /// retrieves the coordinates of a point - static Base::Vector3d getPoint(const Part::Geometry *geo, PointPos PosId); + static Base::Vector3d getPoint(const Part::Geometry* geo, PointPos PosId); Base::Vector3d getPoint(int GeoId, PointPos PosId) const; /// toggle geometry to draft line @@ -288,8 +295,8 @@ public: \param createCorner - keep geoId/pos as a Point and keep as many constraints as possible \retval - 0 on success, -1 on failure */ - int fillet(int geoId, PointPos pos, double radius, bool trim = true, - bool preserveCorner = false); + int + fillet(int geoId, PointPos pos, double radius, bool trim = true, bool preserveCorner = false); /*! \brief More general form of fillet \param geoId1, geoId2 - geoId for two lines (which don't necessarily have to coincide) @@ -299,8 +306,13 @@ public: meet and keep as many of the existing constraints as possible \retval - 0 on success, -1 on failure */ - int fillet(int geoId1, int geoId2, const Base::Vector3d& refPnt1, const Base::Vector3d& refPnt2, - double radius, bool trim = true, bool createCorner = false); + int fillet(int geoId1, + int geoId2, + const Base::Vector3d& refPnt1, + const Base::Vector3d& refPnt2, + double radius, + bool trim = true, + bool createCorner = false); /// trim a curve int trim(int geoId, const Base::Vector3d& point); @@ -317,15 +329,21 @@ public: int join(int geoId1, Sketcher::PointPos posId1, int geoId2, Sketcher::PointPos posId2); /// adds symmetric geometric elements with respect to the refGeoId (line or point) - int addSymmetric(const std::vector& geoIdList, int refGeoId, + int addSymmetric(const std::vector& geoIdList, + int refGeoId, Sketcher::PointPos refPosId = Sketcher::PointPos::none); /// with default parameters adds a copy of the geometric elements displaced by the displacement /// vector. It creates an array of csize elements in the direction of the displacement vector by /// rsize elements in the direction perpendicular to the displacement vector, wherein the /// modulus of this perpendicular vector is scaled by perpscale. - int addCopy(const std::vector& geoIdList, const Base::Vector3d& displacement, - bool moveonly = false, bool clone = false, int csize = 2, int rsize = 1, - bool constraindisplacement = false, double perpscale = 1.0); + int addCopy(const std::vector& geoIdList, + const Base::Vector3d& displacement, + bool moveonly = false, + bool clone = false, + int csize = 2, + int rsize = 1, + bool constraindisplacement = false, + double perpscale = 1.0); int removeAxesAlignment(const std::vector& geoIdList); /// Exposes all internal geometry of an object supporting internal geometry @@ -406,7 +424,9 @@ public: const std::vector> getCoincidenceGroups(); // returns if the given geoId is fixed (coincident) with external geometry on any of the // possible relevant points - void isCoincidentWithExternalGeometry(int GeoId, bool& start_external, bool& mid_external, + void isCoincidentWithExternalGeometry(int GeoId, + bool& start_external, + bool& mid_external, bool& end_external); // returns a map containing all the GeoIds that are coincident with the given point as keys, and // the PosIds as values associated with the keys. @@ -414,9 +434,12 @@ public: /// retrieves for a Vertex number a list with all coincident points (sharing a single /// coincidence constraint) - void getDirectlyCoincidentPoints(int GeoId, PointPos PosId, std::vector& GeoIdList, + void getDirectlyCoincidentPoints(int GeoId, + PointPos PosId, + std::vector& GeoIdList, std::vector& PosIdList); - void getDirectlyCoincidentPoints(int VertexId, std::vector& GeoIdList, + void getDirectlyCoincidentPoints(int VertexId, + std::vector& GeoIdList, std::vector& PosIdList); bool arePointsCoincident(int GeoId1, PointPos PosId1, int GeoId2, PointPos PosId2); @@ -539,14 +562,16 @@ public: /* Solver exposed interface */ inline int initTemporaryMove(int geoId, PointPos pos, bool fine = true); /// Forwards a request for a temporary initBSplinePieceMove to the solver using the current /// sketch state as a reference (enables dragging) - inline int initTemporaryBSplinePieceMove(int geoId, PointPos pos, - const Base::Vector3d& firstPoint, bool fine = true); + inline int initTemporaryBSplinePieceMove(int geoId, + PointPos pos, + const Base::Vector3d& firstPoint, + bool fine = true); /** Forwards a request for point or curve temporary movement to the solver using the current * state as a reference (enables dragging). NOTE: A temporary move operation must always be * preceded by a initTemporaryMove() operation. */ - inline int moveTemporaryPoint(int geoId, PointPos pos, Base::Vector3d toPoint, - bool relative = false); + inline int + moveTemporaryPoint(int geoId, PointPos pos, Base::Vector3d toPoint, bool relative = false); /// forwards a request to update an extension of a geometry of the solver to the solver. inline void updateSolverExtension(int geoId, std::unique_ptr&& ext) { @@ -593,40 +618,44 @@ public: }; /// Return true if this object is allowed as external geometry for the /// sketch. rsn argument receives the reason for disallowing. - bool isExternalAllowed(App::Document* pDoc, App::DocumentObject* pObj, + bool isExternalAllowed(App::Document* pDoc, + App::DocumentObject* pObj, eReasonList* rsn = nullptr) const; - bool isCarbonCopyAllowed(App::Document* pDoc, App::DocumentObject* pObj, bool& xinv, bool& yinv, + bool isCarbonCopyAllowed(App::Document* pDoc, + App::DocumentObject* pObj, + bool& xinv, + bool& yinv, eReasonList* rsn = nullptr) const; - Part::TopoShape getEdge(const Part::Geometry *geo, const char *name) const; + Part::TopoShape getEdge(const Part::Geometry* geo, const char* name) const; - Data::IndexedName checkSubName(const char *sub) const; + Data::IndexedName checkSubName(const char* sub) const; - bool geoIdFromShapeType(const Data::IndexedName &, int &geoId, PointPos &posId) const; + bool geoIdFromShapeType(const Data::IndexedName&, int& geoId, PointPos& posId) const; - bool geoIdFromShapeType(const char *shapetype, int &geoId, PointPos &posId) const + bool geoIdFromShapeType(const char* shapetype, int& geoId, PointPos& posId) const { return geoIdFromShapeType(checkSubName(shapetype), geoId, posId); } - bool geoIdFromShapeType(const char *shapetype, int &geoId) const + bool geoIdFromShapeType(const char* shapetype, int& geoId) const { PointPos posId; - return geoIdFromShapeType(shapetype,geoId,posId); + return geoIdFromShapeType(shapetype, geoId, posId); } - std::string convertSubName(const char *subname, bool postfix=true) const + std::string convertSubName(const char* subname, bool postfix = true) const { return convertSubName(checkSubName(subname), postfix); } - std::string convertSubName(const std::string & subname, bool postfix=true) const + std::string convertSubName(const std::string& subname, bool postfix = true) const { return convertSubName(subname.c_str(), postfix); } - std::string convertSubName(const Data::IndexedName &, bool postfix=true) const; + std::string convertSubName(const Data::IndexedName&, bool postfix = true) const; bool isPerformingInternalTransaction() const { @@ -638,13 +667,18 @@ public: * - it includes internal and external intersecting geometry. * - it returns GeoEnum::GeoUndef if no intersection is found. */ - bool seekTrimPoints(int GeoId, const Base::Vector3d& point, int& GeoId1, - Base::Vector3d& intersect1, int& GeoId2, Base::Vector3d& intersect2); + bool seekTrimPoints(int GeoId, + const Base::Vector3d& point, + int& GeoId1, + Base::Vector3d& intersect1, + int& GeoId2, + Base::Vector3d& intersect2); public: // Analyser functions int autoConstraint(double precision = Precision::Confusion() * 1000, - double angleprecision = M_PI / 20, bool includeconstruction = true); + double angleprecision = M_PI / 20, + bool includeconstruction = true); int detectMissingPointOnPointConstraints(double precision = Precision::Confusion() * 1000, bool includeconstruction = true); @@ -726,8 +760,10 @@ protected: // migration functions void migrateSketch(); - static void appendConstraintsMsg(const std::vector& vector, const std::string& singularmsg, - const std::string& pluralmsg, std::string& msg); + static void appendConstraintsMsg(const std::vector& vector, + const std::string& singularmsg, + const std::string& pluralmsg, + std::string& msg); // retrieves redundant, conflicting and malformed constraint information from the solver void retrieveSolverDiagnostics(); @@ -746,16 +782,20 @@ protected: void synchroniseGeometryState(); // helper function to create a new constraint and move it to the Constraint Property - void addConstraint(Sketcher::ConstraintType constrType, int firstGeoId, - Sketcher::PointPos firstPos, int secondGeoId = GeoEnum::GeoUndef, + void addConstraint(Sketcher::ConstraintType constrType, + int firstGeoId, + Sketcher::PointPos firstPos, + int secondGeoId = GeoEnum::GeoUndef, Sketcher::PointPos secondPos = Sketcher::PointPos::none, int thirdGeoId = GeoEnum::GeoUndef, Sketcher::PointPos thirdPos = Sketcher::PointPos::none); // creates a new constraint std::unique_ptr - createConstraint(Sketcher::ConstraintType constrType, int firstGeoId, - Sketcher::PointPos firstPos, int secondGeoId = GeoEnum::GeoUndef, + createConstraint(Sketcher::ConstraintType constrType, + int firstGeoId, + Sketcher::PointPos firstPos, + int secondGeoId = GeoEnum::GeoUndef, Sketcher::PointPos secondPos = Sketcher::PointPos::none, int thirdGeoId = GeoEnum::GeoUndef, Sketcher::PointPos thirdPos = Sketcher::PointPos::none); @@ -830,25 +870,31 @@ inline int SketchObject::initTemporaryMove(int geoId, PointPos pos, bool fine /* // if a previous operation did not update the geometry (including geometry extensions) // or constraints (including any deleted pointer, as in renameConstraint) of the solver, // here we update them before starting a temporary operation. - if (solverNeedsUpdate) + if (solverNeedsUpdate) { solve(); + } return solvedSketch.initMove(geoId, pos, fine); } -inline int SketchObject::initTemporaryBSplinePieceMove(int geoId, PointPos pos, - const Base::Vector3d& firstPoint, bool fine) +inline int SketchObject::initTemporaryBSplinePieceMove(int geoId, + PointPos pos, + const Base::Vector3d& firstPoint, + bool fine) { // if a previous operation did not update the geometry (including geometry extensions) // or constraints (including any deleted pointer, as in renameConstraint) of the solver, // here we update them before starting a temporary operation. - if (solverNeedsUpdate) + if (solverNeedsUpdate) { solve(); + } return solvedSketch.initBSplinePieceMove(geoId, pos, firstPoint, fine); } -inline int SketchObject::moveTemporaryPoint(int geoId, PointPos pos, Base::Vector3d toPoint, +inline int SketchObject::moveTemporaryPoint(int geoId, + PointPos pos, + Base::Vector3d toPoint, bool relative /*=false*/) { return solvedSketch.movePoint(geoId, pos, toPoint, relative); @@ -859,11 +905,13 @@ const GeometryT* SketchObject::getGeometry(int GeoId) const { if (GeoId >= 0) { const std::vector& geomlist = getInternalGeometry(); - if (GeoId < int(geomlist.size())) + if (GeoId < int(geomlist.size())) { return static_cast(geomlist[GeoId]); + } } - else if (-GeoId <= int(ExternalGeo.size())) + else if (-GeoId <= int(ExternalGeo.size())) { return static_cast(ExternalGeo[-GeoId - 1]); + } return nullptr; } diff --git a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp index c0b721eaa1..7ecb17ebe0 100644 --- a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp @@ -601,7 +601,8 @@ PyObject* SketchObjectPy::delConstraintOnPoint(PyObject* args) && pos <= static_cast(Sketcher::PointPos::mid)) { // This is the whole range of valid positions if (this->getSketchObjectPtr()->delConstraintOnPoint( - Index, static_cast(pos))) { + Index, + static_cast(pos))) { std::stringstream str; str << "Not able to delete a constraint on point with the given index: " << Index << " and position: " << pos; @@ -1055,15 +1056,22 @@ PyObject* SketchObjectPy::movePoint(PyObject* args) int GeoId, PointType; int relative = 0; - if (!PyArg_ParseTuple( - args, "iiO!|i", &GeoId, &PointType, &(Base::VectorPy::Type), &pcObj, &relative)) { + if (!PyArg_ParseTuple(args, + "iiO!|i", + &GeoId, + &PointType, + &(Base::VectorPy::Type), + &pcObj, + &relative)) { return nullptr; } Base::Vector3d v1 = static_cast(pcObj)->value(); - if (this->getSketchObjectPtr()->movePoint( - GeoId, static_cast(PointType), v1, (relative > 0))) { + if (this->getSketchObjectPtr()->movePoint(GeoId, + static_cast(PointType), + v1, + (relative > 0))) { std::stringstream str; str << "Not able to move point with the id and type: (" << GeoId << ", " << PointType << ")"; @@ -1150,8 +1158,8 @@ PyObject* SketchObjectPy::fillet(PyObject* args) Base::Vector3d v1 = static_cast(pcObj1)->value(); Base::Vector3d v2 = static_cast(pcObj2)->value(); - if (this->getSketchObjectPtr()->fillet( - geoId1, geoId2, v1, v2, radius, trim, Base::asBoolean(createCorner))) { + if (this->getSketchObjectPtr() + ->fillet(geoId1, geoId2, v1, v2, radius, trim, Base::asBoolean(createCorner))) { std::stringstream str; str << "Not able to fillet curves with ids : (" << geoId1 << ", " << geoId2 << ") and points (" << v1.x << ", " << v1.y << ", " << v1.z << ") & " @@ -1164,8 +1172,14 @@ PyObject* SketchObjectPy::fillet(PyObject* args) PyErr_Clear(); // Point, radius - if (PyArg_ParseTuple( - args, "iid|iO!", &geoId1, &posId1, &radius, &trim, &PyBool_Type, &createCorner)) { + if (PyArg_ParseTuple(args, + "iid|iO!", + &geoId1, + &posId1, + &radius, + &trim, + &PyBool_Type, + &createCorner)) { if (this->getSketchObjectPtr()->fillet(geoId1, static_cast(posId1), radius, @@ -1215,8 +1229,9 @@ PyObject* SketchObjectPy::extend(PyObject* args) int GeoId; if (PyArg_ParseTuple(args, "idi", &GeoId, &increment, &endPoint)) { - if (this->getSketchObjectPtr()->extend( - GeoId, increment, static_cast(endPoint))) { + if (this->getSketchObjectPtr()->extend(GeoId, + increment, + static_cast(endPoint))) { std::stringstream str; str << "Not able to extend geometry with id : (" << GeoId << ") for increment (" << increment << ") and point position (" << endPoint << ")"; @@ -1267,8 +1282,10 @@ PyObject* SketchObjectPy::join(PyObject* args) return nullptr; } - if (this->getSketchObjectPtr()->join( - GeoId1, (Sketcher::PointPos)PosId1, GeoId2, (Sketcher::PointPos)PosId2)) { + if (this->getSketchObjectPtr()->join(GeoId1, + (Sketcher::PointPos)PosId1, + GeoId2, + (Sketcher::PointPos)PosId2)) { std::stringstream str; str << "Not able to join the curves with end points: (" << GeoId1 << ", " << PosId1 << "), (" << GeoId2 << ", " << PosId2 << ")"; @@ -1298,8 +1315,10 @@ PyObject* SketchObjectPy::addSymmetric(PyObject* args) } } - int ret = this->getSketchObjectPtr()->addSymmetric( - geoIdList, refGeoId, static_cast(refPosId)) + int ret = + this->getSketchObjectPtr()->addSymmetric(geoIdList, + refGeoId, + static_cast(refPosId)) + 1; if (ret == -1) { @@ -1326,8 +1345,13 @@ PyObject* SketchObjectPy::addCopy(PyObject* args) PyObject *pcObj, *pcVect; PyObject* clone = Py_False; - if (!PyArg_ParseTuple( - args, "OO!|O!", &pcObj, &(Base::VectorPy::Type), &pcVect, &PyBool_Type, &clone)) { + if (!PyArg_ParseTuple(args, + "OO!|O!", + &pcObj, + &(Base::VectorPy::Type), + &pcVect, + &PyBool_Type, + &clone)) { return nullptr; } @@ -1692,8 +1716,9 @@ PyObject* SketchObjectPy::modifyBSplineKnotMultiplicity(PyObject* args) return nullptr; } - if (!this->getSketchObjectPtr()->modifyBSplineKnotMultiplicity( - GeoId, knotIndex, multiplicity)) { + if (!this->getSketchObjectPtr()->modifyBSplineKnotMultiplicity(GeoId, + knotIndex, + multiplicity)) { std::stringstream str; str << "Multiplicity modification failed for: " << GeoId; PyErr_SetString(PyExc_ValueError, str.str().c_str()); @@ -1730,13 +1755,18 @@ PyObject* SketchObjectPy::autoconstraint(PyObject* args) PyObject* includeconstruction = Py_True; - if (!PyArg_ParseTuple( - args, "|ddO!", &precision, &angleprecision, &PyBool_Type, &includeconstruction)) { + if (!PyArg_ParseTuple(args, + "|ddO!", + &precision, + &angleprecision, + &PyBool_Type, + &includeconstruction)) { return nullptr; } - if (this->getSketchObjectPtr()->autoConstraint( - precision, angleprecision, Base::asBoolean(includeconstruction))) { + if (this->getSketchObjectPtr()->autoConstraint(precision, + angleprecision, + Base::asBoolean(includeconstruction))) { std::stringstream str; str << "Unable to autoconstraint"; PyErr_SetString(PyExc_ValueError, str.str().c_str()); @@ -1757,7 +1787,8 @@ PyObject* SketchObjectPy::detectMissingPointOnPointConstraints(PyObject* args) return Py::new_reference_to( Py::Long(this->getSketchObjectPtr()->detectMissingPointOnPointConstraints( - precision, Base::asBoolean(includeconstruction)))); + precision, + Base::asBoolean(includeconstruction)))); } PyObject* SketchObjectPy::detectMissingVerticalHorizontalConstraints(PyObject* args) diff --git a/src/Mod/Sketcher/App/SketchObjectSF.cpp b/src/Mod/Sketcher/App/SketchObjectSF.cpp index 7a76de4c01..87da13e326 100644 --- a/src/Mod/Sketcher/App/SketchObjectSF.cpp +++ b/src/Mod/Sketcher/App/SketchObjectSF.cpp @@ -42,8 +42,9 @@ SketchObjectSF::SketchObjectSF() short SketchObjectSF::mustExecute() const { - if (SketchFlatFile.isTouched()) + if (SketchFlatFile.isTouched()) { return 1; + } return 0; } diff --git a/src/Mod/Sketcher/App/SketchObjectSFPy.xml b/src/Mod/Sketcher/App/SketchObjectSFPy.xml index b9b81c4b3c..db7f521fa3 100644 --- a/src/Mod/Sketcher/App/SketchObjectSFPy.xml +++ b/src/Mod/Sketcher/App/SketchObjectSFPy.xml @@ -1,13 +1,13 @@  - diff --git a/src/Mod/Sketcher/App/SketchPyImp.cpp b/src/Mod/Sketcher/App/SketchPyImp.cpp index 4949eca6d4..97cc597852 100644 --- a/src/Mod/Sketcher/App/SketchPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchPyImp.cpp @@ -58,8 +58,9 @@ int SketchPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/) PyObject* SketchPy::solve(PyObject* args) { - if (!PyArg_ParseTuple(args, "")) + if (!PyArg_ParseTuple(args, "")) { return nullptr; + } getSketchPtr()->resetSolver(); return Py::new_reference_to(Py::Long(getSketchPtr()->solve())); } @@ -67,8 +68,9 @@ PyObject* SketchPy::solve(PyObject* args) PyObject* SketchPy::addGeometry(PyObject* args) { PyObject* pcObj; - if (!PyArg_ParseTuple(args, "O", &pcObj)) + if (!PyArg_ParseTuple(args, "O", &pcObj)) { return nullptr; + } if (PyObject_TypeCheck(pcObj, &(Part::GeometryPy::Type))) { Part::Geometry* geo = static_cast(pcObj)->getGeometryPtr(); @@ -103,8 +105,9 @@ PyObject* SketchPy::addGeometry(PyObject* args) PyObject* SketchPy::addConstraint(PyObject* args) { PyObject* pcObj; - if (!PyArg_ParseTuple(args, "O", &pcObj)) + if (!PyArg_ParseTuple(args, "O", &pcObj)) { return nullptr; + } if (PyObject_TypeCheck(pcObj, &(PyList_Type)) || PyObject_TypeCheck(pcObj, &(PyTuple_Type))) { std::vector values; @@ -139,8 +142,9 @@ PyObject* SketchPy::addConstraint(PyObject* args) PyObject* SketchPy::clear(PyObject* args) { - if (!PyArg_ParseTuple(args, "")) + if (!PyArg_ParseTuple(args, "")) { return nullptr; + } getSketchPtr()->clear(); @@ -152,13 +156,22 @@ PyObject* SketchPy::movePoint(PyObject* args) int index1, index2; PyObject* pcObj; int relative = 0; - if (!PyArg_ParseTuple( - args, "iiO!|i", &index1, &index2, &(Base::VectorPy::Type), &pcObj, &relative)) + if (!PyArg_ParseTuple(args, + "iiO!|i", + &index1, + &index2, + &(Base::VectorPy::Type), + &pcObj, + &relative)) { return nullptr; + } Base::Vector3d* toPoint = static_cast(pcObj)->getVectorPtr(); - return Py::new_reference_to(Py::Long(getSketchPtr()->movePoint( - index1, static_cast(index2), *toPoint, (relative > 0)))); + return Py::new_reference_to( + Py::Long(getSketchPtr()->movePoint(index1, + static_cast(index2), + *toPoint, + (relative > 0)))); } // +++ attributes implementer ++++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/src/Mod/Sketcher/App/SolverGeometryExtension.cpp b/src/Mod/Sketcher/App/SolverGeometryExtension.cpp index cb75eabdf9..f5b9125625 100644 --- a/src/Mod/Sketcher/App/SolverGeometryExtension.cpp +++ b/src/Mod/Sketcher/App/SolverGeometryExtension.cpp @@ -34,9 +34,9 @@ using namespace Sketcher; TYPESYSTEM_SOURCE(Sketcher::SolverGeometryExtension, Part::GeometryExtension) SolverGeometryExtension::SolverGeometryExtension() - : Start(SolverGeometryExtension::Dependent), - Mid(SolverGeometryExtension::Dependent), - End(SolverGeometryExtension::Dependent) + : Start(SolverGeometryExtension::Dependent) + , Mid(SolverGeometryExtension::Dependent) + , End(SolverGeometryExtension::Dependent) {} void SolverGeometryExtension::copyAttributes(Part::GeometryExtension* cpy) const @@ -69,12 +69,15 @@ PyObject* SolverGeometryExtension::getPyObject() SolverGeometryExtension::PointParameterStatus SolverGeometryExtension::getPoint(Sketcher::PointPos pos) const { - if (pos == Sketcher::PointPos::start) + if (pos == Sketcher::PointPos::start) { return getStartPoint(); - if (pos == Sketcher::PointPos::end) + } + if (pos == Sketcher::PointPos::end) { return getEndPoint(); - if (pos == Sketcher::PointPos::mid) + } + if (pos == Sketcher::PointPos::mid) { return getMidPoint(); + } THROWM(Base::ValueError, "SolverGeometryExtension - getPoint: Edge is not a point"); } @@ -98,21 +101,24 @@ void SolverGeometryExtension::notifyAttachment(Part::Geometry* geo) auto result = edgeParamMap.find(GeometryType); - if (result == edgeParamMap.end()) + if (result == edgeParamMap.end()) { THROWM(Base::TypeError, "SolverGeometryExtension - notifyAttachment - Geometry not supported!!"); + } auto nedgeparams = (*result).second; - if (nedgeparams > 0) + if (nedgeparams > 0) { Edge.init(nedgeparams); + } } void SolverGeometryExtension::ensureType(const Base::Type& type) { - if (GeometryType != type) + if (GeometryType != type) { THROWM(Base::TypeError, "SolverGeometryExtension - requested edge parameters do not match underlying type!"); + } } SolverGeometryExtension::Point& SolverGeometryExtension::getPoint() diff --git a/src/Mod/Sketcher/App/SolverGeometryExtension.h b/src/Mod/Sketcher/App/SolverGeometryExtension.h index 790076a8f9..f9a420b8a6 100644 --- a/src/Mod/Sketcher/App/SolverGeometryExtension.h +++ b/src/Mod/Sketcher/App/SolverGeometryExtension.h @@ -96,12 +96,15 @@ public: bool xfree = isXDoF(); bool yfree = isYDoF(); - if (xfree && yfree) + if (xfree && yfree) { return 2; - else if (xfree || yfree) + } + else if (xfree || yfree) { return 1; - else + } + else { return 0; + } } void setStatus(ParameterStatus status) @@ -156,8 +159,9 @@ public: void setStatus(int index, ParameterStatus status) { - if (index >= int(pstatus.size())) + if (index >= int(pstatus.size())) { pstatus.resize(index + 1, ParameterStatus::Dependent); + } pstatus.at(index) = status; }; @@ -327,8 +331,9 @@ public: { int npoles = pstatus.size() / 3; - if (poleindex < npoles) + if (poleindex < npoles) { return pstatus[poleindex * 2]; + } THROWM(Base::IndexError, "Pole index out of range") } @@ -337,8 +342,9 @@ public: { int npoles = pstatus.size() / 3; - if (poleindex < npoles) + if (poleindex < npoles) { return pstatus[poleindex * 2 + 1]; + } THROWM(Base::IndexError, "Pole index out of range") } @@ -347,8 +353,9 @@ public: { int nweights = pstatus.size() / 3; - if (weightindex < nweights) + if (weightindex < nweights) { return pstatus[nweights * 2 + weightindex]; + } THROWM(Base::IndexError, "Weight index out of range") } diff --git a/src/Mod/Sketcher/App/planegcs/SubSystem.cpp b/src/Mod/Sketcher/App/planegcs/SubSystem.cpp index f6e5b0db46..17aa57befe 100644 --- a/src/Mod/Sketcher/App/planegcs/SubSystem.cpp +++ b/src/Mod/Sketcher/App/planegcs/SubSystem.cpp @@ -63,8 +63,11 @@ void SubSystem::initialize(VEC_pD& params, MAP_pD_pD& reductionmap) VEC_pD constr_params = (*constr)->params(); s2.insert(constr_params.begin(), constr_params.end()); } - std::set_intersection( - s1.begin(), s1.end(), s2.begin(), s2.end(), std::back_inserter(tmpplist)); + std::set_intersection(s1.begin(), + s1.end(), + s2.begin(), + s2.end(), + std::back_inserter(tmpplist)); } plist.clear(); @@ -82,8 +85,9 @@ void SubSystem::initialize(VEC_pD& params, MAP_pD_pD& reductionmap) pindex[itr->second] = i; i++; } - else// the reduction target is already in plist, just inform rindex + else {// the reduction target is already in plist, just inform rindex rindex[itr->first] = itp->second; + } } else if (pindex.find(*itt) == pindex.end()) {// not in plist yet, so add it now plist.push_back(*itt); @@ -103,8 +107,9 @@ void SubSystem::initialize(VEC_pD& params, MAP_pD_pD& reductionmap) pmap[plist[j]] = &pvals[j]; pvals[j] = *plist[j]; } - for (MAP_pD_I::const_iterator itr = rindex.begin(); itr != rindex.end(); ++itr) + for (MAP_pD_I::const_iterator itr = rindex.begin(); itr != rindex.end(); ++itr) { pmap[itr->first] = &pvals[itr->second]; + } c2p.clear(); p2c.clear(); @@ -116,8 +121,9 @@ void SubSystem::initialize(VEC_pD& params, MAP_pD_pD& reductionmap) for (VEC_pD::const_iterator p = constr_params_orig.begin(); p != constr_params_orig.end(); ++p) { MAP_pD_pD::const_iterator pmapfind = pmap.find(*p); - if (pmapfind != pmap.end()) + if (pmapfind != pmap.end()) { constr_params.insert(pmapfind->second); + } } for (SET_pD::const_iterator p = constr_params.begin(); p != constr_params.end(); ++p) { // jacobi.set(*constr, *p, 0.); @@ -131,8 +137,9 @@ void SubSystem::initialize(VEC_pD& params, MAP_pD_pD& reductionmap) void SubSystem::redirectParams() { // copying values to pvals - for (MAP_pD_pD::const_iterator p = pmap.begin(); p != pmap.end(); ++p) + for (MAP_pD_pD::const_iterator p = pmap.begin(); p != pmap.end(); ++p) { *(p->second) = *(p->first); + } // redirect constraints to point to pvals for (std::vector::iterator constr = clist.begin(); constr != clist.end(); @@ -144,8 +151,10 @@ void SubSystem::redirectParams() void SubSystem::revertParams() { - for (std::vector::iterator constr = clist.begin(); constr != clist.end(); ++constr) + for (std::vector::iterator constr = clist.begin(); constr != clist.end(); + ++constr) { (*constr)->revertParams(); + } } void SubSystem::getParamMap(MAP_pD_pD& pmapOut) @@ -160,23 +169,27 @@ void SubSystem::getParamList(VEC_pD& plistOut) void SubSystem::getParams(VEC_pD& params, Eigen::VectorXd& xOut) { - if (xOut.size() != int(params.size())) + if (xOut.size() != int(params.size())) { xOut.setZero(params.size()); + } for (int j = 0; j < int(params.size()); j++) { MAP_pD_pD::const_iterator pmapfind = pmap.find(params[j]); - if (pmapfind != pmap.end()) + if (pmapfind != pmap.end()) { xOut[j] = *(pmapfind->second); + } } } void SubSystem::getParams(Eigen::VectorXd& xOut) { - if (xOut.size() != psize) + if (xOut.size() != psize) { xOut.setZero(psize); + } - for (int i = 0; i < psize; i++) + for (int i = 0; i < psize; i++) { xOut[i] = pvals[i]; + } } void SubSystem::setParams(VEC_pD& params, Eigen::VectorXd& xIn) @@ -184,16 +197,18 @@ void SubSystem::setParams(VEC_pD& params, Eigen::VectorXd& xIn) assert(xIn.size() == int(params.size())); for (int j = 0; j < int(params.size()); j++) { MAP_pD_pD::const_iterator pmapfind = pmap.find(params[j]); - if (pmapfind != pmap.end()) + if (pmapfind != pmap.end()) { *(pmapfind->second) = xIn[j]; + } } } void SubSystem::setParams(Eigen::VectorXd& xIn) { assert(xIn.size() == psize); - for (int i = 0; i < psize; i++) + for (int i = 0; i < psize; i++) { pvals[i] = xIn[i]; + } } void SubSystem::getConstraintList(std::vector& clist_) @@ -259,9 +274,11 @@ void SubSystem::calcJacobi(VEC_pD& params, Eigen::MatrixXd& jacobi) jacobi.setZero(csize, params.size()); for (int j = 0; j < int(params.size()); j++) { MAP_pD_pD::const_iterator pmapfind = pmap.find(params[j]); - if (pmapfind != pmap.end()) - for (int i = 0; i < csize; i++) + if (pmapfind != pmap.end()) { + for (int i = 0; i < csize; i++) { jacobi(i, j) = clist[i]->grad(pmapfind->second); + } + } } } @@ -282,8 +299,9 @@ void SubSystem::calcGrad(VEC_pD& params, Eigen::VectorXd& grad) std::vector constrs = p2c[pmapfind->second]; for (std::vector::const_iterator constr = constrs.begin(); constr != constrs.end(); - ++constr) + ++constr) { grad[j] += (*constr)->error() * (*constr)->grad(pmapfind->second); + } } } } @@ -300,13 +318,16 @@ double SubSystem::maxStep(VEC_pD& params, Eigen::VectorXd& xdir) MAP_pD_D dir; for (int j = 0; j < int(params.size()); j++) { MAP_pD_pD::const_iterator pmapfind = pmap.find(params[j]); - if (pmapfind != pmap.end()) + if (pmapfind != pmap.end()) { dir[pmapfind->second] = xdir[j]; + } } double alpha = 1e10; - for (std::vector::iterator constr = clist.begin(); constr != clist.end(); ++constr) + for (std::vector::iterator constr = clist.begin(); constr != clist.end(); + ++constr) { alpha = (*constr)->maxStep(dir, alpha); + } return alpha; } @@ -318,8 +339,9 @@ double SubSystem::maxStep(Eigen::VectorXd& xdir) void SubSystem::applySolution() { - for (MAP_pD_pD::const_iterator it = pmap.begin(); it != pmap.end(); ++it) + for (MAP_pD_pD::const_iterator it = pmap.begin(); it != pmap.end(); ++it) { *(it->first) = *(it->second); + } } void SubSystem::analyse(Eigen::MatrixXd& /*J*/, Eigen::MatrixXd& /*ker*/, Eigen::MatrixXd& /*img*/) diff --git a/src/Mod/Sketcher/App/planegcs/qp_eq.cpp b/src/Mod/Sketcher/App/planegcs/qp_eq.cpp index 9673915316..4cc37c2ce7 100644 --- a/src/Mod/Sketcher/App/planegcs/qp_eq.cpp +++ b/src/Mod/Sketcher/App/planegcs/qp_eq.cpp @@ -40,8 +40,9 @@ int qp_eq(MatrixXd& H, VectorXd& g, MatrixXd& A, VectorXd& c, VectorXd& x, Matri size_t constr_num = qrAT.cols(); size_t rank = qrAT.rank(); - if (rank != constr_num || constr_num > params_num) + if (rank != constr_num || constr_num > params_num) { return -1; + } // A^T = Q*R*P^T = Q1*R1*P^T // Q = [Q1,Q2], R=[R1;0] @@ -53,8 +54,9 @@ int qp_eq(MatrixXd& H, VectorXd& g, MatrixXd& A, VectorXd& c, VectorXd& x, Matri .transpose() .solve(Q.leftCols(rank)) * qrAT.colsPermutation().transpose(); - if (params_num == rank) + if (params_num == rank) { x = -Y * c; + } else { Z = Q.rightCols(params_num - rank); diff --git a/src/Mod/Sketcher/App/planegcs/qp_eq.h b/src/Mod/Sketcher/App/planegcs/qp_eq.h index 0d5489250e..fdb85c1bc4 100644 --- a/src/Mod/Sketcher/App/planegcs/qp_eq.h +++ b/src/Mod/Sketcher/App/planegcs/qp_eq.h @@ -21,5 +21,10 @@ ***************************************************************************/ #include -int qp_eq(Eigen::MatrixXd& H, Eigen::VectorXd& g, Eigen::MatrixXd& A, Eigen::VectorXd& c, - Eigen::VectorXd& x, Eigen::MatrixXd& Y, Eigen::MatrixXd& Z); +int qp_eq(Eigen::MatrixXd& H, + Eigen::VectorXd& g, + Eigen::MatrixXd& A, + Eigen::VectorXd& c, + Eigen::VectorXd& x, + Eigen::MatrixXd& Y, + Eigen::MatrixXd& Z); diff --git a/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp b/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp index 38ce0aeae8..e1dabb4eb2 100644 --- a/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp +++ b/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp @@ -199,8 +199,9 @@ void CmdSketcherToggleConstruction::activated(int iMsg) if (geo && geo->getTypeId() == Part::GeomPoint::getClassTypeId()) { // issue the actual commands to toggle - Gui::cmdAppObjectArgs( - selection[0].getObject(), "toggleConstruction(%d) ", geoId); + Gui::cmdAppObjectArgs(selection[0].getObject(), + "toggleConstruction(%d) ", + geoId); } } } diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.h b/src/Mod/Sketcher/Gui/CommandConstraints.h index d1435459ca..0d5947d4c1 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.h +++ b/src/Mod/Sketcher/Gui/CommandConstraints.h @@ -41,8 +41,11 @@ namespace SketcherGui /// NOTE: A command must be opened before calling this function, which this function /// commits or aborts as appropriate. The reason is for compatibility reasons with /// other code e.g. "Autoconstraints" in DrawSketchHandler.cpp -void makeTangentToEllipseviaNewPoint(Sketcher::SketchObject* Obj, const Part::GeomEllipse* ellipse, - const Part::Geometry* geom2, int geoId1, int geoId2); +void makeTangentToEllipseviaNewPoint(Sketcher::SketchObject* Obj, + const Part::GeomEllipse* ellipse, + const Part::Geometry* geom2, + int geoId1, + int geoId2); /// Makes a tangency constraint using external construction line between /// aoe => an arc of ellipse /// geom2 => any of an arc of ellipse, a circle, or an arc (of circle) @@ -53,7 +56,9 @@ void makeTangentToEllipseviaNewPoint(Sketcher::SketchObject* Obj, const Part::Ge /// other code e.g. "Autoconstraints" in DrawSketchHandler.cpp void makeTangentToArcOfEllipseviaNewPoint(Sketcher::SketchObject* Obj, const Part::GeomArcOfEllipse* aoe, - const Part::Geometry* geom2, int geoId1, int geoId2); + const Part::Geometry* geom2, + int geoId1, + int geoId2); /// Makes a tangency constraint using external construction line between /// aoh => an arc of hyperbola @@ -65,7 +70,9 @@ void makeTangentToArcOfEllipseviaNewPoint(Sketcher::SketchObject* Obj, /// other code e.g. "Autoconstraints" in DrawSketchHandler.cpp void makeTangentToArcOfHyperbolaviaNewPoint(Sketcher::SketchObject* Obj, const Part::GeomArcOfHyperbola* aoh, - const Part::Geometry* geom2, int geoId1, int geoId2); + const Part::Geometry* geom2, + int geoId1, + int geoId2); /// Makes a simple tangency constraint using extra point + tangent via point /// aop => an arc of parabola @@ -79,14 +86,21 @@ void makeTangentToArcOfHyperbolaviaNewPoint(Sketcher::SketchObject* Obj, /// DrawSketchHandler.cpp void makeTangentToArcOfParabolaviaNewPoint(Sketcher::SketchObject* Obj, const Part::GeomArcOfParabola* aop, - const Part::Geometry* geom2, int geoId1, int geoId2); + const Part::Geometry* geom2, + int geoId1, + int geoId2); /// Does an endpoint-to-endpoint tangency -void doEndpointTangency(Sketcher::SketchObject* Obj, int GeoId1, int GeoId2, - Sketcher::PointPos PosId1, Sketcher::PointPos PosId2); +void doEndpointTangency(Sketcher::SketchObject* Obj, + int GeoId1, + int GeoId2, + Sketcher::PointPos PosId1, + Sketcher::PointPos PosId2); /// Does an endpoint-edge tangency -void doEndpointToEdgeTangency(Sketcher::SketchObject* Obj, int GeoId1, Sketcher::PointPos PosId1, +void doEndpointToEdgeTangency(Sketcher::SketchObject* Obj, + int GeoId1, + Sketcher::PointPos PosId1, int GeoId2); /// shows constraint substitution information dialog box, enabling the user to forgo further diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index c1e1bc7744..bbb90b79ed 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -242,16 +242,20 @@ CmdSketcherCompCreateRectangles::CmdSketcherCompCreateRectangles() void CmdSketcherCompCreateRectangles::activated(int iMsg) { - if (iMsg == 0) + if (iMsg == 0) { ActivateHandler(getActiveGuiDocument(), new DrawSketchHandlerBox(DrawSketchHandlerBox::Diagonal)); - else if (iMsg == 1) + } + else if (iMsg == 1) { ActivateHandler(getActiveGuiDocument(), new DrawSketchHandlerBox(DrawSketchHandlerBox::CenterAndCorner)); - else if (iMsg == 2) + } + else if (iMsg == 2) { ActivateHandler(getActiveGuiDocument(), new DrawSketchHandlerOblong()); - else + } + else { return; + } // Since the default icon is reset when enabling/disabling the command we have // to explicitly set the icon of the used command. @@ -288,8 +292,9 @@ Gui::Action* CmdSketcherCompCreateRectangles::createAction() void CmdSketcherCompCreateRectangles::updateAction(int mode) { Gui::ActionGroup* pcAction = qobject_cast(getAction()); - if (!pcAction) + if (!pcAction) { return; + } QList a = pcAction->actions(); int index = pcAction->property("defaultAction").toInt(); @@ -314,8 +319,9 @@ void CmdSketcherCompCreateRectangles::languageChange() { Command::languageChange(); - if (!_pcAction) + if (!_pcAction) { return; + } Gui::ActionGroup* pcAction = qobject_cast(_pcAction); QList a = pcAction->actions(); @@ -455,12 +461,15 @@ CmdSketcherCompCreateArc::CmdSketcherCompCreateArc() void CmdSketcherCompCreateArc::activated(int iMsg) { - if (iMsg == 0) + if (iMsg == 0) { ActivateHandler(getActiveGuiDocument(), new DrawSketchHandlerArc()); - else if (iMsg == 1) + } + else if (iMsg == 1) { ActivateHandler(getActiveGuiDocument(), new DrawSketchHandler3PointArc()); - else + } + else { return; + } // Since the default icon is reset when enabling/disabling the command we have // to explicitly set the icon of the used command. @@ -495,8 +504,9 @@ Gui::Action* CmdSketcherCompCreateArc::createAction() void CmdSketcherCompCreateArc::updateAction(int mode) { Gui::ActionGroup* pcAction = qobject_cast(getAction()); - if (!pcAction) + if (!pcAction) { return; + } QList a = pcAction->actions(); int index = pcAction->property("defaultAction").toInt(); @@ -518,8 +528,9 @@ void CmdSketcherCompCreateArc::languageChange() { Command::languageChange(); - if (!_pcAction) + if (!_pcAction) { return; + } Gui::ActionGroup* pcAction = qobject_cast(_pcAction); QList a = pcAction->actions(); @@ -527,14 +538,17 @@ void CmdSketcherCompCreateArc::languageChange() arc1->setText(QApplication::translate("CmdSketcherCompCreateArc", "Center and end points")); arc1->setToolTip(QApplication::translate("Sketcher_CreateArc", "Create an arc by its center and by its end points")); - arc1->setStatusTip(QApplication::translate( - "Sketcher_CreateArc", "Create an arc by its center and by its end points")); + arc1->setStatusTip( + QApplication::translate("Sketcher_CreateArc", + "Create an arc by its center and by its end points")); QAction* arc2 = a[1]; arc2->setText(QApplication::translate("CmdSketcherCompCreateArc", "End points and rim point")); - arc2->setToolTip(QApplication::translate( - "Sketcher_Create3PointArc", "Create an arc by its end points and a point along the arc")); - arc2->setStatusTip(QApplication::translate( - "Sketcher_Create3PointArc", "Create an arc by its end points and a point along the arc")); + arc2->setToolTip( + QApplication::translate("Sketcher_Create3PointArc", + "Create an arc by its end points and a point along the arc")); + arc2->setStatusTip( + QApplication::translate("Sketcher_Create3PointArc", + "Create an arc by its end points and a point along the arc")); } bool CmdSketcherCompCreateArc::isActive() @@ -814,8 +828,9 @@ Gui::Action* CmdSketcherCompCreateConic::createAction() void CmdSketcherCompCreateConic::updateAction(int mode) { Gui::ActionGroup* pcAction = qobject_cast(getAction()); - if (!pcAction) + if (!pcAction) { return; + } QList a = pcAction->actions(); int index = pcAction->property("defaultAction").toInt(); @@ -848,21 +863,25 @@ void CmdSketcherCompCreateConic::languageChange() { Command::languageChange(); - if (!_pcAction) + if (!_pcAction) { return; + } Gui::ActionGroup* pcAction = qobject_cast(_pcAction); QList a = pcAction->actions(); QAction* ellipseByCenter = a[0]; ellipseByCenter->setText(QApplication::translate("CmdSketcherCompCreateConic", "Ellipse by center, major radius, point")); - ellipseByCenter->setToolTip(QApplication::translate( - "Sketcher_CreateEllipseByCenter", "Create an ellipse by center, major radius and point")); - ellipseByCenter->setStatusTip(QApplication::translate( - "Sketcher_CreateEllipseByCenter", "Create an ellipse by center, major radius and point")); + ellipseByCenter->setToolTip( + QApplication::translate("Sketcher_CreateEllipseByCenter", + "Create an ellipse by center, major radius and point")); + ellipseByCenter->setStatusTip( + QApplication::translate("Sketcher_CreateEllipseByCenter", + "Create an ellipse by center, major radius and point")); QAction* ellipseBy3Points = a[1]; - ellipseBy3Points->setText(QApplication::translate( - "CmdSketcherCompCreateConic", "Ellipse by periapsis, apoapsis, minor radius")); + ellipseBy3Points->setText( + QApplication::translate("CmdSketcherCompCreateConic", + "Ellipse by periapsis, apoapsis, minor radius")); ellipseBy3Points->setToolTip( QApplication::translate("Sketcher_CreateEllipseBy3Points", "Create a ellipse by periapsis, apoapsis, and minor radius")); @@ -870,8 +889,9 @@ void CmdSketcherCompCreateConic::languageChange() QApplication::translate("Sketcher_CreateEllipseBy3Points", "Create a ellipse by periapsis, apoapsis, and minor radius")); QAction* arcofellipse = a[2]; - arcofellipse->setText(QApplication::translate( - "CmdSketcherCompCreateConic", "Arc of ellipse by center, major radius, endpoints")); + arcofellipse->setText( + QApplication::translate("CmdSketcherCompCreateConic", + "Arc of ellipse by center, major radius, endpoints")); arcofellipse->setToolTip(QApplication::translate( "Sketcher_CreateArcOfEllipse", "Create an arc of ellipse by its center, major radius, and endpoints")); @@ -879,8 +899,9 @@ void CmdSketcherCompCreateConic::languageChange() "Sketcher_CreateArcOfEllipse", "Create an arc of ellipse by its center, major radius, and endpoints")); QAction* arcofhyperbola = a[3]; - arcofhyperbola->setText(QApplication::translate( - "CmdSketcherCompCreateConic", "Arc of hyperbola by center, major radius, endpoints")); + arcofhyperbola->setText( + QApplication::translate("CmdSketcherCompCreateConic", + "Arc of hyperbola by center, major radius, endpoints")); arcofhyperbola->setToolTip(QApplication::translate( "Sketcher_CreateArcOfHyperbola", "Create an arc of hyperbola by its center, major radius, and endpoints")); @@ -1117,8 +1138,9 @@ Gui::Action* CmdSketcherCompCreateBSpline::createAction() void CmdSketcherCompCreateBSpline::updateAction(int mode) { Gui::ActionGroup* pcAction = qobject_cast(getAction()); - if (!pcAction) + if (!pcAction) { return; + } QList a = pcAction->actions(); int index = pcAction->property("defaultAction").toInt(); @@ -1149,8 +1171,9 @@ void CmdSketcherCompCreateBSpline::languageChange() { Command::languageChange(); - if (!_pcAction) + if (!_pcAction) { return; + } Gui::ActionGroup* pcAction = qobject_cast(_pcAction); QList a = pcAction->actions(); @@ -1164,10 +1187,12 @@ void CmdSketcherCompCreateBSpline::languageChange() QAction* periodicbspline = a[1]; periodicbspline->setText(QApplication::translate("Sketcher_Create_Periodic_BSpline", "Periodic B-spline by control points")); - periodicbspline->setToolTip(QApplication::translate( - "Sketcher_Create_Periodic_BSpline", "Create a periodic B-spline by control points")); - periodicbspline->setStatusTip(QApplication::translate( - "Sketcher_Create_Periodic_BSpline", "Create a periodic B-spline by control points")); + periodicbspline->setToolTip( + QApplication::translate("Sketcher_Create_Periodic_BSpline", + "Create a periodic B-spline by control points")); + periodicbspline->setStatusTip( + QApplication::translate("Sketcher_Create_Periodic_BSpline", + "Create a periodic B-spline by control points")); QAction* bsplinebyknot = a[2]; bsplinebyknot->setText( QApplication::translate("Sketcher_CreateBSplineByInterpolation", "B-spline by knots")); @@ -1176,12 +1201,15 @@ void CmdSketcherCompCreateBSpline::languageChange() bsplinebyknot->setStatusTip(QApplication::translate("Sketcher_CreateBSplineByInterpolation", "Create a B-spline by knots")); QAction* periodicbsplinebyknot = a[3]; - periodicbsplinebyknot->setText(QApplication::translate( - "Sketcher_Create_Periodic_BSplineByInterpolation", "Periodic B-spline by knots")); - periodicbsplinebyknot->setToolTip(QApplication::translate( - "Sketcher_Create_Periodic_BSplineByInterpolation", "Create a periodic B-spline by knots")); - periodicbsplinebyknot->setStatusTip(QApplication::translate( - "Sketcher_Create_Periodic_BSplineByInterpolation", "Create a periodic B-spline by knots")); + periodicbsplinebyknot->setText( + QApplication::translate("Sketcher_Create_Periodic_BSplineByInterpolation", + "Periodic B-spline by knots")); + periodicbsplinebyknot->setToolTip( + QApplication::translate("Sketcher_Create_Periodic_BSplineByInterpolation", + "Create a periodic B-spline by knots")); + periodicbsplinebyknot->setStatusTip( + QApplication::translate("Sketcher_Create_Periodic_BSplineByInterpolation", + "Create a periodic B-spline by knots")); } bool CmdSketcherCompCreateBSpline::isActive() @@ -1238,12 +1266,15 @@ CmdSketcherCompCreateCircle::CmdSketcherCompCreateCircle() void CmdSketcherCompCreateCircle::activated(int iMsg) { - if (iMsg == 0) + if (iMsg == 0) { ActivateHandler(getActiveGuiDocument(), new DrawSketchHandlerCircle()); - else if (iMsg == 1) + } + else if (iMsg == 1) { ActivateHandler(getActiveGuiDocument(), new DrawSketchHandler3PointCircle()); - else + } + else { return; + } // Since the default icon is reset when enabling/disabling the command we have // to explicitly set the icon of the used command. @@ -1278,8 +1309,9 @@ Gui::Action* CmdSketcherCompCreateCircle::createAction() void CmdSketcherCompCreateCircle::updateAction(int mode) { Gui::ActionGroup* pcAction = qobject_cast(getAction()); - if (!pcAction) + if (!pcAction) { return; + } QList a = pcAction->actions(); int index = pcAction->property("defaultAction").toInt(); @@ -1301,8 +1333,9 @@ void CmdSketcherCompCreateCircle::languageChange() { Command::languageChange(); - if (!_pcAction) + if (!_pcAction) { return; + } Gui::ActionGroup* pcAction = qobject_cast(_pcAction); QList a = pcAction->actions(); @@ -1489,8 +1522,9 @@ void CmdSketcherCompCreateFillets::updateAction(int mode) { Q_UNUSED(mode); Gui::ActionGroup* pcAction = qobject_cast(getAction()); - if (!pcAction) + if (!pcAction) { return; + } QList a = pcAction->actions(); int index = pcAction->property("defaultAction").toInt(); @@ -1503,8 +1537,9 @@ void CmdSketcherCompCreateFillets::languageChange() { Command::languageChange(); - if (!_pcAction) + if (!_pcAction) { return; + } Gui::ActionGroup* pcAction = qobject_cast(_pcAction); QList a = pcAction->actions(); @@ -1517,10 +1552,12 @@ void CmdSketcherCompCreateFillets::languageChange() QAction* pointFillet = a[1]; pointFillet->setText(QApplication::translate("CmdSketcherCompCreateFillets", "Constraint-preserving sketch fillet")); - pointFillet->setToolTip(QApplication::translate( - "Sketcher_CreatePointFillet", "Fillet that preserves constraints and intersection point")); - pointFillet->setStatusTip(QApplication::translate( - "Sketcher_CreatePointFillet", "Fillet that preserves constraints and intersection point")); + pointFillet->setToolTip( + QApplication::translate("Sketcher_CreatePointFillet", + "Fillet that preserves constraints and intersection point")); + pointFillet->setStatusTip( + QApplication::translate("Sketcher_CreatePointFillet", + "Fillet that preserves constraints and intersection point")); } bool CmdSketcherCompCreateFillets::isActive() @@ -1912,8 +1949,9 @@ void CmdSketcherCreateRegularPolygon::activated(int iMsg) // Pop-up asking for values SketcherRegularPolygonDialog srpd; - if (srpd.exec() == QDialog::Accepted) + if (srpd.exec() == QDialog::Accepted) { ActivateHandler(getActiveGuiDocument(), new DrawSketchHandlerRegularPolygon(srpd.sides)); + } } bool CmdSketcherCreateRegularPolygon::isActive() @@ -1960,9 +1998,10 @@ void CmdSketcherCompCreateRegularPolygon::activated(int iMsg) case 6: { // Pop-up asking for values SketcherRegularPolygonDialog srpd; - if (srpd.exec() == QDialog::Accepted) + if (srpd.exec() == QDialog::Accepted) { ActivateHandler(getActiveGuiDocument(), new DrawSketchHandlerRegularPolygon(srpd.sides)); + } } break; default: return; @@ -2011,8 +2050,9 @@ Gui::Action* CmdSketcherCompCreateRegularPolygon::createAction() void CmdSketcherCompCreateRegularPolygon::updateAction(int mode) { Gui::ActionGroup* pcAction = qobject_cast(getAction()); - if (!pcAction) + if (!pcAction) { return; + } QList a = pcAction->actions(); int index = pcAction->property("defaultAction").toInt(); @@ -2045,8 +2085,9 @@ void CmdSketcherCompCreateRegularPolygon::languageChange() { Command::languageChange(); - if (!_pcAction) + if (!_pcAction) { return; + } Gui::ActionGroup* pcAction = qobject_cast(_pcAction); QList a = pcAction->actions(); @@ -2062,39 +2103,50 @@ void CmdSketcherCompCreateRegularPolygon::languageChange() square->setText(QApplication::translate("CmdSketcherCompCreateRegularPolygon", "Square")); square->setToolTip(QApplication::translate("Sketcher_CreateSquare", "Create a square by its center and by one corner")); - square->setStatusTip(QApplication::translate( - "Sketcher_CreateSquare", "Create a square by its center and by one corner")); + square->setStatusTip( + QApplication::translate("Sketcher_CreateSquare", + "Create a square by its center and by one corner")); QAction* pentagon = a[2]; pentagon->setText(QApplication::translate("CmdSketcherCompCreateRegularPolygon", "Pentagon")); - pentagon->setToolTip(QApplication::translate( - "Sketcher_CreatePentagon", "Create a pentagon by its center and by one corner")); - pentagon->setStatusTip(QApplication::translate( - "Sketcher_CreatePentagon", "Create a pentagon by its center and by one corner")); + pentagon->setToolTip( + QApplication::translate("Sketcher_CreatePentagon", + "Create a pentagon by its center and by one corner")); + pentagon->setStatusTip( + QApplication::translate("Sketcher_CreatePentagon", + "Create a pentagon by its center and by one corner")); QAction* hexagon = a[3]; hexagon->setText(QApplication::translate("CmdSketcherCompCreateRegularPolygon", "Hexagon")); - hexagon->setToolTip(QApplication::translate( - "Sketcher_CreateHexagon", "Create a hexagon by its center and by one corner")); - hexagon->setStatusTip(QApplication::translate( - "Sketcher_CreateHexagon", "Create a hexagon by its center and by one corner")); + hexagon->setToolTip( + QApplication::translate("Sketcher_CreateHexagon", + "Create a hexagon by its center and by one corner")); + hexagon->setStatusTip( + QApplication::translate("Sketcher_CreateHexagon", + "Create a hexagon by its center and by one corner")); QAction* heptagon = a[4]; heptagon->setText(QApplication::translate("CmdSketcherCompCreateRegularPolygon", "Heptagon")); - heptagon->setToolTip(QApplication::translate( - "Sketcher_CreateHeptagon", "Create a heptagon by its center and by one corner")); - heptagon->setStatusTip(QApplication::translate( - "Sketcher_CreateHeptagon", "Create a heptagon by its center and by one corner")); + heptagon->setToolTip( + QApplication::translate("Sketcher_CreateHeptagon", + "Create a heptagon by its center and by one corner")); + heptagon->setStatusTip( + QApplication::translate("Sketcher_CreateHeptagon", + "Create a heptagon by its center and by one corner")); QAction* octagon = a[5]; octagon->setText(QApplication::translate("CmdSketcherCompCreateRegularPolygon", "Octagon")); - octagon->setToolTip(QApplication::translate( - "Sketcher_CreateOctagon", "Create an octagon by its center and by one corner")); - octagon->setStatusTip(QApplication::translate( - "Sketcher_CreateOctagon", "Create an octagon by its center and by one corner")); + octagon->setToolTip( + QApplication::translate("Sketcher_CreateOctagon", + "Create an octagon by its center and by one corner")); + octagon->setStatusTip( + QApplication::translate("Sketcher_CreateOctagon", + "Create an octagon by its center and by one corner")); QAction* regular = a[6]; regular->setText( QApplication::translate("CmdSketcherCompCreateRegularPolygon", "Regular polygon")); - regular->setToolTip(QApplication::translate( - "Sketcher_CreateOctagon", "Create a regular polygon by its center and by one corner")); - regular->setStatusTip(QApplication::translate( - "Sketcher_CreateOctagon", "Create a regular polygon by its center and by one corner")); + regular->setToolTip( + QApplication::translate("Sketcher_CreateOctagon", + "Create a regular polygon by its center and by one corner")); + regular->setStatusTip( + QApplication::translate("Sketcher_CreateOctagon", + "Create a regular polygon by its center and by one corner")); } bool CmdSketcherCompCreateRegularPolygon::isActive() diff --git a/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp b/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp index 4f0a30655c..c47746943b 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp @@ -67,8 +67,11 @@ void ActivateBSplineHandler(Gui::Document* doc, DrawSketchHandler* handler) /// index within it (by OCC numbering). /// Returns true if the entities are found, false otherwise. /// If returns false, `splineGeoId` and `knotIndexOCC` have garbage values. -bool findBSplineAndKnotIndex(Sketcher::SketchObject* Obj, int knotGeoId, - Sketcher::PointPos knotPosId, int& splineGeoId, int& knotIndexOCC) +bool findBSplineAndKnotIndex(Sketcher::SketchObject* Obj, + int knotGeoId, + Sketcher::PointPos knotPosId, + int& splineGeoId, + int& knotIndexOCC) { for (auto const constraint : Obj->Constraints.getValues()) { if (constraint->Type == Sketcher::InternalAlignment && constraint->First == knotGeoId @@ -222,11 +225,13 @@ void CmdSketcherIncreaseDegree::activated(int iMsg) const Part::Geometry* geo = Obj->getGeometry(GeoId); if (geo->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) { - Gui::cmdAppObjectArgs( - selection[0].getObject(), "increaseBSplineDegree(%d) ", GeoId); + Gui::cmdAppObjectArgs(selection[0].getObject(), + "increaseBSplineDegree(%d) ", + GeoId); // add new control points - Gui::cmdAppObjectArgs( - selection[0].getObject(), "exposeInternalGeometry(%d)", GeoId); + Gui::cmdAppObjectArgs(selection[0].getObject(), + "exposeInternalGeometry(%d)", + GeoId); } else { ignored = true; @@ -299,8 +304,9 @@ void CmdSketcherDecreaseDegree::activated(int iMsg) const Part::Geometry* geo = Obj->getGeometry(GeoId); if (geo->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) { - Gui::cmdAppObjectArgs( - selection[0].getObject(), "decreaseBSplineDegree(%d) ", GeoId); + Gui::cmdAppObjectArgs(selection[0].getObject(), + "decreaseBSplineDegree(%d) ", + GeoId); // add new control points // Currently exposeInternalGeometry is called from within decreaseBSplineDegree // because the old spline is deleted and a new one is added so that the GeoId is @@ -411,16 +417,18 @@ void CmdSketcherIncreaseKnotMultiplicity::activated(int iMsg) catch (const Base::CADKernelError& e) { e.ReportException(); if (e.getTranslatable()) { - Gui::TranslatedUserError( - Obj, QObject::tr("CAD Kernel Error"), QObject::tr(e.getMessage().c_str())); + Gui::TranslatedUserError(Obj, + QObject::tr("CAD Kernel Error"), + QObject::tr(e.getMessage().c_str())); } getSelection().clearSelection(); } catch (const Base::Exception& e) { e.ReportException(); if (e.getTranslatable()) { - Gui::TranslatedUserError( - Obj, QObject::tr("Input Error"), QObject::tr(e.getMessage().c_str())); + Gui::TranslatedUserError(Obj, + QObject::tr("Input Error"), + QObject::tr(e.getMessage().c_str())); } getSelection().clearSelection(); } @@ -451,12 +459,14 @@ void CmdSketcherIncreaseKnotMultiplicity::activated(int iMsg) if (ngfound) { try { // add internalalignment for new pole - Gui::cmdAppObjectArgs( - selection[0].getObject(), "exposeInternalGeometry(%d)", ngeoid); + Gui::cmdAppObjectArgs(selection[0].getObject(), + "exposeInternalGeometry(%d)", + ngeoid); } catch (const Base::Exception& e) { - Gui::NotifyUserError( - Obj, QT_TRANSLATE_NOOP("Notifications", "Invalid Constraint"), e.what()); + Gui::NotifyUserError(Obj, + QT_TRANSLATE_NOOP("Notifications", "Invalid Constraint"), + e.what()); getSelection().clearSelection(); } } @@ -585,12 +595,14 @@ void CmdSketcherDecreaseKnotMultiplicity::activated(int iMsg) if (ngfound) { try { // add internalalignment for new pole - Gui::cmdAppObjectArgs( - selection[0].getObject(), "exposeInternalGeometry(%d)", ngeoid); + Gui::cmdAppObjectArgs(selection[0].getObject(), + "exposeInternalGeometry(%d)", + ngeoid); } catch (const Base::Exception& e) { - Gui::NotifyUserError( - Obj, QT_TRANSLATE_NOOP("Notifications", "Invalid Constraint"), e.what()); + Gui::NotifyUserError(Obj, + QT_TRANSLATE_NOOP("Notifications", "Invalid Constraint"), + e.what()); getSelection().clearSelection(); } } @@ -780,15 +792,17 @@ public: catch (const Base::CADKernelError& e) { e.ReportException(); if (e.getTranslatable()) { - Gui::TranslatedUserError( - Obj, QObject::tr("CAD Kernel Error"), QObject::tr(e.getMessage().c_str())); + Gui::TranslatedUserError(Obj, + QObject::tr("CAD Kernel Error"), + QObject::tr(e.getMessage().c_str())); } } catch (const Base::Exception& e) { e.ReportException(); if (e.getTranslatable()) { - Gui::TranslatedUserError( - Obj, QObject::tr("Input Error"), QObject::tr(e.getMessage().c_str())); + Gui::TranslatedUserError(Obj, + QObject::tr("Input Error"), + QObject::tr(e.getMessage().c_str())); } } @@ -814,8 +828,9 @@ public: Gui::cmdAppObjectArgs(Obj, "exposeInternalGeometry(%d)", newGeoId); } catch (const Base::Exception& e) { - Gui::NotifyUserError( - Obj, QT_TRANSLATE_NOOP("Notifications", "Invalid Constraint"), e.what()); + Gui::NotifyUserError(Obj, + QT_TRANSLATE_NOOP("Notifications", "Invalid Constraint"), + e.what()); } } } @@ -1052,8 +1067,9 @@ void CmdSketcherJoinCurves::activated(int iMsg) // Warning: GeoId list will have changed } catch (const Base::Exception& e) { - Gui::TranslatedUserError( - Obj, QObject::tr("Error"), QObject::tr(getStrippedPythonExceptionString(e).c_str())); + Gui::TranslatedUserError(Obj, + QObject::tr("Error"), + QObject::tr(getStrippedPythonExceptionString(e).c_str())); getSelection().clearSelection(); } diff --git a/src/Mod/Sketcher/Gui/CommandSketcherOverlay.cpp b/src/Mod/Sketcher/Gui/CommandSketcherOverlay.cpp index 5f2f90f6c6..9c0659e887 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherOverlay.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherOverlay.cpp @@ -227,18 +227,24 @@ void CmdSketcherCompBSplineShowHideGeometryInformation::activated(int iMsg) Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager(); Gui::Command* cmd; - if (iMsg == 0) + if (iMsg == 0) { cmd = rcCmdMgr.getCommandByName("Sketcher_BSplineDegree"); - else if (iMsg == 1) + } + else if (iMsg == 1) { cmd = rcCmdMgr.getCommandByName("Sketcher_BSplinePolygon"); - else if (iMsg == 2) + } + else if (iMsg == 2) { cmd = rcCmdMgr.getCommandByName("Sketcher_BSplineComb"); - else if (iMsg == 3) + } + else if (iMsg == 3) { cmd = rcCmdMgr.getCommandByName("Sketcher_BSplineKnotMultiplicity"); - else if (iMsg == 4) + } + else if (iMsg == 4) { cmd = rcCmdMgr.getCommandByName("Sketcher_BSplinePoleWeight"); - else + } + else { return; + } cmd->invoke(0); @@ -284,8 +290,9 @@ void CmdSketcherCompBSplineShowHideGeometryInformation::languageChange() { Command::languageChange(); - if (!_pcAction) + if (!_pcAction) { return; + } Gui::ActionGroup* pcAction = qobject_cast(_pcAction); QList a = pcAction->actions(); diff --git a/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp b/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp index f469a70881..f1651b5667 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp @@ -58,12 +58,14 @@ bool isSketcherVirtualSpaceActive(Gui::Document* doc, bool actsOnSelection) && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { if (static_cast(doc->getInEdit())->getSketchMode() == ViewProviderSketch::STATUS_NONE) { - if (!actsOnSelection) + if (!actsOnSelection) { return true; + } else if (Gui::Selection().countObjectsOfType( Sketcher::SketchObject::getClassTypeId()) - > 0) + > 0) { return true; + } } } } @@ -133,8 +135,9 @@ void CmdSketcherSwitchVirtualSpace::activated(int iMsg) for (std::vector::const_iterator it = SubNames.begin(); it != SubNames.end(); ++it) { // see if we have constraints, if we do it is not a mode change, but a toggle. - if (it->size() > 10 && it->substr(0, 10) == "Constraint") + if (it->size() > 10 && it->substr(0, 10) == "Constraint") { modeChange = false; + } } } @@ -182,10 +185,12 @@ void CmdSketcherSwitchVirtualSpace::activated(int iMsg) } } - if (successful > 0) + if (successful > 0) { commitCommand(); - else + } + else { abortCommand(); + } // recomputer and clear the selection (convenience) tryAutoRecompute(Obj); diff --git a/src/Mod/Sketcher/Gui/ConstraintFilters.h b/src/Mod/Sketcher/Gui/ConstraintFilters.h index d9d561b9f4..60cd2abea9 100644 --- a/src/Mod/Sketcher/Gui/ConstraintFilters.h +++ b/src/Mod/Sketcher/Gui/ConstraintFilters.h @@ -111,19 +111,41 @@ constexpr decltype(auto) buildBitset(Args... args) /// FilterValue, which other FilterValues are comprised therein. It defines the dependencies between /// filters. constexpr std::array filterAggregates { - buildBitset(FilterValue::All, FilterValue::Geometric, FilterValue::Horizontal, - FilterValue::Vertical, FilterValue::Coincident, FilterValue::PointOnObject, - FilterValue::Parallel, FilterValue::Perpendicular, FilterValue::Tangent, - FilterValue::Equality, FilterValue::Symmetric, FilterValue::Block, - FilterValue::Datums, FilterValue::Distance, FilterValue::HorizontalDistance, - FilterValue::VerticalDistance, FilterValue::Radius, FilterValue::Weight, - FilterValue::Diameter, FilterValue::Angle, FilterValue::SnellsLaw, - FilterValue::Named, FilterValue::NonDriving, + buildBitset(FilterValue::All, + FilterValue::Geometric, + FilterValue::Horizontal, + FilterValue::Vertical, + FilterValue::Coincident, + FilterValue::PointOnObject, + FilterValue::Parallel, + FilterValue::Perpendicular, + FilterValue::Tangent, + FilterValue::Equality, + FilterValue::Symmetric, + FilterValue::Block, + FilterValue::Datums, + FilterValue::Distance, + FilterValue::HorizontalDistance, + FilterValue::VerticalDistance, + FilterValue::Radius, + FilterValue::Weight, + FilterValue::Diameter, + FilterValue::Angle, + FilterValue::SnellsLaw, + FilterValue::Named, + FilterValue::NonDriving, FilterValue::InternalAlignment),// All = All other groups are covered (0) - buildBitset(FilterValue::Geometric, FilterValue::Horizontal, FilterValue::Vertical, - FilterValue::Coincident, FilterValue::PointOnObject, FilterValue::Parallel, - FilterValue::Perpendicular, FilterValue::Tangent, FilterValue::Equality, - FilterValue::Symmetric, FilterValue::Block, + buildBitset(FilterValue::Geometric, + FilterValue::Horizontal, + FilterValue::Vertical, + FilterValue::Coincident, + FilterValue::PointOnObject, + FilterValue::Parallel, + FilterValue::Perpendicular, + FilterValue::Tangent, + FilterValue::Equality, + FilterValue::Symmetric, + FilterValue::Block, FilterValue::InternalAlignment),// Geometric = All others not being datums (1) buildBitset(FilterValue::Coincident), // Coincident = Just this (2) @@ -138,9 +160,14 @@ constexpr std::array filterAggregates { buildBitset(FilterValue::Block), // Block = Just this (11) buildBitset(FilterValue::InternalAlignment),// InternalAlignment = Just this (12) - buildBitset(FilterValue::Datums, FilterValue::Distance, FilterValue::HorizontalDistance, - FilterValue::VerticalDistance, FilterValue::Radius, FilterValue::Weight, - FilterValue::Diameter, FilterValue::Angle, + buildBitset(FilterValue::Datums, + FilterValue::Distance, + FilterValue::HorizontalDistance, + FilterValue::VerticalDistance, + FilterValue::Radius, + FilterValue::Weight, + FilterValue::Diameter, + FilterValue::Angle, FilterValue::SnellsLaw),// Datum = all others not being geometric (13) buildBitset(FilterValue::HorizontalDistance),// HorizontalDistance = Just this (14) diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp index f3eccc92fc..e3c84220b9 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp @@ -82,13 +82,15 @@ ViewProviderSketchDrawSketchHandlerAttorney::drawEdit(ViewProviderSketch& vp, } inline void ViewProviderSketchDrawSketchHandlerAttorney::drawEdit( - ViewProviderSketch& vp, const std::list>& list) + ViewProviderSketch& vp, + const std::list>& list) { vp.drawEdit(list); } inline void ViewProviderSketchDrawSketchHandlerAttorney::drawEditMarkers( - ViewProviderSketch& vp, const std::vector& EditMarkers, + ViewProviderSketch& vp, + const std::vector& EditMarkers, unsigned int augmentationlevel) { vp.drawEditMarkers(EditMarkers, augmentationlevel); @@ -132,15 +134,16 @@ ViewProviderSketchDrawSketchHandlerAttorney::getPreselectCross(const ViewProvide } inline void -ViewProviderSketchDrawSketchHandlerAttorney::setAngleSnapping(ViewProviderSketch& vp, bool enable, +ViewProviderSketchDrawSketchHandlerAttorney::setAngleSnapping(ViewProviderSketch& vp, + bool enable, Base::Vector2d referencePoint) { vp.setAngleSnapping(enable, referencePoint); } -inline void -ViewProviderSketchDrawSketchHandlerAttorney::moveConstraint(ViewProviderSketch& vp, int constNum, - const Base::Vector2d& toPos) +inline void ViewProviderSketchDrawSketchHandlerAttorney::moveConstraint(ViewProviderSketch& vp, + int constNum, + const Base::Vector2d& toPos) { vp.moveConstraint(constNum, toPos); } @@ -157,8 +160,9 @@ CurveConverter::CurveConverter() } catch (const Base::ValueError& e) {// ensure that if parameter strings are not well-formed, the // exception is not propagated - Base::Console().DeveloperError( - "CurveConverter", "Malformed parameter string: %s\n", e.what()); + Base::Console().DeveloperError("CurveConverter", + "Malformed parameter string: %s\n", + e.what()); } updateCurvedEdgeCountSegmentsParameter(); @@ -174,8 +178,9 @@ CurveConverter::~CurveConverter() catch (const Base::ValueError& e) {// ensure that if parameter strings are not well-formed, the program is not // terminated when calling the noexcept destructor. - Base::Console().DeveloperError( - "CurveConverter", "Malformed parameter string: %s\n", e.what()); + Base::Console().DeveloperError("CurveConverter", + "Malformed parameter string: %s\n", + e.what()); } } @@ -205,8 +210,9 @@ std::vector CurveConverter::toVector2D(const Part::Geometry* geo double segment = (geo->getLastParameter() - geo->getFirstParameter()) / curvedEdgeCountSegments; - for (int i = 0; i < curvedEdgeCountSegments; i++) + for (int i = 0; i < curvedEdgeCountSegments; i++) { emplaceasvector2d(geo->value(geo->getFirstParameter() + i * segment)); + } // either close the curve for untrimmed conic or set the last point for bounded curves emplaceasvector2d(isconic ? geo->value(0) : geo->value(geo->getLastParameter())); @@ -220,8 +226,9 @@ CurveConverter::toVector2DList(const std::vector& geometries) { std::list> list; - for (const auto& geo : geometries) + for (const auto& geo : geometries) { list.push_back(toVector2D(geo)); + } return list; } @@ -233,8 +240,9 @@ void CurveConverter::updateCurvedEdgeCountSegmentsParameter() int stdcountsegments = hGrp->GetInt("SegmentsPerGeometry", 50); // value cannot be smaller than 6 - if (stdcountsegments < 6) + if (stdcountsegments < 6) { stdcountsegments = 6; + } curvedEdgeCountSegments = stdcountsegments; }; @@ -353,7 +361,9 @@ void DrawSketchHandler::setCrosshairCursor(const char* svgName) setCrosshairCursor(cursorName); } -void DrawSketchHandler::setSvgCursor(const QString& cursorName, int x, int y, +void DrawSketchHandler::setSvgCursor(const QString& cursorName, + int x, + int y, const std::map& colorMapping) { // The Sketcher_Pointer_*.svg icons have a default size of 64x64. When directly creating @@ -374,10 +384,12 @@ void DrawSketchHandler::setSvgCursor(const QString& cursorName, int x, int y, #endif qreal cursorSize = defaultCursorSize * pRatio; - QPixmap pointer = Gui::BitmapFactory().pixmapFromSvg( - cursorName.toStdString().c_str(), QSizeF(cursorSize, cursorSize), colorMapping); - if (isRatioOne) + QPixmap pointer = Gui::BitmapFactory().pixmapFromSvg(cursorName.toStdString().c_str(), + QSizeF(cursorSize, cursorSize), + colorMapping); + if (isRatioOne) { pointer = pointer.scaled(32, 32); + } pointer.setDevicePixelRatio(pRatio); setCursor(pointer, hotX, hotY, false); } @@ -478,8 +490,9 @@ void DrawSketchHandler::updateCursor() { auto cursorstring = getCrosshairCursorSVGName(); - if (cursorstring != QString::fromLatin1("None")) + if (cursorstring != QString::fromLatin1("None")) { setCrosshairCursor(cursorstring); + } } void DrawSketchHandler::applyCursor() @@ -562,16 +575,20 @@ DrawSketchHandler::suggestedConstraintsPixmaps(std::vector& sugg } int DrawSketchHandler::seekAutoConstraint(std::vector& suggestedConstraints, - const Base::Vector2d& Pos, const Base::Vector2d& Dir, + const Base::Vector2d& Pos, + const Base::Vector2d& Dir, AutoConstraint::TargetType type) { suggestedConstraints.clear(); - if (!sketchgui->Autoconstraints.getValue()) + if (!sketchgui->Autoconstraints.getValue()) { return 0;// If Autoconstraints property is not set quit + } - Base::Vector3d hitShapeDir = Base::Vector3d( - 0, 0, 0);// direction of hit shape (if it is a line, the direction of the line) + Base::Vector3d hitShapeDir = + Base::Vector3d(0, + 0, + 0);// direction of hit shape (if it is a line, the direction of the line) // Get Preselection int preSelPnt = getPreselectPoint(); @@ -581,8 +598,9 @@ int DrawSketchHandler::seekAutoConstraint(std::vector& suggested Sketcher::PointPos PosId = Sketcher::PointPos::none; - if (preSelPnt != -1) + if (preSelPnt != -1) { sketchgui->getSketchObject()->getGeoVertexIndex(preSelPnt, GeoId, PosId); + } else if (preSelCrv != -1) { const Part::Geometry* geom = sketchgui->getSketchObject()->getGeometry(preSelCrv); @@ -615,15 +633,19 @@ int DrawSketchHandler::seekAutoConstraint(std::vector& suggested constr.GeoId = GeoId; constr.PosId = PosId; if ((type == AutoConstraint::VERTEX || type == AutoConstraint::VERTEX_NO_TANGENCY) - && PosId != Sketcher::PointPos::none) + && PosId != Sketcher::PointPos::none) { constr.Type = Sketcher::Coincident; - else if (type == AutoConstraint::CURVE && PosId != Sketcher::PointPos::none) + } + else if (type == AutoConstraint::CURVE && PosId != Sketcher::PointPos::none) { constr.Type = Sketcher::PointOnObject; + } else if ((type == AutoConstraint::VERTEX || type == AutoConstraint::VERTEX_NO_TANGENCY) - && PosId == Sketcher::PointPos::none) + && PosId == Sketcher::PointPos::none) { constr.Type = Sketcher::PointOnObject; - else if (type == AutoConstraint::CURVE && PosId == Sketcher::PointPos::none) + } + else if (type == AutoConstraint::CURVE && PosId == Sketcher::PointPos::none) { constr.Type = Sketcher::Tangent; + } if (constr.Type == Sketcher::Tangent && Dir.Length() > 1e-8 && hitShapeDir.Length() @@ -637,20 +659,23 @@ int DrawSketchHandler::seekAutoConstraint(std::vector& suggested // degrees) if (fabs(cosangle) < 0.995f || ((GeoId == Sketcher::GeoEnum::HAxis || GeoId == Sketcher::GeoEnum::VAxis) - && fabs(cosangle) < 0.1)) + && fabs(cosangle) < 0.1)) { suggestedConstraints.push_back(constr); + } return suggestedConstraints.size(); } - if (constr.Type != Sketcher::None) + if (constr.Type != Sketcher::None) { suggestedConstraints.push_back(constr); + } } - if (Dir.Length() < 1e-8 || type == AutoConstraint::CURVE) + if (Dir.Length() < 1e-8 || type == AutoConstraint::CURVE) { // Direction not set so return; return suggestedConstraints.size(); + } // Suggest vertical and horizontal constraints @@ -663,19 +688,23 @@ int DrawSketchHandler::seekAutoConstraint(std::vector& suggested constr.GeoId = GeoEnum::GeoUndef; constr.PosId = Sketcher::PointPos::none; double angle = std::abs(atan2(Dir.y, Dir.x)); - if (angle < angleDevRad || (M_PI - angle) < angleDevRad) + if (angle < angleDevRad || (M_PI - angle) < angleDevRad) { // Suggest horizontal constraint constr.Type = Sketcher::Horizontal; - else if (std::abs(angle - M_PI_2) < angleDevRad) + } + else if (std::abs(angle - M_PI_2) < angleDevRad) { // Suggest vertical constraint constr.Type = Sketcher::Vertical; + } - if (constr.Type != Sketcher::None) + if (constr.Type != Sketcher::None) { suggestedConstraints.push_back(constr); + } // Do not seek for tangent if we are actually building a primitive - if (type == AutoConstraint::VERTEX_NO_TANGENCY) + if (type == AutoConstraint::VERTEX_NO_TANGENCY) { return suggestedConstraints.size(); + } // Find if there are tangent constraints (currently arcs and circles) @@ -706,8 +735,9 @@ int DrawSketchHandler::seekAutoConstraint(std::vector& suggested double radius = circle->getRadius(); // ignore if no touch (use dot product) - if (tmpDir * (center - tmpPos) > 0 || tmpDir * (center - tmpStart) < 0) + if (tmpDir * (center - tmpPos) > 0 || tmpDir * (center - tmpStart) < 0) { continue; + } Base::Vector3d projPnt(0.f, 0.f, 0.f); projPnt = projPnt.ProjectToLine(center - tmpPos, tmpDir); @@ -755,8 +785,9 @@ int DrawSketchHandler::seekAutoConstraint(std::vector& suggested double radius = arc->getRadius(); // ignore if no touch (use dot product) - if (tmpDir * (center - tmpPos) > 0 || tmpDir * (center - tmpStart) < 0) + if (tmpDir * (center - tmpPos) > 0 || tmpDir * (center - tmpStart) < 0) { continue; + } Base::Vector3d projPnt(0.f, 0.f, 0.f); projPnt = projPnt.ProjectToLine(center - tmpPos, tmpDir); @@ -767,8 +798,9 @@ int DrawSketchHandler::seekAutoConstraint(std::vector& suggested arc->getRange(startAngle, endAngle, /*emulateCCW=*/true); double angle = atan2(projPnt.y, projPnt.x); - while (angle < startAngle) + while (angle < startAngle) { angle += 2 * D_PI;// Bring it to range of arc + } // if the point is on correct side of arc if (angle <= endAngle) {// Now need to check only one side @@ -818,8 +850,9 @@ int DrawSketchHandler::seekAutoConstraint(std::vector& suggested - startAngle, 2.f * M_PI); - while (angle < startAngle) + while (angle < startAngle) { angle += 2 * D_PI;// Bring it to range of arc + } // if the point is on correct side of arc if (angle <= endAngle) {// Now need to check only one side @@ -831,8 +864,9 @@ int DrawSketchHandler::seekAutoConstraint(std::vector& suggested } if (tangId != GeoEnum::GeoUndef) { - if (tangId > getHighestCurveIndex())// external Geometry + if (tangId > getHighestCurveIndex()) {// external Geometry tangId = getHighestCurveIndex() - tangId; + } // Suggest vertical constraint constr.Type = Tangent; constr.GeoId = tangId; @@ -844,11 +878,13 @@ int DrawSketchHandler::seekAutoConstraint(std::vector& suggested } void DrawSketchHandler::createAutoConstraints(const std::vector& autoConstrs, - int geoId1, Sketcher::PointPos posId1, + int geoId1, + Sketcher::PointPos posId1, bool createowncommand /*= true*/) { - if (!sketchgui->Autoconstraints.getValue()) + if (!sketchgui->Autoconstraints.getValue()) { return;// If Autoconstraints property is not set quit + } if (!autoConstrs.empty()) { @@ -864,8 +900,9 @@ void DrawSketchHandler::createAutoConstraints(const std::vector& switch (it->Type) { case Sketcher::Coincident: { - if (posId1 == Sketcher::PointPos::none) + if (posId1 == Sketcher::PointPos::none) { continue; + } // If the auto constraint has a point create a coincident otherwise it is an // edge on a point Gui::cmdAppObjectArgs( @@ -918,8 +955,9 @@ void DrawSketchHandler::createAutoConstraints(const std::vector& && (geom1->getTypeId() == Part::GeomEllipse::getClassTypeId() || geom2->getTypeId() == Part::GeomEllipse::getClassTypeId())) { - if (geom1->getTypeId() != Part::GeomEllipse::getClassTypeId()) + if (geom1->getTypeId() != Part::GeomEllipse::getClassTypeId()) { std::swap(geoId1, geoId2); + } // geoId1 is the ellipse geom1 = Obj->getGeometry(geoId1); @@ -945,8 +983,9 @@ void DrawSketchHandler::createAutoConstraints(const std::vector& && (geom1->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() || geom2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId())) { - if (geom1->getTypeId() != Part::GeomArcOfEllipse::getClassTypeId()) + if (geom1->getTypeId() != Part::GeomArcOfEllipse::getClassTypeId()) { std::swap(geoId1, geoId2); + } // geoId1 is the arc of ellipse geom1 = Obj->getGeometry(geoId1); @@ -1049,8 +1088,9 @@ void DrawSketchHandler::drawDirectionAtCursor(const Base::Vector2d& position, void DrawSketchHandler::drawEditMarkers(const std::vector& EditMarkers, unsigned int augmentationlevel) { - ViewProviderSketchDrawSketchHandlerAttorney::drawEditMarkers( - *sketchgui, EditMarkers, augmentationlevel); + ViewProviderSketchDrawSketchHandlerAttorney::drawEditMarkers(*sketchgui, + EditMarkers, + augmentationlevel); } void DrawSketchHandler::setAxisPickStyle(bool on) @@ -1090,12 +1130,12 @@ Sketcher::SketchObject* DrawSketchHandler::getSketchObject() void DrawSketchHandler::setAngleSnapping(bool enable, Base::Vector2d referencePoint) { - ViewProviderSketchDrawSketchHandlerAttorney::setAngleSnapping( - *sketchgui, enable, referencePoint); + ViewProviderSketchDrawSketchHandlerAttorney::setAngleSnapping(*sketchgui, + enable, + referencePoint); } void DrawSketchHandler::moveConstraint(int constNum, const Base::Vector2d& toPos) { - ViewProviderSketchDrawSketchHandlerAttorney::moveConstraint( - *sketchgui, constNum, toPos); -} \ No newline at end of file + ViewProviderSketchDrawSketchHandlerAttorney::moveConstraint(*sketchgui, constNum, toPos); +} diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.h b/src/Mod/Sketcher/Gui/DrawSketchHandler.h index a5679b5e46..c53992a2f9 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.h @@ -83,8 +83,8 @@ class ViewProviderSketchDrawSketchHandlerAttorney { private: static inline void setConstraintSelectability(ViewProviderSketch& vp, bool enabled = true); - static inline void setPositionText(ViewProviderSketch& vp, const Base::Vector2d& Pos, - const SbString& txt); + static inline void + setPositionText(ViewProviderSketch& vp, const Base::Vector2d& Pos, const SbString& txt); static inline void setPositionText(ViewProviderSketch& vp, const Base::Vector2d& Pos); static inline void resetPositionText(ViewProviderSketch& vp); static inline void drawEdit(ViewProviderSketch& vp, @@ -97,14 +97,16 @@ private: static inline void setAxisPickStyle(ViewProviderSketch& vp, bool on); static inline void moveCursorToSketchPoint(ViewProviderSketch& vp, Base::Vector2d point); static inline void preselectAtPoint(ViewProviderSketch& vp, Base::Vector2d point); - static inline void setAngleSnapping(ViewProviderSketch& vp, bool enable, + static inline void setAngleSnapping(ViewProviderSketch& vp, + bool enable, Base::Vector2d referencePoint = Base::Vector2d(0., 0.)); static inline int getPreselectPoint(const ViewProviderSketch& vp); static inline int getPreselectCurve(const ViewProviderSketch& vp); static inline int getPreselectCross(const ViewProviderSketch& vp); - static inline void moveConstraint(ViewProviderSketch& vp, int constNum, const Base::Vector2d& toPos); + static inline void + moveConstraint(ViewProviderSketch& vp, int constNum, const Base::Vector2d& toPos); friend class DrawSketchHandler; }; @@ -153,12 +155,14 @@ public: int getHighestCurveIndex(); int seekAutoConstraint(std::vector& suggestedConstraints, - const Base::Vector2d& Pos, const Base::Vector2d& Dir, + const Base::Vector2d& Pos, + const Base::Vector2d& Dir, AutoConstraint::TargetType type = AutoConstraint::VERTEX); // createowncommand indicates whether a separate command shall be create and committed (for // example for undo purposes) or not is not it is the responsibility of the developer to create // and commit the command appropriately. - void createAutoConstraints(const std::vector& autoConstrs, int geoId, + void createAutoConstraints(const std::vector& autoConstrs, + int geoId, Sketcher::PointPos pointPos = Sketcher::PointPos::none, bool createowncommand = true); @@ -234,7 +238,9 @@ protected: void moveConstraint(int constNum, const Base::Vector2d& toPos); private: - void setSvgCursor(const QString& svgName, int x, int y, + void setSvgCursor(const QString& svgName, + int x, + int y, const std::map& colorMapping = std::map()); diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h index 074d261718..5b38523f5d 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h @@ -154,8 +154,9 @@ public: atan2(onSketchPos.y - CenterPoint.y, onSketchPos.x - CenterPoint.x) - startAngle; double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * M_PI; arcAngle = abs(angle1 - arcAngle) < abs(angle2 - arcAngle) ? angle1 : angle2; - if (arcAngle > 0) + if (arcAngle > 0) { endAngle = startAngle + arcAngle; + } else { endAngle = startAngle; startAngle += arcAngle; @@ -401,8 +402,10 @@ public: } drawEdit(EditCurve); - if (seekAutoConstraint( - sugConstr3, onSketchPos, Base::Vector2d(0.0, 0.0), AutoConstraint::CURVE)) { + if (seekAutoConstraint(sugConstr3, + onSketchPos, + Base::Vector2d(0.0, 0.0), + AutoConstraint::CURVE)) { renderSuggestConstraintsCursor(sugConstr3); return; } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h index 25ada63cd8..f1d035371b 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h @@ -62,8 +62,9 @@ public: { if (Mode == STATUS_SEEK_First) { setPositionText(onSketchPos); - if (seekAutoConstraint( - sugConstr1, onSketchPos, Base::Vector2d(0.f, 0.f))) {// TODO: ellipse prio 1 + if (seekAutoConstraint(sugConstr1, + onSketchPos, + Base::Vector2d(0.f, 0.f))) {// TODO: ellipse prio 1 renderSuggestConstraintsCursor(sugConstr1); return; } @@ -91,8 +92,10 @@ public: } drawEdit(EditCurve); - if (seekAutoConstraint( - sugConstr2, onSketchPos, onSketchPos - centerPoint, AutoConstraint::CURVE)) { + if (seekAutoConstraint(sugConstr2, + onSketchPos, + onSketchPos - centerPoint, + AutoConstraint::CURVE)) { renderSuggestConstraintsCursor(sugConstr2); return; } @@ -177,8 +180,10 @@ public: std::string aString = lengthToDisplayFormat(a, 1); std::string bString = lengthToDisplayFormat(b, 1); std::string angleString = angleToDisplayFormat(arcAngle * 180.0 / M_PI, 1); - text.sprintf( - " (R%s, R%s, %s)", aString.c_str(), bString.c_str(), angleString.c_str()); + text.sprintf(" (R%s, R%s, %s)", + aString.c_str(), + bString.c_str(), + angleString.c_str()); setPositionText(onSketchPos, text); } @@ -252,8 +257,9 @@ public: bool isOriginalArcCCW = true; - if (arcAngle > 0) + if (arcAngle > 0) { endAngle = startAngle + arcAngle; + } else { endAngle = startAngle; startAngle += arcAngle; @@ -312,8 +318,9 @@ public: currentgeoid++; - Gui::cmdAppObjectArgs( - sketchgui->getObject(), "exposeInternalGeometry(%d)", currentgeoid); + Gui::cmdAppObjectArgs(sketchgui->getObject(), + "exposeInternalGeometry(%d)", + currentgeoid); } catch (const Base::Exception&) { Gui::NotifyError( diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h index 006635a091..d79c983247 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h @@ -78,8 +78,10 @@ public: } drawEdit(EditCurve); - if (seekAutoConstraint( - sugConstr2, onSketchPos, Base::Vector2d(0.f, 0.f), AutoConstraint::CURVE)) { + if (seekAutoConstraint(sugConstr2, + onSketchPos, + Base::Vector2d(0.f, 0.f), + AutoConstraint::CURVE)) { renderSuggestConstraintsCursor(sugConstr2); return; } @@ -260,8 +262,9 @@ public: bool isOriginalArcCCW = true; - if (arcAngle > 0) + if (arcAngle > 0) { endAngle = startAngle + arcAngle; + } else { endAngle = startAngle; startAngle += arcAngle; @@ -320,8 +323,9 @@ public: currentgeoid++; - Gui::cmdAppObjectArgs( - sketchgui->getObject(), "exposeInternalGeometry(%d)", currentgeoid); + Gui::cmdAppObjectArgs(sketchgui->getObject(), + "exposeInternalGeometry(%d)", + currentgeoid); } catch (const Base::Exception&) { Gui::NotifyError( diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfParabola.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfParabola.h index bbfbb4b52b..1c3af02a6f 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfParabola.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfParabola.h @@ -250,8 +250,9 @@ public: currentgeoid++; - Gui::cmdAppObjectArgs( - sketchgui->getObject(), "exposeInternalGeometry(%d)", currentgeoid); + Gui::cmdAppObjectArgs(sketchgui->getObject(), + "exposeInternalGeometry(%d)", + currentgeoid); } catch (const Base::Exception&) { Gui::NotifyError( diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h index e4c8463e61..2d124c0f1f 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h @@ -141,8 +141,10 @@ public: // add auto constraints on pole if (!sugConstr.back().empty()) { - createAutoConstraints( - sugConstr.back(), poleGeoIds.back(), Sketcher::PointPos::mid, false); + createAutoConstraints(sugConstr.back(), + poleGeoIds.back(), + Sketcher::PointPos::mid, + false); } static_cast(sketchgui->getObject())->solve(); @@ -155,16 +157,18 @@ public: // check if coincident with first pole for (auto& ac : sugConstr.back()) { if (ac.Type == Sketcher::Coincident) { - if (ac.GeoId == poleGeoIds[0] && ac.PosId == Sketcher::PointPos::mid) + if (ac.GeoId == poleGeoIds[0] && ac.PosId == Sketcher::PointPos::mid) { IsClosed = true; + } else { // The coincidence with first point may be indirect const auto coincidents = static_cast(sketchgui->getObject()) ->getAllCoincidentPoints(ac.GeoId, ac.PosId); if (coincidents.find(poleGeoIds[0]) != coincidents.end() - && coincidents.at(poleGeoIds[0]) == Sketcher::PointPos::mid) + && coincidents.at(poleGeoIds[0]) == Sketcher::PointPos::mid) { IsClosed = true; + } } } } @@ -217,8 +221,10 @@ public: // add auto constraints on pole if (!sugConstr.back().empty()) { - createAutoConstraints( - sugConstr.back(), poleGeoIds.back(), Sketcher::PointPos::mid, false); + createAutoConstraints(sugConstr.back(), + poleGeoIds.back(), + Sketcher::PointPos::mid, + false); } // static_cast(sketchgui->getObject())->solve(); @@ -256,12 +262,14 @@ public: // On pressing Backspace delete last pole else if (SoKeyboardEvent::BACKSPACE == key && pressed) { // when mouse is pressed we are in a transitional state so don't mess with it - if (MOUSE_PRESSED == MousePressMode) + if (MOUSE_PRESSED == MousePressMode) { return; + } // can only delete last pole if it exists - if (STATUS_SEEK_FIRST_CONTROLPOINT == Mode || STATUS_CLOSE == Mode) + if (STATUS_SEEK_FIRST_CONTROLPOINT == Mode || STATUS_CLOSE == Mode) { return; + } // if only first pole exists it's equivalent to canceling current spline if (poleGeoIds.size() == 1) { @@ -279,8 +287,9 @@ public: ->Constraints.getValues(); for (int i = constraints.size() - 1; i >= 0; --i) { if (delGeoId == constraints[i]->First || delGeoId == constraints[i]->Second - || delGeoId == constraints[i]->Third) + || delGeoId == constraints[i]->Third) { Gui::cmdAppObjectArgs(sketchgui->getObject(), "delConstraint(%d)", i); + } } // Remove pole @@ -509,8 +518,9 @@ private: Gui::Command::doCommand(Gui::Command::Doc, cstream.str().c_str()); // for showing the knots on creation - Gui::cmdAppObjectArgs( - sketchgui->getObject(), "exposeInternalGeometry(%d)", currentgeoid); + Gui::cmdAppObjectArgs(sketchgui->getObject(), + "exposeInternalGeometry(%d)", + currentgeoid); } catch (const Base::Exception&) { Gui::NotifyError(sketchgui, diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerBSplineByInterpolation.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerBSplineByInterpolation.h index 031bda63e1..bad862f56e 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerBSplineByInterpolation.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerBSplineByInterpolation.h @@ -131,8 +131,10 @@ public: // add auto constraints on knot if (!sugConstr.back().empty()) { - createAutoConstraints( - sugConstr.back(), knotGeoIds.back(), Sketcher::PointPos::start, false); + createAutoConstraints(sugConstr.back(), + knotGeoIds.back(), + Sketcher::PointPos::start, + false); } static_cast(sketchgui->getObject())->solve(); @@ -143,16 +145,18 @@ public: // check if coincidence issues with first or last added knot for (auto& ac : sugConstr.back()) { if (ac.Type == Sketcher::Coincident) { - if (ac.GeoId == knotGeoIds[0] && ac.PosId == Sketcher::PointPos::start) + if (ac.GeoId == knotGeoIds[0] && ac.PosId == Sketcher::PointPos::start) { IsClosed = true; + } else { // The coincidence with first point may be indirect const auto coincidents = static_cast(sketchgui->getObject()) ->getAllCoincidentPoints(ac.GeoId, ac.PosId); if (coincidents.find(knotGeoIds[0]) != coincidents.end() - && coincidents.at(knotGeoIds[0]) == Sketcher::PointPos::start) + && coincidents.at(knotGeoIds[0]) == Sketcher::PointPos::start) { IsClosed = true; + } else if (coincidents.find(knotGeoIds.back()) != coincidents.end() && coincidents.at(knotGeoIds.back()) == Sketcher::PointPos::start) { @@ -202,8 +206,10 @@ public: // add auto constraints on knot if (!sugConstr.back().empty()) { - createAutoConstraints( - sugConstr.back(), knotGeoIds.back(), Sketcher::PointPos::start, false); + createAutoConstraints(sugConstr.back(), + knotGeoIds.back(), + Sketcher::PointPos::start, + false); } if (!IsClosed) { @@ -254,12 +260,14 @@ public: // On pressing Backspace delete last knot else if (SoKeyboardEvent::BACKSPACE == key && pressed) { // when mouse is pressed we are in a transitional state so don't mess with it - if (MOUSE_PRESSED == MousePressMode) + if (MOUSE_PRESSED == MousePressMode) { return; + } // can only delete last knot if it exists - if (STATUS_SEEK_FIRST_POINT == Mode || STATUS_CLOSE == Mode) + if (STATUS_SEEK_FIRST_POINT == Mode || STATUS_CLOSE == Mode) { return; + } // if only first knot exists it's equivalent to canceling current spline if (knotGeoIds.size() == 1) { @@ -277,8 +285,9 @@ public: ->Constraints.getValues(); for (int i = constraints.size() - 1; i >= 0; --i) { if (delGeoId == constraints[i]->First || delGeoId == constraints[i]->Second - || delGeoId == constraints[i]->Third) + || delGeoId == constraints[i]->Third) { Gui::cmdAppObjectArgs(sketchgui->getObject(), "delConstraint(%d)", i); + } } // Remove knot @@ -475,8 +484,9 @@ private: // FIXME: Decide whether to force a knot or not. std::vector isBetweenC0Points(BSplineKnots.size(), false); for (size_t i = 1; i < BSplineKnots.size() - 1; ++i) { - if (BSplineMults[i - 1] >= myDegree && BSplineMults[i + 1] >= myDegree) + if (BSplineMults[i - 1] >= myDegree && BSplineMults[i + 1] >= myDegree) { isBetweenC0Points[i] = true; + } } int currentgeoid = getHighestCurveIndex(); @@ -511,7 +521,8 @@ private: } else { Gui::Command::runCommand( - Gui::Command::Gui, "_finalbsp_poles.extend(_bsps[-1].getPoles()[1:])"); + Gui::Command::Gui, + "_finalbsp_poles.extend(_bsps[-1].getPoles()[1:])"); Gui::Command::runCommand(Gui::Command::Gui, "_finalbsp_knots.extend([_finalbsp_knots[-1] + i " "for i in _bsps[-1].getKnots()[1:]])"); @@ -605,8 +616,9 @@ private: Gui::Command::doCommand(Gui::Command::Doc, cstream.str().c_str()); // for showing the rest of internal geometry on creation - Gui::cmdAppObjectArgs( - sketchgui->getObject(), "exposeInternalGeometry(%d)", currentgeoid); + Gui::cmdAppObjectArgs(sketchgui->getObject(), + "exposeInternalGeometry(%d)", + currentgeoid); } catch (const Base::Exception&) { Gui::NotifyError(sketchgui, diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerCarbonCopy.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerCarbonCopy.h index d2b7bb9dc8..6121023167 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerCarbonCopy.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerCarbonCopy.h @@ -117,8 +117,9 @@ public: void mouseMove(Base::Vector2d onSketchPos) override { Q_UNUSED(onSketchPos); - if (Gui::Selection().getPreselection().pObjectName) + if (Gui::Selection().getPreselection().pObjectName) { applyCursor(); + } } bool pressButton(Base::Vector2d onSketchPos) override @@ -142,8 +143,9 @@ public: if (msg.Type == Gui::SelectionChanges::AddSelection) { App::DocumentObject* obj = sketchgui->getObject()->getDocument()->getObject(msg.pObjectName); - if (!obj) + if (!obj) { throw Base::ValueError("Sketcher: Carbon Copy: Invalid object in selection"); + } if (obj->getTypeId() == Sketcher::SketchObject::getClassTypeId()) { diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerCircle.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerCircle.h index 6bc2116780..0cc4666d68 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerCircle.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerCircle.h @@ -79,8 +79,10 @@ public: } drawEdit(EditCurve); - if (seekAutoConstraint( - sugConstr2, onSketchPos, onSketchPos - EditCurve[0], AutoConstraint::CURVE)) { + if (seekAutoConstraint(sugConstr2, + onSketchPos, + onSketchPos - EditCurve[0], + AutoConstraint::CURVE)) { renderSuggestConstraintsCursor(sugConstr2); return; } @@ -203,19 +205,23 @@ public: { if (Mode == STATUS_SEEK_First) { setPositionText(onSketchPos); - if (seekAutoConstraint( - sugConstr1, onSketchPos, Base::Vector2d(0.f, 0.f), AutoConstraint::CURVE)) { + if (seekAutoConstraint(sugConstr1, + onSketchPos, + Base::Vector2d(0.f, 0.f), + AutoConstraint::CURVE)) { renderSuggestConstraintsCursor(sugConstr1); return; } } else if (Mode == STATUS_SEEK_Second || Mode == STATUS_SEEK_Third) { try { - if (Mode == STATUS_SEEK_Second) + if (Mode == STATUS_SEEK_Second) { CenterPoint = EditCurve[N + 1] = (onSketchPos - FirstPoint) / 2 + FirstPoint; - else + } + else { CenterPoint = EditCurve[N + 1] = Part::Geom2dCircle::getCircleCenter(FirstPoint, SecondPoint, onSketchPos); + } radius = (onSketchPos - CenterPoint).Length(); double lineAngle = GetPointAngle(CenterPoint, onSketchPos); diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerEllipse.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerEllipse.h index 6bf67dae9d..576009a08c 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerEllipse.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerEllipse.h @@ -125,8 +125,10 @@ public: if (method == PERIAPSIS_APOAPSIS_B) { if (mode == STATUS_SEEK_PERIAPSIS) { setPositionText(onSketchPos); - if (seekAutoConstraint( - sugConstr1, onSketchPos, Base::Vector2d(0.f, 0.f), AutoConstraint::CURVE)) { + if (seekAutoConstraint(sugConstr1, + onSketchPos, + Base::Vector2d(0.f, 0.f), + AutoConstraint::CURVE)) { renderSuggestConstraintsCursor(sugConstr1); return; } @@ -147,8 +149,10 @@ public: drawEdit(editCurve); // Suggestions for ellipse and curves are disabled because many tangent constraints // need an intermediate point or line. - if (seekAutoConstraint( - sugConstr2, onSketchPos, Base::Vector2d(0.f, 0.f), AutoConstraint::CURVE)) { + if (seekAutoConstraint(sugConstr2, + onSketchPos, + Base::Vector2d(0.f, 0.f), + AutoConstraint::CURVE)) { renderSuggestConstraintsCursor(sugConstr2); return; } @@ -167,8 +171,10 @@ public: } drawEdit(editCurve); - if (seekAutoConstraint( - sugConstr3, onSketchPos, Base::Vector2d(0.f, 0.f), AutoConstraint::CURVE)) { + if (seekAutoConstraint(sugConstr3, + onSketchPos, + Base::Vector2d(0.f, 0.f), + AutoConstraint::CURVE)) { renderSuggestConstraintsCursor(sugConstr3); return; } @@ -177,8 +183,9 @@ public: else {// method is CENTER_PERIAPSIS_B if (mode == STATUS_SEEK_CENTROID) { setPositionText(onSketchPos); - if (seekAutoConstraint( - sugConstr1, onSketchPos, Base::Vector2d(0.f, 0.f))) {// TODO: ellipse prio 1 + if (seekAutoConstraint(sugConstr1, + onSketchPos, + Base::Vector2d(0.f, 0.f))) {// TODO: ellipse prio 1 renderSuggestConstraintsCursor(sugConstr1); return; } @@ -197,8 +204,10 @@ public: } drawEdit(editCurve); - if (seekAutoConstraint( - sugConstr2, onSketchPos, onSketchPos - centroid, AutoConstraint::CURVE)) { + if (seekAutoConstraint(sugConstr2, + onSketchPos, + onSketchPos - centroid, + AutoConstraint::CURVE)) { renderSuggestConstraintsCursor(sugConstr2); return; } @@ -217,8 +226,10 @@ public: } drawEdit(editCurve); - if (seekAutoConstraint( - sugConstr3, onSketchPos, onSketchPos - centroid, AutoConstraint::CURVE)) { + if (seekAutoConstraint(sugConstr3, + onSketchPos, + onSketchPos - centroid, + AutoConstraint::CURVE)) { renderSuggestConstraintsCursor(sugConstr3); return; } @@ -416,7 +427,8 @@ private: // decompose cursor with a projection, then length of w_2 will give us b Base::Vector2d w_1 = cursor; w_1.ProjectToLine( - cursor, (periapsis - apoapsis));// projection of cursor line onto apse line + cursor, + (periapsis - apoapsis));// projection of cursor line onto apse line Base::Vector2d w_2 = (cursor - w_1); b = w_2.Length(); @@ -791,8 +803,9 @@ private: currentgeoid++; - Gui::cmdAppObjectArgs( - sketchgui->getObject(), "exposeInternalGeometry(%d)", currentgeoid); + Gui::cmdAppObjectArgs(sketchgui->getObject(), + "exposeInternalGeometry(%d)", + currentgeoid); } catch (const Base::Exception&) { Gui::NotifyError(sketchgui, diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerExtend.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerExtend.h index 288b77c7ca..c98ab607de 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerExtend.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerExtend.h @@ -46,20 +46,24 @@ public: bool allow(App::Document* /*pDoc*/, App::DocumentObject* pObj, const char* sSubName) override { - if (pObj != this->object) + if (pObj != this->object) { return false; - if (!sSubName || sSubName[0] == '\0') + } + if (!sSubName || sSubName[0] == '\0') { return false; - if (disabled) + } + if (disabled) { return true; + } std::string element(sSubName); if (element.substr(0, 4) == "Edge") { int GeoId = std::atoi(element.substr(4, 4000).c_str()) - 1; Sketcher::SketchObject* Sketch = static_cast(object); const Part::Geometry* geom = Sketch->getGeometry(GeoId); if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId() - || geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) + || geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { return true; + } } return false; } @@ -288,8 +292,9 @@ public: ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( "User parameter:BaseApp/Preferences/Mod/Sketcher"); bool autoRecompute = hGrp->GetBool("AutoRecompute", false); - if (autoRecompute) + if (autoRecompute) { Gui::Command::updateActive(); + } // constrain chosen point if (!SugConstr.empty()) { diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerExternal.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerExternal.h index a7b4f812bc..c63e7634f4 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerExternal.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerExternal.h @@ -83,8 +83,9 @@ public: // return false; //} - if (!sSubName || sSubName[0] == '\0') + if (!sSubName || sSubName[0] == '\0') { return false; + } std::string element(sSubName); if ((element.size() > 4 && element.substr(0, 4) == "Edge") || (element.size() > 6 && element.substr(0, 6) == "Vertex") @@ -92,8 +93,9 @@ public: return true; } if (pObj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId()) - || pObj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) + || pObj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) { return true; + } return false; } }; @@ -110,8 +112,9 @@ public: void mouseMove(Base::Vector2d onSketchPos) override { Q_UNUSED(onSketchPos); - if (Gui::Selection().getPreselection().pObjectName) + if (Gui::Selection().getPreselection().pObjectName) { applyCursor(); + } } bool pressButton(Base::Vector2d onSketchPos) override @@ -135,8 +138,9 @@ public: if (msg.Type == Gui::SelectionChanges::AddSelection) { App::DocumentObject* obj = sketchgui->getObject()->getDocument()->getObject(msg.pObjectName); - if (!obj) + if (!obj) { throw Base::ValueError("Sketcher: External geometry: Invalid object in selection"); + } std::string subName(msg.pSubName); if (obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId()) || obj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId()) diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerFillet.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerFillet.h index eaf62182d5..996298c48c 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerFillet.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerFillet.h @@ -45,17 +45,20 @@ public: bool allow(App::Document* /*pDoc*/, App::DocumentObject* pObj, const char* sSubName) override { - if (pObj != this->object) + if (pObj != this->object) { return false; - if (!sSubName || sSubName[0] == '\0') + } + if (!sSubName || sSubName[0] == '\0') { return false; + } std::string element(sSubName); if (element.substr(0, 4) == "Edge") { int GeoId = std::atoi(element.substr(4, 4000).c_str()) - 1; Sketcher::SketchObject* Sketch = static_cast(object); const Part::Geometry* geom = Sketch->getGeometry(GeoId); - if (geom->getTypeId().isDerivedFrom(Part::GeomBoundedCurve::getClassTypeId())) + if (geom->getTypeId().isDerivedFrom(Part::GeomBoundedCurve::getClassTypeId())) { return true; + } } if (element.substr(0, 6) == "Vertex") { int VtId = std::atoi(element.substr(6, 4000).c_str()) - 1; @@ -67,8 +70,9 @@ public: const Part::Geometry* geom1 = Sketch->getGeometry(GeoIdList[0]); const Part::Geometry* geom2 = Sketch->getGeometry(GeoIdList[1]); if (geom1->getTypeId() == Part::GeomLineSegment::getClassTypeId() - && geom2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) + && geom2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { return true; + } } } return false; @@ -128,8 +132,10 @@ public: double radius = -1; std::vector GeoIdList; std::vector PosIdList; - sketchgui->getSketchObject()->getDirectlyCoincidentPoints( - GeoId, PosId, GeoIdList, PosIdList); + sketchgui->getSketchObject()->getDirectlyCoincidentPoints(GeoId, + PosId, + GeoIdList, + PosIdList); if (GeoIdList.size() == 2 && GeoIdList[0] >= 0 && GeoIdList[1] >= 0) { const Part::Geometry* geom1 = sketchgui->getSketchObject()->getGeometry(GeoIdList[0]); @@ -145,18 +151,21 @@ public: static_cast(geom2); Base::Vector3d dir1 = lineSeg1->getEndPoint() - lineSeg1->getStartPoint(); Base::Vector3d dir2 = lineSeg2->getEndPoint() - lineSeg2->getStartPoint(); - if (PosIdList[0] == Sketcher::PointPos::end) + if (PosIdList[0] == Sketcher::PointPos::end) { dir1 *= -1; - if (PosIdList[1] == Sketcher::PointPos::end) + } + if (PosIdList[1] == Sketcher::PointPos::end) { dir2 *= -1; + } double l1 = dir1.Length(); double l2 = dir2.Length(); double angle = dir1.GetAngle(dir2); radius = (l1 < l2 ? l1 : l2) * 0.2 * sin(angle / 2); } } - if (radius < 0) + if (radius < 0) { return false; + } int currentgeoid = getHighestCurveIndex(); // create fillet at point @@ -172,8 +181,9 @@ public: pointFillet ? "True" : "False"); if (construction) { - Gui::cmdAppObjectArgs( - sketchgui->getObject(), "toggleConstruction(%d) ", currentgeoid + 1); + Gui::cmdAppObjectArgs(sketchgui->getObject(), + "toggleConstruction(%d) ", + currentgeoid + 1); } Gui::Command::commitCommand(); @@ -234,8 +244,9 @@ public: sketchgui->getSketchObject()->getGeometry(secondCurve)); radius = Part::suggestFilletRadius(lineSeg1, lineSeg2, refPnt1, refPnt2); - if (radius < 0) + if (radius < 0) { return false; + } construction = Sketcher::GeometryFacade::getConstruction(lineSeg1) && Sketcher::GeometryFacade::getConstruction(lineSeg2); @@ -293,8 +304,9 @@ public: tryAutoRecompute(static_cast(sketchgui->getObject())); if (construction) { - Gui::cmdAppObjectArgs( - sketchgui->getObject(), "toggleConstruction(%d) ", currentgeoid + 1); + Gui::cmdAppObjectArgs(sketchgui->getObject(), + "toggleConstruction(%d) ", + currentgeoid + 1); } @@ -304,9 +316,10 @@ public: } } - if (VtId < 0 && GeoId < 0)// exit the fillet tool if the user clicked on empty space + if (VtId < 0 && GeoId < 0) {// exit the fillet tool if the user clicked on empty space sketchgui ->purgeHandler();// no code after this line, Handler get deleted in ViewProvider + } return true; } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerLine.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerLine.h index 7965cd8210..5c224312d2 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerLine.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerLine.h @@ -129,16 +129,18 @@ public: bool avoidredundant = sketchgui->AvoidRedundant.getValue() && sketchgui->Autoconstraints.getValue(); - if (avoidredundant) + if (avoidredundant) { removeRedundantHorizontalVertical( static_cast(sketchgui->getObject()), sugConstr1, sugConstr2); + } // add auto constraints for the line segment start if (!sugConstr1.empty()) { - createAutoConstraints( - sugConstr1, getHighestCurveIndex(), Sketcher::PointPos::start); + createAutoConstraints(sugConstr1, + getHighestCurveIndex(), + Sketcher::PointPos::start); sugConstr1.clear(); } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h index 379f4f27d7..6c3a919ad4 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h @@ -89,8 +89,9 @@ public: void registerPressedKey(bool pressed, int key) override { - if (Mode != STATUS_SEEK_Second) + if (Mode != STATUS_SEEK_Second) { return;// SegmentMode can be changed only in STATUS_SEEK_Second mode + } if (key == SoKeyboardEvent::M && pressed && previousCurve != -1) { // loop through the following modes: @@ -104,10 +105,12 @@ public: SnapMode = SNAP_MODE_Free; Base::Vector2d onSketchPos; - if (SegmentMode == SEGMENT_MODE_Line) + if (SegmentMode == SEGMENT_MODE_Line) { onSketchPos = EditCurve[EditCurve.size() - 1]; - else + } + else { onSketchPos = EditCurve[29]; + } const Part::Geometry* geom = sketchgui->getSketchObject()->getGeometry(previousCurve); @@ -119,18 +122,23 @@ public: SegmentMode = SEGMENT_MODE_Arc; TransitionMode = TRANSITION_MODE_Tangent; } - else// 1st mode + else {// 1st mode TransitionMode = TRANSITION_MODE_Perpendicular_L; + } break; case TRANSITION_MODE_Perpendicular_L:// 2nd mode - if (geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) + if (geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { TransitionMode = TRANSITION_MODE_Free; - else + } + else { TransitionMode = TRANSITION_MODE_Tangent; + } break; case TRANSITION_MODE_Tangent: - if (geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId())// 1st mode + if (geom->getTypeId() + == Part::GeomArcOfCircle::getClassTypeId()) {// 1st mode TransitionMode = TRANSITION_MODE_Perpendicular_L; + } else {// 3rd mode SegmentMode = SEGMENT_MODE_Arc; TransitionMode = TRANSITION_MODE_Tangent; @@ -151,18 +159,22 @@ public: break; default:// 6th mode (Perpendicular_R) + unexpected mode SegmentMode = SEGMENT_MODE_Line; - if (geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) + if (geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { TransitionMode = TRANSITION_MODE_Tangent; - else + } + else { TransitionMode = TRANSITION_MODE_Free; + } break; } } - if (SegmentMode == SEGMENT_MODE_Line) + if (SegmentMode == SEGMENT_MODE_Line) { EditCurve.resize(TransitionMode == TRANSITION_MODE_Free ? 2 : 3); - else + } + else { EditCurve.resize(32); + } mouseMove(onSketchPos);// trigger an update of EditCurve } } @@ -187,8 +199,9 @@ public: EditCurve[1] = EditCurve[2]; suppressTransition = true; } - else + else { EditCurve[1] = EditCurve[0] + EditCurve[1]; + } } else if (TransitionMode == TRANSITION_MODE_Perpendicular_L || TransitionMode == TRANSITION_MODE_Perpendicular_R) { @@ -219,18 +232,23 @@ public: } else if (SegmentMode == SEGMENT_MODE_Arc) { - if (QApplication::keyboardModifiers() == Qt::ControlModifier) + if (QApplication::keyboardModifiers() == Qt::ControlModifier) { SnapMode = SNAP_MODE_45Degree; - else + } + else { SnapMode = SNAP_MODE_Free; + } Base::Vector2d Tangent; - if (TransitionMode == TRANSITION_MODE_Tangent) + if (TransitionMode == TRANSITION_MODE_Tangent) { Tangent = Base::Vector2d(dirVec.x, dirVec.y); - else if (TransitionMode == TRANSITION_MODE_Perpendicular_L) + } + else if (TransitionMode == TRANSITION_MODE_Perpendicular_L) { Tangent = Base::Vector2d(-dirVec.y, dirVec.x); - else if (TransitionMode == TRANSITION_MODE_Perpendicular_R) + } + else if (TransitionMode == TRANSITION_MODE_Perpendicular_R) { Tangent = Base::Vector2d(dirVec.y, -dirVec.x); + } double theta = Tangent.GetAngle(onSketchPos - EditCurve[0]); @@ -246,10 +264,12 @@ public: double y2 = y1 + Tangent.y; double x3 = onSketchPos.x; double y3 = onSketchPos.y; - if ((x2 * y3 - x3 * y2) - (x1 * y3 - x3 * y1) + (x1 * y2 - x2 * y1) > 0) + if ((x2 * y3 - x3 * y2) - (x1 * y3 - x3 * y1) + (x1 * y2 - x2 * y1) > 0) { arcRadius *= -1; - if (boost::math::isnan(arcRadius) || boost::math::isinf(arcRadius)) + } + if (boost::math::isnan(arcRadius) || boost::math::isinf(arcRadius)) { arcRadius = 0.f; + } CenterPoint = EditCurve[0] + Base::Vector2d(arcRadius * Tangent.y, -arcRadius * Tangent.x); @@ -262,15 +282,19 @@ public: double rxe = onSketchPos.x - CenterPoint.x; double rye = onSketchPos.y - CenterPoint.y; double arcAngle = atan2(-rxe * ry + rye * rx, rxe * rx + rye * ry); - if (boost::math::isnan(arcAngle) || boost::math::isinf(arcAngle)) + if (boost::math::isnan(arcAngle) || boost::math::isinf(arcAngle)) { arcAngle = 0.f; - if (arcRadius >= 0 && arcAngle > 0) + } + if (arcRadius >= 0 && arcAngle > 0) { arcAngle -= 2 * M_PI; - if (arcRadius < 0 && arcAngle < 0) + } + if (arcRadius < 0 && arcAngle < 0) { arcAngle += 2 * M_PI; + } - if (SnapMode == SNAP_MODE_45Degree) + if (SnapMode == SNAP_MODE_45Degree) { arcAngle = round(arcAngle / (M_PI / 4)) * M_PI / 4; + } endAngle = startAngle + arcAngle; @@ -314,7 +338,7 @@ public: // here we check if there is a preselected point and // we set up a transition from the neighbouring segment. // (peviousCurve, previousPosId, dirVec, TransitionMode) - for (unsigned int i = 0; i < sugConstr1.size(); i++) + for (unsigned int i = 0; i < sugConstr1.size(); i++) { if (sugConstr1[i].Type == Sketcher::Coincident) { const Part::Geometry* geom = sketchgui->getSketchObject()->getGeometry(sugConstr1[i].GeoId); @@ -335,15 +359,18 @@ public: break; } } + } // remember our first point (even if we are doing a transition from a previous curve) firstCurve = getHighestCurveIndex() + 1; firstPosId = Sketcher::PointPos::start; - if (SegmentMode == SEGMENT_MODE_Line) + if (SegmentMode == SEGMENT_MODE_Line) { EditCurve.resize(TransitionMode == TRANSITION_MODE_Free ? 2 : 3); - else if (SegmentMode == SEGMENT_MODE_Arc) + } + else if (SegmentMode == SEGMENT_MODE_Arc) { EditCurve.resize(32); + } Mode = STATUS_SEEK_Second; } else if (Mode == STATUS_SEEK_Second) { @@ -392,15 +419,21 @@ public: int GeoId; Sketcher::PointPos PosId; sketchgui->getSketchObject()->getGeoVertexIndex(getPreselectPoint(), GeoId, PosId); - if (sketchgui->getSketchObject()->arePointsCoincident( - GeoId, PosId, firstCurve, firstPosId)) + if (sketchgui->getSketchObject()->arePointsCoincident(GeoId, + PosId, + firstCurve, + firstPosId)) { Mode = STATUS_Close; + } } else if (getPreselectCross() == 0 && firstPosId != Sketcher::PointPos::none) { // close line started at root point - if (sketchgui->getSketchObject()->arePointsCoincident( - -1, Sketcher::PointPos::start, firstCurve, firstPosId)) + if (sketchgui->getSketchObject()->arePointsCoincident(-1, + Sketcher::PointPos::start, + firstCurve, + firstPosId)) { Mode = STATUS_Close; + } } } return true; @@ -481,11 +514,13 @@ public: // in case of a tangency constraint, the coincident constraint is redundant std::string constrType = "Coincident"; if (!suppressTransition && previousCurve != -1) { - if (TransitionMode == TRANSITION_MODE_Tangent) + if (TransitionMode == TRANSITION_MODE_Tangent) { constrType = "Tangent"; + } else if (TransitionMode == TRANSITION_MODE_Perpendicular_L - || TransitionMode == TRANSITION_MODE_Perpendicular_R) + || TransitionMode == TRANSITION_MODE_Perpendicular_R) { constrType = "Perpendicular"; + } } Gui::cmdAppObjectArgs(sketchgui->getObject(), "addConstraint(Sketcher.Constraint('%s',%i,%i,%i,%i)) ", @@ -537,16 +572,18 @@ public: if (avoidredundant) { if (SegmentMode == SEGMENT_MODE_Line) {// avoid redundant constraints. - if (sugConstr1.size() > 0) + if (sugConstr1.size() > 0) { removeRedundantHorizontalVertical( static_cast(sketchgui->getObject()), sugConstr1, sugConstr2); - else + } + else { removeRedundantHorizontalVertical( static_cast(sketchgui->getObject()), virtualsugConstr1, sugConstr2); + } } } @@ -554,11 +591,13 @@ public: // exclude any coincidence constraints std::vector sugConstr; for (unsigned int i = 0; i < sugConstr2.size(); i++) { - if (sugConstr2[i].Type != Sketcher::Coincident) + if (sugConstr2[i].Type != Sketcher::Coincident) { sugConstr.push_back(sugConstr2[i]); + } } - createAutoConstraints( - sugConstr, getHighestCurveIndex(), Sketcher::PointPos::end); + createAutoConstraints(sugConstr, + getHighestCurveIndex(), + Sketcher::PointPos::end); sugConstr2.clear(); } @@ -605,24 +644,27 @@ public: // Add auto constraints if (!sugConstr1.empty()) {// this is relevant only to the very first point - createAutoConstraints( - sugConstr1, getHighestCurveIndex(), Sketcher::PointPos::start); + createAutoConstraints(sugConstr1, + getHighestCurveIndex(), + Sketcher::PointPos::start); sugConstr1.clear(); } if (avoidredundant) { if (SegmentMode == SEGMENT_MODE_Line) {// avoid redundant constraints. - if (sugConstr1.size() > 0) + if (sugConstr1.size() > 0) { removeRedundantHorizontalVertical( static_cast(sketchgui->getObject()), sugConstr1, sugConstr2); - else + } + else { removeRedundantHorizontalVertical( static_cast(sketchgui->getObject()), virtualsugConstr1, sugConstr2); + } } } @@ -753,8 +795,9 @@ protected: EditCurve[0] = Base::Vector2d(lineSeg->getStartPoint().x, lineSeg->getStartPoint().y); } - else + else { EditCurve[0] = Base::Vector2d(lineSeg->getEndPoint().x, lineSeg->getEndPoint().y); + } } else if (geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { const Part::GeomArcOfCircle* arcSeg = static_cast(geom); diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h index 276a4a4e3b..993ac9e4c3 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h @@ -137,15 +137,17 @@ public: // add auto constraints at the center of the polygon if (!sugConstr1.empty()) { - createAutoConstraints( - sugConstr1, getHighestCurveIndex(), Sketcher::PointPos::mid); + createAutoConstraints(sugConstr1, + getHighestCurveIndex(), + Sketcher::PointPos::mid); sugConstr1.clear(); } // add auto constraints to the last side of the polygon if (!sugConstr2.empty()) { - createAutoConstraints( - sugConstr2, getHighestCurveIndex() - 1, Sketcher::PointPos::end); + createAutoConstraints(sugConstr2, + getHighestCurveIndex() - 1, + Sketcher::PointPos::end); sugConstr2.clear(); } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h index 1d316d6229..1e0ba918bc 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h @@ -297,30 +297,34 @@ public: if (constructionMethod == Diagonal) { // add auto constraints at the start of the first side if (!sugConstr1.empty()) { - createAutoConstraints( - sugConstr1, getHighestCurveIndex() - 3, Sketcher::PointPos::start); + createAutoConstraints(sugConstr1, + getHighestCurveIndex() - 3, + Sketcher::PointPos::start); sugConstr1.clear(); } // add auto constraints at the end of the second side if (!sugConstr2.empty()) { - createAutoConstraints( - sugConstr2, getHighestCurveIndex() - 2, Sketcher::PointPos::end); + createAutoConstraints(sugConstr2, + getHighestCurveIndex() - 2, + Sketcher::PointPos::end); sugConstr2.clear(); } } else if (constructionMethod == CenterAndCorner) { // add auto constraints at the start of the first side if (!sugConstr1.empty()) { - createAutoConstraints( - sugConstr1, getHighestCurveIndex(), Sketcher::PointPos::start); + createAutoConstraints(sugConstr1, + getHighestCurveIndex(), + Sketcher::PointPos::start); sugConstr1.clear(); } // add auto constraints at the end of the second side if (!sugConstr2.empty()) { - createAutoConstraints( - sugConstr2, getHighestCurveIndex() - 3, Sketcher::PointPos::end); + createAutoConstraints(sugConstr2, + getHighestCurveIndex() - 3, + Sketcher::PointPos::end); sugConstr2.clear(); } } @@ -470,8 +474,10 @@ public: std::string radiusString = lengthToDisplayFormat(radius, 1); std::string xString = lengthToDisplayFormat(lengthX, 1); std::string yString = lengthToDisplayFormat(lengthY, 1); - text.sprintf( - " (R%s X%s Y%s)", radiusString.c_str(), xString.c_str(), yString.c_str()); + text.sprintf(" (R%s X%s Y%s)", + radiusString.c_str(), + xString.c_str(), + yString.c_str()); setPositionText(onSketchPos, text); } @@ -678,15 +684,17 @@ public: // add auto constraints at the StartPos auxiliary point if (!sugConstr1.empty()) { - createAutoConstraints( - sugConstr1, getHighestCurveIndex() - 1, Sketcher::PointPos::start); + createAutoConstraints(sugConstr1, + getHighestCurveIndex() - 1, + Sketcher::PointPos::start); sugConstr1.clear(); } // add auto constraints at the EndPos auxiliary point if (!sugConstr2.empty()) { - createAutoConstraints( - sugConstr2, getHighestCurveIndex(), Sketcher::PointPos::start); + createAutoConstraints(sugConstr2, + getHighestCurveIndex(), + Sketcher::PointPos::start); sugConstr2.clear(); } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h index 21c20a4c61..e4cc75d5b6 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h @@ -81,10 +81,12 @@ public: dx = onSketchPos.x - StartPos.x; dy = onSketchPos.y - StartPos.y; - if (QApplication::keyboardModifiers() == Qt::ControlModifier) + if (QApplication::keyboardModifiers() == Qt::ControlModifier) { SnapMode = SNAP_MODE_Straight; - else + } + else { SnapMode = SNAP_MODE_Free; + } double a = 0; double rev = 0; @@ -92,16 +94,18 @@ public: r = fabs(dx) / 4; rev = Base::sgn(dx); SnapDir = SNAP_DIR_Horz; - if (SnapMode == SNAP_MODE_Straight) + if (SnapMode == SNAP_MODE_Straight) { dy = 0; + } } else { r = fabs(dy) / 4; a = 8; rev = Base::sgn(dy); SnapDir = SNAP_DIR_Vert; - if (SnapMode == SNAP_MODE_Straight) + if (SnapMode == SNAP_MODE_Straight) { dx = 0; + } } // draw the arcs with each 16 segments @@ -116,8 +120,9 @@ public: // onSketchPos if (!(dx == 0 || dy == 0)) { double rotAngle = atan(dy / dx); - if (a > 0) + if (a > 0) { rotAngle = -atan(dx / dy); + } double rxRot = rx * cos(rotAngle) - ry * sin(rotAngle); double ryRot = rx * sin(rotAngle) + ry * cos(rotAngle); rx = rxRot; @@ -195,11 +200,13 @@ public: try { Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Add slot")); - AutoConstraint lastCons = { - Sketcher::None, Sketcher::GeoEnum::GeoUndef, Sketcher::PointPos::none}; + AutoConstraint lastCons = {Sketcher::None, + Sketcher::GeoEnum::GeoUndef, + Sketcher::PointPos::none}; - if (!sugConstr2.empty()) + if (!sugConstr2.empty()) { lastCons = sugConstr2.back(); + } ostringstream snapCon = ostringstream(""); if (SnapMode == SNAP_MODE_Straight) { @@ -215,15 +222,17 @@ public: // If horizontal/vertical already applied because of snap, do not duplicate with // Autocontraint if (lastCons.Type == Sketcher::Horizontal - || lastCons.Type == Sketcher::Vertical) + || lastCons.Type == Sketcher::Vertical) { sugConstr2.pop_back(); + } } else { // If horizontal/vertical Autoconstraint suggested, applied it on first line // (rather than last arc) if (lastCons.Type == Sketcher::Horizontal - || lastCons.Type == Sketcher::Vertical) + || lastCons.Type == Sketcher::Vertical) { sugConstr2.back().GeoId = firstCurve + 2; + } } Gui::Command::doCommand( @@ -286,15 +295,17 @@ public: // add auto constraints at the center of the first arc if (!sugConstr1.empty()) { - createAutoConstraints( - sugConstr1, getHighestCurveIndex() - 3, Sketcher::PointPos::mid); + createAutoConstraints(sugConstr1, + getHighestCurveIndex() - 3, + Sketcher::PointPos::mid); sugConstr1.clear(); } // add auto constraints at the center of the second arc if (!sugConstr2.empty()) { - createAutoConstraints( - sugConstr2, getHighestCurveIndex() - 2, Sketcher::PointPos::mid); + createAutoConstraints(sugConstr2, + getHighestCurveIndex() - 2, + Sketcher::PointPos::mid); sugConstr2.clear(); } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerSplitting.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerSplitting.h index e844b72907..4134638853 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerSplitting.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerSplitting.h @@ -46,10 +46,12 @@ public: bool allow(App::Document* /*pDoc*/, App::DocumentObject* pObj, const char* sSubName) override { - if (pObj != this->object) + if (pObj != this->object) { return false; - if (!sSubName || sSubName[0] == '\0') + } + if (!sSubName || sSubName[0] == '\0') { return false; + } std::string element(sSubName); if (element.substr(0, 4) == "Edge") { int GeoId = std::atoi(element.substr(4, 4000).c_str()) - 1; @@ -69,8 +71,9 @@ public: Sketcher::PointPos PosId = Sketcher::PointPos::none; Sketcher::SketchObject* Sketch = static_cast(object); Sketch->getGeoVertexIndex(VertId, GeoId, PosId); - if (isBsplineKnot(Sketch, GeoId)) + if (isBsplineKnot(Sketch, GeoId)) { return true; + } } return false; } @@ -127,8 +130,9 @@ public: && constr->First == pointGeoId); }); - if (conIt != constraints.end()) + if (conIt != constraints.end()) { GeoId = (*conIt)->Second; + } } } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerTrimming.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerTrimming.h index dd5b9875fe..963a308f9b 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerTrimming.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerTrimming.h @@ -45,10 +45,12 @@ public: bool allow(App::Document* /*pDoc*/, App::DocumentObject* pObj, const char* sSubName) override { - if (pObj != this->object) + if (pObj != this->object) { return false; - if (!sSubName || sSubName[0] == '\0') + } + if (!sSubName || sSubName[0] == '\0') { return false; + } std::string element(sSubName); if (element.substr(0, 4) == "Edge") { int GeoId = std::atoi(element.substr(4, 4000).c_str()) - 1; @@ -59,8 +61,9 @@ public: || geom->getTypeId() == Part::GeomEllipse::getClassTypeId() || geom->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) { // We do not trim internal geometry of complex geometries - if (Sketcher::GeometryFacade::isInternalType(geom, Sketcher::InternalType::None)) + if (Sketcher::GeometryFacade::isInternalType(geom, Sketcher::InternalType::None)) { return true; + } } } return false; @@ -95,15 +98,17 @@ public: EditMarkers.resize(0); - if (GeoId1 != Sketcher::GeoEnum::GeoUndef) + if (GeoId1 != Sketcher::GeoEnum::GeoUndef) { EditMarkers.emplace_back(intersect1.x, intersect1.y); + } else { auto start = sk->getPoint(GeoId, Sketcher::PointPos::start); EditMarkers.emplace_back(start.x, start.y); } - if (GeoId2 != Sketcher::GeoEnum::GeoUndef) + if (GeoId2 != Sketcher::GeoEnum::GeoUndef) { EditMarkers.emplace_back(intersect2.x, intersect2.y); + } else { auto end = sk->getPoint(GeoId, Sketcher::PointPos::end); EditMarkers.emplace_back(end.x, end.y); @@ -156,9 +161,10 @@ public: EditMarkers.resize(0); drawEditMarkers(EditMarkers); } - else// exit the trimming tool if the user clicked on empty space + else {// exit the trimming tool if the user clicked on empty space sketchgui ->purgeHandler();// no code after this line, Handler get deleted in ViewProvider + } return true; } diff --git a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp index 2bced92a6d..658638d58b 100644 --- a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp +++ b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp @@ -147,8 +147,10 @@ int EditDatumDialog::exec(bool atCursor) ui_ins_datum->cbDriving->setChecked(!Constr->isDriving); - connect( - ui_ins_datum->cbDriving, &QCheckBox::toggled, this, &EditDatumDialog::drivingToggled); + connect(ui_ins_datum->cbDriving, + &QCheckBox::toggled, + this, + &EditDatumDialog::drivingToggled); connect(ui_ins_datum->labelEdit, qOverload(&Gui::QuantitySpinBox::valueChanged), this, @@ -198,22 +200,26 @@ void EditDatumDialog::accepted() }*/ if (!ui_ins_datum->cbDriving->isChecked()) { - if (ui_ins_datum->labelEdit->hasExpression()) + if (ui_ins_datum->labelEdit->hasExpression()) { ui_ins_datum->labelEdit->apply(); - else + } + else { Gui::cmdAppObjectArgs(sketch, "setDatum(%i,App.Units.Quantity('%f %s'))", ConstrNbr, newDatum, (const char*)newQuant.getUnit().getString().toUtf8()); + } } QString constraintName = ui_ins_datum->name->text().trimmed(); if (Base::Tools::toStdString(constraintName) != sketch->Constraints[ConstrNbr]->Name) { std::string escapedstr = Base::Tools::escapedUnicodeFromUtf8(constraintName.toUtf8().constData()); - Gui::cmdAppObjectArgs( - sketch, "renameConstraint(%d, u'%s')", ConstrNbr, escapedstr.c_str()); + Gui::cmdAppObjectArgs(sketch, + "renameConstraint(%d, u'%s')", + ConstrNbr, + escapedstr.c_str()); } Gui::Command::commitCommand(); @@ -239,14 +245,16 @@ void EditDatumDialog::accepted() success = true; } catch (const Base::Exception& e) { - Gui::NotifyUserError( - sketch, QT_TRANSLATE_NOOP("Notifications", "Value Error"), e.what()); + Gui::NotifyUserError(sketch, + QT_TRANSLATE_NOOP("Notifications", "Value Error"), + e.what()); Gui::Command::abortCommand(); - if (sketch->noRecomputes)// if setdatum failed, it is highly likely that solver - // information is invalid. + if (sketch->noRecomputes) {// if setdatum failed, it is highly likely that solver + // information is invalid. sketch->solve(); + } } } } @@ -268,8 +276,9 @@ void EditDatumDialog::drivingToggled(bool state) ui_ins_datum->labelEdit->setToLastUsedValue(); } sketch->setDriving(ConstrNbr, !state); - if (!sketch->noRecomputes)// if noRecomputes, solve() is already done by setDriving() + if (!sketch->noRecomputes) {// if noRecomputes, solve() is already done by setDriving() sketch->solve(); + } } void EditDatumDialog::datumChanged() diff --git a/src/Mod/Sketcher/Gui/EditModeCoinManager.cpp b/src/Mod/Sketcher/Gui/EditModeCoinManager.cpp index 6fb6aba3a1..cf1761e2c8 100644 --- a/src/Mod/Sketcher/Gui/EditModeCoinManager.cpp +++ b/src/Mod/Sketcher/Gui/EditModeCoinManager.cpp @@ -250,8 +250,9 @@ void EditModeCoinManager::ParameterObserver::updateCurvedEdgeCountSegmentsParame App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); int stdcountsegments = hGrp->GetInt(parametername.c_str(), 50); // value cannot be smaller than 6 - if (stdcountsegments < 6) + if (stdcountsegments < 6) { stdcountsegments = 6; + } Client.drawingParameters.curvedEdgeCountSegments = stdcountsegments; } @@ -292,25 +293,32 @@ void EditModeCoinManager::ParameterObserver::updateOverlayVisibilityParameter( ParameterGrp::handle hGrpsk = App::GetApplication().GetParameterGroupByPath( "User parameter:BaseApp/Preferences/Mod/Sketcher/General"); - if constexpr (visibilityparameter == OverlayVisibilityParameter::BSplineDegree) + if constexpr (visibilityparameter == OverlayVisibilityParameter::BSplineDegree) { Client.overlayParameters.bSplineDegreeVisible = hGrpsk->GetBool(parametername.c_str(), true); + } else if constexpr (visibilityparameter - == OverlayVisibilityParameter::BSplineControlPolygonVisible) + == OverlayVisibilityParameter::BSplineControlPolygonVisible) { Client.overlayParameters.bSplineControlPolygonVisible = hGrpsk->GetBool(parametername.c_str(), true); - else if constexpr (visibilityparameter == OverlayVisibilityParameter::BSplineCombVisible) + } + else if constexpr (visibilityparameter == OverlayVisibilityParameter::BSplineCombVisible) { Client.overlayParameters.bSplineCombVisible = hGrpsk->GetBool(parametername.c_str(), true); + } else if constexpr (visibilityparameter - == OverlayVisibilityParameter::BSplineKnotMultiplicityVisible) + == OverlayVisibilityParameter::BSplineKnotMultiplicityVisible) { Client.overlayParameters.bSplineKnotMultiplicityVisible = hGrpsk->GetBool(parametername.c_str(), true); - else if constexpr (visibilityparameter == OverlayVisibilityParameter::BSplinePoleWeightVisible) + } + else if constexpr (visibilityparameter + == OverlayVisibilityParameter::BSplinePoleWeightVisible) { Client.overlayParameters.bSplinePoleWeightVisible = hGrpsk->GetBool(parametername.c_str(), true); - else if constexpr (visibilityparameter == OverlayVisibilityParameter::ArcCircleHelperVisible) + } + else if constexpr (visibilityparameter == OverlayVisibilityParameter::ArcCircleHelperVisible) { Client.overlayParameters.arcCircleHelperVisible = hGrpsk->GetBool(parametername.c_str(), false); + } Client.overlayParameters.visibleInformationChanged = true; } @@ -418,8 +426,9 @@ void EditModeCoinManager::ParameterObserver::subscribeToParameters() } catch (const Base::ValueError& e) {// ensure that if parameter strings are not well-formed, the // exception is not propagated - Base::Console().DeveloperError( - "EditModeCoinManager", "Malformed parameter string: %s\n", e.what()); + Base::Console().DeveloperError("EditModeCoinManager", + "Malformed parameter string: %s\n", + e.what()); } } @@ -445,8 +454,9 @@ void EditModeCoinManager::ParameterObserver::unsubscribeToParameters() catch (const Base::ValueError& e) {// ensure that if parameter strings are not well-formed, the program is not // terminated when calling the noexcept destructor. - Base::Console().DeveloperError( - "EditModeCoinManager", "Malformed parameter string: %s\n", e.what()); + Base::Console().DeveloperError("EditModeCoinManager", + "Malformed parameter string: %s\n", + e.what()); } } @@ -518,8 +528,9 @@ void EditModeCoinManager::drawEditMarkers(const std::vector& Edi if (defaultmarker != supportedsizes.end()) { auto validAugmentationLevels = std::distance(defaultmarker, supportedsizes.end()); - if (augmentationlevel >= validAugmentationLevels) + if (augmentationlevel >= validAugmentationLevels) { augmentationlevel = validAugmentationLevels - 1; + } augmentedmarkersize = *std::next(defaultmarker, augmentationlevel); } @@ -579,8 +590,9 @@ void EditModeCoinManager::drawEdit(const std::list>& { int ncoords = 0; - for (const auto& v : list) + for (const auto& v : list) { ncoords += v.size(); + } editModeScenegraphNodes.EditCurveSet->numVertices.setNum(list.size()); editModeScenegraphNodes.EditCurvesCoordinate->point.setNum(ncoords); @@ -638,10 +650,12 @@ void EditModeCoinManager::resetPositionText() void EditModeCoinManager::setAxisPickStyle(bool on) { - if (on) + if (on) { editModeScenegraphNodes.pickStyleAxes->style = SoPickStyle::SHAPE; - else + } + else { editModeScenegraphNodes.pickStyleAxes->style = SoPickStyle::UNPICKABLE; + } } EditModeCoinManager::PreselectionResult @@ -649,8 +663,9 @@ EditModeCoinManager::detectPreselection(SoPickedPoint* Point, const SbVec2s& cur { EditModeCoinManager::PreselectionResult result; - if (!Point) + if (!Point) { return result; + } // Base::Console().Log("Point pick\n"); SoPath* path = Point->getPath(); @@ -664,10 +679,12 @@ EditModeCoinManager::detectPreselection(SoPickedPoint* Point, const SbVec2s& cur // get the index int pindex = static_cast(point_detail)->getCoordinateIndex(); result.PointIndex = coinMapping.getPointVertexId( - pindex, l);// returns -1 for root, global VertexId for the rest of vertices. + pindex, + l);// returns -1 for root, global VertexId for the rest of vertices. - if (result.PointIndex == -1) + if (result.PointIndex == -1) { result.Cross = PreselectionResult::Axes::RootPoint; + } return result; } @@ -692,10 +709,12 @@ EditModeCoinManager::detectPreselection(SoPickedPoint* Point, const SbVec2s& cur // get the index (reserve index 0 for root point) int CrossIndex = static_cast(cross_detail)->getLineIndex(); - if (CrossIndex == 0) + if (CrossIndex == 0) { result.Cross = PreselectionResult::Axes::HorizontalAxis; - else if (CrossIndex == 1) + } + else if (CrossIndex == 1) { result.Cross = PreselectionResult::Axes::VerticalAxis; + } return result; } @@ -715,8 +734,9 @@ SoGroup* EditModeCoinManager::getSelectedConstraints() for (int i = 0; i < editModeScenegraphNodes.constrGroup->getNumChildren(); i++) { if (ViewProviderSketchCoinAttorney::isConstraintSelected(viewProvider, i)) { SoSeparator* sep = pEditModeConstraintCoinManager->getConstraintIdSeparator(i); - if (sep) + if (sep) { group->addChild(sep); + } } } @@ -726,7 +746,8 @@ SoGroup* EditModeCoinManager::getSelectedConstraints() /***** update coin nodes *****/ void EditModeCoinManager::processGeometryConstraintsInformationOverlay( - const GeoListFacade& geolistfacade, bool rebuildinformationlayer) + const GeoListFacade& geolistfacade, + bool rebuildinformationlayer) { overlayParameters.rebuildInformationLayer = rebuildinformationlayer; @@ -746,9 +767,10 @@ void EditModeCoinManager::updateOverlayParameters() if ((analysisResults.combRepresentationScale > (2 * overlayParameters.currentBSplineCombRepresentationScale)) || (analysisResults.combRepresentationScale - < (overlayParameters.currentBSplineCombRepresentationScale / 2))) + < (overlayParameters.currentBSplineCombRepresentationScale / 2))) { overlayParameters.currentBSplineCombRepresentationScale = analysisResults.combRepresentationScale; + } } void EditModeCoinManager::processGeometryInformationOverlay(const GeoListFacade& geolistfacade) @@ -758,8 +780,10 @@ void EditModeCoinManager::processGeometryInformationOverlay(const GeoListFacade& Gui::coinRemoveAllChildren(editModeScenegraphNodes.infoGroup); } - auto ioconv = EditModeInformationOverlayCoinConverter( - viewProvider, editModeScenegraphNodes.infoGroup, overlayParameters, drawingParameters); + auto ioconv = EditModeInformationOverlayCoinConverter(viewProvider, + editModeScenegraphNodes.infoGroup, + overlayParameters, + drawingParameters); // geometry information layer for bsplines, as they need a second round now that max curvature // is known @@ -782,13 +806,17 @@ void EditModeCoinManager::updateAxesLength() auto zCrossH = ViewProviderSketchCoinAttorney::getViewOrientationFactor(viewProvider) * drawingParameters.zCross; editModeScenegraphNodes.RootCrossCoordinate->point.set1Value( - 0, SbVec3f(-analysisResults.boundingBoxMagnitudeOrder, 0.0f, zCrossH)); + 0, + SbVec3f(-analysisResults.boundingBoxMagnitudeOrder, 0.0f, zCrossH)); editModeScenegraphNodes.RootCrossCoordinate->point.set1Value( - 1, SbVec3f(analysisResults.boundingBoxMagnitudeOrder, 0.0f, zCrossH)); + 1, + SbVec3f(analysisResults.boundingBoxMagnitudeOrder, 0.0f, zCrossH)); editModeScenegraphNodes.RootCrossCoordinate->point.set1Value( - 2, SbVec3f(0.0f, -analysisResults.boundingBoxMagnitudeOrder, zCrossH)); + 2, + SbVec3f(0.0f, -analysisResults.boundingBoxMagnitudeOrder, zCrossH)); editModeScenegraphNodes.RootCrossCoordinate->point.set1Value( - 3, SbVec3f(0.0f, analysisResults.boundingBoxMagnitudeOrder, zCrossH)); + 3, + SbVec3f(0.0f, analysisResults.boundingBoxMagnitudeOrder, zCrossH)); } void EditModeCoinManager::updateColor() @@ -808,8 +836,9 @@ void EditModeCoinManager::updateColor(const GeoListFacade& geolistfacade) auto constraints = ViewProviderSketchCoinAttorney::getConstraints(viewProvider); - if (ViewProviderSketchCoinAttorney::haveConstraintsInvalidGeometry(viewProvider)) + if (ViewProviderSketchCoinAttorney::haveConstraintsInvalidGeometry(viewProvider)) { return; + } pEditModeConstraintCoinManager->updateConstraintColor(constraints); } @@ -858,9 +887,11 @@ void EditModeCoinManager::createEditModeInventorNodes() editModeScenegraphNodes.RootCrossMaterials = new SoMaterial; editModeScenegraphNodes.RootCrossMaterials->setName("RootCrossMaterials"); editModeScenegraphNodes.RootCrossMaterials->diffuseColor.set1Value( - 0, drawingParameters.CrossColorH); + 0, + drawingParameters.CrossColorH); editModeScenegraphNodes.RootCrossMaterials->diffuseColor.set1Value( - 1, drawingParameters.CrossColorV); + 1, + drawingParameters.CrossColorV); crossRoot->addChild(editModeScenegraphNodes.RootCrossMaterials); editModeScenegraphNodes.RootCrossCoordinate = new SoCoordinate3; @@ -1036,9 +1067,11 @@ void EditModeCoinManager::updateInventorNodeSizes() void EditModeCoinManager::updateInventorColors() { editModeScenegraphNodes.RootCrossMaterials->diffuseColor.set1Value( - 0, drawingParameters.CrossColorH); + 0, + drawingParameters.CrossColorH); editModeScenegraphNodes.RootCrossMaterials->diffuseColor.set1Value( - 1, drawingParameters.CrossColorV); + 1, + drawingParameters.CrossColorV); editModeScenegraphNodes.textMaterial->diffuseColor = drawingParameters.CursorTextColor; } diff --git a/src/Mod/Sketcher/Gui/EditModeCoinManagerParameters.cpp b/src/Mod/Sketcher/Gui/EditModeCoinManagerParameters.cpp index aa928f5ac7..9d3916ed22 100644 --- a/src/Mod/Sketcher/Gui/EditModeCoinManagerParameters.cpp +++ b/src/Mod/Sketcher/Gui/EditModeCoinManagerParameters.cpp @@ -33,13 +33,16 @@ SbColor DrawingParameters::CrossColorH(0.8f, 0.4f, 0.4f); // #CC6666 -> SbColor DrawingParameters::CrossColorV(0.47f, 1.0f, 0.51f); // #83FF83 -> (120,255,131) SbColor DrawingParameters::InvalidSketchColor(1.0f, 0.42f, 0.0f); // #FF6D00 -> (255,109, 0) SbColor DrawingParameters::FullyConstrainedColor(0.0f, 1.0f, 0.0f);// #00FF00 -> ( 0,255, 0) -SbColor DrawingParameters::FullyConstraintInternalAlignmentColor(0.87f, 0.87f, +SbColor DrawingParameters::FullyConstraintInternalAlignmentColor(0.87f, + 0.87f, 0.78f);// #DEDEC8 -> (222,222,200) SbColor DrawingParameters::InternalAlignedGeoColor(0.7f, 0.7f, 0.5f); // #B2B27F -> (178,178,127) -SbColor DrawingParameters::FullyConstraintConstructionPointColor(1.0f, 0.58f, +SbColor DrawingParameters::FullyConstraintConstructionPointColor(1.0f, + 0.58f, 0.50f);// #FF9580 -> (255,149,128) SbColor DrawingParameters::VertexColor(1.0f, 0.149f, 0.0f); // #FF2600 -> (255, 38, 0) -SbColor DrawingParameters::FullyConstraintElementColor(0.50f, 0.81f, +SbColor DrawingParameters::FullyConstraintElementColor(0.50f, + 0.81f, 0.62f); // #80D0A0 -> (128,208,160) SbColor DrawingParameters::CurveColor(1.0f, 1.0f, 1.0f); // #FFFFFF -> (255,255,255) SbColor DrawingParameters::PreselectColor(0.88f, 0.88f, 0.0f); // #E1E100 -> (225,225, 0) @@ -48,7 +51,8 @@ SbColor DrawingParameters::PreselectSelectedColor(0.36f, 0.48f, 0.11f);// #5D7B1 SbColor DrawingParameters::CurveExternalColor(0.8f, 0.2f, 0.6f); // #CC3399 -> (204, 51,153) SbColor DrawingParameters::CurveDraftColor(0.0f, 0.0f, 0.86f); // #0000DC -> ( 0, 0,220) SbColor - DrawingParameters::FullyConstraintConstructionElementColor(0.56f, 0.66f, + DrawingParameters::FullyConstraintConstructionElementColor(0.56f, + 0.66f, 0.99f);// #8FA9FD -> (143,169,253) SbColor DrawingParameters::ConstrDimColor(1.0f, 0.149f, 0.0f); // #FF2600 -> (255, 38, 0) diff --git a/src/Mod/Sketcher/Gui/EditModeCoinManagerParameters.h b/src/Mod/Sketcher/Gui/EditModeCoinManagerParameters.h index 93a14816c7..0cb1d457d1 100644 --- a/src/Mod/Sketcher/Gui/EditModeCoinManagerParameters.h +++ b/src/Mod/Sketcher/Gui/EditModeCoinManagerParameters.h @@ -450,20 +450,21 @@ struct CoinMapping auto indexit = std::find(PointIdToVertexId[l].begin(), PointIdToVertexId[l].end(), vertexId); - if (indexit != PointIdToVertexId[l].end()) + if (indexit != PointIdToVertexId[l].end()) { return MultiFieldId(std::distance(PointIdToVertexId[l].begin(), indexit), l); + } } return MultiFieldId::Invalid; } //* These map a MF index (second index) within a coin layer (first index) for points or curves - //to a GeoId */ + // to a GeoId */ std::vector> CurvIdToGeoId; // conversion of SoLineSet index to GeoId std::vector> PointIdToGeoId;// conversion of SoCoordinate3 index to GeoId //* This maps an MF index (second index) of a point within a coin layer (first index) to a - //global VertexId */ + // global VertexId */ std::vector> PointIdToVertexId; /// This maps GeoElementId index {GeoId, PointPos} to a {coin layer and MF index} of a curve or diff --git a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.h b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.h index b4b6e23edc..62fb0756f0 100644 --- a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.h +++ b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.h @@ -94,7 +94,8 @@ private: }; public: - explicit EditModeConstraintCoinManager(ViewProviderSketch& vp, DrawingParameters& drawingParams, + explicit EditModeConstraintCoinManager(ViewProviderSketch& vp, + DrawingParameters& drawingParams, GeometryLayerParameters& geometryLayerParams, ConstraintParameters& constraintParams, EditModeScenegraphNodes& editModeScenegraph, @@ -140,11 +141,14 @@ private: void rebuildConstraintNodes(const GeoListFacade& geolistfacade);// with specific geometry void rebuildConstraintNodes(const GeoListFacade& geolistfacade, - const std::vector constrlist, SbVec3f norm); + const std::vector constrlist, + SbVec3f norm); /// finds a free position for placing a constraint icon - Base::Vector3d seekConstraintPosition(const Base::Vector3d& origPos, const Base::Vector3d& norm, - const Base::Vector3d& dir, float step, + Base::Vector3d seekConstraintPosition(const Base::Vector3d& origPos, + const Base::Vector3d& norm, + const Base::Vector3d& dir, + float step, const SoNode* constraint); /// Return display string for constraint including hiding units if @@ -227,8 +231,11 @@ private: void drawMergedConstraintIcons(IconQueue iconQueue); /// Helper for drawMergedConstraintIcons and drawTypicalConstraintIcon - QImage renderConstrIcon(const QString& type, const QColor& iconColor, const QStringList& labels, - const QList& labelColors, double iconRotation, + QImage renderConstrIcon(const QString& type, + const QColor& iconColor, + const QStringList& labels, + const QList& labelColors, + double iconRotation, //! Gets populated with bounding boxes (in icon //! image coordinates) for the icon at left, then //! labels for different constraints. diff --git a/src/Mod/Sketcher/Gui/EditModeGeometryCoinConverter.cpp b/src/Mod/Sketcher/Gui/EditModeGeometryCoinConverter.cpp index 46c6d7d20b..690bcf6926 100644 --- a/src/Mod/Sketcher/Gui/EditModeGeometryCoinConverter.cpp +++ b/src/Mod/Sketcher/Gui/EditModeGeometryCoinConverter.cpp @@ -35,8 +35,10 @@ using namespace SketcherGui; EditModeGeometryCoinConverter::EditModeGeometryCoinConverter( - ViewProviderSketch& vp, GeometryLayerNodes& geometrylayernodes, - DrawingParameters& drawingparameters, GeometryLayerParameters& geometryLayerParams, + ViewProviderSketch& vp, + GeometryLayerNodes& geometrylayernodes, + DrawingParameters& drawingparameters, + GeometryLayerParameters& geometryLayerParams, CoinMapping& coinMap) : viewProvider(vp) , geometryLayerNodes(geometrylayernodes) @@ -147,15 +149,17 @@ void EditModeGeometryCoinConverter::convert(const Sketcher::GeoListFacade& geoli coinMapping.PointIdToVertexId[coinLayer].push_back(vertexCounter++); } - if (numberCurves > 0)// insert the first segment of the curve into the map + if (numberCurves > 0) {// insert the first segment of the curve into the map coinMapping.GeoElementId2SetId.emplace( std::piecewise_construct, std::forward_as_tuple(geoId, Sketcher::PointPos::none), std::forward_as_tuple(static_cast(coinMapping.CurvIdToGeoId[coinLayer].size()), coinLayer)); + } - for (int i = 0; i < numberCurves; i++) + for (int i = 0; i < numberCurves; i++) { coinMapping.CurvIdToGeoId[coinLayer].push_back(geoId); + } }; for (size_t i = 0; i < geolistfacade.geomlist.size() - 2; i++) { @@ -173,32 +177,40 @@ void EditModeGeometryCoinConverter::convert(const Sketcher::GeoListFacade& geoli EditModeGeometryCoinConverter::PointsMode::InsertSingle, EditModeGeometryCoinConverter::CurveMode::NoCurve, EditModeGeometryCoinConverter::AnalyseMode::BoundingBoxMagnitude>(geom, GeoId); - setTracking( - GeoId, coinLayer, EditModeGeometryCoinConverter::PointsMode::InsertSingle, 0); + setTracking(GeoId, + coinLayer, + EditModeGeometryCoinConverter::PointsMode::InsertSingle, + 0); } else if (type == Part::GeomLineSegment::getClassTypeId()) {// add a line convert(geom, GeoId); - setTracking( - GeoId, coinLayer, EditModeGeometryCoinConverter::PointsMode::InsertStartEnd, 1); + setTracking(GeoId, + coinLayer, + EditModeGeometryCoinConverter::PointsMode::InsertStartEnd, + 1); } else if (type.isDerivedFrom(Part::GeomConic::getClassTypeId())) {// add a closed curve conic convert(geom, GeoId); - setTracking( - GeoId, coinLayer, EditModeGeometryCoinConverter::PointsMode::InsertMidOnly, 1); + setTracking(GeoId, + coinLayer, + EditModeGeometryCoinConverter::PointsMode::InsertMidOnly, + 1); } else if (type.isDerivedFrom(Part::GeomArcOfConic::getClassTypeId())) {// add an arc of conic convert(geom, GeoId); - setTracking( - GeoId, coinLayer, EditModeGeometryCoinConverter::PointsMode::InsertStartEndMid, 1); + setTracking(GeoId, + coinLayer, + EditModeGeometryCoinConverter::PointsMode::InsertStartEndMid, + 1); arcGeoIds.push_back(GeoId); } else if (type == Part::GeomBSplineCurve::getClassTypeId()) {// add a bspline (a bounded @@ -208,8 +220,10 @@ void EditModeGeometryCoinConverter::convert(const Sketcher::GeoListFacade& geoli EditModeGeometryCoinConverter::CurveMode::OpenCurve, EditModeGeometryCoinConverter::AnalyseMode:: BoundingBoxMagnitudeAndBSplineCurvature>(geom, GeoId); - setTracking( - GeoId, coinLayer, EditModeGeometryCoinConverter::PointsMode::InsertStartEnd, 1); + setTracking(GeoId, + coinLayer, + EditModeGeometryCoinConverter::PointsMode::InsertStartEnd, + 1); bsplineGeoIds.push_back(GeoId); } } @@ -230,26 +244,29 @@ void EditModeGeometryCoinConverter::convert(const Sketcher::GeoListFacade& geoli int i = 0;// setting up the line set for (std::vector::const_iterator it = Coords[l].begin(); it != Coords[l].end(); - ++it, i++) + ++it, i++) { verts[i].setValue(it->x, it->y, ViewProviderSketchCoinAttorney::getViewOrientationFactor(viewProvider) * drawingParameters.zLowLines); + } i = 0;// setting up the indexes of the line set for (std::vector::const_iterator it = Index[l].begin(); it != Index[l].end(); - ++it, i++) + ++it, i++) { index[i] = *it; + } i = 0;// setting up the point set for (std::vector::const_iterator it = Points[l].begin(); it != Points[l].end(); - ++it, i++) + ++it, i++) { pverts[i].setValue( it->x, it->y, ViewProviderSketchCoinAttorney::getViewOrientationFactor(viewProvider) * drawingParameters.zLowPoints); + } geometryLayerNodes.CurvesCoordinate[l]->point.finishEditing(); geometryLayerNodes.CurveSet[l]->numVertices.finishEditing(); @@ -257,7 +274,8 @@ void EditModeGeometryCoinConverter::convert(const Sketcher::GeoListFacade& geoli } } -template void EditModeGeometryCoinConverter::convert(const Sketcher::GeometryFacade* geometryfacade, @@ -303,8 +321,9 @@ void EditModeGeometryCoinConverter::convert(const Sketcher::GeometryFacade* geom } else if constexpr (curvemode == CurveMode::ClosedCurve) { int numSegments = drawingParameters.curvedEdgeCountSegments; - if constexpr (std::is_same::value) + if constexpr (std::is_same::value) { numSegments *= geo->countKnots(); + } double segment = (geo->getLastParameter() - geo->getFirstParameter()) / numSegments; @@ -320,8 +339,9 @@ void EditModeGeometryCoinConverter::convert(const Sketcher::GeometryFacade* geom } else if constexpr (curvemode == CurveMode::OpenCurve) { int numSegments = drawingParameters.curvedEdgeCountSegments; - if constexpr (std::is_same::value) + if constexpr (std::is_same::value) { numSegments *= (geo->countKnots() - 1);// one less segments than knots + } double segment = (geo->getLastParameter() - geo->getFirstParameter()) / numSegments; @@ -383,22 +403,26 @@ void EditModeGeometryCoinConverter::convert(const Sketcher::GeometryFacade* geom curvaturelist[i] = 0; } - if (curvaturelist[i] > maxcurv) + if (curvaturelist[i] > maxcurv) { maxcurv = curvaturelist[i]; + } double tempf = (pointatcurvelist[i] - midp).Length(); - if (tempf > maxdisttocenterofmass) + if (tempf > maxdisttocenterofmass) { maxdisttocenterofmass = tempf; + } } double temprepscale = 0; - if (maxcurv > 0) + if (maxcurv > 0) { temprepscale = (0.5 * maxdisttocenterofmass) / maxcurv;// just a factor to make a comb reasonably visible + } - if (temprepscale > combrepscale) + if (temprepscale > combrepscale) { combrepscale = temprepscale; + } } } } diff --git a/src/Mod/Sketcher/Gui/EditModeGeometryCoinConverter.h b/src/Mod/Sketcher/Gui/EditModeGeometryCoinConverter.h index aee7eed6c4..6c6a05825f 100644 --- a/src/Mod/Sketcher/Gui/EditModeGeometryCoinConverter.h +++ b/src/Mod/Sketcher/Gui/EditModeGeometryCoinConverter.h @@ -109,7 +109,8 @@ public: * * @param drawingparameters: Parameters for drawing the overlay information */ - EditModeGeometryCoinConverter(ViewProviderSketch& vp, GeometryLayerNodes& geometrylayernodes, + EditModeGeometryCoinConverter(ViewProviderSketch& vp, + GeometryLayerNodes& geometrylayernodes, DrawingParameters& drawingparameters, GeometryLayerParameters& geometryLayerParams, CoinMapping& coinMap); diff --git a/src/Mod/Sketcher/Gui/EditModeGeometryCoinManager.cpp b/src/Mod/Sketcher/Gui/EditModeGeometryCoinManager.cpp index f71b3d653e..1787003d6c 100644 --- a/src/Mod/Sketcher/Gui/EditModeGeometryCoinManager.cpp +++ b/src/Mod/Sketcher/Gui/EditModeGeometryCoinManager.cpp @@ -52,9 +52,12 @@ using namespace Sketcher; //**************************** EditModeGeometryCoinManager class ****************************** EditModeGeometryCoinManager::EditModeGeometryCoinManager( - ViewProviderSketch& vp, DrawingParameters& drawingParams, - GeometryLayerParameters& geometryLayerParams, AnalysisResults& analysisResultStruct, - EditModeScenegraphNodes& editModeScenegraph, CoinMapping& coinMap) + ViewProviderSketch& vp, + DrawingParameters& drawingParams, + GeometryLayerParameters& geometryLayerParams, + AnalysisResults& analysisResultStruct, + EditModeScenegraphNodes& editModeScenegraph, + CoinMapping& coinMap) : viewProvider(vp) , drawingParameters(drawingParams) , geometryLayerParameters(geometryLayerParams) @@ -96,8 +99,11 @@ void EditModeGeometryCoinManager::processGeometry(const GeoListFacade& geolistfa editModeScenegraphNodes.CurveSet}; // process geometry layers - EditModeGeometryCoinConverter gcconv( - viewProvider, geometrylayernodes, drawingParameters, geometryLayerParameters, coinMapping); + EditModeGeometryCoinConverter gcconv(viewProvider, + geometrylayernodes, + drawingParameters, + geometryLayerParameters, + coinMapping); gcconv.convert(geolistfacade); @@ -118,15 +124,17 @@ void EditModeGeometryCoinManager::updateGeometryColor(const GeoListFacade& geoli // Lambdas for convenience retrieval of geometry information auto isConstructionGeom = [&geolistfacade](int GeoId) { auto geom = geolistfacade.getGeometryFacadeFromGeoId(GeoId); - if (geom) + if (geom) { return geom->getConstruction(); + } return false; }; auto isDefinedGeomPoint = [&geolistfacade](int GeoId) { auto geom = geolistfacade.getGeometryFacadeFromGeoId(GeoId); - if (geom) + if (geom) { return geom->isGeoType(Part::GeomPoint::getClassTypeId()) && !geom->getConstruction(); + } return false; }; @@ -174,8 +182,9 @@ void EditModeGeometryCoinManager::updateGeometryColor(const GeoListFacade& geoli // colors of the point set if (issketchinvalid) { - for (int i = 0; i < PtNum; i++) + for (int i = 0; i < PtNum; i++) { pcolor[i] = drawingParameters.InvalidSketchColor; + } } else { @@ -191,23 +200,29 @@ void EditModeGeometryCoinManager::updateGeometryColor(const GeoListFacade& geoli bool constrainedElement = isFullyConstraintElement(GeoId); if (isInternalAlignedGeom(GeoId)) { - if (constrainedElement) + if (constrainedElement) { pcolor[i] = drawingParameters.FullyConstraintInternalAlignmentColor; - else + } + else { pcolor[i] = drawingParameters.InternalAlignedGeoColor; + } } else { if (!isDefinedGeomPoint(GeoId)) { - if (constrainedElement) + if (constrainedElement) { pcolor[i] = drawingParameters.FullyConstraintConstructionPointColor; - else + } + else { pcolor[i] = drawingParameters.VertexColor; + } } else {// this is a defined GeomPoint - if (constrainedElement) + if (constrainedElement) { pcolor[i] = drawingParameters.FullyConstraintElementColor; - else + } + else { pcolor[i] = drawingParameters.CurveColor; + } } } } @@ -220,12 +235,15 @@ void EditModeGeometryCoinManager::updateGeometryColor(const GeoListFacade& geoli float toprendering, float midrendering, float lowrendering) { - if (drawingParameters.topRenderingGeometry == renderingtype) + if (drawingParameters.topRenderingGeometry == renderingtype) { return toprendering; - else if (drawingParameters.midRenderingGeometry == renderingtype) + } + else if (drawingParameters.midRenderingGeometry == renderingtype) { return midrendering; - else + } + else { return lowrendering; + } }; float zNormPoint = getRenderHeight(DrawingParameters::GeometryRendering::NormalGeometry, @@ -248,10 +266,12 @@ void EditModeGeometryCoinManager::updateGeometryColor(const GeoListFacade& geoli geolistfacade.getGeometryFacadeFromGeoId(coinMapping.getPointGeoId(i, l)); if (geom) { - if (geom->getConstruction()) + if (geom->getConstruction()) { pverts[i].setValue(x, y, viewOrientationFactor * zConstrPoint); - else + } + else { pverts[i].setValue(x, y, viewOrientationFactor * zNormPoint); + } } } } @@ -269,8 +289,9 @@ void EditModeGeometryCoinManager::updateGeometryColor(const GeoListFacade& geoli MultiFieldId preselectpointmfid; if (preselectcross == 0) { - if (l == 0)// cross only in layer 0 + if (l == 0) {// cross only in layer 0 pcolor[0] = drawingParameters.PreselectColor; + } } else if (preselectpoint != -1) { preselectpointmfid = coinMapping.getIndexLayer(preselectpoint); @@ -279,7 +300,8 @@ void EditModeGeometryCoinManager::updateGeometryColor(const GeoListFacade& geoli pcolor[preselectpointmfid.fieldIndex] = drawingParameters.PreselectColor; - raisePoint(pverts[preselectpointmfid.fieldIndex], viewOrientationFactor * drawingParameters.zHighlight); + raisePoint(pverts[preselectpointmfid.fieldIndex], + viewOrientationFactor * drawingParameters.zHighlight); } } @@ -301,7 +323,8 @@ void EditModeGeometryCoinManager::updateGeometryColor(const GeoListFacade& geoli ? drawingParameters.PreselectSelectedColor : drawingParameters.SelectColor; - raisePoint(pverts[pointindex.fieldIndex], viewOrientationFactor * drawingParameters.zHighlight); + raisePoint(pverts[pointindex.fieldIndex], + viewOrientationFactor * drawingParameters.zHighlight); } }); @@ -372,16 +395,20 @@ void EditModeGeometryCoinManager::updateGeometryColor(const GeoListFacade& geoli } else if (isConstructionGeom(GeoId)) { if (isInternalAlignedGeom(GeoId)) { - if (constrainedElement) + if (constrainedElement) { color[i] = drawingParameters.FullyConstraintInternalAlignmentColor; - else + } + else { color[i] = drawingParameters.InternalAlignedGeoColor; + } } else { - if (constrainedElement) + if (constrainedElement) { color[i] = drawingParameters.FullyConstraintConstructionElementColor; - else + } + else { color[i] = drawingParameters.CurveDraftColor; + } } for (int k = j; j < k + indexes; j++) { diff --git a/src/Mod/Sketcher/Gui/EditModeGeometryCoinManager.h b/src/Mod/Sketcher/Gui/EditModeGeometryCoinManager.h index b69e98df91..d029d4264c 100644 --- a/src/Mod/Sketcher/Gui/EditModeGeometryCoinManager.h +++ b/src/Mod/Sketcher/Gui/EditModeGeometryCoinManager.h @@ -86,7 +86,8 @@ class SketcherGuiExport EditModeGeometryCoinManager { public: - explicit EditModeGeometryCoinManager(ViewProviderSketch& vp, DrawingParameters& drawingParams, + explicit EditModeGeometryCoinManager(ViewProviderSketch& vp, + DrawingParameters& drawingParams, GeometryLayerParameters& geometryLayerParams, AnalysisResults& analysisResultStruct, EditModeScenegraphNodes& editModeScenegraph, diff --git a/src/Mod/Sketcher/Gui/EditModeInformationOverlayCoinConverter.cpp b/src/Mod/Sketcher/Gui/EditModeInformationOverlayCoinConverter.cpp index fbd288a8e0..df8e265d6f 100644 --- a/src/Mod/Sketcher/Gui/EditModeInformationOverlayCoinConverter.cpp +++ b/src/Mod/Sketcher/Gui/EditModeInformationOverlayCoinConverter.cpp @@ -45,7 +45,9 @@ using namespace SketcherGui; EditModeInformationOverlayCoinConverter::EditModeInformationOverlayCoinConverter( - ViewProviderSketch& vp, SoGroup* infogroup, OverlayParameters& overlayparameters, + ViewProviderSketch& vp, + SoGroup* infogroup, + OverlayParameters& overlayparameters, DrawingParameters& drawingparameters) : viewProvider(vp) , infoGroup(infogroup) @@ -123,8 +125,9 @@ void EditModeInformationOverlayCoinConverter::calculate(const Part::Geometry* ge Base::Vector3d midp = Base::Vector3d(0, 0, 0); - for (auto val : poles) + for (auto val : poles) { midp += val; + } midp /= poles.size(); @@ -142,18 +145,22 @@ void EditModeInformationOverlayCoinConverter::calculate(const Part::Geometry* ge size_t nvertices; - if (spline->isPeriodic()) + if (spline->isPeriodic()) { nvertices = poles.size() + 1; - else + } + else { nvertices = poles.size(); + } controlPolygon.coordinates.reserve(nvertices); - for (auto& v : poles) + for (auto& v : poles) { controlPolygon.coordinates.emplace_back(v); + } - if (spline->isPeriodic()) + if (spline->isPeriodic()) { controlPolygon.coordinates.emplace_back(poles[0]); + } controlPolygon.indices.push_back( nvertices);// single continuous polygon starting at index 0 @@ -245,18 +252,21 @@ void EditModeInformationOverlayCoinConverter::calculate(const Part::Geometry* ge for (int i = 0; i < ndiv; i++) { // note emplace emplaces on the position BEFORE the iterator given. - curvatureComb.coordinates.emplace_back( - pointatcurvelist[i].x, pointatcurvelist[i].y, zInfoH);// radials - curvatureComb.coordinates.emplace_back( - pointatcomblist[i].x, pointatcomblist[i].y, zInfoH);// radials + curvatureComb.coordinates.emplace_back(pointatcurvelist[i].x, + pointatcurvelist[i].y, + zInfoH);// radials + curvatureComb.coordinates.emplace_back(pointatcomblist[i].x, + pointatcomblist[i].y, + zInfoH);// radials curvatureComb.indices.emplace_back(2);// line } - for (int i = 0; i < ndiv; i++) + for (int i = 0; i < ndiv; i++) { curvatureComb.coordinates.emplace_back(pointatcomblist[i].x, pointatcomblist[i].y, zInfoH);// // comb endpoint closing segment + } curvatureComb.indices.emplace_back(ndiv);// Comb line } @@ -284,8 +294,11 @@ void EditModeInformationOverlayCoinConverter::calculate(const Part::Geometry* ge for (size_t i = 0; i < poles.size(); i++) { poleWeights.positions.emplace_back(poles[i]); - QString WeightString = QString::fromLatin1("[%1]").arg( - weights[i], 0, 'f', Base::UnitsApi::getDecimals()); + QString WeightString = + QString::fromLatin1("[%1]").arg(weights[i], + 0, + 'f', + Base::UnitsApi::getDecimals()); poleWeights.strings.emplace_back(WeightString.toStdString()); } @@ -297,10 +310,12 @@ template void EditModeInformationOverlayCoinConverter::addUpdateNode(const Result& result) { - if (overlayParameters.rebuildInformationLayer) + if (overlayParameters.rebuildInformationLayer) { addNode(result); - else + } + else { updateNode(result); + } } template @@ -338,14 +353,16 @@ void EditModeInformationOverlayCoinConverter::setPolygon(const Result& result, int32_t* index = polygonlineset->numVertices.startEditing(); SbVec3f* vts = polygoncoords->point.startEditing(); - for (size_t i = 0; i < result.coordinates.size(); i++) + for (size_t i = 0; i < result.coordinates.size(); i++) { vts[i].setValue(result.coordinates[i].x, result.coordinates[i].y, ViewProviderSketchCoinAttorney::getViewOrientationFactor(viewProvider) * drawingParameters.zInfo); + } - for (size_t i = 0; i < result.indices.size(); i++) + for (size_t i = 0; i < result.indices.size(); i++) { index[i] = result.indices[i]; + } polygoncoords->point.finishEditing(); polygonlineset->numVertices.finishEditing(); @@ -361,8 +378,9 @@ void EditModeInformationOverlayCoinConverter::setText(const std::string& string, else { assert(line > 1); SoMFString label; - for (int l = 0; l < (line - 1); l++) + for (int l = 0; l < (line - 1); l++) { label.set1Value(l, SbString("")); + } label.set1Value(line - 1, SbString(string.c_str())); text->string = label; @@ -426,10 +444,12 @@ void EditModeInformationOverlayCoinConverter::addNode(const Result& result) // // This could be made into a more generic form, but it is probably not worth the effort // at this time. - if constexpr (Result::calculationType == CalculationType::BSplinePoleWeight) + if constexpr (Result::calculationType == CalculationType::BSplinePoleWeight) { setText<2>(result.strings[i], text); - else + } + else { setText(result.strings[i], text); + } sep->addChild(mat); sep->addChild(font); @@ -487,9 +507,10 @@ void EditModeInformationOverlayCoinConverter::updateNode(const Result& result) for (size_t i = 0; i < result.strings.size(); i++) { SoSwitch* sw = static_cast(infoGroup->getChild(nodeId)); - if (overlayParameters.visibleInformationChanged) + if (overlayParameters.visibleInformationChanged) { sw->whichChild = isVisible() ? SO_SWITCH_ALL : SO_SWITCH_NONE; + } SoSeparator* sep = static_cast(sw->getChild(0)); @@ -507,14 +528,16 @@ void EditModeInformationOverlayCoinConverter::updateNode(const Result& result) // // This could be made into a more generic form, but it is probably not worth the effort // at this time. - if constexpr (Result::calculationType == CalculationType::BSplinePoleWeight) + if constexpr (Result::calculationType == CalculationType::BSplinePoleWeight) { setText<2>(result.strings[i], static_cast( sep->getChild(static_cast(TextNodePosition::TextInformation)))); - else + } + else { setText(result.strings[i], static_cast( sep->getChild(static_cast(TextNodePosition::TextInformation)))); + } nodeId++; } @@ -523,8 +546,9 @@ void EditModeInformationOverlayCoinConverter::updateNode(const Result& result) SoSwitch* sw = static_cast(infoGroup->getChild(nodeId)); - if (overlayParameters.visibleInformationChanged) + if (overlayParameters.visibleInformationChanged) { sw->whichChild = isVisible() ? SO_SWITCH_ALL : SO_SWITCH_NONE; + } SoSeparator* sep = static_cast(sw->getChild(0)); diff --git a/src/Mod/Sketcher/Gui/EditModeInformationOverlayCoinConverter.h b/src/Mod/Sketcher/Gui/EditModeInformationOverlayCoinConverter.h index c74f636228..7dd7e0cc58 100644 --- a/src/Mod/Sketcher/Gui/EditModeInformationOverlayCoinConverter.h +++ b/src/Mod/Sketcher/Gui/EditModeInformationOverlayCoinConverter.h @@ -154,7 +154,8 @@ public: * @param overlayparameters: Parameters for controlling the overlay * @param drawingparameters: Parameters for drawing the overlay information */ - EditModeInformationOverlayCoinConverter(ViewProviderSketch& vp, SoGroup* infogroup, + EditModeInformationOverlayCoinConverter(ViewProviderSketch& vp, + SoGroup* infogroup, OverlayParameters& overlayparameters, DrawingParameters& drawingparameters); diff --git a/src/Mod/Sketcher/Gui/PropertyConstraintListItem.cpp b/src/Mod/Sketcher/Gui/PropertyConstraintListItem.cpp index d428ac6a96..56c9eae2b0 100644 --- a/src/Mod/Sketcher/Gui/PropertyConstraintListItem.cpp +++ b/src/Mod/Sketcher/Gui/PropertyConstraintListItem.cpp @@ -54,8 +54,9 @@ QVariant PropertyConstraintListItem::toString(const QVariant& prop) const QTextStream out(&str); out << "["; for (QList::const_iterator it = value.begin(); it != value.end(); ++it) { - if (it != value.begin()) + if (it != value.begin()) { out << ";"; + } out << it->getUserString(); } out << "]"; @@ -146,8 +147,9 @@ void PropertyConstraintListItem::assignProperty(const App::Property* prop) // Hint: When renaming a constraint that was unnamed before then it can happen that // a constraint appears twice in the property editor, one time in this group and a // second time inside the Unnamed group - if (!prop->getTypeId().isDerivedFrom(Sketcher::PropertyConstraintList::getClassTypeId())) + if (!prop->getTypeId().isDerivedFrom(Sketcher::PropertyConstraintList::getClassTypeId())) { return; + } const Sketcher::PropertyConstraintList* list = static_cast(prop); @@ -199,8 +201,9 @@ void PropertyConstraintListItem::assignProperty(const App::Property* prop) } else { // search inside this item - if (namedIndex < numNamed) + if (namedIndex < numNamed) { child = dynamic_cast(this->child(namedIndex)); + } if (!child) { child = static_cast(PropertyUnitItem::create()); @@ -344,8 +347,9 @@ bool PropertyConstraintListItem::event(QEvent* ev) QString internalName = QString::fromLatin1("Constraint%1").arg(id + 1); if (internalName == propName) { double datum = quant.getValue(); - if ((*it)->Type == Sketcher::Angle) + if ((*it)->Type == Sketcher::Angle) { datum = Base::toRadians(datum); + } std::unique_ptr copy((*it)->clone()); copy->setValue(datum); item->set1Value(id, copy.get()); @@ -365,7 +369,8 @@ void PropertyConstraintListItem::setValue(const QVariant& value) Q_UNUSED(value); } -QWidget* PropertyConstraintListItem::createEditor(QWidget* parent, const QObject* receiver, +QWidget* PropertyConstraintListItem::createEditor(QWidget* parent, + const QObject* receiver, const char* method) const { Q_UNUSED(receiver); diff --git a/src/Mod/Sketcher/Gui/PropertyConstraintListItem.h b/src/Mod/Sketcher/Gui/PropertyConstraintListItem.h index 23315b01cc..04b7867948 100644 --- a/src/Mod/Sketcher/Gui/PropertyConstraintListItem.h +++ b/src/Mod/Sketcher/Gui/PropertyConstraintListItem.h @@ -38,8 +38,8 @@ class PropertyConstraintListItem: public Gui::PropertyEditor::PropertyItem ~PropertyConstraintListItem() override; void assignProperty(const App::Property* prop) override; - QWidget* createEditor(QWidget* parent, const QObject* receiver, - const char* method) const override; + QWidget* + createEditor(QWidget* parent, const QObject* receiver, const char* method) const override; void setEditorData(QWidget* editor, const QVariant& data) const override; QVariant editorData(QWidget* editor) const override; diff --git a/src/Mod/Sketcher/Gui/Resources/translations/Sketcher_fil.ts b/src/Mod/Sketcher/Gui/Resources/translations/Sketcher_fil.ts index 0e6ab84590..1c4a12e0fe 100644 --- a/src/Mod/Sketcher/Gui/Resources/translations/Sketcher_fil.ts +++ b/src/Mod/Sketcher/Gui/Resources/translations/Sketcher_fil.ts @@ -301,7 +301,7 @@ Rectangle - + Taluhaba @@ -5625,7 +5625,7 @@ Select the method to attach this sketch to selected objects. Sketch with a support face cannot be reoriented. Do you want to detach it from the support? - Ang sketch ay may suporta ng face ay hindi pwedeng i-reorient. + Ang sketch ay may suporta ng face ay hindi pwedeng i-reorient. Gusto mo bang tanggalin ito mula sa suporta? diff --git a/src/Mod/Sketcher/Gui/Resources/translations/Sketcher_lt.ts b/src/Mod/Sketcher/Gui/Resources/translations/Sketcher_lt.ts index fbed51202a..ec31fd1b33 100644 --- a/src/Mod/Sketcher/Gui/Resources/translations/Sketcher_lt.ts +++ b/src/Mod/Sketcher/Gui/Resources/translations/Sketcher_lt.ts @@ -3094,7 +3094,7 @@ Priimtini deriniai: dvi kreivės; galinis taškas ir kreivė; du galiniai taška Currently internal geometry is only supported for ellipse or arc of ellipse. The last selected element must be an ellipse or an arc of ellipse. - Vidinė geometrija yra naudojama tik elipsėms ir elipsių lankams. Elipsė ar elipsės lankas turi būti pasirinkti + Vidinė geometrija yra naudojama tik elipsėms ir elipsių lankams. Elipsė ar elipsės lankas turi būti pasirinkti žymėjimo pabaigoje. diff --git a/src/Mod/Sketcher/Gui/SketchOrientationDialog.cpp b/src/Mod/Sketcher/Gui/SketchOrientationDialog.cpp index 5c7d84e3b8..7d53d70fd1 100644 --- a/src/Mod/Sketcher/Gui/SketchOrientationDialog.cpp +++ b/src/Mod/Sketcher/Gui/SketchOrientationDialog.cpp @@ -95,22 +95,28 @@ void SketchOrientationDialog::onPreview() std::string icon; bool reverse = ui->Reverse_checkBox->isChecked(); if (ui->XY_radioButton->isChecked()) { - if (reverse) + if (reverse) { icon = "view-bottom"; - else + } + else { icon = "view-top"; + } } else if (ui->XZ_radioButton->isChecked()) { - if (reverse) + if (reverse) { icon = "view-rear"; - else + } + else { icon = "view-front"; + } } else if (ui->YZ_radioButton->isChecked()) { - if (reverse) + if (reverse) { icon = "view-left"; - else + } + else { icon = "view-right"; + } } ui->previewLabel->setPixmap( diff --git a/src/Mod/Sketcher/Gui/SketcherSettings.cpp b/src/Mod/Sketcher/Gui/SketcherSettings.cpp index 17b4deb15f..152afdd05b 100644 --- a/src/Mod/Sketcher/Gui/SketcherSettings.cpp +++ b/src/Mod/Sketcher/Gui/SketcherSettings.cpp @@ -67,33 +67,36 @@ void SketcherSettings::saveSettings() ui->checkBoxNotifyConstraintSubstitutions->onSave(); ui->checkBoxAutoRemoveRedundants->onSave(); - enum { + enum + { DimensionSingleTool, DimensionSeparateTools, DimensionBoth }; // Dimensioning constraints mode - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher/dimensioning"); + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/Mod/Sketcher/dimensioning"); bool singleTool = true; bool SeparatedTools = false; int index = ui->dimensioningMode->currentIndex(); switch (index) { - case DimensionSeparateTools: - singleTool = false; - SeparatedTools = true; - break; - case DimensionBoth: - singleTool = true; - SeparatedTools = true; - break; + case DimensionSeparateTools: + singleTool = false; + SeparatedTools = true; + break; + case DimensionBoth: + singleTool = true; + SeparatedTools = true; + break; } hGrp->SetBool("SingleDimensioningTool", singleTool); hGrp->SetBool("SeparatedDimensioningTools", SeparatedTools); ui->radiusDiameterMode->setEnabled(index != 1); - enum { + enum + { DimensionAutoRadiusDiam, DimensionDiameter, DimensionRadius @@ -103,14 +106,14 @@ void SketcherSettings::saveSettings() bool Radius = true; index = ui->radiusDiameterMode->currentIndex(); switch (index) { - case DimensionDiameter: - Diameter = true; - Radius = false; - break; - case DimensionRadius: - Diameter = false; - Radius = true; - break; + case DimensionDiameter: + Diameter = true; + Radius = false; + break; + case DimensionRadius: + Diameter = false; + Radius = true; + break; } hGrp->SetBool("DimensioningDiameter", Diameter); hGrp->SetBool("DimensioningRadius", Radius); @@ -131,12 +134,16 @@ void SketcherSettings::loadSettings() ui->dimensioningMode->addItem(tr("Separated tools")); ui->dimensioningMode->addItem(tr("Both")); - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher/dimensioning"); + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/Mod/Sketcher/dimensioning"); bool singleTool = hGrp->GetBool("SingleDimensioningTool", true); bool SeparatedTools = hGrp->GetBool("SeparatedDimensioningTools", false); int index = SeparatedTools ? (singleTool ? 2 : 1) : 0; ui->dimensioningMode->setCurrentIndex(index); - connect(ui->dimensioningMode, QOverload::of(&QComboBox::currentIndexChanged), this, &SketcherSettings::dimensioningModeChanged); + connect(ui->dimensioningMode, + QOverload::of(&QComboBox::currentIndexChanged), + this, + &SketcherSettings::dimensioningModeChanged); ui->radiusDiameterMode->setEnabled(index != 1); @@ -248,13 +255,15 @@ void SketcherSettingsGrid::loadSettings() "User parameter:BaseApp/Preferences/Mod/Sketcher/General"); int pattern = hGrp->GetInt("GridLinePattern", 0x0f0f); int index = ui->gridLinePattern->findData(QVariant(pattern)); - if (index < 0) + if (index < 0) { index = 1; + } ui->gridLinePattern->setCurrentIndex(index); pattern = hGrp->GetInt("GridDivLinePattern", 0xffff); index = ui->gridDivLinePattern->findData(QVariant(pattern)); - if (index < 0) + if (index < 0) { index = 0; + } ui->gridDivLinePattern->setCurrentIndex(index); } @@ -279,8 +288,10 @@ SketcherSettingsDisplay::SketcherSettingsDisplay(QWidget* parent) { ui->setupUi(this); - connect( - ui->btnTVApply, &QPushButton::clicked, this, &SketcherSettingsDisplay::onBtnTVApplyClicked); + connect(ui->btnTVApply, + &QPushButton::clicked, + this, + &SketcherSettingsDisplay::onBtnTVApplyClicked); } /** diff --git a/src/Mod/Sketcher/Gui/SnapManager.cpp b/src/Mod/Sketcher/Gui/SnapManager.cpp index d12793cf29..f874b755be 100644 --- a/src/Mod/Sketcher/Gui/SnapManager.cpp +++ b/src/Mod/Sketcher/Gui/SnapManager.cpp @@ -367,8 +367,9 @@ bool SnapManager::snapToArcMiddle(Base::Vector3d& pointToOverride, const Part::G double u, v; arc->getRange(u, v, true); - if (v < u) + if (v < u) { v += 2 * M_PI; + } double angle = v - u; int revert = angle < M_PI ? 1 : -1; diff --git a/src/Mod/Sketcher/Gui/TaskDlgEditSketch.cpp b/src/Mod/Sketcher/Gui/TaskDlgEditSketch.cpp index 02a530d51f..b73831c91c 100644 --- a/src/Mod/Sketcher/Gui/TaskDlgEditSketch.cpp +++ b/src/Mod/Sketcher/Gui/TaskDlgEditSketch.cpp @@ -58,14 +58,18 @@ TaskDlgEditSketch::TaskDlgEditSketch(ViewProviderSketch* sketchView) Content.push_back(Constraints); Content.push_back(Elements); - if (!hGrp->GetBool("ExpandedMessagesWidget", true)) + if (!hGrp->GetBool("ExpandedMessagesWidget", true)) { Messages->hideGroupBox(); - if (!hGrp->GetBool("ExpandedSolverAdvancedWidget", false)) + } + if (!hGrp->GetBool("ExpandedSolverAdvancedWidget", false)) { SolverAdvanced->hideGroupBox(); - if (!hGrp->GetBool("ExpandedConstraintsWidget", true)) + } + if (!hGrp->GetBool("ExpandedConstraintsWidget", true)) { Constraints->hideGroupBox(); - if (!hGrp->GetBool("ExpandedElementsWidget", true)) + } + if (!hGrp->GetBool("ExpandedElementsWidget", true)) { Elements->hideGroupBox(); + } } TaskDlgEditSketch::~TaskDlgEditSketch() @@ -73,8 +77,9 @@ TaskDlgEditSketch::~TaskDlgEditSketch() // to make sure to delete the advanced solver panel // it must be part to the 'Content' array std::vector::iterator it = std::find(Content.begin(), Content.end(), SolverAdvanced); - if (it == Content.end()) + if (it == Content.end()) { Content.push_back(SolverAdvanced); + } } //==== calls from the TaskView =============================================================== @@ -105,10 +110,12 @@ bool TaskDlgEditSketch::reject() } std::string document = getDocumentName();// needed because resetEdit() deletes this instance - Gui::Command::doCommand( - Gui::Command::Gui, "Gui.getDocument('%s').resetEdit()", document.c_str()); - Gui::Command::doCommand( - Gui::Command::Doc, "App.getDocument('%s').recompute()", document.c_str()); + Gui::Command::doCommand(Gui::Command::Gui, + "Gui.getDocument('%s').resetEdit()", + document.c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.getDocument('%s').recompute()", + document.c_str()); return true; } diff --git a/src/Mod/Sketcher/Gui/TaskSketcherMessages.h b/src/Mod/Sketcher/Gui/TaskSketcherMessages.h index 881d79b9a5..c28454599f 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherMessages.h +++ b/src/Mod/Sketcher/Gui/TaskSketcherMessages.h @@ -49,7 +49,9 @@ public: explicit TaskSketcherMessages(ViewProviderSketch* sketchView); ~TaskSketcherMessages() override; - void slotSetUp(const QString& state, const QString& msg, const QString& link, + void slotSetUp(const QString& state, + const QString& msg, + const QString& link, const QString& linkText); private: diff --git a/src/Mod/Sketcher/Gui/TaskSketcherSolverAdvanced.cpp b/src/Mod/Sketcher/Gui/TaskSketcherSolverAdvanced.cpp index 595285ff3f..6612448546 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherSolverAdvanced.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherSolverAdvanced.cpp @@ -54,7 +54,9 @@ using namespace SketcherGui; using namespace Gui::TaskView; TaskSketcherSolverAdvanced::TaskSketcherSolverAdvanced(ViewProviderSketch* sketchView) - : TaskBox(Gui::BitmapFactory().pixmap("document-new"), tr("Advanced solver control"), true, + : TaskBox(Gui::BitmapFactory().pixmap("document-new"), + tr("Advanced solver control"), + true, nullptr) , sketchView(sketchView) , ui(new Ui_TaskSketcherSolverAdvanced) @@ -177,10 +179,12 @@ void TaskSketcherSolverAdvanced::updateDefaultMethodParameters() int currentindex = ui->comboBoxDefaultSolver->currentIndex(); int redundantcurrentindex = ui->comboBoxRedundantDefaultSolver->currentIndex(); - if (redundantcurrentindex == 2 || currentindex == 2) + if (redundantcurrentindex == 2 || currentindex == 2) { ui->comboBoxDogLegGaussStep->setEnabled(true); - else + } + else { ui->comboBoxDogLegGaussStep->setEnabled(false); + } switch (currentindex) { case 0:// BFGS @@ -276,10 +280,12 @@ void TaskSketcherSolverAdvanced::updateRedundantMethodParameters() int currentindex = ui->comboBoxDefaultSolver->currentIndex(); int redundantcurrentindex = ui->comboBoxRedundantDefaultSolver->currentIndex(); - if (redundantcurrentindex == 2 || currentindex == 2) + if (redundantcurrentindex == 2 || currentindex == 2) { ui->comboBoxDogLegGaussStep->setEnabled(true); - else + } + else { ui->comboBoxDogLegGaussStep->setEnabled(false); + } switch (redundantcurrentindex) { case 0:// BFGS diff --git a/src/Mod/Sketcher/Gui/TaskSketcherValidation.cpp b/src/Mod/Sketcher/Gui/TaskSketcherValidation.cpp index c10b9793c7..0db1bb55d6 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherValidation.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherValidation.cpp @@ -107,10 +107,14 @@ void SketcherValidation::setupConnections() &QPushButton::clicked, this, &SketcherValidation::onFixConstraintClicked); - connect( - ui->findReversed, &QPushButton::clicked, this, &SketcherValidation::onFindReversedClicked); - connect( - ui->swapReversed, &QPushButton::clicked, this, &SketcherValidation::onSwapReversedClicked); + connect(ui->findReversed, + &QPushButton::clicked, + this, + &SketcherValidation::onFindReversedClicked); + connect(ui->swapReversed, + &QPushButton::clicked, + this, + &SketcherValidation::onSwapReversedClicked); connect(ui->orientLockEnable, &QPushButton::clicked, this, @@ -143,8 +147,9 @@ void SketcherValidation::changeEvent(QEvent* e) void SketcherValidation::onFindButtonClicked() { - if (sketch.expired()) + if (sketch.expired()) { return; + } double prec = Precision::Confusion(); bool ok; @@ -163,7 +168,8 @@ void SketcherValidation::onFindButtonClicked() } sketchAnalyser.detectMissingPointOnPointConstraints( - prec, !ui->checkBoxIgnoreConstruction->isChecked()); + prec, + !ui->checkBoxIgnoreConstruction->isChecked()); std::vector& vertexConstraints = sketchAnalyser.getMissingPointOnPointConstraints(); @@ -177,8 +183,9 @@ void SketcherValidation::onFindButtonClicked() hidePoints(); if (vertexConstraints.empty()) { - Gui::TranslatedNotification( - *sketch, tr("No missing coincidences"), tr("No missing coincidences found")); + Gui::TranslatedNotification(*sketch, + tr("No missing coincidences"), + tr("No missing coincidences found")); ui->fixButton->setEnabled(false); } @@ -195,8 +202,9 @@ void SketcherValidation::onFindButtonClicked() void SketcherValidation::onFixButtonClicked() { - if (sketch.expired()) + if (sketch.expired()) { return; + } // undo command open App::Document* doc = sketch->getDocument(); @@ -215,32 +223,37 @@ void SketcherValidation::onFixButtonClicked() void SketcherValidation::onHighlightButtonClicked() { - if (sketch.expired()) + if (sketch.expired()) { return; + } std::vector points; points = sketchAnalyser.getOpenVertices(); hidePoints(); - if (!points.empty()) + if (!points.empty()) { showPoints(points); + } } void SketcherValidation::onFindConstraintClicked() { - if (sketch.expired()) + if (sketch.expired()) { return; + } if (sketch->evaluateConstraints()) { - Gui::TranslatedNotification( - *sketch, tr("No invalid constraints"), tr("No invalid constraints found")); + Gui::TranslatedNotification(*sketch, + tr("No invalid constraints"), + tr("No invalid constraints found")); ui->fixConstraint->setEnabled(false); } else { - Gui::TranslatedUserError( - *sketch, tr("Invalid constraints"), tr("Invalid constraints found")); + Gui::TranslatedUserError(*sketch, + tr("Invalid constraints"), + tr("Invalid constraints found")); ui->fixConstraint->setEnabled(true); } @@ -248,8 +261,9 @@ void SketcherValidation::onFindConstraintClicked() void SketcherValidation::onFixConstraintClicked() { - if (sketch.expired()) + if (sketch.expired()) { return; + } sketch->validateConstraints(); ui->fixConstraint->setEnabled(false); @@ -257,8 +271,9 @@ void SketcherValidation::onFixConstraintClicked() void SketcherValidation::onFindReversedClicked() { - if (sketch.expired()) + if (sketch.expired()) { return; + } std::vector points; const std::vector& geom = sketch->getExternalGeometry(); @@ -314,8 +329,9 @@ void SketcherValidation::onFindReversedClicked() void SketcherValidation::onSwapReversedClicked() { - if (sketch.expired()) + if (sketch.expired()) { return; + } App::Document* doc = sketch->getDocument(); doc->openTransaction("Sketch porting"); @@ -334,8 +350,9 @@ void SketcherValidation::onSwapReversedClicked() void SketcherValidation::onOrientLockEnableClicked() { - if (sketch.expired()) + if (sketch.expired()) { return; + } App::Document* doc = sketch->getDocument(); doc->openTransaction("Constraint orientation lock"); @@ -354,8 +371,9 @@ void SketcherValidation::onOrientLockEnableClicked() void SketcherValidation::onOrientLockDisableClicked() { - if (sketch.expired()) + if (sketch.expired()) { return; + } App::Document* doc = sketch->getDocument(); doc->openTransaction("Constraint orientation unlock"); @@ -375,8 +393,9 @@ void SketcherValidation::onOrientLockDisableClicked() void SketcherValidation::onDelConstrExtrClicked() { - if (sketch.expired()) + if (sketch.expired()) { return; + } int reply; reply = QMessageBox::question( @@ -387,8 +406,9 @@ void SketcherValidation::onDelConstrExtrClicked() "you want to delete the constraints?"), QMessageBox::No | QMessageBox::Yes, QMessageBox::No); - if (reply != QMessageBox::Yes) + if (reply != QMessageBox::Yes) { return; + } App::Document* doc = sketch->getDocument(); doc->openTransaction("Delete constraints"); @@ -461,21 +481,24 @@ void SketcherValidation::hidePoints() void SketcherValidation::onFindDegeneratedClicked() { - if (sketch.expired()) + if (sketch.expired()) { return; + } double prec = Precision::Confusion(); int count = sketchAnalyser.detectDegeneratedGeometries(prec); if (count == 0) { - Gui::TranslatedNotification( - *sketch, tr("No degenerated geometry"), tr("No degenerated geometry found")); + Gui::TranslatedNotification(*sketch, + tr("No degenerated geometry"), + tr("No degenerated geometry found")); ui->fixDegenerated->setEnabled(false); } else { - Gui::TranslatedUserWarning( - *sketch, tr("Degenerated geometry"), tr("%1 degenerated geometry found").arg(count)); + Gui::TranslatedUserWarning(*sketch, + tr("Degenerated geometry"), + tr("%1 degenerated geometry found").arg(count)); ui->fixDegenerated->setEnabled(true); } @@ -483,8 +506,9 @@ void SketcherValidation::onFindDegeneratedClicked() void SketcherValidation::onFixDegeneratedClicked() { - if (sketch.expired()) + if (sketch.expired()) { return; + } // undo command open App::Document* doc = sketch->getDocument(); diff --git a/src/Mod/Sketcher/Gui/Utils.cpp b/src/Mod/Sketcher/Gui/Utils.cpp index ebab5ccd39..7c8d11227f 100644 --- a/src/Mod/Sketcher/Gui/Utils.cpp +++ b/src/Mod/Sketcher/Gui/Utils.cpp @@ -57,14 +57,17 @@ bool SketcherGui::tryAutoRecompute(Sketcher::SketchObject* obj, bool& autoremove // 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) + if (autoRecompute) { Gui::Command::updateActive(); + } autoremoveredundants = autoRemoveRedundants; @@ -98,8 +101,9 @@ std::string SketcherGui::getStrippedPythonExceptionString(const Base::Exception& if (msg.length() > 26 && msg.substr(0, 26) == "FreeCAD exception thrown (") { return msg.substr(26, msg.length() - 27); } - else + else { return msg; + } } bool SketcherGui::ReleaseHandler(Gui::Document* doc) @@ -121,8 +125,10 @@ 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; @@ -134,12 +140,15 @@ void SketcherGui::getIdsFromName(const std::string& name, const Sketcher::Sketch 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") + } + 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); @@ -176,65 +185,80 @@ std::vector SketcherGui::getGeoIdsOfEdgesFromNames(const Sketcher::SketchOb bool SketcherGui::checkBothExternal(int GeoId1, int GeoId2) { - if (GeoId1 == GeoEnum::GeoUndef || GeoId2 == GeoEnum::GeoUndef) + if (GeoId1 == GeoEnum::GeoUndef || GeoId2 == GeoEnum::GeoUndef) { return false; - else + } + else { return (GeoId1 < 0 && GeoId2 < 0); + } } bool SketcherGui::isPointOrSegmentFixed(const Sketcher::SketchObject* Obj, int GeoId) { const std::vector& vals = Obj->Constraints.getValues(); - if (GeoId == GeoEnum::GeoUndef) + if (GeoId == GeoEnum::GeoUndef) { return false; - else + } + else { return checkConstraint(vals, Sketcher::Block, GeoId, Sketcher::PointPos::none) || GeoId <= Sketcher::GeoEnum::RtPnt; + } } -bool SketcherGui::areBothPointsOrSegmentsFixed(const Sketcher::SketchObject* Obj, int GeoId1, +bool SketcherGui::areBothPointsOrSegmentsFixed(const Sketcher::SketchObject* Obj, + int GeoId1, int GeoId2) { const std::vector& vals = Obj->Constraints.getValues(); - if (GeoId1 == GeoEnum::GeoUndef || GeoId2 == GeoEnum::GeoUndef) + if (GeoId1 == GeoEnum::GeoUndef || GeoId2 == GeoEnum::GeoUndef) { return false; - else + } + 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)); + } } -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& vals = Obj->Constraints.getValues(); - if (GeoId1 == GeoEnum::GeoUndef || GeoId2 == GeoEnum::GeoUndef || GeoId3 == GeoEnum::GeoUndef) + if (GeoId1 == GeoEnum::GeoUndef || GeoId2 == GeoEnum::GeoUndef || GeoId3 == GeoEnum::GeoUndef) { return false; - else + } + 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)); + } } bool SketcherGui::isSimpleVertex(const Sketcher::SketchObject* Obj, int GeoId, PointPos PosId) { if (PosId == Sketcher::PointPos::start - && (GeoId == Sketcher::GeoEnum::HAxis || GeoId == Sketcher::GeoEnum::VAxis)) + && (GeoId == Sketcher::GeoEnum::HAxis || GeoId == Sketcher::GeoEnum::VAxis)) { return true; + } const Part::Geometry* geo = Obj->getGeometry(GeoId); - if (geo->getTypeId() == Part::GeomPoint::getClassTypeId()) + if (geo->getTypeId() == Part::GeomPoint::getClassTypeId()) { return true; - else if (PosId == Sketcher::PointPos::mid) + } + else if (PosId == Sketcher::PointPos::mid) { return true; - else + } + else { return false; + } } bool SketcherGui::isBsplineKnot(const Sketcher::SketchObject* Obj, int GeoId) @@ -243,24 +267,29 @@ 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, +bool SketcherGui::isBsplineKnotOrEndPoint(const Sketcher::SketchObject* Obj, + int GeoId, Sketcher::PointPos PosId) { // check first using geometry facade - if (isBsplineKnot(Obj, GeoId)) + if (isBsplineKnot(Obj, GeoId)) { return true; + } 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)) + && (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 @@ -279,8 +308,9 @@ bool SketcherGui::IsPointAlreadyOnCurve(int GeoIdCurve, int GeoIdPoint, const std::vector& constraints = Obj->Constraints.getValues(); for (const auto& constraint : constraints) { if (constraint->Type == Sketcher::ConstraintType::InternalAlignment - && constraint->First == GeoIdPoint && constraint->Second == GeoIdCurve) + && constraint->First == GeoIdPoint && constraint->Second == GeoIdCurve) { return true; + } } } } @@ -293,8 +323,9 @@ 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") } @@ -308,7 +339,9 @@ bool SketcherGui::isBsplinePole(const Sketcher::SketchObject* Obj, int GeoId) } bool SketcherGui::checkConstraint(const std::vector& vals, - ConstraintType type, int geoid, PointPos pos) + ConstraintType type, + int geoid, + PointPos pos) { for (std::vector::const_iterator itc = vals.begin(); itc != vals.end(); ++itc) { @@ -333,7 +366,8 @@ double SketcherGui::GetPointAngle(const Base::Vector2d& p1, const Base::Vector2d // Set the two points on circles at minimal distance // in concentric case set points on relative X axis void SketcherGui::GetCirclesMinimalDistance(const Part::GeomCircle* circle1, - const Part::GeomCircle* circle2, Base::Vector3d& point1, + const Part::GeomCircle* circle2, + Base::Vector3d& point1, Base::Vector3d& point2) { double radius1 = circle1->getRadius(); @@ -422,12 +456,14 @@ bool SketcherGui::isSketcherBSplineActive(Gui::Document* doc, bool actsOnSelecti && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { if (static_cast(doc->getInEdit())->getSketchMode() == ViewProviderSketch::STATUS_NONE) { - if (!actsOnSelection) + if (!actsOnSelection) { return true; + } else if (Gui::Selection().countObjectsOfType( Sketcher::SketchObject::getClassTypeId()) - > 0) + > 0) { return true; + } } } } @@ -484,8 +520,9 @@ void SketcherGui::removeRedundantHorizontalVertical(Sketcher::SketchObject* pske geoId1iterator = coincidents.find(-1); if (geoId1iterator != coincidents.end()) { - if ((*geoId1iterator).second == Sketcher::PointPos::start) + if ((*geoId1iterator).second == Sketcher::PointPos::start) { orig = true; + } } } else {// it may be that there is no constraint at all, but there is external @@ -526,7 +563,8 @@ void SketcherGui::removeRedundantHorizontalVertical(Sketcher::SketchObject* pske } void SketcherGui::ConstraintToAttachment(Sketcher::GeoElementId element, - Sketcher::GeoElementId attachment, double distance, + Sketcher::GeoElementId attachment, + double distance, App::DocumentObject* obj) { if (distance == 0.) { diff --git a/src/Mod/Sketcher/Gui/Utils.h b/src/Mod/Sketcher/Gui/Utils.h index 1ce611e270..2b560a7e3e 100644 --- a/src/Mod/Sketcher/Gui/Utils.h +++ b/src/Mod/Sketcher/Gui/Utils.h @@ -75,7 +75,9 @@ bool ReleaseHandler(Gui::Document* doc); std::string getStrippedPythonExceptionString(const Base::Exception&); -void getIdsFromName(const std::string& name, const Sketcher::SketchObject* Obj, int& GeoId, +void getIdsFromName(const std::string& name, + const Sketcher::SketchObject* Obj, + int& GeoId, Sketcher::PointPos& PosId); /// Returns ONLY the geometry elements when the "Edge" is selected (including GeomPoints) @@ -88,7 +90,9 @@ bool isPointOrSegmentFixed(const Sketcher::SketchObject* Obj, int GeoId); bool areBothPointsOrSegmentsFixed(const Sketcher::SketchObject* Obj, int GeoId1, int GeoId2); -bool areAllPointsOrSegmentsFixed(const Sketcher::SketchObject* Obj, int GeoId1, int GeoId2, +bool areAllPointsOrSegmentsFixed(const Sketcher::SketchObject* Obj, + int GeoId1, + int GeoId2, int GeoId3); bool inline isVertex(int GeoId, Sketcher::PointPos PosId); @@ -101,10 +105,13 @@ bool isSimpleVertex(const Sketcher::SketchObject* Obj, int GeoId, Sketcher::Poin bool isBsplineKnot(const Sketcher::SketchObject* Obj, int GeoId); /// Checks if the (`GeoId`, `PosId`) pair corresponds to a B-Spline knot, including first and last /// knots -bool isBsplineKnotOrEndPoint(const Sketcher::SketchObject* Obj, int GeoId, +bool isBsplineKnotOrEndPoint(const Sketcher::SketchObject* Obj, + int GeoId, Sketcher::PointPos PosId); -bool IsPointAlreadyOnCurve(int GeoIdCurve, int GeoIdPoint, Sketcher::PointPos PosIdPoint, +bool IsPointAlreadyOnCurve(int GeoIdCurve, + int GeoIdPoint, + Sketcher::PointPos PosIdPoint, Sketcher::SketchObject* Obj); bool isBsplinePole(const Part::Geometry* geo); @@ -113,8 +120,10 @@ bool isBsplinePole(const Sketcher::SketchObject* Obj, int GeoId); /// Checks whether there is a constraint of the given type with a First element geoid and a FirstPos /// PosId -bool checkConstraint(const std::vector& vals, Sketcher::ConstraintType type, - int geoid, Sketcher::PointPos pos); +bool checkConstraint(const std::vector& vals, + Sketcher::ConstraintType type, + int geoid, + Sketcher::PointPos pos); inline bool isVertex(int GeoId, Sketcher::PointPos PosId) { @@ -133,8 +142,10 @@ inline bool isEdge(int GeoId, Sketcher::PointPos PosId) double GetPointAngle(const Base::Vector2d& p1, const Base::Vector2d& p2); // Set the two points on circles at minimal distance -void GetCirclesMinimalDistance(const Part::GeomCircle* circle1, const Part::GeomCircle* circle2, - Base::Vector3d& point1, Base::Vector3d& point2); +void GetCirclesMinimalDistance(const Part::GeomCircle* circle1, + const Part::GeomCircle* circle2, + Base::Vector3d& point1, + Base::Vector3d& point2); void ActivateHandler(Gui::Document* doc, DrawSketchHandler* handler); @@ -155,8 +166,10 @@ void removeRedundantHorizontalVertical(Sketcher::SketchObject* psketch, std::vector& sug1, std::vector& sug2); -void ConstraintToAttachment(Sketcher::GeoElementId element, Sketcher::GeoElementId attachment, - double distance, App::DocumentObject* obj); +void ConstraintToAttachment(Sketcher::GeoElementId element, + Sketcher::GeoElementId attachment, + double distance, + App::DocumentObject* obj); // convenience functions for cursor coordinates bool hideUnits(); diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.h b/src/Mod/Sketcher/Gui/ViewProviderSketch.h index 9bf7c3e068..b5b5686738 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.h +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.h @@ -175,14 +175,17 @@ private: void OnChange(Base::Subject& rCaller, const char* sReason) override; private: - void updateBoolProperty(const std::string& string, App::Property* property, - bool defaultvalue); + void + updateBoolProperty(const std::string& string, App::Property* property, bool defaultvalue); void updateGridSize(const std::string& string, App::Property* property); // Only for colors outside of edit mode, edit mode colors are handled by // EditModeCoinManager. - void updateColorProperty(const std::string& string, App::Property* property, float r, - float g, float b); + void updateColorProperty(const std::string& string, + App::Property* property, + float r, + float g, + float b); void updateEscapeKeyBehaviour(const std::string& string, App::Property* property); @@ -624,9 +627,12 @@ public: /// is called when the Provider is in edit and a key event ocours. Only ESC ends edit. bool keyPressed(bool pressed, int key) override; /// is called when the Provider is in edit and the mouse is clicked - bool mouseButtonPressed(int Button, bool pressed, const SbVec2s& cursorPos, + bool mouseButtonPressed(int Button, + bool pressed, + const SbVec2s& cursorPos, const Gui::View3DInventorViewer* viewer) override; - bool mouseWheelEvent(int delta, const SbVec2s& cursorPos, + bool mouseWheelEvent(int delta, + const SbVec2s& cursorPos, const Gui::View3DInventorViewer* viewer) override; //@} @@ -639,8 +645,8 @@ public: /// signals if the constraints list has changed boost::signals2::signal signalConstraintsChanged; /// signals if the sketch has been set up - boost::signals2::signal + boost::signals2::signal< + void(const QString& state, const QString& msg, const QString& url, const QString& linkText)> signalSetUp; /// signals if the elements list has changed boost::signals2::signal signalElementsChanged; @@ -679,7 +685,8 @@ protected: /// Auxiliary function to generate messages about conflicting, redundant and malformed /// constraints - static QString appendConstraintMsg(const QString& singularmsg, const QString& pluralmsg, + static QString appendConstraintMsg(const QString& singularmsg, + const QString& pluralmsg, const std::vector& vector); //@} @@ -699,13 +706,14 @@ protected: private: /// function to handle OCCT BSpline weight calculation singularities and representation void scaleBSplinePoleCirclesAndUpdateSolverAndSketchObjectGeometry( - GeoListFacade& geolist, bool geometrywithmemoryallocation); + GeoListFacade& geolist, + bool geometrywithmemoryallocation); /** @name geometry and coordinates auxiliary functions */ //@{ /// give the coordinates of a line on the sketch plane in sketcher (2D) coordinates - void getCoordsOnSketchPlane(const SbVec3f& point, const SbVec3f& normal, double& u, - double& v) const; + void + getCoordsOnSketchPlane(const SbVec3f& point, const SbVec3f& normal, double& u, double& v) const; /// give projecting line of position void getProjectingLine(const SbVec2s&, const Gui::View3DInventorViewer* viewer, SbLine&) const; @@ -728,7 +736,8 @@ private: /** @name Selection functions */ //@{ /// box selection method - void doBoxSelection(const SbVec2s& startPos, const SbVec2s& endPos, + void doBoxSelection(const SbVec2s& startPos, + const SbVec2s& endPos, const Gui::View3DInventorViewer* viewer); void addSelectPoint(int SelectPoint); diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketchCoinAttorney.h b/src/Mod/Sketcher/Gui/ViewProviderSketchCoinAttorney.h index a99db9462a..1160101f06 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketchCoinAttorney.h +++ b/src/Mod/Sketcher/Gui/ViewProviderSketchCoinAttorney.h @@ -183,7 +183,8 @@ inline QFont ViewProviderSketchCoinAttorney::getApplicationFont(const ViewProvid } inline double ViewProviderSketchCoinAttorney::getRotation(const ViewProviderSketch& vp, - SbVec3f pos0, SbVec3f pos1) + SbVec3f pos0, + SbVec3f pos1) { return vp.getRotation(pos0, pos1); } @@ -271,7 +272,8 @@ inline bool ViewProviderSketchCoinAttorney::isConstraintSelected(const ViewProvi } inline void ViewProviderSketchCoinAttorney::executeOnSelectionPointSet( - const ViewProviderSketch& vp, std::function&& operation) + const ViewProviderSketch& vp, + std::function&& operation) { vp.executeOnSelectionPointSet(std::move(operation)); } diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketchGeometryExtension.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketchGeometryExtension.cpp index 2b6f5185b8..05feb2c345 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketchGeometryExtension.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketchGeometryExtension.cpp @@ -68,8 +68,9 @@ void ViewProviderSketchGeometryExtension::restoreAttributes(Base::XMLReader& rea { Part::GeometryPersistenceExtension::restoreAttributes(reader); - if (reader.hasAttribute("visualLayerId")) + if (reader.hasAttribute("visualLayerId")) { VisualLayerId = reader.getAttributeAsInteger("visualLayerId"); + } } void ViewProviderSketchGeometryExtension::saveAttributes(Base::Writer& writer) const diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketchGeometryExtensionPyImp.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketchGeometryExtensionPyImp.cpp index b236c3b426..df6969d4ce 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketchGeometryExtensionPyImp.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketchGeometryExtensionPyImp.cpp @@ -39,7 +39,8 @@ std::string ViewProviderSketchGeometryExtensionPy::representation() const return str.str(); } -PyObject* ViewProviderSketchGeometryExtensionPy::PyMake(struct _typeobject*, PyObject*, +PyObject* ViewProviderSketchGeometryExtensionPy::PyMake(struct _typeobject*, + PyObject*, PyObject*)// Python wrapper { // create a new instance of PointPy and the Twin object diff --git a/src/Mod/Sketcher/Gui/VisualLayer.h b/src/Mod/Sketcher/Gui/VisualLayer.h index 587a835ddd..5e8c645c26 100644 --- a/src/Mod/Sketcher/Gui/VisualLayer.h +++ b/src/Mod/Sketcher/Gui/VisualLayer.h @@ -37,7 +37,8 @@ namespace SketcherGui class VisualLayer { public: - explicit VisualLayer(unsigned int linePattern = 0xFFFF, float lineWidth = 3.0, + explicit VisualLayer(unsigned int linePattern = 0xFFFF, + float lineWidth = 3.0, bool visible = true); unsigned int getLinePattern() const; diff --git a/src/Mod/Sketcher/Gui/Workbench.cpp b/src/Mod/Sketcher/Gui/Workbench.cpp index 80c16ed94e..c4de567c8c 100644 --- a/src/Mod/Sketcher/Gui/Workbench.cpp +++ b/src/Mod/Sketcher/Gui/Workbench.cpp @@ -441,7 +441,7 @@ inline void SketcherAddWorkbenchConstraints(Gui::ToolBarItem& << "Sketcher_ConstrainBlock" << "Separator"; if (hGrp->GetBool("SingleDimensioningTool", true)) { - if (! hGrp->GetBool("SeparatedDimensioningTools", false)) { + if (!hGrp->GetBool("SeparatedDimensioningTools", false)) { cons << "Sketcher_CompDimensionTools"; } else { @@ -450,11 +450,11 @@ inline void SketcherAddWorkbenchConstraints(Gui::ToolBarItem& } if (hGrp->GetBool("SeparatedDimensioningTools", false)) { cons << "Sketcher_ConstrainLock" - << "Sketcher_ConstrainDistanceX" - << "Sketcher_ConstrainDistanceY" - << "Sketcher_ConstrainDistance" - << "Sketcher_CompConstrainRadDia" - << "Sketcher_ConstrainAngle"; + << "Sketcher_ConstrainDistanceX" + << "Sketcher_ConstrainDistanceY" + << "Sketcher_ConstrainDistance" + << "Sketcher_CompConstrainRadDia" + << "Sketcher_ConstrainAngle"; // << "Sketcher_ConstrainSnellsLaw" // Rarely used, show only in menu } cons << "Separator" diff --git a/src/Mod/Sketcher/InitGui.py b/src/Mod/Sketcher/InitGui.py index 1b2ae6f8a0..f1395481e3 100644 --- a/src/Mod/Sketcher/InitGui.py +++ b/src/Mod/Sketcher/InitGui.py @@ -33,8 +33,7 @@ class SketcherWorkbench(Workbench): def __init__(self): self.__class__.Icon = ( - FreeCAD.getResourceDir() - + "Mod/Sketcher/Resources/icons/SketcherWorkbench.svg" + FreeCAD.getResourceDir() + "Mod/Sketcher/Resources/icons/SketcherWorkbench.svg" ) self.__class__.MenuText = "Sketcher" self.__class__.ToolTip = "Sketcher workbench" diff --git a/src/Mod/Sketcher/ProfileLib/Hexagon.py b/src/Mod/Sketcher/ProfileLib/Hexagon.py index 0b881e9412..7c34d536c9 100644 --- a/src/Mod/Sketcher/ProfileLib/Hexagon.py +++ b/src/Mod/Sketcher/ProfileLib/Hexagon.py @@ -1,64 +1,64 @@ -#*************************************************************************** -#* Copyright (c) 2014 Juergen Riegel * -#* * -#* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU Lesser General Public License (LGPL) * -#* as published by the Free Software Foundation; either version 2 of * -#* the License, or (at your option) any later version. * -#* for detail see the LICENCE text file. * -#* * -#* This program is distributed in the hope that it will be useful, * -#* but WITHOUT ANY WARRANTY; without even the implied warranty of * -#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -#* GNU Library General Public License for more details. * -#* * -#* You should have received a copy of the GNU Library General Public * -#* License along with this program; if not, write to the Free Software * -#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -#* USA * -#* * -#*************************************************************************** +# *************************************************************************** +# * Copyright (c) 2014 Juergen Riegel * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** import FreeCAD, FreeCADGui, Sketcher, Part -__title__="Hexagon profile lib" +__title__ = "Hexagon profile lib" __author__ = "Juergen Riegel" __url__ = "http://www.freecad.org" App = FreeCAD Gui = FreeCADGui + def makeHexagonSimple(sketchName=None): if not sketchName: - sketch = App.ActiveDocument.addObject("Sketcher::SketchObject","Hexagon") + sketch = App.ActiveDocument.addObject("Sketcher::SketchObject", "Hexagon") else: sketch = App.ActiveDocument.getObject(sketchName) geoList = [] - geoList.append(Part.LineSegment(App.Vector(-20.00,34.64,0),App.Vector(20.00,34.64,0))) - geoList.append(Part.LineSegment(App.Vector(20.00,34.64,0),App.Vector(47.082363,0.00,0))) - geoList.append(Part.LineSegment(App.Vector(40.00,0.00,0),App.Vector(20.00,-34.64,0))) - geoList.append(Part.LineSegment(App.Vector(20.00,-34.64,0),App.Vector(-20.00,-34.64,0))) - geoList.append(Part.LineSegment(App.Vector(-20.00,-34.64,0),App.Vector(-40.00,0.00,0))) - geoList.append(Part.LineSegment(App.Vector(-40.00,0.00,0),App.Vector(-20.00,34.64,0))) - (l1,l2,l3,l4,l5,l6) = sketch.addGeometry(geoList) + geoList.append(Part.LineSegment(App.Vector(-20.00, 34.64, 0), App.Vector(20.00, 34.64, 0))) + geoList.append(Part.LineSegment(App.Vector(20.00, 34.64, 0), App.Vector(47.082363, 0.00, 0))) + geoList.append(Part.LineSegment(App.Vector(40.00, 0.00, 0), App.Vector(20.00, -34.64, 0))) + geoList.append(Part.LineSegment(App.Vector(20.00, -34.64, 0), App.Vector(-20.00, -34.64, 0))) + geoList.append(Part.LineSegment(App.Vector(-20.00, -34.64, 0), App.Vector(-40.00, 0.00, 0))) + geoList.append(Part.LineSegment(App.Vector(-40.00, 0.00, 0), App.Vector(-20.00, 34.64, 0))) + (l1, l2, l3, l4, l5, l6) = sketch.addGeometry(geoList) conList = [] - conList.append(Sketcher.Constraint('Coincident',l1,2,l2,1)) - conList.append(Sketcher.Constraint('Coincident',l2,2,l3,1)) - conList.append(Sketcher.Constraint('Coincident',l3,2,l4,1)) - conList.append(Sketcher.Constraint('Coincident',l4,2,l5,1)) - conList.append(Sketcher.Constraint('Coincident',l5,2,l6,1)) - conList.append(Sketcher.Constraint('Coincident',l6,2,l1,1)) - conList.append(Sketcher.Constraint('Equal',l1,l2)) - conList.append(Sketcher.Constraint('Equal',l2,l3)) - conList.append(Sketcher.Constraint('Equal',l3,l4)) - conList.append(Sketcher.Constraint('Equal',l4,l5)) - conList.append(Sketcher.Constraint('Equal',l5,l6)) - conList.append(Sketcher.Constraint('Angle',l1,2,l2,1,App.Units.Quantity('120.000000 deg'))) - conList.append(Sketcher.Constraint('Angle',l3,2,l4,1,App.Units.Quantity('120.000000 deg'))) - conList.append(Sketcher.Constraint('Angle',l5,2,l6,1,App.Units.Quantity('120.000000 deg'))) + conList.append(Sketcher.Constraint("Coincident", l1, 2, l2, 1)) + conList.append(Sketcher.Constraint("Coincident", l2, 2, l3, 1)) + conList.append(Sketcher.Constraint("Coincident", l3, 2, l4, 1)) + conList.append(Sketcher.Constraint("Coincident", l4, 2, l5, 1)) + conList.append(Sketcher.Constraint("Coincident", l5, 2, l6, 1)) + conList.append(Sketcher.Constraint("Coincident", l6, 2, l1, 1)) + conList.append(Sketcher.Constraint("Equal", l1, l2)) + conList.append(Sketcher.Constraint("Equal", l2, l3)) + conList.append(Sketcher.Constraint("Equal", l3, l4)) + conList.append(Sketcher.Constraint("Equal", l4, l5)) + conList.append(Sketcher.Constraint("Equal", l5, l6)) + conList.append(Sketcher.Constraint("Angle", l1, 2, l2, 1, App.Units.Quantity("120.000000 deg"))) + conList.append(Sketcher.Constraint("Angle", l3, 2, l4, 1, App.Units.Quantity("120.000000 deg"))) + conList.append(Sketcher.Constraint("Angle", l5, 2, l6, 1, App.Units.Quantity("120.000000 deg"))) sketch.addConstraint(conList) return - diff --git a/src/Mod/Sketcher/ProfileLib/RegularPolygon.py b/src/Mod/Sketcher/ProfileLib/RegularPolygon.py index 2eb3cc2ba5..7ec90e1b16 100644 --- a/src/Mod/Sketcher/ProfileLib/RegularPolygon.py +++ b/src/Mod/Sketcher/ProfileLib/RegularPolygon.py @@ -1,41 +1,43 @@ -#*************************************************************************** -#* Copyright (c) 2014 Johan Kristensen * -#* Copyright (c) 2014 Juergen Riegel * -#* * -#* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU Lesser General Public License (LGPL) * -#* as published by the Free Software Foundation; either version 2 of * -#* the License, or (at your option) any later version. * -#* for detail see the LICENCE text file. * -#* * -#* This program is distributed in the hope that it will be useful, * -#* but WITHOUT ANY WARRANTY; without even the implied warranty of * -#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -#* GNU Library General Public License for more details. * -#* * -#* You should have received a copy of the GNU Library General Public * -#* License along with this program; if not, write to the Free Software * -#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -#* USA * -#* * -#*************************************************************************** +# *************************************************************************** +# * Copyright (c) 2014 Johan Kristensen * +# * Copyright (c) 2014 Juergen Riegel * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** import FreeCAD, FreeCADGui, Sketcher, Part, math -__title__="Regular polygon profile lib" +__title__ = "Regular polygon profile lib" __author__ = "Johan Kristensen" __url__ = "http://www.freecad.org" App = FreeCAD Gui = FreeCADGui + def makeRegularPolygon( - sketch, - sides, - centerPoint=App.Vector(0,0,0), - firstCornerPoint=App.Vector(-20.00,34.64,0), - construction=False): + sketch, + sides, + centerPoint=App.Vector(0, 0, 0), + firstCornerPoint=App.Vector(-20.00, 34.64, 0), + construction=False, +): if not sketch: App.Console.PrintError("No sketch specified in 'makeRegularPolygon'") @@ -46,40 +48,34 @@ def makeRegularPolygon( diffVec = firstCornerPoint - centerPoint diffVec.z = 0 - angular_diff = 2*math.pi/sides + angular_diff = 2 * math.pi / sides pointList = [] - for i in range(0,sides): - cos_v = math.cos( angular_diff * i ) - sin_v = math.sin( angular_diff * i ) - pointList.append( centerPoint+ - App.Vector( - cos_v * diffVec.x - sin_v * diffVec.y, - cos_v * diffVec.y + sin_v * diffVec.x, - 0 )) + for i in range(0, sides): + cos_v = math.cos(angular_diff * i) + sin_v = math.sin(angular_diff * i) + pointList.append( + centerPoint + + App.Vector( + cos_v * diffVec.x - sin_v * diffVec.y, cos_v * diffVec.y + sin_v * diffVec.x, 0 + ) + ) geoList = [] - for i in range(0,sides-1): - geoList.append(Part.LineSegment(pointList[i],pointList[i+1])) - geoList.append(Part.LineSegment(pointList[sides-1],pointList[0])) - geoList.append(Part.Circle(centerPoint,App.Vector(0,0,1),diffVec.Length)) - geoIndices = sketch.addGeometry(geoList,construction) + for i in range(0, sides - 1): + geoList.append(Part.LineSegment(pointList[i], pointList[i + 1])) + geoList.append(Part.LineSegment(pointList[sides - 1], pointList[0])) + geoList.append(Part.Circle(centerPoint, App.Vector(0, 0, 1), diffVec.Length)) + geoIndices = sketch.addGeometry(geoList, construction) - sketch.setConstruction(geoIndices[-1],True) + sketch.setConstruction(geoIndices[-1], True) conList = [] - for i in range(0,sides-1): - conList.append(Sketcher.Constraint( - 'Coincident', - geoIndices[i],2, - geoIndices[i+1],1)) - conList.append(Sketcher.Constraint( - 'Coincident', - geoIndices[sides-1],2, - geoIndices[0],1)) - for i in range(0,sides-1): - conList.append(Sketcher.Constraint('Equal',geoIndices[0],geoIndices[i+1])) - for i in range(0,sides): - conList.append(Sketcher.Constraint('PointOnObject',geoIndices[i],2,geoIndices[-1])) + for i in range(0, sides - 1): + conList.append(Sketcher.Constraint("Coincident", geoIndices[i], 2, geoIndices[i + 1], 1)) + conList.append(Sketcher.Constraint("Coincident", geoIndices[sides - 1], 2, geoIndices[0], 1)) + for i in range(0, sides - 1): + conList.append(Sketcher.Constraint("Equal", geoIndices[0], geoIndices[i + 1])) + for i in range(0, sides): + conList.append(Sketcher.Constraint("PointOnObject", geoIndices[i], 2, geoIndices[-1])) sketch.addConstraint(conList) return - diff --git a/src/Mod/Sketcher/Profiles.py b/src/Mod/Sketcher/Profiles.py index 3f1528cf22..7ee77a5ea1 100644 --- a/src/Mod/Sketcher/Profiles.py +++ b/src/Mod/Sketcher/Profiles.py @@ -69,9 +69,7 @@ class _CommandProfileHexagon1: FreeCADGui.addModule("ProfileLib.Hexagon") sketch = getSketch() if not sketch is None: - FreeCADGui.doCommand( - "ProfileLib.Hexagon.makeHexagonSimple('%s')" % (sketch.Name) - ) + FreeCADGui.doCommand("ProfileLib.Hexagon.makeHexagonSimple('%s')" % (sketch.Name)) else: FreeCADGui.doCommand("ProfileLib.Hexagon.makeHexagonSimple()") FreeCAD.ActiveDocument.recompute() diff --git a/src/Mod/Sketcher/Templates/Sketch.skf b/src/Mod/Sketcher/Templates/Sketch.skf index 9edf1a21ae..cdf06d0e81 100644 --- a/src/Mod/Sketcher/Templates/Sketch.skf +++ b/src/Mod/Sketcher/Templates/Sketch.skf @@ -8,4 +8,3 @@ PARAM 83ff0001 0.000000000 LAYER 00000001 Layer00000001 1 - diff --git a/src/Mod/Sketcher/sketcher.dox b/src/Mod/Sketcher/sketcher.dox index 16d05619e5..8390e4c77c 100644 --- a/src/Mod/Sketcher/sketcher.dox +++ b/src/Mod/Sketcher/sketcher.dox @@ -2,4 +2,3 @@ * \ingroup CWORKBENCHES * \brief Constrained 2D objects */ -