+## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+##
+## This library 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 2.1 of the License, or (at your option) any later version.
+##
+## This library 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 this library; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+## See http:##www.salome-platform.org/ or
+## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+##
+
# Creation of Platine model using the end-user API
# Author: Sergey POKHODENKO
# -----------------------------
-import geom
-import model
+from salome.shaper import geom
+from salome.shaper import model
+
+# START DEBUG PURPOSES
+# Should be removed
+import os
+import ModelAPI
+# END DEBUG PURPOSES
# Initialisation
model.begin()
P = 80
# Create Parameters
-model.addParameter(part, "L", L)
-model.addParameter(part, "E", E)
-model.addParameter(part, "P", P)
+model.addParameter(part, "L", str(L))
+model.addParameter(part, "E", str(E))
+model.addParameter(part, "P", str(P))
def vertical_body():
# Create YOZ sketch
points = [(0, 0), (0, L), (L, L), (L, 0)]
geom_points = [geom.Pnt2d(*p) for p in points]
- left, top, right, bottom = sketch.addPolygon(*geom_points)
+ left, top, right, bottom = model.addPolygon(sketch, *geom_points)
# Set constraints
- sketch.setRigid(left.startPoint())
+ sketch.setFixed(left.startPoint())
- sketch.setHorizontal(bottom.result())
- sketch.setHorizontal(top.result())
+ sketch.setHorizontal(bottom)
+ sketch.setHorizontal(top)
- sketch.setVertical(right.result())
- sketch.setVertical(left.result())
+ sketch.setVertical(right)
+ sketch.setVertical(left)
- sketch.setLength(top.result(), "L")
- sketch.setLength(left.result(), "L")
+ sketch.setLength(top, "L")
+ sketch.setLength(left, "L")
- sketch.setFillet(left.endPoint(), 32)
+ sketch.setFilletWithRadius(left.endPoint(), 32)
model.do() #!!!
# Create extrusion
body = model.addExtrusion(part, sketch.selectFace(), "E")
- model.do()
-
return body
def bottom_body():
# Create XOY sketch
- sketch = model.addSketch(part, "Extrusion_1_1/LateralFace_2")
+ sketch = model.addSketch(part, "Extrusion_1_1/Generated_Face_5")
# Create base polygon
points = [(0, 0), (0, L), (P, L), (P, 16 + 16), (P - 20, 16 + 16), (P - 20, 16), (P, 16), (P, 0)]
points = [(p[0], -p[1]) for p in points] # as we look to back of the face
geom_points = [geom.Pnt2d(*p) for p in points]
- left, top, v2, h2, v1, h1, right, bottom = sketch.addPolygon(*geom_points)
+ left, top, v2, h2, v1, h1, right, bottom = model.addPolygon(sketch, *geom_points)
- points = [(P - 20, 16 + 16 / 2), (P - 20, 16), (P - 20, 16 + 16)]
+ points = [(P - 20, 16 + 16 / 2), (P - 20, 16 + 16), (P - 20, 16)]
points = [(p[0], -p[1]) for p in points] # as we look to back of the face
center, start, end = [geom.Pnt2d(*p) for p in points]
- arc = sketch.addArc(center, start, end, inversed=True)
+ arc = sketch.addArc(center, start, end, True)
# Set Auxiliarity
v1.setAuxiliary(True)
# Set constraints
- sketch.setParallel(left.result(), right.result())
- sketch.setParallel(left.result(), v2.result())
- sketch.setParallel(bottom.result(), h1.result())
- sketch.setParallel(top.result(), h2.result())
+ sketch.setParallel(left, right)
+ sketch.setParallel(left, v2)
+ sketch.setParallel(bottom, h1)
+ sketch.setParallel(top, h2)
- sketch.setPerpendicular(left.result(), bottom.result())
- sketch.setPerpendicular(left.result(), top.result())
+ sketch.setPerpendicular(left, bottom)
+ sketch.setPerpendicular(left, top)
- sketch.setEqual(top.result(), bottom.result())
- sketch.setEqual(h1.result(), h2.result())
+ sketch.setEqual(top, bottom)
+ sketch.setEqual(h1, h2)
- sketch.setLength(top.result(), "P")
- sketch.setLength(right.result(), 16)
- sketch.setLength(v1.result(), 16)
- sketch.setLength(h2.result(), 20)
-
- sketch.setCoincident(arc.center(), v1.result())
+ sketch.setCoincident(arc.center(), v1)
sketch.setCoincident(arc.startPoint(), h2.endPoint())
sketch.setCoincident(arc.endPoint(), h1.startPoint())
# Binding
- left_e = sketch.addLine("Extrusion_1_1/LateralFace_2|Extrusion_1_1/ToFace_1")
+ left_e = sketch.addLine("Extrusion_1_1/Generated_Face_5&Extrusion_1_1/To_Face_1_1")
sketch.setCoincident(left_e.startPoint(), left.endPoint())
sketch.setCoincident(left_e.endPoint(), left.startPoint())
- model.do() #!!!
+ # Dimensions
+ #sketch.setLength(v1, 16)
+ sketch.setLength(v2, 32)
+ sketch.setLength(h2, 20)
+ sketch.setLength(right, 16)
+ sketch.setLength(top, "P")
+ model.do()
# Create extrusion
body = model.addExtrusion(part, sketch.selectFace(), "-E")
def body_3():
# Create XOZ sketch
- sketch = model.addSketch(part, "Boolean_1_1/Modified_3")
+ sketch = model.addSketch(part, "Boolean_1_1/Modified_2")
# Create base polygon
H, L, l, r = 28, 40, 8, 12
points = [(0, 0), (0, H), (l, H), (l + 2 * r, H), (L, H), (L, 0)]
points = [(p[0], -p[1]) for p in points] # as we look to back of the face
geom_points = [geom.Pnt2d(*p) for p in points]
- left, top_left, top_middle, top_right, right, bottom, = sketch.addPolygon(*geom_points)
+ left, top_left, top_middle, top_right, right, bottom, = model.addPolygon(sketch, *geom_points)
- points = [(l + r, H), (l, H), (l + 2 * r, H)]
+ points = [(l + r, H), (l + 2 * r, H), (l, H)]
points = [(p[0], -p[1]) for p in points] # as we look to back of the face
center, start, end = [geom.Pnt2d(*p) for p in points]
- arc = sketch.addArc(center, start, end)
+ arc = sketch.addArc(center, start, end, False)
# Set Auxiliarity
top_middle.setAuxiliary(True)
# Set constraints
- sketch.setParallel(bottom.result(), top_left.result())
- sketch.setParallel(bottom.result(), top_right.result())
+ sketch.setParallel(bottom, top_left)
+ sketch.setParallel(bottom, top_right)
- sketch.setPerpendicular(bottom.result(), left.result())
- sketch.setPerpendicular(bottom.result(), right.result())
+ sketch.setPerpendicular(bottom, left)
+ sketch.setPerpendicular(bottom, right)
- sketch.setEqual(left.result(), right.result())
+ sketch.setEqual(left, right)
- sketch.setLength(bottom.result(), L)
- sketch.setLength(right.result(), H)
- sketch.setLength(top_left.result(), l)
+ sketch.setLength(bottom, L)
+ sketch.setLength(right, H)
+ sketch.setLength(top_left, l)
- sketch.setCoincident(top_middle.result(), arc.center())
+ sketch.setCoincident(top_middle, arc.center())
sketch.setCoincident(top_middle.endPoint(), arc.startPoint())
sketch.setCoincident(top_middle.startPoint(), arc.endPoint())
- sketch.setRadius(arc.result(), r)
+ sketch.setRadius(arc, r)
# Binding
- bottom_e = sketch.addLine("Boolean_1_1/Modified_1|Boolean_1_1/Modified_3")
- sketch.setCoincident(bottom_e.result(), bottom.startPoint())
+ bottom_e = sketch.addLine("Boolean_1_1/Modified_7&Boolean_1_1/Modified_5")
+ sketch.setCoincident(bottom_e, bottom.startPoint())
sketch.setCoincident(bottom_e.startPoint(), bottom.endPoint())
model.do() #!!!
# Create extrusion
body = model.addExtrusion(part, sketch.selectFace(), "-(L-22)")
- model.do() #!!!
-
return body
def body_4():
# Create XOZ 2nd sketch
- sketch = model.addSketch(part, "Boolean_2_1/Modified_7")
+ sketch = model.addSketch(part, "Boolean_2_1/Modified_4")
# Create base polygon
points = [(0, 0), (0, 1), (1, 0)]
points = [(p[0], -p[1]) for p in points] # as we look to back of the face
geom_points = [geom.Pnt2d(*p) for p in points]
- left, diagonal, bottom = sketch.addPolygon(*geom_points)
+ left, diagonal, bottom = model.addPolygon(sketch, *geom_points)
# Binding
- bottom_e = sketch.addLine("Boolean_2_1/Modified_8|Boolean_2_1/Modified_7")
+ bottom_e = sketch.addLine("Boolean_2_1/Modified_3&Boolean_2_1/Modified_4")
sketch.setCoincident(bottom_e.endPoint(), bottom.startPoint())
sketch.setCoincident(bottom_e.startPoint(), left.startPoint())
- left_e = sketch.addLine("Boolean_2_1/Modified_3|Boolean_2_1/Modified_2")
+ left_e = sketch.addLine("Boolean_2_1/Modified_6&Boolean_2_1/Modified_8")
sketch.setCoincident(left_e.startPoint(), left.endPoint())
model.do() #!!!
# Create extrusion
body = model.addExtrusion(part, sketch.selectFace(), "-12")
- model.do() #!!!
-
return body
b1 = vertical_body()
b2 = bottom_body()
-boolean = model.addAddition(part, b1.result() + b2.result(), [])
+boolean = model.addFuse(part, b1.results() + b2.results())
model.do()
b3 = body_3()
-boolean = model.addAddition(part, boolean.result() + b3.result(), [])
+boolean = model.addFuse(part, boolean.results() + b3.results())
model.do()
+# START DEBUG PURPOSES
+# prepare a study without last operation to trap floating problem with degenerated line
+#aPathToStore = os.path.join(os.getcwd(), "Data")
+#print aPathToStore
+#if not os.path.exists(aPathToStore):
+# os.mkdir(aPathToStore)
+#results = ModelAPI.StringList()
+#ModelAPI.ModelAPI_Session.get().save(aPathToStore, results)
+# END DEBUG PURPOSES
b4 = body_4()
-boolean = model.addAddition(part, boolean.result() + b4.result(), [])
-model.do()
+boolean = model.addFuse(part, boolean.results() + b4.results())
+model.end()
+
+assert(model.checkPythonDump())