def fuse(self, toFuse): """ Fuse shapes together """ fuse_op = BRepAlgoAPI_Fuse(self.wrapped, toFuse.wrapped) fuse_op.RefineEdges() fuse_op.FuseEdges() # fuse_op.SetFuzzyValue(TOLERANCE) fuse_op.Build() return Shape.cast(fuse_op.Shape())
def brep_feat_extrusion_protrusion(event=None): #Extrusion S = BRepPrimAPI_MakeBox(400.,250.,300.).Shape() faces = Topo(S).faces() F = faces.next() surf1 = BRep_Tool_Surface(F) Pl1 = Handle_Geom_Plane_DownCast(surf1).GetObject() D1 = Pl1.Pln().Axis().Direction().Reversed() MW = BRepBuilderAPI_MakeWire() p1,p2 = gp_Pnt2d(200.,-100.), gp_Pnt2d(100.,-100.) aline = GCE2d_MakeLine(p1,p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline,surf1,0.,p1.Distance(p2)).Edge()) p1,p2 = gp_Pnt2d(100.,-100.), gp_Pnt2d(100.,-200.) aline = GCE2d_MakeLine(p1,p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline,surf1,0.,p1.Distance(p2)).Edge()) p1,p2 = gp_Pnt2d(100.,-200.), gp_Pnt2d(200.,-200.) aline = GCE2d_MakeLine(p1,p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline,surf1,0.,p1.Distance(p2)).Edge()) p1,p2 = gp_Pnt2d(200.,-200.), gp_Pnt2d(200.,-100.) aline = GCE2d_MakeLine(p1,p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline,surf1,0.,p1.Distance(p2)).Edge()) MKF = BRepBuilderAPI_MakeFace() MKF.Init(surf1,False,1e-6) MKF.Add(MW.Wire()) FP = MKF.Face() BRepLib_BuildCurves3d(FP) # MKP = BRepFeat_MakePrism(S,FP,F,D1,0,True) # MKP.Perform(-200) # print 'depth 200' # res1 = MKP.Shape() # display.DisplayShape(res1) # time.sleep(1) display.EraseAll() MKP = BRepFeat_MakePrism(S,FP,F,D1,0,True) MKP.PerformThruAll() print 'depth thru all' res1 = MKP.Shape() # display.DisplayShape(res1) # Protrusion faces.next() F2 = faces.next() surf2 = BRep_Tool_Surface(F2) Pl2 = Handle_Geom_Plane_DownCast(surf2).GetObject() D2 = Pl2.Pln().Axis().Direction().Reversed() MW2 = BRepBuilderAPI_MakeWire() p1, p2 = gp_Pnt2d(100.,100.), gp_Pnt2d(200.,100.) # p1, p2 = gp_Pnt2d(100.,100.), gp_Pnt2d(150.,100.) aline = GCE2d_MakeLine(p1,p2).Value() MW2.Add(BRepBuilderAPI_MakeEdge(aline,surf2,0.,p1.Distance(p2)).Edge()) p1, p2 = gp_Pnt2d(200.,100.), gp_Pnt2d(150.,200.) aline = GCE2d_MakeLine(p1,p2).Value() MW2.Add(BRepBuilderAPI_MakeEdge(aline,surf2,0.,p1.Distance(p2)).Edge()) p1, p2 = gp_Pnt2d(150.,200.), gp_Pnt2d(100.,100.) aline = GCE2d_MakeLine(p1,p2).Value() MW2.Add(BRepBuilderAPI_MakeEdge(aline,surf2,0.,p1.Distance(p2)).Edge()) MKF2 = BRepBuilderAPI_MakeFace() MKF2.Init(surf2,False,1e-6) MKF2.Add(MW2.Wire()) MKF2.Build() # display.DisplayShape(MW2.Wire()) FP = MKF2.Face() BRepLib_BuildCurves3d(FP) MKP2 = BRepFeat_MakePrism(res1,FP,F2,D2,0,True) MKP2.PerformThruAll() display.EraseAll() # display.DisplayShape(MKP2.Shape()) trf = gp_Trsf() trf.SetTranslation(gp_Vec(0,0,300)) gtrf = gp_GTrsf() gtrf.SetTrsf(trf) tr = BRepBuilderAPI_GTransform(MKP2.Shape(), gtrf, True) from OCC.BRepAlgoAPI import BRepAlgoAPI_Fuse fused = BRepAlgoAPI_Fuse(tr.Shape(), MKP2.Shape()) fused.RefineEdges() fused.Build() print 'boolean operation error status:', fused.ErrorStatus() display.DisplayShape(fused.Shape())