def __init__(self, shaft, blade, n_blades): self.shaft_solid = shaft.generate_solid() blade.apply_transformations(reflect=True) blade_solid = blade.generate_solid(max_deg=2, display=False, errors=None) blades = [] blades.append(blade_solid) for i in range(n_blades-1): blade.rotate(rad_angle=1.0*2.0*np.pi/float(n_blades)) blade_solid = blade.generate_solid(max_deg=2, display=False, errors=None) blades.append(blade_solid) blades_combined = blades[0] for i in range(len(blades)-1): boolean_union = BRepAlgoAPI_Fuse(blades_combined, blades[i+1]) boolean_union.Build() if not boolean_union.IsDone(): raise RuntimeError('Unsuccessful assembling of blade') blades_combined = boolean_union.Shape() boolean_union = BRepAlgoAPI_Fuse(self.shaft_solid, blades_combined) boolean_union.Build() result_compound = boolean_union.Shape() sewer = BRepBuilderAPI_Sewing(1e-2) sewer.Add(result_compound) sewer.Perform() self.sewed_full_body = sewer.SewedShape()
def brep_feat_extrusion_protrusion(event=None): # Extrusion S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape() faces = TopologyExplorer(S).faces() F = next(faces) surf1 = BRep_Tool_Surface(F) Pl1 = Geom_Plane.DownCast(surf1) 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) display.EraseAll() MKP = BRepFeat_MakePrism(S, FP, F, D1, 0, True) MKP.PerformThruAll() res1 = MKP.Shape() display.DisplayShape(res1) # Protrusion next(faces) F2 = next(faces) surf2 = BRep_Tool_Surface(F2) Pl2 = Geom_Plane.DownCast(surf2) D2 = Pl2.Pln().Axis().Direction().Reversed() MW2 = BRepBuilderAPI_MakeWire() p1, p2 = gp_Pnt2d(100., 100.), gp_Pnt2d(200., 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() FP = MKF2.Face() breplib_BuildCurves3d(FP) MKP2 = BRepFeat_MakePrism(res1, FP, F2, D2, 0, True) MKP2.PerformThruAll() display.EraseAll() trf = gp_Trsf() trf.SetTranslation(gp_Vec(0, 0, 300)) gtrf = gp_GTrsf() gtrf.SetTrsf(trf) tr = BRepBuilderAPI_GTransform(MKP2.Shape(), gtrf, True) fused = BRepAlgoAPI_Fuse(tr.Shape(), MKP2.Shape()) fused.Build() display.DisplayShape(fused.Shape()) display.FitAll()
def occ_pair_union(a, b): algo = BRepAlgoAPI_Fuse(a, b) algo.Build() if not algo.IsDone(): raise Exception("warn: union algotithm failed\n") return algo.Shape()