From 7b76b534d04e5d50f1ad319e58e0e22c6bb742a3 Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 11 Sep 2014 15:00:19 +0400 Subject: [PATCH] Issue #83: rename and transfer some methods related to document --- src/Model/Model_Data.cpp | 5 -- src/Model/Model_Document.cpp | 44 +++++++----- src/Model/Model_Document.h | 3 + src/Model/Model_ResultPart.cpp | 2 +- src/Model/Model_Session.cpp | 70 +++++++++++++++++-- src/Model/Model_Session.h | 41 +++++++++-- src/ModelAPI/ModelAPI_Document.h | 34 +-------- src/ModelAPI/ModelAPI_Feature.cpp | 2 +- src/ModelAPI/ModelAPI_Session.h | 41 +++++++++-- src/ModuleBase/ModuleBase_IOperation.cpp | 8 +-- src/PartSet/PartSet_TestOCC.cpp | 2 +- src/PartSet/PartSet_Tools.cpp | 2 +- src/PartSetPlugin/PartSetPlugin_Duplicate.cpp | 4 +- src/PartSetPlugin/PartSetPlugin_Part.cpp | 4 +- src/PartSetPlugin/PartSetPlugin_Remove.cpp | 4 +- src/XGUI/XGUI_ContextMenuMgr.cpp | 4 +- src/XGUI/XGUI_DocumentDataModel.cpp | 12 ++-- src/XGUI/XGUI_ObjectsBrowser.cpp | 8 +-- src/XGUI/XGUI_PartDataModel.cpp | 26 +++---- src/XGUI/XGUI_Workshop.cpp | 51 ++++++-------- 20 files changed, 230 insertions(+), 137 deletions(-) diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 5dba72cbd..b384b49d7 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -52,11 +52,6 @@ void Model_Data::setName(const std::string& theName) if (isModified) aName->Set(theName.c_str()); } - // to do not cause the update of the result on name change - /*if (isModified) { - static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); - ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent, false); - }*/ } void Model_Data::addAttribute(const std::string& theID, const std::string theAttrType) diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index b66318687..11a7eaa20 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -74,7 +74,7 @@ static TCollection_ExtendedString DocFileName(const char* theFileName, const std bool Model_Document::load(const char* theFileName) { Handle(Model_Application) anApp = Model_Application::getApplication(); - if (this == Model_Session::get()->rootDocument().get()) { + if (this == Model_Session::get()->moduleDocument().get()) { anApp->setLoadPath(theFileName); } TCollection_ExtendedString aPath(DocFileName(theFileName, myID)); @@ -151,7 +151,7 @@ bool Model_Document::load(const char* theFileName) bool Model_Document::save(const char* theFileName, std::list& theResults) { // create a directory in the root document if it is not yet exist - if (this == Model_Session::get()->rootDocument().get()) { + if (this == Model_Session::get()->moduleDocument().get()) { #ifdef WIN32 CreateDirectory(theFileName, NULL); #else @@ -188,8 +188,9 @@ bool Model_Document::save(const char* theFileName, std::list& theRe if (isDone) { // save also sub-documents if any theResults.push_back(TCollection_AsciiString(aPath).ToCString()); std::set::iterator aSubIter = mySubs.begin(); - for (; aSubIter != mySubs.end() && isDone; aSubIter++) - isDone = subDocument(*aSubIter)->save(theFileName, theResults); + for (; aSubIter != mySubs.end() && isDone; aSubIter++) { + isDone = subDoc(*aSubIter)->save(theFileName, theResults); + } } return isDone; } @@ -197,13 +198,13 @@ bool Model_Document::save(const char* theFileName, std::list& theRe void Model_Document::close() { boost::shared_ptr aPM = Model_Session::get(); - if (this != aPM->rootDocument().get() && this == aPM->currentDocument().get()) { - aPM->setCurrentDocument(aPM->rootDocument()); + if (this != aPM->moduleDocument().get() && this == aPM->activeDocument().get()) { + aPM->setActiveDocument(aPM->moduleDocument()); } // close all subs std::set::iterator aSubIter = mySubs.begin(); for (; aSubIter != mySubs.end(); aSubIter++) - subDocument(*aSubIter)->close(); + subDoc(*aSubIter)->close(); mySubs.clear(); // close this /* do not close because it can be undoed @@ -229,7 +230,7 @@ void Model_Document::startOperation() // new command for all subs std::set::iterator aSubIter = mySubs.begin(); for (; aSubIter != mySubs.end(); aSubIter++) - subDocument(*aSubIter)->startOperation(); + subDoc(*aSubIter)->startOperation(); } void Model_Document::compactNested() @@ -280,7 +281,7 @@ void Model_Document::finishOperation() // finish for all subs std::set::iterator aSubIter = mySubs.begin(); for (; aSubIter != mySubs.end(); aSubIter++) - subDocument(*aSubIter)->finishOperation(); + subDoc(*aSubIter)->finishOperation(); } void Model_Document::abortOperation() @@ -302,7 +303,7 @@ void Model_Document::abortOperation() // abort for all subs std::set::iterator aSubIter = mySubs.begin(); for (; aSubIter != mySubs.end(); aSubIter++) - subDocument(*aSubIter)->abortOperation(); + subDoc(*aSubIter)->abortOperation(); } bool Model_Document::isOperation() @@ -314,7 +315,7 @@ bool Model_Document::isOperation() bool Model_Document::isModified() { // is modified if at least one operation was commited and not undoed - return myTransactionsAfterSave > 0; + return myTransactionsAfterSave > 0 || isOperation(); } bool Model_Document::canUndo() @@ -325,7 +326,7 @@ bool Model_Document::canUndo() // check other subs contains operation that can be undoed std::set::iterator aSubIter = mySubs.begin(); for (; aSubIter != mySubs.end(); aSubIter++) - if (subDocument(*aSubIter)->canUndo()) + if (subDoc(*aSubIter)->canUndo()) return true; return false; } @@ -341,7 +342,7 @@ void Model_Document::undo() // undo for all subs std::set::iterator aSubIter = mySubs.begin(); for (; aSubIter != mySubs.end(); aSubIter++) - subDocument(*aSubIter)->undo(); + subDoc(*aSubIter)->undo(); } bool Model_Document::canRedo() @@ -351,7 +352,7 @@ bool Model_Document::canRedo() // check other subs contains operation that can be redoed std::set::iterator aSubIter = mySubs.begin(); for (; aSubIter != mySubs.end(); aSubIter++) - if (subDocument(*aSubIter)->canRedo()) + if (subDoc(*aSubIter)->canRedo()) return true; return false; } @@ -367,7 +368,7 @@ void Model_Document::redo() // redo for all subs std::set::iterator aSubIter = mySubs.begin(); for (; aSubIter != mySubs.end(); aSubIter++) - subDocument(*aSubIter)->redo(); + subDoc(*aSubIter)->redo(); } /// Appenad to the array of references a new referenced label @@ -514,6 +515,15 @@ boost::shared_ptr Model_Document::subDocument(std::string the return Model_Application::getApplication()->getDocument(theDocID); } +boost::shared_ptr Model_Document::subDoc(std::string theDocID) +{ + // just store sub-document identifier here to manage it later + if (mySubs.find(theDocID) == mySubs.end()) + mySubs.insert(theDocID); + return boost::dynamic_pointer_cast( + Model_Application::getApplication()->getDocument(theDocID)); +} + ObjectPtr Model_Document::object(const std::string& theGroupID, const int theIndex, const bool theHidden) { @@ -863,8 +873,8 @@ void Model_Document::updateResults(FeaturePtr theFeature) aNewBody = createBody(theFeature->data(), aResIndex); } else if (anArgLab.IsAttribute(ID_PART)) { aNewBody = createPart(theFeature->data(), aResIndex); - } else if (!anArgLab.IsAttribute(ID_CONSTRUCTION)) { - Events_Error::send("Unknown type of result if found in the document"); + } else if (!anArgLab.IsAttribute(ID_CONSTRUCTION) && anArgLab.FindChild(1).HasAttribute()) { + Events_Error::send("Unknown type of result is found in the document"); } if (aNewBody) { theFeature->setResult(aNewBody, aResIndex); diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 7024925ed..598c3b633 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -86,6 +86,9 @@ class Model_Document : public ModelAPI_Document //! Adds a new sub-document by the identifier, or returns existing one if it is already exist MODEL_EXPORT virtual boost::shared_ptr subDocument(std::string theDocID); + //! Internal sub-document by ID + MODEL_EXPORT virtual boost::shared_ptr subDoc(std::string theDocID); + ///! Returns the id of hte document MODEL_EXPORT virtual const std::string& id() const { diff --git a/src/Model/Model_ResultPart.cpp b/src/Model/Model_ResultPart.cpp index 6d1afbf48..6767ffee6 100644 --- a/src/Model/Model_ResultPart.cpp +++ b/src/Model/Model_ResultPart.cpp @@ -40,5 +40,5 @@ void Model_ResultPart::activate() } } if (aDocRef->value()) - ModelAPI_Session::get()->setCurrentDocument(aDocRef->value()); + ModelAPI_Session::get()->setActiveDocument(aDocRef->value()); } diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 730b6eca2..6f334290c 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -25,6 +25,64 @@ using namespace std; static Model_Session* myImpl = new Model_Session(); +// t oredirect all calls to the root document +#define ROOT_DOC boost::dynamic_pointer_cast(moduleDocument()) + +bool Model_Session::load(const char* theFileName) +{ + return ROOT_DOC->load(theFileName); +} + +bool Model_Session::save(const char* theFileName, std::list& theResults) +{ + return ROOT_DOC->save(theFileName, theResults); +} + +void Model_Session::startOperation() +{ + ROOT_DOC->startOperation(); +} + +void Model_Session::finishOperation() +{ + ROOT_DOC->finishOperation(); +} + +void Model_Session::abortOperation() +{ + ROOT_DOC->abortOperation(); +} + +bool Model_Session::isOperation() +{ + return ROOT_DOC->isOperation(); +} + +bool Model_Session::isModified() +{ + return ROOT_DOC->isModified(); +} + +bool Model_Session::canUndo() +{ + return ROOT_DOC->canUndo(); +} + +void Model_Session::undo() +{ + ROOT_DOC->undo(); +} + +bool Model_Session::canRedo() +{ + return ROOT_DOC->canRedo(); +} + +void Model_Session::redo() +{ + ROOT_DOC->redo(); +} + FeaturePtr Model_Session::createFeature(string theFeatureID) { if (this != myImpl) @@ -55,25 +113,25 @@ FeaturePtr Model_Session::createFeature(string theFeatureID) return FeaturePtr(); // return nothing } -boost::shared_ptr Model_Session::rootDocument() +boost::shared_ptr Model_Session::moduleDocument() { return boost::shared_ptr( Model_Application::getApplication()->getDocument("root")); } -bool Model_Session::hasRootDocument() +bool Model_Session::hasModuleDocument() { return Model_Application::getApplication()->hasDocument("root"); } -boost::shared_ptr Model_Session::currentDocument() +boost::shared_ptr Model_Session::activeDocument() { if (!myCurrentDoc || !Model_Application::getApplication()->hasDocument(myCurrentDoc->id())) - myCurrentDoc = rootDocument(); + myCurrentDoc = moduleDocument(); return myCurrentDoc; } -void Model_Session::setCurrentDocument(boost::shared_ptr theDoc) +void Model_Session::setActiveDocument(boost::shared_ptr theDoc) { myCurrentDoc = theDoc; static Events_Message aMsg(Events_Loop::eventByName("CurrentDocumentChanged")); @@ -141,7 +199,7 @@ void Model_Session::processEvent(const Events_Message* theMessage) } } } else { // create/update/delete - if (myCheckTransactions && !rootDocument()->isOperation()) + if (myCheckTransactions && !isOperation()) Events_Error::send("Modification of data structure outside of the transaction"); } } diff --git a/src/Model/Model_Session.h b/src/Model/Model_Session.h index cc1494a13..5ee656025 100644 --- a/src/Model/Model_Session.h +++ b/src/Model/Model_Session.h @@ -30,17 +30,50 @@ class Model_Session : public ModelAPI_Session, public Events_Listener boost::shared_ptr myCurrentDoc; ///< current working document bool myCheckTransactions; ///< if true, generates error if document is updated outside of transaction public: + + //! Loads the OCAF document from the file. + //! \param theFileName full name of the file to load + //! \param theStudyID identifier of the SALOME study to associate with loaded file + //! \returns true if file was loaded successfully + MODEL_EXPORT virtual bool load(const char* theFileName); + + //! Saves the OCAF document to the file. + //! \param theFileName full name of the file to store + //! \param theResults the result full file names that were stored by "save" + //! \returns true if file was stored successfully + MODEL_EXPORT virtual bool save(const char* theFileName, std::list& theResults); + + //! Starts a new operation (opens a tansaction) + MODEL_EXPORT virtual void startOperation(); + //! Finishes the previously started operation (closes the transaction) + MODEL_EXPORT virtual void finishOperation(); + //! Aborts the operation + MODEL_EXPORT virtual void abortOperation(); + //! Returns true if operation has been started, but not yet finished or aborted + MODEL_EXPORT virtual bool isOperation(); + //! Returns true if document was modified (since creation/opening) + MODEL_EXPORT virtual bool isModified(); + + //! Returns True if there are available Undos + MODEL_EXPORT virtual bool canUndo(); + //! Undoes last operation + MODEL_EXPORT virtual void undo(); + //! Returns True if there are available Redos + MODEL_EXPORT virtual bool canRedo(); + //! Redoes last operation + MODEL_EXPORT virtual void redo(); + /// Returns the root document of the application (that may contains sub-documents) - MODEL_EXPORT virtual boost::shared_ptr rootDocument(); + MODEL_EXPORT virtual boost::shared_ptr moduleDocument(); /// Return true if root document has been already created - MODEL_EXPORT virtual bool hasRootDocument(); + MODEL_EXPORT virtual bool hasModuleDocument(); /// Returns the current document that used for current work in the application - MODEL_EXPORT virtual boost::shared_ptr currentDocument(); + MODEL_EXPORT virtual boost::shared_ptr activeDocument(); /// Defines the current document that used for current work in the application - MODEL_EXPORT virtual void setCurrentDocument(boost::shared_ptr theDoc); + MODEL_EXPORT virtual void setActiveDocument(boost::shared_ptr theDoc); /// Registers the plugin that creates features. /// It is obligatory for each plugin to call this function on loading to be found by diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index f6ed8c5ab..a76ee1a2c 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -28,41 +28,9 @@ class ModelAPI_Data; class ModelAPI_Document { public: - //! Loads the OCAF document from the file. - //! \param theFileName full name of the file to load - //! \param theStudyID identifier of the SALOME study to associate with loaded file - //! \returns true if file was loaded successfully - virtual bool load(const char* theFileName) = 0; - - //! Saves the OCAF document to the file. - //! \param theFileName full name of the file to store - //! \param theResults the result full file names that were stored by "save" - //! \returns true if file was stored successfully - virtual bool save(const char* theFileName, std::list& theResults) = 0; - //! Removes document data virtual void close() = 0; - //! Starts a new operation (opens a tansaction) - virtual void startOperation() = 0; - //! Finishes the previously started operation (closes the transaction) - virtual void finishOperation() = 0; - //! Aborts the operation - virtual void abortOperation() = 0; - //! Returns true if operation has been started, but not yet finished or aborted - virtual bool isOperation() = 0; - //! Returns true if document was modified (since creation/opening) - virtual bool isModified() = 0; - - //! Returns True if there are available Undos - virtual bool canUndo() = 0; - //! Undoes last operation - virtual void undo() = 0; - //! Returns True if there are available Redos - virtual bool canRedo() = 0; - //! Redoes last operation - virtual void redo() = 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) virtual boost::shared_ptr addFeature(std::string theID) = 0; @@ -72,7 +40,7 @@ class ModelAPI_Document ///! Adds a new sub-document by the identifier, or returns existing one if it is already exist virtual boost::shared_ptr - subDocument(std::string theDocID) = 0; + subDocument(std::string theDocID) = 0; ///! Returns the id of the document virtual const std::string& id() const = 0; diff --git a/src/ModelAPI/ModelAPI_Feature.cpp b/src/ModelAPI/ModelAPI_Feature.cpp index 72fdcd9b3..a34d71bc5 100644 --- a/src/ModelAPI/ModelAPI_Feature.cpp +++ b/src/ModelAPI/ModelAPI_Feature.cpp @@ -88,7 +88,7 @@ void ModelAPI_Feature::eraseResults() boost::shared_ptr ModelAPI_Feature::documentToAdd() { - return ModelAPI_Session::get()->currentDocument(); + return ModelAPI_Session::get()->activeDocument(); } ModelAPI_Feature::~ModelAPI_Feature() diff --git a/src/ModelAPI/ModelAPI_Session.h b/src/ModelAPI/ModelAPI_Session.h index 0c6df4987..54e807693 100644 --- a/src/ModelAPI/ModelAPI_Session.h +++ b/src/ModelAPI/ModelAPI_Session.h @@ -7,6 +7,7 @@ #include "ModelAPI.h" #include +#include #include class ModelAPI_Feature; @@ -27,22 +28,54 @@ class MODELAPI_EXPORT ModelAPI_Session /// Returns the real implementation (the alone instance per application) of the plugin manager static boost::shared_ptr get(); + //! Loads the OCAF document from the file. + //! \param theFileName full name of the file to load + //! \param theStudyID identifier of the SALOME study to associate with loaded file + //! \returns true if file was loaded successfully + virtual bool load(const char* theFileName) = 0; + + //! Saves the OCAF document to the file. + //! \param theFileName full name of the file to store + //! \param theResults the result full file names that were stored by "save" + //! \returns true if file was stored successfully + virtual bool save(const char* theFileName, std::list& theResults) = 0; + + //! Starts a new operation (opens a tansaction) + virtual void startOperation() = 0; + //! Finishes the previously started operation (closes the transaction) + virtual void finishOperation() = 0; + //! Aborts the operation + virtual void abortOperation() = 0; + //! Returns true if operation has been started, but not yet finished or aborted + virtual bool isOperation() = 0; + //! Returns true if document was modified (since creation/opening) + virtual bool isModified() = 0; + + //! Returns True if there are available Undos + virtual bool canUndo() = 0; + //! Undoes last operation + virtual void undo() = 0; + //! Returns True if there are available Redos + virtual bool canRedo() = 0; + //! Redoes last operation + virtual void redo() = 0; + /// Registers the plugin that creates features. /// It is obligatory for each plugin to call this function on loading to be found by /// the plugin manager on call of the feature) virtual void registerPlugin(ModelAPI_Plugin* thePlugin) = 0; /// Returns the root document of the application (that may contains sub-documents) - virtual boost::shared_ptr rootDocument() = 0; + virtual boost::shared_ptr moduleDocument() = 0; /// Return true if root document has been already created - virtual bool hasRootDocument() = 0; + virtual bool hasModuleDocument() = 0; /// Returns the current document that used for current work in the application - virtual boost::shared_ptr currentDocument() = 0; + virtual boost::shared_ptr activeDocument() = 0; /// Defines the current document that used for current work in the application - virtual void setCurrentDocument(boost::shared_ptr theDoc) = 0; + virtual void setActiveDocument(boost::shared_ptr theDoc) = 0; /// Copies the document to the new one with the given id virtual boost::shared_ptr copy(boost::shared_ptr theSource, diff --git a/src/ModuleBase/ModuleBase_IOperation.cpp b/src/ModuleBase/ModuleBase_IOperation.cpp index fec4856da..f9fb72b87 100644 --- a/src/ModuleBase/ModuleBase_IOperation.cpp +++ b/src/ModuleBase/ModuleBase_IOperation.cpp @@ -51,12 +51,12 @@ bool ModuleBase_IOperation::canBeCommitted() const boost::shared_ptr ModuleBase_IOperation::document() const { - return ModelAPI_Session::get()->rootDocument(); + return ModelAPI_Session::get()->moduleDocument(); } void ModuleBase_IOperation::start() { - document()->startOperation(); + ModelAPI_Session::get()->startOperation(); startOperation(); emit started(); @@ -74,7 +74,7 @@ void ModuleBase_IOperation::abort() stopOperation(); - document()->abortOperation(); + ModelAPI_Session::get()->abortOperation(); emit stopped(); } @@ -86,7 +86,7 @@ bool ModuleBase_IOperation::commit() stopOperation(); - document()->finishOperation(); + ModelAPI_Session::get()->finishOperation(); emit stopped(); afterCommitOperation(); diff --git a/src/PartSet/PartSet_TestOCC.cpp b/src/PartSet/PartSet_TestOCC.cpp index f67a1e06a..bd9b24833 100644 --- a/src/PartSet/PartSet_TestOCC.cpp +++ b/src/PartSet/PartSet_TestOCC.cpp @@ -132,7 +132,7 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop) if (aPreviewOp) { // create a line - boost::shared_ptr aDoc = ModelAPI_Session::get()->rootDocument(); + boost::shared_ptr aDoc = ModelAPI_Session::get()->moduleDocument(); FeaturePtr aFeature = aDoc->addFeature(SketchPlugin_Line::ID()); if (aFeature) // TODO: generate an error if feature was not created aFeature->execute(); diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index f301c8e0a..a52a43453 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -171,7 +171,7 @@ FeaturePtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theVie boost::shared_ptr PartSet_Tools::document() { - return ModelAPI_Session::get()->rootDocument(); + return ModelAPI_Session::get()->moduleDocument(); } void PartSet_Tools::setFeaturePoint(FeaturePtr theFeature, double theX, double theY, diff --git a/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp b/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp index f8ebfd900..b8919426b 100644 --- a/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp @@ -21,13 +21,13 @@ void PartSetPlugin_Duplicate::initAttributes() data()->addAttribute(ORIGIN_REF(), ModelAPI_AttributeRefAttr::type()); boost::shared_ptr aPManager = ModelAPI_Session::get(); - boost::shared_ptr aRoot = aPManager->rootDocument(); + boost::shared_ptr aRoot = aPManager->moduleDocument(); boost::shared_ptr aSource; // searching for source document attribute for (int a = aRoot->size(getGroup()) - 1; a >= 0; a--) { aSource = boost::dynamic_pointer_cast(aRoot->object(getGroup(), a)); if (aSource && aSource->data() && aSource->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value() - == aPManager->currentDocument()) + == aPManager->activeDocument()) break; aSource.reset(); } diff --git a/src/PartSetPlugin/PartSetPlugin_Part.cpp b/src/PartSetPlugin/PartSetPlugin_Part.cpp index 739f63629..937820bec 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Part.cpp @@ -32,7 +32,7 @@ void PartSetPlugin_Part::execute() if (!aDocRef->value()) { // create a document if not yet created boost::shared_ptr aPartSetDoc = - ModelAPI_Session::get()->rootDocument(); + ModelAPI_Session::get()->moduleDocument(); aDocRef->setValue(aPartSetDoc->subDocument(data()->name())); } */ @@ -40,5 +40,5 @@ void PartSetPlugin_Part::execute() boost::shared_ptr PartSetPlugin_Part::documentToAdd() { - return ModelAPI_Session::get()->rootDocument(); + return ModelAPI_Session::get()->moduleDocument(); } diff --git a/src/PartSetPlugin/PartSetPlugin_Remove.cpp b/src/PartSetPlugin/PartSetPlugin_Remove.cpp index d6053e5dc..f764ddc48 100644 --- a/src/PartSetPlugin/PartSetPlugin_Remove.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Remove.cpp @@ -12,7 +12,7 @@ void PartSetPlugin_Remove::execute() { boost::shared_ptr aPManager = ModelAPI_Session::get(); - boost::shared_ptr aRoot = aPManager->rootDocument(); + boost::shared_ptr aRoot = aPManager->moduleDocument(); boost::shared_ptr aCurrent; boost::shared_ptr a; for (int a = aRoot->size(ModelAPI_ResultPart::group()) - 1; a >= 0; a--) { @@ -20,7 +20,7 @@ void PartSetPlugin_Remove::execute() aRoot->object(ModelAPI_ResultPart::group(), a)); if (aPart && aPart->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value() - == aPManager->currentDocument()) { + == aPManager->activeDocument()) { FeaturePtr aFeature = aRoot->feature(aPart); if (aFeature) { // do remove diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 34c334147..ec698bc52 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -115,7 +115,7 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const ResultPartPtr aPart = boost::dynamic_pointer_cast(aObject); FeaturePtr aFeature = boost::dynamic_pointer_cast(aObject); if (aPart) { - if (aMgr->currentDocument() == aPart->partDoc()) + if (aMgr->activeDocument() == aPart->partDoc()) aMenu->addAction(action("DEACTIVATE_PART_CMD")); else aMenu->addAction(action("ACTIVATE_PART_CMD")); @@ -130,7 +130,7 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const aMenu->addAction(action("SHOW_ONLY_CMD")); } } else { // If feature is 0 the it means that selected root object (document) - if (aMgr->currentDocument() != aMgr->rootDocument()) + if (aMgr->activeDocument() != aMgr->moduleDocument()) aMenu->addAction(action("ACTIVATE_PART_CMD")); } } else if (aSelected >= 1) { diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp index 0fcbd794b..291c193e8 100644 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ b/src/XGUI/XGUI_DocumentDataModel.cpp @@ -45,7 +45,7 @@ XGUI_DocumentDataModel::~XGUI_DocumentDataModel() void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) { - DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); // Created object event ******************* if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) { @@ -155,7 +155,7 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) void XGUI_DocumentDataModel::rebuildDataTree() { - DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); beginResetModel(); clearModelIndexes(); @@ -200,7 +200,7 @@ QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) case HistoryNode: { int aOffset = historyOffset(); - DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); ObjectPtr aObj = aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset); FeaturePtr aFeature = boost::dynamic_pointer_cast(aObj); if (!aFeature) @@ -242,7 +242,7 @@ QVariant XGUI_DocumentDataModel::headerData(int theSection, Qt::Orientation theO int XGUI_DocumentDataModel::rowCount(const QModelIndex& theParent) const { if (!theParent.isValid()) { - DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); // Size of external models int aVal = historyOffset(); // Plus history size @@ -371,7 +371,7 @@ ObjectPtr XGUI_DocumentDataModel::object(const QModelIndex& theIndex) const if (theIndex.internalId() == PartsFolder) return ObjectPtr(); if (theIndex.internalId() == HistoryNode) { - DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); int aOffset = historyOffset(); return aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset); } @@ -529,7 +529,7 @@ QModelIndex XGUI_DocumentDataModel::partIndex(const ResultPartPtr& theObject) co QModelIndex XGUI_DocumentDataModel::objectIndex(const ObjectPtr theObject) const { // Check that this feature belongs to root document - DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); DocumentPtr aDoc = theObject->document(); if (aDoc == aRootDoc) { // This feature belongs to histrory or top model diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index c128f3235..c62643ad0 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -84,9 +84,9 @@ void XGUI_DataTree::commitData(QWidget* theEditor) QString aRes = aEditor->text(); ObjectPtr aFeature = mySelectedData.first(); SessionPtr aMgr = ModelAPI_Session::get(); - aMgr->rootDocument()->startOperation(); + aMgr->startOperation(); aFeature->data()->setName(qPrintable(aRes)); - aMgr->rootDocument()->finishOperation(); + aMgr->finishOperation(); } } @@ -120,7 +120,7 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) aLabelLay->addWidget(aLbl); SessionPtr aMgr = ModelAPI_Session::get(); - DocumentPtr aDoc = aMgr->rootDocument(); + DocumentPtr aDoc = aMgr->moduleDocument(); // TODO: Find a name of the root document myActiveDocLbl = new QLineEdit(tr("Part set"), aLabelWgt); @@ -227,7 +227,7 @@ void XGUI_ObjectsBrowser::closeDocNameEditing(bool toSave) if (toSave) { // TODO: Save the name of root document SessionPtr aMgr = ModelAPI_Session::get(); - DocumentPtr aDoc = aMgr->rootDocument(); + DocumentPtr aDoc = aMgr->moduleDocument(); } else { myActiveDocLbl->setText(myActiveDocLbl->property("OldText").toString()); } diff --git a/src/XGUI/XGUI_PartDataModel.cpp b/src/XGUI/XGUI_PartDataModel.cpp index 6f6fc8f04..c492229c9 100644 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ b/src/XGUI/XGUI_PartDataModel.cpp @@ -42,7 +42,7 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const case ParamsFolder: return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex)); case ParamObject: { - DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultParameters::group(), theIndex.row()); if (aObject) return aObject->data()->name().c_str(); @@ -51,7 +51,7 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const case ConstructFolder: return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex)); case ConstructObject: { - DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row()); if (aObject) @@ -61,7 +61,7 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const case BodiesFolder: return tr("Bodies") + QString(" (%1)").arg(rowCount(theIndex)); case BodiesObject: { - DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultBody::group(), theIndex.row()); if (aObject) return aObject->data()->name().c_str(); @@ -103,7 +103,7 @@ int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const if (!theParent.isValid()) return 3; - DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); if (theParent.internalId() == ParamsFolder) return aRootDoc->size(ModelAPI_ResultParameters::group()); @@ -175,15 +175,15 @@ ObjectPtr XGUI_TopDataModel::object(const QModelIndex& theIndex) const case BodiesFolder: return ObjectPtr(); case ParamObject: { - DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); return aRootDoc->object(ModelAPI_ResultParameters::group(), theIndex.row()); } case ConstructObject: { - DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); return aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row()); } case BodiesObject: { - DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); return aRootDoc->object(ModelAPI_ResultBody::group(), theIndex.row()); } } @@ -210,7 +210,7 @@ QModelIndex XGUI_TopDataModel::objectIndex(const ObjectPtr& theObject) const { QModelIndex aIndex; if (theObject) { - DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); std::string aGroup = theObject->groupName(); int aNb = aRootDoc->size(aGroup); int aRow = -1; @@ -251,7 +251,7 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons // return a name switch (theIndex.internalId()) { case MyRoot: { - DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId); if (aObject) return boost::dynamic_pointer_cast(aObject)->data()->name().c_str(); @@ -325,7 +325,7 @@ QVariant XGUI_PartDataModel::headerData(int section, Qt::Orientation orientation int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const { if (!parent.isValid()) { - DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); if (aRootDoc->object(ModelAPI_ResultPart::group(), myId)) return 1; else @@ -410,7 +410,7 @@ bool XGUI_PartDataModel::hasChildren(const QModelIndex& theParent) const DocumentPtr XGUI_PartDataModel::partDocument() const { - DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId); ResultPartPtr aPart = boost::dynamic_pointer_cast(aObject); return aPart->partDoc(); @@ -420,7 +420,7 @@ ObjectPtr XGUI_PartDataModel::object(const QModelIndex& theIndex) const { switch (theIndex.internalId()) { case MyRoot: { - DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); return aRootDoc->object(ModelAPI_ResultPart::group(), myId); } case ParamsFolder: @@ -462,7 +462,7 @@ QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const ResultPartPtr XGUI_PartDataModel::part() const { - DocumentPtr aRootDoc = ModelAPI_Session::get()->rootDocument(); + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); ObjectPtr aObj = aRootDoc->object(ModelAPI_ResultPart::group(), myId); return boost::dynamic_pointer_cast(aObj); } diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index eeff54c44..1c9277eaa 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -306,9 +306,8 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) } if (!isSalomeMode()) { SessionPtr aMgr = ModelAPI_Session::get(); - DocumentPtr aDoc = aMgr->rootDocument(); - if (aDoc->isModified() != myMainWindow->isModifiedState()) - myMainWindow->setModifiedState(aDoc->isModified()); + if (aMgr->isModified() != myMainWindow->isModifiedState()) + myMainWindow->setModifiedState(aMgr->isModified()); } } @@ -531,8 +530,7 @@ void XGUI_Workshop::saveDocument(const QString& theName, std::list& { QApplication::restoreOverrideCursor(); SessionPtr aMgr = ModelAPI_Session::get(); - DocumentPtr aDoc = aMgr->rootDocument(); - aDoc->save(theName.toLatin1().constData(), theFileNames); + aMgr->save(theName.toLatin1().constData(), theFileNames); QApplication::restoreOverrideCursor(); } @@ -540,8 +538,7 @@ void XGUI_Workshop::saveDocument(const QString& theName, std::list& void XGUI_Workshop::onExit() { SessionPtr aMgr = ModelAPI_Session::get(); - DocumentPtr aDoc = aMgr->rootDocument(); - if (aDoc->isModified()) { + if (aMgr->isModified()) { int anAnswer = QMessageBox::question( myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel); @@ -582,8 +579,7 @@ void XGUI_Workshop::onOpen() { //save current file before close if modified SessionPtr aMgr = ModelAPI_Session::get(); - DocumentPtr aDoc = aMgr->rootDocument(); - if (aDoc->isModified()) { + if (aMgr->isModified()) { //TODO(sbh): re-launch the app? int anAnswer = QMessageBox::question( myMainWindow, tr("Save current file"), @@ -594,7 +590,7 @@ void XGUI_Workshop::onOpen() } else if (anAnswer == QMessageBox::Cancel) { return; } - aDoc->close(); + aMgr->moduleDocument()->close(); myCurrentDir = ""; } @@ -609,7 +605,7 @@ void XGUI_Workshop::onOpen() return; } QApplication::setOverrideCursor(Qt::WaitCursor); - aDoc->load(myCurrentDir.toLatin1().constData()); + aMgr->load(myCurrentDir.toLatin1().constData()); myObjectBrowser->rebuildDataTree(); displayAllResults(); updateCommandStatus(); @@ -668,10 +664,9 @@ void XGUI_Workshop::onUndo() { objectBrowser()->treeView()->setCurrentIndex(QModelIndex()); SessionPtr aMgr = ModelAPI_Session::get(); - DocumentPtr aDoc = aMgr->rootDocument(); - if (aDoc->isOperation()) + if (aMgr->isOperation()) operationMgr()->abortOperation(); - aDoc->undo(); + aMgr->undo(); updateCommandStatus(); } @@ -680,10 +675,9 @@ void XGUI_Workshop::onRedo() { objectBrowser()->treeView()->setCurrentIndex(QModelIndex()); SessionPtr aMgr = ModelAPI_Session::get(); - DocumentPtr aDoc = aMgr->rootDocument(); - if (aDoc->isOperation()) + if (aMgr->isOperation()) operationMgr()->abortOperation(); - aDoc->redo(); + aMgr->redo(); updateCommandStatus(); } @@ -792,7 +786,7 @@ void XGUI_Workshop::updateCommandStatus() aCommands.append(aCmd); } SessionPtr aMgr = ModelAPI_Session::get(); - if (aMgr->hasRootDocument()) { + if (aMgr->hasModuleDocument()) { QAction* aUndoCmd; QAction* aRedoCmd; foreach(QAction* aCmd, aCommands) @@ -806,9 +800,8 @@ void XGUI_Workshop::updateCommandStatus() // Enable all commands aCmd->setEnabled(true); } - DocumentPtr aDoc = aMgr->rootDocument(); - aUndoCmd->setEnabled(aDoc->canUndo()); - aRedoCmd->setEnabled(aDoc->canRedo()); + aUndoCmd->setEnabled(aMgr->canUndo()); + aRedoCmd->setEnabled(aMgr->canRedo()); } else { foreach(QAction* aCmd, aCommands) { @@ -942,12 +935,12 @@ void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj) if (aPart) { DocumentPtr aPartDoc = aPart->partDoc(); if (aPartDoc) { - aMgr->setCurrentDocument(aPartDoc); + aMgr->setActiveDocument(aPartDoc); return; } } } - aMgr->setCurrentDocument(aMgr->rootDocument()); + aMgr->setActiveDocument(aMgr->moduleDocument()); } //****************************************************** @@ -1015,7 +1008,7 @@ void XGUI_Workshop::activatePart(ResultPartPtr theFeature) void XGUI_Workshop::activateLastPart() { SessionPtr aMgr = ModelAPI_Session::get(); - DocumentPtr aDoc = aMgr->rootDocument(); + DocumentPtr aDoc = aMgr->moduleDocument(); std::string aGrpName = ModelAPI_ResultPart::group(); ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1); ResultPartPtr aPart = boost::dynamic_pointer_cast(aLastPart); @@ -1033,16 +1026,16 @@ void XGUI_Workshop::deleteObjects(const QList& theList) // ToDo: definbe deleting method if (aRes == QMessageBox::Yes) { SessionPtr aMgr = ModelAPI_Session::get(); - aMgr->rootDocument()->startOperation(); + aMgr->startOperation(); foreach (ObjectPtr aObj, theList) { ResultPartPtr aPart = boost::dynamic_pointer_cast(aObj); if (aPart) { DocumentPtr aDoc = aPart->document(); - if (aDoc == aMgr->currentDocument()) { + if (aDoc == aMgr->activeDocument()) { aDoc->close(); } - //aMgr->rootDocument()->removeFeature(aPart->owner()); + //aMgr->moduleDocument()->removeFeature(aPart->owner()); } else { FeaturePtr aFeature = boost::dynamic_pointer_cast(aObj); if (aFeature) @@ -1050,7 +1043,7 @@ void XGUI_Workshop::deleteObjects(const QList& theList) } } myDisplayer->updateViewer(); - aMgr->rootDocument()->finishOperation(); + aMgr->finishOperation(); } } @@ -1119,7 +1112,7 @@ void XGUI_Workshop::registerValidators() const void XGUI_Workshop::displayAllResults() { SessionPtr aMgr = ModelAPI_Session::get(); - DocumentPtr aRootDoc = aMgr->rootDocument(); + DocumentPtr aRootDoc = aMgr->moduleDocument(); displayDocumentResults(aRootDoc); for (int i = 0; i < aRootDoc->size(ModelAPI_ResultPart::group()); i++) { ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i); -- 2.39.2