FEM: mesh region, allow any shape as reference shape, not only elements of the shape to mesh

This commit is contained in:
Bernd Hahnebach
2016-12-20 18:11:31 +01:00
committed by Yorik van Havre
parent be831e78bd
commit 6304258975
3 changed files with 54 additions and 55 deletions

View File

@@ -231,11 +231,26 @@ class FemGmshTools():
# print(Units.Quantity(mr_obj.CharacteristicLength).Value)
for sub in mr_obj.References:
# print(sub[0]) # Part the elements belongs to
# check if the shape of the mesh region is an element of the Part to mesh
# check if the shape of the mesh region is an element of the Part to mesh, if not try to find the element in the shape to mesh
search_ele_in_shape_to_mesh = False
if not self.part_obj.Shape.isSame(sub[0].Shape):
FreeCAD.Console.PrintError("One element of the meshregion " + mr_obj.Name + " is not an element of the Part to mesh.\n")
# print(" One element of the meshregion " + mr_obj.Name + " is not an element of the Part to mesh.")
# print(" But we gone try to fine it in the Shape to mesh :-)")
search_ele_in_shape_to_mesh = True
for eles in sub[1]:
# print(eles) # element
if search_ele_in_shape_to_mesh:
if eles.startswith('Solid'):
ele_shape = sub[0].Shape.Solids[int(eles.lstrip('Solid')) - 1] # Solid
else:
ele_shape = sub[0].Shape.getElement(eles) # Face, Edge, Vertex
import FemMeshTools
found_element = FemMeshTools.find_element_in_shape(self.part_obj.Shape, ele_shape)
if found_element:
eles = found_element
else:
FreeCAD.Console.PrintError("One element of the meshregion " + mr_obj.Name + " could not be found in the Part to mesh. It will be ignored.\n")
print(eles) # element
if eles not in self.ele_length_map:
self.ele_length_map[eles] = Units.Quantity(mr_obj.CharacteristicLength).Value
else:

View File

@@ -120,55 +120,43 @@ class _TaskPanelFemMeshRegion:
def selectionParser(self, selection):
print('selection: ', selection[0].Shape.ShapeType, ' ', selection[0].Name, ' ', selection[1])
if hasattr(selection[0], "Shape"):
# get the Shape to mesh
if len(self.obj.InList) == 1:
shape_to_mesh = self.obj.InList[0].Part.Shape
# check if the Shape the selected element belongs to is the Part to mesh of the mesh object
if shape_to_mesh.isSame(selection[0].Shape):
if 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(shape_to_mesh.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(shape_to_mesh.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: ', 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')
else:
FreeCAD.Console.PrintError("No selection[1].\n")
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:
FreeCAD.Console.PrintError("The selected element does not belong to the shape to mesh. Select an element of the object: " + self.obj.InList[0].Part.Name + "\n")
return
if selection not in self.references:
self.references.append(selection)
self.rebuild_list_References()
else:
FreeCAD.Console.PrintMessage(self.obj.Name + ' seam to belong to more than one mesh object. This is not supported.\n')
FreeCAD.Console.PrintMessage(selection[0].Name + ' --> ' + selection[1] + ' is in reference list already!\n')
def rebuild_list_References(self):
self.form.list_References.clear()

View File

@@ -59,14 +59,10 @@ class _ViewProviderFemMeshRegion:
return
def setEdit(self, vobj, mode=0):
# hide all meshes and shapes, show part to mesh
# hide all meshes
for o in FreeCAD.ActiveDocument.Objects:
if o.isDerivedFrom("Fem::FemMeshObject") or hasattr(o, "Shape"):
if o.isDerivedFrom("Fem::FemMeshObject"):
o.ViewObject.hide()
if len(self.Object.InList) == 1:
self.Object.InList[0].Part.ViewObject.show()
else:
FreeCAD.Console.PrintError(self.Object.Name + ' seam to belong to more than one mesh object. This is not supported.\n')
# show task panel
import _TaskPanelFemMeshRegion
taskd = _TaskPanelFemMeshRegion._TaskPanelFemMeshRegion(self.Object)