Skip to content

Commit

Permalink
Merge pull request FreeCAD#12753 from davesrocketshop/20240301_FEM_Mo…
Browse files Browse the repository at this point in the history
…dels

Material: New data models to support elasticity
  • Loading branch information
chennes authored Mar 11, 2024
2 parents 9dac838 + 1c7dc55 commit f6eead2
Show file tree
Hide file tree
Showing 38 changed files with 1,055 additions and 41 deletions.
14 changes: 13 additions & 1 deletion src/Mod/Material/App/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ ModelProperty::ModelProperty()
{}

ModelProperty::ModelProperty(const QString& name,
const QString& header,
const QString& type,
const QString& units,
const QString& url,
const QString& description)
: _name(name)
, _displayName(header)
, _propertyType(type)
, _units(units)
, _url(url)
Expand All @@ -52,6 +54,7 @@ ModelProperty::ModelProperty(const QString& name,

ModelProperty::ModelProperty(const ModelProperty& other)
: _name(other._name)
, _displayName(other._displayName)
, _propertyType(other._propertyType)
, _units(other._units)
, _url(other._url)
Expand All @@ -63,13 +66,22 @@ ModelProperty::ModelProperty(const ModelProperty& other)
}
}

const QString ModelProperty::getDisplayName() const
{
if (_displayName.isEmpty()) {
return getName();
}
return _displayName;
}

ModelProperty& ModelProperty::operator=(const ModelProperty& other)
{
if (this == &other) {
return *this;
}

_name = other._name;
_displayName = other._displayName;
_propertyType = other._propertyType;
_units = other._units;
_url = other._url;
Expand All @@ -89,7 +101,7 @@ bool ModelProperty::operator==(const ModelProperty& other) const
return true;
}

return (_name == other._name) && (_propertyType == other._propertyType)
return (_name == other._name) && (_displayName == other._displayName) && (_propertyType == other._propertyType)
&& (_units == other._units) && (_url == other._url) && (_description == other._description)
&& (_inheritance == other._inheritance);
}
Expand Down
7 changes: 7 additions & 0 deletions src/Mod/Material/App/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class MaterialsExport ModelProperty: public Base::BaseClass
public:
ModelProperty();
ModelProperty(const QString& name,
const QString& header,
const QString& type,
const QString& units,
const QString& url,
Expand All @@ -67,6 +68,7 @@ class MaterialsExport ModelProperty: public Base::BaseClass
{
return _name;
}
const QString getDisplayName() const;
const QString getPropertyType() const
{
return _propertyType;
Expand Down Expand Up @@ -96,6 +98,10 @@ class MaterialsExport ModelProperty: public Base::BaseClass
{
_name = name;
}
void setColumnHeader(const QString& header)
{
_displayName = header;
}
virtual void setPropertyType(const QString& type)
{
_propertyType = type;
Expand Down Expand Up @@ -139,6 +145,7 @@ class MaterialsExport ModelProperty: public Base::BaseClass

private:
QString _name;
QString _displayName;
QString _propertyType;
QString _units;
QString _url;
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/Material/App/ModelLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,15 @@ void ModelLoader::addToTree(std::shared_ptr<ModelEntry> model,
if (exclude.count(QString::fromStdString(propName)) == 0) {
// showYaml(it->second);
auto yamlProp = yamlProperties[propName];
auto propDisplayName = yamlValue(yamlProp, "DisplayName", "");
auto propType = yamlValue(yamlProp, "Type", "");
auto propUnits = yamlValue(yamlProp, "Units", "");
auto propURL = yamlValue(yamlProp, "URL", "");
auto propDescription = yamlValue(yamlProp, "Description", "");
// auto inherits = yamlValue(yamlProp, "Inherits", "");

ModelProperty property(QString::fromStdString(propName),
propDisplayName,
propType,
propUnits,
propURL,
Expand All @@ -276,11 +278,13 @@ void ModelLoader::addToTree(std::shared_ptr<ModelEntry> model,
// Base::Console().Log("\tColumns '%s'\n", colName.c_str());

auto colProp = cols[colName];
auto colPropDisplayName = yamlValue(colProp, "DisplayName", "");
auto colPropType = yamlValue(colProp, "Type", "");
auto colPropUnits = yamlValue(colProp, "Units", "");
auto colPropURL = yamlValue(colProp, "URL", "");
auto colPropDescription = yamlValue(colProp, "Description", "");
ModelProperty colProperty(QString::fromStdString(colName),
colPropDisplayName,
colPropType,
colPropUnits,
colPropURL,
Expand Down
13 changes: 13 additions & 0 deletions src/Mod/Material/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,24 @@ SET(MaterialModel_Files
Resources/Models/Fluid/Fluid.yml
Resources/Models/Legacy/Father.yml
Resources/Models/Legacy/MaterialStandard.yml
Resources/Models/Mechanical/ArrudaBoyce.yml
Resources/Models/Mechanical/Density.yml
Resources/Models/Mechanical/IsotropicLinearElastic.yml
Resources/Models/Mechanical/LinearElastic.yml
Resources/Models/Mechanical/MooneyRivlin.yml
Resources/Models/Mechanical/NeoHooke.yml
Resources/Models/Mechanical/OgdenN1.yml
Resources/Models/Mechanical/OgdenN2.yml
Resources/Models/Mechanical/OgdenN3.yml
Resources/Models/Mechanical/OgdenYld2004p18.yml
Resources/Models/Mechanical/OrthotropicLinearElastic.yml
Resources/Models/Mechanical/PolynomialN1.yml
Resources/Models/Mechanical/PolynomialN2.yml
Resources/Models/Mechanical/PolynomialN3.yml
Resources/Models/Mechanical/ReducedPolynomialN1.yml
Resources/Models/Mechanical/ReducedPolynomialN2.yml
Resources/Models/Mechanical/ReducedPolynomialN3.yml
Resources/Models/Mechanical/Yeoh.yml
Resources/Models/Patterns/PAT.yml
"Resources/Models/Patterns/Pattern File.yml"
"Resources/Models/Render Workbench/RenderAppleseed.yml"
Expand Down
11 changes: 1 addition & 10 deletions src/Mod/Material/Gui/Array2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Array2D::Array2D(const QString& propertyName,
if (_property) {
_value =
std::static_pointer_cast<Materials::Material2DArray>(_property->getMaterialValue());
setWindowTitle(_property->getDisplayName());
}
else {
_value = nullptr;
Expand All @@ -81,16 +82,6 @@ Array2D::Array2D(const QString& propertyName,
connect(ui->standardButtons, &QDialogButtonBox::rejected, this, &Array2D::reject);
}

void Array2D::setHeaders(QStandardItemModel* model)
{
QStringList headers;
auto columns = _property->getColumns();
for (auto column = columns.begin(); column != columns.end(); column++) {
headers.append(column->getName());
}
model->setHorizontalHeaderLabels(headers);
}

void Array2D::setColumnWidths(QTableView* table)
{
int length = _property->columns();
Expand Down
1 change: 0 additions & 1 deletion src/Mod/Material/Gui/Array2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class Array2D: public QDialog

QAction _deleteAction;

void setHeaders(QStandardItemModel* model);
void setColumnWidths(QTableView* table);
void setColumnDelegates(QTableView* table);
void setupArray();
Expand Down
6 changes: 3 additions & 3 deletions src/Mod/Material/Gui/ArrayModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ QVariant Array2DModel::headerData(int section, Qt::Orientation orientation, int
if (role == Qt::DisplayRole) {
if (orientation == Qt::Horizontal) {
const Materials::MaterialProperty& column = _property->getColumn(section);
return column.getName();
return column.getDisplayName();
}
else if (orientation == Qt::Vertical) {
// Vertical header
Expand Down Expand Up @@ -251,7 +251,7 @@ QVariant Array3DDepthModel::headerData(int section, Qt::Orientation orientation,
if (role == Qt::DisplayRole) {
if (orientation == Qt::Horizontal) {
const Materials::MaterialProperty& column = _property->getColumn(section);
return column.getName();
return column.getDisplayName();
}
if (orientation == Qt::Vertical) {
// Vertical header
Expand Down Expand Up @@ -406,7 +406,7 @@ QVariant Array3DModel::headerData(int section, Qt::Orientation orientation, int
if (role == Qt::DisplayRole) {
if (orientation == Qt::Horizontal) {
const Materials::MaterialProperty& column = _property->getColumn(section + 1);
return column.getName();
return column.getDisplayName();
}
if (orientation == Qt::Vertical) {
// Vertical header
Expand Down
12 changes: 8 additions & 4 deletions src/Mod/Material/Gui/MaterialDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ QVariant MaterialDelegate::getValue(const QModelIndex& index) const
QVariant propertyValue;
if (group->child(row, 1)) {
auto material = group->child(row, 1)->data().value<std::shared_ptr<Materials::Material>>();
auto propertyName = group->child(row, 0)->text();
// auto propertyName = group->child(row, 0)->text();
auto propertyName = group->child(row, 0)->data().toString();
propertyValue = material->getProperty(propertyName)->getValue();
}
return propertyValue;
Expand All @@ -130,7 +131,8 @@ void MaterialDelegate::setValue(QAbstractItemModel* model,
int row = index.row();
if (group->child(row, 1)) {
auto material = group->child(row, 1)->data().value<std::shared_ptr<Materials::Material>>();
auto propertyName = group->child(row, 0)->text();
// auto propertyName = group->child(row, 0)->text();
auto propertyName = group->child(row, 0)->data().toString();
material->getProperty(propertyName)->setValue(value);
group->child(row, 1)->setText(value.toString());
}
Expand All @@ -152,7 +154,8 @@ void MaterialDelegate::notifyChanged(const QAbstractItemModel* model,
int row = index.row();
if (group->child(row, 1)) {
auto material = group->child(row, 1)->data().value<std::shared_ptr<Materials::Material>>();
auto propertyName = group->child(row, 0)->text();
// auto propertyName = group->child(row, 0)->text();
auto propertyName = group->child(row, 0)->data().toString();
auto propertyValue = material->getProperty(propertyName)->getValue();
material->setEditStateAlter();
Base::Console().Log("MaterialDelegate::notifyChanged() - marked altered\n");
Expand Down Expand Up @@ -181,7 +184,8 @@ bool MaterialDelegate::editorEvent(QEvent* event,

int row = index.row();

QString propertyName = group->child(row, 0)->text();
// QString propertyName = group->child(row, 0)->text();
QString propertyName = group->child(row, 0)->data().toString();

auto type = getType(index);
if (type == Materials::MaterialValue::Color) {
Expand Down
8 changes: 6 additions & 2 deletions src/Mod/Material/Gui/MaterialsEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,9 @@ void MaterialsEditor::updateMaterialAppearance()
QList<QStandardItem*> items;

QString key = itp->first;
auto propertyItem = new QStandardItem(key);
// auto propertyItem = new QStandardItem(key);
auto propertyItem = new QStandardItem(itp->second.getDisplayName());
propertyItem->setData(key);
propertyItem->setToolTip(itp->second.getDescription());
items.append(propertyItem);

Expand Down Expand Up @@ -1026,7 +1028,9 @@ void MaterialsEditor::updateMaterialProperties()
QString key = itp->first;
Materials::ModelProperty modelProperty =
static_cast<Materials::ModelProperty>(itp->second);
auto propertyItem = new QStandardItem(key);
// auto propertyItem = new QStandardItem(key);
auto propertyItem = new QStandardItem(modelProperty.getDisplayName());
propertyItem->setData(key);
propertyItem->setToolTip(modelProperty.getDescription());
items.append(propertyItem);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ Model:
Description: "default architectural model"
DOI: ""
EnvironmentalEfficiencyClass:
DisplayName: "Environmental Efficiency Class"
Type: 'String'
Units: ''
URL: ''
Description: " "
ExecutionInstructions:
DisplayName: "Execution Instructions"
Type: 'String'
Units: ''
URL: ''
Description: " "
FireResistanceClass:
DisplayName: "Fire Resistance Class"
Type: 'String'
Units: ''
URL: ''
Expand All @@ -48,11 +51,13 @@ Model:
URL: ''
Description: " "
SoundTransmissionClass:
DisplayName: "Sound Transmission Class"
Type: 'String'
Units: ''
URL: ''
Description: " "
UnitsPerQuantity:
DisplayName: "Units Per Quantity"
Type: 'Float'
Units: ''
URL: ''
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Material/Resources/Models/Costs/Costs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ Model:
Description: "default cost model"
DOI: ""
ProductURL:
DisplayName: "Product URL"
Type: 'URL'
Units: ''
URL: 'https://de.wikipedia.org/wiki/Hyperlink'
Description: "Product URL, recommended are wikipedia links"
SpecificPrice:
DisplayName: "Specific Price"
Type: 'Float'
Units: ''
URL: ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ Model:
Description: "default electromagnetic model"
DOI: ""
RelativePermittivity:
DisplayName: "Relative Permittivity"
Type: 'Float'
Units: ''
URL: 'https://en.wikipedia.org/wiki/Relative_permittivity'
Description: "The ratio to the permittivity of the vacuum"
ElectricalConductivity:
DisplayName: "Electrical Conductivity"
Type: 'Quantity'
Units: 'S/m'
URL: 'https://en.wikipedia.org/wiki/Electrical_resistivity_and_conductivity'
Description: >
The electrical conductivity in [FreeCAD ElectricalConductivity unit]
RelativePermeability:
DisplayName: "Relative Permeability"
Type: 'Float'
Units: ''
URL: 'https://en.wikipedia.org/wiki/Permeability_(electromagnetism)'
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/Material/Resources/Models/Fluid/Fluid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Model:
- Density:
UUID: '454661e5-265b-4320-8e6f-fcf6223ac3af'
DynamicViscosity:
DisplayName: "Dynamic Viscosity"
Type: 'Quantity'
Units: 'Pa*s'
URL: 'https://en.wikipedia.org/wiki/Viscosity'
Expand All @@ -38,11 +39,13 @@ Model:
flow and deform during mechanical oscillation as a function of
temperature, frequency, time, or both
KinematicViscosity:
DisplayName: "Kinematic Viscosity"
Type: 'Quantity'
Units: 'm^2/s'
URL: 'https://en.wikipedia.org/wiki/Viscosity'
Description: "Kinematic Viscosity = Dynamic Viscosity / Density"
PrandtlNumber:
DisplayName: "Prandtl Number"
Type: 'Float'
Units: ''
URL: 'https://en.wikipedia.org/wiki/Prandtl_number'
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/Material/Resources/Models/Legacy/MaterialStandard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ Model:
Description: "Describes the norm or standards referenced by this material"
DOI: ""
KindOfMaterial:
DisplayName: "Kind Of Material"
Type: 'String'
Units: ''
URL: ''
Description: " "
MaterialNumber:
DisplayName: "Material Number"
Type: 'String'
Units: ''
URL: ''
Description: " "
StandardCode:
DisplayName: "Standard Code"
Type: 'String'
Units: ''
URL: ''
Expand Down
Loading

0 comments on commit f6eead2

Please sign in to comment.