Salome HOME
Update copyrights
[modules/shaper.git] / test.API / SHAPER / Primitives / TestBox.py
1 # Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 """
21 Test case for Primitive Box feature.
22 Written on High API.
23 """
24 from salome.shaper import model
25
26 model.begin()
27 partSet = model.moduleDocument()
28 Part_1 = model.addPart(partSet)
29 Part_1_doc = Part_1.document()
30
31 # Init
32 Point_1 = model.addPoint(Part_1_doc, 0, 0, 0).result()
33 Point_2 = model.addPoint(Part_1_doc, 50, 50, 50).result()
34 Point_3 = model.addPoint(Part_1_doc, 0, 50, 50).result()
35 Point_4 = model.addPoint(Part_1_doc, 50, 0, 50).result()
36 Point_5 = model.addPoint(Part_1_doc, 50, 50, 0).result()
37 Vertex_3 = model.selection("VERTEX", "pnt")
38
39 # Sketch
40 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
41 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("YOZ"))
42 SketchLine_1 = Sketch_1.addLine(20, 10, 40, 10)
43 SketchLine_2 = Sketch_1.addLine(40, 10, 40, 20)
44 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
45 SketchLine_3 = Sketch_1.addLine(40, 20, 20, 20)
46 SketchLine_4 = Sketch_1.addLine(20, 20, 20, 10)
47 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
48 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_4.endPoint())
49 SketchLine_5 = Sketch_2.addLine(20, 10, 40, 10)
50 SketchLine_6 = Sketch_2.addLine(40, 10, 40, 20)
51 SketchConstraintCoincidence_1 = Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
52 SketchLine_7 = Sketch_2.addLine(40, 20, 20, 20)
53 SketchLine_8 = Sketch_2.addLine(20, 20, 20, 10)
54 SketchConstraintCoincidence_3 = Sketch_2.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint())
55 SketchConstraintCoincidence_4 = Sketch_2.setCoincident(SketchLine_5.startPoint(), SketchLine_8.endPoint())
56 Vertex_1 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Sketch_1/SketchLine_1_StartVertex")])
57 Vertex_2 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Sketch_2/SketchLine_6_EndVertex")])
58
59 # Extrusion
60 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection("EDGE", "PartSet/OZ"), 100, 0)
61 Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_2")], model.selection("EDGE", "PartSet/OX"), 100, 0)
62
63 # Parameters
64 model.addParameter(Part_1_doc, "dx", "10")
65 model.addParameter(Part_1_doc, "dy", "25")
66 model.addParameter(Part_1_doc, "dz", "15")
67
68 # Tests
69 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
70 Box_2 = model.addBox(Part_1_doc, 0, 10, 10)
71 Box_3 = model.addBox(Part_1_doc, 10, 0, 10)
72 Box_4 = model.addBox(Part_1_doc, 10, 10, 0)
73 Box_5 = model.addBox(Part_1_doc, -10, 10, 10)
74 Box_6 = model.addBox(Part_1_doc, 10, -10, 10)
75 Box_7 = model.addBox(Part_1_doc, 10, 10, -10)
76 Box_8 = model.addBox(Part_1_doc, Point_1, Point_2)
77 Box_9 = model.addBox(Part_1_doc, Point_1, Point_1)
78 Box_10 = model.addBox(Part_1_doc, Point_1, Point_3)
79 Box_11 = model.addBox(Part_1_doc, Point_1, Point_4)
80 Box_12 = model.addBox(Part_1_doc, Point_1, Point_5)
81 Box_13 = model.addBox(Part_1_doc, Vertex_3, Point_2)
82 Box_14 = model.addBox(Part_1_doc, Point_2, Vertex_3)
83 Box_15 = model.addBox(Part_1_doc, model.selection("VERTEX", "Sketch_1/SketchLine_1_StartVertex"), model.selection("VERTEX", "Sketch_2/SketchLine_6_EndVertex"))
84 Box_16 = model.addBox(Part_1_doc, model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/To_Face]"), model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_6][Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_7][Extrusion_2_1/To_Face]"))
85 Box_17 = model.addBox(Part_1_doc, model.selection("VERTEX", "Vertex_1_1"), model.selection("VERTEX", "Vertex_2_1"))
86 Box_18 = model.addBox(Part_1_doc, "dx", "dy", "dz")
87 model.do()
88 model.end()
89
90 # Checks
91 from GeomAPI import GeomAPI_Shape
92
93 model.testNbResults(Box_1, 1)
94 model.testNbSubResults(Box_1, [0])
95 model.testNbSubShapes(Box_1, GeomAPI_Shape.SOLID, [1])
96 model.testNbSubShapes(Box_1, GeomAPI_Shape.FACE, [6])
97 model.testHaveNamingFaces(Box_1, model, Part_1_doc)
98
99 model.testNbResults(Box_8, 1)
100 model.testNbSubResults(Box_8, [0])
101 model.testNbSubShapes(Box_8, GeomAPI_Shape.SOLID, [1])
102 model.testNbSubShapes(Box_8, GeomAPI_Shape.FACE, [6])
103 model.testHaveNamingFaces(Box_8, model, Part_1_doc)
104
105 model.testNbResults(Box_15, 1)
106 model.testNbSubResults(Box_15, [0])
107 model.testNbSubShapes(Box_15, GeomAPI_Shape.SOLID, [1])
108 model.testNbSubShapes(Box_15, GeomAPI_Shape.FACE, [6])
109 model.testHaveNamingFaces(Box_15, model, Part_1_doc)
110
111 model.testNbResults(Box_16, 1)
112 model.testNbSubResults(Box_16, [0])
113 model.testNbSubShapes(Box_16, GeomAPI_Shape.SOLID, [1])
114 model.testNbSubShapes(Box_16, GeomAPI_Shape.FACE, [6])
115 model.testHaveNamingFaces(Box_16, model, Part_1_doc)
116
117 model.testNbResults(Box_17, 1)
118 model.testNbSubResults(Box_17, [0])
119 model.testNbSubShapes(Box_17, GeomAPI_Shape.SOLID, [1])
120 model.testNbSubShapes(Box_17, GeomAPI_Shape.FACE, [6])
121 model.testHaveNamingFaces(Box_17, model, Part_1_doc)
122
123 model.testNbResults(Box_18, 1)
124 model.testNbSubResults(Box_18, [0])
125 model.testNbSubShapes(Box_18, GeomAPI_Shape.SOLID, [1])
126 model.testNbSubShapes(Box_18, GeomAPI_Shape.FACE, [6])
127 model.testHaveNamingFaces(Box_18, model, Part_1_doc)
128
129 model.testNbResults(Box_2, 0)
130 assert(Box_2.feature().error() == "Box builder with dimensions :: Dx is null or negative.")
131
132 model.testNbResults(Box_3, 0)
133 assert(Box_3.feature().error() == "Box builder with dimensions :: Dy is null or negative.")
134
135 model.testNbResults(Box_4, 0)
136 assert(Box_4.feature().error() == "Box builder with dimensions :: Dz is null or negative.")
137
138 model.testNbResults(Box_5, 0)
139 assert(Box_5.feature().error() == "Box builder with dimensions :: Dx is null or negative.")
140
141 model.testNbResults(Box_6, 0)
142 assert(Box_6.feature().error() == "Box builder with dimensions :: Dy is null or negative.")
143
144 model.testNbResults(Box_7, 0)
145 assert(Box_7.feature().error() == "Box builder with dimensions :: Dz is null or negative.")
146
147 model.testNbResults(Box_9, 0)
148 assert(Box_9.feature().error() == "Box builder with points :: the distance between the two points is null.")
149
150 model.testNbResults(Box_10, 0)
151 assert(Box_10.feature().error() == "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.")
152
153 model.testNbResults(Box_11, 0)
154 assert(Box_11.feature().error() == "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.")
155
156 model.testNbResults(Box_12, 0)
157 assert(Box_12.feature().error() == "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.")
158
159 model.testNbResults(Box_13, 0)
160 assert(Box_13.feature().error() == "Attribute \"FirstPoint\" is not initialized.")
161
162 model.testNbResults(Box_14, 0)
163 assert(Box_14.feature().error() == "Attribute \"SecondPoint\" is not initialized.")