FeaturePython.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef APP_FEATUREPYTHON_H
00026 #define APP_FEATUREPYTHON_H
00027
00028
00029 #include <Base/Writer.h>
00030 #include <App/GeoFeature.h>
00031 #include <App/DynamicProperty.h>
00032 #include <App/PropertyPythonObject.h>
00033 #include <App/PropertyGeo.h>
00034 #include <App/FeaturePythonPy.h>
00035
00036 namespace App
00037 {
00038
00039 class Property;
00040 class FeaturePythonPy;
00041
00042
00043 class AppExport FeaturePythonImp
00044 {
00045 public:
00046 FeaturePythonImp(App::DocumentObject*);
00047 ~FeaturePythonImp();
00048
00049 DocumentObjectExecReturn *execute();
00050 void onChanged(const Property* prop);
00051
00052 private:
00053 App::DocumentObject* object;
00054 };
00055
00061 template <class FeatureT>
00062 class FeaturePythonT : public FeatureT
00063 {
00064 PROPERTY_HEADER(App::FeaturePythonT<FeatureT>);
00065
00066 public:
00067 FeaturePythonT() {
00068 ADD_PROPERTY(Proxy,(Py::Object()));
00069
00070 imp = new FeaturePythonImp(this);
00071 props = new DynamicProperty(this);
00072 }
00073 virtual ~FeaturePythonT() {
00074 delete imp;
00075 delete props;
00076 }
00077
00080 short mustExecute() const {
00081 if (this->isTouched())
00082 return 1;
00083 return FeatureT::mustExecute();
00084 }
00086 virtual DocumentObjectExecReturn *execute(void) {
00087 return imp->execute();
00088 }
00090 virtual const char* getViewProviderName(void) const {
00091 return FeatureT::getViewProviderName();
00092
00093 }
00094
00097 Property* addDynamicProperty(
00098 const char* type, const char* name=0,
00099 const char* group=0, const char* doc=0,
00100 short attr=0, bool ro=false, bool hidden=false) {
00101 return props->addDynamicProperty(type, name, group, doc, attr, ro, hidden);
00102 }
00103 std::vector<std::string> getDynamicPropertyNames() const {
00104 return props->getDynamicPropertyNames();
00105 }
00106 Property *getDynamicPropertyByName(const char* name) const {
00107 return props->getDynamicPropertyByName(name);
00108 }
00109 virtual void addDynamicProperties(const PropertyContainer* cont) {
00110 return props->addDynamicProperties(cont);
00111 }
00113 virtual void getPropertyList(std::vector<Property*> &List) const {
00114 props->getPropertyList(List);
00115 }
00117 void getPropertyMap(std::map<std::string,Property*> &Map) const {
00118 props->getPropertyMap(Map);
00119 }
00121 virtual Property *getPropertyByName(const char* name) const {
00122 return props->getPropertyByName(name);
00123 }
00125 virtual const char* getName(const Property* prop) const {
00126 return props->getName(prop);
00127 }
00129
00132
00133 short getPropertyType(const Property* prop) const {
00134 return props->getPropertyType(prop);
00135 }
00137 short getPropertyType(const char *name) const {
00138 return props->getPropertyType(name);
00139 }
00141 const char* getPropertyGroup(const Property* prop) const {
00142 return props->getPropertyGroup(prop);
00143 }
00145 const char* getPropertyGroup(const char *name) const {
00146 return props->getPropertyGroup(name);
00147 }
00149 const char* getPropertyDocumentation(const Property* prop) const {
00150 return props->getPropertyDocumentation(prop);
00151 }
00153 const char* getPropertyDocumentation(const char *name) const {
00154 return props->getPropertyDocumentation(name);
00155 }
00157 bool isReadOnly(const Property* prop) const {
00158 return props->isReadOnly(prop);
00159 }
00161 bool isReadOnly(const char *name) const {
00162 return props->isReadOnly(name);
00163 }
00165 bool isHidden(const Property* prop) const {
00166 return props->isHidden(prop);
00167 }
00169 bool isHidden(const char *name) const {
00170 return props->isHidden(name);
00171 }
00173
00176 void Save (Base::Writer &writer) const {
00177 writer.ObjectName = this->getNameInDocument();
00178 props->Save(writer);
00179 }
00180 void Restore(Base::XMLReader &reader) {
00181 props->Restore(reader);
00182 }
00184
00185 PyObject *getPyObject(void) {
00186 if (FeatureT::PythonObject.is(Py::_None())) {
00187
00188 FeatureT::PythonObject = Py::Object(new FeaturePythonPy(this),true);
00189 }
00190 return Py::new_reference_to(FeatureT::PythonObject);
00191 }
00192 void setPyObject(PyObject *obj) {
00193 if (obj)
00194 FeatureT::PythonObject = obj;
00195 else
00196 FeatureT::PythonObject = Py::None();
00197 }
00198
00199 friend class FeaturePythonPy;
00200
00201 protected:
00202 virtual void onChanged(const Property* prop) {
00203 imp->onChanged(prop);
00204 FeatureT::onChanged(prop);
00205 }
00206
00207 private:
00208 FeaturePythonImp* imp;
00209 DynamicProperty* props;
00210 PropertyPythonObject Proxy;
00211 };
00212
00213
00214 typedef FeaturePythonT<DocumentObject> FeaturePython;
00215 typedef FeaturePythonT<GeoFeature > GeometryPython;
00216
00217 }
00218
00219 #endif // APP_FEATUREPYTHON_H