]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_Document.h
Salome HOME
Provide feature-owner by result in document
[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   //! Returns the existing object: result or feature
76   //! \param theLabel base label of the object
77   MODEL_EXPORT virtual ObjectPtr object(TDF_Label& theLabel);
78
79   //! Adds a new sub-document by the identifier, or returns existing one if it is already exist
80   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> subDocument(std::string theDocID);
81
82   ///! Returns the id of hte document
83   MODEL_EXPORT virtual const std::string& id() const {return myID;}
84
85   //! Returns the feature in the group by the index (started from zero)
86   //! \param theGroupID group that contains a feature
87   //! \param theIndex zero-based index of feature in the group
88   //! \param isOperation if it is true, returns feature (not Object)
89   MODEL_EXPORT virtual ObjectPtr object(const std::string& theGroupID, const int theIndex);
90
91   //! Returns the number of features in the group
92   MODEL_EXPORT virtual int size(const std::string& theGroupID);
93
94   //! Allows to store the result in the data tree of the document (attaches 'data' of result to tree)
95   MODEL_EXPORT virtual void storeResult(boost::shared_ptr<ModelAPI_Data> theFeatureData,
96     boost::shared_ptr<ModelAPI_Result> theResult, const int theResultIndex = 0);
97
98   /// Creates a construction cresults
99   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultConstruction> createConstruction();
100   /// Creates a body results
101   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultBody> createBody();
102   /// Creates a part results
103   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultPart> createPart();
104
105   //! Returns a feature by result (owner of result)
106   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> 
107     feature(const boost::shared_ptr<ModelAPI_Result>& theResult);
108
109
110 protected:
111
112   //! Returns (creates if needed) the group label
113   TDF_Label groupLabel(const std::string theGroup);
114
115   //! Initializes feature with a unique name in this group (unique name is generated as 
116   //! feature type + "_" + index
117   void setUniqueName(FeaturePtr theFeature);
118
119   //! Synchronizes myFeatures list with the updated document
120   void synchronizeFeatures(const bool theMarkUpdated = false);
121
122   //! Creates new document with binary file format
123   Model_Document(const std::string theID);
124
125   Handle_TDocStd_Document document() {return myDoc;}
126
127   //! performas compactification of all nested operations into one
128   void compactNested();
129
130   //! Initializes the data fields of the feature
131   void Model_Document::initData(ObjectPtr theObj, TDF_Label& theLab, const int theTag);
132
133
134
135   friend class Model_Application;
136   friend class Model_PluginManager;
137   friend class DFBrowser;
138
139 private:
140   std::string myID; ///< identifier of the document in the application
141   Handle_TDocStd_Document myDoc; ///< OCAF document
142   /// number of transactions after the last "save" call, used for "IsModified" method
143   int myTransactionsAfterSave;
144   /// number of nested transactions performed (or -1 if not nested)
145   int myNestedNum;
146   /// All objects managed by this document (not only in history of OB)
147   std::map<std::string, std::vector<ObjectPtr> > myObjs;
148
149   ///< set of identifiers of sub-documents of this document
150   std::set<std::string> mySubs;
151   /// transaction indexes (related to myTransactionsAfterSave) which were empty in this doc
152   std::map<int, bool> myIsEmptyTr;
153 };
154
155 #endif