diff --git a/src/Mod/Fem/femcommands/commands.py b/src/Mod/Fem/femcommands/commands.py index bc8dbe14c599..79c2ec641516 100644 --- a/src/Mod/Fem/femcommands/commands.py +++ b/src/Mod/Fem/femcommands/commands.py @@ -158,13 +158,7 @@ def __init__(self): self.is_active = 'with_analysis' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create FemConstraintBodyHeatSource") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "FemGui.getActiveAnalysis().addObject(ObjectsFem." - "makeConstraintBodyHeatSource(FreeCAD.ActiveDocument))" - ) - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_noset_edit(self.__class__.__name__.lstrip("_")) class _ConstraintElectrostaticPotential(CommandManager): @@ -182,17 +176,7 @@ def __init__(self): self.is_active = 'with_analysis' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create FemConstraintElectrostaticPotential") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "FemGui.getActiveAnalysis().addObject(ObjectsFem." - "makeConstraintElectrostaticPotential(FreeCAD.ActiveDocument))" - ) - FreeCADGui.doCommand( - "FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)" - ) - FreeCADGui.Selection.clearSelection() - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_set_edit(self.__class__.__name__.lstrip("_")) class _ConstraintFlowVelocity(CommandManager): @@ -210,17 +194,7 @@ def __init__(self): self.is_active = 'with_analysis' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create FemConstraintFlowVelocity") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "FemGui.getActiveAnalysis().addObject(ObjectsFem." - "makeConstraintFlowVelocity(FreeCAD.ActiveDocument))" - ) - FreeCADGui.doCommand( - "FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)" - ) - FreeCADGui.Selection.clearSelection() - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_set_edit(self.__class__.__name__.lstrip("_")) class _ConstraintInitialFlowVelocity(CommandManager): @@ -238,17 +212,7 @@ def __init__(self): self.is_active = 'with_analysis' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create FemConstraintInitialFlowVelocity") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "FemGui.getActiveAnalysis().addObject(ObjectsFem." - "makeConstraintInitialFlowVelocity(FreeCAD.ActiveDocument))" - ) - FreeCADGui.doCommand( - "FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)" - ) - FreeCADGui.Selection.clearSelection() - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_set_edit(self.__class__.__name__.lstrip("_")) class _ConstraintSelfWeight(CommandManager): @@ -270,13 +234,7 @@ def __init__(self): self.is_active = 'with_analysis' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create FemConstraintSelfWeight") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "FemGui.getActiveAnalysis().addObject(ObjectsFem." - "makeConstraintSelfWeight(FreeCAD.ActiveDocument))" - ) - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_noset_edit(self.__class__.__name__.lstrip("_")) class _ElementFluid1D(CommandManager): @@ -298,17 +256,7 @@ def __init__(self): self.is_active = 'with_analysis' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create FemElementFluid1D") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "FemGui.getActiveAnalysis().addObject(ObjectsFem." - "makeElementFluid1D(FreeCAD.ActiveDocument))" - ) - FreeCADGui.doCommand( - "FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)" - ) - FreeCADGui.Selection.clearSelection() - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_set_edit(self.__class__.__name__.lstrip("_")) class _ElementGeometry1D(CommandManager): @@ -330,17 +278,7 @@ def __init__(self): self.is_active = 'with_analysis' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create FemElementGeometry1D") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "FemGui.getActiveAnalysis().addObject(ObjectsFem." - "makeElementGeometry1D(FreeCAD.ActiveDocument))" - ) - FreeCADGui.doCommand( - "FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)" - ) - FreeCADGui.Selection.clearSelection() - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_set_edit(self.__class__.__name__.lstrip("_")) class _ElementGeometry2D(CommandManager): @@ -362,16 +300,7 @@ def __init__(self): self.is_active = 'with_analysis' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create FemElementGeometry2D") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "FemGui.getActiveAnalysis().addObject(ObjectsFem." - "makeElementGeometry2D(FreeCAD.ActiveDocument))") - FreeCADGui.doCommand( - "FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)" - ) - FreeCADGui.Selection.clearSelection() - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_set_edit(self.__class__.__name__.lstrip("_")) class _ElementRotation1D(CommandManager): @@ -393,17 +322,7 @@ def __init__(self): self.is_active = 'with_analysis' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create FemElementRotation1D") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "FemGui.getActiveAnalysis().addObject(ObjectsFem." - "makeElementRotation1D(FreeCAD.ActiveDocument))" - ) - FreeCADGui.doCommand( - "FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)" - ) - FreeCADGui.Selection.clearSelection() - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_noset_edit(self.__class__.__name__.lstrip("_")) class _EquationElectrostatic(CommandManager): @@ -424,15 +343,7 @@ def __init__(self): self.is_active = 'with_solver_elmer' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create FemEquationElasticity") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "ObjectsFem.makeEquationElectrostatic(" - "FreeCAD.ActiveDocument, FreeCAD.ActiveDocument.{})" - .format(self.selobj.Name) - ) - FreeCADGui.Selection.clearSelection() - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_selobj_noset_edit(self.__class__.__name__.lstrip("_")) class _EquationElasticity(CommandManager): @@ -452,15 +363,7 @@ def __init__(self): self.is_active = 'with_solver_elmer' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create FemEquationElasticity") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "ObjectsFem.makeEquationElasticity(" - "FreeCAD.ActiveDocument, FreeCAD.ActiveDocument.{})" - .format(self.selobj.Name) - ) - FreeCADGui.Selection.clearSelection() - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_selobj_noset_edit(self.__class__.__name__.lstrip("_")) class _EquationFlow(CommandManager): @@ -481,15 +384,7 @@ def __init__(self): self.is_active = 'with_solver_elmer' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create FemEquationFlow") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "ObjectsFem.makeEquationFlow(" - "FreeCAD.ActiveDocument, FreeCAD.ActiveDocument.{})" - .format(self.selobj.Name) - ) - FreeCADGui.Selection.clearSelection() - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_selobj_noset_edit(self.__class__.__name__.lstrip("_")) class _EquationFluxsolver(CommandManager): @@ -510,15 +405,7 @@ def __init__(self): self.is_active = 'with_solver_elmer' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create FemEquationFluxsolver") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "ObjectsFem.makeEquationFluxsolver(" - "FreeCAD.ActiveDocument, FreeCAD.ActiveDocument.{})" - .format(self.selobj.Name) - ) - FreeCADGui.Selection.clearSelection() - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_selobj_noset_edit(self.__class__.__name__.lstrip("_")) class _EquationHeat(CommandManager): @@ -539,15 +426,7 @@ def __init__(self): self.is_active = 'with_solver_elmer' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create FemEquationHeat") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "ObjectsFem.makeEquationHeat(" - "FreeCAD.ActiveDocument, FreeCAD.ActiveDocument.{})" - .format(self.selobj.Name) - ) - FreeCADGui.Selection.clearSelection() - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_selobj_noset_edit(self.__class__.__name__.lstrip("_")) class _MaterialEditor(CommandManager): @@ -592,16 +471,7 @@ def __init__(self): self.is_active = 'with_analysis' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create Fluid Material") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "FemGui.getActiveAnalysis().addObject(ObjectsFem." - "makeMaterialFluid(FreeCAD.ActiveDocument, 'FluidMaterial'))" - ) - FreeCADGui.doCommand( - "FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)" - ) - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_set_edit(self.__class__.__name__.lstrip("_")) class _MaterialMechanicalNonlinear(CommandManager): @@ -684,16 +554,7 @@ def __init__(self): self.is_active = 'with_analysis' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create Reinforced Material") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "FemGui.getActiveAnalysis().addObject(ObjectsFem." - "makeMaterialReinforced(FreeCAD.ActiveDocument, 'ReinforcedMaterial'))" - ) - FreeCADGui.doCommand( - "FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)" - ) - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_set_edit(self.__class__.__name__.lstrip("_")) class _MaterialSolid(CommandManager): @@ -715,16 +576,7 @@ def __init__(self): self.is_active = 'with_analysis' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create Solid Material") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "FemGui.getActiveAnalysis().addObject(ObjectsFem." - "makeMaterialSolid(FreeCAD.ActiveDocument, 'SolidMaterial'))" - ) - FreeCADGui.doCommand( - "FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)" - ) - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_set_edit(self.__class__.__name__.lstrip("_")) class _Mesh2Mesh(CommandManager): @@ -795,18 +647,7 @@ def __init__(self): self.is_active = 'with_gmsh_femmesh' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create FemMeshBoundaryLayer") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "ObjectsFem.makeMeshBoundaryLayer(" - "FreeCAD.ActiveDocument, FreeCAD.ActiveDocument.{})" - .format(self.selobj.Name) - ) - FreeCADGui.doCommand( - "FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)" - ) - FreeCADGui.Selection.clearSelection() - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_selobj_set_edit(self.__class__.__name__.lstrip("_")) class _MeshClear(CommandManager): @@ -934,18 +775,7 @@ def __init__(self): self.is_active = 'with_gmsh_femmesh' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create FemMeshGroup") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "ObjectsFem.makeMeshGroup(" - "FreeCAD.ActiveDocument, FreeCAD.ActiveDocument.{})" - .format(self.selobj.Name) - ) - FreeCADGui.doCommand( - "FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)" - ) - FreeCADGui.Selection.clearSelection() - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_selobj_set_edit(self.__class__.__name__.lstrip("_")) class _MeshNetgenFromShape(CommandManager): @@ -1014,18 +844,7 @@ def __init__(self): self.is_active = 'with_gmsh_femmesh' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create FemMeshRegion") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "ObjectsFem.makeMeshRegion(" - "FreeCAD.ActiveDocument, FreeCAD.ActiveDocument.{})" - .format(self.selobj.Name) - ) - FreeCADGui.doCommand( - "FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)" - ) - FreeCADGui.Selection.clearSelection() - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_selobj_set_edit(self.__class__.__name__.lstrip("_")) class _ResultShow(CommandManager): @@ -1133,14 +952,7 @@ def __init__(self): self.is_active = 'with_analysis' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create CalculiX solver object") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "FemGui.getActiveAnalysis().addObject(ObjectsFem." - "makeSolverCalculix(FreeCAD.ActiveDocument))" - ) - FreeCAD.ActiveDocument.commitTransaction() - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_noset_edit(self.__class__.__name__.lstrip("_")) class _SolverControl(CommandManager): @@ -1184,14 +996,7 @@ def __init__(self): self.is_active = 'with_analysis' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create Elmer solver object") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "FemGui.getActiveAnalysis().addObject(ObjectsFem." - "makeSolverElmer(FreeCAD.ActiveDocument))" - ) - FreeCAD.ActiveDocument.commitTransaction() - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_noset_edit(self.__class__.__name__.lstrip("_")) class _SolverRun(CommandManager): @@ -1238,12 +1043,7 @@ def __init__(self): self.is_active = 'with_analysis' def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create SolverZ88") - FreeCADGui.addModule("ObjectsFem") - FreeCADGui.doCommand( - "FemGui.getActiveAnalysis().addObject(ObjectsFem.makeSolverZ88(FreeCAD.ActiveDocument))" - ) - FreeCAD.ActiveDocument.recompute() + self.add_obj_on_gui_noset_edit(self.__class__.__name__.lstrip("_")) # the string in add command will be the page name on FreeCAD wiki diff --git a/src/Mod/Fem/femcommands/manager.py b/src/Mod/Fem/femcommands/manager.py index 9b3ac01e4b1e..ada698b1217c 100644 --- a/src/Mod/Fem/femcommands/manager.py +++ b/src/Mod/Fem/femcommands/manager.py @@ -262,4 +262,79 @@ def hide_meshes_show_parts_constraints(self): # e.g. on purging results acnstrmesh.ViewObject.Visibility = False + # **************************************************************************************** + # methods to add the objects to the document in FreeCADGui mode + + def add_obj_on_gui_set_edit(self, objtype): + FreeCAD.ActiveDocument.openTransaction( + "Create Fem{}" + .format(objtype) + ) + FreeCADGui.addModule( + "ObjectsFem" + ) + FreeCADGui.doCommand( + "FemGui.getActiveAnalysis().addObject(ObjectsFem." + "make{}(FreeCAD.ActiveDocument))" + .format(objtype) + ) + # no other obj should be selected if we go in task panel + FreeCADGui.Selection.clearSelection() + FreeCADGui.doCommand( + "FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)" + ) + FreeCAD.ActiveDocument.recompute() + + def add_obj_on_gui_noset_edit(self, objtype): + FreeCAD.ActiveDocument.openTransaction( + "Create Fem{}" + .format(objtype) + ) + FreeCADGui.addModule( + "ObjectsFem" + ) + FreeCADGui.doCommand( + "FemGui.getActiveAnalysis().addObject(ObjectsFem." + "make{}(FreeCAD.ActiveDocument))" + .format(objtype) + ) + # FreeCAD.ActiveDocument.commitTransaction() # solver command class had this line + # no clear selection is done + FreeCAD.ActiveDocument.recompute() + + def add_obj_on_gui_selobj_set_edit(self, objtype): + FreeCAD.ActiveDocument.openTransaction( + "Create Fem{}" + .format(objtype) + ) + FreeCADGui.addModule( + "ObjectsFem" + ) + FreeCADGui.doCommand( + "ObjectsFem.make{}(" + "FreeCAD.ActiveDocument, FreeCAD.ActiveDocument.{})" + .format(objtype, self.selobj.Name) + ) + FreeCADGui.Selection.clearSelection() + FreeCADGui.doCommand( + "FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)" + ) + FreeCAD.ActiveDocument.recompute() + + def add_obj_on_gui_selobj_noset_edit(self, objtype): + FreeCAD.ActiveDocument.openTransaction( + "Create Fem{}" + .format(objtype) + ) + FreeCADGui.addModule( + "ObjectsFem" + ) + FreeCADGui.doCommand( + "ObjectsFem.make{}(" + "FreeCAD.ActiveDocument, FreeCAD.ActiveDocument.{})" + .format(objtype, self.selobj.Name) + ) + FreeCADGui.Selection.clearSelection() + FreeCAD.ActiveDocument.recompute() + ## @}