+ Selection handling of Python view providers

This commit is contained in:
wmayer 2013-10-26 19:52:22 +02:00
parent 3a0037ff8d
commit 6d8f51f92a

View File

@ -337,22 +337,15 @@ std::string ViewProviderPythonFeatureImp::getElement(const SoDetail *det) const
Py::Object vp = static_cast<App::PropertyPythonObject*>(proxy)->getValue(); Py::Object vp = static_cast<App::PropertyPythonObject*>(proxy)->getValue();
if (vp.hasAttr(std::string("getElement"))) { if (vp.hasAttr(std::string("getElement"))) {
PyObject* pivy = 0; PyObject* pivy = 0;
pivy = Base::Interpreter().createSWIGPointerObj("pivy.coin", "SoDetail *", (void*)det, 1); // Note: As there is no ref'counting mechanism for the SoDetail class we must
if (vp.hasAttr("__object__")) { // pass '0' as the last parameter so that the Python object does not 'own'
Py::Callable method(vp.getAttr(std::string("getElement"))); // the detail object.
Py::Tuple args(1); pivy = Base::Interpreter().createSWIGPointerObj("pivy.coin", "SoDetail *", (void*)det, 0);
args.setItem(0, Py::Object(pivy, true)); Py::Callable method(vp.getAttr(std::string("getElement")));
Py::String name(method.apply(args)); Py::Tuple args(1);
return (std::string)name; args.setItem(0, Py::Object(pivy, true));
} Py::String name(method.apply(args));
else { return (std::string)name;
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;
}
} }
} }
} }
@ -376,25 +369,13 @@ SoDetail* ViewProviderPythonFeatureImp::getDetail(const char* name) const
if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) { if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) {
Py::Object vp = static_cast<App::PropertyPythonObject*>(proxy)->getValue(); Py::Object vp = static_cast<App::PropertyPythonObject*>(proxy)->getValue();
if (vp.hasAttr(std::string("getDetail"))) { if (vp.hasAttr(std::string("getDetail"))) {
if (vp.hasAttr("__object__")) { Py::Callable method(vp.getAttr(std::string("getDetail")));
Py::Callable method(vp.getAttr(std::string("getDetail"))); Py::Tuple args(1);
Py::Tuple args(1); args.setItem(0, Py::String(name));
args.setItem(0, Py::String(name)); Py::Object det(method.apply(args));
Py::Object det(method.apply(args)); void* ptr = 0;
void* ptr = 0; Base::Interpreter().convertSWIGPointerObj("pivy.coin", "SoDetail *", det.ptr(), &ptr, 0);
Base::Interpreter().convertSWIGPointerObj("pivy.coin", "SoNode *", det.ptr(), &ptr, 0); return reinterpret_cast<SoDetail*>(ptr);
return reinterpret_cast<SoDetail*>(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<SoDetail*>(ptr);
}
} }
} }
} }