From 249829913bc6c01fd7811c0fee4d01291fdb26d9 Mon Sep 17 00:00:00 2001 From: Uwe Date: Fri, 24 Mar 2023 06:48:14 +0100 Subject: [PATCH] [FEM] implement further object addition mode - for e.g. the solver objects it is important that the added equations are visible in the TreeView - also improve activation of analyses for documents with multiple analyses: one activates one and can then subsequently add an object to it because the activation will also select --- src/Mod/Fem/Gui/ViewProviderAnalysis.cpp | 14 ++++----- src/Mod/Fem/femcommands/commands.py | 11 +++++--- src/Mod/Fem/femcommands/manager.py | 36 ++++++++++++++++++------ src/Mod/Fem/femtools/femutils.py | 10 +++++++ 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/src/Mod/Fem/Gui/ViewProviderAnalysis.cpp b/src/Mod/Fem/Gui/ViewProviderAnalysis.cpp index 49b2730609..7e734774db 100644 --- a/src/Mod/Fem/Gui/ViewProviderAnalysis.cpp +++ b/src/Mod/Fem/Gui/ViewProviderAnalysis.cpp @@ -109,13 +109,6 @@ void ViewProviderFemAnalysis::attach(App::DocumentObject *obj) auto *workbench = Gui::WorkbenchManager::instance()->active(); if (workbench->name() == "FemWorkbench") { doubleClicked(); - // indicate the activated analysis by selecting it - // especially useful for files with 2 or more analyses but also - // necessary for the workflow with new files to add a solver as next object - std::vector selVector {}; - selVector.push_back(this->getObject()); - auto docName = this->getObject()->getDocument()->getName(); - Gui::Selection().setSelection(docName, selVector); } } @@ -134,6 +127,13 @@ bool ViewProviderFemAnalysis::doubleClicked(void) // After activation of the analysis the allowed FEM toolbar buttons should become active. // To achieve this we must clear the object selection to trigger the selection observer. Gui::Command::doCommand(Gui::Command::Gui, "Gui.Selection.clearSelection()"); + // indicate the activated analysis by selecting it + // especially useful for files with 2 or more analyses but also + // necessary for the workflow with new files to add a solver as next object + std::vector selVector {}; + selVector.push_back(this->getObject()); + auto *docName = this->getObject()->getDocument()->getName(); + Gui::Selection().setSelection(docName, selVector); return true; } diff --git a/src/Mod/Fem/femcommands/commands.py b/src/Mod/Fem/femcommands/commands.py index f128de524d..66f1673248 100644 --- a/src/Mod/Fem/femcommands/commands.py +++ b/src/Mod/Fem/femcommands/commands.py @@ -35,6 +35,7 @@ from FreeCAD import Qt from .manager import CommandManager from femsolver import settings +from femtools.femutils import expandParentObject from femtools.femutils import is_of_type @@ -1074,6 +1075,8 @@ class _SolverCxxtools(CommandManager): "makeSolverCalculixCcxTools(FreeCAD.ActiveDocument))" ) FreeCAD.ActiveDocument.commitTransaction() + # expand analysis object in tree view + expandParentObject() FreeCAD.ActiveDocument.recompute() @@ -1094,7 +1097,7 @@ class _SolverCalculix(CommandManager): ) self.is_active = "with_analysis" self.is_active = "with_analysis" - self.do_activated = "add_obj_on_gui_noset_edit" + self.do_activated = "add_obj_on_gui_expand_noset_edit" class _SolverControl(CommandManager): @@ -1129,7 +1132,7 @@ class _SolverElmer(CommandManager): "Creates a FEM solver Elmer" ) self.is_active = "with_analysis" - self.do_activated = "add_obj_on_gui_noset_edit" + self.do_activated = "add_obj_on_gui_expand_noset_edit" class _SolverMystran(CommandManager): @@ -1142,7 +1145,7 @@ class _SolverMystran(CommandManager): self.accel = "S, M" self.tooltip = Qt.QT_TRANSLATE_NOOP("FEM_SolverMystran", "Creates a FEM solver Mystran") self.is_active = "with_analysis" - self.do_activated = "add_obj_on_gui_noset_edit" + self.do_activated = "add_obj_on_gui_expand_noset_edit" class _SolverRun(CommandManager): @@ -1174,7 +1177,7 @@ class _SolverZ88(CommandManager): self.accel = "S, Z" self.tooltip = Qt.QT_TRANSLATE_NOOP("FEM_SolverZ88", "Creates a FEM solver Z88") self.is_active = "with_analysis" - self.do_activated = "add_obj_on_gui_noset_edit" + self.do_activated = "add_obj_on_gui_expand_noset_edit" # 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 c19a122bd1..57b2f07b4b 100644 --- a/src/Mod/Fem/femcommands/manager.py +++ b/src/Mod/Fem/femcommands/manager.py @@ -32,6 +32,7 @@ __url__ = "https://www.freecadweb.org" import FreeCAD +from femtools.femutils import expandParentObject from femtools.femutils import is_of_type if FreeCAD.GuiUp: @@ -147,6 +148,8 @@ class CommandManager(object): def Activated(self): if self.do_activated == "add_obj_on_gui_noset_edit": self.add_obj_on_gui_noset_edit(self.__class__.__name__.lstrip("_")) + elif self.do_activated == "add_obj_on_gui_expand_noset_edit": + self.add_obj_on_gui_expand_noset_edit(self.__class__.__name__.lstrip("_")) elif self.do_activated == "add_obj_on_gui_set_edit": self.add_obj_on_gui_set_edit(self.__class__.__name__.lstrip("_")) elif self.do_activated == "add_obj_on_gui_selobj_noset_edit": @@ -341,6 +344,29 @@ class CommandManager(object): # no clear selection is done FreeCAD.ActiveDocument.recompute() + def add_obj_on_gui_expand_noset_edit(self, objtype): + # like add_obj_on_gui_noset_edit but the parent object + # is expanded in the tree to see the added obj + FreeCAD.ActiveDocument.openTransaction( + "Create Fem{}" + .format(objtype) + ) + FreeCADGui.addModule( + "ObjectsFem" + ) + FreeCADGui.addModule( + "FemGui" + ) + # expand parent obj in tree view if selected + expandParentObject() + # add the object + FreeCADGui.doCommand( + "addedObj = FemGui.getActiveAnalysis().addObject(ObjectsFem." + "make{}(FreeCAD.ActiveDocument))" + .format(objtype) + ) + FreeCAD.ActiveDocument.recompute() + def add_obj_on_gui_selobj_set_edit(self, objtype): FreeCAD.ActiveDocument.openTransaction( "Create Fem{}" @@ -378,7 +404,7 @@ class CommandManager(object): def add_obj_on_gui_selobj_expand_noset_edit(self, objtype): # like add_obj_on_gui_selobj_noset_edit but the selection is kept - # and the selobj view is expanded in the tree to see the added obj + # and the selobj is expanded in the tree to see the added obj FreeCAD.ActiveDocument.openTransaction( "Create Fem{}" .format(objtype) @@ -392,11 +418,5 @@ class CommandManager(object): .format(objtype, self.selobj.Name) ) # expand selobj in tree view - trees = FreeCADGui.getMainWindow().findChildren(QtGui.QTreeWidget) - for tree in trees: - items = tree.selectedItems() - if items == []: - continue - for item in items: - tree.expandItem(item) + expandParentObject() FreeCAD.ActiveDocument.recompute() diff --git a/src/Mod/Fem/femtools/femutils.py b/src/Mod/Fem/femtools/femutils.py index b48510ce01..fa7cddabd5 100644 --- a/src/Mod/Fem/femtools/femutils.py +++ b/src/Mod/Fem/femtools/femutils.py @@ -396,3 +396,13 @@ def startProgramInfo(code): info.wShowWindow = SW_DEFAULT info.dwFlags = subprocess.STARTF_USESHOWWINDOW return info + +def expandParentObject(): + """ expands parent and selected obj in tree view """ + trees = FreeCADGui.getMainWindow().findChildren(QtGui.QTreeWidget) + for tree in trees: + items = tree.selectedItems() + if items == []: + continue + for item in items: + tree.expandItem(item)