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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef ModelAPI_Feature_H_
22 #define ModelAPI_Feature_H_
25 #include <ModelAPI_Object.h>
26 #include <ModelAPI_Data.h>
27 #include <ModelAPI_Document.h>
34 /**\class ModelAPI_Feature
36 * \brief Feature function that represents the particular functionality
37 * of this operation. Produces results by the arguments.
39 class ModelAPI_Feature : public ModelAPI_Object
41 ///< list of current results of this feature
42 std::list<std::shared_ptr<ModelAPI_Result> > myResults;
43 ///< is feature disabled or not
45 ///< is feature is stable (not editing)
49 /// Returns the unique kind of a feature (like "Point")
50 virtual const std::string& getKind() = 0;
52 /// Returns the group identifier of all features
53 inline static std::string group()
55 static std::string MY_GROUP = "Features";
59 /// Returns document this feature belongs to
60 virtual std::shared_ptr<ModelAPI_Document> document() const
62 return ModelAPI_Object::document();
65 /// Returns the group identifier of this result
66 virtual std::string groupName()
71 /// Computes or recomputes the results
72 virtual void execute() = 0;
74 /// Computes the attribute value on the base of other attributes if the value can be computed
75 /// \param theAttributeId an attribute index to be computed
76 /// \return a boolean value about it is computed
77 virtual bool compute(const std::string& theAttributeId) { return false; };
79 /// Registers error during the execution, causes the ExecutionFailed state
80 MODELAPI_EXPORT virtual void setError(const std::string& theError,
82 bool isTranslate = true);
84 /// Returns error, arose during the execution
85 virtual std::string error() const {
86 return data()->error();
89 /// returns the current results of the feature
90 MODELAPI_EXPORT const std::list<std::shared_ptr<ModelAPI_Result> >& results();
91 /// returns the first result in the list or NULL reference
92 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Result> firstResult() const;
93 /// returns the last result in the list or NULL reference
94 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Result> lastResult();
95 /// sets the alone result
96 MODELAPI_EXPORT void setResult(const std::shared_ptr<ModelAPI_Result>& theResult);
97 /// sets the result by index (zero based), results before this must be set before
98 MODELAPI_EXPORT void setResult(const std::shared_ptr<ModelAPI_Result>& theResult,
100 /// removes all results starting from the given index (zero-based)
101 /// \param theSinceIndex - index of the deleted result and all after also will be deleted
102 /// \param theForever - removes results for long period (not just because of feature disabling)
103 /// \param theFlush - if it is false, REDISPLAY message is not flushed
104 MODELAPI_EXPORT void removeResults(const int theSinceIndex,
105 const bool theForever = true, const bool theFlush = true);
106 /// removes all results from the feature
107 MODELAPI_EXPORT void eraseResults(const bool theForever = true);
108 /// removes all fields from this feature: results, data, etc
109 MODELAPI_EXPORT virtual void erase();
110 /// removes the result from the list of feature (not doing in disabled): normally this
111 /// method is not used from features. only internally
112 MODELAPI_EXPORT void eraseResultFromList(const std::shared_ptr<ModelAPI_Result>& theResult);
114 /// Returns true if result is persistent (stored in document) and on undo-redo, save-open
115 /// it is not needed to recompute it.
116 virtual bool isPersistentResult() {return true;}
118 /// Returns true if this feature must not be created: this is just an action
119 /// that is not stored in the features history and data model (like "delete part").
120 virtual bool isAction()
125 /// Returns true if this feature is used as macro: creates other features and then removed.
126 /// \returns false by default
127 MODELAPI_EXPORT virtual bool isMacro() const;
129 /// Returns true if preview update during the edition needed. Otherwise the update-mechanism
130 /// calls the \a execute function only on "apply" of the operation
131 /// \returns true by default
132 MODELAPI_EXPORT virtual bool isPreviewNeeded() const;
134 /// Must return document where the new feature must be added to
135 /// By default it is empty: it is added to the document this method is called to
136 MODELAPI_EXPORT virtual const std::string& documentToAdd();
138 /// Enables/disables the feature. The disabled feature has no results and does not participate in
140 /// \returns true if state is really changed
141 MODELAPI_EXPORT virtual bool setDisabled(const bool theFlag);
143 /// Returns the feature is disabled or not.
144 MODELAPI_EXPORT virtual bool isDisabled();
146 /// To virtually destroy the fields of successors
147 MODELAPI_EXPORT virtual ~ModelAPI_Feature();
149 /// Returns the feature by the object (result).
150 MODELAPI_EXPORT static std::shared_ptr<ModelAPI_Feature> feature(ObjectPtr theObject);
152 /// Set the stable feature flag. If feature is currently editing then it is not stable.
153 /// \returns true if state is really changed
154 MODELAPI_EXPORT virtual bool setStable(const bool theFlag);
156 /// Returns the feature is stable or not.
157 MODELAPI_EXPORT virtual bool isStable();
159 /// Performs some custom feature specific functionality (normally called by some GUI button)
160 /// \param theActionId an action key
161 /// \return a boolean value about it is performed
162 MODELAPI_EXPORT virtual bool customAction(const std::string& theActionId);
165 // Helper methods, aliases for data()->method()
166 // -----------------------------------------------------------------------------------------------
167 /// Returns the name stored in the attribute
168 inline std::string name()
170 return data()->name();
172 /// Returns the Boolean attribute by the identifier
173 inline std::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID)
175 return data()->boolean(theID);
177 /// Returns the document reference attribute
178 inline std::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID)
180 return data()->document(theID);
182 /// Returns the real attribute by the identifier
183 inline std::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID)
185 return data()->real(theID);
187 /// Returns the integer attribute by the identifier
188 inline std::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID)
190 return data()->integer(theID);
192 /// Returns the integer array attribute by the identifier
193 inline std::shared_ptr<ModelAPI_AttributeIntArray> intArray(const std::string& theID)
195 return data()->intArray(theID);
197 /// Returns the reference attribute by the identifier
198 inline std::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID)
200 return data()->refattr(theID);
202 /// Returns the reference attribute by the identifier
203 inline std::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID)
205 return data()->reference(theID);
207 /// Returns the list of references attribute by the identifier
208 inline std::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string& theID)
210 return data()->reflist(theID);
212 /// Returns the shape selection attribute by the identifier
213 inline std::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID)
215 return data()->selection(theID);
217 /// Returns the list of shape selections attribute by the identifier
218 inline std::shared_ptr<ModelAPI_AttributeSelectionList> selectionList(const std::string& theID)
220 return data()->selectionList(theID);
222 /// Returns the string attribute by the identifier
223 inline std::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID)
225 return data()->string(theID);
227 /// Returns the string array attribute by the identifier
228 inline std::shared_ptr<ModelAPI_AttributeStringArray> stringArray(const std::string& theID)
230 return data()->stringArray(theID);
232 /// Returns the tables attribute by the identifier
233 inline std::shared_ptr<ModelAPI_AttributeTables> tables(const std::string& theID)
235 return data()->tables(theID);
237 /// Returns the attribute by the identifier
238 inline std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID)
240 return data()->attribute(theID);
243 /// This method is called just after creation of the object: it must initialize
244 /// all fields, normally initialized in the constructor
245 MODELAPI_EXPORT virtual void init();
247 friend class Model_Document;
248 friend class Model_Objects;
251 //! Pointer on feature object
252 typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;