+ Interface for selection of Python view providers
This commit is contained in:
parent
b652dc13aa
commit
2d62de2932
|
@ -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>();
|
||||
|
|
|
@ -48,7 +48,9 @@ public:
|
|||
// Returns the icon
|
||||
QIcon getIcon() const;
|
||||
std::vector<App::DocumentObject*> claimChildren(const std::vector<App::DocumentObject*>&) const;
|
||||
bool useNewSelectionModel() const;
|
||||
std::string getElement(const SoDetail *det) const;
|
||||
SoDetail* getDetail(const char*) const;
|
||||
std::vector<Base::Vector3d> 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<Base::Vector3d> getSelectionShape(const char* Element) const {
|
||||
return ViewProviderT::getSelectionShape(Element);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user