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>
12 #include <TDocStd_Document.hxx>
16 class Handle_Model_Document;
18 /**\class Model_Document
20 * \brief Document for internal data structure of any object storage.
21 * Document contains all data that must be stored/retrived in the file.
22 * Also it provides acces to this data: open/save, transactions management etc.
24 class Model_Document: public ModelAPI_Document
28 //! Loads the OCAF document from the file.
29 //! \param theFileName full name of the file to load
30 //! \param theStudyID identifier of the SALOME study to associate with loaded file
31 //! \returns true if file was loaded successfully
32 MODEL_EXPORT virtual bool load(const char* theFileName);
34 //! Saves the OCAF document to the file.
35 //! \param theFileName full name of the file to store
36 //! \returns true if file was stored successfully
37 MODEL_EXPORT virtual bool save(const char* theFileName);
39 //! Removes document data
40 MODEL_EXPORT virtual void close();
42 //! Starts a new operation (opens a tansaction)
43 MODEL_EXPORT virtual void startOperation();
44 //! Finishes the previously started operation (closes the transaction)
45 //! Returns true if transaction in this document is not empty and really was performed
46 MODEL_EXPORT virtual void finishOperation();
47 //! Aborts the operation
48 MODEL_EXPORT virtual void abortOperation();
49 //! Returns true if operation has been started, but not yet finished or aborted
50 MODEL_EXPORT virtual bool isOperation();
51 //! Returns true if document was modified (since creation/opening)
52 MODEL_EXPORT virtual bool isModified();
54 //! Returns True if there are available Undos
55 MODEL_EXPORT virtual bool canUndo();
56 //! Undoes last operation
57 MODEL_EXPORT virtual void undo();
58 //! Returns True if there are available Redos
59 MODEL_EXPORT virtual bool canRedo();
60 //! Redoes last operation
61 MODEL_EXPORT virtual void redo();
63 //! Adds to the document the new feature of the given feature id
64 //! \param creates feature and puts it in the document
65 MODEL_EXPORT virtual FeaturePtr addFeature(std::string theID);
67 //! Removes the feature from the document
68 MODEL_EXPORT virtual void removeFeature(FeaturePtr theFeature);
70 //! Returns the existing feature by the label
71 //! \param theLabel base label of the feature
72 MODEL_EXPORT virtual FeaturePtr feature(TDF_Label& theLabel);
74 //! Adds a new sub-document by the identifier, or returns existing one if it is already exist
75 MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> subDocument(std::string theDocID);
77 ///! Returns the id of hte document
78 MODEL_EXPORT virtual const std::string& id() const {return myID;}
80 //! Returns the feature in the group by the index (started from zero)
81 //! \param theGroupID group that contains a feature
82 //! \param theIndex zero-based index of feature in the group
83 //! \param isOperation if it is true, returns feature (not Object)
84 MODEL_EXPORT virtual FeaturePtr
85 feature(const std::string& theGroupID, const int theIndex, const bool isOperation = false);
87 //! Returns the number of features in the group
88 MODEL_EXPORT virtual int size(const std::string& theGroupID);
92 //! Returns (creates if needed) the group label
93 TDF_Label groupLabel(const std::string theGroup);
95 //! Initializes feature with a unique name in this group (unique name is generated as
96 //! feature type + "_" + index
97 void setUniqueName(FeaturePtr theFeature);
99 //! Adds to the document the new feature
100 void addFeature(const FeaturePtr theFeature);
102 //! Returns the object by the feature
103 FeaturePtr objectByFeature(
104 const FeaturePtr theFeature);
106 //! Synchronizes myFeatures list with the updated document
107 void synchronizeFeatures(const bool theMarkUpdated = false);
109 //! Creates new document with binary file format
110 Model_Document(const std::string theID);
112 Handle_TDocStd_Document document() {return myDoc;}
114 //! performas compactification of all nested operations into one
115 void compactNested();
117 friend class Model_Application;
118 friend class Model_PluginManager;
121 std::string myID; ///< identifier of the document in the application
122 Handle_TDocStd_Document myDoc; ///< OCAF document
123 /// number of transactions after the last "save" call, used for "IsModified" method
124 int myTransactionsAfterSave;
125 /// number of nested transactions performed (or -1 if not nested)
127 /// All features managed by this document (not only in history of OB)
128 std::vector<FeaturePtr > myFeatures;
130 ///< set of identifiers of sub-documents of this document
131 std::set<std::string> mySubs;
132 /// transaction indexes (related to myTransactionsAfterSave) which were empty in this doc
133 std::map<int, bool> myIsEmptyTr;