def make_wire(*args): # if we get an iterable, than add all edges to wire builder if isinstance(args[0], list) or isinstance(args[0], tuple): wire = BRepBuilderAPI_MakeWire() for i in args[0]: wire.Add(i) wire.Build() return wire.Wire() wire = BRepBuilderAPI_MakeWire(*args) wire.Build() with assert_isdone(wire, 'failed to produce wire'): result = wire.Wire() return result
def pipe_fillet(radius): # the points p1 = gp_Pnt(0, 0, 0) p2 = gp_Pnt(0, 1, 0) p3 = gp_Pnt(1, 2, 0) p4 = gp_Pnt(2, 2, 0) # the edges ed1 = BRepBuilderAPI_MakeEdge(p1, p2).Edge() ed2 = BRepBuilderAPI_MakeEdge(p2, p3).Edge() ed3 = BRepBuilderAPI_MakeEdge(p3, p4).Edge() # inbetween fillet12 = filletEdges(ed1, ed2) fillet23 = filletEdges(ed2, ed3) # the wire makeWire = BRepBuilderAPI_MakeWire() makeWire.Add(ed1) makeWire.Add(fillet12) makeWire.Add(ed2) makeWire.Add(fillet23) makeWire.Add(ed3) makeWire.Build() wire = makeWire.Wire() # the pipe dir = gp_Dir(0, 1, 0) circle = gp_Circ(gp_Ax2(p1, dir), radius) profile_edge = BRepBuilderAPI_MakeEdge(circle).Edge() profile_wire = BRepBuilderAPI_MakeWire(profile_edge).Wire() profile_face = BRepBuilderAPI_MakeFace(profile_wire).Face() pipe = BRepOffsetAPI_MakePipe(wire, profile_face).Shape() #display.DisplayShape(pipe, update=True) return (pipe)
def stitch(self, other): """Attempt to stich wires""" wire_builder = BRepBuilderAPI_MakeWire() wire_builder.Add(topods_Wire(self.wrapped)) wire_builder.Add(topods_Wire(other.wrapped)) wire_builder.Build() return self.__class__(wire_builder.Wire())
def make_wire(*args): # if we get an iterable, than add all edges to wire builder if isinstance(args[0], list) or isinstance(args[0], tuple): wire = BRepBuilderAPI_MakeWire() for i in args[0]: wire.Add(i) wire.Build() return wire.Wire() wire = BRepBuilderAPI_MakeWire(*args) return wire.Wire()
def make_wirex(*args): """ list of Edge """ # if we get an iterable, than add all edges to wire builder wire = BRepBuilderAPI_MakeWire() for a in args: wire.Add(a) wire.Build() with assert_isdone(wire, 'failed to produce wire'): result = wire.Wire() return result
def pipe(point1, point2, radius): makeWire = BRepBuilderAPI_MakeWire() edge = BRepBuilderAPI_MakeEdge(point1, point2).Edge() makeWire.Add(edge) makeWire.Build() wire = makeWire.Wire() dir = gp_Dir(point2.X() - point1.X(), point2.Y() - point1.Y(), point2.Z() - point1.Z()) circle = gp_Circ(gp_Ax2(point1, dir), radius) profile_edge = BRepBuilderAPI_MakeEdge(circle).Edge() profile_wire = BRepBuilderAPI_MakeWire(profile_edge).Wire() profile_face = BRepBuilderAPI_MakeFace(profile_wire).Face() pipe = BRepOffsetAPI_MakePipe(wire, profile_face).Shape() return (pipe)
def create(cls, *args, close=True): builder = BRepBuilderAPI_MakeWire() if isinstance(args, (list, tuple)): if isinstance(args[0], (gp.gp_Pnt, TopoDS_Vertex)): s = 0 if close is True else 1 for i in range(s, len(args)): edge = make_edge(args[i - 1], args[i]) builder.Add(edge) elif isinstance(args[0], TopoDS_Edge): for e in args: builder.Add(e) # while not builder.IsDone(): with assert_isdone(builder, 'f'): builder.Build() shp = builder.Wire() builder.Delete() return shp
def brepfeat_prism(event=None): box = BRepPrimAPI_MakeBox(400, 250, 300).Shape() faces = Topo(box).faces() for i in range(3): face = next(faces) srf = BRep_Tool_Surface(face) c = gp_Circ2d(gp_Ax2d(gp_Pnt2d(200, 130), gp_Dir2d(1, 0)), 75) circle = Geom2d_Circle(c).GetHandle() wire = BRepBuilderAPI_MakeWire() wire.Add(BRepBuilderAPI_MakeEdge(circle, srf, 0., pi).Edge()) wire.Add(BRepBuilderAPI_MakeEdge(circle, srf, pi, 2. * pi).Edge()) wire.Build() display.DisplayShape(wire.Wire()) mkf = BRepBuilderAPI_MakeFace() mkf.Init(srf, False, 1e-6) mkf.Add(wire.Wire()) mkf.Build() new_face = mkf.Face() breplib_BuildCurves3d(new_face) display.DisplayColoredShape(box, 'GREEN') display.DisplayShape(new_face) """ prism = BRepFeat_MakeDPrism(box, mkf.Face(), face, 100, True, True) prism.Perform(400) assert prism.IsDone() display.EraseAll() display.DisplayShape(prism.Shape()) """ #display.DisplayColoredShape(wire.Wire(), 'RED') display.FitAll()
def arrange_edges_2_wires(occedgelist, isclosed=False): from OCC.TopoDS import topods from OCC.TopExp import topexp from OCC.BRep import BRep_Tool from OCC.ShapeAnalysis import ShapeAnalysis_WireOrder from OCC.Precision import precision from OCC.BRepBuilderAPI import BRepBuilderAPI_WireDone, BRepBuilderAPI_EmptyWire, BRepBuilderAPI_DisconnectedWire, BRepBuilderAPI_NonManifoldWire wb_errdict = { BRepBuilderAPI_WireDone: "No error", BRepBuilderAPI_EmptyWire: "Empty wire", BRepBuilderAPI_DisconnectedWire: "disconnected wire", BRepBuilderAPI_NonManifoldWire: "non-manifold wire" } sawo_statusdict = { 0: "all edges are direct and in sequence", 1: "all edges are direct but some are not in sequence", 2: "unresolved gaps remain", -1: "some edges are reversed, but no gaps remain", -2: "some edges are reversed and some gaps remain", -10: "failure on reorder" } mode3d = True SAWO = ShapeAnalysis_WireOrder(mode3d, precision.PConfusion()) for edge in occedgelist: V1 = topexp.FirstVertex(topods.Edge(edge)) V2 = topexp.LastVertex(topods.Edge(edge)) pnt1 = BRep_Tool().Pnt(V1) pnt2 = BRep_Tool().Pnt(V2) SAWO.Add(pnt1.XYZ(), pnt2.XYZ()) SAWO.SetKeepLoopsMode(True) SAWO.Perform(isclosed) #print "SAWO.Status()", SAWO.Status() if not SAWO.IsDone(): raise RuntimeError, "build wire: Unable to reorder edges: \n" + sawo_statusdict[ SAWO.Status()] else: if SAWO.Status() not in [0, -1]: pass # not critical, wirebuilder will handle this SAWO.SetChains(precision.PConfusion()) wirelist = [] #print "Number of chains: ", SAWO.NbChains() for i in range(SAWO.NbChains()): wirebuilder = BRepBuilderAPI_MakeWire() estart, eend = SAWO.Chain(i + 1) #print "Number of edges in chain", i, ": ", eend - estart + 1 if (eend - estart + 1) == 0: continue for j in range(estart, eend + 1): idx = abs( SAWO.Ordered(j) ) # wirebuilder = s_addToWireBuilder(wirebuilder, edgelist[idx-1]) edge2w = occedgelist[idx - 1] wirebuilder.Add(edge2w) if wirebuilder is None: raise RuntimeError, " build wire: Error adding edge number " + str( j + 1) + " to Wire number " + str(i) err = wirebuilder.Error() if err != BRepBuilderAPI_WireDone: raise RuntimeError, "Overlay2D: build wire: Error adding edge number " + str( j + 1) + " to Wire number " + str( i) + ": \n" + wb_errdict[err] try: wirebuilder.Build() aWire = wirebuilder.Wire() wirelist.append(aWire) except Exception, err: raise RuntimeError, "Overlay2D: build wire: Creation of Wire number " + str( i) + " from edge(s) failed. \n" + str(err) wirebuilder.Build() aWire = wirebuilder.Wire() wirelist.append(aWire)