Salome HOME
366c5cfc2a4503d0474f94e3be1fa174bec39ca9
[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 # Tests
45 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
46 Box_2 = model.addBox(Part_1_doc, 0, 10, 10)
47 Box_3 = model.addBox(Part_1_doc, 10, 0, 10)
48 Box_4 = model.addBox(Part_1_doc, 10, 10, 0)
49 Box_5 = model.addBox(Part_1_doc, -10, 10, 10)
50 Box_6 = model.addBox(Part_1_doc, 10, -10, 10)
51 Box_7 = model.addBox(Part_1_doc, 10, 10, -10)
52 Box_8 = model.addBox(Part_1_doc, Point_1, Point_2)
53 Box_9 = model.addBox(Part_1_doc, Point_1, Point_1)
54 Box_10 = model.addBox(Part_1_doc, Point_1, Point_3)
55 Box_11 = model.addBox(Part_1_doc, Point_1, Point_4)
56 Box_12 = model.addBox(Part_1_doc, Point_1, Point_5)
57 Box_13 = model.addBox(Part_1_doc, Vertex_3, Point_2)
58 Box_14 = model.addBox(Part_1_doc, Point_2, Vertex_3)
59 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"))
60 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"))
61 Box_17 = model.addBox(Part_1_doc, model.selection("VERTEX", "Vertex_1_1"), model.selection("VERTEX", "Vertex_2_1"))
62
63 # Checks
64 from GeomAPI import GeomAPI_Shape
65
66 model.testNbResults(Box_1, 1)
67 model.testNbSubResults(Box_1, [0])
68 model.testNbSubShapes(Box_1, GeomAPI_Shape.SOLID, [1])
69 model.testNbSubShapes(Box_1, GeomAPI_Shape.FACE, [6])
70 model.testHaveNamingFaces(Box_1, model, Part_1_doc)
71
72 model.testNbResults(Box_8, 1)
73 model.testNbSubResults(Box_8, [0])
74 model.testNbSubShapes(Box_8, GeomAPI_Shape.SOLID, [1])
75 model.testNbSubShapes(Box_8, GeomAPI_Shape.FACE, [6])
76 model.testHaveNamingFaces(Box_8, model, Part_1_doc)
77
78 model.testNbResults(Box_15, 1)
79 model.testNbSubResults(Box_15, [0])
80 model.testNbSubShapes(Box_15, GeomAPI_Shape.SOLID, [1])
81 model.testNbSubShapes(Box_15, GeomAPI_Shape.FACE, [6])
82 model.testHaveNamingFaces(Box_15, model, Part_1_doc)
83
84 model.testNbResults(Box_16, 1)
85 model.testNbSubResults(Box_16, [0])
86 model.testNbSubShapes(Box_16, GeomAPI_Shape.SOLID, [1])
87 model.testNbSubShapes(Box_16, GeomAPI_Shape.FACE, [6])
88 model.testHaveNamingFaces(Box_16, model, Part_1_doc)
89
90 model.testNbResults(Box_17, 1)
91 model.testNbSubResults(Box_17, [0])
92 model.testNbSubShapes(Box_17, GeomAPI_Shape.SOLID, [1])
93 model.testNbSubShapes(Box_17, GeomAPI_Shape.FACE, [6])
94 model.testHaveNamingFaces(Box_17, model, Part_1_doc)
95
96 model.testNbResults(Box_2, 0)
97 assert(Box_2.feature().error() == "Box builder with dimensions :: Dx is null or negative.")
98
99 model.testNbResults(Box_3, 0)
100 assert(Box_3.feature().error() == "Box builder with dimensions :: Dy is null or negative.")
101
102 model.testNbResults(Box_4, 0)
103 assert(Box_4.feature().error() == "Box builder with dimensions :: Dz is null or negative.")
104
105 model.testNbResults(Box_5, 0)
106 assert(Box_5.feature().error() == "Box builder with dimensions :: Dx is null or negative.")
107
108 model.testNbResults(Box_6, 0)
109 assert(Box_6.feature().error() == "Box builder with dimensions :: Dy is null or negative.")
110
111 model.testNbResults(Box_7, 0)
112 assert(Box_7.feature().error() == "Box builder with dimensions :: Dz is null or negative.")
113
114 model.testNbResults(Box_9, 0)
115 assert(Box_9.feature().error() == "Box builder with points :: the distance between the two points is null.")
116
117 model.testNbResults(Box_10, 0)
118 assert(Box_10.feature().error() == "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.")
119
120 model.testNbResults(Box_11, 0)
121 assert(Box_11.feature().error() == "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.")
122
123 model.testNbResults(Box_12, 0)
124 assert(Box_12.feature().error() == "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.")
125
126 model.testNbResults(Box_13, 0)
127 assert(Box_13.feature().error() == "Attribute \"FirstPoint\" is not initialized.")
128
129 model.testNbResults(Box_14, 0)
130 assert(Box_14.feature().error() == "Attribute \"SecondPoint\" is not initialized.")