Skip to content

Commit

Permalink
FEM: material task panel, add explizit solid selection mode, add supp…
Browse files Browse the repository at this point in the history
…ort for Solids of Compounds and CompSolids
  • Loading branch information
berndhahnebach authored and yorikvanhavre committed Dec 21, 2016
1 parent c06c150 commit 8b61027
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 41 deletions.
6 changes: 3 additions & 3 deletions src/Mod/Fem/FemMeshTools.py
Expand Up @@ -72,10 +72,10 @@ def get_femnodes_by_references(femmesh, references):
def get_femnodes_by_refshape(femmesh, ref):
nodes = []
for refelement in ref[1]:
if refelement:
r = ref[0].Shape.getElement(refelement) # Vertex, Edge, Face
if refelement.startswith('Solid'):
r = ref[0].Shape.Solids[int(refelement.lstrip('Solid')) - 1] # Solid
else:
r = ref[0].Shape # solid
r = ref[0].Shape.getElement(refelement) # Face, Edge, Vertex
print(' ReferenceShape : ', r.ShapeType, ', ', ref[0].Name, ', ', ref[0].Label, ' --> ', refelement)
if r.ShapeType == 'Vertex':
nodes += femmesh.getNodesByVertex(r)
Expand Down
42 changes: 30 additions & 12 deletions src/Mod/Fem/TaskPanelMechanicalMaterial.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>370</width>
<height>713</height>
<height>700</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -57,17 +57,7 @@
<item>
<widget class="QLabel" name="l_label_text_1">
<property name="text">
<string>Leave references blank </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="l_label_text_2">
<property name="text">
<string>to choose all remaining shapes</string>
</property>
<property name="wordWrap">
<bool>true</bool>
<string>Leave blank to choose all remaining shapes</string>
</property>
</widget>
</item>
Expand All @@ -81,6 +71,34 @@
<item>
<widget class="QListWidget" name="list_References"/>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QRadioButton" name="rb_standard">
<property name="text">
<string>Face, Edge</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QRadioButton" name="rb_solid">
<property name="text">
<string>Solid</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="l_label_text_5">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Selection&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down
86 changes: 60 additions & 26 deletions src/Mod/Fem/_TaskPanelMechanicalMaterial.py
Expand Up @@ -40,6 +40,9 @@ def __init__(self, obj):
FreeCADGui.Selection.clearSelection()
self.sel_server = None
self.obj = obj
self.selection_mode_solid = False
self.selection_mode_std_print_message = "Select Faces and Edges by single click on them to add them to the list."
self.selection_mode_solid_print_message = "Select Solids by single click on a Face or Edge which belongs to the Solid, to add the Solid to the list."
self.material = self.obj.Material
self.references = []
if self.obj.References:
Expand All @@ -54,6 +57,8 @@ def __init__(self, obj):
QtCore.QObject.connect(self.form.spinBox_poisson_ratio, QtCore.SIGNAL("valueChanged(double)"), self.pr_changed)
QtCore.QObject.connect(self.form.input_fd_density, QtCore.SIGNAL("valueChanged(double)"), self.density_changed)
QtCore.QObject.connect(self.form.pushButton_Reference, QtCore.SIGNAL("clicked()"), self.add_references)
QtCore.QObject.connect(self.form.rb_standard, QtCore.SIGNAL("toggled(bool)"), self.choose_selection_mode_standard)
QtCore.QObject.connect(self.form.rb_solid, QtCore.SIGNAL("toggled(bool)"), self.choose_selection_mode_solid)
QtCore.QObject.connect(self.form.input_fd_thermal_conductivity, QtCore.SIGNAL("valueChanged(double)"), self.tc_changed)
QtCore.QObject.connect(self.form.input_fd_expansion_coefficient, QtCore.SIGNAL("valueChanged(double)"), self.tec_changed)
QtCore.QObject.connect(self.form.input_fd_specific_heat, QtCore.SIGNAL("valueChanged(double)"), self.sh_changed)
Expand Down Expand Up @@ -102,6 +107,16 @@ def remove_active_sel_server(self):
if self.sel_server:
FreeCADGui.Selection.removeObserver(self.sel_server)

def choose_selection_mode_standard(self, state):
self.selection_mode_solid = not state
if self.sel_server and not self.selection_mode_solid:
print(self.selection_mode_std_print_message)

def choose_selection_mode_solid(self, state):
self.selection_mode_solid = state
if self.sel_server and self.selection_mode_solid:
print(self.selection_mode_solid_print_message)

def get_references(self):
for ref in self.tuplereferences:
for elem in ref[1]:
Expand All @@ -111,10 +126,10 @@ def has_equal_references_shape_types(self):
if not self.references:
self.references_shape_type = None
for ref in self.references:
if ref[1]:
r = ref[0].Shape.getElement(ref[1])
if ref[1].startswith('Solid'):
r = ref[0].Shape.Solids[int(ref[1].lstrip('Solid')) - 1] # Solid
else:
r = ref[0].Shape
r = ref[0].Shape.getElement(ref[1]) # Face, Edge
# print(' ReferenceShape : ', r.ShapeType, ', ', ref[0].Name, ', ', ref[0].Label, ' --> ', ref[1])
if self.references_shape_type is None:
self.references_shape_type = r.ShapeType
Expand Down Expand Up @@ -339,33 +354,52 @@ 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
# 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 single click on a Vertex to add them to the list"
if self.selection_mode_solid: # print message on button click
print_message = self.selection_mode_solid_print_message
else:
print_message = self.selection_mode_std_print_message
import FemSelectionObserver
self.sel_server = FemSelectionObserver.FemSelectionObserver(self.selectionParser, print_message)

def selectionParser(self, selection):
# print('selection: ', selection[0].Shape.ShapeType, ' --> ', selection[0].Name, ' --> ', selection[1])
if hasattr(selection[0], "Shape"):
if selection[1]:
elt = selection[0].Shape.getElement(selection[1])
if elt.ShapeType == "Vertex":
if selection[0].Shape.ShapeType == "Solid":
elt = selection[0].Shape
selection = (selection[0], '')
else:
FreeCAD.Console.PrintMessage("Selected Vertex does not belong to a Solid: " + selection[0].Name + " is a " + selection[0].Shape.ShapeType + " \n")
if elt.ShapeType == 'Edge' or elt.ShapeType == 'Face' or elt.ShapeType == 'Solid':
if not self.references:
self.references_shape_type = elt.ShapeType
if elt.ShapeType == self.references_shape_type:
if selection not in self.references:
self.references.append(selection)
self.rebuild_list_References()
else:
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')
print('selection: ', selection[0].Shape.ShapeType, ' --> ', selection[0].Name, ' --> ', selection[1])
if hasattr(selection[0], "Shape") and selection[1]:
elt = selection[0].Shape.getElement(selection[1])
if self.selection_mode_solid:
# in solid selection mode use edges and faces for selection of a solid
solid_to_add = None
if elt.ShapeType == 'Edge':
found_edge = False
for i, s in enumerate(selection[0].Shape.Solids):
for e in s.Edges:
if elt.isSame(e):
if not found_edge:
solid_to_add = str(i + 1)
else:
FreeCAD.Console.PrintMessage('Edge belongs to more than one solid\n')
solid_to_add = None
found_edge = True
elif elt.ShapeType == 'Face':
found_face = False
for i, s in enumerate(selection[0].Shape.Solids):
for e in s.Faces:
if elt.isSame(e):
if not found_face:
solid_to_add = str(i + 1)
else:
FreeCAD.Console.PrintMessage('Face belongs to more than one solid\n')
solid_to_add = None
found_edge = True
if solid_to_add:
selection = (selection[0], 'Solid' + solid_to_add)
print('selection element changed to Solid: ', selection[0].Shape.ShapeType, ' ', selection[0].Name, ' ', selection[1])
else:
return
if selection not in self.references:
self.references.append(selection)
self.rebuild_list_References()
else:
FreeCAD.Console.PrintMessage(selection[0].Name + ' --> ' + selection[1] + ' is in reference list already!\n')

def rebuild_list_References(self):
self.form.list_References.clear()
Expand Down

0 comments on commit 8b61027

Please sign in to comment.