Materials: Physical property attributes

Add dynamic attributes to report the physical attributes of a part that
are automatically recalculaated when the shape or material changes.
These values are accessible from the part data display and as attributes
within Python
This commit is contained in:
David Carter
2024-10-24 00:10:46 -04:00
committed by Yorik van Havre
parent 223877873b
commit 6af113bc4f
7 changed files with 105 additions and 8 deletions

View File

@@ -89,8 +89,34 @@ Feature::Feature()
{
ADD_PROPERTY(Shape, (TopoDS_Shape()));
auto mat = Materials::MaterialManager::defaultMaterial();
// ADD_PROPERTY_TYPE(ShapeMaterial, (mat), osgroup, App::Prop_None, "Shape material");
ADD_PROPERTY(ShapeMaterial, (*mat));
// Read only properties based on the material
static const char* group = "PhysicalProperties";
ADD_PROPERTY_TYPE(MaterialName,
(""),
group,
static_cast<App::PropertyType>(App::Prop_ReadOnly | App::Prop_Output
| App::Prop_NoRecompute | App::Prop_NoPersist),
"Feature material");
ADD_PROPERTY_TYPE(Density,
(0.0),
group,
static_cast<App::PropertyType>(App::Prop_ReadOnly | App::Prop_Output
| App::Prop_NoRecompute | App::Prop_NoPersist),
"Feature density");
ADD_PROPERTY_TYPE(Mass,
(0.0),
group,
static_cast<App::PropertyType>(App::Prop_ReadOnly | App::Prop_Output
| App::Prop_NoRecompute | App::Prop_NoPersist),
"Feature mass");
ADD_PROPERTY_TYPE(Volume,
(1.0),
group,
static_cast<App::PropertyType>(App::Prop_ReadOnly | App::Prop_Output
| App::Prop_NoRecompute | App::Prop_NoPersist),
"Feature volume");
}
Feature::~Feature() = default;
@@ -1477,11 +1503,40 @@ void Feature::onChanged(const App::Property* prop)
}
}
}
updatePhysicalProperties();
} else if (prop == &this->ShapeMaterial) {
updatePhysicalProperties();
}
GeoFeature::onChanged(prop);
}
void Feature::updatePhysicalProperties()
{
MaterialName.setValue(ShapeMaterial.getValue().getName().toStdString());
if (ShapeMaterial.getValue().hasPhysicalProperty(QString::fromLatin1("Density"))) {
Density.setValue(ShapeMaterial.getValue()
.getPhysicalQuantity(QString::fromLatin1("Density"))
.getValue());
} else {
Base::Console().Log("Density is undefined\n");
Density.setValue(0.0);
}
auto topoShape = Shape.getValue();
if (!topoShape.IsNull()) {
GProp_GProps props;
BRepGProp::VolumeProperties(topoShape, props);
Volume.setValue(props.Mass());
Mass.setValue(Volume.getValue() * Density.getValue());
} else {
// No shape
Base::Console().Log("No shape defined\n");
Volume.setValue(0.0);
Mass.setValue(0.0);
}
}
const std::vector<std::string>& Feature::searchElementCache(const std::string& element,
Data::SearchOptions options,