Salome HOME
Issue #83: rename and transfer some methods related to document
authormpv <mikhail.ponikarov@opencascade.com>
Thu, 11 Sep 2014 11:00:19 +0000 (15:00 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Thu, 11 Sep 2014 11:00:19 +0000 (15:00 +0400)
20 files changed:
src/Model/Model_Data.cpp
src/Model/Model_Document.cpp
src/Model/Model_Document.h
src/Model/Model_ResultPart.cpp
src/Model/Model_Session.cpp
src/Model/Model_Session.h
src/ModelAPI/ModelAPI_Document.h
src/ModelAPI/ModelAPI_Feature.cpp
src/ModelAPI/ModelAPI_Session.h
src/ModuleBase/ModuleBase_IOperation.cpp
src/PartSet/PartSet_TestOCC.cpp
src/PartSet/PartSet_Tools.cpp
src/PartSetPlugin/PartSetPlugin_Duplicate.cpp
src/PartSetPlugin/PartSetPlugin_Part.cpp
src/PartSetPlugin/PartSetPlugin_Remove.cpp
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_DocumentDataModel.cpp
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_PartDataModel.cpp
src/XGUI/XGUI_Workshop.cpp

index 5dba72cbdc74460c305b2bf275f7db5e24e4e7b7..b384b49d77846c29b47a856eeca3280fe9cc5bac 100644 (file)
@@ -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)
index b66318687afd51c2a32e52caa3ecf4e46dd2092f..11a7eaa20b745669cdd1d6de2e933626532a8345 100644 (file)
@@ -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<std::string>& 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<std::string>& theRe
   if (isDone) {  // save also sub-documents if any
     theResults.push_back(TCollection_AsciiString(aPath).ToCString());
     std::set<std::string>::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<std::string>& theRe
 void Model_Document::close()
 {
   boost::shared_ptr<ModelAPI_Session> 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<std::string>::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<std::string>::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<std::string>::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<std::string>::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<std::string>::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<std::string>::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<std::string>::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<std::string>::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<ModelAPI_Document> Model_Document::subDocument(std::string the
   return Model_Application::getApplication()->getDocument(theDocID);
 }
 
+boost::shared_ptr<Model_Document> 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_Document>(
+    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);
index 7024925edb0609f01bc96f74538e597d24f43678..598c3b633f674c283e69f89c7b1edaff4f75341b 100644 (file)
@@ -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<ModelAPI_Document> subDocument(std::string theDocID);
 
+  //! Internal sub-document by ID
+  MODEL_EXPORT virtual boost::shared_ptr<Model_Document> subDoc(std::string theDocID);
+
   ///! Returns the id of hte document
   MODEL_EXPORT virtual const std::string& id() const
   {
index 6d1afbf48bff9c9dd87c5021403bb44531113518..6767ffee65d7e056b2edb51297941cc6963cd9f0 100644 (file)
@@ -40,5 +40,5 @@ void Model_ResultPart::activate()
     }
   }
   if (aDocRef->value())
-    ModelAPI_Session::get()->setCurrentDocument(aDocRef->value());
+    ModelAPI_Session::get()->setActiveDocument(aDocRef->value());
 }
index 730b6eca2b1d87aef743d0cab7c7e4b1784f3fb0..6f334290c900e761b3dcf56414b59b1951691ae4 100644 (file)
@@ -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<Model_Document>(moduleDocument())
+
+bool Model_Session::load(const char* theFileName)
+{
+  return ROOT_DOC->load(theFileName);
+}
+
+bool Model_Session::save(const char* theFileName, std::list<std::string>& 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<ModelAPI_Document> Model_Session::rootDocument()
+boost::shared_ptr<ModelAPI_Document> Model_Session::moduleDocument()
 {
   return boost::shared_ptr<ModelAPI_Document>(
       Model_Application::getApplication()->getDocument("root"));
 }
 
-bool Model_Session::hasRootDocument()
+bool Model_Session::hasModuleDocument()
 {
   return Model_Application::getApplication()->hasDocument("root");
 }
 
-boost::shared_ptr<ModelAPI_Document> Model_Session::currentDocument()
+boost::shared_ptr<ModelAPI_Document> Model_Session::activeDocument()
 {
   if (!myCurrentDoc || !Model_Application::getApplication()->hasDocument(myCurrentDoc->id()))
-    myCurrentDoc = rootDocument();
+    myCurrentDoc = moduleDocument();
   return myCurrentDoc;
 }
 
-void Model_Session::setCurrentDocument(boost::shared_ptr<ModelAPI_Document> theDoc)
+void Model_Session::setActiveDocument(boost::shared_ptr<ModelAPI_Document> 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");
   }
 }
index cc1494a13e7ff22d9545b5661dd330ff896ad17c..5ee656025d1cf71e3da7fbab5e49423a085f7295 100644 (file)
@@ -30,17 +30,50 @@ class Model_Session : public ModelAPI_Session, public Events_Listener
   boost::shared_ptr<ModelAPI_Document> 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<std::string>& 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<ModelAPI_Document> rootDocument();
+  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> 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<ModelAPI_Document> currentDocument();
+  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> activeDocument();
 
   /// Defines the current document that used for current work in the application
-  MODEL_EXPORT virtual void setCurrentDocument(boost::shared_ptr<ModelAPI_Document> theDoc);
+  MODEL_EXPORT virtual void setActiveDocument(boost::shared_ptr<ModelAPI_Document> theDoc);
 
   /// Registers the plugin that creates features.
   /// It is obligatory for each plugin to call this function on loading to be found by 
index f6ed8c5ab5e4fa87a78b12145ae6db3d6c2cee0b..a76ee1a2c98ca9c0e365c33ef07412634fd9f216 100644 (file)
@@ -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<std::string>& 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<ModelAPI_Feature> 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<ModelAPI_Document>
-  subDocument(std::string theDocID) = 0;
+    subDocument(std::string theDocID) = 0;
 
   ///! Returns the id of the document
   virtual const std::string& id() const = 0;
index 72fdcd9b320025bf4a9bb3f13fcc8ae334f109ef..a34d71bc56236ee18ea9891c353c0b9b08b1b02f 100644 (file)
@@ -88,7 +88,7 @@ void ModelAPI_Feature::eraseResults()
 
 boost::shared_ptr<ModelAPI_Document> ModelAPI_Feature::documentToAdd()
 {
-  return ModelAPI_Session::get()->currentDocument();
+  return ModelAPI_Session::get()->activeDocument();
 }
 
 ModelAPI_Feature::~ModelAPI_Feature()
index 0c6df4987d33b99d70c7c5a3dccfc5633137ed49..54e807693d9ac7032af15e0f6e1aad3f7828a754 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "ModelAPI.h"
 #include <string>
+#include <list>
 #include <boost/shared_ptr.hpp>
 
 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<ModelAPI_Session> 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<std::string>& 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<ModelAPI_Document> rootDocument() = 0;
+  virtual boost::shared_ptr<ModelAPI_Document> 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<ModelAPI_Document> currentDocument() = 0;
+  virtual boost::shared_ptr<ModelAPI_Document> activeDocument() = 0;
 
   /// Defines the current document that used for current work in the application
-  virtual void setCurrentDocument(boost::shared_ptr<ModelAPI_Document> theDoc) = 0;
+  virtual void setActiveDocument(boost::shared_ptr<ModelAPI_Document> theDoc) = 0;
 
   /// Copies the document to the new one with the given id
   virtual boost::shared_ptr<ModelAPI_Document> copy(boost::shared_ptr<ModelAPI_Document> theSource,
index fec4856da9cae6729063311ad520ba795ca57aa1..f9fb72b8702eefddc904344753205507c4e1bb8c 100644 (file)
@@ -51,12 +51,12 @@ bool ModuleBase_IOperation::canBeCommitted() const
 
 boost::shared_ptr<ModelAPI_Document> 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();
index f67a1e06a4d0a71d3d345ea0a30c08f597560e8f..bd9b248330a075112716d61061cc996b2915d210 100644 (file)
@@ -132,7 +132,7 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop)
 
   if (aPreviewOp) {
     // create a line
-    boost::shared_ptr<ModelAPI_Document> aDoc = ModelAPI_Session::get()->rootDocument();
+    boost::shared_ptr<ModelAPI_Document> 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();
index f301c8e0abdf482bda1b8f1188f77fb6f3359412..a52a43453679dade0c073386a9fe9516cf8948bc 100644 (file)
@@ -171,7 +171,7 @@ FeaturePtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theVie
 
 boost::shared_ptr<ModelAPI_Document> PartSet_Tools::document()
 {
-  return ModelAPI_Session::get()->rootDocument();
+  return ModelAPI_Session::get()->moduleDocument();
 }
 
 void PartSet_Tools::setFeaturePoint(FeaturePtr theFeature, double theX, double theY,
index f8ebfd9006d1f522e90b164d0bf47c4f1a56488e..b8919426b1f77c567129fdc3c7f980a6a4a11c2c 100644 (file)
@@ -21,13 +21,13 @@ void PartSetPlugin_Duplicate::initAttributes()
   data()->addAttribute(ORIGIN_REF(), ModelAPI_AttributeRefAttr::type());
 
   boost::shared_ptr<ModelAPI_Session> aPManager = ModelAPI_Session::get();
-  boost::shared_ptr<ModelAPI_Document> aRoot = aPManager->rootDocument();
+  boost::shared_ptr<ModelAPI_Document> aRoot = aPManager->moduleDocument();
   boost::shared_ptr<ModelAPI_ResultPart> aSource;  // searching for source document attribute
   for (int a = aRoot->size(getGroup()) - 1; a >= 0; a--) {
     aSource = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aRoot->object(getGroup(), a));
     if (aSource && aSource->data()
         && aSource->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value()
-            == aPManager->currentDocument())
+            == aPManager->activeDocument())
       break;
     aSource.reset();
   }
index 739f63629c9319a745b31936ccc8743be4ba8b57..937820becdad0902bb4be7f36908548dc20d68f7 100644 (file)
@@ -32,7 +32,7 @@ void PartSetPlugin_Part::execute()
   
   if (!aDocRef->value()) {  // create a document if not yet created
     boost::shared_ptr<ModelAPI_Document> 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<ModelAPI_Document> PartSetPlugin_Part::documentToAdd()
 {
-  return ModelAPI_Session::get()->rootDocument();
+  return ModelAPI_Session::get()->moduleDocument();
 }
index d6053e5dc2516c6a5c4560c97a8bc4fdf818615f..f764ddc485f5137f81f64dab577f40a589edef97 100644 (file)
@@ -12,7 +12,7 @@
 void PartSetPlugin_Remove::execute()
 {
   boost::shared_ptr<ModelAPI_Session> aPManager = ModelAPI_Session::get();
-  boost::shared_ptr<ModelAPI_Document> aRoot = aPManager->rootDocument();
+  boost::shared_ptr<ModelAPI_Document> aRoot = aPManager->moduleDocument();
   boost::shared_ptr<ModelAPI_Document> aCurrent;
   boost::shared_ptr<PartSetPlugin_Part> 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
index 34c3341471d515eacffb195aa701b84d52ea4d6b..ec698bc5246d8eb6edc6d1c0954bbf6c06ae3e01 100644 (file)
@@ -115,7 +115,7 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const
         ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
         FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(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) {
index 0fcbd794be563e6dd1c141aab7aeee2b3fc31fa0..291c193e8ad64576d7320ee7ed931395f6c9829b 100644 (file)
@@ -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<ModelAPI_Feature>(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
index c128f3235d88ab3400f19b6facd8054faae04f77..c62643ad065f97a18032baa3b02005e42e80c134 100644 (file)
@@ -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());
   }
index 6f6fc8f041563b24abf474234423e978b32dd567..c492229c9a54e67712a8cecaefbc503da1e921d6 100644 (file)
@@ -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<ModelAPI_Object>(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<ModelAPI_ResultPart>(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<ModelAPI_ResultPart>(aObj);
 }
index eeff54c4496308cd0437276cf3d2c6e6cc96b356..1c9277eaa584686f825eba4bfb7d913f7a173f42 100644 (file)
@@ -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<std::string>&
 {
   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<std::string>&
 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<ModelAPI_ResultPart>(aLastPart);
@@ -1033,16 +1026,16 @@ void XGUI_Workshop::deleteObjects(const QList<ObjectPtr>& 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<ModelAPI_ResultPart>(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<ModelAPI_Feature>(aObj);
         if (aFeature)
@@ -1050,7 +1043,7 @@ void XGUI_Workshop::deleteObjects(const QList<ObjectPtr>& 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);