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