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