- std::set<std::string>::iterator aSubIter = mySubs.begin();
- for (; aSubIter != mySubs.end(); aSubIter++)
- subDoc(*aSubIter)->close();
- mySubs.clear();
- // close this only if it is module document, otherwise it can be undoed
- if (this == aPM->moduleDocument().get()) {
+ const std::set<std::string> aSubs = subDocuments(true);
+ std::set<std::string>::iterator aSubIter = aSubs.begin();
+ for (; aSubIter != aSubs.end(); aSubIter++)
+ subDoc(*aSubIter)->close(theForever);
+
+ // close for thid document needs no transaction in this document
+ std::static_pointer_cast<Model_Session>(Model_Session::get())->setCheckTransactions(false);
+
+ // delete all features of this document
+ std::shared_ptr<ModelAPI_Document> aThis =
+ Model_Application::getApplication()->getDocument(myID);
+ Events_Loop* aLoop = Events_Loop::loop();
+ NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFeaturesIter(myObjs);
+ for(; aFeaturesIter.More(); aFeaturesIter.Next()) {
+ FeaturePtr aFeature = aFeaturesIter.Value();
+ static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ ModelAPI_EventCreator::get()->sendDeleted(aThis, ModelAPI_Feature::group());
+ ModelAPI_EventCreator::get()->sendUpdated(aFeature, EVENT_DISP);
+ aFeature->eraseResults();
+ if (theForever) { // issue #294: do not delete content of the document until it can be redone
+ aFeature->erase();
+ } else {
+ aFeature->data()->execState(ModelAPI_StateMustBeUpdated);
+ }
+ }
+ if (theForever) {
+ myObjs.Clear();
+ }
+ aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
+ aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+
+ // close all only if it is really asked, otherwise it can be undoed/redoed
+ if (theForever) {