Salome HOME
Update copyrights
[modules/shaper.git] / src / ModelAPI / Test / TestFolder_Sketch.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 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
136 #=========================================================================
137 # Test 3. Sketch could be removed from the folder
138 #=========================================================================
139 fromFolder = FeatureList()
140 fromFolder.append(Sketch_1.feature())
141
142 aSession.startOperation()
143 isMovedOut = aPartDoc.removeFromFolder(fromFolder)
144 aSession.finishOperation()
145 assert(isMovedOut)
146 assert(aPartDoc.index(Sketch_1.feature(), True) == 1), "Wrong index of the {}: {}".format(Sketch_1.feature().name(), aPartDoc.index(Sketch_1.feature(), True))
147 NB_FEATURES_OUT += 1
148 # full number of features
149 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
150 # number of features outside the folder
151 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
152
153
154 #=========================================================================
155 # Test 4. Add 2 sketches to the folder below
156 #=========================================================================
157
158 toFolder = FeatureList()
159 toFolder.append(Sketch_0.feature())
160 toFolder.append(Sketch_1.feature())
161
162 # move features to the folder
163 aSession.startOperation()
164 aFolder = aPartDoc.findFolderBelow(toFolder)
165 assert(aFolder is not None and aFolder.data().isEqual(Folder_1.data()))
166 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
167 aSession.finishOperation()
168 assert(isAdded)
169 NB_FEATURES_OUT -= 2
170 # full number of features
171 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
172 # number of features outside the folder
173 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
174
175 # check the index of the sketch in the folder
176 aFound = aPartDoc.findContainingFolder(Sketch_0.feature())
177 assert(aFound[0].data().isEqual(aFolder.data()))
178 assert(aFound[1] == 0)
179 # check the index of the extrusion in the folder
180 aFound = aPartDoc.findContainingFolder(Sketch_1.feature())
181 assert(aFound[0].data().isEqual(aFolder.data()))
182 assert(aFound[1] == 1)
183
184
185 from salome.shaper import model
186 assert(model.checkPythonDump())