Skip to content

Commit

Permalink
Material: Add thermal reference temperature (#13026)
Browse files Browse the repository at this point in the history
* Material: Add thermal reference temperature

Fixes #13019

Adds the property 'Thermal Expansion Reference Temperature' to
the Thermal properties

* Fix delegates
  • Loading branch information
davesrocketshop committed Apr 1, 2024
1 parent 79f9da4 commit 57c66a9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
15 changes: 11 additions & 4 deletions src/Mod/Material/Gui/BaseDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,13 @@ void BaseDelegate::paintQuantity(QPainter* painter,
else {
QVariant item = getValue(index);
auto quantity = item.value<Base::Quantity>();
QString text = quantity.getUserString();
painter->drawText(option.rect, 0, text);
if (quantity.isValid()) {
QString text = quantity.getUserString();
painter->drawText(option.rect, 0, text);
}
else {
painter->drawText(option.rect, 0, QString());
}
}

painter->restore();
Expand Down Expand Up @@ -350,8 +355,10 @@ void BaseDelegate::setModelData(QWidget* editor,
}
else if (type == Materials::MaterialValue::Quantity) {
auto input = dynamic_cast<Gui::InputField*>(editor);
value = input->text();
return;
// value = input->text();
// return;
auto quantity = Base::Quantity::parse(input->text());
value = QVariant::fromValue(quantity);
}
else if (type == Materials::MaterialValue::Integer) {
auto spinner = dynamic_cast<Gui::IntSpinBox*>(editor);
Expand Down
16 changes: 9 additions & 7 deletions src/Mod/Material/Gui/MaterialDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ void MaterialDelegate::setValue(QAbstractItemModel* model,
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)->data().toString();
material->getProperty(propertyName)->setValue(value);
group->child(row, 1)->setText(value.toString());
std::string _name = propertyName.toStdString();
auto property = material->getProperty(propertyName);
property->setValue(value);
group->child(row, 1)->setText(property->getString());
}

notifyChanged(model, index);
Expand Down Expand Up @@ -267,7 +269,7 @@ void MaterialDelegate::showImageModal(const QString& propertyName, QStandardItem

dlg->adjustSize();

//connect(dlg, &QDialog::finished, this, [&](int result) {});
// connect(dlg, &QDialog::finished, this, [&](int result) {});

dlg->exec();
}
Expand All @@ -281,7 +283,7 @@ void MaterialDelegate::showListModal(const QString& propertyName, QStandardItem*

dlg->adjustSize();

//connect(dlg, &QDialog::finished, this, [&](int result) {});
// connect(dlg, &QDialog::finished, this, [&](int result) {});

dlg->exec();
}
Expand All @@ -295,7 +297,7 @@ void MaterialDelegate::showMultiLineStringModal(const QString& propertyName, QSt

dlg->adjustSize();

//connect(dlg, &QDialog::finished, this, [&](int result) {});
// connect(dlg, &QDialog::finished, this, [&](int result) {});

dlg->exec();
}
Expand All @@ -310,7 +312,7 @@ void MaterialDelegate::showArray2DModal(const QString& propertyName, QStandardIt

dlg->adjustSize();

//connect(dlg, &QDialog::finished, this, [&](int result) {});
// connect(dlg, &QDialog::finished, this, [&](int result) {});

dlg->exec();
}
Expand All @@ -324,7 +326,7 @@ void MaterialDelegate::showArray3DModal(const QString& propertyName, QStandardIt

dlg->adjustSize();

//connect(dlg, &QDialog::finished, this, [&](int result) {});
// connect(dlg, &QDialog::finished, this, [&](int result) {});

dlg->exec();
}
Expand Down
8 changes: 8 additions & 0 deletions src/Mod/Material/Resources/Models/Thermal/Thermal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,11 @@ Model:
Description: >
Thermal expansion coefficient (linear) in [FreeCAD
ThermalExpansionCoefficient unit]
ThermalExpansionReferenceTemperature:
DisplayName: "Thermal Expansion Reference Temperature"
Type: 'Quantity'
Units: 'K'
URL: ''
Description: >
The reference temperature is the temperature at which zero thermal
strains exist for the analysis.
2 changes: 1 addition & 1 deletion src/Mod/Material/materialtests/TestMaterials.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def testCalculiXSteel(self):

self.assertTrue(steel.isPhysicalModelComplete(self.uuids.Density))
self.assertFalse(steel.isPhysicalModelComplete(self.uuids.IsotropicLinearElastic))
self.assertTrue(steel.isPhysicalModelComplete(self.uuids.Thermal))
self.assertFalse(steel.isPhysicalModelComplete(self.uuids.Thermal))
self.assertFalse(steel.isPhysicalModelComplete(self.uuids.LinearElastic))
self.assertTrue(steel.isAppearanceModelComplete(self.uuids.BasicRendering))

Expand Down
2 changes: 1 addition & 1 deletion tests/src/Mod/Material/App/TestMaterials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ TEST_F(TestMaterial, TestCalculiXSteel)

EXPECT_TRUE(steel->isPhysicalModelComplete(Materials::ModelUUIDs::ModelUUID_Mechanical_Density)); // Density
EXPECT_FALSE(steel->isPhysicalModelComplete(Materials::ModelUUIDs::ModelUUID_Mechanical_IsotropicLinearElastic)); // IsotropicLinearElastic - incomplete
EXPECT_TRUE(steel->isPhysicalModelComplete(Materials::ModelUUIDs::ModelUUID_Thermal_Default)); // Thermal
EXPECT_FALSE(steel->isPhysicalModelComplete(Materials::ModelUUIDs::ModelUUID_Thermal_Default)); // Thermal
EXPECT_FALSE(steel->isPhysicalModelComplete(Materials::ModelUUIDs::ModelUUID_Mechanical_LinearElastic)); // Legacy linear elastic - Not in the model
EXPECT_TRUE(steel->isAppearanceModelComplete(Materials::ModelUUIDs::ModelUUID_Rendering_Basic)); // BasicRendering - inherited from Steel.FCMat

Expand Down

0 comments on commit 57c66a9

Please sign in to comment.