Skip to content

Commit

Permalink
FEM: geom tools, move get element
Browse files Browse the repository at this point in the history
  • Loading branch information
berndhahnebach committed Mar 27, 2020
1 parent 5d9bb6a commit 6c399ae
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/Mod/Fem/femguiobjects/FemSelectionWidgets.py
Expand Up @@ -39,7 +39,7 @@
import FreeCADGui
import FreeCADGui as Gui

from femmesh import meshtools
from femtools import geomtools


class _Selector(QtGui.QWidget):
Expand Down Expand Up @@ -375,7 +375,7 @@ def select_clicked_reference_shape(self):
# since only Subelements can be selected
# we're going to select all Faces of said Solids
# the method getElement(element)doesn't return Solid elements
solid = meshtools.get_element(ref[0], ref[1])
solid = geomtools.get_element(ref[0], ref[1])
if not solid:
return
faces = []
Expand Down Expand Up @@ -553,7 +553,7 @@ def selectionParser(self, selection):
def has_equal_references_shape_types(self, ref_shty=""):
for ref in self.references:
# the method getElement(element) does not return Solid elements
r = meshtools.get_element(ref[0], ref[1])
r = geomtools.get_element(ref[0], ref[1])
if not r:
FreeCAD.Console.PrintError(
"Problem in retrieving element: {} \n".format(ref[1])
Expand Down
6 changes: 3 additions & 3 deletions src/Mod/Fem/femmesh/gmshtools.py
Expand Up @@ -414,7 +414,7 @@ def get_region_data(self):
# Shape to mesh and use the found element as elems
# the method getElement(element)
# does not return Solid elements
ele_shape = meshtools.get_element(sub[0], elems)
ele_shape = geomtools.get_element(sub[0], elems)
found_element = geomtools.find_element_in_shape(
self.part_obj.Shape, ele_shape
)
Expand Down Expand Up @@ -451,7 +451,7 @@ def get_region_data(self):
)
for eleml in self.ele_length_map:
# the method getElement(element) does not return Solid elements
ele_shape = meshtools.get_element(self.part_obj, eleml)
ele_shape = geomtools.get_element(self.part_obj, eleml)
ele_vertexes = geomtools.get_vertexes_by_element(self.part_obj.Shape, ele_shape)
self.ele_node_map[eleml] = ele_vertexes
Console.PrintMessage(" {}\n".format(self.ele_length_map))
Expand Down Expand Up @@ -502,7 +502,7 @@ def get_boundary_layer_data(self):
# we try to find the element it in the Shape to mesh
# and use the found element as elems
# the method getElement(element) does not return Solid elements
ele_shape = meshtools.get_element(sub[0], elems)
ele_shape = geomtools.get_element(sub[0], elems)
found_element = geomtools.find_element_in_shape(
self.part_obj.Shape,
ele_shape
Expand Down
22 changes: 2 additions & 20 deletions src/Mod/Fem/femmesh/meshtools.py
Expand Up @@ -115,7 +115,7 @@ def get_femnodes_by_refshape(
nodes = []
for refelement in ref[1]:
# the following method getElement(element) does not return Solid elements
r = get_element(ref[0], refelement)
r = geomtools.get_element(ref[0], refelement)
FreeCAD.Console.PrintMessage(
" "
"ReferenceShape ... Type: {0}, "
Expand Down Expand Up @@ -1936,7 +1936,7 @@ def get_reference_group_elements(
# FreeCAD.Console.PrintMessage("{}\n".format(childs))
for child in childs:
# the method getElement(element) does not return Solid elements
ref_shape = get_element(parent, child)
ref_shape = geomtools.get_element(parent, child)
if not stype:
stype = ref_shape.ShapeType
elif stype != ref_shape.ShapeType:
Expand Down Expand Up @@ -2058,24 +2058,6 @@ def get_anlysis_empty_references_group_elements(
return group_elements


# ************************************************************************************************
def get_element(
part,
element
):
if element.startswith("Solid"):
index = int(element.lstrip("Solid")) - 1
if index >= len(part.Shape.Solids):
FreeCAD.Console.PrintError(
"Index out of range. This Solid does not exist in the Shape!\n"
)
return None
else:
return part.Shape.Solids[index] # Solid
else:
return part.Shape.getElement(element) # Face, Edge, Vertex


# ************************************************************************************************
def femelements_count_ok(
len_femelement_table,
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Fem/femtools/femutils.py
Expand Up @@ -309,10 +309,10 @@ def get_refshape_type(fem_doc_object):
:note:
Undefined behaviour if constraint contains no references (empty list).
"""
import femmesh.meshtools as FemMeshTools
from femtools.geomtools import get_element
if hasattr(fem_doc_object, "References") and fem_doc_object.References:
first_ref_obj = fem_doc_object.References[0]
first_ref_shape = FemMeshTools.get_element(first_ref_obj[0], first_ref_obj[1][0])
first_ref_shape = get_element(first_ref_obj[0], first_ref_obj[1][0])
st = first_ref_shape.ShapeType
FreeCAD.Console.PrintMessage(
"References: {} in {}, {}\n". format(st, fem_doc_object.Name, fem_doc_object.Label)
Expand Down
18 changes: 18 additions & 0 deletions src/Mod/Fem/femtools/geomtools.py
Expand Up @@ -173,6 +173,24 @@ def is_same_geometry(
return False


# ************************************************************************************************
def get_element(
part,
element
):
if element.startswith("Solid"):
index = int(element.lstrip("Solid")) - 1
if index >= len(part.Shape.Solids):
FreeCAD.Console.PrintError(
"Index out of range. This Solid does not exist in the Shape!\n"
)
return None
else:
return part.Shape.Solids[index] # Solid
else:
return part.Shape.getElement(element) # Face, Edge, Vertex


# ************************************************************************************************
def get_rectangular_coords(
obj
Expand Down

0 comments on commit 6c399ae

Please sign in to comment.