Salome HOME
[PythonAPI] Add new model example: Platine.
[modules/shaper.git] / src / PythonAPI / examples / Platine.py
1 # Creation of Platine model using the end-user API
2 # Author: Sergey POKHODENKO
3 # -----------------------------
4
5 import geom
6 import model
7
8 # Initialisation
9 model.begin()
10 partset = model.moduleDocument()
11
12 # Create a new Part
13 part = model.addPart(partset).document()
14
15 L = 64
16 E = 16
17 P = 80
18
19 # Create Parameters
20 model.addParameter(part, "L", L)
21 model.addParameter(part, "E", E)
22 model.addParameter(part, "P", P)
23
24 def vertical_body():
25     # Create YOZ sketch
26     sketch = model.addSketch(part, model.defaultPlane("YOZ"))
27
28     points = [(0, 0), (0, L), (L, L), (L, 0)]
29     geom_points = [geom.Pnt2d(*p) for p in points]
30     left, top, right, bottom = sketch.addPolygon(*geom_points)
31
32     # Set constraints
33     sketch.setRigid(left.startPointData())
34
35     sketch.setHorizontal(bottom.result())
36     sketch.setHorizontal(top.result())
37
38     sketch.setVertical(right.result())
39     sketch.setVertical(left.result())
40
41     sketch.setLength(top.result(), "L")
42     sketch.setLength(left.result(), "L")
43
44     sketch.setFillet(left.endPointData(), 32)
45
46     model.do()  #!!!
47
48     # Create extrusion
49     body = model.addExtrusion(part, sketch.selectFace(), "E")
50
51     model.do()
52
53     return body
54
55 def bottom_body():
56     # Create XOY sketch
57     sketch = model.addSketch(part, "Extrusion_1_1/LateralFace_2")
58
59     # Create base polygon
60     points = [(0, 0), (0, L), (P, L), (P, 16 + 16), (P - 20, 16 + 16), (P - 20, 16), (P, 16), (P, 0)]
61     points = [(p[0], -p[1]) for p in points]  # as we look to back of the face
62     geom_points = [geom.Pnt2d(*p) for p in points]
63     left, top, v2, h2, v1, h1, right, bottom = sketch.addPolygon(*geom_points)
64
65     points = [(P - 20, 16 + 16 / 2), (P - 20, 16), (P - 20, 16 + 16)]
66     points = [(p[0], -p[1]) for p in points]  # as we look to back of the face
67     center, start, end = [geom.Pnt2d(*p) for p in points]
68     arc = sketch.addArc(center, start, end, inversed=True)
69
70     # Set Auxiliarity
71     v1.setAuxiliary(True)
72
73     # Set constraints
74     sketch.setParallel(left.result(), right.result())
75     sketch.setParallel(left.result(), v2.result())
76     sketch.setParallel(bottom.result(), h1.result())
77     sketch.setParallel(top.result(), h2.result())
78
79     sketch.setPerpendicular(left.result(), bottom.result())
80     sketch.setPerpendicular(left.result(), top.result())
81
82     sketch.setEqual(top.result(), bottom.result())
83     sketch.setEqual(h1.result(), h2.result())
84
85     sketch.setLength(top.result(), "P")
86     sketch.setLength(right.result(), 16)
87     sketch.setLength(v1.result(), 16)
88     sketch.setLength(h2.result(), 20)
89
90     sketch.setCoincident(arc.center(), v1.result())
91     sketch.setCoincident(arc.startPoint(), h2.endPointData())
92     sketch.setCoincident(arc.endPoint(), h1.startPointData())
93
94     # Binding
95     left_e = sketch.addLine("Extrusion_1_1/LateralFace_2|Extrusion_1_1/ToFace_1")
96     sketch.setCoincident(left_e.startPointData(), left.endPointData())
97     sketch.setCoincident(left_e.endPointData(), left.startPointData())
98
99     model.do()  #!!!
100
101     # Create extrusion
102     body = model.addExtrusion(part, sketch.selectFace(), "-E")
103
104     model.do()
105
106     return body
107
108 def body_3():
109     # Create XOZ sketch
110     sketch = model.addSketch(part, "Boolean_1_1/Modified_3")
111
112     # Create base polygon
113     H, L, l, r = 28, 40, 8, 12
114
115     points = [(0, 0), (0, H), (l, H), (l + 2 * r, H), (L, H), (L, 0)]
116     points = [(p[0], -p[1]) for p in points]  # as we look to back of the face
117     geom_points = [geom.Pnt2d(*p) for p in points]
118     left, top_left, top_middle, top_right, right, bottom, = sketch.addPolygon(*geom_points)
119
120     points = [(l + r, H), (l, H), (l + 2 * r, H)]
121     points = [(p[0], -p[1]) for p in points]  # as we look to back of the face
122     center, start, end = [geom.Pnt2d(*p) for p in points]
123     arc = sketch.addArc(center, start, end)
124
125     # Set Auxiliarity
126     top_middle.setAuxiliary(True)
127
128     # Set constraints
129     sketch.setParallel(bottom.result(), top_left.result())
130     sketch.setParallel(bottom.result(), top_right.result())
131
132     sketch.setPerpendicular(bottom.result(), left.result())
133     sketch.setPerpendicular(bottom.result(), right.result())
134
135     sketch.setEqual(left.result(), right.result())
136
137     sketch.setLength(bottom.result(), L)
138     sketch.setLength(right.result(), H)
139     sketch.setLength(top_left.result(), l)
140
141     sketch.setCoincident(top_middle.result(), arc.center())
142     sketch.setCoincident(top_middle.endPointData(), arc.startPoint())
143     sketch.setCoincident(top_middle.startPointData(), arc.endPoint())
144
145     sketch.setRadius(arc.result(), r)
146
147     # Binding
148     bottom_e = sketch.addLine("Boolean_1_1/Modified_1|Boolean_1_1/Modified_3")
149     sketch.setCoincident(bottom_e.result(), bottom.startPointData())
150     sketch.setCoincident(bottom_e.startPointData(), bottom.endPointData())
151
152     model.do()  #!!!
153
154     # Create extrusion
155     body = model.addExtrusion(part, sketch.selectFace(), "-(L-22)")
156
157     model.do()  #!!!
158
159     return body
160
161 def body_4():
162     # Create XOZ 2nd sketch
163     sketch = model.addSketch(part, "Boolean_2_1/Modified_7")
164
165     # Create base polygon
166     points = [(0, 0), (0, 1), (1, 0)]
167     points = [(p[0], -p[1]) for p in points]  # as we look to back of the face
168     geom_points = [geom.Pnt2d(*p) for p in points]
169     left, diagonal, bottom = sketch.addPolygon(*geom_points)
170
171     # Binding
172     bottom_e = sketch.addLine("Boolean_2_1/Modified_8|Boolean_2_1/Modified_7")
173     sketch.setCoincident(bottom_e.endPointData(), bottom.startPointData())
174     sketch.setCoincident(bottom_e.startPointData(), left.startPointData())
175
176     left_e = sketch.addLine("Boolean_2_1/Modified_3|Boolean_2_1/Modified_2")
177     sketch.setCoincident(left_e.startPointData(), left.endPointData())
178
179     model.do()  #!!!
180
181     # Create extrusion
182     body = model.addExtrusion(part, sketch.selectFace(), "-12")
183
184     model.do()  #!!!
185
186     return body
187
188
189 b1 = vertical_body()
190 b2 = bottom_body()
191
192 boolean = model.addAddition(part, b1.result() + b2.result(), [])
193 model.do()
194
195 b3 = body_3()
196
197 boolean = model.addAddition(part, boolean.result() + b3.result(), [])
198 model.do()
199
200 b4 = body_4()
201
202 boolean = model.addAddition(part, boolean.result() + b4.result(), [])
203 model.do()