]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
[PythonAPI] Example Platine. Comlete version
authorspo <sergey.pokhodenko@opencascade.com>
Thu, 17 Dec 2015 11:06:12 +0000 (14:06 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Thu, 17 Dec 2015 11:53:09 +0000 (14:53 +0300)
src/PythonAPI/examples/Platine.py

index 556832c6dba763acedf41fe010c261eb1bd85e23..040647c410c893e66fd6bcf15cae80f0d05aaf69 100644 (file)
@@ -2,7 +2,6 @@
 # Author: Sergey POKHODENKO
 # -----------------------------
 
-from GeomDataAPI import geomDataAPI_Point2D
 import geom
 import model
 
@@ -18,173 +17,187 @@ E = 16
 P = 80
 
 # Create Parameters
-model.addParameter(part, "L", str(L))
-model.addParameter(part, "E", str(E))
-model.addParameter(part, "P", str(P))
+model.addParameter(part, "L", L)
+model.addParameter(part, "E", E)
+model.addParameter(part, "P", P)
 
-# Create YOZ sketch
-sketch = model.addSketch(part, model.defaultPlane("YOZ"))
+def vertical_body():
+    # Create YOZ sketch
+    sketch = model.addSketch(part, model.defaultPlane("YOZ"))
 
-model.do()
+    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)
 
-# Create base polygon
-H, L, r = 64, 64, 32
-dx, dy = 0, 0
+    # Set constraints
+    sketch.setRigid(left.startPointData())
 
-points = [(0, 0), (0, H), (L, H), (L, 0)]
-points = [(p[0] + dx, p[1] + dy) for p in points]
-geom_points = [geom.Pnt2d(*p) for p in points]
-left, top, right, bottom = sketch.addPolygon(*geom_points)
+    sketch.setHorizontal(bottom.result())
+    sketch.setHorizontal(top.result())
 
-model.do()
+    sketch.setVertical(right.result())
+    sketch.setVertical(left.result())
 
-# Set constraints
-sketch.setRigid(left.startPointData())
+    sketch.setLength(top.result(), "L")
+    sketch.setLength(left.result(), "L")
 
-sketch.setHorizontal(bottom.result())
-sketch.setHorizontal(top.result())
+    sketch.setFillet(left.endPointData(), 32)
 
-sketch.setVertical(right.result())
-sketch.setVertical(left.result())
+    model.do()  #!!!
 
-sketch.setLength(top.result(), "L")
-sketch.setLength(left.result(), "L")
+    # Create extrusion
+    body = model.addExtrusion(part, sketch.selectFace(), "E")
 
-sketch.setFillet(left.endPointData(), r)
+    model.do()
 
-model.do()
+    return body
 
-# Create extrusion
-YOZ_body = model.addExtrusion(part, sketch.selectFace(), "E")
+def bottom_body():
+    # Create XOY sketch
+    sketch = model.addSketch(part, "Extrusion_1_1/LateralFace_2")
 
-model.do()
+    # 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)
 
-# Create XOY sketch
-sketch = model.addSketch(part, model.defaultPlane("XOY"))
+    points = [(P - 20, 16 + 16 / 2), (P - 20, 16), (P - 20, 16 + 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)
 
-# Create base polygon
-L, P = 64, P
-dx, dy = E, 0
+    # Set Auxiliarity
+    v1.setAuxiliary(True)
 
-points = [(0, 0), (0, L), (P, L), (P, 16 + 16), (P - 20, 16 + 16), (P - 20, 16), (P, 16), (P, 0)]
-points = [(p[0] + dx, p[1] + dy) for p in points]
-geom_points = [geom.Pnt2d(*p) for p in points]
-left, top, v2, h2, v1, h1, right, bottom = sketch.addPolygon(*geom_points)
+    # 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())
 
-points = [(P - 20, 16 + 16 / 2), (P - 20, 16), (P - 20, 16 + 16)]
-points = [(p[0] + dx, p[1] + dy) for p in points]
-center, start, end = [geom.Pnt2d(*p) for p in points]
-arc = sketch.addArc(center, start, end)
+    sketch.setPerpendicular(left.result(), bottom.result())
+    sketch.setPerpendicular(left.result(), top.result())
 
-model.do()
+    sketch.setEqual(top.result(), bottom.result())
+    sketch.setEqual(h1.result(), h2.result())
 
-# Set Auxiliarity
-v1.setAuxiliary(True)
+    sketch.setLength(top.result(), "P")
+    sketch.setLength(right.result(), 16)
+    sketch.setLength(v1.result(), 16)
+    sketch.setLength(h2.result(), 20)
 
-# Set constraints
-sketch.setCoincident(arc.center(), v1.result())
-sketch.setCoincident(h2.endPointData(), arc.startPoint())
-sketch.setCoincident(arc.endPoint(), h1.startPointData())
+    sketch.setCoincident(arc.center(), v1.result())
+    sketch.setCoincident(arc.startPoint(), h2.endPointData())
+    sketch.setCoincident(arc.endPoint(), h1.startPointData())
 
-sketch.setPerpendicular(bottom.result(), right.result())
-sketch.setPerpendicular(top.result(), left.result())
-sketch.setPerpendicular(top.result(), v2.result())
+    # Binding
+    left_e = sketch.addLine("Extrusion_1_1/LateralFace_2|Extrusion_1_1/ToFace_1")
+    sketch.setCoincident(left_e.startPointData(), left.endPointData())
+    sketch.setCoincident(left_e.endPointData(), left.startPointData())
 
-sketch.setParallel(bottom.result(), h1.result())
-sketch.setParallel(h1.result(), h2.result())
-sketch.setParallel(h2.result(), top.result())
-sketch.setParallel(v1.result(), v2.result())
+    model.do()  #!!!
 
-sketch.setLength(top.result(), "P")
-sketch.setLength(h2.result(), "20")
-sketch.setLength(v1.result(), "16")
-sketch.setLength(right.result(), "16")
+    # Create extrusion
+    body = model.addExtrusion(part, sketch.selectFace(), "-E")
 
-model.do()
+    model.do()
 
-# Create extrusion
-XOY_body = model.addExtrusion(part, sketch.selectFace(), "E")
-# TODO(spo): collision with first object. Move object to the right place.
+    return body
 
-# Create XOZ sketch
-plane = model.defaultPlane("XOZ")
-plane.o.setY(64)
-sketch = model.addSketch(part, plane)
+def body_3():
+    # Create XOZ sketch
+    sketch = model.addSketch(part, "Boolean_1_1/Modified_3")
 
-# TODO(spo): select origin point
+    # Create base polygon
+    H, L, l, r = 28, 40, 8, 12
 
-# Create base polygon
-H, L, l, r = 28, 40, 8, 12
-dx, dy = E, E
+    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)
 
-points = [(l + 2 * r, H), (L, H), (L, 0), (0, 0), (0, H), (l, H)]
-points = [(p[0] + dx, p[1] + dy) for p in points]
-geom_points = [geom.Pnt2d(*p) for p in points]
-top_right, right, bottom, left, top_left = sketch.addPolyline(*geom_points)
+    points = [(l + r, H), (l, H), (l + 2 * r, 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)
 
-points = [(l + r, H), (l, H), (l + 2 * r, H)]
-points = [(p[0] + dx, p[1] + dy) for p in points]
-center, start, end = [geom.Pnt2d(*p) for p in points]
-arc = sketch.addArc(center, start, end)
+    # Set Auxiliarity
+    top_middle.setAuxiliary(True)
 
-model.do()
+    # Set constraints
+    sketch.setParallel(bottom.result(), top_left.result())
+    sketch.setParallel(bottom.result(), top_right.result())
 
-# Set constraints
-sketch.setCoincident(top_left.endPointData(), arc.startPoint())
-sketch.setCoincident(arc.endPoint(), top_right.endPointData())
+    sketch.setPerpendicular(bottom.result(), left.result())
+    sketch.setPerpendicular(bottom.result(), right.result())
 
-sketch.setPerpendicular(bottom.result(), right.result())
+    sketch.setEqual(left.result(), right.result())
 
-sketch.setParallel(bottom.result(), top_left.result())
-sketch.setParallel(bottom.result(), top_right.result())
-sketch.setParallel(left.result(), right.result())
+    sketch.setLength(bottom.result(), L)
+    sketch.setLength(right.result(), H)
+    sketch.setLength(top_left.result(), l)
 
-sketch.setLength(bottom.result(), L)
-sketch.setLength(right.result(), H)
-sketch.setLength(top_left.result(), l)
+    sketch.setCoincident(top_middle.result(), arc.center())
+    sketch.setCoincident(top_middle.endPointData(), arc.startPoint())
+    sketch.setCoincident(top_middle.startPointData(), arc.endPoint())
 
-sketch.setRadius(arc.result(), r)
+    sketch.setRadius(arc.result(), r)
 
-model.do()
+    # Binding
+    bottom_e = sketch.addLine("Boolean_1_1/Modified_1|Boolean_1_1/Modified_3")
+    sketch.setCoincident(bottom_e.result(), bottom.startPointData())
+    sketch.setCoincident(bottom_e.startPointData(), bottom.endPointData())
 
-# Create extrusion
-XOZ_body = model.addExtrusion(part, sketch.selectFace(), "42")
+    model.do()  #!!!
 
-model.do()
+    # Create extrusion
+    body = model.addExtrusion(part, sketch.selectFace(), "-(L-22)")
 
-# Create XOZ 2nd sketch
-plane = model.defaultPlane("XOZ")
-plane.o.setY(64)
-sketch = model.addSketch(part, plane)
+    model.do()  #!!!
 
-# TODO(spo): make coincidence with existing points
+    return body
 
-# Create base polygon
-dx, dy = E + L, E
-H, L = 28, 96 - dx
+def body_4():
+    # Create XOZ 2nd sketch
+    sketch = model.addSketch(part, "Boolean_2_1/Modified_7")
 
-points = [(0, 0), (0, H), (L, 0)]
-points = [(p[0] + dx, p[1] + dy) for p in points]
-geom_points = [geom.Pnt2d(*p) for p in points]
-left, diagonal, bottom = sketch.addPolygon(*geom_points)
+    # 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)
 
-model.do()
+    # Binding
+    bottom_e = sketch.addLine("Boolean_2_1/Modified_8|Boolean_2_1/Modified_7")
+    sketch.setCoincident(bottom_e.endPointData(), bottom.startPointData())
+    sketch.setCoincident(bottom_e.startPointData(), left.startPointData())
+
+    left_e = sketch.addLine("Boolean_2_1/Modified_3|Boolean_2_1/Modified_2")
+    sketch.setCoincident(left_e.startPointData(), left.endPointData())
+
+    model.do()  #!!!
+
+    # Create extrusion
+    body = model.addExtrusion(part, sketch.selectFace(), "-12")
+
+    model.do()  #!!!
+
+    return body
 
-# TODO(spo): make coincidence instead of constraints
-sketch.setLength(bottom.result(), L)
-sketch.setLength(left.result(), H)
 
-sketch.setPerpendicular(bottom.result(), left.result())
+b1 = vertical_body()
+b2 = bottom_body()
 
+boolean = model.addAddition(part, b1.result() + b2.result(), [])
 model.do()
 
-# Create extrusion
-XOZ_2nd_body = model.addExtrusion(part, sketch.selectFace(), "12")
+b3 = body_3()
 
+boolean = model.addAddition(part, boolean.result() + b3.result(), [])
 model.do()
 
-# Create Boolean
-boolean = model.addAddition(part, YOZ_body.result() + XOY_body.result() +
-                                  XOZ_body.result() + XOZ_2nd_body.result(), [])
+b4 = body_4()
 
+boolean = model.addAddition(part, boolean.result() + b4.result(), [])
 model.do()