void Model_Application::deleteDocument(string theDocID)
{
- myDocs.erase(theDocID);
+ if (myDocs.find(theDocID) != myDocs.end()) {
+ myDocs[theDocID]->close(true);
+ myDocs.erase(theDocID);
+ }
+ myLoadedByDemand.clear();
+}
+
+void Model_Application::deleteAllDocuments()
+{
+ myDocs.clear();
+ myLoadedByDemand.clear();
}
//=======================================================================
MODEL_EXPORT bool hasDocument(std::string theDocID);
//! Deletes the document from the application
MODEL_EXPORT void deleteDocument(std::string theDocID);
+ //! Deletes all documents existing in the application
+ MODEL_EXPORT void deleteAllDocuments();
//! Set path for the loaded by demand documents
void setLoadPath(std::string thePath);
return isDone;
}
-void Model_Document::close()
+void Model_Document::close(const bool theForever)
{
boost::shared_ptr<ModelAPI_Session> aPM = Model_Session::get();
if (this != aPM->moduleDocument().get() && this == aPM->activeDocument().get()) {
// close all subs
std::set<std::string>::iterator aSubIter = mySubs.begin();
for (; aSubIter != mySubs.end(); aSubIter++)
- subDoc(*aSubIter)->close();
+ subDoc(*aSubIter)->close(theForever);
mySubs.clear();
- // close this only if it is module document, otherwise it can be undoed
- if (this == aPM->moduleDocument().get()) {
+
+ // close for thid document needs no transaction in this document
+ boost::static_pointer_cast<Model_Session>(Model_Session::get())->setCheckTransactions(false);
+
+ // delete all features of this document
+ boost::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();
+ aFeature->erase();
+ }
+ 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) {
if (myDoc->CanClose() == CDM_CCS_OK)
myDoc->Close();
- Model_Application::getApplication()->deleteDocument(myID);
}
+
+ boost::static_pointer_cast<Model_Session>(Model_Session::get())->setCheckTransactions(true);
}
void Model_Document::startOperation()
for (; aLabIter.More(); aLabIter.Next()) {
TDF_Label aFLabel = aLabIter.Value()->Label();
FeaturePtr aFeature = feature(aFLabel);
+ if (!aFeature) // may be on close
+ continue;
const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
for (; aRIter != aResults.cend(); aRIter++) {
MODEL_EXPORT virtual bool save(const char* theFileName, std::list<std::string>& theResults);
//! Removes document data
- MODEL_EXPORT virtual void close();
+ //! \param theForever if it is false, document is just hiden (to keep possibility make it back on Undo/Redo)
+ MODEL_EXPORT virtual void close(const bool theForever = false);
//! Starts a new operation (opens a tansaction)
MODEL_EXPORT virtual void startOperation();
return ROOT_DOC->save(theFileName, theResults);
}
+void Model_Session::closeAll()
+{
+ ROOT_DOC->close(true);
+ Model_Application::getApplication()->deleteAllDocuments();
+}
+
void Model_Session::startOperation()
{
ROOT_DOC->startOperation();
//! \returns true if file was stored successfully
MODEL_EXPORT virtual bool save(const char* theFileName, std::list<std::string>& theResults);
+ //! Closes all documents
+ MODEL_EXPORT virtual void closeAll();
+
//! Starts a new operation (opens a tansaction)
MODEL_EXPORT virtual void startOperation();
//! Finishes the previously started operation (closes the transaction)
virtual const std::string& kind() const = 0;
//! Removes document data
- virtual void close() = 0;
+ //! \param theForever if it is false, document is just hiden (to keep possibility make it back on Undo/Redo)
+ virtual void close(const bool theForever = false) = 0;
//! Adds to the document the new feature of the given feature id
//! \param creates feature and puts it in the document (if it is not action)
//! \returns true if file was stored successfully
virtual bool save(const char* theFileName, std::list<std::string>& theResults) = 0;
+ //! Closes all documents
+ virtual void closeAll() = 0;
+
//! Starts a new operation (opens a tansaction)
virtual void startOperation() = 0;
//! Finishes the previously started operation (closes the transaction)
DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId);
ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
- return aPart->partDoc();
+ if (aPart)
+ return aPart->partDoc();
+ return DocumentPtr(); // null if not found
}
ObjectPtr XGUI_PartDataModel::object(const QModelIndex& theIndex) const
} else if (anAnswer == QMessageBox::Cancel) {
return;
}
- aSession->moduleDocument()->close();
+ aSession->closeAll();
myCurrentDir = "";
}
objectBrowser()->clearContent();
SessionPtr aMgr = ModelAPI_Session::get();
- aMgr->moduleDocument()->close();
+ aMgr->closeAll();
objectBrowser()->clearContent();
}