Skip to content

Commit

Permalink
partial2
Browse files Browse the repository at this point in the history
  • Loading branch information
psauvan committed Dec 20, 2024
1 parent 452f57f commit b74891c
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 70 deletions.
9 changes: 5 additions & 4 deletions src/geouned/GEOUNED/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,11 @@ def start(self):
# sets self.geometry_bounding_box with default padding
self._get_geometry_bounding_box()

self.Surfaces = UF.SurfacesDict(offset=self.settings.startSurf - 1)
self.Surfaces = UF.SurfacesDict(offset=self.settings.startSurf - 1,
options=self.options,
tolerances=self.tolerances,
numeric_format=self.numeric_format
)

warnSolids = []
warnEnclosures = []
Expand Down Expand Up @@ -641,9 +645,6 @@ def _decompose_solids(self, meta: bool):
self.numeric_format,
MakeObj=True,
),
self.options,
self.tolerances,
self.numeric_format,
)
m.set_cad_solid()
m.update_solids(comsolid.Solids)
Expand Down
30 changes: 17 additions & 13 deletions src/geouned/GEOUNED/decompose/decom_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ def split_full_cylinder(solid, options, tolerances, numeric_format):

def cut_full_cylinder(solid, options, tolerances, numeric_format):
solid_gu = GU.SolidGu(solid, tolerances=tolerances)
surfaces = UF.SurfacesDict()
surfaces = UF.SurfacesDict(options=options,
tolerances=tolerances,
numeric_format=numeric_format
)

flag_inv = CD.is_inverted(solid_gu.solid)
universe_box = solid.BoundBox

Expand All @@ -70,12 +74,12 @@ def cut_full_cylinder(solid, options, tolerances, numeric_format):
dim_l = face.ParameterRange[3] - face.ParameterRange[2]
cylinder = UF.GeounedSurface(("Cylinder", (orig, dir, rad, dim_l)), universe_box)
cylinder.build_surface()
surfaces.add_cylinder(cylinder, options, tolerances, numeric_format, False)
surfaces.add_cylinder(cylinder, False)

# add planes if cylinder axis is cut by a plane (plane quasi perpedicular to axis)
for p in cyl_bound_planes(solid_gu, face, universe_box):
p.build_surface()
surfaces.add_plane(p, options, tolerances, numeric_format, False)
surfaces.add_plane(p, False)
break

planes = []
Expand Down Expand Up @@ -260,7 +264,7 @@ def extract_surfaces(solid, kind, universe_box, options, tolerances, numeric_for
plane = UF.GeounedSurface(("Plane", (pos, normal, dim1, dim2)), universe_box)
if MakeObj:
plane.build_surface()
surfaces.add_plane(plane, options, tolerances, numeric_format, fuzzy)
surfaces.add_plane(plane, fuzzy)

elif surf == "<Cylinder object>":
dir = face.Surface.Axis
Expand All @@ -271,14 +275,14 @@ def extract_surfaces(solid, kind, universe_box, options, tolerances, numeric_for
cylinder = UF.GeounedSurface(("Cylinder", (orig, dir, rad, dim_l)), universe_box)
if MakeObj:
cylinder.build_surface()
surfaces.add_cylinder(cylinder, options, tolerances, numeric_format, fuzzy)
surfaces.add_cylinder(cylinder, fuzzy)

if kind in ["Planes", "All"]:
# add planes if cylinder axis is cut by a plane (plane quasi perpedicular to axis)
for p in cyl_bound_planes(solid_GU, face, universe_box):
if MakeObj:
p.build_surface()
surfaces.add_plane(p, options, tolerances, numeric_format, False)
surfaces.add_plane(p, False)

elif surf == "<Cone object>":
dir = face.Surface.Axis
Expand All @@ -290,27 +294,27 @@ def extract_surfaces(solid, kind, universe_box, options, tolerances, numeric_for
cone = UF.GeounedSurface(("Cone", (apex, dir, half_angle, dim_l, dimR)), universe_box)
if MakeObj:
cone.build_surface()
surfaces.add_cone(cone, tolerances)
surfaces.add_cone(cone)

if kind in ["Planes", "All"]:
for p in cyl_bound_planes(solid_GU, face, universe_box):
if MakeObj:
p.build_surface()
surfaces.add_plane(p, options, tolerances, numeric_format, False)
surfaces.add_plane(p, False)

elif surf[0:6] == "Sphere" and kind in ["Sph", "All"]:
rad = face.Surface.Radius
pnt = face.Surface.Center
sphere = UF.GeounedSurface(("Sphere", (pnt, rad)), universe_box)
if MakeObj:
sphere.build_surface()
surfaces.add_sphere(sphere, tolerances)
surfaces.add_sphere(sphere)

if kind in ["Planes", "All"]:
for p in cyl_bound_planes(solid_GU, face, universe_box):
if MakeObj:
p.build_surface()
surfaces.add_plane(p, options, tolerances, numeric_format, False)
surfaces.add_plane(p, False)

elif surf == "<Toroid object>":
if kind in ["Tor", "All"]:
Expand All @@ -321,13 +325,13 @@ def extract_surfaces(solid, kind, universe_box, options, tolerances, numeric_for
torus = UF.GeounedSurface(("Torus", (center, dir, radMaj, radMin)), universe_box)
if MakeObj:
torus.build_surface()
surfaces.add_torus(torus, tolerances)
surfaces.add_torus(torus)

if kind in ["Planes", "All"]:
for p in torus_bound_planes(solid_GU, face, universe_box, tolerances):
if MakeObj:
p.build_surface()
surfaces.add_plane(p, options, tolerances, numeric_format, False)
surfaces.add_plane(p, False)

elif surf == "<Plane object>" and kind == "Plane3Pts":
pos = face.CenterOfMass
Expand All @@ -339,7 +343,7 @@ def extract_surfaces(solid, kind, universe_box, options, tolerances, numeric_for
plane = UF.GeounedSurface(("Plane3Pts", (pos, normal, dim1, dim2, points)), universe_box)
if MakeObj:
plane.build_surface()
surfaces.add_plane(plane, options, tolerances, numeric_format, fuzzy)
surfaces.add_plane(plane, fuzzy)

return surfaces

Expand Down
40 changes: 25 additions & 15 deletions src/geouned/GEOUNED/utils/boolean_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ def __new__(cls, *args, **kwrds):
def __init__(self, label, definition=None):
if definition is None:
self.definition = BoolSequence(str(label))
self.level = 0
else:
self.definition = definition
self.surfaces = self.definition.get_surfaces_numbers(self)
self.level = definition.level
self.surfaces = self.definition.get_surfaces_numbers()

def __str__(self):
return self.definition.__str__()

def __neg__(self):
return BoolRegion(-self.__int__(), self.definition.get_complementary())
Expand Down Expand Up @@ -57,7 +62,11 @@ def __mul__(self, def2):

def setDef(self, definition):
self.definition = definition
self.surfaces = self.definition.get_surfaces_numbers(self)
self.surfaces = self.definition.get_surfaces_numbers()
self.level = definition.level

def level_update(self):
pass

def copy(self, newname):
return BoolRegion(newname, self.definition)
Expand All @@ -80,7 +89,7 @@ def __str__(self):
if type(self.elements) is bool:
return " True " if self.elements else " False "
for e in self.elements:
if type(e) is int or type(e) is bool or type(e) is str:
if isinstance(e, (bool,int)):
out += f" {e} "
else:
out += e.__str__()
Expand All @@ -92,16 +101,17 @@ def append(self, *seq):
"""Append a BoolSequence Objects. seq may be :
- An iterable containing allowed BoolSequence Objects
- A BoolSequence object
- An integer value
- An BoolRegion object
- An integer
- A Boolean value"""

if type(self.elements) is bool:
if isinstance(self.elements, bool):
if (self.elements and self.operator == "AND") or (not self.elements and self.operator == "OR"):
self.assign(seq)
return

for s in seq:
if type(s) is int:
if isinstance(s,(int,BoolRegion)):
level = -1
if s in self.elements:
continue
Expand All @@ -112,16 +122,16 @@ def append(self, *seq):
else:
self.elements = True
return
elif type(s) is bool:
elif isinstance(s, bool):
if self.operator == "AND" and s or self.operator == "OR" and not s:
continue
else:
self.elements = s
self.level = -1
return
return
else:
level = s.level
if type(s.elements) is bool:
if isinstance(s.elements, bool):
if self.operator == "AND" and not s.elements or self.operator == "OR" and s.elements:
self.level = -1
self.elements = s.elements
Expand All @@ -130,11 +140,11 @@ def append(self, *seq):
continue

self.elements.append(s)
self.level = max(self.level, level + 1)
self.level_update()

def assign(self, seq):
"""Assign the BoolSequence Seq to the self instance BoolSequence"""
if type(seq) is bool:
if isinstance(seq, bool):
self.operator == "AND"
self.elements = seq
self.level = -1
Expand All @@ -158,7 +168,7 @@ def update(self, seq, pos):
for i in reversed(indexes):
del base.elements[i]

if type(seq.elements) is bool:
if isinstance(seq.elements, bool):
base.elements = seq.elements
base.level = -1
else:
Expand All @@ -177,11 +187,11 @@ def copy(self):
cp = BoolSequence()
cp.operator = self.operator
cp.level = self.level
if type(self.elements) is bool:
if isinstance(self.elements, bool):
cp.elements = self.elements
else:
for e in self.elements:
if type(e) is int:
if isinstance(e, int):
cp.elements.append(e)
else:
cp.elements.append(e.copy())
Expand Down Expand Up @@ -692,7 +702,7 @@ def level_update(self):

self.level = 0
for e in self.elements:
if type(e) is int:
if isinstance(e, int):
continue
e.level_update()
self.level = max(e.level + 1, self.level)
Expand Down
Loading

0 comments on commit b74891c

Please sign in to comment.