1 # Copyright (C) 2014-2020 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 email : webmaster.salome@opencascade.com
20 # Creation of Platine model using the end-user API
21 # Author: Sergey POKHODENKO
22 # -----------------------------
24 from salome.shaper import geom
25 from salome.shaper import model
27 # START DEBUG PURPOSES
35 partset = model.moduleDocument()
38 part = model.addPart(partset).document()
45 model.addParameter(part, "L", str(L))
46 model.addParameter(part, "E", str(E))
47 model.addParameter(part, "P", str(P))
51 sketch = model.addSketch(part, model.defaultPlane("YOZ"))
53 points = [(0, 0), (0, L), (L, L), (L, 0)]
54 geom_points = [geom.Pnt2d(*p) for p in points]
55 left, top, right, bottom = model.addPolygon(sketch, *geom_points)
58 sketch.setFixed(left.startPoint())
60 sketch.setHorizontal(bottom)
61 sketch.setHorizontal(top)
63 sketch.setVertical(right)
64 sketch.setVertical(left)
66 sketch.setLength(top, "L")
67 sketch.setLength(left, "L")
69 sketch.setFilletWithRadius(left.endPoint(), 32)
74 body = model.addExtrusion(part, sketch.selectFace(), "E")
80 sketch = model.addSketch(part, "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4")
83 points = [(0, 0), (0, L), (P, L), (P, 16 + 16), (P - 20, 16 + 16), (P - 20, 16), (P, 16), (P, 0)]
84 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
85 geom_points = [geom.Pnt2d(*p) for p in points]
86 left, top, v2, h2, v1, h1, right, bottom = model.addPolygon(sketch, *geom_points)
88 points = [(P - 20, 16 + 16 / 2), (P - 20, 16 + 16), (P - 20, 16)]
89 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
90 center, start, end = [geom.Pnt2d(*p) for p in points]
91 arc = sketch.addArc(center, start, end, True)
97 sketch.setParallel(left, right)
98 sketch.setParallel(left, v2)
99 sketch.setParallel(bottom, h1)
100 sketch.setParallel(top, h2)
102 sketch.setPerpendicular(left, bottom)
103 sketch.setPerpendicular(left, top)
105 sketch.setEqual(top, bottom)
106 sketch.setEqual(h1, h2)
108 sketch.setCoincident(arc.center(), v1)
109 sketch.setCoincident(arc.startPoint(), h2.endPoint())
110 sketch.setCoincident(arc.endPoint(), h1.startPoint())
113 left_e = sketch.addLine("[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/To_Face]")
114 sketch.setCoincident(left_e.startPoint(), left.endPoint())
115 sketch.setCoincident(left_e.endPoint(), left.startPoint())
118 #sketch.setLength(v1, 16)
119 sketch.setLength(v2, 32)
120 sketch.setLength(h2, 20)
121 sketch.setLength(right, 16)
122 sketch.setLength(top, "P")
126 body = model.addExtrusion(part, sketch.selectFace(), "-E")
134 sketch = model.addSketch(part, "Boolean_1_1/Modified_Face&Sketch_1/SketchLine_3")
136 # Create base polygon
137 H, L, l, r = 28, 40, 8, 12
139 points = [(0, 0), (0, H), (l, H), (l + 2 * r, H), (L, H), (L, 0)]
140 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
141 geom_points = [geom.Pnt2d(*p) for p in points]
142 left, top_left, top_middle, top_right, right, bottom, = model.addPolygon(sketch, *geom_points)
144 points = [(l + r, H), (l + 2 * r, H), (l, H)]
145 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
146 center, start, end = [geom.Pnt2d(*p) for p in points]
147 arc = sketch.addArc(center, start, end, False)
150 top_middle.setAuxiliary(True)
153 sketch.setParallel(bottom, top_left)
154 sketch.setParallel(bottom, top_right)
156 sketch.setPerpendicular(bottom, left)
157 sketch.setPerpendicular(bottom, right)
159 sketch.setEqual(left, right)
161 sketch.setLength(bottom, L)
162 sketch.setLength(right, H)
163 sketch.setLength(top_left, l)
165 sketch.setCoincident(top_middle, arc.center())
166 sketch.setCoincident(top_middle.endPoint(), arc.startPoint())
167 sketch.setCoincident(top_middle.startPoint(), arc.endPoint())
169 sketch.setRadius(arc, r)
172 bottom_e = sketch.addLine("[Boolean_1_1/Modified_Face&Sketch_2/SketchLine_6][Extrusion_2_1/To_Face]")
173 sketch.setCoincident(bottom_e, bottom.startPoint())
174 sketch.setCoincident(bottom_e.startPoint(), bottom.endPoint())
179 body = model.addExtrusion(part, sketch.selectFace(), "-(L-22)")
184 # Create XOZ 2nd sketch
185 sketch = model.addSketch(part, "Boolean_2_1/Modified_Face&Sketch_2/SketchLine_6")
187 # Create base polygon
188 points = [(0, 0), (0, 1), (1, 0)]
189 points = [(p[0], -p[1]) for p in points] # as we look to back of the face
190 geom_points = [geom.Pnt2d(*p) for p in points]
191 left, diagonal, bottom = model.addPolygon(sketch, *geom_points)
194 bottom_e = sketch.addLine("[Boolean_2_1/Modified_Face&Extrusion_2_1/To_Face][Boolean_2_1/Modified_Face&Sketch_2/SketchLine_6]")
195 sketch.setCoincident(bottom_e.endPoint(), bottom.startPoint())
196 sketch.setCoincident(bottom_e.startPoint(), left.startPoint())
198 left_e = sketch.addLine("[Boolean_2_1/Modified_Face&Extrusion_3_1/From_Face][Extrusion_3_1/Generated_Face&Sketch_3/SketchLine_18]")
199 sketch.setCoincident(left_e.startPoint(), left.endPoint())
204 body = model.addExtrusion(part, sketch.selectFace(), "-12")
212 boolean = model.addFuse(part, b1.results() + b2.results())
213 boolean.result().setName("Boolean_1_1")
218 boolean = model.addFuse(part, boolean.results() + b3.results())
219 boolean.result().setName("Boolean_2_1")
222 # START DEBUG PURPOSES
223 # prepare a study without last operation to trap floating problem with degenerated line
224 #aPathToStore = os.path.join(os.getcwd(), "Data")
226 #if not os.path.exists(aPathToStore):
227 # os.mkdir(aPathToStore)
228 #results = ModelAPI.StringList()
229 #ModelAPI.ModelAPI_Session.get().save(aPathToStore, results)
233 boolean = model.addFuse(part, boolean.results() + b4.results())
236 assert(model.checkPythonDump())