def makePieSlice(r, theta0, theta1, z_min, z_max): p0 = gp_Pnt(0, 0, z_min) p1 = gp_Pnt(r * cos(theta0), r * sin(theta0), z_min) p2 = gp_Pnt(r * cos(theta1), r * sin(theta1), z_min) edges = [] los = TopTools_ListOfShape() me = BRepBuilderAPI_MakeEdge(p0, p1) edges.append(me.Edge()) los.Append(me.Edge()) ax = gp_Ax2(gp_Pnt(0, 0, z_min), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0)) circ = gp_Circ(ax, r) me = BRepBuilderAPI_MakeEdge(circ, theta0, theta1) edges.append(me.Edge()) los.Append(me.Edge()) me = BRepBuilderAPI_MakeEdge(p2, p0) edges.append(me.Edge()) los.Append(me.Edge()) """ mw = BRepBuilderAPI_MakeWire() for i in edges: mw.Add(i) """ mw = BRepBuilderAPI_MakeWire() mw.Add(los) pln = gp_Pln(gp_Pnt(0, 0, z_min), gp_Dir(0, 0, 1)) mf = BRepBuilderAPI_MakeFace(pln, mw.Wire()) face = mf.Face() mp = BRepPrimAPI_MakePrism(face, gp_Vec(0, 0, z_max - z_min)) return mp.Shape()
def extrudeLinear(cls, outerWire, innerWires, vecNormal): """ Attempt to extrude the list of wires into a prismatic solid in the provided direction :param outerWire: the outermost wire :param innerWires: a list of inner wires :param vecNormal: a vector along which to extrude the wires :return: a Solid object The wires must not intersect Extruding wires is very non-trivial. Nested wires imply very different geometry, and there are many geometries that are invalid. In general, the following conditions must be met: * all wires must be closed * there cannot be any intersecting or self-intersecting wires * wires must be listed from outside in * more than one levels of nesting is not supported reliably This method will attempt to sort the wires, but there is much work remaining to make this method reliable. """ # one would think that fusing faces into a compound and then extruding would work, # but it doesnt-- the resulting compound appears to look right, ( right number of faces, etc), # but then cutting it from the main solid fails with BRep_NotDone. # the work around is to extrude each and then join the resulting solids, which seems to work # FreeCAD allows this in one operation, but others might not face = Face.makeFromWires(outerWire, innerWires) prism_builder = BRepPrimAPI_MakePrism(face.wrapped, vecNormal.wrapped, True) return cls(prism_builder.Shape())
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.GetHandle(), 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 Solid(self): mw = BRepBuilderAPI_MakeWire() points = [] x = -self.length / 2.0 y = -self.width / 2.0 z = 0.0 points.append(gp_Pnt(x, y, z)) x = self.length / 2.0 points.append(gp_Pnt(x, y, z)) me = BRepBuilderAPI_MakeEdge(points[0], points[1]) mw.Add(me.Edge()) # bottom edge ax = gp_Ax2(gp_Pnt(x, 0, 0), gp_Dir(0, 0, 1), gp_Dir(0, -1, 0)) circ = gp_Circ(ax, self.width / 2.0) me = BRepBuilderAPI_MakeEdge(circ, 0, pi) mw.Add(me.Edge()) points = [] y = self.width / 2.0 points.append(gp_Pnt(x, y, z)) x = -self.length / 2.0 points.append(gp_Pnt(x, y, z)) me = BRepBuilderAPI_MakeEdge(points[0], points[1]) mw.Add(me.Edge()) # top edge ax = gp_Ax2(gp_Pnt(x, 0, 0), gp_Dir(0, 0, 1), gp_Dir(0, 1, 0)) circ = gp_Circ(ax, self.width / 2.0) me = BRepBuilderAPI_MakeEdge(circ, 0, pi) mw.Add(me.Edge()) mf = BRepBuilderAPI_MakeFace(mw.Wire()) mp = BRepPrimAPI_MakePrism(mf.Face(), gp_Vec(0, 0, self.thickness)) shape = mp.Shape() #v_trans = gp_Vec(self.ax2.Location().XYZ()) ax = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0)) #mainRotationAngle = ax.Angle(self.ax2) trsf = gp_Trsf() trsf.SetTransformation(gp_Ax3(self.ax2), gp_Ax3(ax)) mt = BRepBuilderAPI_Transform(shape, trsf) return mt.Shape()
def update_shape(self, change): d = self.declaration if d.shape: c = d.shape.proxy else: c = self.get_shape() if d.infinite: self.shape = BRepPrimAPI_MakePrism(c.shape.Shape(), d.direction, True, d.copy, d.canonize) else: self.shape = BRepPrimAPI_MakePrism(c.shape.Shape(), gp_Vec(*d.vector), d.copy, d.canonize)
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 build(input, output): #sample xml for testing xml = "<eagle version=\"7\"><drawing><board><plain><wire x1=\"0\" y1=\"0\" x2=\"0\" y2=\"2\" width=\"0.254\" layer=\"20\"/><wire x1=\"0\" y1=\"2\" x2=\"1.5\" y2=\"2\" width=\"0.254\" layer=\"20\"/><wire x1=\"1.5\" y1=\"2\" x2=\"1\" y2=\"0\" width=\"0.254\" layer=\"20\"/><wire x1=\"1\" y1=\"0\" x2=\"0\" y2=\"0\" width=\"0.254\" layer=\"20\"/></plain></board></drawing></eagle>" #xmldoc = minidom.parseString( xml ) xmldoc = minidom.parse(input) wires = xmldoc.getElementsByTagName('wire') makeWire = BRepBuilderAPI_MakeWire() for wire in wires: if wire.attributes['layer'].value == '20': x1 = float(wire.attributes['x1'].value) y1 = float(wire.attributes['y1'].value) x2 = float(wire.attributes['x2'].value) y2 = float(wire.attributes['y2'].value) #print('Building edge from {}, {} to {}, {}'.format( x1,y1,x2,y2)) edge = BRepBuilderAPI_MakeEdge( gp_Pnt( x1, y1, 0.0 ), \ gp_Pnt( x2, y2, 0.0 ) \ ) makeWire.Add(edge.Edge()) face = BRepBuilderAPI_MakeFace(makeWire.Wire()) #vector & height vector = gp_Vec(0, 0, .1) body = BRepPrimAPI_MakePrism(face.Face(), vector) # initialize the STEP exporter step_writer = STEPControl_Writer() Interface_Static_SetCVal("write.step.schema", "AP203") # transfer shapes and write file step_writer.Transfer(body.Shape(), STEPControl_AsIs) status = step_writer.Write(output) if status != IFSelect_RetDone: raise AssertionError("load failed")
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 make_shape(self): # 1 - retrieve the data from the UIUC airfoil data page foil_dat_url = 'http://www.ae.illinois.edu/m-selig/ads/coord_seligFmt/%s.dat' % self.profile if py2: f = urllib2.urlopen(foil_dat_url) else: http = urllib3.PoolManager() f = http.urlopen('GET', foil_dat_url).data.decode() f = io.StringIO(f) 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) line = line.lstrip().rstrip().replace(' ', ' ').replace( ' ', ' ').replace(' ', ' ') data = line.split(' ') # data[0] = x coord. data[1] = y coord. # 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 makeEllipticalAnnularSolid(rx_outer, ry_outer, rx_inner, ry_inner, z_min, z_max): # Make the outer part of the clamp ax = gp_Ax2(gp_Pnt(0, 0, z_min), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0)) ge = Geom_Ellipse(ax, rx_outer, ry_outer) elip = ge.Elips() me = BRepBuilderAPI_MakeEdge(elip, 0, 2 * pi) edge = me.Edge() mw = BRepBuilderAPI_MakeWire(edge) wire = mw.Wire() pln = gp_Pln(gp_Pnt(0, 0, z_min), gp_Dir(0, 0, 1)) mf = BRepBuilderAPI_MakeFace(pln, wire) face = mf.Face() mp = BRepPrimAPI_MakePrism(face, gp_Vec(0, 0, z_max - z_min)) body = mp.Shape() # Make the cutter for the inner hole body ax = gp_Ax2(gp_Pnt(0, 0, z_min - 1), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0)) ge = Geom_Ellipse(ax, rx_inner, ry_inner) elip = ge.Elips() me = BRepBuilderAPI_MakeEdge(elip, 0, 2 * pi) edge = me.Edge() mw = BRepBuilderAPI_MakeWire(edge) wire = mw.Wire() pln = gp_Pln(gp_Pnt(0, 0, z_min - 1), gp_Dir(0, 0, 1)) mf = BRepBuilderAPI_MakeFace(pln, wire) face = mf.Face() mp = BRepPrimAPI_MakePrism(face, gp_Vec(0, 0, z_max + 1)) innerHoleCutter = mp.Shape() # Cut out the middle mc = BRepAlgoAPI_Cut(body, innerHoleCutter) return mc.Shape()
def ExtrudeFace(face, vec=gp_Vec(1, 0, 0)): """Extrudes a face by input vector Parameters ---------- face : TopoDS_Face vec : OCC.gp.gp_Vec The offset vector to extrude through Returns ------- shape : TopoDS_Shape The extruded shape Notes ----- Uses BRepBuilderAPI_MakePrism """ from OCC.BRepPrimAPI import BRepPrimAPI_MakePrism builder = BRepPrimAPI_MakePrism(face, vec) builder.Build() return builder.Shape()
def build_test(path): #points pt1 = gp_Pnt(0, 0, 0) pt2 = gp_Pnt(0, 2, 0) pt3 = gp_Pnt(1.5, 2, 0) pt4 = gp_Pnt(1, 0, 0) edge1 = BRepBuilderAPI_MakeEdge(pt1, pt2) edge2 = BRepBuilderAPI_MakeEdge(pt2, pt3) edge3 = BRepBuilderAPI_MakeEdge(pt3, pt4) edge4 = BRepBuilderAPI_MakeEdge(pt4, pt1) #make wire with 4 edges wire = BRepBuilderAPI_MakeWire(edge1.Edge(), edge2.Edge(), edge3.Edge(), edge4.Edge()) #alternate wire. create and then add in #makeWire = BRepBuilderAPI_MakeWire() #makeWire.add( wire ) #wireProfile = makeWire.Wire() face = BRepBuilderAPI_MakeFace(wire.Wire()) #vector & height vector = gp_Vec(0, 0, .1) body = BRepPrimAPI_MakePrism(face.Face(), vector) # initialize the STEP exporter step_writer = STEPControl_Writer() Interface_Static_SetCVal("write.step.schema", "AP203") # transfer shapes and write file step_writer.Transfer(body.Shape(), STEPControl_AsIs) status = step_writer.Write(path) if status != IFSelect_RetDone: raise AssertionError("load failed")
def shape_base_drain(): ''' output s: TopoDS_Shape ''' wire = wire_circle() trsf = gp_Trsf() trsf.SetScale(DRAIN_RCS.Location(), DRAIN_R) bresp_trsf = BRepBuilderAPI_Transform(wire, trsf) wire = topods.Wire(bresp_trsf.Shape()) base_face = BRepBuilderAPI_MakeFace(wire).Face() shape = BRepPrimAPI_MakePrism(base_face, gp_Vec(0, 0, DRAIN_T)).Shape() return shape
def draw3D(self, spaces, displaySize = (1024, 768), update = False): """ draw3D(aecSpaceGroup) Accepts an aecSpaceGroup object and renders its list of aecSpaces to the pythonOCC display. Returns True on success failure. Returns False on failure. """ try: if not spaces: return False if type(spaces) != list: spaces = spaces.spaces if not spaces: return False __display, __start_display, __add_menu, __add_function_to_menu = init_display('qt-pyqt5', size = displaySize) for space in spaces: points = self.makePoints(space) if not points: continue pointPairs = self.makePointPairs(points) if not pointPairs: continue edges = self.makeEdges(pointPairs) if not edges: continue wire = self.makeWire(edges) if not wire.IsDone: continue #if not wire: continue face = BRepBuilderAPI_MakeFace(wire.Wire()) if not face: continue vector = gp_Vec(0, 0, space.height) spaceVolume = BRepPrimAPI_MakePrism(face.Face(), vector).Shape() if not spaceVolume: continue displayColor = space.color.color_01 spaceColor = OCC.Quantity.Quantity_Color_Name( displayColor[0], displayColor[1], displayColor[2]) __display.DisplayShape( spaceVolume, color = spaceColor, transparency = space.color.alpha_01, update = update) __display.FitAll() __start_display() __display = None return True except Exception: traceback.print_exc() return False
def draw(self, display, c): #self.out() pol = self.curve.polygon() if pol != None: pol = pol.Wire() n = Vector(0, 0, 1) n.scale(self.height) n = n.gpV() prism = BRepPrimAPI_MakePrism(pol, n).Shape() if c == 0: color = 'YELLOW' elif c == 1: color = 'BLUE' elif c == 2: color = 'GREEN' elif c == 3: color = 'BLACK' elif c == 4: color = 'RED' elif c == 5: color = 'WHITE' elif c == 6: color = 'CYAN' else: color = 'ORANGE' display.DisplayColoredShape(prism, color, update=True)
def draw(self,display,c) : pol=self.curve.polygon() if pol!=None: pol=pol.Wire() n=copy.copy(self.normal) n.scale(self.thickness) n=n.gpV() face=BRepBuilderAPI_MakeFace(pol,True).Face() #my_shell = BRepPrimAPI_MakePrism(my_pol,n1).Shape() prism = BRepPrimAPI_MakePrism(face,n).Shape() if c==0: color='YELLOW' elif c==1: color='BLUE' elif c==2: color='GREEN' elif c==3: color='BLACK' elif c==4: color='RED' elif c==5: color='WHITE' elif c==6: color='CYAN' else: color='ORANGE' display.DisplayColoredShape(prism,color, update=True)
def gen_boxSolidAsTable(width=1000, depth=1000, height=1215): pntList = [ gp_Pnt(width / 2., depth / 2., 0), gp_Pnt(-width / 2., depth / 2., 0), gp_Pnt(-width / 2., -depth / 2., 0), gp_Pnt(width / 2., -depth / 2., 0) ] edgList = [] for i in range(0, len(pntList) - 1): edgList.append(BRepBuilderAPI_MakeEdge(pntList[i], pntList[i + 1])) edgList.append(BRepBuilderAPI_MakeEdge(pntList[3], pntList[0])) wire = BRepBuilderAPI_MakeWire() for i in edgList: wire.Add(i.Edge()) wireProfile = wire.Wire() faceProfile = BRepBuilderAPI_MakeFace(wireProfile).Shape() aPrismVec = gp_Vec(0, 0, height) return BRepPrimAPI_MakePrism(faceProfile, aPrismVec).Shape()
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 char_to_solid(self, glyph): layer = glyph.layers['Fore'] bodies = [] for contour in layer: i = 0 total = len(contour) curve_points = [] if total <= 2: # Can't make solid out of 1 or 2 points continue wire = BRepBuilderAPI_MakeWire() for point in contour: if point.on_curve: if i > 0: # Complete old curve curve_points.append(gp_Pnt(point.x, point.y, 0)) self.add_to_wire(curve_points, wire) if i < total: # Start new curve curve_points = [gp_Pnt(point.x, point.y, 0)] if i == total-1: first = contour[0] curve_points.append(gp_Pnt(first.x, first.y, 0)) self.add_to_wire(curve_points, wire) else: curve_points.append(gp_Pnt(point.x, point.y, 0)) if i == total-1: first = contour[0] curve_points.append(gp_Pnt(first.x, first.y, 0)) self.add_to_wire(curve_points, wire) i += 1 face = BRepBuilderAPI_MakeFace(wire.Wire()) extrusion_vector = gp_Vec(0, 0, self.thickness) prism = BRepPrimAPI_MakePrism(face.Shape(), extrusion_vector) bodies.append(dict( prism = prism, isClockwise = contour.isClockwise(), )) if len(bodies) > 0: if len(bodies) == 1: return bodies[0]['prism'].Shape() elif len(bodies) > 1: final = None positive_union = None for body in bodies: if body['isClockwise'] == 1: if positive_union: positive_union = BRepAlgoAPI_Fuse( positive_union.Shape(), body['prism'].Shape()) else: positive_union = body['prism'] negative_union = None for body in bodies: if body['isClockwise'] == 0: if negative_union: negative_union = BRepAlgoAPI_Fuse( negative_union.Shape(), body['prism'].Shape()) else: negative_union = body['prism'] if positive_union and negative_union: final = BRepAlgoAPI_Cut( positive_union.Shape(), negative_union.Shape()) elif positive_union: final = positive_union elif negative_union: final = negative_union return final.Shape()
def create_shape(self): d = self.declaration self.shape = BRepPrimAPI_MakePrism(d.shape, d.direction, d.infinite, d.copy, d.canonize)
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() Proxy(trimmed_base).Reverse() # just a trick p0 = Proxy(trimmed_base).StartPoint() p1 = Proxy(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: 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 = Handle_Geom2d_TrimmedCurve.DownCast( Proxy(trimmed_base).Copy()) mirror_profile = Handle_Geom2d_TrimmedCurve.DownCast( Proxy(trimmed_profile).Copy()) mirror_outer = Handle_Geom2d_TrimmedCurve.DownCast( Proxy(trimmed_outer).Copy()) Proxy(mirror_base).Mirror(mirror_axis) Proxy(mirror_profile).Mirror(mirror_axis) Proxy(mirror_outer).Mirror(mirror_axis) Proxy(mirror_base).Reverse() Proxy(mirror_profile).Reverse() Proxy(mirror_outer).Reverse() # Replace the two outer arcs with a single one outer_start = Proxy(trimmed_outer).StartPoint() outer_mid = Proxy(trimmed_outer).EndPoint() outer_end = Proxy(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() Proxy(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 = Proxy(mirror_base).EndPoint() p5 = Proxy(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 = Proxy(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 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() Proxy(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 makeStringerWithContinuousSlot(): thickness = 5.0 width = 25.0 slot_width = 5.0 slot_depth = thickness / 4.0 length = 150.0 points = [] x = 0 y = 0 z = 0 x = thickness / 2.0 y = -width / 2.0 points.append(gp_Pnt(x, y, z)) # bottom right corner y = -slot_width / 2.0 points.append(gp_Pnt(x, y, z)) x = x - slot_depth points.append(gp_Pnt(x, y, z)) y = slot_width / 2.0 points.append(gp_Pnt(x, y, z)) x = x + slot_depth points.append(gp_Pnt(x, y, z)) y = width / 2.0 # top right corner points.append(gp_Pnt(x, y, z)) x = -thickness / 2.0 # top left corner points.append(gp_Pnt(x, y, z)) y = slot_width / 2.0 points.append(gp_Pnt(x, y, z)) x = x + slot_depth points.append(gp_Pnt(x, y, z)) y = -slot_width / 2.0 points.append(gp_Pnt(x, y, z)) x = x - slot_depth points.append(gp_Pnt(x, y, z)) y = -width / 2.0 points.append(gp_Pnt(x, y, z)) # bottom left corner x = thickness / 2.0 points.append(gp_Pnt(x, y, z)) # back to the bottom right corner mw = BRepBuilderAPI_MakeWire() for i in range(len(points) - 1): me = BRepBuilderAPI_MakeEdge(points[i], points[i + 1]) edge = me.Edge() mw.Add(edge) mf = BRepBuilderAPI_MakeFace(mw.Wire()) mp = BRepPrimAPI_MakePrism(mf.Face(), gp_Vec(0, 0, length)) return mp.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 # Create the neck of the bottle neckLocation = gp_Pnt(0, 0, height)
aBRepTrsf = Transform(aWire.Wire(), aTrsf) aMirroredShape = aBRepTrsf.Shape() aMirroredWire = OCC.TopoDS.TopoDS_Shape(aMirroredShape) aMirroredWire = OCC.TopoDS.topods().Wire(aMirroredWire) mkWire = MakeWire() mkWire.Add(aWire.Wire()) mkWire.Add(aMirroredWire) myWireProfile = mkWire.Wire() # Body : Prism the Profile myFaceProfile = MakeFace(myWireProfile) if myFaceProfile.IsDone(): bottomFace = myFaceProfile.Face() aPrismVec = gp_Vec(0, 0, myHeight) myBody = MakePrism(myFaceProfile.Shape(), aPrismVec) # Body : Apply Fillets mkFillet = MakeFillet(myBody.Shape()) aEdgeExplorer = Explorer(myBody.Shape(), OCC.TopAbs.TopAbs_EDGE) while aEdgeExplorer.More(): aEdge = OCC.TopoDS.topods_Edge(aEdgeExplorer.Current()) mkFillet.Add(myThickness / 12, aEdge) aEdgeExplorer.Next() myBody = mkFillet.Shape() # Body : Add the Neck neckLocation = OCC.gp.gp_Pnt(0, 0, myHeight) neckNormal = OCC.gp.gp_DZ() neckAx2 = OCC.gp.gp_Ax2(neckLocation, neckNormal) myNeckRadius = myThickness / 4