Gui: Add getObject<T>() helpers to various classes
Obtaining specific kind of document object is very common task. This commit introduces handy helper which makes that a lot easier.
This commit is contained in:
@@ -71,9 +71,15 @@ public:
|
||||
inline const std::vector<Base::Vector3d> 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 <class T>
|
||||
const T* getObject() const { return dynamic_cast<T*>(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 <class T>
|
||||
T* getObject() { return dynamic_cast<T*>(getObject()); }
|
||||
|
||||
/// check the selected object is a special type or derived of
|
||||
bool isObjectTypeOf(const Base::Type& typeId) const;
|
||||
|
||||
@@ -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 <class T>
|
||||
T *getObject() const { return dynamic_cast<T*>(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
|
||||
|
||||
@@ -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<App::GeoFeature*>(getObject());
|
||||
auto geometry = getObject<App::GeoFeature>();
|
||||
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<App::GeoFeature*>(getObject());
|
||||
if (geometry) {
|
||||
if (auto geometry = getObject<App::GeoFeature>()) {
|
||||
/*
|
||||
* 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
|
||||
|
||||
@@ -65,10 +65,15 @@ protected:
|
||||
{
|
||||
return m_view;
|
||||
}
|
||||
Fem::FemPostFunction* getObject()
|
||||
Fem::FemPostFunction* getObject() const
|
||||
{
|
||||
return m_object;
|
||||
}
|
||||
template<class T>
|
||||
T* getObject() const
|
||||
{
|
||||
return dynamic_cast<T*>(getObject());
|
||||
}
|
||||
|
||||
bool blockObjectUpdates()
|
||||
{
|
||||
|
||||
@@ -178,6 +178,9 @@ protected:
|
||||
*/
|
||||
PartDesign::Transformed* getObject() const;
|
||||
|
||||
template <class T>
|
||||
T* getObject() const { return dynamic_cast<T*>(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;
|
||||
|
||||
@@ -63,6 +63,7 @@ public:
|
||||
bool operator== (const ReferenceEntry& otherRef) const;
|
||||
|
||||
App::DocumentObject* getObject() const;
|
||||
template <class T> T* getObject() const { return dynamic_cast<T*>(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; }
|
||||
|
||||
Reference in New Issue
Block a user