Skip to content

Commit

Permalink
FEM: nonlinear material, fix selection for adding one
Browse files Browse the repository at this point in the history
  • Loading branch information
berndhahnebach committed Jan 22, 2020
1 parent c532169 commit 9e73609
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
19 changes: 18 additions & 1 deletion src/Mod/Fem/femcommands/commands.py
Expand Up @@ -510,9 +510,26 @@ def __init__(self):
"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."
Expand Down
20 changes: 1 addition & 19 deletions src/Mod/Fem/femcommands/manager.py
Expand Up @@ -104,12 +104,11 @@ def IsActive(self):
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 = (
Expand Down Expand Up @@ -204,23 +203,6 @@ def material_solid_selected(self):
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"):
Expand Down

0 comments on commit 9e73609

Please sign in to comment.