1 // File: ModelAPI_Feature.hxx
2 // Created: 21 Mar 2014
3 // Author: Mikhail PONIKAROV
5 #ifndef ModelAPI_Feature_H_
6 #define ModelAPI_Feature_H_
9 #include <ModelAPI_Object.h>
10 #include <ModelAPI_Data.h>
11 #include <ModelAPI_Document.h>
18 /**\class ModelAPI_Feature
20 * \brief Feature function that represents the particular functionality
21 * of this operation. Produces results by the arguments.
23 class ModelAPI_Feature : public ModelAPI_Object
25 ///< list of current results of this feature
26 std::list<std::shared_ptr<ModelAPI_Result> > myResults;
28 /// Returns the unique kind of a feature (like "Point")
29 virtual const std::string& getKind() = 0;
31 /// Returns the group identifier of all features
32 static std::string group()
34 static std::string MY_GROUP = "Features";
38 /// Returns document this feature belongs to
39 virtual std::shared_ptr<ModelAPI_Document> document() const
41 return ModelAPI_Object::document();
44 /// Returns the group identifier of this result
45 virtual std::string groupName()
50 /// Request for initialization of data model of the feature: adding all attributes
51 virtual void initAttributes() = 0;
53 /// Computes or recomputes the results
54 virtual void execute() = 0;
56 /// Registers error during the execution, causes the ExecutionFailed state
57 virtual void setError(const std::string& theError) {
58 data()->setError(theError);
61 /// returns the current results of the feature
62 MODELAPI_EXPORT const std::list<std::shared_ptr<ModelAPI_Result> >& results();
63 /// returns the first result in the list or NULL reference
64 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Result> firstResult();
65 /// returns the last result in the list or NULL reference
66 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Result> lastResult();
67 /// sets the alone result
68 MODELAPI_EXPORT void setResult(const std::shared_ptr<ModelAPI_Result>& theResult);
69 /// sets the result by index (zero based), results before this must be set before
70 MODELAPI_EXPORT void setResult(const std::shared_ptr<ModelAPI_Result>& theResult,
72 /// removes the result from the feature
73 MODELAPI_EXPORT void removeResult(const std::shared_ptr<ModelAPI_Result>& theResult);
74 /// removes all results from the feature
75 MODELAPI_EXPORT void eraseResults();
76 /// removes all fields from this feature: results, data, etc
77 MODELAPI_EXPORT virtual void erase();
79 /// Returns true if result is persistent (stored in document) and on undo-redo, save-open
80 /// it is not needed to recompute it.
81 virtual bool isPersistentResult() {return true;}
83 /// Returns true if this feature must not be created: this is just an action
84 /// that is not stored in the features history and data model (like "delete part").
85 virtual bool isAction()
90 /// Must return document where the new feature must be added to
91 /// By default it is current document
92 MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Document> documentToAdd();
94 /// To virtually destroy the fields of successors
95 MODELAPI_EXPORT virtual ~ModelAPI_Feature();
97 MODELAPI_EXPORT static std::shared_ptr<ModelAPI_Feature> feature(ObjectPtr theObject);
100 // Helper methods, aliases for data()->method()
101 // -----------------------------------------------------------------------------------------------
102 inline std::string name()
104 return data()->name();
107 inline std::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID)
109 return data()->boolean(theID);
112 inline std::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID)
114 return data()->document(theID);
117 inline std::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID)
119 return data()->real(theID);
122 inline std::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID)
124 return data()->integer(theID);
127 inline std::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID)
129 return data()->refattr(theID);
132 inline std::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID)
134 return data()->reference(theID);
137 inline std::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string& theID)
139 return data()->reflist(theID);
142 inline std::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID)
144 return data()->selection(theID);
147 inline std::shared_ptr<ModelAPI_AttributeSelectionList> selectionList(const std::string& theID)
149 return data()->selectionList(theID);
152 inline std::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID)
154 return data()->string(theID);
157 inline std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID)
159 return data()->attribute(theID);
161 // -----------------------------------------------------------------------------------------------
164 //! Pointer on feature object
165 typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;