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