1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #ifndef ModelAPI_Document_H_
21 #define ModelAPI_Document_H_
24 #include "ModelAPI_Entity.h"
32 class ModelAPI_Feature;
33 class ModelAPI_Object;
34 class ModelAPI_Result;
35 class ModelAPI_ResultConstruction;
36 class ModelAPI_ResultBody;
37 class ModelAPI_ResultPart;
38 class ModelAPI_ResultGroup;
39 class ModelAPI_ResultField;
40 class ModelAPI_ResultParameter;
44 /**\class ModelAPI_Document
46 * \brief Document for internal data structure of any object storage.
47 * Document contains all data that must be stored/retrived in the file.
48 * Also it provides acces to this data: open/save, transactions management etc.
50 class ModelAPI_Document: public ModelAPI_Entity
53 //! Returns the kind of the document: "PartSet", "Part", or something else.
54 //! This kind is used for feature buttons enable/disable depending on active document
55 //! (it uses workbench "document" identifier in XML configuration file for this)
56 virtual const std::string& kind() const = 0;
58 //! Removes document data
59 //! \param theForever if it is false, document is just hiden
60 //! (to keep possibility make it back on Undo/Redo)
61 virtual void close(const bool theForever = false) = 0;
63 //! Adds to the document the new feature of the given feature id
64 //! \param theID creates feature and puts it in the document (if it is not action)
65 //! \param theMakeCurrent to make current this new feature in this document
66 virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID,
67 const bool theMakeCurrent = true) = 0;
69 //! Return a list of features, which refers to the feature
70 //! \param theFeature a feature
71 //! \param theRefs a list of features
72 //! \param isSendError a flag whether the error message should be send
73 virtual void refsToFeature(std::shared_ptr<ModelAPI_Feature> theFeature,
74 std::set<std::shared_ptr<ModelAPI_Feature> >& theRefs,
75 const bool isSendError = true) = 0;
77 //! Removes the feature from the document
78 //! \param theFeature a feature to be removed
79 virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature) = 0;
81 //! Moves the feature to make it after the given one in the history.
82 virtual void moveFeature(std::shared_ptr<ModelAPI_Feature> theMoved,
83 std::shared_ptr<ModelAPI_Feature> theAfterThis) = 0;
85 ///! Returns the id of the document
86 virtual const int id() const = 0;
88 //! Returns the object in the group by the index (started from zero)
89 //! \param theGroupID group that contains an object
90 //! \param theIndex zero-based index of feature in the group
91 virtual std::shared_ptr<ModelAPI_Object> object(const std::string& theGroupID,
92 const int theIndex) = 0;
94 //! Returns the first found object in the group by the object name
95 //! \param theGroupID group that contains an object
96 //! \param theName name of the object to search
97 //! \returns null if such object is not found
98 virtual std::shared_ptr<ModelAPI_Object> objectByName(const std::string& theGroupID,
99 const std::string& theName) = 0;
101 //! Returns the object index in the group. Object must be visible. Otherwise returns -1.
102 //! \param theObject object of this document
103 //! \returns index started from zero, or -1 if object is invisible or belongs to another document
104 virtual const int index(std::shared_ptr<ModelAPI_Object> theObject) = 0;
106 //! Returns the number of objects in the group of objects
107 virtual int size(const std::string& theGroupID) = 0;
109 //! Returns the feature that is currently edited in this document, normally
110 //! this is the latest created feature
111 //! \param theVisible use visible features only: flag is true for Object Browser functionality
112 //! \returns null if next created feature must be the first
113 virtual std::shared_ptr<ModelAPI_Feature> currentFeature(const bool theVisible) = 0;
115 //! Sets the current feature: all features below will be disabled, new features
116 //! will be appended after this one. This method does not flushes the events appeared:
117 //! it will be done by the finishOperation, or direct flushes
118 //! \param theCurrent the selected feature as current: blow it everythin become disabled
119 //! \param theVisible use visible features only: flag is true for Object Browser functionality
120 virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent,
121 const bool theVisible) = 0;
122 //! Makes the current feature one feature upper
123 virtual void setCurrentFeatureUp() = 0;
125 //! Returns the number of all features: in the history or not
126 virtual int numInternalFeatures() = 0;
127 //! Returns the feature by zero-based index: features in the history or not
128 virtual std::shared_ptr<ModelAPI_Feature> internalFeature(const int theIndex) = 0;
129 //! Performs synchronization of transactions with the module document:
130 //! If some document is not active (by undo of activation) but in memory,
131 //! on activation the transactions must be synchronised because all redos performed
132 //! wihtout this participation
133 virtual void synchronizeTransactions() = 0;
135 //! Returns feature by the id of the feature (produced by the Data "featureId" method)
136 virtual std::shared_ptr<ModelAPI_Feature> featureById(const int theId) = 0;
138 //! To virtually destroy the fields of successors
139 MODELAPI_EXPORT virtual ~ModelAPI_Document();
141 //! Creates a construction result
142 virtual std::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
143 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
144 //! Creates a body result
145 virtual std::shared_ptr<ModelAPI_ResultBody> createBody(
146 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
147 //! Creates a part result
148 virtual std::shared_ptr<ModelAPI_ResultPart> createPart(
149 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
150 //! Copies a part result, keeping the reference to the origin
151 virtual std::shared_ptr<ModelAPI_ResultPart> copyPart(
152 const std::shared_ptr<ModelAPI_ResultPart>& theOrigin,
153 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
154 //! Creates a group result
155 virtual std::shared_ptr<ModelAPI_ResultGroup> createGroup(
156 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
157 //! Creates a field result
158 virtual std::shared_ptr<ModelAPI_ResultField> createField(
159 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
160 //! Creates a parameter result
161 virtual std::shared_ptr<ModelAPI_ResultParameter> createParameter(
162 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
164 //! Returns a feature by result (owner of result)
165 virtual std::shared_ptr<ModelAPI_Feature> feature(
166 const std::shared_ptr<ModelAPI_Result>& theResult) = 0;
168 //! Returns all features of the document including the hidden features which are not in
169 //! history. Not very fast method, for calling once, not in big cycles.
170 virtual std::list<std::shared_ptr<ModelAPI_Feature> > allFeatures() = 0;
172 //! Informs the document that it becomes active and some actions must be performed
173 virtual void setActive(const bool theFlag) = 0;
174 //! Returns true if this document is currently active
175 virtual bool isActive() const = 0;
177 /// Returns true if document is opened and valid
178 virtual bool isOpened() = 0;
180 /// Returns the feature that produced the given face of the given result.
181 virtual std::shared_ptr<ModelAPI_Feature> producedByFeature(
182 std::shared_ptr<ModelAPI_Result> theResult,
183 const std::shared_ptr<GeomAPI_Shape>& theShape) = 0;
185 /// Returns true if theLater is in history of features creation later than theCurrent
186 virtual bool isLater(std::shared_ptr<ModelAPI_Feature> theLater,
187 std::shared_ptr<ModelAPI_Feature> theCurrent) const = 0;
189 //! Internally makes document know that feature was removed or added in history after creation
190 MODELAPI_EXPORT virtual void updateHistory(const std::string theGroup) = 0;
192 /// Stores in the document boolean flags: states of the nodes in the object browser.
193 /// Normally is called outside of the transaction, just before "save".
194 MODELAPI_EXPORT virtual void storeNodesState(const std::list<bool>& theStates) = 0;
196 /// Returns the stored nodes states. Normally it is calles just after "open".
197 /// Appends the values to theStates list.
198 MODELAPI_EXPORT virtual void restoreNodesState(std::list<bool>& theStates) const = 0;
200 /// Just removes all features without touching the document data (to be able undo)
201 MODELAPI_EXPORT virtual void eraseAllFeatures() = 0;
204 //! Only for SWIG wrapping it is here
205 MODELAPI_EXPORT ModelAPI_Document();
207 //! Internally makes document know that feature was removed or added in history after creation
208 MODELAPI_EXPORT virtual void updateHistory(const std::shared_ptr<ModelAPI_Object> theObject) = 0;
210 friend class ModelAPI_Object; // to add or remove from the history
211 friend class ModelAPI_Result; // to add or remove from the history
214 //! Pointer on document object
215 typedef std::shared_ptr<ModelAPI_Document> DocumentPtr;