From 0327a0987909758bbcb9974f914216be045c4973 Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Tue, 14 Sep 2021 00:33:27 -0400 Subject: [PATCH] [FEM] Add backward compatibility for simple hardening Prior to a recent commit (or this, if squashed), yield points of a non-linear material with simple hardening were stored as three different properties. These changes consolidate them into the new `YieldPoints` property. --- .../material_mechanicalnonlinear.py | 79 +++++++++++++------ 1 file changed, 56 insertions(+), 23 deletions(-) diff --git a/src/Mod/Fem/femobjects/material_mechanicalnonlinear.py b/src/Mod/Fem/femobjects/material_mechanicalnonlinear.py index 8aa8b3b577..c95296dd66 100644 --- a/src/Mod/Fem/femobjects/material_mechanicalnonlinear.py +++ b/src/Mod/Fem/femobjects/material_mechanicalnonlinear.py @@ -41,29 +41,62 @@ class MaterialMechanicalNonlinear(base_fempythonobject.BaseFemPythonObject): def __init__(self, obj): super(MaterialMechanicalNonlinear, self).__init__(obj) + self.add_properties(obj) - obj.addProperty( - "App::PropertyLink", - "LinearBaseMaterial", - "Base", - "Set the linear material the nonlinear builds upon." - ) + def onDocumentRestored(self, obj): - choices_nonlinear_material_models = ["simple hardening"] - obj.addProperty( - "App::PropertyEnumeration", - "MaterialModelNonlinearity", - "Fem", - "Set the type on nonlinear material model" - ) - obj.MaterialModelNonlinearity = choices_nonlinear_material_models - obj.MaterialModelNonlinearity = choices_nonlinear_material_models[0] + # YieldPoints was (until 0.19) stored as 3 separate variables. Consolidate them if present. + yield_points = [] + if hasattr(obj, "YieldPoint1"): + if obj.YieldPoint1: + yield_points.append(obj.YieldPoint1) + obj.removeProperty("YieldPoint1") + if hasattr(obj, "YieldPoint2"): + if obj.YieldPoint2: + yield_points.append(obj.YieldPoint2) + obj.removeProperty("YieldPoint2") + if hasattr(obj, "YieldPoint3"): + if obj.YieldPoint3: + yield_points.append(obj.YieldPoint3) + obj.removeProperty("YieldPoint3") - obj.addProperty( - "App::PropertyStringList", - "YieldPoints", - "Fem", - "Set stress and strain for yield points as a list of strings, " - "each point \"stress, plastic strain\"" - ) - obj.YieldPoints = [] + self.add_properties(obj) + if yield_points: + obj.YieldPoints = yield_points + + # TODO: If in the future more nonlinear options are added, update choices here. + + def add_properties(self, obj): + + # this method is called from onDocumentRestored + # thus only add and or set a attribute + # if the attribute does not exist + + if not hasattr(obj, "LinearBaseMaterial"): + obj.addProperty( + "App::PropertyLink", + "LinearBaseMaterial", + "Base", + "Set the linear material the nonlinear builds upon." + ) + + if not hasattr(obj, "MaterialModelNonlinearity"): + choices_nonlinear_material_models = ["simple hardening"] + obj.addProperty( + "App::PropertyEnumeration", + "MaterialModelNonlinearity", + "Fem", + "Set the type on nonlinear material model" + ) + obj.MaterialModelNonlinearity = choices_nonlinear_material_models + obj.MaterialModelNonlinearity = choices_nonlinear_material_models[0] + + if not hasattr(obj, "YieldPoints"): + obj.addProperty( + "App::PropertyStringList", + "YieldPoints", + "Fem", + "Set stress and strain for yield points as a list of strings, " + "each point \"stress, plastic strain\"" + ) + obj.YieldPoints = []