+ Interface for selection of Python view providers
This commit is contained in:
@@ -303,11 +303,112 @@ std::vector<App::DocumentObject*> 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<App::PropertyPythonObject*>(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<App::PropertyPythonObject*>(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<App::PropertyPythonObject*>(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<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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
e.ReportException();
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
e.ReportException();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<Base::Vector3d> ViewProviderPythonFeatureImp::getSelectionShape(const char* Element) const
|
||||
{
|
||||
return std::vector<Base::Vector3d>();
|
||||
|
||||
Reference in New Issue
Block a user