diff --git a/src/Gui/SelectionObject.h b/src/Gui/SelectionObject.h index cc0d618246..700eaaf2f8 100644 --- a/src/Gui/SelectionObject.h +++ b/src/Gui/SelectionObject.h @@ -71,9 +71,15 @@ public: inline const std::vector getPickedPoints() const { return SelPoses; } /// returns the selected DocumentObject or NULL if the object is already deleted - const App::DocumentObject *getObject() const; + const App::DocumentObject* getObject() const; + /// returns the selected DocumentObject or NULL if the object is already deleted + template + const T* getObject() const { return dynamic_cast(getObject()); }; /// returns the selected DocumentObject or NULL if the object is already deleted App::DocumentObject *getObject(); + /// returns the selected DocumentObject if it is of T type or null otherwise + template + T* getObject() { return dynamic_cast(getObject()); } /// check the selected object is a special type or derived of bool isObjectTypeOf(const Base::Type& typeId) const; diff --git a/src/Gui/ViewProviderDocumentObject.h b/src/Gui/ViewProviderDocumentObject.h index 71d8fa9576..e325142b70 100644 --- a/src/Gui/ViewProviderDocumentObject.h +++ b/src/Gui/ViewProviderDocumentObject.h @@ -92,6 +92,9 @@ public: void updateView(); /// Get the object of this ViewProvider object App::DocumentObject *getObject() const {return pcObject;} + /// Get the object of this ViewProvider object as specified type + template + T *getObject() const { return dynamic_cast(pcObject); } /// Asks the view provider if the given object can be deleted. bool canDelete(App::DocumentObject* obj) const override; /// Ask the view provider if it accepts object deletions while in edit diff --git a/src/Gui/ViewProviderGeometryObject.cpp b/src/Gui/ViewProviderGeometryObject.cpp index 80739a4210..be8672106d 100644 --- a/src/Gui/ViewProviderGeometryObject.cpp +++ b/src/Gui/ViewProviderGeometryObject.cpp @@ -173,7 +173,7 @@ void ViewProviderGeometryObject::updateData(const App::Property* prop) pcBoundingBox->maxBounds.setValue(box.MaxX, box.MaxY, box.MaxZ); } else if (prop->isDerivedFrom(App::PropertyPlacement::getClassTypeId())) { - auto geometry = dynamic_cast(getObject()); + auto geometry = getObject(); if (geometry && prop == &geometry->Placement) { const App::PropertyComplexGeoData* data = geometry->getPropertyOfGeometry(); if (data) { @@ -185,8 +185,7 @@ void ViewProviderGeometryObject::updateData(const App::Property* prop) } else if (std::string(prop->getName()) == "ShapeMaterial") { // Set the appearance from the material - auto geometry = dynamic_cast(getObject()); - if (geometry) { + if (auto geometry = getObject()) { /* * Change the appearance only if the appearance hasn't been set explicitly. A cached * material appearance is used to see if the current appearance matches the last diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostFunction.h b/src/Mod/Fem/Gui/ViewProviderFemPostFunction.h index 7b69218d84..87b3e9c7e0 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostFunction.h +++ b/src/Mod/Fem/Gui/ViewProviderFemPostFunction.h @@ -65,10 +65,15 @@ protected: { return m_view; } - Fem::FemPostFunction* getObject() + Fem::FemPostFunction* getObject() const { return m_object; } + template + T* getObject() const + { + return dynamic_cast(getObject()); + } bool blockObjectUpdates() { diff --git a/src/Mod/PartDesign/Gui/TaskTransformedParameters.h b/src/Mod/PartDesign/Gui/TaskTransformedParameters.h index 0cd72f2eb6..8fc17d4ee7 100644 --- a/src/Mod/PartDesign/Gui/TaskTransformedParameters.h +++ b/src/Mod/PartDesign/Gui/TaskTransformedParameters.h @@ -178,6 +178,9 @@ protected: */ PartDesign::Transformed* getObject() const; + template + T* getObject() const { return dynamic_cast(getObject()); } + /// Get the sketch object of the first original either of the object associated with this /// feature or with the parent feature (MultiTransform mode) App::DocumentObject* getSketchObject() const; diff --git a/src/Mod/TechDraw/App/DimensionReferences.h b/src/Mod/TechDraw/App/DimensionReferences.h index faa5fd769c..8816cd8f88 100644 --- a/src/Mod/TechDraw/App/DimensionReferences.h +++ b/src/Mod/TechDraw/App/DimensionReferences.h @@ -63,6 +63,7 @@ public: bool operator== (const ReferenceEntry& otherRef) const; App::DocumentObject* getObject() const; + template T* getObject() const { return dynamic_cast(getObject()); } void setObject(App::DocumentObject* docObj) { m_object = docObj; } std::string getSubName(bool longForm = false) const; void setSubName(const std::string& subName) { m_subName = subName; }