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:
Kacper Donat
2024-10-27 18:45:19 +01:00
parent ad50bb9bef
commit deb15a57e4
6 changed files with 22 additions and 5 deletions

View File

@@ -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