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