Salome HOME
Overconstraint situation: redisplay objects through the events loop.
[modules/shaper.git] / src / ModelAPI / ModelAPI_Document.h
index 42ee9c3acd0859b54831af8e61a5caf6bf8128b6..8c1297359b113bdbe76c4156f6aa546717d14d64 100644 (file)
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        ModelAPI_Document.cxx
 // Created:     28 Feb 2014
 // Author:      Mikhail PONIKAROV
 
-#ifndef ModelAPI_Document_HeaderFile
-#define ModelAPI_Document_HeaderFile
+#ifndef ModelAPI_Document_H_
+#define ModelAPI_Document_H_
+
+#include "ModelAPI.h"
+#include "ModelAPI_Entity.h"
 
-#include <ModelAPI.h>
 #include <string>
-#include <boost/shared_ptr.hpp>
+#include <memory>
 #include <vector>
+#include <list>
+#include <set>
 
 class ModelAPI_Feature;
-
-/**\class Model_Document
+class ModelAPI_Object;
+class ModelAPI_Result;
+class ModelAPI_ResultConstruction;
+class ModelAPI_ResultBody;
+class ModelAPI_ResultPart;
+class ModelAPI_ResultGroup;
+class ModelAPI_ResultParameter;
+class ModelAPI_Data;
+
+/**\class ModelAPI_Document
  * \ingroup DataModel
  * \brief Document for internal data structure of any object storage.
  * Document contains all data that must be stored/retrived in the file.
  * Also it provides acces to this data: open/save, transactions management etc.
  */
-class ModelAPI_Document
+class ModelAPI_Document: public ModelAPI_Entity
 {
 public:
-  //! Common groups identifiers
-  //! Group of parameters
-  inline static const std::string& PARAMETERS_GROUP()
-  {
-    static const std::string MY_PARAMETERS_GROUP = "Parameters";
-    return MY_PARAMETERS_GROUP;
-  }
-  //! Group of constructions
-  inline static const std::string& CONSTRUCTIONS_GROUP()
-  {
-    static const std::string MY_CONSTRUCTIONS_GROUP = "Construction";
-    return MY_CONSTRUCTIONS_GROUP;
-  }
-  //! Group of parts
-  inline static const std::string& PARTS_GROUP()
-  {
-    static const std::string MY_PARTS_GROUP = "Parts";
-    return MY_PARTS_GROUP;
-  }
-  //! All created fetaures of the document (a history)
-  inline static const std::string& FEATURES_GROUP()
-  {
-    static const std::string MY_FEATURES_GROUP = "Features";
-    return MY_FEATURES_GROUP;
-  }
-
-  //! 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
-  MODELAPI_EXPORT virtual bool load(const char* theFileName) = 0;
-
-  //! Saves the OCAF document to the file.
-  //! \param theFileName full name of the file to store
-  //! \returns true if file was stored successfully
-  MODELAPI_EXPORT virtual bool save(const char* theFileName) = 0;
+  //! Returns the kind of the document: "PartSet", "Part", or something else.
+  //! This kind is used for feature buttons enable/disable depending on active document
+  //! (it uses workbench "document" identifier in XML configuration file for this)
+  virtual const std::string& kind() const = 0;
 
   //! Removes document data
-  MODELAPI_EXPORT virtual void close() = 0;
-
-  //! Starts a new operation (opens a tansaction)
-  MODELAPI_EXPORT virtual void startOperation() = 0;
-  //! Finishes the previously started operation (closes the transaction)
-  MODELAPI_EXPORT virtual void finishOperation() = 0;
-  //! Aborts the operation 
-  MODELAPI_EXPORT virtual void abortOperation() = 0;
-  //! Returns true if operation has been started, but not yet finished or aborted
-  MODELAPI_EXPORT virtual bool isOperation() = 0;
-  //! Returns true if document was modified (since creation/opening)
-  MODELAPI_EXPORT virtual bool isModified() = 0;
-
-  //! Returns True if there are available Undos
-  MODELAPI_EXPORT virtual bool canUndo() = 0;
-  //! Undoes last operation
-  MODELAPI_EXPORT virtual void undo() = 0;
-  //! Returns True if there are available Redos
-  MODELAPI_EXPORT virtual bool canRedo() = 0;
-  //! Redoes last operation
-  MODELAPI_EXPORT virtual void redo() = 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
-  MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> addFeature(std::string theID) = 0;
+  //! \param theID creates feature and puts it in the document (if it is not action)
+  //! \param theMakeCurrent to make current this new feature in this document
+  virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID, 
+    const bool theMakeCurrent = true) = 0;
+
+  //! Return a list of features, which refers to the feature
+  //! \param theFeature a feature
+  //! \param theRefs a list of features
+  //! \param isSendError a flag whether the error message should be send
+  virtual void refsToFeature(std::shared_ptr<ModelAPI_Feature> theFeature,
+                             std::set<std::shared_ptr<ModelAPI_Feature> >& theRefs,
+                             const bool isSendError = true) = 0;
 
   //! Removes the feature from the document
-  MODELAPI_EXPORT virtual void removeFeature(boost::shared_ptr<ModelAPI_Feature> theFeature) = 0;
+  //! \param theFeature a feature to be removed
+  virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature) = 0;
 
-  ///! Adds a new sub-document by the identifier, or returns existing one if it is already exist
-  MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Document> 
-    subDocument(std::string theDocID) = 0;
+  //! Moves the feature to make it after the given one in the history.
+  virtual void moveFeature(std::shared_ptr<ModelAPI_Feature> theMoved, 
+                           std::shared_ptr<ModelAPI_Feature> theAfterThis) = 0;
 
-  ///! Returns the id of hte document
-  MODELAPI_EXPORT virtual const std::string& id() const = 0;
+  ///! Returns the id of the document
+  virtual const int id() const = 0;
 
-  //! Returns the feature in the group by the index (started from zero)
-  //! \param theGroupID group that contains a feature
+  //! Returns the object in the group by the index (started from zero)
+  //! \param theGroupID group that contains an object
   //! \param theIndex zero-based index of feature in the group
-  //! \param isOperation if it is true, returns feature (not Object)
-  MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> 
-    feature(const std::string& theGroupID, const int theIndex, const bool isOperation = false) = 0;
-
-  //! Returns the number of features in the group
-  MODELAPI_EXPORT virtual int size(const std::string& theGroupID) = 0;
+  virtual std::shared_ptr<ModelAPI_Object> object(const std::string& theGroupID,
+                                                    const int theIndex) = 0;
+
+  //! Returns the first found object in the group by the object name
+  //! \param theGroupID group that contains an object
+  //! \param theName name of the object to search
+  //! \returns null if such object is not found
+  virtual std::shared_ptr<ModelAPI_Object> objectByName(const std::string& theGroupID,
+                                                    const std::string& theName) = 0;
+
+  //! Returns the object index in the group. Object must be visible. Otherwise returns -1.
+  //! \param theObject object of this document
+  //! \returns index started from zero, or -1 if object is invisible or belongs to another document
+  virtual const int index(std::shared_ptr<ModelAPI_Object> theObject) = 0;
+
+  //! Returns the number of objects in the group of objects
+  virtual int size(const std::string& theGroupID) = 0;
+
+  //! Returns the feature that is currently edited in this document, normally
+  //! this is the latest created feature
+  //! \param theVisible use visible features only: flag is true for Object Browser functionality
+  //! \returns null if next created feature must be the first
+  virtual std::shared_ptr<ModelAPI_Feature> currentFeature(const bool theVisible) = 0;
+
+  //! Sets the current feature: all features below will be disabled, new features
+  //! will be appended after this one.
+  //! \param theCurrent the selected feature as current: blow it everythin become disabled
+  //! \param theVisible use visible features only: flag is true for Object Browser functionality
+  virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent,
+    const bool theVisible) = 0;
+  //! Makes the current feature one feature upper
+  virtual void setCurrentFeatureUp() = 0;
+
+  //! Returns the number of all features: in the history or not
+  virtual int numInternalFeatures() = 0;
+  //! Returns the feature by zero-based index: features in the history or not
+  virtual std::shared_ptr<ModelAPI_Feature> internalFeature(const int theIndex) = 0;
+  //! Performs synchronization of transactions with the module document:
+  //! If some document is not active (by undo of activation) but in memory,
+  //! on activation the transactions must be synchronised because all redos performed 
+  //! wihtout this participation
+  virtual void synchronizeTransactions() = 0;
+
+  //! Returns feature by the id of the feature (produced by the Data "featureId" method)
+  virtual std::shared_ptr<ModelAPI_Feature> featureById(const int theId) = 0;
+
+  //! To virtually destroy the fields of successors
+  MODELAPI_EXPORT virtual ~ModelAPI_Document();
+
+  //! Creates a construction result
+  virtual std::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
+      const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
+  //! Creates a body result
+  virtual std::shared_ptr<ModelAPI_ResultBody> createBody(
+      const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
+  //! Creates a part result
+  virtual std::shared_ptr<ModelAPI_ResultPart> createPart(
+      const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
+  //! Copies a part result, keeping the reference to the origin
+  virtual std::shared_ptr<ModelAPI_ResultPart> copyPart(
+      const std::shared_ptr<ModelAPI_ResultPart>& theOrigin,
+      const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
+  //! Creates a group result
+  virtual std::shared_ptr<ModelAPI_ResultGroup> createGroup(
+      const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
+  //! Creates a parameter result
+  virtual std::shared_ptr<ModelAPI_ResultParameter> createParameter(
+      const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
+
+  //! Returns a feature by result (owner of result)
+  virtual std::shared_ptr<ModelAPI_Feature> feature(
+      const std::shared_ptr<ModelAPI_Result>& theResult) = 0;
+
+  //! Returns all features of the document including the hidden features which are not in
+  //! history. Not very fast method, for calling once, not in big cycles.
+  virtual std::list<std::shared_ptr<ModelAPI_Feature> > allFeatures() = 0;
+
+  //! Informs the document that it becomes active and some actions must be performed
+  virtual void setActive(const bool theFlag) = 0;
+  //! Returns true if this document is currently active
+  virtual bool isActive() const = 0;
+
+  /// Returns true if document is opened and valid
+  virtual bool isOpened() = 0;
 
-  /// To virtually destroy the fields of successors
-  virtual ~ModelAPI_Document() {}
 
 protected:
-  /// Only for SWIG wrapping it is here
-  MODELAPI_EXPORT ModelAPI_Document()
-  {}
-};
+  //! Only for SWIG wrapping it is here
+  MODELAPI_EXPORT ModelAPI_Document();
 
+  //! Internally makes document know that feature was removed or added in history after creation
+  MODELAPI_EXPORT virtual void updateHistory(const std::shared_ptr<ModelAPI_Object> theObject) = 0;
+  //! Internally makes document know that feature was removed or added in history after creation
+  MODELAPI_EXPORT virtual void updateHistory(const std::string theGroup) = 0;
 
-//! Pointer on document object
-typedef boost::shared_ptr<ModelAPI_Document> DocumentPtr;
+  friend class ModelAPI_Object; // to add or remove from the history
+  friend class ModelAPI_Result; // to add or remove from the history
+};
 
+//! Pointer on document object
+typedef std::shared_ptr<ModelAPI_Document> DocumentPtr;
 
 #endif