Skip to content

Commit

Permalink
minor improvements to occ exception handling and minor bugfix in beam…
Browse files Browse the repository at this point in the history
… jusl
  • Loading branch information
Krande committed Dec 17, 2023
1 parent 34409b7 commit e391a1b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/ada/api/beams/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,16 @@ def is_strong_axis_stiffened(beam: Beam, other_beam: Beam) -> bool:
def get_justification(beam: Beam) -> Justification:
"""Justification line"""
# Check if both self.e1 and self.e2 are None
if beam.section.type in (beam.section.TYPES.TUBULAR, beam.section.TYPES.CIRCULAR):
bm_height = beam.section.r * 2
else:
bm_height = beam.section.h

if beam.e1 is None and beam.e2 is None:
return Justification.NA
elif beam.e1 is None or beam.e2 is None:
return Justification.CUSTOM
elif beam.e1.is_equal(beam.e2) and beam.e1.is_equal(beam.up * beam.section.h / 2):
elif beam.e1.is_equal(beam.e2) and beam.e1.is_equal(beam.up * bm_height / 2):
return Justification.TOS
else:
return Justification.CUSTOM
Expand Down
4 changes: 4 additions & 0 deletions src/ada/occ/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ class UnableToCreateSolidOCCGeom(Exception):
pass


class UnableToCreateCurveOCCGeom(Exception):
pass


class UnableToCreateTesselationFromSolidOCCGeom(Exception):
pass

Expand Down
3 changes: 2 additions & 1 deletion src/ada/occ/geom/curves.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from ada.geom import curves as geo_cu
from ada.geom.surfaces import PolyLoop
from ada.occ.exceptions import UnableToCreateCurveOCCGeom
from ada.occ.utils import point3d


Expand All @@ -30,7 +31,7 @@ def segments_to_wire(segments: list[geo_cu.Line | geo_cu.ArcLine]) -> TopoDS_Wir
try:
return wire.Wire()
except RuntimeError:
raise ValueError("Segments do not form a closed loop")
raise UnableToCreateCurveOCCGeom("Segments do not form a closed loop")


def make_wire_from_indexed_poly_curve_geom(
Expand Down
13 changes: 8 additions & 5 deletions src/ada/occ/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def shape_iterator(
if isinstance(geom_repr, str):
geom_repr = GeomRepr.from_str(geom_repr)

def safe_geom(obj_):
def safe_geom(obj_, name_ref=None):
geo_repr = render_override.get(obj_.guid, geom_repr)
try:
if geo_repr == GeomRepr.SOLID:
Expand All @@ -63,7 +63,10 @@ def safe_geom(obj_):
occ_geom = BRepBuilderAPI_Transform(occ_geom, trsf, True).Shape()
return occ_geom
except RuntimeError as e:
logger.warning(f"Failed to add shape {obj.name} due to {e}")
logger.warning(f"Failed to add shape {obj.name} due to \"{e}\" from {name_ref}")
return None
except BaseException as e:
logger.warning(f"Failed to add shape {obj.name} due to \"{e}\" from {name_ref}")
return None

if isinstance(part, StepStore):
Expand All @@ -76,11 +79,11 @@ def safe_geom(obj_):
geom_repr = GeomRepr.from_str(geom_repr)

if issubclass(type(obj), ada.Shape):
geom = safe_geom(obj)
geom = safe_geom(obj, part.name)
elif isinstance(obj, (ada.Beam, ada.Plate, ada.Wall)):
geom = safe_geom(obj)
geom = safe_geom(obj, part.name)
elif isinstance(obj, (ada.PipeSegStraight, ada.PipeSegElbow)):
geom = safe_geom(obj)
geom = safe_geom(obj, part.name)
else:
logger.error(f"Geometry type {type(obj)} not yet implemented")
geom = None
Expand Down
9 changes: 5 additions & 4 deletions src/ada/occ/tessellating.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ def tessellate_shape(shape: TopoDS_Shape, quality=1.0, render_edges=False, paral
# first, compute the tesselation
try:
tess = ShapeTesselator(shape)
tess.Compute(compute_edges=render_edges, mesh_quality=quality, parallel=parallel)
except RuntimeError as e:
raise UnableToCreateTesselationFromSolidOCCGeom(e)

tess.Compute(compute_edges=render_edges, mesh_quality=quality, parallel=parallel)
raise UnableToCreateTesselationFromSolidOCCGeom(f'Failed to tessellate OCC geometry due to "{e}"')

# get vertices and normals
vertices_position = tess.GetVerticesPositionAsTuple()
Expand Down Expand Up @@ -178,7 +177,9 @@ def batch_tessellate(
logger.error(e)
continue

def tessellate_part(self, part: Part, filter_by_guids=None, render_override=None, merge_meshes=True) -> trimesh.Scene:
def tessellate_part(
self, part: Part, filter_by_guids=None, render_override=None, merge_meshes=True
) -> trimesh.Scene:
graph = part.get_graph_store()
scene = trimesh.Scene(base_frame=graph.top_level.name)

Expand Down

0 comments on commit e391a1b

Please sign in to comment.