Salome HOME
Fix the problem of the sketch plane update
[modules/shaper.git] / src / SketchPlugin / Test / TestSketchDrawer.py
1 # -*- coding: utf-8 -*-
2
3 from SketchAPI import *
4
5 from salome.shaper import model
6
7 model.begin()
8 partSet = model.moduleDocument()
9 Part_1 = model.addPart(partSet)
10 Part_1_doc = Part_1.document()
11 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
12 SketchLine_1 = Sketch_1.addLine(-14.48008258397498, -13.79591274114419, 5.519917416025022, -13.79591274114419)
13 SketchLine_2 = Sketch_1.addLine(10.51991741602502, -8.795912741144186, 10.51991741602502, 18.20408725885581)
14 SketchLine_3 = Sketch_1.addLine(10.51991741602502, 18.20408725885581, -14.48008258397498, 13.79591274114419)
15 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
16 SketchConstraintCoincidence_1.setName("SketchConstraintCoincidence_2")
17 SketchLine_4 = Sketch_1.addLine(-14.48008258397498, 13.79591274114419, -14.48008258397498, -13.79591274114419)
18 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
19 SketchConstraintCoincidence_2.setName("SketchConstraintCoincidence_3")
20 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_4.endPoint())
21 SketchConstraintCoincidence_3.setName("SketchConstraintCoincidence_4")
22 SketchArc_1 = Sketch_1.addArc(5.519917416025022, -8.795912741144186, 5.519917416025022, -13.79591274114419, 10.51991741602502, -8.795912741144186, False)
23 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_1.endPoint())
24 SketchConstraintCoincidence_4.setName("SketchConstraintCoincidence_5")
25 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_2.startPoint())
26 SketchConstraintCoincidence_5.setName("SketchConstraintCoincidence_6")
27 SketchConstraintTangent_1 = Sketch_1.setTangent(SketchArc_1.results()[1], SketchLine_1.result())
28 SketchConstraintTangent_2 = Sketch_1.setTangent(SketchArc_1.results()[1], SketchLine_2.result())
29 SketchCircle_1 = Sketch_1.addCircle(0, 0, 5)
30 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
31 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
32 SketchConstraintAngle_1 = Sketch_1.setAngle(SketchLine_4.result(), SketchLine_3.result(), 100)
33 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_2.result(), 27)
34 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchLine_1.startPoint(), SketchLine_2.result(), 25, True)
35 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], 5)
36 SketchConstraintPerpendicular_1 = Sketch_1.setPerpendicular(SketchLine_1.result(), SketchLine_4.result())
37 SketchConstraintDistance_2 = Sketch_1.setDistance(SketchLine_4.startPoint(), SketchCircle_1.center(), 20, True)
38 SketchConstraintDistance_3 = Sketch_1.setDistance(SketchLine_4.endPoint(), SketchCircle_1.center(), 20, True)
39 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
40 SketchPoint_1 = SketchProjection_1.createdFeature()
41 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchAPI_Point(SketchPoint_1).coordinates(), SketchCircle_1.center())
42 SketchConstraintCoincidence_6.setName("SketchConstraintCoincidence_7")
43 SketchConstraintRadius_2 = Sketch_1.setRadius(SketchCircle_1.results()[1], 5)
44 model.do()
45 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchArc_1_2f-SketchLine_2f-SketchLine_3f-SketchLine_4f-SketchCircle_1_2r")], model.selection(), 10, 0)
46 model.do()
47 # create a drawer feature of the extrusion and upper face, without dimensions
48 Drawer1 = Part_1_doc.addFeature("SketchDrawer")
49 Drawer1.selection("base_shape").setValue(Extrusion_1.feature(), None)
50 Drawer1.boolean("add_dimensions").setValue(False)
51 PlaneSelection = model.selection("FACE", "Extrusion_1_1/To_Face")
52 PlaneSelection.fillAttribute(Drawer1.selection("plane"))
53 model.do()
54 # create a drawer feature of the extrusion and upper face, with dimensions
55 Drawer2 = Part_1_doc.addFeature("SketchDrawer")
56 Drawer2.selection("base_shape").setValue(Extrusion_1.feature(), None)
57 Drawer2.boolean("add_dimensions").setValue(True)
58 PlaneSelection = model.selection("FACE", "Extrusion_1_1/To_Face")
59 PlaneSelection.fillAttribute(Drawer2.selection("plane"))
60 model.end()
61
62 # check that a sketch is created with valid elements
63 assert(Part_1_doc.size("Construction") == 3) # three sketches: base of extrusion and drawer's two
64
65 from ModelAPI import *
66 aFactory = ModelAPI_Session.get().validators()
67
68 Sketch1 = objectToFeature(Part_1_doc.object("Features", 2)) # the first created sketch feature
69 assert(aFactory.validate(Sketch1))
70 assert(len(Sketch1.results()) == 1)
71
72 Sketch2 = objectToFeature(Part_1_doc.object("Features", 3)) # the second created sketch feature
73 assert(aFactory.validate(Sketch2))
74 assert(len(Sketch2.results()) == 1)