From 6d8f51f92a81df9343186dfee8ea7ec6925a8303 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 26 Oct 2013 19:52:22 +0200 Subject: [PATCH] + Selection handling of Python view providers --- src/Gui/ViewProviderPythonFeature.cpp | 51 +++++++++------------------ 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/src/Gui/ViewProviderPythonFeature.cpp b/src/Gui/ViewProviderPythonFeature.cpp index 7611542b4..d8f682649 100644 --- a/src/Gui/ViewProviderPythonFeature.cpp +++ b/src/Gui/ViewProviderPythonFeature.cpp @@ -337,22 +337,15 @@ std::string ViewProviderPythonFeatureImp::getElement(const SoDetail *det) const 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; - } + // Note: As there is no ref'counting mechanism for the SoDetail class we must + // pass '0' as the last parameter so that the Python object does not 'own' + // the detail object. + pivy = Base::Interpreter().createSWIGPointerObj("pivy.coin", "SoDetail *", (void*)det, 0); + 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; } } } @@ -376,25 +369,13 @@ SoDetail* ViewProviderPythonFeatureImp::getDetail(const char* name) const 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); - } + 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", "SoDetail *", det.ptr(), &ptr, 0); + return reinterpret_cast(ptr); } } }