Salome HOME
Update unit tests for SHAPER group
[modules/shaper.git] / test.API / SHAPER / Transformations / TestTranslation_5.py
1 ## Copyright (C) 2014-2017  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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 """
22 Test case for Translation feature.
23 Written on High API.
24 """
25 from salome.shaper import model
26
27 model.begin()
28 partSet = model.moduleDocument()
29 Part_1 = model.addPart(partSet)
30 Part_1_doc = Part_1.document()
31
32 # Boxes
33 Box_1 = model.addBox(Part_1_doc, 10, 20, 10)
34 Box_2 = model.addBox(Part_1_doc, 10, 20, 10)
35 Box_3 = model.addBox(Part_1_doc, 10, 20, 10)
36 Box_4 = model.addBox(Part_1_doc, 10, 20, 10)
37
38 # Sketches
39 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
40 SketchLine_1 = Sketch_1.addLine(47.23370043826552, 82.68004022993115, -80.41547074975036, -6.189635913624215)
41 SketchLine_2 = Sketch_1.addLine(-80.41547074975036, -6.189635913624215, 57.33252727276048, -26.79124265599387)
42 SketchLine_3 = Sketch_1.addLine(57.33252727276048, -26.79124265599387, 47.23370043826552, 82.68004022993115)
43 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
44 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
45 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_3.endPoint())
46 model.do()
47
48 # Points
49 Point_1 = model.addPoint(Part_1_doc, 10, 0, 0)
50 Point_2 = model.addPoint(Part_1_doc, 10, 10, 0)
51
52 # Vertex
53 Vertex_1 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Sketch_1/SketchLine_1_StartVertex")])
54 Vertex_2 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Sketch_1/SketchLine_1_EndVertex")])
55
56 # Translations
57 Translation_99 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("VERTEX", "Point_1"), model.selection("VERTEX", "Point_2"))
58 Translation_100 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Translation_1_1")], model.selection("VERTEX", "Point_1"), model.selection("VERTEX", "Point_1"))
59 Translation_101 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Translation_1_1")], model.selection("VERTEX", "InvalidName"), model.selection("VERTEX", "Point_1"))
60 Translation_102 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Translation_1_1")], model.selection("VERTEX", "Point_1"), model.selection("VERTEX", "InvalidName"))
61 Translation_103 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_2_1")], model.selection("VERTEX", "Sketch_1/SketchLine_1_StartVertex"), model.selection("VERTEX", "Sketch_1/SketchLine_1_EndVertex"))
62 Translation_104 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("VERTEX", "Vertex_1_1"), model.selection("VERTEX", "Vertex_2_1"))
63 Translation_105 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_4_1")], model.selection("VERTEX", "[Box_4_1/Back][Box_4_1/Left][Box_4_1/Bottom]"), model.selection("VERTEX", "[Box_4_1/Front][Box_4_1/Right][Box_4_1/Top]"))
64 model.do()
65 model.end()
66
67 # Checks
68 from GeomAPI import GeomAPI_Shape
69
70 model.testNbResults(Translation_99, 1)
71 model.testNbSubResults(Translation_99, [0])
72 model.testNbSubShapes(Translation_99, GeomAPI_Shape.SOLID, [1])
73 model.testNbSubShapes(Translation_99, GeomAPI_Shape.FACE, [6])
74 model.testHaveNamingFaces(Translation_99, model, Part_1_doc)
75
76 model.testNbResults(Translation_103, 1)
77 model.testNbSubResults(Translation_103, [0])
78 model.testNbSubShapes(Translation_103, GeomAPI_Shape.SOLID, [1])
79 model.testNbSubShapes(Translation_103, GeomAPI_Shape.FACE, [6])
80 model.testHaveNamingFaces(Translation_103, model, Part_1_doc)
81
82 model.testNbResults(Translation_104, 1)
83 model.testNbSubResults(Translation_104, [0])
84 model.testNbSubShapes(Translation_104, GeomAPI_Shape.SOLID, [1])
85 model.testNbSubShapes(Translation_104, GeomAPI_Shape.FACE, [6])
86 model.testHaveNamingFaces(Translation_104, model, Part_1_doc)
87
88 model.testNbResults(Translation_105, 1)
89 model.testNbSubResults(Translation_105, [0])
90 model.testNbSubShapes(Translation_105, GeomAPI_Shape.SOLID, [1])
91 model.testNbSubShapes(Translation_105, GeomAPI_Shape.FACE, [6])
92 model.testHaveNamingFaces(Translation_105, model, Part_1_doc)
93
94
95 model.testNbResults(Translation_100, 0)
96 assert(Translation_100.feature().error() == 'The feature uses equal shapes.')
97
98 model.testNbResults(Translation_101, 0)
99 assert(Translation_101.feature().error() == 'Attribute "start_point" is not initialized.')
100
101 model.testNbResults(Translation_102, 0)
102 assert(Translation_102.feature().error() == 'Attribute "end_point" is not initialized.')