diff --git a/src/Gui/ViewProviderPythonFeature.cpp b/src/Gui/ViewProviderPythonFeature.cpp index dab7c85b9..7611542b4 100644 --- a/src/Gui/ViewProviderPythonFeature.cpp +++ b/src/Gui/ViewProviderPythonFeature.cpp @@ -303,11 +303,112 @@ std::vector ViewProviderPythonFeatureImp::claimChildren(co return children; } +bool ViewProviderPythonFeatureImp::useNewSelectionModel() const +{ + // Run the useNewSelectionModel method of the proxy object. + Base::PyGILStateLocker lock; + try { + App::Property* proxy = object->getPropertyByName("Proxy"); + if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) { + Py::Object vp = static_cast(proxy)->getValue(); + if (vp.hasAttr(std::string("useNewSelectionModel"))) { + Py::Callable method(vp.getAttr(std::string("useNewSelectionModel"))); + Py::Tuple args; + Py::Boolean ok(method.apply(args)); + return (bool)ok; + } + } + } + catch (Py::Exception&) { + Base::PyException e; // extract the Python error text + e.ReportException(); + } + + return true; +} + std::string ViewProviderPythonFeatureImp::getElement(const SoDetail *det) const { + // Run the onChanged method of the proxy object. + Base::PyGILStateLocker lock; + try { + App::Property* proxy = object->getPropertyByName("Proxy"); + if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) { + Py::Object vp = static_cast(proxy)->getValue(); + if (vp.hasAttr(std::string("getElement"))) { + PyObject* pivy = 0; + pivy = Base::Interpreter().createSWIGPointerObj("pivy.coin", "SoDetail *", (void*)det, 1); + if (vp.hasAttr("__object__")) { + Py::Callable method(vp.getAttr(std::string("getElement"))); + Py::Tuple args(1); + args.setItem(0, Py::Object(pivy, true)); + Py::String name(method.apply(args)); + return (std::string)name; + } + else { + Py::Callable method(vp.getAttr(std::string("getElement"))); + Py::Tuple args(2); + args.setItem(0, Py::Object(object->getPyObject(), true)); + args.setItem(1, Py::Object(pivy, true)); + Py::String name(method.apply(args)); + return (std::string)name; + } + } + } + } + catch (const Base::Exception& e) { + e.ReportException(); + } + catch (Py::Exception&) { + Base::PyException e; // extract the Python error text + e.ReportException(); + } + return ""; } +SoDetail* ViewProviderPythonFeatureImp::getDetail(const char* name) const +{ + // Run the onChanged method of the proxy object. + Base::PyGILStateLocker lock; + try { + App::Property* proxy = object->getPropertyByName("Proxy"); + if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) { + Py::Object vp = static_cast(proxy)->getValue(); + if (vp.hasAttr(std::string("getDetail"))) { + if (vp.hasAttr("__object__")) { + Py::Callable method(vp.getAttr(std::string("getDetail"))); + Py::Tuple args(1); + args.setItem(0, Py::String(name)); + Py::Object det(method.apply(args)); + void* ptr = 0; + Base::Interpreter().convertSWIGPointerObj("pivy.coin", "SoNode *", det.ptr(), &ptr, 0); + return reinterpret_cast(ptr); + } + else { + Py::Callable method(vp.getAttr(std::string("getDetail"))); + Py::Tuple args(2); + args.setItem(0, Py::Object(object->getPyObject(), true)); + args.setItem(1, Py::String(name)); + Py::Object det(method.apply(args)); + void* ptr = 0; + Base::Interpreter().convertSWIGPointerObj("pivy.coin", "SoNode *", det.ptr(), &ptr, 0); + return reinterpret_cast(ptr); + } + } + } + } + catch (const Base::Exception& e) { + e.ReportException(); + } + catch (Py::Exception&) { + Base::PyException e; // extract the Python error text + e.ReportException(); + } + + return 0; +} + std::vector ViewProviderPythonFeatureImp::getSelectionShape(const char* Element) const { return std::vector(); diff --git a/src/Gui/ViewProviderPythonFeature.h b/src/Gui/ViewProviderPythonFeature.h index ff3e34cff..f92363d0b 100644 --- a/src/Gui/ViewProviderPythonFeature.h +++ b/src/Gui/ViewProviderPythonFeature.h @@ -48,7 +48,9 @@ public: // Returns the icon QIcon getIcon() const; std::vector claimChildren(const std::vector&) const; + bool useNewSelectionModel() const; std::string getElement(const SoDetail *det) const; + SoDetail* getDetail(const char*) const; std::vector getSelectionShape(const char* Element) const; bool setEdit(int ModNum); bool unsetEdit(int ModNum); @@ -124,11 +126,18 @@ public: /** @name Selection handling */ //@{ virtual bool useNewSelectionModel() const { - return ViewProviderT::useNewSelectionModel(); + return imp->useNewSelectionModel(); } virtual std::string getElement(const SoDetail *det) const { + std::string name = imp->getElement(det); + if (!name.empty()) return name; return ViewProviderT::getElement(det); } + virtual SoDetail* getDetail(const char* name) const { + SoDetail* det = imp->getDetail(name); + if (det) return det; + return ViewProviderT::getDetail(name); + } virtual std::vector getSelectionShape(const char* Element) const { return ViewProviderT::getSelectionShape(Element); };