Salome HOME
Updated test for "Box" primitive (use parameters).
[modules/shaper.git] / test.API / SHAPER / Primitives / TestBox.py
1 """
2 Test case for Primitive Box feature. 
3 Written on High API.
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
12 # Init
13 Point_1 = model.addPoint(Part_1_doc, 0, 0, 0).result()
14 Point_2 = model.addPoint(Part_1_doc, 50, 50, 50).result()
15 Point_3 = model.addPoint(Part_1_doc, 0, 50, 50).result()
16 Point_4 = model.addPoint(Part_1_doc, 50, 0, 50).result()
17 Point_5 = model.addPoint(Part_1_doc, 50, 50, 0).result()
18 Vertex_3 = model.selection("VERTEX", "pnt")
19
20 # Sketch
21 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
22 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("YOZ"))
23 SketchLine_1 = Sketch_1.addLine(20, 10, 40, 10)
24 SketchLine_2 = Sketch_1.addLine(40, 10, 40, 20)
25 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
26 SketchLine_3 = Sketch_1.addLine(40, 20, 20, 20)
27 SketchLine_4 = Sketch_1.addLine(20, 20, 20, 10)
28 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
29 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_4.endPoint())
30 SketchLine_5 = Sketch_2.addLine(20, 10, 40, 10)
31 SketchLine_6 = Sketch_2.addLine(40, 10, 40, 20)
32 SketchConstraintCoincidence_1 = Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
33 SketchLine_7 = Sketch_2.addLine(40, 20, 20, 20)
34 SketchLine_8 = Sketch_2.addLine(20, 20, 20, 10)
35 SketchConstraintCoincidence_3 = Sketch_2.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint())
36 SketchConstraintCoincidence_4 = Sketch_2.setCoincident(SketchLine_5.startPoint(), SketchLine_8.endPoint())
37 Vertex_1 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Sketch_1/Vertex-SketchLine_1s-SketchLine_4e")])
38 Vertex_2 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Sketch_2/Vertex-SketchLine_7s-SketchLine_6e")])
39
40 # Extrusion
41 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection("EDGE", "PartSet/OZ"), 100, 0)
42 Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_2")], model.selection("EDGE", "PartSet/OX"), 100, 0)
43
44 # Parameters
45 model.addParameter(Part_1_doc, "dx", "10")
46 model.addParameter(Part_1_doc, "dy", "10")
47 model.addParameter(Part_1_doc, "dz", "10")
48
49 # Tests
50 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
51 Box_2 = model.addBox(Part_1_doc, 0, 10, 10)
52 Box_3 = model.addBox(Part_1_doc, 10, 0, 10)
53 Box_4 = model.addBox(Part_1_doc, 10, 10, 0)
54 Box_5 = model.addBox(Part_1_doc, -10, 10, 10)
55 Box_6 = model.addBox(Part_1_doc, 10, -10, 10)
56 Box_7 = model.addBox(Part_1_doc, 10, 10, -10)
57 Box_8 = model.addBox(Part_1_doc, Point_1, Point_2)
58 Box_9 = model.addBox(Part_1_doc, Point_1, Point_1)
59 Box_10 = model.addBox(Part_1_doc, Point_1, Point_3)
60 Box_11 = model.addBox(Part_1_doc, Point_1, Point_4)
61 Box_12 = model.addBox(Part_1_doc, Point_1, Point_5)
62 Box_13 = model.addBox(Part_1_doc, Vertex_3, Point_2)
63 Box_14 = model.addBox(Part_1_doc, Point_2, Vertex_3)
64 Box_15 = model.addBox(Part_1_doc, model.selection("VERTEX", "Sketch_1/Vertex-SketchLine_1s-SketchLine_4e"), model.selection("VERTEX", "Sketch_2/Vertex-SketchLine_7s-SketchLine_6e"))
65 Box_16 = model.addBox(Part_1_doc, model.selection("VERTEX", "Extrusion_1_1/Generated_Face_3&Extrusion_1_1/Generated_Face_2&Extrusion_1_1/To_Face_1"), model.selection("VERTEX", "Extrusion_2_1/Generated_Face_2&Extrusion_2_1/Generated_Face_1&Extrusion_2_1/To_Face_1"))
66 Box_17 = model.addBox(Part_1_doc, model.selection("VERTEX", "Vertex_1_1"), model.selection("VERTEX", "Vertex_2_1"))
67 Box_18 = model.addBox(Part_1_doc, "dx", "dy", "dz")
68 model.do()
69 model.end()
70
71 # Checks
72 from GeomAPI import GeomAPI_Shape
73
74 model.testNbResults(Box_1, 1)
75 model.testNbSubResults(Box_1, [0])
76 model.testNbSubShapes(Box_1, GeomAPI_Shape.SOLID, [1])
77 model.testNbSubShapes(Box_1, GeomAPI_Shape.FACE, [6])
78 model.testHaveNamingFaces(Box_1, model, Part_1_doc)
79
80 model.testNbResults(Box_8, 1)
81 model.testNbSubResults(Box_8, [0])
82 model.testNbSubShapes(Box_8, GeomAPI_Shape.SOLID, [1])
83 model.testNbSubShapes(Box_8, GeomAPI_Shape.FACE, [6])
84 model.testHaveNamingFaces(Box_8, model, Part_1_doc)
85
86 model.testNbResults(Box_15, 1)
87 model.testNbSubResults(Box_15, [0])
88 model.testNbSubShapes(Box_15, GeomAPI_Shape.SOLID, [1])
89 model.testNbSubShapes(Box_15, GeomAPI_Shape.FACE, [6])
90 model.testHaveNamingFaces(Box_15, model, Part_1_doc)
91
92 model.testNbResults(Box_16, 1)
93 model.testNbSubResults(Box_16, [0])
94 model.testNbSubShapes(Box_16, GeomAPI_Shape.SOLID, [1])
95 model.testNbSubShapes(Box_16, GeomAPI_Shape.FACE, [6])
96 model.testHaveNamingFaces(Box_16, model, Part_1_doc)
97
98 model.testNbResults(Box_17, 1)
99 model.testNbSubResults(Box_17, [0])
100 model.testNbSubShapes(Box_17, GeomAPI_Shape.SOLID, [1])
101 model.testNbSubShapes(Box_17, GeomAPI_Shape.FACE, [6])
102 model.testHaveNamingFaces(Box_17, model, Part_1_doc)
103
104 model.testNbResults(Box_18, 1)
105 model.testNbSubResults(Box_18, [0])
106 model.testNbSubShapes(Box_18, GeomAPI_Shape.SOLID, [1])
107 model.testNbSubShapes(Box_18, GeomAPI_Shape.FACE, [6])
108 model.testHaveNamingFaces(Box_18, model, Part_1_doc)
109
110 model.testNbResults(Box_2, 0)
111 assert(Box_2.feature().error() == "Box builder with dimensions :: Dx is null or negative.")
112
113 model.testNbResults(Box_3, 0)
114 assert(Box_3.feature().error() == "Box builder with dimensions :: Dy is null or negative.")
115
116 model.testNbResults(Box_4, 0)
117 assert(Box_4.feature().error() == "Box builder with dimensions :: Dz is null or negative.")
118
119 model.testNbResults(Box_5, 0)
120 assert(Box_5.feature().error() == "Box builder with dimensions :: Dx is null or negative.")
121
122 model.testNbResults(Box_6, 0)
123 assert(Box_6.feature().error() == "Box builder with dimensions :: Dy is null or negative.")
124
125 model.testNbResults(Box_7, 0)
126 assert(Box_7.feature().error() == "Box builder with dimensions :: Dz is null or negative.")
127
128 model.testNbResults(Box_9, 0)
129 assert(Box_9.feature().error() == "Box builder with points :: the distance between the two points is null.")
130
131 model.testNbResults(Box_10, 0)
132 assert(Box_10.feature().error() == "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.")
133
134 model.testNbResults(Box_11, 0)
135 assert(Box_11.feature().error() == "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.")
136
137 model.testNbResults(Box_12, 0)
138 assert(Box_12.feature().error() == "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.")
139
140 model.testNbResults(Box_13, 0)
141 assert(Box_13.feature().error() == "Attribute \"FirstPoint\" is not initialized.")
142
143 model.testNbResults(Box_14, 0)
144 assert(Box_14.feature().error() == "Attribute \"SecondPoint\" is not initialized.")