From 9e736095187450812e16ff9b92b6839e578f5506 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Wed, 22 Jan 2020 17:33:15 +0100 Subject: [PATCH] FEM: nonlinear material, fix selection for adding one --- src/Mod/Fem/femcommands/commands.py | 19 ++++++++++++++++++- src/Mod/Fem/femcommands/manager.py | 20 +------------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/Mod/Fem/femcommands/commands.py b/src/Mod/Fem/femcommands/commands.py index 417eaee5a4..897b981239 100644 --- a/src/Mod/Fem/femcommands/commands.py +++ b/src/Mod/Fem/femcommands/commands.py @@ -510,9 +510,26 @@ class _MaterialMechanicalNonlinear(CommandManager): "Creates a nonlinear mechanical material" ) } - self.is_active = "with_material_solid_which_has_no_nonlinear_material" + self.is_active = "with_material_solid" def Activated(self): + # test if there is a nonlinear material which has the selected material as base material + for o in self.selobj.Document.Objects: + if ( + hasattr(o, "Proxy") + and o.Proxy is not None + and hasattr(o.Proxy, "Type") + and o.Proxy.Type == "Fem::MaterialMechanicalNonlinear" + and o.LinearBaseMaterial == self.selobj + ): + FreeCAD.Console.PrintError( + "Nonlinear material {} is based on the selected material {}. " + "Only one nonlinear object allowed for each material.\n" + .format(o.Name, self.selobj.Name) + ) + return + + # add a nonlinear material string_lin_mat_obj = "FreeCAD.ActiveDocument.getObject('" + self.selobj.Name + "')" command_to_run = ( "FemGui.getActiveAnalysis().addObject(ObjectsFem." diff --git a/src/Mod/Fem/femcommands/manager.py b/src/Mod/Fem/femcommands/manager.py index 4dffc3aa8e..0aac948218 100644 --- a/src/Mod/Fem/femcommands/manager.py +++ b/src/Mod/Fem/femcommands/manager.py @@ -104,12 +104,11 @@ class CommandManager(object): and self.active_analysis_in_active_doc() and self.material_selected() ) - elif self.is_active == "with_material_solid_which_has_no_nonlinear_material": + elif self.is_active == "with_material_solid": active = ( FemGui.getActiveAnalysis() is not None and self.active_analysis_in_active_doc() and self.material_solid_selected() - and self.has_no_nonlinear_material() ) elif self.is_active == "with_solver": active = ( @@ -204,23 +203,6 @@ class CommandManager(object): else: return False - def has_no_nonlinear_material(self): - "check if an nonlinear material exists which is already based on the selected material" - for o in FreeCAD.ActiveDocument.Objects: - if ( - hasattr(o, "Proxy") - and o.Proxy is not None - and o.Proxy.Type == "Fem::MaterialMechanicalNonlinear" - and o.LinearBaseMaterial == self.selobj - ): - FreeCAD.Console.PrintError( - "{} is based on the selected material: {}. " - "Only one nonlinear object for each material allowed.\n" - .format(o.Name, self.selobj) - ) - return False - return True - def with_femmesh_andor_res_selected(self): sel = FreeCADGui.Selection.getSelection() if len(sel) == 1 and sel[0].isDerivedFrom("Fem::FemMeshObject"):