Salome HOME
Debugging Translation feature.
[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_ResultField;
27 class ModelAPI_ResultParameter;
28 class ModelAPI_Data;
29 class GeomAPI_Shape;
30
31 /**\class ModelAPI_Document
32  * \ingroup DataModel
33  * \brief Document for internal data structure of any object storage.
34  * Document contains all data that must be stored/retrived in the file.
35  * Also it provides acces to this data: open/save, transactions management etc.
36  */
37 class ModelAPI_Document: public ModelAPI_Entity
38 {
39 public:
40   //! Returns the kind of the document: "PartSet", "Part", or something else.
41   //! This kind is used for feature buttons enable/disable depending on active document
42   //! (it uses workbench "document" identifier in XML configuration file for this)
43   virtual const std::string& kind() const = 0;
44
45   //! Removes document data
46   //! \param theForever if it is false, document is just hiden
47   //!                   (to keep possibility make it back on Undo/Redo)
48   virtual void close(const bool theForever = false) = 0;
49
50   //! Adds to the document the new feature of the given feature id
51   //! \param theID creates feature and puts it in the document (if it is not action)
52   //! \param theMakeCurrent to make current this new feature in this document
53   virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID,
54     const bool theMakeCurrent = true) = 0;
55
56   //! Return a list of features, which refers to the feature
57   //! \param theFeature a feature
58   //! \param theRefs a list of features
59   //! \param isSendError a flag whether the error message should be send
60   virtual void refsToFeature(std::shared_ptr<ModelAPI_Feature> theFeature,
61                              std::set<std::shared_ptr<ModelAPI_Feature> >& theRefs,
62                              const bool isSendError = true) = 0;
63
64   //! Removes the feature from the document
65   //! \param theFeature a feature to be removed
66   virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature) = 0;
67
68   //! Moves the feature to make it after the given one in the history.
69   virtual void moveFeature(std::shared_ptr<ModelAPI_Feature> theMoved,
70                            std::shared_ptr<ModelAPI_Feature> theAfterThis) = 0;
71
72   ///! Returns the id of the document
73   virtual const int id() const = 0;
74
75   //! Returns the object in the group by the index (started from zero)
76   //! \param theGroupID group that contains an object
77   //! \param theIndex zero-based index of feature in the group
78   virtual std::shared_ptr<ModelAPI_Object> object(const std::string& theGroupID,
79                                                     const int theIndex) = 0;
80
81   //! Returns the first found object in the group by the object name
82   //! \param theGroupID group that contains an object
83   //! \param theName name of the object to search
84   //! \returns null if such object is not found
85   virtual std::shared_ptr<ModelAPI_Object> objectByName(const std::string& theGroupID,
86                                                     const std::string& theName) = 0;
87
88   //! Returns the object index in the group. Object must be visible. Otherwise returns -1.
89   //! \param theObject object of this document
90   //! \returns index started from zero, or -1 if object is invisible or belongs to another document
91   virtual const int index(std::shared_ptr<ModelAPI_Object> theObject) = 0;
92
93   //! Returns the number of objects in the group of objects
94   virtual int size(const std::string& theGroupID) = 0;
95
96   //! Returns the feature that is currently edited in this document, normally
97   //! this is the latest created feature
98   //! \param theVisible use visible features only: flag is true for Object Browser functionality
99   //! \returns null if next created feature must be the first
100   virtual std::shared_ptr<ModelAPI_Feature> currentFeature(const bool theVisible) = 0;
101
102   //! Sets the current feature: all features below will be disabled, new features
103   //! will be appended after this one. This method does not flushes the events appeared:
104   //! it will be done by the finishOperation, or direct flushes
105   //! \param theCurrent the selected feature as current: blow it everythin become disabled
106   //! \param theVisible use visible features only: flag is true for Object Browser functionality
107   virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent,
108     const bool theVisible) = 0;
109   //! Makes the current feature one feature upper
110   virtual void setCurrentFeatureUp() = 0;
111
112   //! Returns the number of all features: in the history or not
113   virtual int numInternalFeatures() = 0;
114   //! Returns the feature by zero-based index: features in the history or not
115   virtual std::shared_ptr<ModelAPI_Feature> internalFeature(const int theIndex) = 0;
116   //! Performs synchronization of transactions with the module document:
117   //! If some document is not active (by undo of activation) but in memory,
118   //! on activation the transactions must be synchronised because all redos performed
119   //! wihtout this participation
120   virtual void synchronizeTransactions() = 0;
121
122   //! Returns feature by the id of the feature (produced by the Data "featureId" method)
123   virtual std::shared_ptr<ModelAPI_Feature> featureById(const int theId) = 0;
124
125   //! To virtually destroy the fields of successors
126   MODELAPI_EXPORT virtual ~ModelAPI_Document();
127
128   //! Creates a construction result
129   virtual std::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
130       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
131   //! Creates a body result
132   virtual std::shared_ptr<ModelAPI_ResultBody> createBody(
133       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
134   //! Creates a part result
135   virtual std::shared_ptr<ModelAPI_ResultPart> createPart(
136       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
137   //! Copies a part result, keeping the reference to the origin
138   virtual std::shared_ptr<ModelAPI_ResultPart> copyPart(
139       const std::shared_ptr<ModelAPI_ResultPart>& theOrigin,
140       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
141   //! Creates a group result
142   virtual std::shared_ptr<ModelAPI_ResultGroup> createGroup(
143       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
144   //! Creates a field result
145   virtual std::shared_ptr<ModelAPI_ResultField> createField(
146       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
147   //! Creates a parameter result
148   virtual std::shared_ptr<ModelAPI_ResultParameter> createParameter(
149       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
150
151   //! Returns a feature by result (owner of result)
152   virtual std::shared_ptr<ModelAPI_Feature> feature(
153       const std::shared_ptr<ModelAPI_Result>& theResult) = 0;
154
155   //! Returns all features of the document including the hidden features which are not in
156   //! history. Not very fast method, for calling once, not in big cycles.
157   virtual std::list<std::shared_ptr<ModelAPI_Feature> > allFeatures() = 0;
158
159   //! Informs the document that it becomes active and some actions must be performed
160   virtual void setActive(const bool theFlag) = 0;
161   //! Returns true if this document is currently active
162   virtual bool isActive() const = 0;
163
164   /// Returns true if document is opened and valid
165   virtual bool isOpened() = 0;
166
167   /// Returns the feature that produced the given face of the given result.
168   virtual std::shared_ptr<ModelAPI_Feature> producedByFeature(
169     std::shared_ptr<ModelAPI_Result> theResult,
170     const std::shared_ptr<GeomAPI_Shape>& theShape) = 0;
171
172   /// Returns true if theLater is in history of features creation later than theCurrent
173   virtual bool isLater(std::shared_ptr<ModelAPI_Feature> theLater,
174                        std::shared_ptr<ModelAPI_Feature> theCurrent) const = 0;
175
176   //! Internally makes document know that feature was removed or added in history after creation
177   MODELAPI_EXPORT virtual void updateHistory(const std::string theGroup) = 0;
178
179   /// Stores in the document boolean flags: states of the nodes in the object browser.
180   /// Normally is called outside of the transaction, just before "save".
181   MODELAPI_EXPORT virtual void storeNodesState(const std::list<bool>& theStates) = 0;
182
183   /// Returns the stored nodes states. Normally it is calles just after "open".
184   /// Appends the values to theStates list.
185   MODELAPI_EXPORT virtual void restoreNodesState(std::list<bool>& theStates) const = 0;
186
187 protected:
188   //! Only for SWIG wrapping it is here
189   MODELAPI_EXPORT ModelAPI_Document();
190
191   //! Internally makes document know that feature was removed or added in history after creation
192   MODELAPI_EXPORT virtual void updateHistory(const std::shared_ptr<ModelAPI_Object> theObject) = 0;
193
194   friend class ModelAPI_Object; // to add or remove from the history
195   friend class ModelAPI_Result; // to add or remove from the history
196 };
197
198 //! Pointer on document object
199 typedef std::shared_ptr<ModelAPI_Document> DocumentPtr;
200
201 #endif