Salome HOME
Updated copyright comment
[modules/shaper.git] / test.API / SHAPER / Primitives / TestBox.py
1 # Copyright (C) 2014-2024  CEA, EDF
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 Box_19 = model.addBox(Part_1_doc, 0, 0, 0, 20, 20 ,20)
88 model.do()
89 model.end()
90
91 # Checks
92 from GeomAPI import GeomAPI_Shape
93
94 model.testNbResults(Box_1, 1)
95 model.testNbSubResults(Box_1, [0])
96 model.testNbSubShapes(Box_1, GeomAPI_Shape.SOLID, [1])
97 model.testNbSubShapes(Box_1, GeomAPI_Shape.FACE, [6])
98 model.testHaveNamingFaces(Box_1, model, Part_1_doc)
99
100 model.testNbResults(Box_8, 1)
101 model.testNbSubResults(Box_8, [0])
102 model.testNbSubShapes(Box_8, GeomAPI_Shape.SOLID, [1])
103 model.testNbSubShapes(Box_8, GeomAPI_Shape.FACE, [6])
104 model.testHaveNamingFaces(Box_8, model, Part_1_doc)
105
106 model.testNbResults(Box_15, 1)
107 model.testNbSubResults(Box_15, [0])
108 model.testNbSubShapes(Box_15, GeomAPI_Shape.SOLID, [1])
109 model.testNbSubShapes(Box_15, GeomAPI_Shape.FACE, [6])
110 model.testHaveNamingFaces(Box_15, model, Part_1_doc)
111
112 model.testNbResults(Box_16, 1)
113 model.testNbSubResults(Box_16, [0])
114 model.testNbSubShapes(Box_16, GeomAPI_Shape.SOLID, [1])
115 model.testNbSubShapes(Box_16, GeomAPI_Shape.FACE, [6])
116 model.testHaveNamingFaces(Box_16, model, Part_1_doc)
117
118 model.testNbResults(Box_17, 1)
119 model.testNbSubResults(Box_17, [0])
120 model.testNbSubShapes(Box_17, GeomAPI_Shape.SOLID, [1])
121 model.testNbSubShapes(Box_17, GeomAPI_Shape.FACE, [6])
122 model.testHaveNamingFaces(Box_17, model, Part_1_doc)
123
124 model.testNbResults(Box_18, 1)
125 model.testNbSubResults(Box_18, [0])
126 model.testNbSubShapes(Box_18, GeomAPI_Shape.SOLID, [1])
127 model.testNbSubShapes(Box_18, GeomAPI_Shape.FACE, [6])
128 model.testHaveNamingFaces(Box_18, model, Part_1_doc)
129
130 model.testNbResults(Box_19, 1)
131 model.testNbSubResults(Box_19, [0])
132 model.testNbSubShapes(Box_19, GeomAPI_Shape.SOLID, [1])
133 model.testNbSubShapes(Box_19, GeomAPI_Shape.FACE, [6])
134 model.testHaveNamingFaces(Box_19, model, Part_1_doc)
135
136 model.testNbResults(Box_2, 0)
137 assert(Box_2.feature().error() == "Box builder with dimensions :: Dx is null or negative.")
138
139 model.testNbResults(Box_3, 0)
140 assert(Box_3.feature().error() == "Box builder with dimensions :: Dy is null or negative.")
141
142 model.testNbResults(Box_4, 0)
143 assert(Box_4.feature().error() == "Box builder with dimensions :: Dz is null or negative.")
144
145 model.testNbResults(Box_5, 0)
146 assert(Box_5.feature().error() == "Box builder with dimensions :: Dx is null or negative.")
147
148 model.testNbResults(Box_6, 0)
149 assert(Box_6.feature().error() == "Box builder with dimensions :: Dy is null or negative.")
150
151 model.testNbResults(Box_7, 0)
152 assert(Box_7.feature().error() == "Box builder with dimensions :: Dz is null or negative.")
153
154 model.testNbResults(Box_9, 0)
155 assert(Box_9.feature().error() == "Box builder with two points :: the distance between the two points is null.")
156
157 model.testNbResults(Box_10, 0)
158 assert(Box_10.feature().error() == "Box builder with two points :: the points belong both to one of the OXY, OYZ or OZX planes.")
159
160 model.testNbResults(Box_11, 0)
161 assert(Box_11.feature().error() == "Box builder with two points :: the points belong both to one of the OXY, OYZ or OZX planes.")
162
163 model.testNbResults(Box_12, 0)
164 assert(Box_12.feature().error() == "Box builder with two points :: the points belong both to one of the OXY, OYZ or OZX planes.")
165
166 model.testNbResults(Box_13, 0)
167 assert(Box_13.feature().error() == "Attribute \"FirstPoint\" is not initialized.")
168
169 model.testNbResults(Box_14, 0)
170 assert(Box_14.feature().error() == "Attribute \"SecondPoint\" is not initialized.")