Repository: FreeCAD/FreeCAD
File: src/Mod/Fem/femcommands/commands.py (Python)

Code before:

    def __init__(self):
        super().__init__()
        self.menutext = Qt.QT_TRANSLATE_NOOP("FEM_MaterialFluid", "Fluid Material")
        self.tooltip = Qt.QT_TRANSLATE_NOOP("FEM_MaterialFluid", "Creates a fluid material")
        self.is_active = "with_analysis"
        self.do_activated = "add_obj_on_gui_set_edit"


class _MaterialMechanicalNonlinear(CommandManager):
    "The FEM_MaterialMechanicalNonlinear command definition"

    def __init__(self):
        super().__init__()
        self.menutext = Qt.QT_TRANSLATE_NOOP(
            "FEM_MaterialMechanicalNonlinear", "Non-Linear Mechanical Material"
        )
        self.tooltip = Qt.QT_TRANSLATE_NOOP(
            "FEM_MaterialMechanicalNonlinear", "Add non-linear mechanical properties to material"
        )

    def IsActive(self):
        if self.material_solid_selected() and (self.selobj.Nonlinear is None):
            return True
        else:
            return False

    def Activated(self):
        # add a nonlinear material
        FreeCAD.ActiveDocument.openTransaction("Create FemMaterialMechanicalNonlinear")
        FreeCADGui.addModule("ObjectsFem")
        lin_mat_obj = f"FreeCAD.ActiveDocument.getObject('{self.selobj.Name}')"
        command_to_run = (
            f"ObjectsFem.makeMaterialMechanicalNonlinear(FreeCAD.ActiveDocument, {lin_mat_obj})"
        )
        FreeCADGui.doCommand(command_to_run)

        expandParentObject()
        FreeCAD.ActiveDocument.commitTransaction()
        FreeCADGui.Selection.clearSelection()
        FreeCAD.ActiveDocument.recompute()


class _MaterialReinforced(CommandManager):
    "The FEM_MaterialReinforced command definition"

    def __init__(self):
        super().__init__()
        self.menutext = Qt.QT_TRANSLATE_NOOP(
            "FEM_MaterialReinforced", "Reinforced Material (Concrete)"
        )

Review comment (suggestion):
```suggestion
        return self.material_solid_selected() and (self.selobj.Nonlinear is None)
```

Code after:

    def __init__(self):
        super().__init__()
        self.menutext = Qt.QT_TRANSLATE_NOOP("FEM_MaterialFluid", "Fluid Material")
        self.tooltip = Qt.QT_TRANSLATE_NOOP("FEM_MaterialFluid", "Creates a fluid material")
        self.is_active = "with_analysis"
        self.do_activated = "add_obj_on_gui_set_edit"


class _MaterialMechanicalNonlinear(CommandManager):
    "The FEM_MaterialMechanicalNonlinear command definition"

    def __init__(self):
        super().__init__()
        self.menutext = Qt.QT_TRANSLATE_NOOP(
            "FEM_MaterialMechanicalNonlinear", "Non-Linear Mechanical Material"
        )
        self.tooltip = Qt.QT_TRANSLATE_NOOP(
            "FEM_MaterialMechanicalNonlinear", "Add non-linear mechanical properties to material"
        )

    def IsActive(self):
        return self.material_solid_selected() and (self.selobj.Nonlinear is None)

    def Activated(self):
        # add a nonlinear material
        FreeCAD.ActiveDocument.openTransaction("Create FemMaterialMechanicalNonlinear")
        FreeCADGui.addModule("ObjectsFem")
        lin_mat_obj = f"FreeCAD.ActiveDocument.getObject('{self.selobj.Name}')"
        command_to_run = (
            f"ObjectsFem.makeMaterialMechanicalNonlinear(FreeCAD.ActiveDocument, {lin_mat_obj})"
        )
        FreeCADGui.doCommand(command_to_run)

        expandParentObject()
        FreeCAD.ActiveDocument.commitTransaction()
        FreeCADGui.Selection.clearSelection()
        FreeCAD.ActiveDocument.recompute()


class _MaterialReinforced(CommandManager):
    "The FEM_MaterialReinforced command definition"

    def __init__(self):
        super().__init__()
        self.menutext = Qt.QT_TRANSLATE_NOOP(
            "FEM_MaterialReinforced", "Reinforced Material (Concrete)"
        )
        self.tooltip = Qt.QT_TRANSLATE_NOOP(
            "FEM_MaterialReinforced",
            "Creates a material for reinforced matrix material such as concrete",