def __init__(self, shape, edges=True, faces=True, bsplines=False): from OCC.Core.ShapeUpgrade import ShapeUpgrade_UnifySameDomain tool = ShapeUpgrade_UnifySameDomain(shape.object, edges, faces, bsplines) tool.Build() self._shape = Shape.wrap(tool.Shape()) self._history = tool.History()
def create_beam_geom(beam: Beam, solid=True): from ada.concepts.transforms import Placement from ada.sections.categories import SectionCat from .section_utils import cross_sec_face xdir, ydir, zdir = beam.ori ydir_neg = tuple_minus( ydir) if beam.section.type not in SectionCat.angular else tuple(ydir) section_profile = beam.section.get_section_profile(solid) taper_profile = beam.taper.get_section_profile(solid) placement_1 = Placement(origin=beam.n1.p, xdir=ydir_neg, zdir=xdir) placement_2 = Placement(origin=beam.n2.p, xdir=ydir_neg, zdir=xdir) sec = cross_sec_face(section_profile, placement_1, solid) tap = cross_sec_face(taper_profile, placement_2, solid) if type(sec) != list and (sec.IsNull() or tap.IsNull()): raise UnableToCreateSolidOCCGeom( f"Unable to create solid OCC geometry from Beam '{beam.name}'") def through_section(sec_a, sec_b, solid_): generator_sec = BRepOffsetAPI_ThruSections(solid_, False) generator_sec.AddWire(sec_a) generator_sec.AddWire(sec_b) generator_sec.Build() return generator_sec.Shape() if type(sec) is TopoDS_Face: sec_result = face_to_wires(sec) tap_result = face_to_wires(tap) elif type(sec) is TopoDS_Wire: sec_result = [sec] tap_result = [tap] else: try: assert isinstance(sec, list) except AssertionError as e: logging.error(e) sec_result = sec tap_result = tap shapes = list() for s_, t_ in zip(sec_result, tap_result): shapes.append(through_section(s_, t_, solid)) if beam.section.type in SectionCat.box + SectionCat.tubular + SectionCat.rhs + SectionCat.shs and solid is True: cut_shape = BRepAlgoAPI_Cut(shapes[0], shapes[1]).Shape() shape_upgrade = ShapeUpgrade_UnifySameDomain(cut_shape, False, True, False) shape_upgrade.Build() return shape_upgrade.Shape() if len(shapes) == 1: return shapes[0] else: result = shapes[0] for s in shapes[1:]: result = BRepAlgoAPI_Fuse(result, s).Shape() return result
from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer # Fuse two boxes. # In[ ]: box1 = BRepPrimAPI_MakeBox(10., 20., 30.).Shape() box2 = BRepPrimAPI_MakeBox(20., 1., 30.).Shape() fused_shp = BRepAlgoAPI_Fuse(box1, box2).Shape() # Display the union of two boxes. Edges appears from the input of the initial boxes' boundaries. # In[ ]: rnd = JupyterRenderer() rnd.DisplayShape(fused_shp, render_edges=True, update=True) # Apply the upgrading tool to unify the faces and edges. # In[ ]: shapeUpgrade = ShapeUpgrade_UnifySameDomain(fused_shp, False, True, False) shapeUpgrade.Build() fused_shp_upgrade = shapeUpgrade.Shape() # In[ ]: rnd_upgrade = JupyterRenderer() rnd_upgrade.DisplayShape(fused_shp_upgrade, render_edges=True, update=True)
def build_representation(beam, solid=True): """ Build a 3d model by :param beam: :param solid: :type beam: ada.Beam :return: """ from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut, BRepAlgoAPI_Fuse from OCC.Core.BRepOffsetAPI import BRepOffsetAPI_ThruSections from OCC.Core.ShapeUpgrade import ShapeUpgrade_UnifySameDomain from OCC.Core.TopoDS import TopoDS_Face, TopoDS_Wire from ada.core.utils import face_to_wires, tuple_minus from ada.sections import SectionCat xdir, ydir, zdir = beam.ori ydir_neg = tuple_minus( ydir) if beam.section.type not in SectionCat.angular else tuple( ydir) sec = beam.section.cross_sec_shape( solid, origin=tuple(beam.n1.p.astype(float)), xdir=ydir_neg, normal=tuple(xdir), ) tap = beam.taper.cross_sec_shape( solid, origin=tuple(beam.n2.p.astype(float)), xdir=ydir_neg, normal=tuple(xdir), ) def through_section(sec_a, sec_b, solid_): generator_sec = BRepOffsetAPI_ThruSections(solid_, False) generator_sec.AddWire(sec_a) generator_sec.AddWire(sec_b) generator_sec.Build() return generator_sec.Shape() if type(sec) is TopoDS_Face: sec_result = face_to_wires(sec) tap_result = face_to_wires(tap) elif type(sec) is TopoDS_Wire: sec_result = [sec] tap_result = [tap] else: assert isinstance(sec, list) sec_result = sec tap_result = tap shapes = list() for s_, t_ in zip(sec_result, tap_result): shapes.append(through_section(s_, t_, solid)) if beam.section.type in SectionCat.box + SectionCat.tubular + SectionCat.rhs + SectionCat.shs and solid is True: cut_shape = BRepAlgoAPI_Cut(shapes[0], shapes[1]).Shape() shape_upgrade = ShapeUpgrade_UnifySameDomain( cut_shape, False, True, False) shape_upgrade.Build() return shape_upgrade.Shape() if len(shapes) == 1: return shapes[0] else: result = shapes[0] for s in shapes[1:]: result = BRepAlgoAPI_Fuse(result, s).Shape() return result
def unify_same_domain(solid): from OCC.Core.ShapeUpgrade import ShapeUpgrade_UnifySameDomain up = ShapeUpgrade_UnifySameDomain(solid) return up.Shape()
def _unify_face(proto): USD = ShapeUpgrade_UnifySameDomain(proto.Shape(), True, True, True) USD.Build() return Shape(USD.Shape())