+ return myLoadedByDemand.find(theID) != myLoadedByDemand.end() &&
+ myLoadedByDemand[theID] == theDocIndex;
+}
+
+//=======================================================================
+void Model_Application::removeUselessDocuments(
+ std::list<std::shared_ptr<ModelAPI_Document> > theUsedDocs)
+{
+ std::map<int, std::shared_ptr<Model_Document> >::iterator aDoc = myDocs.begin();
+ while(aDoc != myDocs.end()) {
+ bool aFound = false;
+ std::list<std::shared_ptr<ModelAPI_Document> >::iterator aUsed = theUsedDocs.begin();
+ for(; !aFound && aUsed != theUsedDocs.end(); aUsed++) {
+ aFound = aDoc->second == *aUsed;
+ }
+ if (!aFound) { // remove the useless
+ aDoc->second->close();
+ myDocs.erase(aDoc);
+ aDoc = myDocs.begin();
+ } else {
+ aDoc++;
+ }
+ }
+}
+
+int Model_Application::generateDocumentId()
+{
+ 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;