Skip to content

Commit

Permalink
FEM: separate selection observer class from _TaskPanel shellthickness…
Browse files Browse the repository at this point in the history
… and beamsection
  • Loading branch information
berndhahnebach committed Nov 11, 2015
1 parent dc20525 commit ba39481
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/Mod/Fem/App/CMakeLists.txt
Expand Up @@ -103,6 +103,7 @@ SET(FemScripts_SRCS
FemTools.py
MechanicalAnalysis.py
MechanicalMaterial.py
SelectionObserverFem.py
TestFem.py

TaskPanelFemBeamSection.ui
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Fem/CMakeLists.txt
Expand Up @@ -14,6 +14,7 @@ INSTALL(
convert2TetGen.py
FemExample.py

SelectionObserverFem.py
TestFem.py

ccxDatReader.py
Expand Down
44 changes: 44 additions & 0 deletions src/Mod/Fem/SelectionObserverFem.py
@@ -0,0 +1,44 @@
# ***************************************************************************
# * *
# * Copyright (c) 2015 - Bernd Hahnebach <bernd@bimstatik.org> *
# * *
# * 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)
19 changes: 3 additions & 16 deletions src/Mod/Fem/_TaskPanelFemBeamSection.py
Expand Up @@ -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])
Expand All @@ -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)
19 changes: 3 additions & 16 deletions src/Mod/Fem/_TaskPanelFemShellThickness.py
Expand Up @@ -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])
Expand All @@ -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)

0 comments on commit ba39481

Please sign in to comment.