isSameName = (*aRIter)->data()->name() == aName;
}
}
+ // for new Parts create names that are not in the Postponed list
+ if (!isSameName && (theFeature->getKind() == "Part" || theFeature->getKind() == "Duplicate")) {
+ std::shared_ptr<Model_Session> aSession =
+ std::dynamic_pointer_cast<Model_Session>(Model_Session::get());
+ isSameName = aSession->isLoadByDemand(aName) || aSession->hasDocument(aName);
+ }
+
if (isSameName) {
aNumObjects++;
std::stringstream aNameStream;
std::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->document(DOC_REF());
+ // activation may cause changes in current features in document, so it must be in transaction
+ bool isNewTransaction = false;
+ SessionPtr aMgr = ModelAPI_Session::get();
if (!aDocRef->value().get()) { // create (or open) a document if it is not yet created
myIsInLoad = true;
+ if (!aMgr->isOperation()) {
+ aMgr->startOperation("Activation");
+ isNewTransaction = true;
+ }
std::shared_ptr<ModelAPI_Document> aDoc = document()->subDocument(data()->name());
myIsInLoad = false;
if (aDoc) {
}
}
if (aDocRef->value().get()) {
- SessionPtr aMgr = ModelAPI_Session::get();
- bool isNewTransaction = !aMgr->isOperation();
- // activation may cause changes in current features in document, so it must be in transaction
- if (isNewTransaction) {
- aMgr->startOperation("Activation");
- }
ModelAPI_Session::get()->setActiveDocument(aDocRef->value());
- if (isNewTransaction) {
- aMgr->finishOperation();
- }
+ }
+ if (isNewTransaction) {
+ aMgr->finishOperation();
}
}
(new Events_Message(Events_Loop::eventByName("StartOperation")));
Events_Loop::loop()->send(aStartedMsg);
// remove all useless documents that has been closed: on start of operation undo/redo is cleared
- std::list<std::shared_ptr<ModelAPI_Document> > aUsedDocs = allOpenedDocuments();
- Model_Application::getApplication()->removeUselessDocuments(aUsedDocs);
+ // MPV: this code is dangerous now because it may close the document that is activated right now
+ // but not in the list of the opened documents yet (create, delete, undo, activate Part)
+ // later this must be updated by correct usage of uniques IDs of documents, not names of results
+ //std::list<std::shared_ptr<ModelAPI_Document> > aUsedDocs = allOpenedDocuments();
+ //Model_Application::getApplication()->removeUselessDocuments(aUsedDocs);
}
void Model_Session::finishOperation()
return Model_Application::getApplication()->hasDocument("root");
}
+bool Model_Session::hasDocument(std::string theDocID)
+{
+ return Model_Application::getApplication()->hasDocument(theDocID);
+}
+
std::shared_ptr<ModelAPI_Document> Model_Session::activeDocument()
{
if (!myCurrentDoc || !Model_Application::getApplication()->hasDocument(myCurrentDoc->id()))
/// Returns the document by ID, loads if not loaded yet. Returns null if no such document.
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> document(std::string theDocID);
+ /// Return true if document with such ID has been already created
+ MODEL_EXPORT virtual bool hasDocument(std::string theDocID);
/// Return true if root document has been already created
MODEL_EXPORT virtual bool hasModuleDocument();