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() const
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 /// returns the last result in the list or NULL reference
76 MODELAPI_EXPORT boost::shared_ptr<ModelAPI_Result> lastResult();
77 /// sets the alone result
78 MODELAPI_EXPORT void setResult(const boost::shared_ptr<ModelAPI_Result>& theResult);
79 /// sets the result by index (zero based), results before this must be set before
80 MODELAPI_EXPORT void setResult(const boost::shared_ptr<ModelAPI_Result>& theResult,
82 /// removes the result from the feature
83 MODELAPI_EXPORT void removeResult(const boost::shared_ptr<ModelAPI_Result>& theResult);
84 /// removes all results from the feature
85 MODELAPI_EXPORT void eraseResults();
86 /// removes all fields from this feature: results, data, etc
87 MODELAPI_EXPORT virtual void erase();
89 /// Returns true if result is persistent (stored in document) and on undo-redo, save-open
90 /// it is not needed to recompute it.
91 virtual bool isPersistentResult() {return true;}
93 /// Returns true if this feature must not be created: this is just an action
94 /// that is not stored in the features history and data model (like "delete part").
95 virtual bool isAction()
100 /// Must return document where the new feature must be added to
101 /// By default it is current document
102 MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Document> documentToAdd();
104 /// To virtually destroy the fields of successors
105 MODELAPI_EXPORT virtual ~ModelAPI_Feature();
107 MODELAPI_EXPORT static boost::shared_ptr<ModelAPI_Feature> feature(ObjectPtr theObject);
110 // Helper methods, aliases for data()->method()
111 // -----------------------------------------------------------------------------------------------
112 inline std::string name()
114 return data()->name();
117 inline boost::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID)
119 return data()->boolean(theID);
122 inline boost::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID)
124 return data()->document(theID);
127 inline boost::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID)
129 return data()->real(theID);
132 inline boost::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID)
134 return data()->integer(theID);
137 inline boost::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID)
139 return data()->refattr(theID);
142 inline boost::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID)
144 return data()->reference(theID);
147 inline boost::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string& theID)
149 return data()->reflist(theID);
152 inline boost::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID)
154 return data()->selection(theID);
157 inline boost::shared_ptr<ModelAPI_AttributeSelectionList> selectionList(const std::string& theID)
159 return data()->selectionList(theID);
162 inline boost::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID)
164 return data()->string(theID);
167 inline boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID)
169 return data()->attribute(theID);
171 // -----------------------------------------------------------------------------------------------
174 //! Pointer on feature object
175 typedef boost::shared_ptr<ModelAPI_Feature> FeaturePtr;