1 ## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 ## This library is free software; you can redistribute it and/or
4 ## modify it under the terms of the GNU Lesser General Public
5 ## License as published by the Free Software Foundation; either
6 ## version 2.1 of the License, or (at your option) any later version.
8 ## This library is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ## Lesser General Public License for more details.
13 ## You should have received a copy of the GNU Lesser General Public
14 ## License along with this library; if not, write to the Free Software
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 # Creation of Platine model using the end-user API
22 # Author: Sergey POKHODENKO
23 # -----------------------------
25 from salome.shaper import geom
26 from salome.shaper import model
28 # START DEBUG PURPOSES
36 partset = model.moduleDocument()
39 part = model.addPart(partset).document()
46 model.addParameter(part, "L", str(L))
47 model.addParameter(part, "E", str(E))
48 model.addParameter(part, "P", str(P))
52 sketch = model.addSketch(part, model.defaultPlane("YOZ"))
54 points = [(0, 0), (0, L), (L, L), (L, 0)]
55 geom_points = [geom.Pnt2d(*p) for p in points]
56 left, top, right, bottom = model.addPolygon(sketch, *geom_points)
59 sketch.setFixed(left.startPoint())
61 sketch.setHorizontal(bottom)
62 sketch.setHorizontal(top)
64 sketch.setVertical(right)
65 sketch.setVertical(left)
67 sketch.setLength(top, "L")
68 sketch.setLength(left, "L")
70 sketch.setFilletWithRadius(left.endPoint(), 32)
75 body = model.addExtrusion(part, sketch.selectFace(), "E")
81 sketch = model.addSketch(part, "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4")
84 points = [(0, 0), (0, L), (P, L), (P, 16 + 16), (P - 20, 16 + 16), (P - 20, 16), (P, 16), (P, 0)]
85 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
86 geom_points = [geom.Pnt2d(*p) for p in points]
87 left, top, v2, h2, v1, h1, right, bottom = model.addPolygon(sketch, *geom_points)
89 points = [(P - 20, 16 + 16 / 2), (P - 20, 16 + 16), (P - 20, 16)]
90 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
91 center, start, end = [geom.Pnt2d(*p) for p in points]
92 arc = sketch.addArc(center, start, end, True)
98 sketch.setParallel(left, right)
99 sketch.setParallel(left, v2)
100 sketch.setParallel(bottom, h1)
101 sketch.setParallel(top, h2)
103 sketch.setPerpendicular(left, bottom)
104 sketch.setPerpendicular(left, top)
106 sketch.setEqual(top, bottom)
107 sketch.setEqual(h1, h2)
109 sketch.setCoincident(arc.center(), v1)
110 sketch.setCoincident(arc.startPoint(), h2.endPoint())
111 sketch.setCoincident(arc.endPoint(), h1.startPoint())
114 left_e = sketch.addLine("[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/To_Face]")
115 sketch.setCoincident(left_e.startPoint(), left.endPoint())
116 sketch.setCoincident(left_e.endPoint(), left.startPoint())
119 #sketch.setLength(v1, 16)
120 sketch.setLength(v2, 32)
121 sketch.setLength(h2, 20)
122 sketch.setLength(right, 16)
123 sketch.setLength(top, "P")
127 body = model.addExtrusion(part, sketch.selectFace(), "-E")
135 sketch = model.addSketch(part, "Boolean_1_1/Modified_Face&Sketch_1/SketchLine_3")
137 # Create base polygon
138 H, L, l, r = 28, 40, 8, 12
140 points = [(0, 0), (0, H), (l, H), (l + 2 * r, H), (L, H), (L, 0)]
141 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
142 geom_points = [geom.Pnt2d(*p) for p in points]
143 left, top_left, top_middle, top_right, right, bottom, = model.addPolygon(sketch, *geom_points)
145 points = [(l + r, H), (l + 2 * r, H), (l, H)]
146 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
147 center, start, end = [geom.Pnt2d(*p) for p in points]
148 arc = sketch.addArc(center, start, end, False)
151 top_middle.setAuxiliary(True)
154 sketch.setParallel(bottom, top_left)
155 sketch.setParallel(bottom, top_right)
157 sketch.setPerpendicular(bottom, left)
158 sketch.setPerpendicular(bottom, right)
160 sketch.setEqual(left, right)
162 sketch.setLength(bottom, L)
163 sketch.setLength(right, H)
164 sketch.setLength(top_left, l)
166 sketch.setCoincident(top_middle, arc.center())
167 sketch.setCoincident(top_middle.endPoint(), arc.startPoint())
168 sketch.setCoincident(top_middle.startPoint(), arc.endPoint())
170 sketch.setRadius(arc, r)
173 bottom_e = sketch.addLine("[Boolean_1_1/Modified_Face&Sketch_2/SketchLine_6][Extrusion_2_1/To_Face]")
174 sketch.setCoincident(bottom_e, bottom.startPoint())
175 sketch.setCoincident(bottom_e.startPoint(), bottom.endPoint())
180 body = model.addExtrusion(part, sketch.selectFace(), "-(L-22)")
185 # Create XOZ 2nd sketch
186 sketch = model.addSketch(part, "Boolean_2_1/Modified_Face&Sketch_2/SketchLine_6")
188 # Create base polygon
189 points = [(0, 0), (0, 1), (1, 0)]
190 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
191 geom_points = [geom.Pnt2d(*p) for p in points]
192 left, diagonal, bottom = model.addPolygon(sketch, *geom_points)
195 bottom_e = sketch.addLine("[Boolean_2_1/Modified_Face&Extrusion_2_1/To_Face][Boolean_2_1/Modified_Face&Sketch_2/SketchLine_6]")
196 sketch.setCoincident(bottom_e.endPoint(), bottom.startPoint())
197 sketch.setCoincident(bottom_e.startPoint(), left.startPoint())
199 left_e = sketch.addLine("[Boolean_2_1/Modified_Face&Extrusion_3_1/From_Face][Extrusion_3_1/Generated_Face&Sketch_3/SketchLine_18]")
200 sketch.setCoincident(left_e.startPoint(), left.endPoint())
205 body = model.addExtrusion(part, sketch.selectFace(), "-12")
213 boolean = model.addFuse(part, b1.results() + b2.results())
214 boolean.result().setName("Boolean_1_1")
219 boolean = model.addFuse(part, boolean.results() + b3.results())
220 boolean.result().setName("Boolean_2_1")
223 # START DEBUG PURPOSES
224 # prepare a study without last operation to trap floating problem with degenerated line
225 #aPathToStore = os.path.join(os.getcwd(), "Data")
227 #if not os.path.exists(aPathToStore):
228 # os.mkdir(aPathToStore)
229 #results = ModelAPI.StringList()
230 #ModelAPI.ModelAPI_Session.get().save(aPathToStore, results)
234 boolean = model.addFuse(part, boolean.results() + b4.results())
237 assert(model.checkPythonDump())