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>
11 #include <TDocStd_Document.hxx>
15 class Handle_Model_Document;
17 /**\class Model_Document
19 * \brief Document for internal data structure of any object storage. Corresponds to the SALOME study.
20 * Document contains all data of te SALOME Study specific to this module
21 * that must be written into the HDF file.
22 * Also it provides acces to this data: open/save, transactions management etc.
23 * to provide access to all stored data.
26 class Model_Document: public ModelAPI_Document
30 //! Loads the OCAF document from the file.
31 //! \param theFileName full name of the file to load
32 //! \param theStudyID identifier of the SALOME study to associate with loaded file
33 //! \returns true if file was loaded successfully
34 MODEL_EXPORT virtual bool load(const char* theFileName);
36 //! Saves the OCAF document to the file.
37 //! \param theFileName full name of the file to store
38 //! \returns true if file was stored successfully
39 MODEL_EXPORT virtual bool save(const char* theFileName);
41 //! Removes document data
42 MODEL_EXPORT virtual void close();
44 //! Starts a new operation (opens a tansaction)
45 MODEL_EXPORT virtual void startOperation();
46 //! Finishes the previously started operation (closes the transaction)
47 //! Returns true if transaction in this document is not empty and really was performed
48 MODEL_EXPORT virtual void finishOperation();
49 //! Aborts the operation
50 MODEL_EXPORT virtual void abortOperation();
51 //! Returns true if operation has been started, but not yet finished or aborted
52 MODEL_EXPORT virtual bool isOperation();
53 //! Returns true if document was modified (since creation/opening)
54 MODEL_EXPORT virtual bool isModified();
56 //! Returns True if there are available Undos
57 MODEL_EXPORT virtual bool canUndo();
58 //! Undoes last operation
59 MODEL_EXPORT virtual void undo();
60 //! Returns True if there are available Redos
61 MODEL_EXPORT virtual bool canRedo();
62 //! Redoes last operation
63 MODEL_EXPORT virtual void redo();
65 //! Adds to the document the new feature of the given feature id
66 //! \param creates feature and puts it in the document
67 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID);
69 //! Returns the existing feature by the label
70 //! \param theLabel base label of the feature
71 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Feature> feature(TDF_Label& theLabel);
73 //! Adds a new sub-document by the identifier, or returns existing one if it is already exist
74 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> subDocument(std::string theDocID);
76 //! Creates an iterator of the features by the specific groups
77 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Iterator> featuresIterator(
78 const std::string theGroup);
80 MODEL_EXPORT virtual const std::string& id() const {return myID;}
82 //! Returns the feature in the group by the index (started from zero)
83 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Feature>
84 feature(const std::string& theGroupID, const int theIndex);
86 ///! Returns the vector of groups already added to the document
87 MODEL_EXPORT virtual const std::vector<std::string>& getGroups() const;
89 //! Returns the index of feature in the group (zero based)
90 //! \retruns -1 if not found
91 MODEL_EXPORT virtual int featureIndex(std::shared_ptr<ModelAPI_Feature> theFeature);
95 //! Returns (creates if needed) the group label
96 TDF_Label groupLabel(const std::string theGroup);
98 //! Initializes feature with a unique name in this group (unique name is generated as
99 //! feature type + "_" + index
100 void setUniqueName(std::shared_ptr<ModelAPI_Feature> theFeature);
102 //! Adds to the document the new feature
103 void addFeature(const std::shared_ptr<ModelAPI_Feature> theFeature);
105 //! Synchronizes myGroups, myGroupsNames, myFeatures and mySubs list with the updated document
106 void synchronizeFeatures();
108 //! Creates new document with binary file format
109 Model_Document(const std::string theID);
111 friend class Model_Application;
114 std::string myID; ///< identifier of the document in the application
115 Handle_TDocStd_Document myDoc; ///< OCAF document
116 /// number of transactions after the last "save" call, used for "IsModified" method
117 int myTransactionsAfterSave;
118 /// root labels of the features groups identified by names
119 std::map<std::string, TDF_Label> myGroups;
120 std::vector<std::string> myGroupsNames; ///< names of added groups to the document
121 /// Features managed by this document: by group name
122 std::map<std::string, std::vector<std::shared_ptr<ModelAPI_Feature> > > myFeatures;
123 std::set<std::string> mySubs; ///< set of identifiers of sub-documents of this document
124 /// transaction indexes (related to myTransactionsAfterSave) which were empty in this doc
125 std::map<int, bool> myIsEmptyTr;