From ae15d98fd3cd95e95521b0d910ea47da607516c1 Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Wed, 15 Jan 2025 22:31:36 +0100 Subject: [PATCH] Use is() when possible --- src/Mod/Assembly/Gui/ViewProviderAssembly.cpp | 10 +++----- .../Inspection/Gui/ViewProviderInspection.cpp | 2 +- src/Mod/Sandbox/Gui/AppSandboxGui.cpp | 4 +-- .../App/ExternalGeometryFacadePyImp.cpp | 2 +- src/Mod/Sketcher/App/GeometryFacade.h | 2 +- src/Mod/Sketcher/App/PythonConverter.cpp | 25 +++++++++++-------- src/Mod/Sketcher/App/SketchObject.cpp | 18 +++++++------ .../Sketcher/Gui/DrawSketchHandlerOffset.h | 5 ++-- .../Sketcher/Gui/DrawSketchHandlerSplitting.h | 11 ++++++-- src/Mod/Spreadsheet/App/Sheet.cpp | 6 ++--- 10 files changed, 46 insertions(+), 39 deletions(-) diff --git a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp b/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp index e3b78445b2..b9a59e29a0 100644 --- a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp +++ b/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp @@ -160,10 +160,7 @@ bool ViewProviderAssembly::doubleClicked() bool ViewProviderAssembly::canDragObject(App::DocumentObject* obj) const { // The user should not be able to drag the joint group out of the assembly - if (!obj || obj->getTypeId() == Assembly::JointGroup::getClassTypeId()) { - return false; - } - return true; + return obj && !obj->is(); } bool ViewProviderAssembly::canDragObjectToTarget(App::DocumentObject* obj, @@ -1028,9 +1025,8 @@ bool ViewProviderAssembly::onDelete(const std::vector& subNames) { // Delete the assembly groups when assembly is deleted for (auto obj : getObject()->getOutList()) { - if (obj->getTypeId() == Assembly::JointGroup::getClassTypeId() - || obj->getTypeId() == Assembly::ViewGroup::getClassTypeId() - || obj->getTypeId() == Assembly::BomGroup::getClassTypeId()) { + if (obj->is() || obj->is() + || obj->is()) { // Delete the group content first. Gui::Command::doCommand(Gui::Command::Doc, diff --git a/src/Mod/Inspection/Gui/ViewProviderInspection.cpp b/src/Mod/Inspection/Gui/ViewProviderInspection.cpp index 4dd4d784b3..b296fd94fa 100644 --- a/src/Mod/Inspection/Gui/ViewProviderInspection.cpp +++ b/src/Mod/Inspection/Gui/ViewProviderInspection.cpp @@ -385,7 +385,7 @@ void ViewProviderInspection::setDistances() SoDebugError::post("ViewProviderInspection::setDistances", "Unknown property 'Distances'"); return; } - if (pDistances->getTypeId() != Inspection::PropertyDistanceList::getClassTypeId()) { + if (!pDistances->is()) { SoDebugError::post( "ViewProviderInspection::setDistances", "Property 'Distances' has type %s (Inspection::PropertyDistanceList was expected)", diff --git a/src/Mod/Sandbox/Gui/AppSandboxGui.cpp b/src/Mod/Sandbox/Gui/AppSandboxGui.cpp index 848ec3169f..210dada07f 100644 --- a/src/Mod/Sandbox/Gui/AppSandboxGui.cpp +++ b/src/Mod/Sandbox/Gui/AppSandboxGui.cpp @@ -73,9 +73,9 @@ private: return; Part::Geometry* g1 = items[0]; Part::Geometry* g2 = items[1]; - if (!g1 || g1->getTypeId() != Part::GeomArcOfCircle::getClassTypeId()) + if (!g1 || !g1->is()) return; - if (!g2 || g2->getTypeId() != Part::GeomLineSegment::getClassTypeId()) + if (!g2 || !g2->is()) return; Part::GeomArcOfCircle* arc = static_cast(g1); Part::GeomLineSegment* seg = static_cast(g2); diff --git a/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp b/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp index 1127d31f4d..cebe5f27b1 100644 --- a/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp +++ b/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp @@ -510,7 +510,7 @@ Py::Boolean ExternalGeometryFacadePy::getConstruction() const void ExternalGeometryFacadePy::setConstruction(Py::Boolean arg) { - if (getExternalGeometryFacadePtr()->getTypeId() != Part::GeomPoint::getClassTypeId()) { + if (!getExternalGeometryFacadePtr()->is()) { getExternalGeometryFacadePtr()->setConstruction(arg); } } diff --git a/src/Mod/Sketcher/App/GeometryFacade.h b/src/Mod/Sketcher/App/GeometryFacade.h index 43da4bc8ec..1b8e218484 100644 --- a/src/Mod/Sketcher/App/GeometryFacade.h +++ b/src/Mod/Sketcher/App/GeometryFacade.h @@ -87,7 +87,7 @@ class GeometryFacadePy; * * Part::Geometry* copy = v->copy(); * - * if(construction && copy->getTypeId() != Part::GeomPoint::getClassTypeId()) { + * if(construction && !copy->is()) { * GeometryFacade::setConstruction(copy, construction); * } * diff --git a/src/Mod/Sketcher/App/PythonConverter.cpp b/src/Mod/Sketcher/App/PythonConverter.cpp index 8e2c05b7b0..7c7dbdae19 100644 --- a/src/Mod/Sketcher/App/PythonConverter.cpp +++ b/src/Mod/Sketcher/App/PythonConverter.cpp @@ -46,15 +46,16 @@ std::string PythonConverter::convert(const Part::Geometry* geo, Mode mode) command = boost::str(boost::format("addGeometry(%s,%s)\n") % sg.creation % (sg.construction ? "True" : "False")); - if ((geo->getTypeId() != Part::GeomEllipse::getClassTypeId() - || geo->getTypeId() != Part::GeomArcOfEllipse::getClassTypeId() - || geo->getTypeId() != Part::GeomArcOfHyperbola::getClassTypeId() - || geo->getTypeId() != Part::GeomArcOfParabola::getClassTypeId() - || geo->getTypeId() != Part::GeomBSplineCurve::getClassTypeId()) - && mode == Mode::CreateInternalGeometry) { + // clang-format off: keep line breaks for readability + if ((!geo->is() + || !geo->is() + || !geo->is() + || !geo->is() + || !geo->is()) && mode == Mode::CreateInternalGeometry) { command += boost::str(boost::format("exposeInternalGeometry(len(ActiveSketch.Geometry))\n")); } + // clang-format on return command; } @@ -149,15 +150,17 @@ std::string PythonConverter::convert(const std::string& doc, if (mode == Mode::CreateInternalGeometry) { for (auto geo : geos) { index++; - if (geo->getTypeId() != Part::GeomEllipse::getClassTypeId() - || geo->getTypeId() != Part::GeomArcOfEllipse::getClassTypeId() - || geo->getTypeId() != Part::GeomArcOfHyperbola::getClassTypeId() - || geo->getTypeId() != Part::GeomArcOfParabola::getClassTypeId() - || geo->getTypeId() != Part::GeomBSplineCurve::getClassTypeId()) { + // clang-format off: keep line breaks for readability + if (!geo->is() + || !geo->is() + || !geo->is() + || !geo->is() + || !geo->is()) { std::string newcommand = boost::str(boost::format("exposeInternalGeometry(lastGeoId + %d)\n") % (index)); command += newcommand; } + // clang-format on } } diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 8c14ad1e7d..fd4dbbbca4 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -2480,8 +2480,8 @@ void SketchObject::transferFilletConstraints(int geoId1, PointPos posId1, int ge // TODO: Add support for curved lines. const Part::Geometry* geo1 = getGeometry(geoId1); const Part::Geometry* geo2 = getGeometry(geoId2); - if (geo1->getTypeId() != Part::GeomLineSegment::getClassTypeId() - || geo2->getTypeId() != Part::GeomLineSegment::getClassTypeId()) { + if (!geo1->is() + || !geo2->is()) { delConstraintOnPoint(geoId1, posId1, false); delConstraintOnPoint(geoId2, posId2, false); return; @@ -4458,7 +4458,7 @@ bool SketchObject::isCarbonCopyAllowed(App::Document* pDoc, App::DocumentObject* std::string sketchArchType ("Sketcher::SketchObjectPython"); // Only applicable to sketches - if (pObj->getTypeId() != Sketcher::SketchObject::getClassTypeId() + if (!pObj->is() && sketchArchType != pObj->getTypeId().getName()) { if (rsn) { *rsn = rlNotASketch; @@ -6913,13 +6913,15 @@ bool SketchObject::increaseBSplineDegree(int GeoId, int degreeincrement /*= 1*/) // no need to check input data validity as this is an sketchobject managed operation. Base::StateLocker lock(managedoperation, true); - if (GeoId < 0 || GeoId > getHighestCurveIndex()) + if (GeoId < 0 || GeoId > getHighestCurveIndex()) { return false; + } const Part::Geometry* geo = getGeometry(GeoId); - if (geo->getTypeId() != Part::GeomBSplineCurve::getClassTypeId()) + if (!geo->is()) { return false; + } const auto* bsp = static_cast(geo); @@ -6960,7 +6962,7 @@ bool SketchObject::decreaseBSplineDegree(int GeoId, int degreedecrement /*= 1*/) const Part::Geometry* geo = getGeometry(GeoId); - if (geo->getTypeId() != Part::GeomBSplineCurve::getClassTypeId()) + if (!geo->is()) return false; const auto* bsp = static_cast(geo); @@ -7449,7 +7451,7 @@ int SketchObject::carbonCopy(App::DocumentObject* pObj, bool construction) for (std::vector::const_iterator it = svals.begin(); it != svals.end(); ++it) { Part::Geometry* geoNew = (*it)->copy(); generateId(geoNew); - if (construction && geoNew->getTypeId() != Part::GeomPoint::getClassTypeId()) { + if (construction && !geoNew->is()) { GeometryFacade::setConstruction(geoNew, true); } newVals.push_back(geoNew); @@ -10111,7 +10113,7 @@ void SketchObject::onChanged(const App::Property* prop) if (ext->testMigrationType(Part::GeometryMigrationExtension::Construction)) { bool oldconstr = ext->getConstruction(); - if (geometryValue->getTypeId() == Part::GeomPoint::getClassTypeId() + if (geometryValue->is() && !gf->isInternalAligned()) { oldconstr = true; } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h index 81ee64b6db..f098cb7160 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h @@ -735,9 +735,8 @@ private: break; } } - else if (isLineSegment(*geo2) - || geo2->getTypeId() == Part::GeomArcOfConic::getClassTypeId() - || isBSplineCurve(*geo2)) { + else if (isLineSegment(*geo2) || isBSplineCurve(*geo2) + || geo2->is()) { // cases where arc is created by arc join mode. Base::Vector3d p2, p3; diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerSplitting.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerSplitting.h index a40752e237..5ad102ec25 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerSplitting.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerSplitting.h @@ -65,12 +65,16 @@ public: 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->is() || geom->is() + + // clang-format off: keep line breaks for readability + if (geom->is() + || geom->is() || geom->is() || geom->isDerivedFrom(Part::GeomArcOfConic::getClassTypeId()) || geom->is()) { return true; } + // clang-format on } else if (element.substr(0, 6) == "Vertex") { int VertId = std::atoi(element.substr(6, 4000).c_str()) - 1; @@ -114,12 +118,15 @@ public: int curveGeoId = getPreselectCurve(); if (curveGeoId >= 0) { const Part::Geometry* geom = sketchgui->getSketchObject()->getGeometry(curveGeoId); - if (geom->is() || geom->is() + // clang-format off: keep line breaks for readability + if (geom->is() + || geom->is() || geom->is() || geom->isDerivedFrom(Part::GeomArcOfConic::getClassTypeId()) || geom->is()) { GeoId = curveGeoId; } + // clang-format on } else { // No curve of interest is pre-selected. Try pre-selected point. diff --git a/src/Mod/Spreadsheet/App/Sheet.cpp b/src/Mod/Spreadsheet/App/Sheet.cpp index 88376404dd..cfd800dd36 100644 --- a/src/Mod/Spreadsheet/App/Sheet.cpp +++ b/src/Mod/Spreadsheet/App/Sheet.cpp @@ -573,7 +573,7 @@ Property* Sheet::setFloatProperty(CellAddress key, double value) Property* prop = props.getDynamicPropertyByName(name.c_str()); PropertyFloat* floatProp; - if (!prop || prop->getTypeId() != PropertyFloat::getClassTypeId()) { + if (!prop || !prop->is()) { if (prop) { this->removeDynamicProperty(name.c_str()); propAddress.erase(prop); @@ -601,7 +601,7 @@ Property* Sheet::setIntegerProperty(CellAddress key, long value) Property* prop = props.getDynamicPropertyByName(name.c_str()); PropertyInteger* intProp; - if (!prop || prop->getTypeId() != PropertyInteger::getClassTypeId()) { + if (!prop || !prop->is()) { if (prop) { this->removeDynamicProperty(name.c_str()); propAddress.erase(prop); @@ -641,7 +641,7 @@ Property* Sheet::setQuantityProperty(CellAddress key, double value, const Base:: Property* prop = props.getDynamicPropertyByName(name.c_str()); PropertySpreadsheetQuantity* quantityProp; - if (!prop || prop->getTypeId() != PropertySpreadsheetQuantity::getClassTypeId()) { + if (!prop || !prop->is()) { if (prop) { this->removeDynamicProperty(name.c_str()); propAddress.erase(prop);