Skip to content

Commit

Permalink
FEM: use new selection observer class for material reference shape se…
Browse files Browse the repository at this point in the history
…lection
  • Loading branch information
berndhahnebach committed Nov 11, 2015
1 parent ba39481 commit c6989ac
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 42 deletions.
5 changes: 2 additions & 3 deletions src/Mod/Fem/SelectionObserverFem.py
Expand Up @@ -39,6 +39,5 @@ def __init__(self, parseSelectionFunction, print_message=''):
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)
# on double click on a vertex of a solid sub is None and obj is the solid
self.parseSelectionFunction(self.added_obj)
17 changes: 8 additions & 9 deletions src/Mod/Fem/_TaskPanelFemBeamSection.py
Expand Up @@ -93,15 +93,14 @@ def add_references(self):
def selectionParser(self, selection):
# print('selection: ', selection[0].Shape.ShapeType, ' ', selection[0].Name, ' ', selection[1])
if hasattr(selection[0], "Shape"):
elt = selection[0].Shape.getElement(selection[1])
if elt.ShapeType == 'Edge':
if selection not in self.references:
self.references.append(selection)
self.rebuild_list_References()
else:
print(selection[0].Name, '-->', selection[1], ' is already in reference list!')
else:
print('Selection has no shape!')
if selection[1]:
elt = selection[0].Shape.getElement(selection[1])
if elt.ShapeType == 'Edge':
if selection not in self.references:
self.references.append(selection)
self.rebuild_list_References()
else:
print(selection[0].Name, '-->', selection[1], ' is already in reference list!')

def rebuild_list_References(self):
self.form.list_References.clear()
Expand Down
17 changes: 8 additions & 9 deletions src/Mod/Fem/_TaskPanelFemShellThickness.py
Expand Up @@ -93,15 +93,14 @@ def add_references(self):
def selectionParser(self, selection):
# print('selection: ', selection[0].Shape.ShapeType, ' ', selection[0].Name, ' ', selection[1])
if hasattr(selection[0], "Shape"):
elt = selection[0].Shape.getElement(selection[1])
if elt.ShapeType == 'Face':
if selection not in self.references:
self.references.append(selection)
self.rebuild_list_References()
else:
print(selection[0].Name, '-->', selection[1], ' is already in reference list!')
else:
print('Selection has no shape!')
if selection[1]:
elt = selection[0].Shape.getElement(selection[1])
if elt.ShapeType == 'Face':
if selection not in self.references:
self.references.append(selection)
self.rebuild_list_References()
else:
print(selection[0].Name, '-->', selection[1], ' is already in reference list!')

def rebuild_list_References(self):
self.form.list_References.clear()
Expand Down
25 changes: 4 additions & 21 deletions src/Mod/Fem/_TaskPanelMechanicalMaterial.py
Expand Up @@ -241,7 +241,10 @@ 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)
# TODO add a ToolTip with print_message if the mouse pointer is over addReference button
print_message = "Select Edges and Faces by single click on them or Solids by double click on a Vertex 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 @@ -261,10 +264,6 @@ def selectionParser(self, selection):
FreeCAD.Console.PrintMessage(selection[0].Name + ' --> ' + selection[1] + ' is in reference list already!\n')
else:
FreeCAD.Console.PrintMessage(elt.ShapeType + ' selected, but reference list has ' + self.references_shape_type + 's already!\n')
else:
FreeCAD.Console.PrintMessage("Select Edges and Faces by single click on them or Solids by double click on a Vertex!\n")
else:
FreeCAD.Console.PrintMessage("Selection has no shape!\n")

def rebuild_list_References(self):
self.form.list_References.clear()
Expand All @@ -277,19 +276,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 Edges and Faces by single click on them or Solids by double click on a Vertex!\n")
# TODO add a ToolTip if mouse pointer is over addReference button

def addSelection(self, docName, objName, sub, pos):
selected_object = FreeCAD.getDocument(docName).getObject(objName) # get the obj objName
self.added_obj = (selected_object, sub)
# on double click on a vertex of a solid sub is None and obj is the solid
self.parseSelectionFunction(self.added_obj)

0 comments on commit c6989ac

Please sign in to comment.