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_AttributeBoolean.h>
11 #include <ModelAPI_AttributeDocRef.h>
12 #include <ModelAPI_AttributeDouble.h>
13 #include <ModelAPI_AttributeInteger.h>
14 #include <ModelAPI_AttributeRefAttr.h>
15 #include <ModelAPI_AttributeReference.h>
16 #include <ModelAPI_AttributeSelection.h>
17 #include <ModelAPI_AttributeSelectionList.h>
18 #include <ModelAPI_AttributeString.h>
19 #include <ModelAPI_AttributeRefList.h>
20 #include <ModelAPI_Data.h>
21 #include <ModelAPI_Document.h>
22 #include <ModelAPI_Result.h>
24 #include <boost/shared_ptr.hpp>
30 class ModelAPI_Document;
31 class ModelAPI_Result;
33 /**\class ModelAPI_Feature
35 * \brief Feature function that represents the particular functionality
36 * of this operation. Produces results by the arguments.
38 class ModelAPI_Feature : public ModelAPI_Object
40 ///< list of current results of this feature
41 std::list<boost::shared_ptr<ModelAPI_Result> > myResults;
43 /// Returns the unique kind of a feature (like "Point")
44 virtual const std::string& getKind() = 0;
46 /// Returns the group identifier of all features
47 static std::string group()
49 static std::string MY_GROUP = "Features";
53 /// Returns document this feature belongs to
54 virtual boost::shared_ptr<ModelAPI_Document> document()
56 return ModelAPI_Object::document();
59 /// Returns the group identifier of this result
60 virtual std::string groupName()
65 /// Request for initialization of data model of the feature: adding all attributes
66 virtual void initAttributes() = 0;
68 /// Computes or recomputes the results
69 virtual void execute() = 0;
71 /// returns the current results of the feature
72 MODELAPI_EXPORT const std::list<boost::shared_ptr<ModelAPI_Result> >& results();
73 /// returns the first result in the list or NULL reference
74 MODELAPI_EXPORT boost::shared_ptr<ModelAPI_Result> firstResult();
75 /// sets the alone result
76 MODELAPI_EXPORT void setResult(const boost::shared_ptr<ModelAPI_Result>& theResult);
77 /// sets the result by index (zero based), results before this must be set before
78 MODELAPI_EXPORT void setResult(const boost::shared_ptr<ModelAPI_Result>& theResult,
80 /// removes the result from the feature
81 MODELAPI_EXPORT void removeResult(const boost::shared_ptr<ModelAPI_Result>& theResult);
82 /// removes all results from the feature
83 MODELAPI_EXPORT void eraseResults();
84 /// removes all fields from this feature: results, data, etc
85 MODELAPI_EXPORT virtual void erase();
87 /// Returns true if result is persistent (stored in document) and on undo-redo, save-open
88 /// it is not needed to recompute it.
89 virtual bool isPersistentResult() {return true;}
91 /// Returns true if this feature must not be created: this is just an action
92 /// that is not stored in the features history and data model (like "delete part").
93 virtual bool isAction()
98 /// Must return document where the new feature must be added to
99 /// By default it is current document
100 MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Document> documentToAdd();
102 /// To virtually destroy the fields of successors
103 MODELAPI_EXPORT virtual ~ModelAPI_Feature();
105 MODELAPI_EXPORT static boost::shared_ptr<ModelAPI_Feature> feature(ObjectPtr theObject);
108 // Helper methods, aliases for data()->method()
109 // -----------------------------------------------------------------------------------------------
110 inline std::string name()
112 return data()->name();
115 inline boost::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID)
117 return data()->boolean(theID);
120 inline boost::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID)
122 return data()->document(theID);
125 inline boost::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID)
127 return data()->real(theID);
130 inline boost::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID)
132 return data()->integer(theID);
135 inline boost::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID)
137 return data()->refattr(theID);
140 inline boost::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID)
142 return data()->reference(theID);
145 inline boost::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string& theID)
147 return data()->reflist(theID);
150 inline boost::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID)
152 return data()->selection(theID);
155 inline boost::shared_ptr<ModelAPI_AttributeSelectionList> selectionList(const std::string& theID)
157 return data()->selectionList(theID);
160 inline boost::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID)
162 return data()->string(theID);
165 inline boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID)
167 return data()->attribute(theID);
169 // -----------------------------------------------------------------------------------------------
172 //! Pointer on feature object
173 typedef boost::shared_ptr<ModelAPI_Feature> FeaturePtr;