Salome HOME
0a1a7f5b09c0f839d55fccb88ee08021977554c0
[modules/shaper.git] / src / ModelAPI / ModelAPI_Document.h
1 // File:        ModelAPI_Document.cxx
2 // Created:     28 Feb 2014
3 // Author:      Mikhail PONIKAROV
4
5 #ifndef ModelAPI_Document_HeaderFile
6 #define ModelAPI_Document_HeaderFile
7
8 #include <ModelAPI.h>
9 #include <string>
10 #include <boost/shared_ptr.hpp>
11 #include <vector>
12
13 class ModelAPI_Feature;
14 class ModelAPI_Object;
15 class ModelAPI_Result;
16 class ModelAPI_ResultConstruction;
17 class ModelAPI_ResultBody;
18 class ModelAPI_ResultPart;
19 class ModelAPI_Data;
20
21 /**\class Model_Document
22  * \ingroup DataModel
23  * \brief Document for internal data structure of any object storage.
24  * Document contains all data that must be stored/retrived in the file.
25  * Also it provides acces to this data: open/save, transactions management etc.
26  */
27 class ModelAPI_Document
28 {
29 public:
30   //! Loads the OCAF document from the file.
31   //! \param theFileName full name of the file to load
32   //! \param theStudyID identifier of the SALOME study to associate with loaded file
33   //! \returns true if file was loaded successfully
34   virtual bool load(const char* theFileName) = 0;
35
36   //! Saves the OCAF document to the file.
37   //! \param theFileName full name of the file to store
38   //! \returns true if file was stored successfully
39   virtual bool save(const char* theFileName) = 0;
40
41   //! Removes document data
42   virtual void close() = 0;
43
44   //! Starts a new operation (opens a tansaction)
45   virtual void startOperation() = 0;
46   //! Finishes the previously started operation (closes the transaction)
47   virtual void finishOperation() = 0;
48   //! Aborts the operation 
49   virtual void abortOperation() = 0;
50   //! Returns true if operation has been started, but not yet finished or aborted
51   virtual bool isOperation() = 0;
52   //! Returns true if document was modified (since creation/opening)
53   virtual bool isModified() = 0;
54
55   //! Returns True if there are available Undos
56   virtual bool canUndo() = 0;
57   //! Undoes last operation
58   virtual void undo() = 0;
59   //! Returns True if there are available Redos
60   virtual bool canRedo() = 0;
61   //! Redoes last operation
62   virtual void redo() = 0;
63
64   //! Adds to the document the new feature of the given feature id
65   //! \param creates feature and puts it in the document (if it is not action)
66   virtual boost::shared_ptr<ModelAPI_Feature> addFeature(std::string theID) = 0;
67
68   //! Removes the feature from the document
69   virtual void removeFeature(boost::shared_ptr<ModelAPI_Feature> theFeature) = 0;
70
71   ///! Adds a new sub-document by the identifier, or returns existing one if it is already exist
72   virtual boost::shared_ptr<ModelAPI_Document> 
73     subDocument(std::string theDocID) = 0;
74
75   ///! Returns the id of the document
76   virtual const std::string& id() const = 0;
77
78   //! Returns the object in the group by the index (started from zero)
79   //! \param theGroupID group that contains an object
80   //! \param theIndex zero-based index of feature in the group
81   virtual boost::shared_ptr<ModelAPI_Object> 
82     object(const std::string& theGroupID, const int theIndex) = 0;
83
84   //! Returns the number of objects in the group of objects
85   virtual int size(const std::string& theGroupID) = 0;
86
87   /// To virtually destroy the fields of successors
88   virtual ~ModelAPI_Document() {}
89
90   /// Creates a construction cresults
91   virtual boost::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
92     const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
93   /// Creates a body results
94   virtual boost::shared_ptr<ModelAPI_ResultBody> createBody(
95     const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
96   /// Creates a part results
97   virtual boost::shared_ptr<ModelAPI_ResultPart> createPart(
98     const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
99
100   //! Allows to store the result in the data tree of the document (attaches 'data' of result to tree)
101   virtual void storeResult(boost::shared_ptr<ModelAPI_Data> theFeatureData,
102     boost::shared_ptr<ModelAPI_Result> theResult, const int theResultIndex = 0) = 0;
103
104   //! Returns a feature by result (owner of result)
105   virtual boost::shared_ptr<ModelAPI_Feature> feature(
106     const boost::shared_ptr<ModelAPI_Result>& theResult) = 0;
107
108 protected:
109   /// Only for SWIG wrapping it is here
110   MODELAPI_EXPORT ModelAPI_Document()
111   {}
112 };
113
114
115 //! Pointer on document object
116 typedef boost::shared_ptr<ModelAPI_Document> DocumentPtr;
117
118
119 #endif