]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelAPI/Test/TestFolder_Sketch.py
Salome HOME
Added a unit-test for #21537 : Dumped file not loadable
[modules/shaper.git] / src / ModelAPI / Test / TestFolder_Sketch.py
1 # Copyright (C) 2014-2020  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 checks adding sketch into a folder
22 """
23
24 from ModelAPI import *
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 Sketch_0 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
33 SketchLine_1 = Sketch_0.addLine(10, -10, 10, 10)
34 model.do()
35
36 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
37 SketchCircle_1 = Sketch_1.addCircle(50, 50, 25)
38 model.do()
39 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchCircle_1_2r")], model.selection(), 50, 0)
40
41 Sketch_2 = model.addSketch(Part_1_doc, model.standardPlane("XOY"))
42 SketchCircle_2 = Sketch_2.addCircle(100, -100, 50)
43 model.do()
44 Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_3")], model.selection(), 10, 0)
45 ExtrusionCut_1 = model.addExtrusionCut(Part_1_doc, [], model.selection(), 0, 10, [model.selection("SOLID", "Extrusion_2_1")])
46 Sketch_3 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_2_1/To_Face_1"))
47 SketchProjection_1 = Sketch_3.addProjection(model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_3/SketchCircle_2_2][Extrusion_2_1/To_Face]__cc"), False)
48 SketchPoint_1 = SketchProjection_1.createdFeature()
49 SketchCircle_3 = Sketch_3.addCircle(100, -100, 25)
50 SketchConstraintCoincidence_1 = Sketch_3.setCoincident(SketchPoint_1.result(), SketchCircle_3.center())
51 ExtrusionCut_1.setNestedSketch(Sketch_3)
52 model.do()
53 model.end()
54
55
56 aSession = ModelAPI_Session.get()
57 aPartDoc = aSession.activeDocument()
58
59 #=========================================================================
60 # Test 1. Sketch and extrusion could be added to the folder above
61 #=========================================================================
62 aSession.startOperation()
63 Folder_1 = aPartDoc.addFolder(Sketch_1.feature())
64 aSession.finishOperation()
65
66 NB_FEATURES_FULL = 7
67 NB_FEATURES_OUT  = 7
68 # full number of features
69 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
70 # number of features outside the folder
71 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
72
73 toFolder = FeatureList()
74 toFolder.append(Sketch_1.feature())
75 toFolder.append(Extrusion_1.feature())
76
77 # move features to the folder
78 aSession.startOperation()
79 aFolder = aPartDoc.findFolderAbove(toFolder)
80 assert(aFolder is not None and aFolder.data().isEqual(Folder_1.data()))
81 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
82 aSession.finishOperation()
83 assert(isAdded)
84 NB_FEATURES_OUT -= 2
85 # full number of features
86 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
87 # number of features outside the folder
88 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
89
90 # check the index of the sketch in the folder
91 aFound = aPartDoc.findContainingFolder(Sketch_1.feature())
92 assert(aFound[0].data().isEqual(aFolder.data()))
93 assert(aFound[1] == 0)
94 # check the index of the extrusion in the folder
95 aFound = aPartDoc.findContainingFolder(Extrusion_1.feature())
96 assert(aFound[0].data().isEqual(aFolder.data()))
97 assert(aFound[1] == 1)
98
99
100 #=========================================================================
101 # Test 2. Sketch could be added to the folder below
102 #=========================================================================
103 aSession.startOperation()
104 Folder_2 = aPartDoc.addFolder(Extrusion_2.feature())
105 aSession.finishOperation()
106
107 NB_FEATURES_FULL += 1
108 NB_FEATURES_OUT  += 1
109 # full number of features
110 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
111 # number of features outside the folder
112 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
113
114 toFolder = FeatureList()
115 toFolder.append(Sketch_2.feature())
116
117 # move feature to the folder
118 aSession.startOperation()
119 aFolder = aPartDoc.findFolderBelow(toFolder)
120 assert(aFolder is not None and aFolder.data().isEqual(Folder_2.data()))
121 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
122 aSession.finishOperation()
123 assert(isAdded)
124 NB_FEATURES_OUT -= 1
125 # full number of features
126 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
127 # number of features outside the folder
128 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
129
130 # check the index of the sketch in the folder
131 aFound = aPartDoc.findContainingFolder(Sketch_2.feature())
132 assert(aFound[0].data().isEqual(aFolder.data()))
133 assert(aFound[1] == 0)
134
135 # check sketch is the last feature in the folder
136 aLastFeature = Folder_2.lastVisibleFeature()
137 assert(aLastFeature.getKind() == "Sketch")
138
139
140 #=========================================================================
141 # Test 3. Sketch could be removed from the folder
142 #=========================================================================
143 fromFolder = FeatureList()
144 fromFolder.append(Sketch_1.feature())
145
146 aSession.startOperation()
147 isMovedOut = aPartDoc.removeFromFolder(fromFolder)
148 aSession.finishOperation()
149 assert(isMovedOut)
150 assert(aPartDoc.index(Sketch_1.feature(), True) == 1), "Wrong index of the {}: {}".format(Sketch_1.feature().name(), aPartDoc.index(Sketch_1.feature(), True))
151 NB_FEATURES_OUT += 1
152 # full number of features
153 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
154 # number of features outside the folder
155 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
156
157
158 #=========================================================================
159 # Test 4. Add 2 sketches to the folder below
160 #=========================================================================
161
162 toFolder = FeatureList()
163 toFolder.append(Sketch_0.feature())
164 toFolder.append(Sketch_1.feature())
165
166 # move features to the folder
167 aSession.startOperation()
168 aFolder = aPartDoc.findFolderBelow(toFolder)
169 assert(aFolder is not None and aFolder.data().isEqual(Folder_1.data()))
170 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
171 aSession.finishOperation()
172 assert(isAdded)
173 NB_FEATURES_OUT -= 2
174 # full number of features
175 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
176 # number of features outside the folder
177 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
178
179 # check the index of the sketch in the folder
180 aFound = aPartDoc.findContainingFolder(Sketch_0.feature())
181 assert(aFound[0].data().isEqual(aFolder.data()))
182 assert(aFound[1] == 0)
183 # check the index of the extrusion in the folder
184 aFound = aPartDoc.findContainingFolder(Sketch_1.feature())
185 assert(aFound[0].data().isEqual(aFolder.data()))
186 assert(aFound[1] == 1)
187
188
189 from salome.shaper import model
190 assert(model.checkPythonDump())