}
//=======================================================================
-void Model_Application::setLoadByDemand(std::string theID)
+void Model_Application::setLoadByDemand(std::string theID, const int theDocID)
{
- myLoadedByDemand.insert(theID);
+ myLoadedByDemand[theID] = theDocID;
}
//=======================================================================
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<std::string, int>::iterator aLBDIter = myLoadedByDemand.begin();
+ for(; aLBDIter != myLoadedByDemand.end(); aLBDIter++) {
+ if (aLBDIter->second == aResult) {
+ aFound = true;
+ break;
+ }
+ }
+ if (!aFound) break;
+ }
+ }
return aResult;
}
//! 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
std::map<int, std::shared_ptr<Model_Document> > myDocs;
/// Path for the loaded by demand documents
std::string myPath;
- /// Path for the loaded by demand documents
- std::set<std::string> myLoadedByDemand;
+ /// Path for the loaded by demand documents (and the persistent ID as the value)
+ std::map<std::string, int> myLoadedByDemand;
};
#endif
for(; aPartRes != aPartResults.end(); aPartRes++) {
ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*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
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<ModelAPI_Document> Model_ResultPart::partDoc()