1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModelAPI_Feature.hxx
4 // Created: 21 Mar 2014
5 // Author: Mikhail PONIKAROV
7 #ifndef ModelAPI_Feature_H_
8 #define ModelAPI_Feature_H_
11 #include <ModelAPI_Object.h>
12 #include <ModelAPI_Data.h>
13 #include <ModelAPI_Document.h>
20 /**\class ModelAPI_Feature
22 * \brief Feature function that represents the particular functionality
23 * of this operation. Produces results by the arguments.
25 class ModelAPI_Feature : public ModelAPI_Object
27 ///< list of current results of this feature
28 std::list<std::shared_ptr<ModelAPI_Result> > myResults;
30 /// Returns the unique kind of a feature (like "Point")
31 virtual const std::string& getKind() = 0;
33 /// Returns the group identifier of all features
34 inline static std::string group()
36 static std::string MY_GROUP = "Features";
40 /// Returns document this feature belongs to
41 virtual std::shared_ptr<ModelAPI_Document> document() const
43 return ModelAPI_Object::document();
46 /// Returns the group identifier of this result
47 virtual std::string groupName()
52 /// Computes or recomputes the results
53 virtual void execute() = 0;
55 /// Computes the attribute value on the base of other attributes if the value can be computed
56 /// \param theAttributeId an attribute index to be computed
57 /// \return a boolean value about it is computed
58 virtual bool compute(const std::string& theAttributeId) { return false; };
60 /// Registers error during the execution, causes the ExecutionFailed state
61 virtual void setError(const std::string& theError) {
62 data()->setError(theError);
65 /// returns the current results of the feature
66 MODELAPI_EXPORT const std::list<std::shared_ptr<ModelAPI_Result> >& results();
67 /// returns the first result in the list or NULL reference
68 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Result> firstResult();
69 /// returns the last result in the list or NULL reference
70 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Result> lastResult();
71 /// sets the alone result
72 MODELAPI_EXPORT void setResult(const std::shared_ptr<ModelAPI_Result>& theResult);
73 /// sets the result by index (zero based), results before this must be set before
74 MODELAPI_EXPORT void setResult(const std::shared_ptr<ModelAPI_Result>& theResult,
76 /// removes the result from the feature
77 MODELAPI_EXPORT void removeResult(const std::shared_ptr<ModelAPI_Result>& theResult);
78 /// removes all results from the feature
79 MODELAPI_EXPORT void eraseResults();
80 /// removes all fields from this feature: results, data, etc
81 MODELAPI_EXPORT virtual void erase();
83 /// Returns true if result is persistent (stored in document) and on undo-redo, save-open
84 /// it is not needed to recompute it.
85 virtual bool isPersistentResult() {return true;}
87 /// Returns true if this feature must not be created: this is just an action
88 /// that is not stored in the features history and data model (like "delete part").
89 virtual bool isAction()
94 /// Must return document where the new feature must be added to
95 /// By default it is current document
96 MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Document> documentToAdd();
98 /// To virtually destroy the fields of successors
99 MODELAPI_EXPORT virtual ~ModelAPI_Feature();
101 /// Returns the feature by the object (result).
102 MODELAPI_EXPORT static std::shared_ptr<ModelAPI_Feature> feature(ObjectPtr theObject);
105 // Helper methods, aliases for data()->method()
106 // -----------------------------------------------------------------------------------------------
107 /// Returns the name stored in the attribute
108 inline std::string name()
110 return data()->name();
112 /// Returns the Boolean attribute by the identifier
113 inline std::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID)
115 return data()->boolean(theID);
117 /// Returns the document reference attribute
118 inline std::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID)
120 return data()->document(theID);
122 /// Returns the real attribute by the identifier
123 inline std::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID)
125 return data()->real(theID);
127 /// Returns the integer attribute by the identifier
128 inline std::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID)
130 return data()->integer(theID);
132 /// Returns the reference attribute by the identifier
133 inline std::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID)
135 return data()->refattr(theID);
137 /// Returns the reference attribute by the identifier
138 inline std::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID)
140 return data()->reference(theID);
142 /// Returns the list of references attribute by the identifier
143 inline std::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string& theID)
145 return data()->reflist(theID);
147 /// Returns the shape selection attribute by the identifier
148 inline std::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID)
150 return data()->selection(theID);
152 /// Returns the list of shape selections attribute by the identifier
153 inline std::shared_ptr<ModelAPI_AttributeSelectionList> selectionList(const std::string& theID)
155 return data()->selectionList(theID);
157 /// Returns the string attribute by the identifier
158 inline std::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID)
160 return data()->string(theID);
162 /// Returns the attribute by the identifier
163 inline std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID)
165 return data()->attribute(theID);
167 // -----------------------------------------------------------------------------------------------
170 //! Pointer on feature object
171 typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;