From 830d521e939cf0345bb6252416ae55cc093e92d2 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Mon, 21 May 2018 14:31:48 +0200 Subject: [PATCH] FEM: python task panel with solid reference shapes, make solids better visible on click if they are in Compound or BooleanFragment --- .../femguiobjects/_ViewProviderFemMaterial.py | 22 +++++++++++++++++-- .../_ViewProviderFemMeshGroup.py | 21 +++++++++++++++++- .../_ViewProviderFemMeshRegion.py | 21 +++++++++++++++++- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/Mod/Fem/femguiobjects/_ViewProviderFemMaterial.py b/src/Mod/Fem/femguiobjects/_ViewProviderFemMaterial.py index 02e7c4d2be..8505befd86 100644 --- a/src/Mod/Fem/femguiobjects/_ViewProviderFemMaterial.py +++ b/src/Mod/Fem/femguiobjects/_ViewProviderFemMaterial.py @@ -33,6 +33,7 @@ import FreeCADGui # for the panel from FreeCAD import Units +import femmesh.meshtools as FemMeshTools from PySide import QtCore from PySide import QtGui from PySide.QtGui import QFileDialog @@ -200,7 +201,6 @@ class _TaskPanelFemMaterial: self.references.append((ref[0], elem)) def has_equal_references_shape_types(self): - import femmesh.meshtools as FemMeshTools ref_shty = '' for ref in self.references: r = FemMeshTools.get_element(ref[0], ref[1]) # the method getElement(element) does not return Solid elements @@ -697,7 +697,25 @@ class _TaskPanelFemMaterial: self.obj_notvisible.append(ref[0]) ref[0].ViewObject.Visibility = True FreeCADGui.Selection.clearSelection() - FreeCADGui.Selection.addSelection(ref[0], ref[1]) + if ref[1].startswith('Solid') and (ref[0].Shape.ShapeType == 'Compound' or ref[0].Shape.ShapeType == 'CompSolid'): + # selection of Solids of Compounds or CompSolids is not possible, because a Solid is no Subelement + # since only Subelements can be selected, we gone select all Faces of such an Solids + solid = FemMeshTools.get_element(ref[0], ref[1]) # the method getElement(element) does not return Solid elements + if not solid: + return + faces = [] + for fs in solid.Faces: + # find these faces in ref[0] + for i, fref in enumerate(ref[0].Shape.Faces): + if fs.isSame(fref): + fref_elstring = 'Face' + str(i + 1) + if fref_elstring not in faces: + faces.append(fref_elstring) + for f in faces: + FreeCADGui.Selection.addSelection(ref[0], f) + else: + # Selection of all other element types is supported + FreeCADGui.Selection.addSelection(ref[0], ref[1]) def setback_listobj_visibility(self): '''set back Visibility of the list objects diff --git a/src/Mod/Fem/femguiobjects/_ViewProviderFemMeshGroup.py b/src/Mod/Fem/femguiobjects/_ViewProviderFemMeshGroup.py index b51d3b5945..5cc7fd30b2 100644 --- a/src/Mod/Fem/femguiobjects/_ViewProviderFemMeshGroup.py +++ b/src/Mod/Fem/femguiobjects/_ViewProviderFemMeshGroup.py @@ -32,6 +32,7 @@ import FreeCADGui # for the panel +import femmesh.meshtools as FemMeshTools from PySide import QtCore from PySide import QtGui @@ -275,7 +276,25 @@ class _TaskPanelFemMeshGroup: self.obj_notvisible.append(ref[0]) ref[0].ViewObject.Visibility = True FreeCADGui.Selection.clearSelection() - FreeCADGui.Selection.addSelection(ref[0], ref[1]) + if ref[1].startswith('Solid') and (ref[0].Shape.ShapeType == 'Compound' or ref[0].Shape.ShapeType == 'CompSolid'): + # selection of Solids of Compounds or CompSolids is not possible, because a Solid is no Subelement + # since only Subelements can be selected, we gone select all Faces of such an Solids + solid = FemMeshTools.get_element(ref[0], ref[1]) # the method getElement(element) does not return Solid elements + if not solid: + return + faces = [] + for fs in solid.Faces: + # find these faces in ref[0] + for i, fref in enumerate(ref[0].Shape.Faces): + if fs.isSame(fref): + fref_elstring = 'Face' + str(i + 1) + if fref_elstring not in faces: + faces.append(fref_elstring) + for f in faces: + FreeCADGui.Selection.addSelection(ref[0], f) + else: + # Selection of all other element types is supported + FreeCADGui.Selection.addSelection(ref[0], ref[1]) def setback_listobj_visibility(self): '''set back Visibility of the list objects diff --git a/src/Mod/Fem/femguiobjects/_ViewProviderFemMeshRegion.py b/src/Mod/Fem/femguiobjects/_ViewProviderFemMeshRegion.py index b8ae71d5aa..9ed9bb6f85 100644 --- a/src/Mod/Fem/femguiobjects/_ViewProviderFemMeshRegion.py +++ b/src/Mod/Fem/femguiobjects/_ViewProviderFemMeshRegion.py @@ -32,6 +32,7 @@ import FreeCADGui # for the panel +import femmesh.meshtools as FemMeshTools from PySide import QtCore from PySide import QtGui @@ -271,7 +272,25 @@ class _TaskPanelFemMeshRegion: self.obj_notvisible.append(ref[0]) ref[0].ViewObject.Visibility = True FreeCADGui.Selection.clearSelection() - FreeCADGui.Selection.addSelection(ref[0], ref[1]) + if ref[1].startswith('Solid') and (ref[0].Shape.ShapeType == 'Compound' or ref[0].Shape.ShapeType == 'CompSolid'): + # selection of Solids of Compounds or CompSolids is not possible, because a Solid is no Subelement + # since only Subelements can be selected, we gone select all Faces of such an Solids + solid = FemMeshTools.get_element(ref[0], ref[1]) # the method getElement(element) does not return Solid elements + if not solid: + return + faces = [] + for fs in solid.Faces: + # find these faces in ref[0] + for i, fref in enumerate(ref[0].Shape.Faces): + if fs.isSame(fref): + fref_elstring = 'Face' + str(i + 1) + if fref_elstring not in faces: + faces.append(fref_elstring) + for f in faces: + FreeCADGui.Selection.addSelection(ref[0], f) + else: + # Selection of all other element types is supported + FreeCADGui.Selection.addSelection(ref[0], ref[1]) def setback_listobj_visibility(self): '''set back Visibility of the list objects