diff --git a/src/Mod/Fem/App/CMakeLists.txt b/src/Mod/Fem/App/CMakeLists.txt index e60d831b1..8f14d2570 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 de3db2455..5feb2383e 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 000000000..c0cc4013b --- /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 1fad27b36..403e689c0 100644 --- a/src/Mod/Fem/_TaskPanelFemBeamSection.py +++ b/src/Mod/Fem/_TaskPanelFemBeamSection.py @@ -86,7 +86,9 @@ class _TaskPanelFemBeamSection: # 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 @@ class _TaskPanelFemBeamSection: 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 e507f3b9d..10da5c642 100644 --- a/src/Mod/Fem/_TaskPanelFemShellThickness.py +++ b/src/Mod/Fem/_TaskPanelFemShellThickness.py @@ -86,7 +86,9 @@ class _TaskPanelFemShellThickness: # 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 @@ class _TaskPanelFemShellThickness: 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)