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 extrusion(event=None): # Make a box Box = BRepPrimAPI_MakeBox(400., 250., 300.) S = Box.Shape() # Choose the first Face of the box F = next(Topo(S).faces()) surf = BRep_Tool_Surface(F) # Make a plane from this face Pl = Handle_Geom_Plane_DownCast(surf) Pln = Pl.GetObject() # Get the normal of this plane. This will be the direction of extrusion. D = Pln.Axis().Direction() # Inverse normal #D.Reverse() # Create the 2D planar sketch MW = BRepBuilderAPI_MakeWire() p1 = gp_Pnt2d(200., -100.) p2 = gp_Pnt2d(100., -100.) aline = GCE2d_MakeLine(p1, p2).Value() Edge1 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge1.Edge()) p1 = p2 p2 = gp_Pnt2d(100., -200.) aline = GCE2d_MakeLine(p1, p2).Value() Edge2 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge2.Edge()) p1 = p2 p2 = gp_Pnt2d(200., -200.) aline = GCE2d_MakeLine(p1, p2).Value() Edge3 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge3.Edge()) p1 = p2 p2 = gp_Pnt2d(200., -100.) aline = GCE2d_MakeLine(p1, p2).Value() Edge4 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge4.Edge()) # Build Face from Wire. NB: a face is required to generate a solid. MKF = BRepBuilderAPI_MakeFace() MKF.Init(surf, False, 1e-6) MKF.Add(MW.Wire()) FP = MKF.Face() breplib_BuildCurves3d(FP) MKP = BRepFeat_MakePrism(S, FP, F, D, False, True) MKP.Perform(200.) # TODO MKP completes, seeing a split operation but no extrusion assert MKP.IsDone() res1 = MKP.Shape() display.EraseAll() display.DisplayColoredShape(res1, 'BLUE') display.DisplayColoredShape(FP, 'YELLOW') display.FitAll()
def edge(event=None): # The blud edge blue_edge = BRepBuilderAPI_MakeEdge(gp_Pnt(-80, -50, -20), gp_Pnt(-30, -60, -60)) v1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-20, 10, -30)) v2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10, 7, -25)) yellow_edge = BRepBuilderAPI_MakeEdge(v1.Vertex(), v2.Vertex()) # The white edge line = gp_Lin(gp_Ax1(gp_Pnt(10, 10, 10), gp_Dir(1, 0, 0))) white_edge = BRepBuilderAPI_MakeEdge(line, -20, 10) # The red edge elips = gp_Elips(gp_Ax2(gp_Pnt(10, 0, 0), gp_Dir(1, 1, 1)), 60, 30) red_edge = BRepBuilderAPI_MakeEdge(elips, 0, math.pi / 2) # The green edge and the both extreme vertex p1 = gp_Pnt(-15, 200, 10) p2 = gp_Pnt(5, 204, 0) p3 = gp_Pnt(15, 200, 0) p4 = gp_Pnt(-15, 20, 15) p5 = gp_Pnt(-5, 20, 0) p6 = gp_Pnt(15, 20, 0) p7 = gp_Pnt(24, 120, 0) p8 = gp_Pnt(-24, 120, 12.5) array = TColgp_Array1OfPnt(1, 8) array.SetValue(1, p1) array.SetValue(2, p2) array.SetValue(3, p3) array.SetValue(4, p4) array.SetValue(5, p5) array.SetValue(6, p6) array.SetValue(7, p7) array.SetValue(8, p8) curve = Geom_BezierCurve(array) make_edge = BRepBuilderAPI_MakeEdge(curve.GetHandle()) green_edge = make_edge v3 = make_edge.Vertex1() v4 = make_edge.Vertex2() display.DisplayColoredShape(blue_edge.Edge(), 'BLUE') display.DisplayShape(v1.Vertex()) display.DisplayShape(v2.Vertex()) display.DisplayColoredShape(white_edge.Edge(), 'WHITE') display.DisplayColoredShape(yellow_edge.Edge(), 'YELLOW') display.DisplayColoredShape(red_edge.Edge(), 'RED') display.DisplayColoredShape(green_edge.Edge(), 'GREEN') display.DisplayShape(v3) display.DisplayShape(v4, update=True)
def edge(event=None): # The blud edge BlueEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(-80, -50, -20), gp_Pnt(-30, -60, -60)) V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-20, 10, -30)) V2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10, 7, -25)) YellowEdge = BRepBuilderAPI_MakeEdge(V1.Vertex(), V2.Vertex()) #The white edge line = gp_Lin(gp_Ax1(gp_Pnt(10, 10, 10), gp_Dir(1, 0, 0))) WhiteEdge = BRepBuilderAPI_MakeEdge(line, -20, 10) #The red edge Elips = gp_Elips(gp_Ax2(gp_Pnt(10, 0, 0), gp_Dir(1, 1, 1)), 60, 30) RedEdge = BRepBuilderAPI_MakeEdge(Elips, 0, math.pi / 2) # The green edge and the both extreme vertex P1 = gp_Pnt(-15, 200, 10) P2 = gp_Pnt(5, 204, 0) P3 = gp_Pnt(15, 200, 0) P4 = gp_Pnt(-15, 20, 15) P5 = gp_Pnt(-5, 20, 0) P6 = gp_Pnt(15, 20, 0) P7 = gp_Pnt(24, 120, 0) P8 = gp_Pnt(-24, 120, 12.5) array = TColgp_Array1OfPnt(1, 8) array.SetValue(1, P1) array.SetValue(2, P2) array.SetValue(3, P3) array.SetValue(4, P4) array.SetValue(5, P5) array.SetValue(6, P6) array.SetValue(7, P7) array.SetValue(8, P8) curve = Geom_BezierCurve(array) ME = BRepBuilderAPI_MakeEdge(curve.GetHandle()) GreenEdge = ME V3 = ME.Vertex1() V4 = ME.Vertex2() display.DisplayColoredShape(BlueEdge.Edge(), 'BLUE') display.DisplayShape(V1.Vertex()) display.DisplayShape(V2.Vertex()) display.DisplayColoredShape(WhiteEdge.Edge(), 'WHITE') display.DisplayColoredShape(YellowEdge.Edge(), 'YELLOW') display.DisplayColoredShape(RedEdge.Edge(), 'RED') display.DisplayColoredShape(GreenEdge.Edge(), 'GREEN') display.DisplayShape(V3) display.DisplayShape(V4, update=True)
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 add_to_wire(self, points, wire): array=TColgp_Array1OfPnt(1, len(points)) for i in range(len(points)): array.SetValue(i+1, points[i]) curve = Geom_BezierCurve(array) me = BRepBuilderAPI_MakeEdge(curve.GetHandle()) wire.Add(me.Edge())
def occ_triangle_mesh(event=None): # # Mesh the shape # BRepMesh_IncrementalMesh(aShape, 0.1) builder = BRep_Builder() Comp = TopoDS_Compound() builder.MakeCompound(Comp) ex = TopExp_Explorer(aShape, TopAbs_FACE) while ex.More(): F = topods_Face(ex.Current()) L = TopLoc_Location() facing = (BRep_Tool().Triangulation(F, L)).GetObject() tab = facing.Nodes() tri = facing.Triangles() for i in range(1, facing.NbTriangles() + 1): trian = tri.Value(i) #print trian index1, index2, index3 = trian.Get() for j in range(1, 4): if j == 1: M = index1 N = index2 elif j == 2: N = index3 elif j == 3: M = index2 ME = BRepBuilderAPI_MakeEdge(tab.Value(M), tab.Value(N)) if ME.IsDone(): builder.Add(Comp, ME.Edge()) ex.Next() display.DisplayShape(Comp, update=True)
def trimedge(lbound, ubound, occedge): """ This function trims the OCCedge according to the specified lower and upper bound. Parameters ---------- lbound : float The lower bound of the OCCedge. ubound : float The upper bound of the OCCedge. occedge : OCCedge The edge to be trimmed. Returns ------- trimmed edge : OCCedge The trimmed OCCedge. """ adaptor = BRepAdaptor_Curve(occedge) tr = Geom_TrimmedCurve(adaptor.Curve().Curve(), lbound, ubound) tr.SetTrim(lbound, ubound) bspline_handle = geomconvert_CurveToBSplineCurve(tr.GetHandle()) tr_edge = BRepBuilderAPI_MakeEdge(bspline_handle) return tr_edge.Edge()
def write_edge(points_edge, topo_edge): """ Method to recreate an Edge associated to a geometric curve after the modification of its points. :param points_edge: the deformed points array. :param topo_edge: the Edge to be modified :return: Edge (Shape) :rtype: TopoDS_Edge """ # convert Edge to Geom B-spline Curve nurbs_converter = BRepBuilderAPI_NurbsConvert(topo_edge) nurbs_converter.Perform(topo_edge) nurbs_curve = nurbs_converter.Shape() topo_curve = topods_Edge(nurbs_curve) h_geomcurve = BRep_Tool.Curve(topo_curve)[0] h_bcurve = geomconvert_CurveToBSplineCurve(h_geomcurve) bspline_edge_curve = h_bcurve.GetObject() # Edge geometric properties nb_cpt = bspline_edge_curve.NbPoles() # check consistency if points_edge.shape[0] != nb_cpt: raise ValueError("Input control points do not have not have the " "same number as the geometric edge!") else: for i in range(1, nb_cpt + 1): cpt = points_edge[i - 1] bspline_edge_curve.SetPole(i, gp_Pnt(cpt[0], cpt[1], cpt[2])) new_edge = BRepBuilderAPI_MakeEdge(bspline_edge_curve.GetHandle()) return new_edge.Edge()
def make_edge(*args): """ (gp_Pnt, gp_Pnt) """ edge = BRepBuilderAPI_MakeEdge(*args) with assert_isdone(edge, 'failed to produce edge'): result = edge.Edge() edge.Delete() return result
def face(): #The brown face circle = gp_Circ(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 80) Edge1 = BRepBuilderAPI_MakeEdge(circle, 0, math.pi) Edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, -80), gp_Pnt(0, -10, 40)) Edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, -10.00001, 40), gp_Pnt(0, 0, 80)) ##TopoDS_Wire YellowWire MW1 = BRepBuilderAPI_MakeWire(Edge1.Edge(), Edge2.Edge(), Edge3.Edge()) print MW1.IsDone() if MW1.IsDone(): yellow_wire = MW1.Wire() brown_face = BRepBuilderAPI_MakeFace(yellow_wire) display.DisplayColoredShape(brown_face.Face(), 'BLUE')
def make_bspline_edge(pyptlist, mindegree=3, maxdegree=8): array = TColgp_Array1OfPnt(1, len(pyptlist)) pcnt = 1 for pypt in pyptlist: gppt = make_gppnt(pypt) array.SetValue(pcnt, gppt) pcnt += 1 bcurve = GeomAPI_PointsToBSpline(array, mindegree, maxdegree).Curve() curve_edge = BRepBuilderAPI_MakeEdge(bcurve) return curve_edge.Edge()
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 wire_2_bsplinecurve_edge(occwire): ''' occwire: wire to be converted type: occwire ''' adaptor = BRepAdaptor_CompCurve(occwire) hadap = BRepAdaptor_HCompCurve(adaptor) from OCC.Approx import Approx_Curve3d from OCC.GeomAbs import GeomAbs_C0, GeomAbs_C0, GeomAbs_C2, GeomAbs_C3 approx = Approx_Curve3d(hadap.GetHandle(), 1e-06, GeomAbs_C2, 10000, 12) bspline_handle = approx.Curve() occedge = BRepBuilderAPI_MakeEdge(bspline_handle) return occedge.Edge()
def make_bspline_edge_interpolate(pyptlist, is_closed): ''' pyptlist: list of pypt type: list(tuple) is_closed: is the curve open or close type: bool, True or False ''' gpptlist = make_gppntlist(pyptlist) bcurve = Common.interpolate_points_to_spline_no_tangency(gpptlist, closed=is_closed) curve_edge = BRepBuilderAPI_MakeEdge(bcurve) return curve_edge.Edge()
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 makeEdges(self, pointPairs): """ [Topo_DS_Edge,] makeEdges([[gp_Pnt, gp_Pnt],]) Returns a list of Topo_DS_Edges derived from a list of gp_Pnt pairs. Returns None on failure. """ try: edges = [] for pair in pointPairs: newEdge = BRepBuilderAPI_MakeEdge(pair[0], pair[1]) edges.append(newEdge.Edge()) return edges except Exception: traceback.print_exc() return None
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 simple_mesh(): # # Create the shape # shape = BRepPrimAPI_MakeBox(200, 200, 200).Shape() theBox = BRepPrimAPI_MakeBox(200, 60, 60).Shape() theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100, 20, 20), 80).Shape() shape = BRepAlgoAPI_Fuse(theSphere, theBox).Shape() # # Mesh the shape # BRepMesh_IncrementalMesh(shape, 0.8) builder = BRep_Builder() comp = TopoDS_Compound() builder.MakeCompound(comp) bt = BRep_Tool() ex = TopExp_Explorer(shape, TopAbs_FACE) while ex.More(): face = topods_Face(ex.Current()) location = TopLoc_Location() facing = (bt.Triangulation(face, location)).GetObject() tab = facing.Nodes() tri = facing.Triangles() for i in range(1, facing.NbTriangles()+1): trian = tri.Value(i) index1, index2, index3 = trian.Get() for j in range(1, 4): if j == 1: m = index1 n = index2 elif j == 2: n = index3 elif j == 3: m = index2 me = BRepBuilderAPI_MakeEdge(tab.Value(m), tab.Value(n)) if me.IsDone(): builder.Add(comp, me.Edge()) ex.Next() display.EraseAll() display.DisplayShape(shape) display.DisplayShape(comp, update=True)
def makeEllipticalAnnularSolidSlice(rx_outer, ry_outer, rx_inner, ry_inner, z_min, z_max, theta0, theta1, bias=0.5): # bias: 0.5 means the # theta is the radius where the pie sliced ends coinside with theta1 and theta0 full = makeEllipticalAnnularSolid(rx_outer, ry_outer, rx_inner, ry_inner, z_min, z_max) ax = gp_Ax2(gp_Pnt(0, 0, z_min), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0)) rx = (rx_outer - rx_inner) * bias + rx_inner ry = (ry_outer - ry_inner) * bias + ry_inner ge = Geom_Ellipse(ax, rx, ry) elip = ge.Elips() me = BRepBuilderAPI_MakeEdge(elip, 0, 2 * pi) edge = me.Edge()
def project_edge_on_face(occedge, occface): """ This function projects an OCCedge towards the OCCface. #TODO: figure out if it is a faceplane or just the face. Parameters ---------- occedge : OCCedge The edge to be projected. occface : OCCface The face to be projected on. Returns ------- Projected edge : OCCedge The projected edge on the face. """ fc = face.Face(occface) projected_curve = fc.project_curve(occedge) curve_edge = BRepBuilderAPI_MakeEdge(projected_curve) return curve_edge.Edge()
def wire_2_bsplinecurve_edge(occwire): """ This function covnerts an OCCwire to a bspline OCCedge. Parameters ---------- occwire : OCCwire The OCCwire to be converted. Returns ------- converted bspline edge : OCCedge The converted OCCedge. """ adaptor = BRepAdaptor_CompCurve(occwire) hadap = BRepAdaptor_HCompCurve(adaptor) from OCC.Approx import Approx_Curve3d from OCC.GeomAbs import GeomAbs_C2 approx = Approx_Curve3d(hadap.GetHandle(), 1e-06, GeomAbs_C2, 10000, 12) bspline_handle = approx.Curve() occedge = BRepBuilderAPI_MakeEdge(bspline_handle) return occedge.Edge()
def trimedge(lbound, ubound, occedge): ''' lbound: lower bound of the parameterise edge type: float ubound: upper bound of the parameterise edge type: float occedge: the edge to be trimmed type: occedge ''' adaptor = BRepAdaptor_Curve(occedge) #print adaptor.Trim(adaptor.FirstParameter(), adaptor.LastParameter(), adaptor.Tolerance()).GetObject().NbPoles().Curve() tr = Geom_TrimmedCurve(adaptor.Curve().Curve(), lbound, ubound) tr.SetTrim(lbound, ubound) bspline_handle = geomconvert_CurveToBSplineCurve(tr.GetHandle()) #print tr.GetHandle() tr_edge = BRepBuilderAPI_MakeEdge(bspline_handle) #occutil_edge = edge.Edge(occedge) #trimedge = occutil_edge.trim(lbound, ubound) return tr_edge.Edge()
def face(): p1 = gp_Pnt() p2 = gp_Pnt() p3 = gp_Pnt() p4 = gp_Pnt() p5 = gp_Pnt() p6 = gp_Pnt() # The white Face sphere = gp_Sphere(gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 150) green_face = BRepBuilderAPI_MakeFace(sphere, 0.1, 0.7, 0.2, 0.9) # The red face p1.SetCoord(-15, 200, 10) p2.SetCoord(5, 204, 0) p3.SetCoord(15, 200, 0) p4.SetCoord(-15, 20, 15) p5.SetCoord(-5, 20, 0) p6.SetCoord(15, 20, 35) array = TColgp_Array2OfPnt(1, 3, 1, 2) array.SetValue(1, 1, p1) array.SetValue(2, 1, p2) array.SetValue(3, 1, p3) array.SetValue(1, 2, p4) array.SetValue(2, 2, p5) array.SetValue(3, 2, p6) curve = GeomAPI_PointsToBSplineSurface(array, 3, 8, GeomAbs_C2, 0.001).Surface() red_face = BRepBuilderAPI_MakeFace(curve, 1e-6) #The brown face circle = gp_Circ(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 80) Edge1 = BRepBuilderAPI_MakeEdge(circle, 0, math.pi) Edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, -80), gp_Pnt(0, -10, 40)) Edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, -10, 40), gp_Pnt(0, 0, 80)) ##TopoDS_Wire YellowWire MW1 = BRepBuilderAPI_MakeWire(Edge1.Edge(), Edge2.Edge(), Edge3.Edge()) if MW1.IsDone(): yellow_wire = MW1.Wire() brown_face = BRepBuilderAPI_MakeFace(yellow_wire) #The pink face p1.SetCoord(35, -200, 40) p2.SetCoord(50, -204, 30) p3.SetCoord(65, -200, 30) p4.SetCoord(35, -20, 45) p5.SetCoord(45, -20, 30) p6.SetCoord(65, -20, 65) array2 = TColgp_Array2OfPnt(1, 3, 1, 2) array2.SetValue(1, 1, p1) array2.SetValue(2, 1, p2) array2.SetValue(3, 1, p3) array2.SetValue(1, 2, p4) array2.SetValue(2, 2, p5) array2.SetValue(3, 2, p6) BSplineSurf = GeomAPI_PointsToBSplineSurface(array2, 3, 8, GeomAbs_C2, 0.001) aFace = BRepBuilderAPI_MakeFace(BSplineSurf.Surface(), 1e-6).Face() ## ##//2d lines P12d = gp_Pnt2d(0.9, 0.1) P22d = gp_Pnt2d(0.2, 0.7) P32d = gp_Pnt2d(0.02, 0.1) ## line1 = Geom2d_Line(P12d, gp_Dir2d((0.2-0.9), (0.7-0.1))) line2 = Geom2d_Line(P22d, gp_Dir2d((0.02-0.2), (0.1-0.7))) line3 = Geom2d_Line(P32d, gp_Dir2d((0.9-0.02), (0.1-0.1))) ## ##//Edges are on the BSpline surface Edge1 = BRepBuilderAPI_MakeEdge(line1.GetHandle(), BSplineSurf.Surface(), 0, P12d.Distance(P22d)).Edge() Edge2 = BRepBuilderAPI_MakeEdge(line2.GetHandle(), BSplineSurf.Surface(), 0, P22d.Distance(P32d)).Edge() Edge3 = BRepBuilderAPI_MakeEdge(line3.GetHandle(), BSplineSurf.Surface(), 0, P32d.Distance(P12d)).Edge() ## Wire1 = BRepBuilderAPI_MakeWire(Edge1, Edge2, Edge3).Wire() Wire1.Reverse() pink_face = BRepBuilderAPI_MakeFace(aFace, Wire1).Face() breplib_BuildCurves3d(pink_face) display.DisplayColoredShape(green_face.Face(), 'GREEN') display.DisplayColoredShape(red_face.Face(), 'RED') display.DisplayColoredShape(pink_face, Quantity_Color(Quantity_NOC_PINK)) display.DisplayColoredShape(brown_face.Face(), 'BLUE') display.DisplayColoredShape(yellow_wire, 'YELLOW', update=True)
def __init__(self, knotVector=[], controlPoints=[], degree=3, thickness=10, axis=0, center=False): self.thickness = thickness wire = BRepBuilderAPI_MakeWire() uniqueKnots = unique(knotVector) frequency = [knotVector.count(knot) for knot in uniqueKnots] knots = TColStd_Array1OfReal(0, len(uniqueKnots) - 1) for i in range(len(uniqueKnots)): knots.SetValue(i, uniqueKnots[i]) mults = TColStd_Array1OfInteger(0, len(frequency) - 1) for i in range(len(frequency)): mults.SetValue(i, frequency[i]) poles = TColgp_Array1OfPnt(0, len(controlPoints) - 1) for i in range(len(controlPoints)): p = controlPoints[i] poles.SetValue(i, gp_Pnt(p[0], p[1], p[2])) poles2d = TColgp_Array1OfPnt2d(0, len(controlPoints) - 1) plane = get_principal_plane(controlPoints) for i in range(len(controlPoints)): p = controlPoints[i] if plane == 0: poles2d.SetValue(i, gp_Pnt2d(p[1], p[2])) elif plane == 1: poles2d.SetValue(i, gp_Pnt2d(p[0], p[2])) elif plane == 2: poles2d.SetValue(i, gp_Pnt2d(p[0], p[1])) curve2d = Geom2d_BSplineCurve(poles2d, knots, mults, degree) if is_self_intersecting(curve2d.GetHandle()): from cadmium import CadmiumException raise CadmiumException('Self intersecting BSpline not allowed') curve = Geom_BSplineCurve(poles, knots, mults, degree) me = BRepBuilderAPI_MakeEdge(curve.GetHandle()) wire.Add(me.Edge()) first = controlPoints[0] first = gp_Pnt(first[0], first[1], first[2]) last = controlPoints[-1] last = gp_Pnt(last[0], last[1], last[2]) if not first.IsEqual(last, 1.0e-9): closer = BRepBuilderAPI_MakeEdge( gp_Lin(first, gp_Dir(gp_Vec(first, last))), first, last) wire.Add(closer.Edge()) face = BRepBuilderAPI_MakeFace(wire.Wire()) if axis == 0: extrusion_vector = gp_Vec(self.thickness, 0, 0) elif axis == 1: extrusion_vector = gp_Vec(0, self.thickness, 0) elif axis == 2: extrusion_vector = gp_Vec(0, 0, self.thickness) self.instance = BRepPrimAPI_MakePrism(face.Shape(), extrusion_vector) Solid.__init__(self, self.instance.Shape(), center=center)
def make_edge(*args): edge = BRepBuilderAPI_MakeEdge(*args) result = edge.Edge() return result
def write(cls, filename, data, tolerance=1e-6): # cycle on the faces to update the control points position # init some quantities shape = data.shape control_point_position = data.control_point_position mesh_points = data.points faces_explorer = TopExp_Explorer(shape, TopAbs_FACE) n_faces = 0 compound_builder = BRep_Builder() compound = TopoDS_Compound() compound_builder.MakeCompound(compound) while faces_explorer.More(): # similar to the parser method face = topods_Face(faces_explorer.Current()) nurbs_converter = BRepBuilderAPI_NurbsConvert(face) nurbs_converter.Perform(face) nurbs_face = nurbs_converter.Shape() face_aux = topods_Face(nurbs_face) brep_face = BRep_Tool.Surface(topods_Face(nurbs_face)) bspline_face = geomconvert_SurfaceToBSplineSurface(brep_face) occ_face = bspline_face.GetObject() n_poles_u = occ_face.NbUPoles() n_poles_v = occ_face.NbVPoles() i = 0 for pole_u_direction in range(n_poles_u): for pole_v_direction in range(n_poles_v): control_point_coordinates = mesh_points[ +control_point_position[n_faces], :] point_xyz = gp_XYZ(*control_point_coordinates) gp_point = gp_Pnt(point_xyz) occ_face.SetPole(pole_u_direction + 1, pole_v_direction + 1, gp_point) i += 1 # construct the deformed wire for the trimmed surfaces wire_maker = BRepBuilderAPI_MakeWire() tol = ShapeFix_ShapeTolerance() brep = BRepBuilderAPI_MakeFace(occ_face.GetHandle(), tolerance).Face() brep_face = BRep_Tool.Surface(brep) # cycle on the edges edge_explorer = TopExp_Explorer(nurbs_face, TopAbs_EDGE) while edge_explorer.More(): edge = topods_Edge(edge_explorer.Current()) # edge in the (u,v) coordinates edge_uv_coordinates = BRep_Tool.CurveOnSurface(edge, face_aux) # evaluating the new edge: same (u,v) coordinates, but # different (x,y,x) ones edge_phis_coordinates_aux = BRepBuilderAPI_MakeEdge( edge_uv_coordinates[0], brep_face) edge_phis_coordinates = edge_phis_coordinates_aux.Edge() tol.SetTolerance(edge_phis_coordinates, tolerance) wire_maker.Add(edge_phis_coordinates) edge_explorer.Next() # grouping the edges in a wire wire = wire_maker.Wire() # trimming the surfaces brep_surf = BRepBuilderAPI_MakeFace(occ_face.GetHandle(), wire).Shape() compound_builder.Add(compound, brep_surf) n_faces += 1 faces_explorer.Next() IGESControl_Controller_Init() writer = IGESControl_Writer() writer.AddShape(compound) writer.Write(filename)
def write(self, mesh_points, filename, tolerance=None): """ Writes a output file, called filename, copying all the structures from self.filename but the coordinates. mesh_points is a matrix that contains the new coordinates to write in the output file. :param numpy.ndarray mesh_points: it is a `n_points`-by-3 matrix containing the coordinates of the points of the mesh :param string filename: name of the output file. :param float tolerance: tolerance for the construction of the faces and wires in the write function. If not given it uses `self.tolerance`. """ self._check_filename_type(filename) self._check_extension(filename) self._check_infile_instantiation() self.outfile = filename if tolerance is not None: self.tolerance = tolerance # cycle on the faces to update the control points position # init some quantities faces_explorer = TopExp_Explorer(self.shape, TopAbs_FACE) n_faces = 0 control_point_position = self._control_point_position compound_builder = BRep_Builder() compound = OCC.TopoDS.TopoDS_Compound() compound_builder.MakeCompound(compound) while faces_explorer.More(): # similar to the parser method face = OCC.TopoDS.topods_Face(faces_explorer.Current()) nurbs_converter = BRepBuilderAPI_NurbsConvert(face) nurbs_converter.Perform(face) nurbs_face = nurbs_converter.Shape() face_aux = OCC.TopoDS.topods_Face(nurbs_face) brep_face = BRep_Tool.Surface(OCC.TopoDS.topods_Face(nurbs_face)) bspline_face = geomconvert_SurfaceToBSplineSurface(brep_face) occ_face = bspline_face.GetObject() n_poles_u = occ_face.NbUPoles() n_poles_v = occ_face.NbVPoles() i = 0 for pole_u_direction in range(n_poles_u): for pole_v_direction in range(n_poles_v): control_point_coordinates = mesh_points[ i + control_point_position[n_faces], :] point_xyz = gp_XYZ(*control_point_coordinates) gp_point = gp_Pnt(point_xyz) occ_face.SetPole(pole_u_direction + 1, pole_v_direction + 1, gp_point) i += 1 # construct the deformed wire for the trimmed surfaces wire_maker = BRepBuilderAPI_MakeWire() tol = ShapeFix_ShapeTolerance() brep = BRepBuilderAPI_MakeFace(occ_face.GetHandle(), self.tolerance).Face() brep_face = BRep_Tool.Surface(brep) # cycle on the edges edge_explorer = TopExp_Explorer(nurbs_face, TopAbs_EDGE) while edge_explorer.More(): edge = OCC.TopoDS.topods_Edge(edge_explorer.Current()) # edge in the (u,v) coordinates edge_uv_coordinates = BRep_Tool.CurveOnSurface(edge, face_aux) # evaluating the new edge: same (u,v) coordinates, but different (x,y,x) ones edge_phis_coordinates_aux = BRepBuilderAPI_MakeEdge(\ edge_uv_coordinates[0], brep_face) edge_phis_coordinates = edge_phis_coordinates_aux.Edge() tol.SetTolerance(edge_phis_coordinates, self.tolerance) wire_maker.Add(edge_phis_coordinates) edge_explorer.Next() # grouping the edges in a wire wire = wire_maker.Wire() # trimming the surfaces brep_surf = BRepBuilderAPI_MakeFace(occ_face.GetHandle(), wire).Shape() compound_builder.Add(compound, brep_surf) n_faces += 1 faces_explorer.Next() self.write_shape_to_file(compound, self.outfile)
aPnt1 = gp_Pnt(-myWidth / 2, 0, 0) aPnt2 = gp_Pnt(-myWidth / 2, -myThickness / 4, 0) aPnt3 = gp_Pnt(0, -myThickness / 2, 0) aPnt4 = gp_Pnt(myWidth / 2, -myThickness / 4, 0) aPnt5 = gp_Pnt(myWidth / 2, 0, 0) # Profile : Define the Geometry aArcOfCircle = GC_MakeArcOfCircle(aPnt2, aPnt3, aPnt4) aSegment1 = GC_MakeSegment(aPnt1, aPnt2) aSegment2 = GC_MakeSegment(aPnt4, aPnt5) # Profile : Define the Topology aEdge1 = MakeEdge(aSegment1.Value()) aEdge2 = MakeEdge(aArcOfCircle.Value()) aEdge3 = MakeEdge(aSegment2.Value()) aWire = MakeWire(aEdge1.Edge(), aEdge2.Edge(), aEdge3.Edge()) # Complete Profile xAxis = OCC.gp.gp_OX() aTrsf = OCC.gp.gp_Trsf() aTrsf.SetMirror(xAxis) 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()
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()