diff --git a/src/App/Services.cpp b/src/App/Services.cpp index ae70735441..4b021529df 100644 --- a/src/App/Services.cpp +++ b/src/App/Services.cpp @@ -27,4 +27,9 @@ std::optional App::NullCenterOfMass::ofDocumentObject([[maybe_unused]] DocumentObject* object) const { return std::nullopt; +} + +bool App::NullCenterOfMass::supports(DocumentObject* object) const +{ + return false; } \ No newline at end of file diff --git a/src/App/Services.h b/src/App/Services.h index 297819e0c6..ba32404e89 100644 --- a/src/App/Services.h +++ b/src/App/Services.h @@ -55,6 +55,7 @@ class CenterOfMassProvider public: virtual ~CenterOfMassProvider() = default; + virtual bool supports(DocumentObject* object) const = 0; virtual std::optional ofDocumentObject(DocumentObject* object) const = 0; }; @@ -66,6 +67,7 @@ class NullCenterOfMass final : public CenterOfMassProvider { public: std::optional ofDocumentObject(DocumentObject* object) const override; + bool supports(DocumentObject* object) const override; }; } diff --git a/src/Gui/TaskTransform.cpp b/src/Gui/TaskTransform.cpp index ceec188946..a6a05e0f7b 100644 --- a/src/Gui/TaskTransform.cpp +++ b/src/Gui/TaskTransform.cpp @@ -173,7 +173,7 @@ void TaskTransform::loadPlacementModeItems() const QVariant::fromValue(PlacementMode::ObjectOrigin) ); - if (centerOfMassProvider->ofDocumentObject(vp->getObject()).has_value()) { + if (centerOfMassProvider->supports(vp->getObject())) { ui->placementComboBox->addItem( tr("Center of mass / centroid"), QVariant::fromValue(PlacementMode::Centroid) diff --git a/src/Mod/Part/App/Services.cpp b/src/Mod/Part/App/Services.cpp index 8c84cafd77..f10c23c269 100644 --- a/src/Mod/Part/App/Services.cpp +++ b/src/Mod/Part/App/Services.cpp @@ -45,7 +45,7 @@ Base::Placement AttacherSubObjectPlacement::calculate( std::optional PartCenterOfMass::ofDocumentObject(App::DocumentObject* object) const { - if (const auto feature = dynamic_cast(object)) { + if (const auto* feature = freecad_cast(object)) { const auto shape = feature->Shape.getShape(); if (const auto cog = shape.centerOfGravity()) { @@ -57,3 +57,8 @@ std::optional PartCenterOfMass::ofDocumentObject(App::DocumentOb return {}; } + +bool PartCenterOfMass::supports(App::DocumentObject* object) const +{ + return object->isDerivedFrom(); +} diff --git a/src/Mod/Part/App/Services.h b/src/Mod/Part/App/Services.h index 217ff47e8d..b331c5eea3 100644 --- a/src/Mod/Part/App/Services.h +++ b/src/Mod/Part/App/Services.h @@ -42,6 +42,7 @@ class PartCenterOfMass final: public App::CenterOfMassProvider { public: std::optional ofDocumentObject(App::DocumentObject* object) const override; + bool supports(App::DocumentObject* object) const override; }; #endif // PART_SERVICES_H