def gen_through(self): obj = BRepOffsetAPI_ThruSections() ax2_1 = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)) crl_1 = gp_Circ(ax2_1, 100) obj.AddWire(crl_1) ax2_2 = gp_Ax2(gp_Pnt(0, 0, 100), gp_Dir(0, 0, 1)) crl_2 = gp_Circ(ax2_2, 200) obj.AddWire(crl_2) obj.Build() self.display.DisplayShape(obj.Shape())
def thicken_spline(event=None): # Creation of points for the spine array = TColgp_Array1OfPnt(1, 5) array.SetValue(1, gp_Pnt(1, 4, 0)) array.SetValue(2, gp_Pnt(2, 2, 0)) array.SetValue(3, gp_Pnt(3, 3, 0)) array.SetValue(4, gp_Pnt(4, 3, 0)) array.SetValue(5, gp_Pnt(5, 5, 0)) # Creation of a Bezier Curve as the spine bz_curv = Geom_BezierCurve(array) bz_curv_edge = BRepBuilderAPI_MakeEdge(bz_curv).Edge() bz_curv_wire = BRepBuilderAPI_MakeWire(bz_curv_edge).Wire() display.DisplayShape(bz_curv_wire) # Creation of profile to sweep along the spine circle = gp_Circ(gp_ZOX(), 1) circle.SetLocation(array[0]) circle_edge = BRepBuilderAPI_MakeEdge(circle).Edge() circle_wire = BRepBuilderAPI_MakeWire(circle_edge).Wire() # Creation of the law to dictate the evolution of the profile brep1 = BRepOffsetAPI_MakePipeShell(bz_curv_wire) law_f = Law_Linear() law_f.Set(0, 0.5, 1, 1) brep1.SetLaw(circle_wire, law_f, False, True) return brep1.Shape()
def createEdges(self): edges = [] # Join points a,b edge = make_edge(getGpPt(self.a), getGpPt(self.b)) edges.append(edge) # # Join points b1 and b2 # cirl = gp_Circ(gp_Ax2(getGpPt(self.o1), getGpDir(self.wDir)), self.R1) # edge = make_edge(cirl,getGpPt(self.b2), getGpPt(self.b1)) # edges.append(edge) # Join points b and c2 edge = make_edge(getGpPt(self.b), getGpPt(self.c2)) edges.append(edge) # join points c2 and c1 cirl2 = gp_Circ(gp_Ax2(getGpPt(self.o2), getGpDir(self.wDir)), self.R1) edge = make_edge(cirl2, getGpPt(self.c1), getGpPt(self.c2)) edges.append(edge) # Join points c1 and d edge = make_edge(getGpPt(self.c1), getGpPt(self.d)) edges.append(edge) # Join points d and a edge = make_edge(getGpPt(self.d), getGpPt(self.a)) edges.append(edge) return edges
def __init__(self, axs=gp_Ax3()): self.rot = axs self.axs = gp_Ax3(self.rot.Ax2()) self.rim = make_edge(gp_Circ(self.axs.Ax2(), 100)) self.pln = dispocc.make_plane_axs(self.axs) self.surf = make_plane(self.axs.Location(), dir_to_vec(self.axs.Direction()), -500, 500, -500, 500)
def make_circle(p, vec, r): from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge from OCC.Core.gp import gp_Ax2, gp_Circ, gp_Dir, gp_Pnt circle_origin = gp_Ax2(gp_Pnt(p[0], p[1], p[2]), gp_Dir(vec[0], vec[1], vec[2])) circle = gp_Circ(circle_origin, r) return BRepBuilderAPI_MakeEdge(circle).Edge()
def make_circle(pnt, radius): ''' returns an edge @param pnt: @param radius: ''' circ = gp_Circ() circ.SetLocation(pnt) circ.SetRadius(radius) return make_edge(circ)
def holes_in_face(): aPlane = gp_Pln() print(type(gp_Pln())) print(type(gp_XOY())) aCircle1 = gp_Circ(gp_XOY(), 1.0) aCircle2 = gp_Circ(gp_XOY(), 1.0) aCircle3 = gp_Circ(gp_XOY(), 1.0) aCircle1.SetLocation(gp_Pnt(3.0, 3.0, 0.0)) aCircle2.SetLocation(gp_Pnt(7.0, 3.0, 0.0)) aCircle3.SetLocation(gp_Pnt(3.0, 7.0, 0.0)) anEdgeMaker1 = BRepBuilderAPI_MakeEdge(aCircle1) anEdgeMaker2 = BRepBuilderAPI_MakeEdge(aCircle2) anEdgeMaker3 = BRepBuilderAPI_MakeEdge(aCircle3) aWireMaker1 = BRepBuilderAPI_MakeWire(anEdgeMaker1.Edge()) aWireMaker2 = BRepBuilderAPI_MakeWire(anEdgeMaker2.Edge()) aWireMaker3 = BRepBuilderAPI_MakeWire(anEdgeMaker3.Edge()) aFaceMaker = BRepBuilderAPI_MakeFace(aPlane, 0.0, 10.0, 0.0, 10.0) if aWireMaker1.IsDone(): aWire1 = aWireMaker1.Wire() aWire1.Reverse() # Makes this a hole in outer profile aFaceMaker.Add(aWire1) if aWireMaker2.IsDone(): aWire2 = aWireMaker2.Wire() aWire2.Reverse() # Makes this a hole in outer profile aFaceMaker.Add(aWire2) if aWireMaker3.IsDone(): aWire3 = aWireMaker3.Wire() aWire3.Reverse() # Makes this a hole in outer profile aFaceMaker.Add(aWire3) if not aFaceMaker.IsDone(): raise AssertionError("shape not Done.") return aFaceMaker.Shape()
def compute_minimal_distance_between_circles(): """ compute the minimal distance between 2 circles here the minimal distance overlaps the intersection of the circles the points are rendered to indicate the locations """ # required for precise rendering of the circles display.Context.SetDeviationCoefficient(0.0001) L = gp_Pnt(4, 10, 0) M = gp_Pnt(10, 16, 0) Laxis = gp_Ax2() Maxis = gp_Ax2() Laxis.SetLocation(L) Maxis.SetLocation(M) r1 = 12.0 r2 = 15.0 Lcircle = gp_Circ(Laxis, r1) Mcircle = gp_Circ(Maxis, r2) l_circle, m_circle = make_edge(Lcircle), make_edge(Mcircle) display.DisplayShape([l_circle, m_circle]) # compute the minimal distance between 2 circles # the minimal distance here matches the intersection of the circles dss = BRepExtrema_DistShapeShape(l_circle, m_circle) print("intersection parameters on l_circle:", [dss.ParOnEdgeS1(i) for i in range(1, dss.NbSolution() + 1)]) print("intersection parameters on m_circle:", [dss.ParOnEdgeS2(i) for i in range(1, dss.NbSolution() + 1)]) for i in range(1, dss.NbSolution() + 1): pnt = dss.PointOnShape1(i) display.DisplayShape(make_vertex(pnt))
def makeCircle(self, p1, p2): axe = gp_Ax2(p1, self.new_sketch.dir) radius = p1.Distance(p2) circle = gp_Circ(axe, radius) edge = BRepBuilderAPI_MakeEdge(circle) if self._tmp_geometry is None: shape = AIS_Shape(TopoDS_Edge()) shape.Set(edge.Edge()) self._tmp_geometry = shape self._display.Context.Display(self._tmp_geometry, True) else: self._tmp_geometry.Set(edge.Edge()) self._tmp_geometry.Redisplay(False)
def through_sections(): #ruled circle_1 = gp_Circ(gp_Ax2(gp_Pnt(-100., 0., -100.), gp_Dir(0., 0., 1.)), 40.) wire_1 = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_1).Edge()).Wire() circle_2 = gp_Circ(gp_Ax2(gp_Pnt(-10., 0., -0.), gp_Dir(0., 0., 1.)), 40.) wire_2 = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_2).Edge()).Wire() circle_3 = gp_Circ(gp_Ax2(gp_Pnt(-75., 0., 100.), gp_Dir(0., 0., 1.)), 40.) wire_3 = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_3).Edge()).Wire() circle_4 = gp_Circ(gp_Ax2(gp_Pnt(0., 0., 200.), gp_Dir(0., 0., 1.)), 40.) wire_4 = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_4).Edge()).Wire() generatorA = BRepOffsetAPI_ThruSections(False, True) # the use of the map function fails at producing the ThruSection # on py3k. Why ? # map(generatorA.AddWire, [wire_1, wire_2, wire_3, wire_4]) # we have to use a loop for wir in [wire_1, wire_2, wire_3, wire_4]: generatorA.AddWire(wir) generatorA.Build() display.DisplayShape(generatorA.Shape()) #smooth circle_1b = gp_Circ(gp_Ax2(gp_Pnt(100., 0., -100.), gp_Dir(0., 0., 1.)), 40.) wire_1b = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_1b).Edge()).Wire() circle_2b = gp_Circ(gp_Ax2(gp_Pnt(210., 0., -0.), gp_Dir(0., 0., 1.)), 40.) wire_2b = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_2b).Edge()).Wire() circle_3b = gp_Circ(gp_Ax2(gp_Pnt(275., 0., 100.), gp_Dir(0., 0., 1.)), 40.) wire_3b = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_3b).Edge()).Wire() circle_4b = gp_Circ(gp_Ax2(gp_Pnt(200., 0., 200.), gp_Dir(0., 0., 1.)), 40.) wire_4b = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_4b).Edge()).Wire() generatorB = BRepOffsetAPI_ThruSections(True, False) # same here, the following line fails # map(generatorB.AddWire, [wire_1b, wire_2b, wire_3b, wire_4b]) for wir in [wire_1b, wire_2b, wire_3b, wire_4b]: generatorB.AddWire(wir) generatorB.Build() display.DisplayShape(generatorB.Shape(), update=True)
def make_pipe(wire, p1, p2): # the pipe if p2 is not None: direction_coords = np.array(p2.XYZ().Coord()) - np.array( p1.XYZ().Coord()) direction_coords /= np.linalg.norm(direction_coords) direction = gp_Dir(*list(direction_coords)) else: direction = gp_Dir(1, 0, 0) # print(p1.XYZ().Coord(), p2.XYZ().Coord()) circle = gp_Circ(gp_Ax2(p1, direction), RADIUS) profile_edge = BRepBuilderAPI_MakeEdge(circle).Edge() profile_wire = BRepBuilderAPI_MakeWire(profile_edge).Wire() profile_face = BRepBuilderAPI_MakeFace(profile_wire).Face() pipe = BRepOffsetAPI_MakePipe(wire, profile_face).Shape() return pipe
def __init__(self): plotocc.__init__(self) self.axs = gp_Ax3() self.circle = Geom_Circle(gp_Circ(self.axs.Ax2(), 100)) p0, v1, v2 = gp_Pnt(), gp_Vec(), gp_Vec() GeomLProp_CurveTool.D2(self.circle, 0, p0, v1, v2) self.poly_axs = gp_Ax3(p0, vec_to_dir(v1)) for num in range(4, 9): self.poly = self.make_PolyWire( num=num, radi=20.0, axs=self.poly_axs) self.base = self.make_Thru(50) self.display.DisplayShape( self.base, transparency=0.7, color="BLUE") write_step_file(self.base, self.tmpdir + "ThruSurf_{:d}.stp".format(num))
def face_rotate(self, face=TopoDS_Face(), axs=gp_Ax1()): plan = self.pln_on_face(face) plan_axs = plan.Position() self.display.DisplayShape(plan_axs.Location()) v0 = dir_to_vec(self.tmp_axis.Direction()) v1 = dir_to_vec(plan_axs.Direction()) print(v0.Dot(v1)) lin_vec = gp_Vec(axs.Location(), plan_axs.Location()) edg_circl = Geom_Circle( gp_Circ( gp_Ax2(axs.Location(), axs.Direction(), vec_to_dir(lin_vec)), 5)) rim_u0, rim_u1 = edg_circl.FirstParameter(), edg_circl.LastParameter() rim_p0 = edg_circl.Value(rim_u0) pln_angle = self.tmp_axis.Angle(plan_axs) ref_angle = self.tmp_axis.Direction().AngleWithRef( plan_axs.Direction(), axs.Direction()) print(np.rad2deg(pln_angle), np.rad2deg(ref_angle)) rim_u2 = -ref_angle rim_p2 = edg_circl.Value(rim_u2) rim_angle = Geom_TrimmedCurve(edg_circl, rim_u0, rim_u2) trf = gp_Trsf() #trf.SetRotation(axs, 2*np.pi - ref_angle) if np.abs(ref_angle) >= np.pi / 2: trf.SetRotation(axs, -ref_angle) elif 0 < ref_angle < np.pi / 2: trf.SetRotation(axs, np.pi - ref_angle) elif -np.pi / 2 < ref_angle < 0: trf.SetRotation(axs, -ref_angle - np.pi) else: trf.SetRotation(axs, -ref_angle) #trf.SetTransformation(axs3.Rotated(axs, angle), axs3) loc_face = TopLoc_Location(trf) new_face = face.Moved(loc_face) self.display.DisplayShape(new_face, transparency=0.5) self.display.DisplayShape(rim_angle) self.display.DisplayShape(rim_p0) self.display.DisplayShape(rim_p2) return new_face
def create_model(self): boltCylinderex = BRepPrimAPI_MakeCylinder( gp_Ax2(getGpPt(self.p1), getGpDir(-self.shaftDir)), self.r, self.cylex_length).Shape() boltCylinder1 = BRepPrimAPI_MakeCylinder( gp_Ax2(getGpPt(self.p1), getGpDir(self.shaftDir)), self.r, self.cyl1_length).Shape() boltCylinder2 = BRepPrimAPI_MakeCylinder( gp_Ax2(getGpPt(self.p2), getGpDir(self.cyl2_angle)), self.r, self.cyl2_ht).Shape() boltCylinder3 = BRepPrimAPI_MakeCylinder( gp_Ax2(getGpPt(self.p3), getGpDir(self.shaftDir)), self.r, self.cyl3_length).Shape() boltCylinder4 = BRepPrimAPI_MakeCylinder( gp_Ax2(getGpPt(self.p6), getGpDir(-self.shaftDir)), self.r, self.cyl5_length).Shape() sphere1 = BRepPrimAPI_MakeSphere(getGpPt(self.p2), self.r).Shape() sphere2 = BRepPrimAPI_MakeSphere(getGpPt(self.p3), self.r).Shape() edg_points = gp_Circ(gp_Ax2(getGpPt(self.p4), getGpDir(self.shaftDir)), self.r) hexwire = BRepBuilderAPI_MakeWire() hexedge = BRepBuilderAPI_MakeEdge(edg_points).Edge() hexwire.Add(hexedge) hexwire_wire = hexwire.Wire() hexface = BRepBuilderAPI_MakeFace(hexwire_wire).Face() revolve_axis = gp_Ax1(getGpPt(self.p5), gp_Dir(0, -1, 0)) revolved_shape = BRepPrimAPI_MakeRevol(hexface, revolve_axis, math.radians(180.)).Shape() Anchor_BOlt = BRepAlgoAPI_Fuse(boltCylinder1, boltCylinder2).Shape() Anchor_BOlt = BRepAlgoAPI_Fuse(boltCylinder3, Anchor_BOlt).Shape() Anchor_BOlt = BRepAlgoAPI_Fuse(revolved_shape, Anchor_BOlt).Shape() Anchor_BOlt = BRepAlgoAPI_Fuse(boltCylinder4, Anchor_BOlt).Shape() Anchor_BOlt = BRepAlgoAPI_Fuse(sphere1, Anchor_BOlt).Shape() Anchor_BOlt = BRepAlgoAPI_Fuse(sphere2, Anchor_BOlt).Shape() Anchor_BOlt = BRepAlgoAPI_Fuse(boltCylinderex, Anchor_BOlt).Shape() return Anchor_BOlt
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()) assert 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, BSplineSurf.Surface(), 0, P12d.Distance(P22d)).Edge() Edge2 = BRepBuilderAPI_MakeEdge(line2, BSplineSurf.Surface(), 0, P22d.Distance(P32d)).Edge() Edge3 = BRepBuilderAPI_MakeEdge(line3, 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 make_circular_sec_wire(point: gp_Pnt, direction: gp_Dir, radius) -> TopoDS_Wire: circle = gp_Circ(gp_Ax2(point, direction), radius) profile_edge = BRepBuilderAPI_MakeEdge(circle).Edge() return BRepBuilderAPI_MakeWire(profile_edge).Wire()
## ##pythonOCC is free software: you can redistribute it and/or modify ##it under the terms of the GNU Lesser General Public License as published by ##the Free Software Foundation, either version 3 of the License, or ##(at your option) any later version. ## ##pythonOCC is distributed in the hope that it will be useful, ##but WITHOUT ANY WARRANTY; without even the implied warranty of ##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##GNU Lesser General Public License for more details. ## ##You should have received a copy of the GNU Lesser General Public License ##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>. from OCC.Core.gp import gp_Dir, gp_Ax2, gp_Circ, gp_Pnt from OCC.Core.AIS import AIS_Shape, AIS_RadiusDimension from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge from OCC.Display.SimpleGui import init_display display, start_display, add_menu, add_function_to_menu = init_display() c = gp_Circ(gp_Ax2(gp_Pnt(200., 200., 0.), gp_Dir(0., 0., 1.)), 80) ec = BRepBuilderAPI_MakeEdge(c).Edge() ais_shp = AIS_Shape(ec) display.Context.Display(ais_shp) rd = AIS_RadiusDimension(ec) #rd.SetArrowSize(12) display.Context.Display(rd) display.FitAll() start_display()