]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_Document.h
Salome HOME
Initial version of redesign of working with results
[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(
92     boost::shared_ptr<ModelAPI_Result> theResult, const int theResultIndex);
93
94   /// Creates a construction cresults
95   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultConstruction> createConstruction();
96
97 protected:
98
99   //! Returns (creates if needed) the group label
100   TDF_Label groupLabel(const std::string theGroup);
101
102   //! Initializes feature with a unique name in this group (unique name is generated as 
103   //! feature type + "_" + index
104   void setUniqueName(FeaturePtr theFeature);
105
106   //! Synchronizes myFeatures list with the updated document
107   void synchronizeFeatures(const bool theMarkUpdated = false);
108
109   //! Creates new document with binary file format
110   Model_Document(const std::string theID);
111
112   Handle_TDocStd_Document document() {return myDoc;}
113
114   //! performas compactification of all nested operations into one
115   void compactNested();
116
117   //! Initializes the data fields of the feature
118   void Model_Document::initData(ObjectPtr theObj, TDF_Label& theLab, const int theTag);
119
120
121
122   friend class Model_Application;
123   friend class Model_PluginManager;
124   friend class DFBrowser;
125
126 private:
127   std::string myID; ///< identifier of the document in the application
128   Handle_TDocStd_Document myDoc; ///< OCAF document
129   /// number of transactions after the last "save" call, used for "IsModified" method
130   int myTransactionsAfterSave;
131   /// number of nested transactions performed (or -1 if not nested)
132   int myNestedNum;
133   /// All objects managed by this document (not only in history of OB)
134   std::map<std::string, std::vector<ObjectPtr> > myObjs;
135
136   ///< set of identifiers of sub-documents of this document
137   std::set<std::string> mySubs;
138   /// transaction indexes (related to myTransactionsAfterSave) which were empty in this doc
139   std::map<int, bool> myIsEmptyTr;
140 };
141
142 #endif