]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_Document.h
Salome HOME
f0bc738451488ad11bfb24feba474990054ce24a
[modules/shaper.git] / src / Model / Model_Document.h
1 // File:        Model_Document.h
2 // Created:     28 Feb 2014
3 // Author:      Mikhail PONIKAROV
4
5 #ifndef Model_Document_HeaderFile
6 #define Model_Document_HeaderFile
7
8 #include <Model.h>
9 #include <ModelAPI_Document.h>
10 #include <ModelAPI_Feature.h>
11 #include <ModelAPI_Result.h>
12
13 #include <TDocStd_Document.hxx>
14 #include <map>
15 #include <set>
16
17 class Handle_Model_Document;
18
19 /**\class Model_Document
20  * \ingroup DataModel
21  * \brief Document for internal data structure of any object storage.
22  * Document contains all data that must be stored/retrived in the file.
23  * Also it provides acces to this data: open/save, transactions management etc.
24  */
25 class Model_Document: public ModelAPI_Document
26 {
27 public:
28
29   //! Loads the OCAF document from the file.
30   //! \param theFileName full name of the file to load
31   //! \param theStudyID identifier of the SALOME study to associate with loaded file
32   //! \returns true if file was loaded successfully
33   MODEL_EXPORT virtual bool load(const char* theFileName);
34
35   //! Saves the OCAF document to the file.
36   //! \param theFileName full name of the file to store
37   //! \returns true if file was stored successfully
38   MODEL_EXPORT virtual bool save(const char* theFileName);
39
40   //! Removes document data
41   MODEL_EXPORT virtual void close();
42
43   //! Starts a new operation (opens a tansaction)
44   MODEL_EXPORT virtual void startOperation();
45   //! Finishes the previously started operation (closes the transaction)
46   //! Returns true if transaction in this document is not empty and really was performed
47   MODEL_EXPORT virtual void finishOperation();
48   //! Aborts the operation 
49   MODEL_EXPORT virtual void abortOperation();
50   //! Returns true if operation has been started, but not yet finished or aborted
51   MODEL_EXPORT virtual bool isOperation();
52   //! Returns true if document was modified (since creation/opening)
53   MODEL_EXPORT virtual bool isModified();
54
55   //! Returns True if there are available Undos
56   MODEL_EXPORT virtual bool canUndo();
57   //! Undoes last operation
58   MODEL_EXPORT virtual void undo();
59   //! Returns True if there are available Redos
60   MODEL_EXPORT virtual bool canRedo();
61   //! Redoes last operation
62   MODEL_EXPORT virtual void redo();
63
64   //! Adds to the document the new feature of the given feature id
65   //! \param creates feature and puts it in the document
66   MODEL_EXPORT virtual FeaturePtr addFeature(std::string theID);
67
68   //! Removes the feature from the document (with result)
69   MODEL_EXPORT virtual void removeFeature(FeaturePtr theFeature);
70
71   //! Returns the existing feature by the label
72   //! \param theLabel base label of the feature
73   MODEL_EXPORT virtual FeaturePtr feature(TDF_Label& theLabel);
74
75   //! Adds a new sub-document by the identifier, or returns existing one if it is already exist
76   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> subDocument(std::string theDocID);
77
78   ///! Returns the id of hte document
79   MODEL_EXPORT virtual const std::string& id() const {return myID;}
80
81   //! Returns the feature in the group by the index (started from zero)
82   //! \param theGroupID group that contains a feature
83   //! \param theIndex zero-based index of feature in the group
84   //! \param isOperation if it is true, returns feature (not Object)
85   MODEL_EXPORT virtual ObjectPtr object(const std::string& theGroupID, const int theIndex);
86
87   //! Returns the number of features in the group
88   MODEL_EXPORT virtual int size(const std::string& theGroupID);
89
90   //! Allows to store the result in the data tree of the document (attaches 'data' of result to tree)
91   MODEL_EXPORT virtual void storeResult(boost::shared_ptr<ModelAPI_Data> theFeatureData,
92     boost::shared_ptr<ModelAPI_Result> theResult, const int theResultIndex = 0);
93
94   /// Creates a construction cresults
95   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultConstruction> createConstruction();
96   /// Creates a body results
97   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultBody> createBody();
98   /// Creates a part results
99   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultPart> createPart();
100
101 protected:
102
103   //! Returns (creates if needed) the group label
104   TDF_Label groupLabel(const std::string theGroup);
105
106   //! Initializes feature with a unique name in this group (unique name is generated as 
107   //! feature type + "_" + index
108   void setUniqueName(FeaturePtr theFeature);
109
110   //! Synchronizes myFeatures list with the updated document
111   void synchronizeFeatures(const bool theMarkUpdated = false);
112
113   //! Creates new document with binary file format
114   Model_Document(const std::string theID);
115
116   Handle_TDocStd_Document document() {return myDoc;}
117
118   //! performas compactification of all nested operations into one
119   void compactNested();
120
121   //! Initializes the data fields of the feature
122   void Model_Document::initData(ObjectPtr theObj, TDF_Label& theLab, const int theTag);
123
124
125
126   friend class Model_Application;
127   friend class Model_PluginManager;
128   friend class DFBrowser;
129
130 private:
131   std::string myID; ///< identifier of the document in the application
132   Handle_TDocStd_Document myDoc; ///< OCAF document
133   /// number of transactions after the last "save" call, used for "IsModified" method
134   int myTransactionsAfterSave;
135   /// number of nested transactions performed (or -1 if not nested)
136   int myNestedNum;
137   /// All objects managed by this document (not only in history of OB)
138   std::map<std::string, std::vector<ObjectPtr> > myObjs;
139
140   ///< set of identifiers of sub-documents of this document
141   std::set<std::string> mySubs;
142   /// transaction indexes (related to myTransactionsAfterSave) which were empty in this doc
143   std::map<int, bool> myIsEmptyTr;
144 };
145
146 #endif