ViewProviderPythonFeature.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 #ifndef GUI_VIEWPROVIDERPYTHONFEATURE_H
00025 #define GUI_VIEWPROVIDERPYTHONFEATURE_H
00026
00027 #include <Gui/ViewProviderGeometryObject.h>
00028 #include <Gui/ViewProviderPythonFeaturePy.h>
00029 #include <App/PropertyPythonObject.h>
00030 #include <App/DynamicProperty.h>
00031
00032 class SoSensor;
00033 class SoDragger;
00034 class SoNode;
00035
00036 namespace Gui {
00037 class SoFCSelection;
00038 class SoFCBoundingBox;
00039
00040 class GuiExport ViewProviderPythonFeatureImp
00041 {
00042 public:
00044 ViewProviderPythonFeatureImp(ViewProviderDocumentObject*);
00046 ~ViewProviderPythonFeatureImp();
00047
00048
00049 QIcon getIcon() const;
00050 std::vector<App::DocumentObject*> claimChildren() const;
00051 std::string getElement(const SoPickedPoint *pp) const;
00052 std::vector<Base::Vector3d> getSelectionShape(const char* Element) const;
00053 bool setEdit(int ModNum);
00054 bool unsetEdit(int ModNum);
00055
00058 void attach(App::DocumentObject *pcObject);
00059 void updateData(const App::Property*);
00060 void onChanged(const App::Property* prop);
00061 void startRestoring();
00062 void finishRestoring();
00064
00067
00068 const char* getDefaultDisplayMode() const;
00070 std::vector<std::string> getDisplayModes(void) const;
00072 std::string setDisplayMode(const char* ModeName);
00074
00075 private:
00076 ViewProviderDocumentObject* object;
00077 };
00078
00079 template <class ViewProviderT>
00080 class ViewProviderPythonFeatureT : public ViewProviderT
00081 {
00082 PROPERTY_HEADER(Gui::ViewProviderPythonFeatureT<ViewProviderT>);
00083
00084 public:
00086 ViewProviderPythonFeatureT() : _attached(false) {
00087 ADD_PROPERTY(Proxy,(Py::Object()));
00088 imp = new ViewProviderPythonFeatureImp(this);
00089 props = new App::DynamicProperty(this);
00090 }
00092 virtual ~ViewProviderPythonFeatureT() {
00093 delete imp;
00094 delete props;
00095 }
00096
00097
00098 QIcon getIcon() const {
00099 QIcon icon = imp->getIcon();
00100 if (icon.isNull())
00101 icon = ViewProviderT::getIcon();
00102 return icon;
00103 }
00104
00105 std::vector<App::DocumentObject*> claimChildren() const {
00106 return imp->claimChildren();
00107 }
00108
00111 virtual SoSeparator* getRoot() {
00112 return ViewProviderT::getRoot();
00113 }
00114 virtual SoSeparator* getFrontRoot() const {
00115 return ViewProviderT::getFrontRoot();
00116 }
00117
00118 virtual SoSeparator* getBackRoot() const {
00119 return ViewProviderT::getBackRoot();
00120 }
00122
00125 virtual bool useNewSelectionModel() const {
00126 return ViewProviderT::useNewSelectionModel();
00127 }
00128 virtual std::string getElement(const SoPickedPoint *pp) const {
00129 return ViewProviderT::getElement(pp);
00130 }
00131 virtual std::vector<Base::Vector3d> getSelectionShape(const char* Element) const {
00132 return ViewProviderT::getSelectionShape(Element);
00133 };
00135
00138 virtual void attach(App::DocumentObject *obj) {
00139
00140
00141 ViewProviderT::pcObject = obj;
00142 }
00143 virtual void updateData(const App::Property* prop) {
00144 imp->updateData(prop);
00145 ViewProviderT::updateData(prop);
00146 }
00147 virtual void getTaskViewContent(std::vector<Gui::TaskView::TaskContent*>& c) const {
00148 ViewProviderT::getTaskViewContent(c);
00149 }
00151
00154 virtual void startRestoring() {
00155 imp->startRestoring();
00156 }
00157 virtual void finishRestoring() {
00158 imp->finishRestoring();
00159 }
00161
00164
00165 virtual const char* getDefaultDisplayMode() const {
00166 return imp->getDefaultDisplayMode();
00167 }
00169 virtual std::vector<std::string> getDisplayModes(void) const {
00170 std::vector<std::string> modes = ViewProviderT::getDisplayModes();
00171 std::vector<std::string> more_modes = imp->getDisplayModes();
00172 modes.insert(modes.end(), more_modes.begin(), more_modes.end());
00173 return modes;
00174 }
00176 virtual void setDisplayMode(const char* ModeName) {
00177 std::string mask = imp->setDisplayMode(ModeName);
00178 ViewProviderT::setDisplayMaskMode(mask.c_str());
00179 ViewProviderT::setDisplayMode(ModeName);
00180 }
00182
00185 App::Property* addDynamicProperty(
00186 const char* type, const char* name=0,
00187 const char* group=0, const char* doc=0,
00188 short attr=0, bool ro=false, bool hidden=false) {
00189 return props->addDynamicProperty(type, name, group, doc, attr, ro, hidden);
00190 }
00191 std::vector<std::string> getDynamicPropertyNames() const {
00192 return props->getDynamicPropertyNames();
00193 }
00194 App::Property *getDynamicPropertyByName(const char* name) const {
00195 return props->getDynamicPropertyByName(name);
00196 }
00197 virtual void addDynamicProperties(const App::PropertyContainer* cont) {
00198 return props->addDynamicProperties(cont);
00199 }
00201 virtual void getPropertyMap(std::map<std::string,App::Property*> &Map) const {
00202 return props->getPropertyMap(Map);
00203 }
00205 virtual App::Property *getPropertyByName(const char* name) const {
00206 return props->getPropertyByName(name);
00207 }
00209 virtual const char* getName(const App::Property* prop) const {
00210 return props->getName(prop);
00211 }
00213
00216
00217 short getPropertyType(const App::Property* prop) const {
00218 return props->getPropertyType(prop);
00219 }
00221 short getPropertyType(const char *name) const {
00222 return props->getPropertyType(name);
00223 }
00225 const char* getPropertyGroup(const App::Property* prop) const {
00226 return props->getPropertyGroup(prop);
00227 }
00229 const char* getPropertyGroup(const char *name) const {
00230 return props->getPropertyGroup(name);
00231 }
00233 const char* getPropertyDocumentation(const App::Property* prop) const {
00234 return props->getPropertyDocumentation(prop);
00235 }
00237 const char* getPropertyDocumentation(const char *name) const {
00238 return props->getPropertyDocumentation(name);
00239 }
00241 bool isReadOnly(const App::Property* prop) const {
00242 return props->isReadOnly(prop);
00243 }
00245 bool isReadOnly(const char *name) const {
00246 return props->isReadOnly(name);
00247 }
00249 bool isHidden(const App::Property* prop) const {
00250 return props->isHidden(prop);
00251 }
00253 bool isHidden(const char *name) const {
00254 return props->isHidden(name);
00255 }
00257
00260 void Save (Base::Writer &writer) const {
00261 props->Save(writer);
00262 }
00263 void Restore(Base::XMLReader &reader) {
00264 props->Restore(reader);
00265 }
00267
00268 PyObject* getPyObject() {
00269 if (!ViewProviderT::pyViewObject)
00270 ViewProviderT::pyViewObject = new ViewProviderPythonFeaturePy(this);
00271 ViewProviderT::pyViewObject->IncRef();
00272 return ViewProviderT::pyViewObject;
00273 }
00274
00275 protected:
00276 virtual void onChanged(const App::Property* prop) {
00277 if (prop == &Proxy) {
00278 if (ViewProviderT::pcObject && !Proxy.getValue().is(Py::_None())) {
00279 if (!_attached) {
00280 _attached = true;
00281 imp->attach(ViewProviderT::pcObject);
00282 ViewProviderT::attach(ViewProviderT::pcObject);
00283
00284 ViewProviderT::DisplayMode.touch();
00285 }
00286 ViewProviderT::updateView();
00287 }
00288 }
00289 else {
00290 imp->onChanged(prop);
00291 ViewProviderT::onChanged(prop);
00292 }
00293 }
00295 virtual bool setEdit(int ModNum)
00296 {
00297 bool ok = imp->setEdit(ModNum);
00298 if (!ok) ok = ViewProviderT::setEdit(ModNum);
00299 return ok;
00300 }
00302 virtual void unsetEdit(int ModNum)
00303 {
00304 bool ok = imp->unsetEdit(ModNum);
00305 if (!ok) ViewProviderT::unsetEdit(ModNum);
00306 }
00307
00308 private:
00309 ViewProviderPythonFeatureImp* imp;
00310 App::DynamicProperty *props;
00311 App::PropertyPythonObject Proxy;
00312 bool _attached;
00313 };
00314
00315
00316 typedef ViewProviderPythonFeatureT<ViewProviderDocumentObject> ViewProviderPythonFeature;
00317 typedef ViewProviderPythonFeatureT<ViewProviderGeometryObject> ViewProviderPythonGeometry;
00318
00319 }
00320
00321 #endif // GUI_VIEWPROVIDERPYTHONFEATURE_H
00322