Salome HOME
c030212160b955c05eb21e253835347d77b8e725
[modules/shaper.git] / test.API / SHAPER / Transformations / TestMultiTranslation.py
1 # Copyright (C) 2014-2022  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 MultiTranslation 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 # Create Boxes
32 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
33 Box_2 = model.addBox(Part_1_doc, 10, 10, 10)
34 Box_3 = model.addBox(Part_1_doc, 10, 10, 10)
35 Box_4 = model.addBox(Part_1_doc, 10, 10, 10)
36 Box_5 = model.addBox(Part_1_doc, 10, 10, 10)
37 Box_6 = model.addBox(Part_1_doc, 10, 10, 10)
38 Box_7 = model.addBox(Part_1_doc, 10, 10, 10)
39 Box_8 = model.addBox(Part_1_doc, 10, 10, 10)
40 Box_9 = model.addBox(Part_1_doc, 10, 10, 10)
41
42 # Create Sketches
43 # Sketch contenant un contour ferme de 3 lignes
44 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
45 SketchLine_1 = Sketch_1.addLine(20.57127738485033, 88.55774147773481, -110.037034305799, -25.45393392073257)
46 SketchLine_2 = Sketch_1.addLine(-110.037034305799, -25.45393392073257, 49.43499267560162, -77.40862144408482)
47 SketchLine_3 = Sketch_1.addLine(49.43499267560162, -77.40862144408482, 68.1964076145899, 55.3644688933709)
48 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
49 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
50
51 # Sketch creer sur la face de la box confondue avec le plan XOZ contenant un cercle inclus dans la face de la box
52 Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_9_1/Left"))
53 SketchCircle_1 = Sketch_2.addCircle(3.420516499282639, 6.702654232424678, 2.660489383382409)
54 model.do()
55
56 # Create Wire & Extrusion
57 Wire_1 = model.addWire(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_2"), model.selection("EDGE", "Sketch_1/SketchLine_1"), model.selection("EDGE", "Sketch_1/SketchLine_3")])
58 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Wire_1_1")], model.selection("EDGE", "PartSet/OZ"), 50, 0)
59
60 # Revolution of the circle
61 Revolution_1 = model.addRevolution(Part_1_doc, [model.selection("WIRE", "Sketch_2/Face-SketchCircle_1_2r_wire")], model.selection("EDGE", "PartSet/OZ"), 360, 0)
62
63 # Create MultiTranslations
64 MultiTranslation_1 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 15, 5)
65 MultiTranslation_2 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_2_1")], model.selection("EDGE", "PartSet/OX"), -15, 5)
66 MultiTranslation_3 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("EDGE", "PartSet/OX"), 15, -2)
67 MultiTranslation_4 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_4_1")], model.selection("EDGE", "InvalidName"), 15, -2)
68 MultiTranslation_5 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_5_1")], model.selection("EDGE", "PartSet/OX"), 10, 5, model.selection("EDGE", "PartSet/OY"), 10, 5)
69 MultiTranslation_6 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_6_1")], model.selection("EDGE", "PartSet/OX"), 10, 5, model.selection("EDGE", "PartSet/OY"), -10, 5)
70 MultiTranslation_7 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_7_1")], model.selection("EDGE", "PartSet/OX"), 10, 5, model.selection("EDGE", "PartSet/OY"), 10, -2)
71 MultiTranslation_8 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_8_1")], model.selection("EDGE", "PartSet/OX"), 10, 5, model.selection("EDGE", "InvalidName"), 10, 5)
72 MultiTranslation_9 = model.addMultiTranslation(Part_1_doc, [model.selection("SHELL", "Extrusion_1_1")], model.selection("EDGE", "PartSet/OZ"), 50, 10)
73 MultiTranslation_10 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Revolution_1_1"), model.selection("SOLID", "Box_9_1")], model.selection("EDGE", "PartSet/OY"), 20, 3)
74
75 model.do()
76 model.end()
77
78
79
80 # Checks
81 from GeomAPI import GeomAPI_Shape, GeomAPI_ShapeExplorer
82 from GeomAlgoAPI import *
83
84 model.testNbResults(MultiTranslation_1, 1)
85 model.testNbSubResults(MultiTranslation_1, [5])
86 model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.COMPOUND, [1])
87 model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.SOLID, [5])
88 model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.FACE, [30])
89 model.testHaveNamingFaces(MultiTranslation_1, model, Part_1_doc)
90
91 model.testNbResults(MultiTranslation_2, 1)
92 model.testNbSubResults(MultiTranslation_2, [5])
93 model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.COMPOUND, [1])
94 model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.SOLID, [5])
95 model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.FACE, [30])
96 model.testHaveNamingFaces(MultiTranslation_2, model, Part_1_doc)
97
98 model.testNbResults(MultiTranslation_5, 1)
99 model.testNbSubResults(MultiTranslation_5, [25])
100 model.testNbSubShapes(MultiTranslation_5, GeomAPI_Shape.COMPOUND, [1])
101 model.testNbSubShapes(MultiTranslation_5, GeomAPI_Shape.SOLID, [25])
102 model.testNbSubShapes(MultiTranslation_5, GeomAPI_Shape.FACE, [150])
103 model.testHaveNamingFaces(MultiTranslation_5, model, Part_1_doc)
104
105 model.testNbResults(MultiTranslation_6, 1)
106 model.testNbSubResults(MultiTranslation_6, [25])
107 model.testNbSubShapes(MultiTranslation_6, GeomAPI_Shape.COMPOUND, [1])
108 model.testNbSubShapes(MultiTranslation_6, GeomAPI_Shape.SOLID, [25])
109 model.testNbSubShapes(MultiTranslation_6, GeomAPI_Shape.FACE, [150])
110 model.testHaveNamingFaces(MultiTranslation_6, model, Part_1_doc)
111
112 ####################################################################################################
113 # Test of MultiTranslation 10
114 model.testNbResults(MultiTranslation_10, 2)
115 model.testNbSubResults(MultiTranslation_10, [3, 3])
116
117 def testSubResult(theFeature, theModel, thePartDoc, resultIndex, nbSolidsExpected, nbFacesExpected):
118     result = theFeature.results()[resultIndex].resultSubShapePair()[0]
119     shape = result.shape()
120     shapeExplorer = GeomAPI_ShapeExplorer(shape, GeomAPI_Shape.SOLID)
121     nbSolids = 0
122     while shapeExplorer.more():
123         nbSolids += 1
124         shapeExplorer.next()
125     assert(nbSolids == nbSolidsExpected)
126
127     shapeExplorer = GeomAPI_ShapeExplorer(shape, GeomAPI_Shape.FACE)
128     nbFaces = 0
129     selectionList = []
130     while shapeExplorer.more():
131         nbFaces += 1
132         selection = theModel.selection(result, shapeExplorer.current()) # First argument should be result/sub-result, second is sub-shape on this result/sub-result
133         selectionList.append(selection)
134         shapeExplorer.next()
135     assert(nbFaces == nbFacesExpected)
136     # Create group with this selection list
137     Group_1 = theModel.addGroup(thePartDoc, selectionList)
138     theModel.do()
139     theModel.end()
140
141     # Now you can check that all selected shapes in group have right shape type and name.
142     groupFeature = Group_1.feature()
143     groupSelectionList = groupFeature.selectionList("group_list")
144     theModel.end()
145     assert(groupSelectionList.size() == len(selectionList))
146     for index in range(0, groupSelectionList.size()):
147         attrSelection = groupSelectionList.value(index)
148         shape = attrSelection.value()
149         name = attrSelection.namingName()
150         assert(shape.isFace())
151         assert(name != ""), "String empty"
152
153 testSubResult(MultiTranslation_10, model, Part_1_doc, 0, 3, 3)
154 testSubResult(MultiTranslation_10, model, Part_1_doc, 1, 3, 18)
155 ####################################################################################################
156
157 model.testNbResults(MultiTranslation_3, 0)
158 assert(MultiTranslation_3.feature().error() == 'Multitranslation builder :: the number of copies for the first direction is null or negative.')
159
160 model.testNbResults(MultiTranslation_4, 0)
161 assert(MultiTranslation_4.feature().error() == 'Attribute "axis_first_dir" is not initialized.')
162
163 model.testNbResults(MultiTranslation_7, 0)
164 assert(MultiTranslation_7.feature().error() == 'Multitranslation builder :: the number of copies for the second direction is null or negative.')
165
166 model.testNbResults(MultiTranslation_8, 0)
167 assert(MultiTranslation_8.feature().error() == 'Attribute "axis_second_dir" is not initialized.')
168
169
170 # Multitranslation en erreur
171 #model.testNbResults(MultiTranslation_9, 1)
172 #model.testNbSubResults(MultiTranslation_9, [10])
173 #model.testNbSubShapes(MultiTranslation_9, GeomAPI_Shape.COMPOUND, [1])
174 #model.testNbSubShapes(MultiTranslation_9, GeomAPI_Shape.SOLID, [0])
175 #model.testNbSubShapes(MultiTranslation_9, GeomAPI_Shape.SHELL, [10])
176 #model.testNbSubShapes(MultiTranslation_9, GeomAPI_Shape.FACE, [30])
177 #model.testHaveNamingFaces(MultiTranslation_9, model, Part_1_doc)