1 // File: Model_Document.h
2 // Created: 28 Feb 2014
3 // Author: Mikhail PONIKAROV
5 #ifndef Model_Document_HeaderFile
6 #define Model_Document_HeaderFile
9 #include <ModelAPI_Document.h>
10 #include <ModelAPI_Feature.h>
11 #include <ModelAPI_Result.h>
13 #include <TDocStd_Document.hxx>
17 class Handle_Model_Document;
19 /**\class Model_Document
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.
25 class Model_Document: public ModelAPI_Document
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);
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);
40 //! Removes document data
41 MODEL_EXPORT virtual void close();
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();
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();
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);
68 //! Removes the feature from the document (with result)
69 MODEL_EXPORT virtual void removeFeature(FeaturePtr theFeature);
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);
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);
78 ///! Returns the id of hte document
79 MODEL_EXPORT virtual const std::string& id() const {return myID;}
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);
87 //! Returns the number of features in the group
88 MODEL_EXPORT virtual int size(const std::string& theGroupID);
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);
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();
103 //! Returns (creates if needed) the group label
104 TDF_Label groupLabel(const std::string theGroup);
106 //! Initializes feature with a unique name in this group (unique name is generated as
107 //! feature type + "_" + index
108 void setUniqueName(FeaturePtr theFeature);
110 //! Synchronizes myFeatures list with the updated document
111 void synchronizeFeatures(const bool theMarkUpdated = false);
113 //! Creates new document with binary file format
114 Model_Document(const std::string theID);
116 Handle_TDocStd_Document document() {return myDoc;}
118 //! performas compactification of all nested operations into one
119 void compactNested();
121 //! Initializes the data fields of the feature
122 void Model_Document::initData(ObjectPtr theObj, TDF_Label& theLab, const int theTag);
126 friend class Model_Application;
127 friend class Model_PluginManager;
128 friend class DFBrowser;
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)
137 /// All objects managed by this document (not only in history of OB)
138 std::map<std::string, std::vector<ObjectPtr> > myObjs;
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;