From: mpv Date: Wed, 22 Mar 2017 14:44:51 +0000 (+0300) Subject: Fix for the issue #2020 : take into account not yet loaded documents to generate... X-Git-Tag: V_2.7.0~200 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9081107c3a1a164f3674194adb59d55320ee7e66;p=modules%2Fshaper.git Fix for the issue #2020 : take into account not yet loaded documents to generate a new document persistent ID. --- diff --git a/src/Model/Model_Application.cpp b/src/Model/Model_Application.cpp index 50fa75c04..e6170af5c 100644 --- a/src/Model/Model_Application.cpp +++ b/src/Model/Model_Application.cpp @@ -116,9 +116,9 @@ const std::string& Model_Application::loadPath() const } //======================================================================= -void Model_Application::setLoadByDemand(std::string theID) +void Model_Application::setLoadByDemand(std::string theID, const int theDocID) { - myLoadedByDemand.insert(theID); + myLoadedByDemand[theID] = theDocID; } //======================================================================= @@ -150,8 +150,21 @@ void Model_Application::removeUselessDocuments( int Model_Application::generateDocumentId() { - int aResult = int(myDocs.size()); - for(; myDocs.find(aResult) != myDocs.end(); aResult++) {} // count until the result id is unique + int aResult; + // count until the result id is unique + for(aResult = int(myDocs.size()); true; aResult++) { + if (myDocs.find(aResult) == myDocs.end()) { + bool aFound = false; + std::map::iterator aLBDIter = myLoadedByDemand.begin(); + for(; aLBDIter != myLoadedByDemand.end(); aLBDIter++) { + if (aLBDIter->second == aResult) { + aFound = true; + break; + } + } + if (!aFound) break; + } + } return aResult; } diff --git a/src/Model/Model_Application.h b/src/Model/Model_Application.h index 492326dc3..f1ca5af06 100644 --- a/src/Model/Model_Application.h +++ b/src/Model/Model_Application.h @@ -61,7 +61,7 @@ public: //! Returns the path for the loaded by demand documents const std::string& loadPath() const; //! Defines that specified document must be loaded by demand - void setLoadByDemand(std::string theID); + void setLoadByDemand(std::string theID, const int theDocID); //! Returns true if specified document must be loaded by demand bool isLoadByDemand(std::string theID); //! Closes and removes the documents that are not loaded by demand and @@ -88,8 +88,8 @@ public: std::map > myDocs; /// Path for the loaded by demand documents std::string myPath; - /// Path for the loaded by demand documents - std::set myLoadedByDemand; + /// Path for the loaded by demand documents (and the persistent ID as the value) + std::map myLoadedByDemand; }; #endif diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index d4e7b2d23..ce8386a2e 100755 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -222,7 +222,8 @@ bool Model_Document::load(const char* theDirName, const char* theFileName, Docum for(; aPartRes != aPartResults.end(); aPartRes++) { ResultPartPtr aPart = std::dynamic_pointer_cast(*aPartRes); if (aPart.get()) - anApp->setLoadByDemand(aPart->data()->name()); + anApp->setLoadByDemand(aPart->data()->name(), + aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->docId()); } } else { // open failed, but new documnet was created to work with it: inform the model diff --git a/src/Model/Model_ResultPart.cpp b/src/Model/Model_ResultPart.cpp index 93830df44..d06786869 100644 --- a/src/Model/Model_ResultPart.cpp +++ b/src/Model/Model_ResultPart.cpp @@ -43,7 +43,7 @@ void Model_ResultPart::initAttributes() if (aDocRef->isInitialized() && // initialized immideately means already exist and will be loaded !Model_Application::getApplication()->hasDocument(aDocRef->docId())) - Model_Application::getApplication()->setLoadByDemand(data()->name()); + Model_Application::getApplication()->setLoadByDemand(data()->name(), aDocRef->docId()); } std::shared_ptr Model_ResultPart::partDoc()