From: azv Date: Fri, 24 Nov 2017 12:15:42 +0000 (+0300) Subject: Method to remove folder (Task 2.3. Ability to put consecutive Features in a folder) X-Git-Tag: V_2.10.0RC~123^2~18 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5495266766c85977f72b748cf674f0cf8b039a51;p=modules%2Fshaper.git Method to remove folder (Task 2.3. Ability to put consecutive Features in a folder) --- diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index 459fff166..92b57970c 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -1275,7 +1275,29 @@ std::shared_ptr Model_Objects::createFolder( void Model_Objects::removeFolder(std::shared_ptr theFolder) { - /// \todo + std::shared_ptr aData = std::static_pointer_cast(theFolder->data()); + if (!aData.get() || !aData->isValid()) + return; + + // this must be before erase since theFolder erasing removes all information about it + clearHistory(theFolder); + // erase fields + theFolder->erase(); + + TDF_Label aFolderLabel = aData->label().Father(); + if (myFolders.IsBound(aFolderLabel)) + myFolders.UnBind(aFolderLabel); + + static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY); + ModelAPI_EventCreator::get()->sendUpdated(theFolder, EVENT_DISP); + // erase all attributes under the label of feature + aFolderLabel.ForgetAllAttributes(); + // remove it from the references array + RemoveFromRefArray(featuresLabel(), aFolderLabel); + // event: feature is deleted + ModelAPI_EventCreator::get()->sendDeleted(theFolder->document(), ModelAPI_Folder::group()); + updateHistory(ModelAPI_Folder::group()); + updateHistory(ModelAPI_Feature::group()); } static FeaturePtr limitingFeature(std::list& theFeatures, const bool isLast) diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index 7bea51bbc..aa0b87e0c 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -191,5 +191,6 @@ ADD_UNIT_TESTS(TestConstants.py TestCustomName_Translation.py TestFolder_Create.py TestFolder_Update.py + TestFolder_Remove.py TestFolder_Stability.py ) diff --git a/src/ModelAPI/Test/TestFolder_Remove.py b/src/ModelAPI/Test/TestFolder_Remove.py new file mode 100644 index 000000000..6e78b581f --- /dev/null +++ b/src/ModelAPI/Test/TestFolder_Remove.py @@ -0,0 +1,154 @@ +## 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 +## + +#========================================================================= +# Initialization of the test +#========================================================================= +from ModelAPI import * + +__updated__ = "2017-11-24" + +aSession = ModelAPI_Session.get() + + +def newPoint(theDocument, theX, theY, theZ): + aSession.startOperation() + 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) + aPointData.string("creation_method").setValue("by_xyz") + aSession.finishOperation() + return aPoint + + +#========================================================================= +# Prepare some features and folders +#========================================================================= +aSession.startOperation() +aPart = aSession.moduleDocument().addFeature("Part") +aSession.finishOperation() + +# add points +aPartDoc = aSession.activeDocument() +aPoint1 = newPoint(aPartDoc, 0., 0., 0.) +aPoint2 = newPoint(aPartDoc, 10., 0., 0.) +aPoint3 = newPoint(aPartDoc, 10., 10., 0.) +aPoint4 = newPoint(aPartDoc, 0., 10., 0.) + +# add folders +aSession.startOperation() +aFolder1 = aPartDoc.addFolder(aPoint2) +aSession.finishOperation() +aSession.startOperation() +aFolder2 = aPartDoc.addFolder(aPoint2) +aSession.finishOperation() +aSession.startOperation() +aFolder3 = aPartDoc.addFolder(aPoint3) +aSession.finishOperation() + +# place points into folders +toFolder = FeatureList() +toFolder.append(aPoint1) + +aSession.startOperation() +aFolder = aPartDoc.findFolderBelow(toFolder) +assert(aFolder is not None) +isAdded = aPartDoc.moveToFolder(toFolder, aFolder) +aSession.finishOperation() +assert(isAdded) + +toFolder = FeatureList() +toFolder.append(aPoint3) +toFolder.append(aPoint4) + +aSession.startOperation() +aFolder = aPartDoc.findFolderAbove(toFolder) +assert(aFolder is not None) +isAdded = aPartDoc.moveToFolder(toFolder, aFolder) +aSession.finishOperation() +assert(isAdded) + +NB_FEATURES_FULL = 7 +NB_FEATURES_OUT = 4 + +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) + +assert(aPartDoc.index(aFolder1, True) == 0), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder1, True)) +assert(aPartDoc.index(aFolder2, True) == 1), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder2, True)) +assert(aPartDoc.index(aFolder3, True) == 3), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True)) + +assert(aPartDoc.index(aPoint1, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint1, True)) +assert(aPartDoc.index(aPoint2, True) == 2), "Wrong index of the point: {}".format(aPartDoc.index(aPoint2, True)) +assert(aPartDoc.index(aPoint3, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint3, True)) +assert(aPartDoc.index(aPoint4, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True)) + + +#========================================================================= +# Test 1. Remove empty folder +#========================================================================= +aSession.startOperation() +aPartDoc.removeFolder(aFolder2) +aSession.finishOperation() + +NB_FEATURES_FULL -= 1 +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) + +assert(aPartDoc.index(aFolder1, True) == 0), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder1, True)) +assert(aPartDoc.index(aFolder2, True) == -1), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder2, True)) +assert(aPartDoc.index(aFolder3, True) == 2), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True)) + +assert(aPartDoc.index(aPoint1, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint1, True)) +assert(aPartDoc.index(aPoint2, True) == 1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint2, True)) +assert(aPartDoc.index(aPoint3, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint3, True)) +assert(aPartDoc.index(aPoint4, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True)) + + +#========================================================================= +# Test 2. Remove non-empty folder +#========================================================================= +aSession.startOperation() +aPartDoc.removeFolder(aFolder3) +aSession.finishOperation() + +NB_FEATURES_FULL -= 1 +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) + +assert(aPartDoc.index(aFolder1, True) == 0), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder1, True)) +assert(aPartDoc.index(aFolder2, True) == -1), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder2, True)) +assert(aPartDoc.index(aFolder3, True) == -1), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True)) + +assert(aPartDoc.index(aPoint1, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint1, True)) +assert(aPartDoc.index(aPoint2, True) == 1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint2, True)) +assert(aPartDoc.index(aPoint3, True) == 2), "Wrong index of the point: {}".format(aPartDoc.index(aPoint3, True)) +assert(aPartDoc.index(aPoint4, True) == 3), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True)) + + +from salome.shaper import model +assert(model.checkPythonDump())