Salome HOME
Merge branch 'SALOME-8.2.0_porting'
[modules/shaper.git] / src / Model / Model_Session.h
index e691cea306f281d799c829a38cb0f3e35f9de2c4..d9f9f2c2d0b63d450257463beeaf9d9be0f4deb2 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        Model_Session.hxx
 // Created:     20 Mar 2014
 // Author:      Mikhail PONIKAROV
@@ -24,16 +26,18 @@ class Model_Session : public ModelAPI_Session, public Events_Listener
 {
   bool myPluginsInfoLoaded;  ///< it true if plugins information is loaded
   /// map of feature IDs to plugin name and document kind
-  std::map<std::string, std::pair<std::string, std::string> > myPlugins; 
+  std::map<std::string, std::pair<std::string, std::string> > myPlugins;
   std::map<std::string, ModelAPI_Plugin*> myPluginObjs;  ///< instances of the already plugins
   std::string myCurrentPluginName;  ///< name of the plugin that must be loaded currently
-  boost::shared_ptr<ModelAPI_Document> myCurrentDoc;  ///< current working document
-  bool myCheckTransactions;  ///< if true, generates error if document is updated outside of transaction
+  std::shared_ptr<ModelAPI_Document> myCurrentDoc;  ///< current working document
+
+  /// if true, generates error if document is updated outside of transaction
+  bool myCheckTransactions;
+  bool myOperationAttachedToNext; ///< the current operation must be committed twice, with nested
  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);
 
@@ -43,11 +47,19 @@ class Model_Session : public ModelAPI_Session, public Events_Listener
   //! \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();
+  //! Closes all documents
+  MODEL_EXPORT virtual void closeAll();
+
+  //! Starts a new operation (opens a transaction)
+  //! \param theId string-identifier of the started transaction
+  //! \param theAttachedToNested if it is true,
+  //!                            it means that this transaction is attached to the nested
+  //!          where it is located and will be committed on the next commit with the nested
+  MODEL_EXPORT virtual void startOperation(
+    const std::string& theId = "", const bool theAttachedToNested = false);
   //! Finishes the previously started operation (closes the transaction)
   MODEL_EXPORT virtual void finishOperation();
-  //! Aborts the operation 
+  //! 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();
@@ -62,37 +74,49 @@ class Model_Session : public ModelAPI_Session, public Events_Listener
   MODEL_EXPORT virtual bool canRedo();
   //! Redoes last operation
   MODEL_EXPORT virtual void redo();
+  //! Returns stack of performed operations
+  MODEL_EXPORT virtual std::list<std::string> undoList();
+  //! Returns stack of rolled back operations
+  MODEL_EXPORT virtual std::list<std::string> redoList();
 
   /// Returns the root document of the application (that may contains sub-documents)
-  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> moduleDocument();
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> moduleDocument();
+
+  /// 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(int theDocID);
 
   /// Return true if root document has been already created
   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> activeDocument();
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> activeDocument();
 
   /// Defines the current document that used for current work in the application
-  MODEL_EXPORT virtual void setActiveDocument(boost::shared_ptr<ModelAPI_Document> theDoc);
+  MODEL_EXPORT virtual void setActiveDocument(
+    std::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal = true);
 
   /// Returns all the opened documents of the session (without postponed)
-  MODEL_EXPORT virtual std::list<boost::shared_ptr<ModelAPI_Document> > allOpenedDocuments();
+  MODEL_EXPORT virtual std::list<std::shared_ptr<ModelAPI_Document> > allOpenedDocuments();
+
+  /// Returns true if document is not loaded yet
+  MODEL_EXPORT virtual bool isLoadByDemand(const std::string theDocID);
 
   /// Registers the plugin that creates features.
-  /// It is obligatory for each plugin to call this function on loading to be found by 
+  /// It is obligatory for each plugin to call this function on loading to be found by
   /// the plugin manager on call of the feature)
   MODEL_EXPORT virtual void registerPlugin(ModelAPI_Plugin* thePlugin);
 
   /// Processes the configuration file reading
-  MODEL_EXPORT virtual void processEvent(const boost::shared_ptr<Events_Message>& theMessage);
+  MODEL_EXPORT virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
 
-  /// Copies the document to the new one wit hthe given id
-  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> copy(
-      boost::shared_ptr<ModelAPI_Document> theSource, std::string theID);
+  /// Copies the document to the new one
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> copy(
+      std::shared_ptr<ModelAPI_Document> theSource, const int theDestID);
 
   /// Returns the validators factory: the only one instance per application
   MODEL_EXPORT virtual ModelAPI_ValidatorsFactory* validators();
 
+  /// Sets the flag to check modifications outside the transaction or not
   void setCheckTransactions(const bool theCheck)
   {
     myCheckTransactions = theCheck;
@@ -101,12 +125,21 @@ class Model_Session : public ModelAPI_Session, public Events_Listener
   /// Is called only once, on startup of the application
   Model_Session();
 
+  /// Returns the global identifier of the current transaction (needed for the update algo)
+  MODEL_EXPORT virtual int transactionID();
+
+  /// Load plugin by its name
+  MODEL_EXPORT virtual void forceLoadPlugin(const std::string& thePluginName);
+
  protected:
   /// Loads (if not done yet) the information about the features and plugins
   void LoadPluginsInfo();
 
   /// Creates the feature object using plugins functionality
-  virtual FeaturePtr createFeature(std::string theFeatureID);
+  FeaturePtr createFeature(std::string theFeatureID, Model_Document* theDocOwner);
+
+  friend class Model_Document;
+  friend class Model_Objects;
 };
 
 #endif