X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPythonAPI%2Fexamples%2FPlatine.py;h=a21d55eed5d1e1bbf39f8d875c8289460c40745d;hb=05cb54cb247bda099b1dc9218e3382e79becb40c;hp=f037cece43650224fd4724026dcdd1a4624db3f4;hpb=6c2db92a41188bb3becbd20e1b5dcaeda7099eab;p=modules%2Fshaper.git diff --git a/src/PythonAPI/examples/Platine.py b/src/PythonAPI/examples/Platine.py index f037cece4..a21d55eed 100644 --- a/src/PythonAPI/examples/Platine.py +++ b/src/PythonAPI/examples/Platine.py @@ -4,7 +4,12 @@ import geom import model + +# START DEBUG PURPOSES +# Should be removed +import os import ModelAPI +# END DEBUG PURPOSES # Initialisation model.begin() @@ -18,9 +23,9 @@ E = 16 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 @@ -28,77 +33,74 @@ def vertical_body(): 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.setFillet([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/Generated_Face_4") + sketch = model.addSketch(part, "Extrusion_1_1/Generated_Face_3") # 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.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/Generated_Face_4&Extrusion_1_1/To_Face_1_1") + left_e = sketch.addLine("Extrusion_1_1/Generated_Face_3&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.result(), 16) - sketch.setLength(h2.result(), 20) - sketch.setLength(right.result(), 16) - sketch.setLength(top.result(), "P") + #sketch.setLength(v1, 16) + sketch.setLength(v2, 32) + sketch.setLength(h2, 20) + sketch.setLength(right, 16) + sketch.setLength(top, "P") model.do() # Create extrusion @@ -118,38 +120,38 @@ def body_3(): 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_5&Boolean_1_1/Modified_8") - sketch.setCoincident(bottom_e.result(), bottom.startPoint()) + sketch.setCoincident(bottom_e, bottom.startPoint()) sketch.setCoincident(bottom_e.startPoint(), bottom.endPoint()) model.do() #!!! @@ -157,8 +159,6 @@ def body_3(): # Create extrusion body = model.addExtrusion(part, sketch.selectFace(), "-(L-22)") - model.do() #!!! - return body def body_4(): @@ -169,7 +169,7 @@ def body_4(): 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_3&Boolean_2_1/Modified_4") @@ -184,28 +184,32 @@ def body_4(): # 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.result() + b2.result()) model.do() b3 = body_3() -boolean = model.addAddition(part, boolean.result() + b3.result()) +boolean = model.addFuse(part, boolean.result() + b3.result()) model.do() # START DEBUG PURPOSES # prepare a study without last operation to trap floating problem with degenerated line -results = ModelAPI.StringList() -ModelAPI.ModelAPI_Session.get().save("/misc/dn48/newgem/azv/testPlatine", results) +#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.result() + b4.result()) +model.end() + +assert(model.checkPythonDump())