Dynamic change of object properties

About the development of the FEM module/workbench.

Moderator: bernd

Post Reply
sodelo
Posts: 73
Joined: Tue Jan 24, 2017 9:20 am

Dynamic change of object properties

Post by sodelo »

Hi,

I would like to enrich the definition of non linear materials. So I would like to dynamically modify the properties of the non linear material data.
The code would be something like this:

Code: Select all

class _FemMaterialMechanicalNonlinear:
    "The FemMaterialMechanicalNonlinear object"
    def __init__(self, obj):
        obj.Proxy = self
        self.Type = "FemMaterialMechanicalNonlinear"

        obj.addProperty("App::PropertyLink", "LinearBaseMaterial", "Base", "Set the linear material the nonlinear build uppon.")

       // Several choices of hardening model
        choices_nonlinear_material_models = ["isotropic hardening","kinematic hardening","combined"]
        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]

        // The following properties should change depending on the material model
        // however these are the properties at init 
        obj.addProperty("App::PropertyString", "YieldPoint1", "Fem", "Set stress and strain for yield point one, separated by a comma.")
        obj.YieldPoint1 = "235.0, 0.0"

        obj.addProperty("App::PropertyString", "YieldPoint2", "Fem", "Set stress and strain for yield point one, separated by a comma.")
        obj.YieldPoint2 = "241.0, 0.025"
        obj.addProperty("App::PropertyString", "YieldPoint3", "Fem", "Set stress and strain for yield point three, separated by a comma.")
        obj.YieldPoint3 = "250.0, 0.03"

    def execute(self, obj):
       // Depending on the choice, I want to add another property
        if obj.MaterialModelNonlinearity == choices_nonlinear_material_models[1]:
           obj.addProperty("App::PropertyString", "YieldPoint4", "Fem", "Set stress and strain for yield point three, separated by a comma.")
           obj.YieldPoint4 = "260.0, 0.04"
       // I should remove as well properties that are no more relevant:
           obj.RemoveProperty("App::PropertyString", "YieldPoint1"")
           
        return
This code however does not work, which is not suprising since there is a lot of guesses here.
What is the correct approach ?

BR

Sodelo
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Dynamic change of object properties

Post by DeepSOIC »

Maybe you should hide properties instead of removing them completely?
You say it doesn't work, but it will be easier to help if you say how exactly it doesn't work. E.g. you get error in report view. Or the property is not added. Or it is, but you don't see it in property editor.....
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Dynamic change of object properties

Post by bernd »

Good question sodelo. Two years ago I have been experimenting with such problem dynamic properties depending of a user choice. At that time it did not work as aspected. ATM there is some remove property but I have not used it so far.

For the profile definition in 1D element geometry object what we gone do is just add all properties and initialize them but only use the ones needed. See https://github.com/FreeCAD/FreeCAD/blob ... y1D.py#L37 It is a general question what is best for such objects ...

I agree with DeepSOIC and would not try to remove them.
sodelo
Posts: 73
Joined: Tue Jan 24, 2017 9:20 am

Re: Dynamic change of object properties

Post by sodelo »

Maybe this approach is not the correct one and a dialog box would be preferable to handle the different options. I am having a look at Qt Designer and at the way the material property dialog is defined. I may have some questions ....
Post Reply