Salome HOME
updated copyright message
[modules/shaper.git] / src / ModelAPI / Test / TestFolder_Update.py
index c16eb03c380c5662d2522f85ca694832978c91ca..bff7ab0a40966bebf52ed1abdba808c28aae69df 100644 (file)
@@ -1,27 +1,27 @@
-## Copyright (C) 2014-2017  CEA/DEN, EDF R&D
-##
-## This library is free software; you can redistribute it and/or
-## modify it under the terms of the GNU Lesser General Public
-## License as published by the Free Software Foundation; either
-## version 2.1 of the License, or (at your option) any later version.
-##
-## This library is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-## Lesser General Public License for more details.
-##
-## You should have received a copy of the GNU Lesser General Public
-## License along with this library; if not, write to the Free Software
-## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-##
-## See http:##www.salome-platform.org/ or
-## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
-##
+# Copyright (C) 2014-2023  CEA, EDF
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
 
 #=========================================================================
 # Initialization of the test
 #=========================================================================
 from ModelAPI import *
+from GeomDataAPI import *
 
 __updated__ = "2017-11-23"
 
@@ -33,9 +33,7 @@ def newPoint(theDocument, theX, theY, theZ):
     aPoint = theDocument.addFeature("Point")
     aPointData = aPoint.data()
     assert(aPointData is not None)
-    aPointData.real("x").setValue(theX)
-    aPointData.real("y").setValue(theY)
-    aPointData.real("z").setValue(theZ)
+    geomDataAPI_Point(aPointData.attribute("point3d")).setValue(theX, theY, theZ)
     aPointData.string("creation_method").setValue("by_xyz")
     aSession.finishOperation()
     return aPoint
@@ -60,7 +58,7 @@ NB_FEATURES_FULL = 2
 NB_FEATURES_OUT  = 2
 
 assert(aPartDoc.size("Folders") == 1), "Wrong number of folders: {}".format(aPartDoc.size("Folders"))
-assert(aPartDoc.size("Features") == 2), "Wrong number of features: {}".format(aPartDoc.size("Features"))
+assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}".format(aPartDoc.size("Features"))
 FOLDER_NAME_EXPECTED = "Folder_1"
 assert(aFolder1.name() == FOLDER_NAME_EXPECTED), "Actual name '{}', expected '{}'".format(aFolder1.name(), FOLDER_NAME_EXPECTED)
 
@@ -86,17 +84,34 @@ assert(aFound[0].data().isEqual(aFolder1.data()))
 assert(aFound[1] == 0)
 
 #=========================================================================
-# Test 2. Add a point into a folder below
+# Test 2. Add a point, check it is added to a folder, then move it out
 #=========================================================================
 aPoint2 = newPoint(aPartDoc, 10., 0., 0.)
-aPoint3 = newPoint(aPartDoc, 10., 10., 0.)
 
-NB_FEATURES_FULL += 2
-NB_FEATURES_OUT += 2
+NB_FEATURES_FULL += 1
+assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
+assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
+
+fromFolder = FeatureList()
+fromFolder.append(aPoint2)
+
+aSession.startOperation()
+isMovedOut = aPartDoc.removeFromFolder(fromFolder)
+aSession.finishOperation()
+assert(isMovedOut)
 
+NB_FEATURES_OUT += 1
 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
 
+#=========================================================================
+# Test 3. Add a point into a folder below
+#=========================================================================
+aPoint3 = newPoint(aPartDoc, 10., 10., 0.)
+
+NB_FEATURES_FULL += 1
+NB_FEATURES_OUT += 1
+
 # add a folder
 aSession.startOperation()
 aFolder2 = aPartDoc.addFolder(aPoint3)
@@ -133,7 +148,7 @@ aFound = aPartDoc.findContainingFolder(aPoint3)
 assert(aFound == -1)
 
 #=========================================================================
-# Test 3. Add several points into a folder
+# Test 4. Add several points into a folder
 #=========================================================================
 aPoint4 = newPoint(aPartDoc, 0., 10., 0.)
 
@@ -201,9 +216,16 @@ aFound = aPartDoc.findContainingFolder(aPoint4)
 assert(aFound[0].data().isEqual(aFolder3.data()))
 assert(aFound[1] == 1)
 
+aPoint5 = newPoint(aPartDoc, 0., 0., 10.)
+fromFolder = FeatureList()
+fromFolder.append(aPoint5)
+
+aSession.startOperation()
+isMovedOut = aPartDoc.removeFromFolder(fromFolder)
+aSession.finishOperation()
+assert(isMovedOut)
 
 # add more points to the folder to move them out
-aPoint5 = newPoint(aPartDoc, 0., 0., 10.)
 aPoint6 = newPoint(aPartDoc, 10., 0., 10.)
 aPoint7 = newPoint(aPartDoc, 10., 10., 10.)
 aPoint8 = newPoint(aPartDoc, 0., 10., 10.)
@@ -235,7 +257,7 @@ assert(aFolder3.reference("first_feature").value() is not None)
 assert(aFolder3.reference("last_feature").value() is not None)
 
 #=========================================================================
-# Test 4. Remove a point from a folder before it
+# Test 5. Remove a point from a folder before it
 #=========================================================================
 fromFolder = FeatureList()
 fromFolder.append(aPoint3)
@@ -256,7 +278,7 @@ assert(aFolder3.reference("first_feature").value() is not None)
 assert(aFolder3.reference("last_feature").value() is not None)
 
 #=========================================================================
-# Test 5. Remove a point from a folder after it
+# Test 6. Remove a point from a folder after it
 #=========================================================================
 fromFolder = FeatureList()
 fromFolder.append(aPoint8)
@@ -277,7 +299,7 @@ assert(aFolder3.reference("first_feature").value() is not None)
 assert(aFolder3.reference("last_feature").value() is not None)
 
 #=========================================================================
-# Test 6. Try to remove several points which are not start nor end in a folder
+# Test 7. Try to remove several points which are not start nor end in a folder
 #=========================================================================
 fromFolder = FeatureList()
 fromFolder.append(aPoint5)
@@ -300,7 +322,7 @@ assert(aFolder3.reference("first_feature").value() is not None)
 assert(aFolder3.reference("last_feature").value() is not None)
 
 #=========================================================================
-# Test 7. Remove several points from a folder after it
+# Test 8. Remove several points from a folder after it
 #=========================================================================
 fromFolder = FeatureList()
 fromFolder.append(aPoint6)
@@ -324,7 +346,7 @@ assert(aFolder3.reference("first_feature").value() is not None)
 assert(aFolder3.reference("last_feature").value() is not None)
 
 #=========================================================================
-# Test 8. Remove all remaining points from a folder after it
+# Test 9. Remove all remaining points from a folder after it
 #=========================================================================
 fromFolder = FeatureList()
 fromFolder.append(aPoint4)
@@ -349,7 +371,10 @@ assert(aPartDoc.index(aPoint8, True) == 8), "Wrong index of the point: {}".forma
 # folder is empty
 assert(aFolder3.reference("first_feature").value() is None)
 assert(aFolder3.reference("last_feature").value() is None)
-
+# remove empty folder
+aSession.startOperation()
+aPartDoc.removeFolder(aFolder3)
+aSession.finishOperation()
 
 from salome.shaper import model
 assert(model.checkPythonDump())