FEM: geometric selection widget, check to only allow to select one geometric shpape type for the list
This commit is contained in:
@@ -211,7 +211,7 @@ class SmallListView(QtGui.QListView):
|
||||
|
||||
class GeometryElementsSelection(QtGui.QWidget):
|
||||
|
||||
def __init__(self, ref, eltypes=[]):
|
||||
def __init__(self, ref, eltypes=[], multigeom=True):
|
||||
super(GeometryElementsSelection, self).__init__()
|
||||
# init ui stuff
|
||||
FreeCADGui.Selection.clearSelection()
|
||||
@@ -219,6 +219,8 @@ class GeometryElementsSelection(QtGui.QWidget):
|
||||
self.sel_server = None
|
||||
self.obj_notvisible = []
|
||||
self.initElemTypes(eltypes)
|
||||
self.allow_multiple_geom_types = multigeom
|
||||
print(self.allow_multiple_geom_types)
|
||||
self.initUI()
|
||||
# set references and fill the list widget
|
||||
self.references = []
|
||||
@@ -441,13 +443,37 @@ class GeometryElementsSelection(QtGui.QWidget):
|
||||
if ele_ShapeType in self.sel_elem_types:
|
||||
if (self.selection_mode_solid and ele_ShapeType == 'Solid') or self.selection_mode_solid is False:
|
||||
if selection not in self.references:
|
||||
self.references.append(selection)
|
||||
self.rebuild_list_References(self.get_allitems_text().index(self.get_item_text(selection)))
|
||||
if self.allow_multiple_geom_types is False: # only equal shape types are allowed to add
|
||||
if self.has_equal_references_shape_types(ele_ShapeType):
|
||||
self.references.append(selection)
|
||||
self.rebuild_list_References(self.get_allitems_text().index(self.get_item_text(selection)))
|
||||
else:
|
||||
# since the selected shape will not added to the list we gone clear selection
|
||||
FreeCADGui.Selection.clearSelection()
|
||||
else: # multiple shape types are allowed to add
|
||||
self.references.append(selection)
|
||||
self.rebuild_list_References(self.get_allitems_text().index(self.get_item_text(selection)))
|
||||
else:
|
||||
FreeCAD.Console.PrintMessage(selection[0].Name + ' --> ' + selection[1] + ' is in reference list already!\n')
|
||||
else:
|
||||
FreeCAD.Console.PrintMessage(ele_ShapeType + ' not allowed to add to the list!\n')
|
||||
|
||||
def has_equal_references_shape_types(self, ref_shty=''):
|
||||
for ref in self.references:
|
||||
r = FemMeshTools.get_element(ref[0], ref[1]) # the method getElement(element) does not return Solid elements
|
||||
if not r:
|
||||
FreeCAD.Console.PrintError('Problem in retrieving element: {} \n'.format(ref[1]))
|
||||
continue
|
||||
# print(' ReferenceShape : ', r.ShapeType, ', ', ref[0].Name, ', ', ref[0].Label, ' --> ', ref[1])
|
||||
if not ref_shty:
|
||||
ref_shty = r.ShapeType
|
||||
if r.ShapeType != ref_shty:
|
||||
message = 'Multiple shape types are not allowed in the reference list.\n'
|
||||
FreeCAD.Console.PrintMessage(message)
|
||||
QtGui.QMessageBox.critical(None, "Multiple ShapeTypes not allowed", message)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
class FemSelectionObserver:
|
||||
'''selection observer especially for the needs of geometry reference selection of FEM'''
|
||||
|
||||
@@ -35,11 +35,9 @@ False if False else FemGui.__name__ # dummy usage of FemGui for flake8, just re
|
||||
# for the panel
|
||||
from FreeCAD import Units
|
||||
from . import FemSelectionWidgets
|
||||
import femmesh.meshtools as FemMeshTools
|
||||
from PySide import QtCore
|
||||
from PySide import QtGui
|
||||
from PySide.QtGui import QFileDialog
|
||||
from PySide.QtGui import QMessageBox
|
||||
import sys
|
||||
if sys.version_info.major >= 3:
|
||||
unicode = str
|
||||
@@ -157,19 +155,17 @@ class _TaskPanelFemMaterial:
|
||||
self.choose_material(index)
|
||||
|
||||
# geometry selection widget
|
||||
self.selectionWidget = FemSelectionWidgets.GeometryElementsSelection(obj.References, ['Solid', 'Face', 'Edge']) # start with Solid in list!
|
||||
self.selectionWidget = FemSelectionWidgets.GeometryElementsSelection(obj.References, ['Solid', 'Face', 'Edge'], False) # start with Solid in list!
|
||||
|
||||
# form made from param and selection widget
|
||||
self.form = [self.parameterWidget, self.selectionWidget]
|
||||
|
||||
# reference shape checks, should be moved into the selection widget or better in another separate module, class
|
||||
# TODO check if the reference shapes realy exists, if the reference shape is an element of a Shape check if the Shape realy has this element
|
||||
# this should be done in all constraints with reference shapes too !
|
||||
self.has_equal_references_shape_types() # has to be after initializion of selectionWidget
|
||||
# check references, has to be after initialisation of selectionWidget
|
||||
self.selectionWidget.has_equal_references_shape_types()
|
||||
|
||||
def accept(self):
|
||||
# print(self.material)
|
||||
if self.has_equal_references_shape_types():
|
||||
if self.selectionWidget.has_equal_references_shape_types():
|
||||
self.obj.Material = self.material
|
||||
self.obj.References = self.selectionWidget.references
|
||||
self.set_back_all_and_recompute()
|
||||
@@ -187,23 +183,6 @@ class _TaskPanelFemMaterial:
|
||||
FreeCADGui.Selection.removeObserver(self.selectionWidget.sel_server)
|
||||
doc.resetEdit()
|
||||
|
||||
def has_equal_references_shape_types(self):
|
||||
ref_shty = ''
|
||||
for ref in self.selectionWidget.references:
|
||||
r = FemMeshTools.get_element(ref[0], ref[1]) # the method getElement(element) does not return Solid elements
|
||||
if not r:
|
||||
FreeCAD.Console.PrintError('Problem in retrieving element: {} \n'.format(ref[1]))
|
||||
continue
|
||||
# print(' ReferenceShape : ', r.ShapeType, ', ', ref[0].Name, ', ', ref[0].Label, ' --> ', ref[1])
|
||||
if not ref_shty:
|
||||
ref_shty = r.ShapeType
|
||||
if r.ShapeType != ref_shty:
|
||||
message = 'Multiple shape types are not allowed in the reference list.\n'
|
||||
FreeCAD.Console.PrintError(message)
|
||||
QMessageBox.critical(None, "Multiple ShapeTypes not allowed", message)
|
||||
return False
|
||||
return True
|
||||
|
||||
################ parameter widget methods #########################
|
||||
def goto_MatWeb(self):
|
||||
import webbrowser
|
||||
|
||||
Reference in New Issue
Block a user