def brep_feat_rib(event=None): mkw = BRepBuilderAPI_MakeWire() mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(0., 0., 0.), gp_Pnt(200., 0., 0.)).Edge()) mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(200., 0., 0.), gp_Pnt(200., 0., 50.)).Edge()) mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(200., 0., 50.), gp_Pnt(50., 0., 50.)).Edge()) mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 0., 50.), gp_Pnt(50., 0., 200.)).Edge()) mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 0., 200.), gp_Pnt(0., 0., 200.)).Edge()) mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(0., 0., 200.), gp_Pnt(0., 0., 0.)).Edge()) S = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(mkw.Wire()).Face(), gp_Vec(gp_Pnt(0., 0., 0.), gp_Pnt(0., 100., 0.))) display.EraseAll() # display.DisplayShape(S.Shape()) W = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 45., 100.), gp_Pnt(100., 45., 50.)).Edge()) aplane = Geom_Plane(0., 1., 0., -45.) aform = BRepFeat_MakeLinearForm(S.Shape(), W.Wire(), aplane, gp_Vec(0., 10., 0.), gp_Vec(0., 0., 0.), 1, True) aform.Perform() display.DisplayShape(aform.Shape()) display.FitAll()
def make_prism(profile, vec): ''' makes a finite prism ''' pri = BRepPrimAPI_MakePrism(profile, vec, True) with assert_isdone(pri, 'failed building prism'): pri.Build() return pri.Shape()
def sweep(self, vec: numpy.array, s: float): # Sweep the face in the vec direction the distance s svec = vec * s aVec = OccVector(svec) if self.face_is_plane(self.face): mksolid = BRepPrimAPI_MakePrism(self.face, aVec.Value()) if mksolid.IsDone(): self.solid = mksolid.Shape() self.done = True else: OccError('MakeSolidPrism', mksolid) else: OccError('MakeSolidPrism', self) return
def prism(): # the bspline profile array = TColgp_Array1OfPnt(1, 5) array.SetValue(1, gp_Pnt(0, 0, 0)) array.SetValue(2, gp_Pnt(1, 2, 0)) array.SetValue(3, gp_Pnt(2, 3, 0)) array.SetValue(4, gp_Pnt(4, 3, 0)) array.SetValue(5, gp_Pnt(5, 5, 0)) bspline = GeomAPI_PointsToBSpline(array).Curve() profile = BRepBuilderAPI_MakeEdge(bspline).Edge() # the linear path starting_point = gp_Pnt(0., 0., 0.) end_point = gp_Pnt(0., 0., 6.) vec = gp_Vec(starting_point, end_point) path = BRepBuilderAPI_MakeEdge(starting_point, end_point).Edge() # extrusion prism = BRepPrimAPI_MakePrism(profile, vec).Shape() display.DisplayShape(profile, update=False) display.DisplayShape(starting_point, update=False) display.DisplayShape(end_point, update=False) display.DisplayShape(path, update=False) display.DisplayShape(prism, update=True)
def create(self): if self.face_is_plane(self.face): # Create the extrusion vector from the UnboundedSurface and the material direction unb = UnboundedGeometry(self.model, self.object, self.dict, self.logging) surf = unb.surface() normal = numpy.array([0, 0, 0]) if surf.tag == self.dict['plane3d']: plane = OCXParser.ParametricPlane(surf, self.dict, self.model) normal = plane.normal elif surf.tag == self.dict['gridref']: ref = surf.get(self.dict['guidref']) normal = self.model.frameTableNormal(ref) # Get the sweep length as the object thickness pm = self.object.find(self.dict['platematerial']) material = OCXParser.Material(self.model, self.object, pm, self.dict, self.logging) th = material.thickness() # Create the solid # mksolid = OCCWrapper.OccMakeSolidPrism(self.face) v = th * normal aVec = gp_Vec(v[0], v[1], v[2]) self.solid = BRepPrimAPI_MakePrism(self.face, aVec).Shape() # if mksolid.IsDone(): # mksolid.sweep(normal, thick) # self.solid = mksolid.Value() self.done = True else: # TODO: Create solid from complex surface self.done = False
def makeBody(event=None): partName = 'body' aPrismVec = gp_Vec(0, 0, height) myBody = BRepPrimAPI_MakePrism(myFaceProfile.Shape(), aPrismVec).Shape() win.getNewPartUID(myBody, name=partName) win.statusBar().showMessage('Bottle body complete') win.redraw()
def extrude_polyline2d(polyline, frame, height): pol3d = polyline.to_frame(frame) lines = [] yb_point = Point([frame[0][i] for i in range(3)]) yb_vec = Vector([frame[1][0][i] for i in range(3)]).unit() print '*************' print yb_vec orig = gp_Pnt(frame[0][0], frame[0][1], frame[0][2]) vec = gp_Dir(yb_vec[0], yb_vec[1], yb_vec[2]) plane = gp_Pln(orig, vec) for i, p in enumerate(pol3d[:-1]): print p print 'zob' gp0 = gp_Pnt(p[0], p[1], p[2]) gp1 = gp_Pnt(pol3d[i + 1][0], pol3d[i + 1][1], pol3d[i + 1][2]) lines.append(BRepBuilderAPI_MakeEdge(gp0, gp1).Edge()) wire = BRepBuilderAPI_MakeWire(lines[0]) for l in lines[1:]: wire.Add(l) face = BRepBuilderAPI_MakeFace(wire.Wire()) print 'normal' print[vec.X(), vec.Y(), vec.Z()] extrude = BRepPrimAPI_MakePrism( face.Shape(), gp_Vec(height * vec.X(), height * vec.Y(), height * vec.Z())).Shape() return extrude
def pull(): """Pull profile on active WP onto active part.""" wp = win.activeWp if win.lineEditStack: length = float(win.lineEditStack.pop()) * win.unitscale wireOK = wp.makeWire() if not wireOK: print("Unable to make wire.") return wire = wp.wire workPart = win.activePart uid = win.activePartUID pullProfile = BRepBuilderAPI_MakeFace(wire) aPrismVec = wp.wVec * length tool = BRepPrimAPI_MakePrism(pullProfile.Shape(), aPrismVec).Shape() newPart = BRepAlgoAPI_Fuse(workPart, tool).Shape() win.erase_shape(uid) doc.replaceShape(uid, newPart) win.draw_shape(uid) win.setActivePart(uid) win.statusBar().showMessage("Pull operation complete") win.clearCallback() else: win.registerCallback(pullC) win.lineEdit.setFocus() statusText = "Enter pull distance (pos in +w direction)" win.statusBar().showMessage(statusText)
def extrude(): """Extrude profile on active WP to create a new part.""" wp = win.activeWp if len(win.lineEditStack) == 2: name = win.lineEditStack.pop() length = float(win.lineEditStack.pop()) * win.unitscale wireOK = wp.makeWire() if not wireOK: print("Unable to make wire.") return myFaceProfile = BRepBuilderAPI_MakeFace(wp.wire) aPrismVec = wp.wVec * length myBody = BRepPrimAPI_MakePrism(myFaceProfile.Shape(), aPrismVec).Shape() uid = doc.addComponent(myBody, name, DEFAULT_COLOR) win.build_tree() win.setActivePart(uid) win.draw_shape(uid) win.syncUncheckedToHideList() win.statusBar().showMessage("New part created.") win.clearCallback() else: win.registerCallback(extrudeC) win.lineEdit.setFocus() statusText = "Enter extrusion length, then enter part name." win.statusBar().showMessage(statusText)
def __init__(self, pln, width, height, depth): w = width / 2. h = height / 2. gp_pln = pln.gp_pln topods_face = BRepBuilderAPI_MakeFace(gp_pln, -w, w, -h, h).Face() vn = pln.norm(0., 0.) vn.Normalize() vn.Scale(depth) self._solid = Solid(BRepPrimAPI_MakePrism(topods_face, vn).Shape())
def make_extrusion(face, length, vector=gp_Vec(0., 0., 1.)): ''' creates a extrusion from a face, along the vector vector. with a distance legnth. Note that the normal vector does not necessary be normalized. By default, the extrusion is along the z axis. ''' vector.Normalize() vector.Scale(length) return BRepPrimAPI_MakePrism(face, vector).Shape()
def Compute(self): # self.myGeometry = Geom_SurfaceOfLinearExtrusion(self.myCurve, self.myVec) # face = BRepBuilderAPI_MakeFace() # face.Init(self.myGeometry, True, 1.0e-6) # face.Build() profile = BRepBuilderAPI_MakeEdge(self.myCurve).Edge() prism = BRepPrimAPI_MakePrism(profile, self.myVec * self.myLength).Shape() self.myAIS_InteractiveObject = AIS_Shape(prism) self.myContext.Display(self.myAIS_InteractiveObject, True) self.SetCenter(prism) self.InitClippingPlane()
def make_shape(self): # 1 - retrieve the data from the UIUC airfoil data page foil_dat_url = 'http://m-selig.ae.illinois.edu/ads/coord_seligFmt/%s.dat' % self.profile # explicitly tell to not use ssl verification ssl._create_default_https_context = ssl._create_unverified_context print("Connecting to m-selig, retrieving foil data") f = urllib2.urlopen(foil_dat_url) print("Building foil geometry") plan = gp_Pln(gp_Pnt(0., 0., 0.), gp_Dir(0., 0., 1.)) # Z=0 plan / XY plan section_pts_2d = [] for line in f.readlines()[1:]: # The first line contains info only # 2 - do some cleanup on the data (mostly dealing with spaces) data = line.split() # 3 - create an array of points if len(data) == 2: # two coordinates for each point section_pts_2d.append( gp_Pnt2d( float(data[0]) * self.chord, float(data[1]) * self.chord)) # 4 - use the array to create a spline describing the airfoil section spline_2d = Geom2dAPI_PointsToBSpline( point2d_list_to_TColgp_Array1OfPnt2d(section_pts_2d), len(section_pts_2d) - 1, # order min len(section_pts_2d)) # order max spline = geomapi.To3d(spline_2d.Curve(), plan) # 5 - figure out if the trailing edge has a thickness or not, # and create a Face try: #first and last point of spline -> trailing edge trailing_edge = make_edge( gp_Pnt(section_pts_2d[0].X(), section_pts_2d[0].Y(), 0.0), gp_Pnt(section_pts_2d[-1].X(), section_pts_2d[-1].Y(), 0.0)) face = BRepBuilderAPI_MakeFace( make_wire([make_edge(spline), trailing_edge])) except AssertionError: # the trailing edge segment could not be created, probably because # the points are too close # No need to build a trailing edge face = BRepBuilderAPI_MakeFace(make_wire(make_edge(spline))) # 6 - extrude the Face to create a Solid return BRepPrimAPI_MakePrism( face.Face(), gp_Vec(gp_Pnt(0., 0., 0.), gp_Pnt(0., 0., self.span))).Shape()
def _extrude(shp, vec, center=False): if type(vec) in (float, int): vec = vector3(0, 0, vec) else: vec = vector3(vec) if center: trs = translate(-vec / 2) return _extrude(trs(shp), vec) # Если в объекте есть только один face, но сам объект не face, # извлекаем face и применяем влгоритм на нём. shp = _restore_shapetype(shp) obj = shp.Shape() return Shape(BRepPrimAPI_MakePrism(obj, vec.Vec()).Shape())
def linear_extrude(self, height=1.0): faces = [] for c in self.children: debug("Adding face") f = c.get_face() faces.append(f) self.children = [] for f in faces: prism_vec = gp_Vec(0, 0, height) shape = BRepPrimAPI_MakePrism(f.Face(), prism_vec).Shape() scls = SCLShape(shape) sclp = SCLPart3(self) sclp.set_shape(scls) name = get_inc_name("extrusion") sclp.set_name(name) debug("Creating extrusion %s" % (name, )) self.add_child_context(sclp)
def extrude(): """Extrude profile on active WP to create a new part.""" wp = win.activeWp if len(win.lineEditStack) == 2: name = win.lineEditStack.pop() length = float(win.lineEditStack.pop()) * win.unitscale wireOK = wp.makeWire() if not wireOK: print("Unable to make wire.") return myFaceProfile = BRepBuilderAPI_MakeFace(wp.wire) aPrismVec = wp.wVec * length myBody = BRepPrimAPI_MakePrism(myFaceProfile.Shape(), aPrismVec).Shape() uid = win.getNewPartUID(myBody, name=name) win.redraw() else: win.registerCallback(extrudeC) win.lineEdit.setFocus() statusText = "Enter extrusion length, then enter part name." win.statusBar().showMessage(statusText)
def mill(): """Mill profile on active WP into active part.""" wp = win.activeWp if win.lineEditStack: length = float(win.lineEditStack.pop()) * win.unitscale wire = wp.wire if not wire: print("Need to 'makeWire' first.") return workPart = win.activePart wrkPrtUID = win.activePartUID punchProfile = BRepBuilderAPI_MakeFace(wire) aPrismVec = wp.wVec * length tool = BRepPrimAPI_MakePrism(punchProfile.Shape(), aPrismVec).Shape() newPart = BRepAlgoAPI_Cut(workPart, tool).Shape() uid = win.getNewPartUID(newPart, ancestor=wrkPrtUID) win.statusBar().showMessage('Mill operation complete') win.clearCallback() win.redraw() else: win.registerCallback(millC) win.lineEdit.setFocus() statusText = "Enter milling depth for tool (Neg value for -W)" win.statusBar().showMessage(statusText)
def startBottle(startOnly=True): # minus the neck fillet, shelling & threads partName = "Bottle-start" # The points we'll use to create the profile of the bottle's body aPnt1 = gp_Pnt(-width / 2.0, 0, 0) aPnt2 = gp_Pnt(-width / 2.0, -thickness / 4.0, 0) aPnt3 = gp_Pnt(0, -thickness / 2.0, 0) aPnt4 = gp_Pnt(width / 2.0, -thickness / 4.0, 0) aPnt5 = gp_Pnt(width / 2.0, 0, 0) aArcOfCircle = GC_MakeArcOfCircle(aPnt2, aPnt3, aPnt4) aSegment1 = GC_MakeSegment(aPnt1, aPnt2) aSegment2 = GC_MakeSegment(aPnt4, aPnt5) # Could also construct the line edges directly using the points # instead of the resulting line. aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1.Value()) aEdge2 = BRepBuilderAPI_MakeEdge(aArcOfCircle.Value()) aEdge3 = BRepBuilderAPI_MakeEdge(aSegment2.Value()) # Create a wire out of the edges aWire = BRepBuilderAPI_MakeWire(aEdge1.Edge(), aEdge2.Edge(), aEdge3.Edge()) # Quick way to specify the X axis xAxis = gp_OX() # Set up the mirror aTrsf = gp_Trsf() aTrsf.SetMirror(xAxis) # Apply the mirror transformation aBRespTrsf = BRepBuilderAPI_Transform(aWire.Wire(), aTrsf) # Get the mirrored shape back out of the transformation # and convert back to a wire aMirroredShape = aBRespTrsf.Shape() # A wire instead of a generic shape now aMirroredWire = topods.Wire(aMirroredShape) # Combine the two constituent wires mkWire = BRepBuilderAPI_MakeWire() mkWire.Add(aWire.Wire()) mkWire.Add(aMirroredWire) myWireProfile = mkWire.Wire() # The face that we'll sweep to make the prism myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile) # We want to sweep the face along the Z axis to the height aPrismVec = gp_Vec(0, 0, height) myBody = BRepPrimAPI_MakePrism(myFaceProfile.Face(), aPrismVec) # Add fillets to all edges through the explorer mkFillet = BRepFilletAPI_MakeFillet(myBody.Shape()) anEdgeExplorer = TopExp_Explorer(myBody.Shape(), TopAbs_EDGE) while anEdgeExplorer.More(): anEdge = topods.Edge(anEdgeExplorer.Current()) mkFillet.Add(thickness / 12.0, anEdge) anEdgeExplorer.Next() myBody = mkFillet.Shape() # Create the neck of the bottle neckLocation = gp_Pnt(0, 0, height) neckAxis = gp_DZ() neckAx2 = gp_Ax2(neckLocation, neckAxis) myNeckRadius = thickness / 4.0 myNeckHeight = height / 10.0 mkCylinder = BRepPrimAPI_MakeCylinder(neckAx2, myNeckRadius, myNeckHeight) myBody = BRepAlgoAPI_Fuse(myBody, mkCylinder.Shape()) if startOnly: # quit here uid = win.getNewPartUID(myBody.Shape(), name=partName) win.redraw() return partName = "Bottle-complete" # Our goal is to find the highest Z face and remove it faceToRemove = None zMax = -1 # We have to work our way through all the faces to find the highest Z face aFaceExplorer = TopExp_Explorer(myBody.Shape(), TopAbs_FACE) while aFaceExplorer.More(): aFace = topods.Face(aFaceExplorer.Current()) if face_is_plane(aFace): aPlane = geom_plane_from_face(aFace) # We want the highest Z face, so compare this to the previous faces aPnt = aPlane.Location() aZ = aPnt.Z() if aZ > zMax: zMax = aZ faceToRemove = aFace aFaceExplorer.Next() facesToRemove = TopTools_ListOfShape() facesToRemove.Append(faceToRemove) myBody = BRepOffsetAPI_MakeThickSolid(myBody.Shape(), facesToRemove, -thickness / 50.0, 0.001) # Set up our surfaces for the threading on the neck neckAx2_Ax3 = gp_Ax3(neckLocation, gp_DZ()) aCyl1 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 0.99) aCyl2 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 1.05) # Set up the curves for the threads on the bottle's neck aPnt = gp_Pnt2d(2.0 * math.pi, myNeckHeight / 2.0) aDir = gp_Dir2d(2.0 * math.pi, myNeckHeight / 4.0) anAx2d = gp_Ax2d(aPnt, aDir) aMajor = 2.0 * math.pi aMinor = myNeckHeight / 10.0 anEllipse1 = Geom2d_Ellipse(anAx2d, aMajor, aMinor) anEllipse2 = Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4.0) anArc1 = Geom2d_TrimmedCurve(anEllipse1, 0, math.pi) anArc2 = Geom2d_TrimmedCurve(anEllipse2, 0, math.pi) anEllipsePnt1 = anEllipse1.Value(0) anEllipsePnt2 = anEllipse1.Value(math.pi) aSegment = GCE2d_MakeSegment(anEllipsePnt1, anEllipsePnt2) # Build edges and wires for threading anEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(anArc1, aCyl1) anEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCyl1) anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(anArc2, aCyl2) anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCyl2) threadingWire1 = BRepBuilderAPI_MakeWire(anEdge1OnSurf1.Edge(), anEdge2OnSurf1.Edge()) threadingWire2 = BRepBuilderAPI_MakeWire(anEdge1OnSurf2.Edge(), anEdge2OnSurf2.Edge()) # Compute the 3D representations of the edges/wires breplib.BuildCurves3d(threadingWire1.Shape()) breplib.BuildCurves3d(threadingWire2.Shape()) # Create the surfaces of the threading aTool = BRepOffsetAPI_ThruSections(True) aTool.AddWire(threadingWire1.Wire()) aTool.AddWire(threadingWire2.Wire()) aTool.CheckCompatibility(False) myThreading = aTool.Shape() # Build the resulting compound aRes = TopoDS_Compound() aBuilder = BRep_Builder() aBuilder.MakeCompound(aRes) aBuilder.Add(aRes, myBody.Shape()) aBuilder.Add(aRes, myThreading) uid = win.getNewPartUID(aRes, name=partName) win.redraw()
# A wire instead of a generic shape now aMirroredWire = topods.Wire(aMirroredShape) # Combine the two constituent wires mkWire = BRepBuilderAPI_MakeWire() mkWire.Add(aWire.Wire()) mkWire.Add(aMirroredWire) myWireProfile = mkWire.Wire() # The face that we'll sweep to make the prism myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile) # We want to sweep the face along the Z axis to the height aPrismVec = gp_Vec(0, 0, height) myBody = BRepPrimAPI_MakePrism(myFaceProfile.Face(), aPrismVec) # Add fillets to all edges through the explorer mkFillet = BRepFilletAPI_MakeFillet(myBody.Shape()) anEdgeExplorer = TopExp_Explorer(myBody.Shape(), TopAbs_EDGE) while anEdgeExplorer.More(): anEdge = topods.Edge(anEdgeExplorer.Current()) mkFillet.Add(thickness / 12.0, anEdge) anEdgeExplorer.Next() myBody = mkFillet # Create the neck of the bottle neckLocation = gp_Pnt(0, 0, height)
type="float", nargs=3) opt, argc = parser.parse_args(argvs) print(opt, argc) px = np.linspace(-1, 1, 100) * 110 / 2 py = np.linspace(-1, 1, 200) * 110 / 2 mesh = np.meshgrid(px, py) dae_data = uiuc_dae_data() obj = plotocc() axs = gp_Ax3() ax1 = gp_Ax3(gp_Pnt(0, 0, -10), axs.Direction()) vec = gp_Vec(gp_Pnt(0, 0, -10), gp_Pnt(0, 0, 10)) face = obj.make_EllipWire(rxy=[50.0, 50.0], axs=ax1, skin=0) body = BRepPrimAPI_MakePrism(face, vec).Shape() data1 = (mesh[0]**2 / 750 + mesh[1]**2 / 750) + 6.0 data2 = (mesh[0]**2 / 1000 + mesh[1]**2 / 1000) - 6.0 face1 = spl_face(*mesh, data1, axs=axs) face2 = spl_face(*mesh, data2, axs=axs) splitter = BOPAlgo_Splitter() splitter.AddArgument(body) splitter.AddTool(face1) splitter.AddTool(face2) splitter.Perform() print(splitter.Arguments()) print(splitter.ShapesSD()) exp = TopExp_Explorer(splitter.Shape(), TopAbs_SOLID) shp = [] while exp.More():
def cut_out(base): outer = gp_Circ2d(gp_OX2d(), top_radius - 1.75 * roller_diameter) inner = gp_Circ2d(gp_OX2d(), center_radius + 0.75 * roller_diameter) geom_outer = GCE2d_MakeCircle(outer).Value() geom_inner = GCE2d_MakeCircle(inner).Value() geom_inner.Reverse() base_angle = (2. * M_PI) / mounting_hole_count hole_angle = atan(hole_radius / mounting_radius) correction_angle = 3 * hole_angle left = gp_Lin2d(gp_Origin2d(), gp_DX2d()) right = gp_Lin2d(gp_Origin2d(), gp_DX2d()) left.Rotate(gp_Origin2d(), correction_angle) right.Rotate(gp_Origin2d(), base_angle - correction_angle) geom_left = GCE2d_MakeLine(left).Value() geom_right = GCE2d_MakeLine(right).Value() inter_1 = Geom2dAPI_InterCurveCurve(geom_outer, geom_left) inter_2 = Geom2dAPI_InterCurveCurve(geom_outer, geom_right) inter_3 = Geom2dAPI_InterCurveCurve(geom_inner, geom_right) inter_4 = Geom2dAPI_InterCurveCurve(geom_inner, geom_left) if inter_1.Point(1).X() > 0: p1 = inter_1.Point(1) else: p1 = inter_1.Point(2) if inter_2.Point(1).X() > 0: p2 = inter_2.Point(1) else: p2 = inter_2.Point(2) if inter_3.Point(1).X() > 0: p3 = inter_3.Point(1) else: p3 = inter_3.Point(2) if inter_4.Point(1).X() > 0: p4 = inter_4.Point(1) else: p4 = inter_4.Point(2) trimmed_outer = GCE2d_MakeArcOfCircle(outer, p1, p2).Value() trimmed_inner = GCE2d_MakeArcOfCircle(inner, p4, p3).Value() plane = gp_Pln(gp_Origin(), gp_DZ()) arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_outer, plane)).Edge() lin1 = BRepBuilderAPI_MakeEdge(gp_Pnt(p2.X(), p2.Y(), 0), gp_Pnt(p3.X(), p3.Y(), 0)).Edge() arc2 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_inner, plane)).Edge() lin2 = BRepBuilderAPI_MakeEdge(gp_Pnt(p4.X(), p4.Y(), 0), gp_Pnt(p1.X(), p1.Y(), 0)).Edge() cutout_wire = BRepBuilderAPI_MakeWire(arc1) cutout_wire.Add(lin1) cutout_wire.Add(arc2) cutout_wire.Add(lin2) # Turn the wire into a face cutout_face = BRepBuilderAPI_MakeFace(cutout_wire.Wire()) filleted_face = BRepFilletAPI_MakeFillet2d(cutout_face.Face()) explorer = BRepTools_WireExplorer(cutout_wire.Wire()) while explorer.More(): vertex = explorer.CurrentVertex() filleted_face.AddFillet(vertex, roller_radius) explorer.Next() cutout = BRepPrimAPI_MakePrism(filleted_face.Shape(), gp_Vec(0.0, 0.0, thickness)).Shape() result = base rotate = gp_Trsf() for i in range(0, mounting_hole_count): rotate.SetRotation(gp_OZ(), i * 2. * M_PI / mounting_hole_count) rotated_cutout = BRepBuilderAPI_Transform(cutout, rotate, True) result = BRepAlgoAPI_Cut(result, rotated_cutout.Shape()).Shape() return result
def build_tooth(): base_center = gp_Pnt2d(pitch_circle_radius + (tooth_radius - roller_radius), 0) base_circle = gp_Circ2d(gp_Ax2d(base_center, gp_Dir2d()), tooth_radius) trimmed_base = GCE2d_MakeArcOfCircle(base_circle, M_PI - (roller_contact_angle / 2.), M_PI).Value() trimmed_base.Reverse() # just a trick p0 = trimmed_base.StartPoint() p1 = trimmed_base.EndPoint() # Determine the center of the profile circle x_distance = cos(roller_contact_angle / 2.) * (profile_radius + tooth_radius) y_distance = sin(roller_contact_angle / 2.) * (profile_radius + tooth_radius) profile_center = gp_Pnt2d(pitch_circle_radius - x_distance, y_distance) # Construct the profile circle gp_Circ2d profile_circle = gp_Circ2d(gp_Ax2d(profile_center, gp_Dir2d()), profile_center.Distance(p1)) geom_profile_circle = GCE2d_MakeCircle(profile_circle).Value() # Construct the outer circle gp_Circ2d outer_circle = gp_Circ2d(gp_Ax2d(gp_Pnt2d(0, 0), gp_Dir2d()), top_radius) geom_outer_circle = GCE2d_MakeCircle(outer_circle).Value() inter = Geom2dAPI_InterCurveCurve(geom_profile_circle, geom_outer_circle) num_points = inter.NbPoints() assert isinstance(p1, gp_Pnt2d) if num_points == 2: if p1.Distance(inter.Point(1)) < p1.Distance(inter.Point(2)): p2 = inter.Point(1) else: p2 = inter.Point(2) elif num_points == 1: p2 = inter.Point(1) else: sys.exit(-1) # Trim the profile circle and mirror trimmed_profile = GCE2d_MakeArcOfCircle(profile_circle, p1, p2).Value() # Calculate the outermost point p3 = gp_Pnt2d(cos(tooth_angle / 2.) * top_radius, sin(tooth_angle / 2.) * top_radius) # and use it to create the third arc trimmed_outer = GCE2d_MakeArcOfCircle(outer_circle, p2, p3).Value() # Mirror and reverse the three arcs mirror_axis = gp_Ax2d(gp_Origin2d(), gp_DX2d().Rotated(tooth_angle / 2.)) mirror_base = Geom2d_TrimmedCurve.DownCast(trimmed_base.Copy()) mirror_profile = Geom2d_TrimmedCurve.DownCast(trimmed_profile.Copy()) mirror_outer = Geom2d_TrimmedCurve.DownCast(trimmed_outer.Copy()) mirror_base.Mirror(mirror_axis) mirror_profile.Mirror(mirror_axis) mirror_outer.Mirror(mirror_axis) mirror_base.Reverse() mirror_profile.Reverse() mirror_outer.Reverse() # Replace the two outer arcs with a single one outer_start = trimmed_outer.StartPoint() outer_mid = trimmed_outer.EndPoint() outer_end = mirror_outer.EndPoint() outer_arc = GCE2d_MakeArcOfCircle(outer_start, outer_mid, outer_end).Value() # Create an arc for the inside of the wedge inner_circle = gp_Circ2d(gp_Ax2d(gp_Pnt2d(0, 0), gp_Dir2d()), top_radius - roller_diameter) inner_start = gp_Pnt2d(top_radius - roller_diameter, 0) inner_arc = GCE2d_MakeArcOfCircle(inner_circle, inner_start, tooth_angle).Value() inner_arc.Reverse() # Convert the 2D arcs and two extra lines to 3D edges plane = gp_Pln(gp_Origin(), gp_DZ()) arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_base, plane)).Edge() arc2 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_profile, plane)).Edge() arc3 = BRepBuilderAPI_MakeEdge(geomapi_To3d(outer_arc, plane)).Edge() arc4 = BRepBuilderAPI_MakeEdge(geomapi_To3d(mirror_profile, plane)).Edge() arc5 = BRepBuilderAPI_MakeEdge(geomapi_To3d(mirror_base, plane)).Edge() p4 = mirror_base.EndPoint() p5 = inner_arc.StartPoint() lin1 = BRepBuilderAPI_MakeEdge(gp_Pnt(p4.X(), p4.Y(), 0), gp_Pnt(p5.X(), p5.Y(), 0)).Edge() arc6 = BRepBuilderAPI_MakeEdge(geomapi_To3d(inner_arc, plane)).Edge() p6 = inner_arc.EndPoint() lin2 = BRepBuilderAPI_MakeEdge(gp_Pnt(p6.X(), p6.Y(), 0), gp_Pnt(p0.X(), p0.Y(), 0)).Edge() wire = BRepBuilderAPI_MakeWire(arc1) wire.Add(arc2) wire.Add(arc3) wire.Add(arc4) wire.Add(arc5) wire.Add(lin1) wire.Add(arc6) wire.Add(lin2) face = BRepBuilderAPI_MakeFace(wire.Wire()) wedge = BRepPrimAPI_MakePrism(face.Shape(), gp_Vec(0.0, 0.0, thickness)) return wedge.Shape()
def __init__(self, shape, v): v = CheckGeom.to_vector(v) builder = BRepPrimAPI_MakePrism(shape.object, v) self._shape = Shape.wrap(builder.Shape()) self._s1 = Shape.wrap(builder.FirstShape()) self._s2 = Shape.wrap(builder.LastShape())
def __init__(self, face, v): v = CheckGeom.to_vector(v) builder = BRepPrimAPI_MakePrism(face.object, v) self._solid = Solid(builder.Shape()) self._f1 = Face(builder.FirstShape()) self._f2 = Face(builder.LastShape())
def makePrismFromFace(aface, edir): return BRepPrimAPI_MakePrism(aface, gp_Vec(gp_Pnt(0., 0., 0.), gp_Pnt(edir[0], edir[1], edir[2]))).Shape()
def __init__(self, wire, v): v = CheckGeom.to_vector(v) builder = BRepPrimAPI_MakePrism(wire.object, v) self._shell = Shell(builder.Shape()) self._w1 = Wire(builder.FirstShape()) self._w2 = Wire(builder.LastShape())
def __init__(self, edge, v): v = CheckGeom.to_vector(v) builder = BRepPrimAPI_MakePrism(edge.object, v) self._f = Face(builder.Shape()) self._e1 = Edge(builder.FirstShape()) self._e2 = Edge(builder.LastShape())
def __init__(self, vertex, v): v = CheckGeom.to_vector(v) builder = BRepPrimAPI_MakePrism(vertex.object, v) self._e = Edge(builder.Shape()) self._v1 = Vertex(builder.FirstShape()) self._v2 = Vertex(builder.LastShape())
def make_prism_from_face(aFace, eDir): return BRepPrimAPI_MakePrism( aFace, gp_Vec(gp_Pnt(0., 0., 0.), gp_Pnt(eDir[0], eDir[1], eDir[2]))).Shape()
# A wire instead of a generic shape now aMirroredWire = topods.Wire(aMirroredShape) # Combine the two constituent wires mkWire = BRepBuilderAPI_MakeWire() mkWire.Add(aWire.Wire()) mkWire.Add(aMirroredWire) myWireProfile = mkWire.Wire() # The face that we'll sweep to make the prism myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile) # We want to sweep the face along the Z axis to the height aPrismVec = gp_Vec(0, 0, height) myBody_step1 = BRepPrimAPI_MakePrism(myFaceProfile.Face(), aPrismVec) # Add fillets to all edges through the explorer mkFillet = BRepFilletAPI_MakeFillet(myBody_step1.Shape()) anEdgeExplorer = TopExp_Explorer(myBody_step1.Shape(), TopAbs_EDGE) while anEdgeExplorer.More(): anEdge = topods.Edge(anEdgeExplorer.Current()) mkFillet.Add(thickness / 12.0, anEdge) anEdgeExplorer.Next() # Create the neck of the bottle neckLocation = gp_Pnt(0, 0, height) neckAxis = gp_DZ() neckAx2 = gp_Ax2(neckLocation, neckAxis)