FEM: nonlinear material, fix selection for adding one

This commit is contained in:
Bernd Hahnebach
2020-01-22 17:33:15 +01:00
parent c5321691dc
commit 9e73609518
2 changed files with 19 additions and 20 deletions

View File

@@ -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."

View File

@@ -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"):