From: azv Date: Fri, 24 Nov 2017 05:23:03 +0000 (+0300) Subject: Do not store out-of-folder history for the features which cannot be placed in folders X-Git-Tag: V_2.10.0RC~123^2~25 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=dbf57e009e52c6d8eeb093b120d7379a5d586c26;p=modules%2Fshaper.git Do not store out-of-folder history for the features which cannot be placed in folders --- diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index 104ec2b1d..452b202b9 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -53,13 +53,9 @@ static const std::string& groupNameFoldering(const std::string& theGroupID, const bool theAllowFolder) { if (theAllowFolder) { - static std::map aNames; - std::map::const_iterator aFound = aNames.find(theGroupID); - if (aFound == aNames.end()) { - aNames[theGroupID] = std::string("__") + theGroupID; - aFound = aNames.find(theGroupID); - } - return aFound->second; + static const std::string anOutOfFolderName = std::string("__") + ModelAPI_Feature::group(); + static const std::string aDummyName; + return theGroupID == ModelAPI_Feature::group() ? anOutOfFolderName : aDummyName; } return theGroupID; } @@ -416,6 +412,7 @@ void Model_Objects::createHistory(const std::string& theGroupID) FeaturePtr aLastFeatureInFolder; // iterate the array of references and get feature by feature from the array bool isFeature = theGroupID == ModelAPI_Feature::group(); + bool isFolder = theGroupID == ModelAPI_Folder::group(); Handle(TDataStd_ReferenceArray) aRefs; if (featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) { for(int a = aRefs->Lower(); a <= aRefs->Upper(); a++) { @@ -456,9 +453,12 @@ void Model_Objects::createHistory(const std::string& theGroupID) // it may be a folder ObjectPtr aFolder = folder(aRefs->Value(a)); if (aFolder.get()) { - aResult.push_back(aFolder); - if (theGroupID != ModelAPI_Folder::group()) - aResultOutOfFolder.push_back(aFolder); + // store folder information for the Features group only + if (isFeature || isFolder) { + aResult.push_back(aFolder); + if (!isFolder) + aResultOutOfFolder.push_back(aFolder); + } // get the last feature in the folder AttributeReferencePtr aLastFeatAttr = @@ -475,7 +475,8 @@ void Model_Objects::createHistory(const std::string& theGroupID) // store the features placed out of any folder const std::string& anOutOfFolderGroupID = groupNameFoldering(theGroupID, true); - myHistory[anOutOfFolderGroupID] = aResultOutOfFolder; + if (!anOutOfFolderGroupID.empty()) + myHistory[anOutOfFolderGroupID] = aResultOutOfFolder; } } } @@ -493,7 +494,8 @@ void Model_Objects::updateHistory(const std::string theGroup) // erase history for the group of objects placed out of any folder const std::string& anOutOfFolderGroupID = groupNameFoldering(theGroup, true); - myHistory.erase(anOutOfFolderGroupID); + if (!anOutOfFolderGroupID.empty()) + myHistory.erase(anOutOfFolderGroupID); } } @@ -562,7 +564,7 @@ ObjectPtr Model_Objects::object(const std::string& theGroupID, return ObjectPtr(); createHistory(theGroupID); const std::string& aGroupID = groupNameFoldering(theGroupID, theAllowFolder); - return myHistory[aGroupID][theIndex]; + return aGroupID.empty() ? myHistory[theGroupID][theIndex] : myHistory[aGroupID][theIndex]; } std::shared_ptr Model_Objects::objectByName( @@ -624,7 +626,7 @@ int Model_Objects::size(const std::string& theGroupID, const bool theAllowFolder { createHistory(theGroupID); const std::string& aGroupID = groupNameFoldering(theGroupID, theAllowFolder); - return int(myHistory[aGroupID].size()); + return aGroupID.empty() ? int(myHistory[theGroupID].size()) : int(myHistory[aGroupID].size()); } void Model_Objects::allResults(const std::string& theGroupID, std::list& theResults) diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index a5a864cf4..7bea51bbc 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -191,4 +191,5 @@ ADD_UNIT_TESTS(TestConstants.py TestCustomName_Translation.py TestFolder_Create.py TestFolder_Update.py + TestFolder_Stability.py ) diff --git a/src/ModelAPI/Test/TestFolder_Stability.py b/src/ModelAPI/Test/TestFolder_Stability.py new file mode 100644 index 000000000..9ceb2ee3e --- /dev/null +++ b/src/ModelAPI/Test/TestFolder_Stability.py @@ -0,0 +1,74 @@ +## 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 +## + +#========================================================================= +# Test checks stability of the foldering mechanism due to incorrect input parameters +#========================================================================= +from ModelAPI import * + +__updated__ = "2017-11-23" + +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 + + +#========================================================================= +# Initialization of the model +#========================================================================= +aSession.startOperation() +aPart = aSession.moduleDocument().addFeature("Part") +aSession.finishOperation() + +# add point and a folder before it +aPartDoc = aSession.activeDocument() +aPoint1 = newPoint(aPartDoc, 0., 0., 0.) + +aSession.startOperation() +aFolder1 = aPartDoc.addFolder(aPoint1) +aSession.finishOperation() + +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") == NB_FEATURES_FULL), "Wrong number of features: {}".format(aPartDoc.size("Features")) + +#========================================================================= +# Test 1. Check number of features out of folder +# and absense of the crash while getting size of incorrect groupd +#========================================================================= +assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT) +assert(aPartDoc.size("Construction", True) == 1), "Wrong size: {}".format(aPartDoc.size("Construction", True)) + + +from salome.shaper import model +assert(model.checkPythonDump())