1 | # -*- coding: utf-8 -*- |
---|
2 | from OCC.gp import * |
---|
3 | from OCC.BRepPrimAPI import * |
---|
4 | from OCC.TopExp import * |
---|
5 | from OCC.TopAbs import * |
---|
6 | from OCC.BRep import * |
---|
7 | from OCC.Geom import * |
---|
8 | from OCC.GCE2d import * |
---|
9 | from OCC.GC import * |
---|
10 | from OCC.Geom2d import * |
---|
11 | from OCC.BRepLib import * |
---|
12 | from OCC.BRepFeat import * |
---|
13 | from OCC.Utils.Topology import Topo |
---|
14 | from OCC.BRepBuilderAPI import * |
---|
15 | from OCC.BRepAlgoAPI import * |
---|
16 | from OCC.BRepFilletAPI import * |
---|
17 | from OCC.TopoDS import * |
---|
18 | from OCC.StlAPI import * |
---|
19 | from math import radians |
---|
20 | |
---|
21 | from OCC.Display.SimpleGui import * |
---|
22 | from OCC.Graphic3d import * |
---|
23 | from OCC.BRepFeat import * |
---|
24 | |
---|
25 | R = 31 |
---|
26 | L = 120 |
---|
27 | p = gp_Pnt(0.,0.,0) |
---|
28 | d = gp_Dir(1. ,0., 0.) |
---|
29 | myAxes1 = gp_Ax2(p,d) |
---|
30 | myPrim1 = BRepPrimAPI_MakeCylinder(myAxes1, R, 100) |
---|
31 | |
---|
32 | mkFillet = BRepFilletAPI_MakeChamfer(myPrim1.Shape()) |
---|
33 | ex = TopExp_Explorer(myPrim1.Shape(), TopAbs_EDGE) |
---|
34 | ex2 = TopExp_Explorer(myPrim1.Shape(), TopAbs_FACE) |
---|
35 | edge = TopoDS_edge(ex.Current()) |
---|
36 | face = TopoDS_face(ex2.Current()) |
---|
37 | mkFillet.Add(15.0, 3.0, edge, face) |
---|
38 | |
---|
39 | myAxes2 = gp_Ax2(p, gp_Dir(0,-1,0)) |
---|
40 | myPrim2 = BRepPrimAPI_MakeCylinder(myAxes1, R-5, L) |
---|
41 | myShp1 = BRepAlgoAPI_Cut(mkFillet.Shape(),myPrim2.Shape()) |
---|
42 | |
---|
43 | mySphere = BRepPrimAPI_MakeSphere(p, R) |
---|
44 | |
---|
45 | rotateAxis = gp_Ax1(p, gp_Dir(0.0,0.0,1.0)) #Os rotacije |
---|
46 | transfRot1 = gp_Trsf() |
---|
47 | transfRot1.SetRotation(rotateAxis, radians(90.0)) |
---|
48 | myShp2 = BRepBuilderAPI_Transform(myShp1.Shape(), transfRot1) |
---|
49 | myShp3 = BRepAlgoAPI_Fuse(myShp1.Shape(),myShp2.Shape()) |
---|
50 | myShp4 = BRepAlgoAPI_Fuse(myShp3.Shape(), mySphere.Shape()) |
---|
51 | |
---|
52 | |
---|
53 | # Izdelamo navadno rebro |
---|
54 | rib_thickness = 6.0 # polovica debeline rebra |
---|
55 | rib1 = gp_Pnt(2*R,R,0) |
---|
56 | rib2 = gp_Pnt(R,2*R,0) |
---|
57 | aPlane = Geom_Plane(0,0,1.0,0.0) |
---|
58 | edge1 = BRepBuilderAPI_MakeEdge(rib1, rib2).Edge() |
---|
59 | aWire = BRepBuilderAPI_MakeWire(edge1) |
---|
60 | rib = BRepFeat_MakeLinearForm( myShp4.Shape(), aWire.Wire(), aPlane.GetHandle(), \ |
---|
61 | gp_Vec(0.,0.,rib_thickness), gp_Vec(0.,0.,-rib_thickness), 1, True ) |
---|
62 | rib.Perform() |
---|
63 | |
---|
64 | # Poiščemo vse štiri robove na obeh debelinah rebra, ki imajo začetno in končno Z isto |
---|
65 | # in so vzporedni z osjo X ali Y ter jim dodamo spremenljivo debelino zaokrožitve |
---|
66 | TOL=1E-6 |
---|
67 | with_fillet = BRepFilletAPI_MakeFillet(rib.Shape()) |
---|
68 | topology_traverser = Topo(rib.Shape()) |
---|
69 | for aEdge in topology_traverser.edges(): |
---|
70 | first, last = TopExp().FirstVertex(aEdge), TopExp().LastVertex(aEdge) |
---|
71 | first_vert, last_vert = BRep_Tool().Pnt(first), BRep_Tool().Pnt(last) |
---|
72 | if abs(abs(first_vert.Z())-rib_thickness) < TOL and \ |
---|
73 | abs(first_vert.Z() - last_vert.Z()) < TOL and \ |
---|
74 | (abs(first_vert.X()-last_vert.X())<TOL or abs(first_vert.Y()-last_vert.Y())<TOL): |
---|
75 | with_fillet.Add(25, 0.0, aEdge) |
---|
76 | |
---|
77 | myPart = with_fillet |
---|
78 | |
---|
79 | stl_writer = StlAPI() |
---|
80 | stl_writer.Write(myPart.Shape(), "elbow.stl", False) |
---|
81 | |
---|
82 | display, start_display, add_menu, add_function_to_menu = init_display() |
---|
83 | material = Graphic3d_MaterialAspect(Graphic3d_NOM_SILVER) |
---|
84 | display.DisplayShape(myPart.Shape(), material) |
---|
85 | start_display() |
---|