From ba394818a35cd8a277cf36ba823cab7d83a3af9c Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Mon, 9 Nov 2015 07:06:16 +0100 Subject: [PATCH] FEM: separate selection observer class from _TaskPanel shellthickness and beamsection --- src/Mod/Fem/App/CMakeLists.txt | 1 + src/Mod/Fem/CMakeLists.txt | 1 + src/Mod/Fem/SelectionObserverFem.py | 44 ++++++++++++++++++++++ src/Mod/Fem/_TaskPanelFemBeamSection.py | 19 ++-------- src/Mod/Fem/_TaskPanelFemShellThickness.py | 19 ++-------- 5 files changed, 52 insertions(+), 32 deletions(-) create mode 100644 src/Mod/Fem/SelectionObserverFem.py diff --git a/src/Mod/Fem/App/CMakeLists.txt b/src/Mod/Fem/App/CMakeLists.txt index e60d831b1ee7..8f14d25706c3 100755 --- a/src/Mod/Fem/App/CMakeLists.txt +++ b/src/Mod/Fem/App/CMakeLists.txt @@ -103,6 +103,7 @@ SET(FemScripts_SRCS FemTools.py MechanicalAnalysis.py MechanicalMaterial.py + SelectionObserverFem.py TestFem.py TaskPanelFemBeamSection.ui diff --git a/src/Mod/Fem/CMakeLists.txt b/src/Mod/Fem/CMakeLists.txt index de3db2455582..5feb2383e993 100755 --- a/src/Mod/Fem/CMakeLists.txt +++ b/src/Mod/Fem/CMakeLists.txt @@ -14,6 +14,7 @@ INSTALL( convert2TetGen.py FemExample.py + SelectionObserverFem.py TestFem.py ccxDatReader.py diff --git a/src/Mod/Fem/SelectionObserverFem.py b/src/Mod/Fem/SelectionObserverFem.py new file mode 100644 index 000000000000..c0cc4013bd35 --- /dev/null +++ b/src/Mod/Fem/SelectionObserverFem.py @@ -0,0 +1,44 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2015 - Bernd Hahnebach * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +__title__ = "SelectionObserverFem" +__author__ = "Bernd Hahnebach" +__url__ = "http://www.freecadweb.org" + + +import FreeCAD +import FreeCADGui + + +class SelectionObserverFem: + '''SelectionObserverFem''' + def __init__(self, parseSelectionFunction, print_message=''): + self.parseSelectionFunction = parseSelectionFunction + FreeCADGui.Selection.addObserver(self) + FreeCAD.Console.PrintMessage(print_message + "!\n") + + def addSelection(self, docName, objName, sub, pos): + selected_object = FreeCAD.getDocument(docName).getObject(objName) # get the obj objName + self.added_obj = (selected_object, sub) + + if sub: # on doubleClick the solid is selected and sub will be empty + self.parseSelectionFunction(self.added_obj) diff --git a/src/Mod/Fem/_TaskPanelFemBeamSection.py b/src/Mod/Fem/_TaskPanelFemBeamSection.py index 1fad27b36191..403e689c00d4 100644 --- a/src/Mod/Fem/_TaskPanelFemBeamSection.py +++ b/src/Mod/Fem/_TaskPanelFemBeamSection.py @@ -86,7 +86,9 @@ def add_references(self): # here the addReference button EditTaskPanel has to be triggered to start selection mode FreeCADGui.Selection.clearSelection() # start SelectionObserver and parse the function to add the References to the widget - self.sel_server = ReferenceShapeSelectionObserver(self.selectionParser) + print_message = "Select Edges by single click on them to add them to the list" + import SelectionObserverFem + self.sel_server = SelectionObserverFem.SelectionObserverFem(self.selectionParser, print_message) def selectionParser(self, selection): # print('selection: ', selection[0].Shape.ShapeType, ' ', selection[0].Name, ' ', selection[1]) @@ -109,18 +111,3 @@ def rebuild_list_References(self): items.append(item_name) for listItemName in sorted(items): self.form.list_References.addItem(listItemName) - - -class ReferenceShapeSelectionObserver: - '''ReferenceShapeSelectionObserver - started on click button addReference''' - def __init__(self, parseSelectionFunction): - self.parseSelectionFunction = parseSelectionFunction - FreeCADGui.Selection.addObserver(self) - FreeCAD.Console.PrintMessage("Select Faces to add them to the list!\n") - - def addSelection(self, docName, objName, sub, pos): - selected_object = FreeCAD.getDocument(docName).getObject(objName) # get the obj objName - self.added_obj = (selected_object, sub) - if sub: # on doubleClick the solid is selected and sub will be empty - self.parseSelectionFunction(self.added_obj) diff --git a/src/Mod/Fem/_TaskPanelFemShellThickness.py b/src/Mod/Fem/_TaskPanelFemShellThickness.py index e507f3b9de31..10da5c642b39 100644 --- a/src/Mod/Fem/_TaskPanelFemShellThickness.py +++ b/src/Mod/Fem/_TaskPanelFemShellThickness.py @@ -86,7 +86,9 @@ def add_references(self): # here the addReference button EditTaskPanel has to be triggered to start selection mode FreeCADGui.Selection.clearSelection() # start SelectionObserver and parse the function to add the References to the widget - self.sel_server = ReferenceShapeSelectionObserver(self.selectionParser) + print_message = "Select Faces by single click on them to add them to the list" + import SelectionObserverFem + self.sel_server = SelectionObserverFem.SelectionObserverFem(self.selectionParser, print_message) def selectionParser(self, selection): # print('selection: ', selection[0].Shape.ShapeType, ' ', selection[0].Name, ' ', selection[1]) @@ -109,18 +111,3 @@ def rebuild_list_References(self): items.append(item_name) for listItemName in sorted(items): self.form.list_References.addItem(listItemName) - - -class ReferenceShapeSelectionObserver: - '''ReferenceShapeSelectionObserver - started on click button addReference''' - def __init__(self, parseSelectionFunction): - self.parseSelectionFunction = parseSelectionFunction - FreeCADGui.Selection.addObserver(self) - FreeCAD.Console.PrintMessage("Select Faces to add them to the list!\n") - - def addSelection(self, docName, objName, sub, pos): - selected_object = FreeCAD.getDocument(docName).getObject(objName) # get the obj objName - self.added_obj = (selected_object, sub) - if sub: # on doubleClick the solid is selected and sub will be empty - self.parseSelectionFunction(self.added_obj)