1 ## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #=========================================================================
22 # Initialization of the test
23 #=========================================================================
24 from ModelAPI import *
26 __updated__ = "2017-11-23"
28 aSession = ModelAPI_Session.get()
31 def newPoint(theDocument, theX, theY, theZ):
32 aSession.startOperation()
33 aPoint = theDocument.addFeature("Point")
34 aPointData = aPoint.data()
35 assert(aPointData is not None)
36 aPointData.real("x").setValue(theX)
37 aPointData.real("y").setValue(theY)
38 aPointData.real("z").setValue(theZ)
39 aPointData.string("creation_method").setValue("by_xyz")
40 aSession.finishOperation()
44 #=========================================================================
45 # Test 1. Add a point into a folder above
46 #=========================================================================
47 aSession.startOperation()
48 aPart = aSession.moduleDocument().addFeature("Part")
49 aSession.finishOperation()
51 # add point and a folder before it
52 aPartDoc = aSession.activeDocument()
53 aPoint1 = newPoint(aPartDoc, 0., 0., 0.)
55 aSession.startOperation()
56 aFolder1 = aPartDoc.addFolder(aPoint1)
57 aSession.finishOperation()
62 assert(aPartDoc.size("Folders") == 1), "Wrong number of folders: {}".format(aPartDoc.size("Folders"))
63 assert(aPartDoc.size("Features") == 2), "Wrong number of features: {}".format(aPartDoc.size("Features"))
64 FOLDER_NAME_EXPECTED = "Folder_1"
65 assert(aFolder1.name() == FOLDER_NAME_EXPECTED), "Actual name '{}', expected '{}'".format(aFolder1.name(), FOLDER_NAME_EXPECTED)
67 toFolder = FeatureList()
68 toFolder.append(aPoint1)
70 # move point to the folder
71 aSession.startOperation()
72 aFolder = aPartDoc.findFolderAbove(toFolder)
73 assert(aFolder is not None)
74 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
75 aSession.finishOperation()
78 # full number of features
79 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
80 # number of features outside the folder
81 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
83 #=========================================================================
84 # Test 2. Add a point into a folder below
85 #=========================================================================
86 aPoint2 = newPoint(aPartDoc, 10., 0., 0.)
87 aPoint3 = newPoint(aPartDoc, 10., 10., 0.)
92 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
93 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
96 aSession.startOperation()
97 aFolder2 = aPartDoc.addFolder(aPoint3)
98 aSession.finishOperation()
100 NB_FEATURES_FULL += 1
103 assert(aPartDoc.size("Folders") == 2), "Wrong number of folders: {}".format(aPartDoc.size("Folders"))
104 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
105 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
107 toFolder = FeatureList()
108 toFolder.append(aPoint2)
110 # move point to the folder
111 aSession.startOperation()
112 aFolder = aPartDoc.findFolderAbove(toFolder)
113 assert(aFolder is not None)
114 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
115 aSession.finishOperation()
120 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
121 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
123 #=========================================================================
124 # Test 3. Add several points into a folder
125 #=========================================================================
126 aPoint4 = newPoint(aPartDoc, 0., 10., 0.)
128 NB_FEATURES_FULL += 1
131 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
132 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
135 aSession.startOperation()
136 aFolder2 = aPartDoc.addFolder(aPoint3)
137 aSession.finishOperation()
139 NB_FEATURES_FULL += 1
142 assert(aPartDoc.size("Folders") == 3), "Wrong number of folders: {}".format(aPartDoc.size("Folders"))
143 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
144 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
146 toFolder = FeatureList()
147 toFolder.append(aPoint3)
148 toFolder.append(aPoint4)
150 # move point to the folder
151 aSession.startOperation()
152 aFolder = aPartDoc.findFolderAbove(toFolder)
153 assert(aFolder is not None)
154 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
155 aSession.finishOperation()
160 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
161 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
164 from salome.shaper import model
165 assert(model.checkPythonDump())