Salome HOME
Refactoring: static constants are replaced by inline functions in:
[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
15 /**\class Model_Document
16  * \ingroup DataModel
17  * \brief Document for internal data structure of any object storage.
18  * Document contains all data that must be stored/retrived in the file.
19  * Also it provides acces to this data: open/save, transactions management etc.
20  */
21 class ModelAPI_Document
22 {
23 public:
24   //! Common groups identifiers
25   //! Group of parameters
26   inline static const std::string& PARAMETERS_GROUP()
27   {
28     static const std::string MY_PARAMETERS_GROUP = "Parameters";
29     return MY_PARAMETERS_GROUP;
30   }
31   //! Group of constructions
32   inline static const std::string& CONSTRUCTIONS_GROUP()
33   {
34     static const std::string MY_CONSTRUCTIONS_GROUP = "Construction";
35     return MY_CONSTRUCTIONS_GROUP;
36   }
37   //! Group of parts
38   inline static const std::string& PARTS_GROUP()
39   {
40     static const std::string MY_PARTS_GROUP = "Parts";
41     return MY_PARTS_GROUP;
42   }
43   //! All created fetaures of the document (a history)
44   inline static const std::string& FEATURES_GROUP()
45   {
46     static const std::string MY_FEATURES_GROUP = "Features";
47     return MY_FEATURES_GROUP;
48   }
49
50   //! Loads the OCAF document from the file.
51   //! \param theFileName full name of the file to load
52   //! \param theStudyID identifier of the SALOME study to associate with loaded file
53   //! \returns true if file was loaded successfully
54   MODELAPI_EXPORT virtual bool load(const char* theFileName) = 0;
55
56   //! Saves the OCAF document to the file.
57   //! \param theFileName full name of the file to store
58   //! \returns true if file was stored successfully
59   MODELAPI_EXPORT virtual bool save(const char* theFileName) = 0;
60
61   //! Removes document data
62   MODELAPI_EXPORT virtual void close() = 0;
63
64   //! Starts a new operation (opens a tansaction)
65   MODELAPI_EXPORT virtual void startOperation() = 0;
66   //! Finishes the previously started operation (closes the transaction)
67   MODELAPI_EXPORT virtual void finishOperation() = 0;
68   //! Aborts the operation 
69   MODELAPI_EXPORT virtual void abortOperation() = 0;
70   //! Returns true if operation has been started, but not yet finished or aborted
71   MODELAPI_EXPORT virtual bool isOperation() = 0;
72   //! Returns true if document was modified (since creation/opening)
73   MODELAPI_EXPORT virtual bool isModified() = 0;
74
75   //! Returns True if there are available Undos
76   MODELAPI_EXPORT virtual bool canUndo() = 0;
77   //! Undoes last operation
78   MODELAPI_EXPORT virtual void undo() = 0;
79   //! Returns True if there are available Redos
80   MODELAPI_EXPORT virtual bool canRedo() = 0;
81   //! Redoes last operation
82   MODELAPI_EXPORT virtual void redo() = 0;
83
84   //! Adds to the document the new feature of the given feature id
85   //! \param creates feature and puts it in the document
86   MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> addFeature(std::string theID) = 0;
87
88   //! Removes the feature from the document
89   MODELAPI_EXPORT virtual void removeFeature(boost::shared_ptr<ModelAPI_Feature> theFeature) = 0;
90
91   ///! Adds a new sub-document by the identifier, or returns existing one if it is already exist
92   MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Document> 
93     subDocument(std::string theDocID) = 0;
94
95   ///! Returns the id of hte document
96   MODELAPI_EXPORT virtual const std::string& id() const = 0;
97
98   //! Returns the feature in the group by the index (started from zero)
99   //! \param theGroupID group that contains a feature
100   //! \param theIndex zero-based index of feature in the group
101   //! \param isOperation if it is true, returns feature (not Object)
102   MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> 
103     feature(const std::string& theGroupID, const int theIndex, const bool isOperation = false) = 0;
104
105   //! Returns the number of features in the group
106   MODELAPI_EXPORT virtual int size(const std::string& theGroupID) = 0;
107
108   /// To virtually destroy the fields of successors
109   virtual ~ModelAPI_Document() {}
110
111 protected:
112   /// Only for SWIG wrapping it is here
113   MODELAPI_EXPORT ModelAPI_Document()
114   {}
115 };
116
117
118 //! Pointer on document object
119 typedef boost::shared_ptr<ModelAPI_Document> DocumentPtr;
120
121
122 #endif