def create_shape_from_serialization(brep_object): brep_data, occ_shape, styles = None, None, () is_product_shape = True try: brep_data = brep_object.geometry.brep_data styles = brep_object.geometry.surface_styles except BaseException: try: brep_data = brep_object.brep_data styles = brep_object.surface_styles is_product_shape = False except BaseException: pass styles = tuple(styles[i:i + 4] for i in range(0, len(styles), 4)) if not brep_data: return shape_tuple(brep_object, None, styles) try: ss = BRepTools.BRepTools_ShapeSet() ss.ReadFromString(brep_data) occ_shape = ss.Shape(ss.NbShapes()) except BaseException: pass if is_product_shape: return shape_tuple(brep_object, occ_shape, styles) else: return occ_shape
def get_geom(ifc_elem, settings): from ifcopenshell.geom.occ_utils import shape_tuple from OCC.Core import BRepTools from OCC.Core.TopoDS import TopoDS_Compound try: pdct_shape = ifcopenshell.geom.create_shape(settings, inst=ifc_elem) except RuntimeError: print(f'unable to parse ifc_elem "{ifc_elem}"') return if isinstance(pdct_shape, shape_tuple): shape = pdct_shape[1] else: shape = pdct_shape.solid if type(shape) is not TopoDS_Compound: brep_data = pdct_shape.solid.brep_data ss = BRepTools.BRepTools_ShapeSet() ss.ReadFromString(brep_data) nb_shapes = ss.NbShapes() occ_shape = ss.Shape(nb_shapes) else: occ_shape = shape return occ_shape
def _ifc_geom_to_shape(self, ifc_geom): from OCC.Core import BRepTools from OCC.Core.TopoDS import TopoDS_Compound if type(ifc_geom) is TopoDS_Compound: geom = ifc_geom elif type(ifc_geom.solid) is not TopoDS_Compound: brep_data = ifc_geom.solid.brep_data ss = BRepTools.BRepTools_ShapeSet() ss.ReadFromString(brep_data) nb_shapes = ss.NbShapes() geom = ss.Shape(nb_shapes) else: geom = ifc_geom.solid return geom
def serialize_shape(shape): shapes = BRepTools.BRepTools_ShapeSet() shapes.Add(shape) return shapes.WriteToString()