Salome HOME
Update the internal persistence mechanism of documents identification: on load/save...
[modules/shaper.git] / src / ModelAPI / ModelAPI_Document.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_Document.cxx
4 // Created:     28 Feb 2014
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef ModelAPI_Document_H_
8 #define ModelAPI_Document_H_
9
10 #include "ModelAPI.h"
11 #include "ModelAPI_Entity.h"
12
13 #include <string>
14 #include <memory>
15 #include <vector>
16 #include <list>
17 #include <set>
18
19 class ModelAPI_Feature;
20 class ModelAPI_Object;
21 class ModelAPI_Result;
22 class ModelAPI_ResultConstruction;
23 class ModelAPI_ResultBody;
24 class ModelAPI_ResultPart;
25 class ModelAPI_ResultGroup;
26 class ModelAPI_ResultParameter;
27 class ModelAPI_Data;
28
29 /**\class ModelAPI_Document
30  * \ingroup DataModel
31  * \brief Document for internal data structure of any object storage.
32  * Document contains all data that must be stored/retrived in the file.
33  * Also it provides acces to this data: open/save, transactions management etc.
34  */
35 class ModelAPI_Document: public ModelAPI_Entity
36 {
37 public:
38   //! Returns the kind of the document: "PartSet", "Part", or something else.
39   //! This kind is used for feature buttons enable/disable depending on active document
40   //! (it uses workbench "document" identifier in XML configuration file for this)
41   virtual const std::string& kind() const = 0;
42
43   //! Removes document data
44   //! \param theForever if it is false, document is just hiden (to keep possibility make it back on Undo/Redo)
45   virtual void close(const bool theForever = false) = 0;
46
47   //! Adds to the document the new feature of the given feature id
48   //! \param theID creates feature and puts it in the document (if it is not action)
49   //! \param theMakeCurrent to make current this new feature in this document
50   virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID, 
51     const bool theMakeCurrent = true) = 0;
52
53   //! Return a list of features, which refers to the feature
54   //! \param theFeature a feature
55   //! \param theRefs a list of features
56   //! \param isSendError a flag whether the error message should be send
57   virtual void refsToFeature(std::shared_ptr<ModelAPI_Feature> theFeature,
58                              std::set<std::shared_ptr<ModelAPI_Feature> >& theRefs,
59                              const bool isSendError = true) = 0;
60
61   //! Removes the feature from the document
62   //! \param theFeature a feature to be removed
63   virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature) = 0;
64
65   //! Moves the feature to make it after the given one in the history.
66   virtual void moveFeature(std::shared_ptr<ModelAPI_Feature> theMoved, 
67                            std::shared_ptr<ModelAPI_Feature> theAfterThis) = 0;
68
69   ///! Returns the id of the document
70   virtual const int id() const = 0;
71
72   //! Returns the object in the group by the index (started from zero)
73   //! \param theGroupID group that contains an object
74   //! \param theIndex zero-based index of feature in the group
75   virtual std::shared_ptr<ModelAPI_Object> object(const std::string& theGroupID,
76                                                     const int theIndex) = 0;
77
78   //! Returns the first found object in the group by the object name
79   //! \param theGroupID group that contains an object
80   //! \param theName name of the object to search
81   //! \returns null if such object is not found
82   virtual std::shared_ptr<ModelAPI_Object> objectByName(const std::string& theGroupID,
83                                                     const std::string& theName) = 0;
84
85   //! Returns the object index in the group. Object must be visible. Otherwise returns -1.
86   //! \param theObject object of this document
87   //! \returns index started from zero, or -1 if object is invisible or belongs to another document
88   virtual const int index(std::shared_ptr<ModelAPI_Object> theObject) = 0;
89
90   //! Returns the number of objects in the group of objects
91   virtual int size(const std::string& theGroupID) = 0;
92
93   //! Returns the feature that is currently edited in this document, normally
94   //! this is the latest created feature
95   //! \param theVisible use visible features only: flag is true for Object Browser functionality
96   //! \returns null if next created feature must be the first
97   virtual std::shared_ptr<ModelAPI_Feature> currentFeature(const bool theVisible) = 0;
98
99   //! Sets the current feature: all features below will be disabled, new features
100   //! will be appended after this one.
101   //! \param theCurrent the selected feature as current: blow it everythin become disabled
102   //! \param theVisible use visible features only: flag is true for Object Browser functionality
103   virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent,
104     const bool theVisible) = 0;
105   //! Makes the current feature one feature upper
106   virtual void setCurrentFeatureUp() = 0;
107
108   //! Returns the number of all features: in the history or not
109   virtual int numInternalFeatures() = 0;
110   //! Returns the feature by zero-based index: features in the history or not
111   virtual std::shared_ptr<ModelAPI_Feature> internalFeature(const int theIndex) = 0;
112   //! Performs synchronization of transactions with the module document:
113   //! If some document is not active (by undo of activation) but in memory,
114   //! on activation the transactions must be synchronised because all redos performed 
115   //! wihtout this participation
116   virtual void synchronizeTransactions() = 0;
117
118   //! Returns feature by the id of the feature (produced by the Data "featureId" method)
119   virtual std::shared_ptr<ModelAPI_Feature> featureById(const int theId) = 0;
120
121   //! To virtually destroy the fields of successors
122   MODELAPI_EXPORT virtual ~ModelAPI_Document();
123
124   //! Creates a construction result
125   virtual std::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
126       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
127   //! Creates a body result
128   virtual std::shared_ptr<ModelAPI_ResultBody> createBody(
129       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
130   //! Creates a part result
131   virtual std::shared_ptr<ModelAPI_ResultPart> createPart(
132       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
133   //! Copies a part result, keeping the reference to the origin
134   virtual std::shared_ptr<ModelAPI_ResultPart> copyPart(
135       const std::shared_ptr<ModelAPI_ResultPart>& theOrigin,
136       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
137   //! Creates a group result
138   virtual std::shared_ptr<ModelAPI_ResultGroup> createGroup(
139       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
140   //! Creates a parameter result
141   virtual std::shared_ptr<ModelAPI_ResultParameter> createParameter(
142       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
143
144   //! Returns a feature by result (owner of result)
145   virtual std::shared_ptr<ModelAPI_Feature> feature(
146       const std::shared_ptr<ModelAPI_Result>& theResult) = 0;
147
148   //! Returns all features of the document including the hidden features which are not in
149   //! history. Not very fast method, for calling once, not in big cycles.
150   virtual std::list<std::shared_ptr<ModelAPI_Feature> > allFeatures() = 0;
151
152   //! Informs the document that it becomes active and some actions must be performed
153   virtual void setActive(const bool theFlag) = 0;
154   //! Returns true if this document is currently active
155   virtual bool isActive() const = 0;
156
157   /// Returns true if document is opened and valid
158   virtual bool isOpened() = 0;
159
160
161 protected:
162   //! Only for SWIG wrapping it is here
163   MODELAPI_EXPORT ModelAPI_Document();
164
165   //! Internally makes document know that feature was removed or added in history after creation
166   MODELAPI_EXPORT virtual void updateHistory(const std::shared_ptr<ModelAPI_Object> theObject) = 0;
167   //! Internally makes document know that feature was removed or added in history after creation
168   MODELAPI_EXPORT virtual void updateHistory(const std::string theGroup) = 0;
169
170   friend class ModelAPI_Object; // to add or remove from the history
171   friend class ModelAPI_Result; // to add or remove from the history
172 };
173
174 //! Pointer on document object
175 typedef std::shared_ptr<ModelAPI_Document> DocumentPtr;
176
177 #endif