0001059: Cannot add object to DocumentObjectGroupPython
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "DocumentObjectGroup.h"
|
||||
#include "Document.h"
|
||||
#include <CXX/Objects.hxx>
|
||||
|
||||
// inclusion of the generated files (generated out of DocumentObjectGroupPy.xml)
|
||||
#include "DocumentObjectGroupPy.h"
|
||||
@@ -81,7 +82,24 @@ PyObject* DocumentObjectGroupPy::addObject(PyObject *args)
|
||||
}
|
||||
}
|
||||
|
||||
getDocumentObjectGroupPtr()->addObject(docObj->getDocumentObjectPtr());
|
||||
DocumentObjectGroup* grp = getDocumentObjectGroupPtr();
|
||||
|
||||
if (grp->getTypeId().isDerivedFrom(App::DocumentObjectGroupPython::getClassTypeId())) {
|
||||
DocumentObjectGroupPython* grppy = static_cast<DocumentObjectGroupPython*>(grp);
|
||||
App::Property* proxy = grppy->getPropertyByName("Proxy");
|
||||
if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) {
|
||||
Py::Object vp = static_cast<App::PropertyPythonObject*>(proxy)->getValue();
|
||||
if (vp.hasAttr(std::string("addObject"))) {
|
||||
Py::Callable method(vp.getAttr(std::string("addObject")));
|
||||
Py::Tuple args(1);
|
||||
args[0] = Py::Object(object);
|
||||
method.apply(args);
|
||||
Py_Return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
grp->addObject(docObj->getDocumentObjectPtr());
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
@@ -101,7 +119,24 @@ PyObject* DocumentObjectGroupPy::removeObject(PyObject *args)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
getDocumentObjectGroupPtr()->removeObject(docObj->getDocumentObjectPtr());
|
||||
DocumentObjectGroup* grp = getDocumentObjectGroupPtr();
|
||||
|
||||
if (grp->getTypeId().isDerivedFrom(App::DocumentObjectGroupPython::getClassTypeId())) {
|
||||
DocumentObjectGroupPython* grppy = static_cast<DocumentObjectGroupPython*>(grp);
|
||||
App::Property* proxy = grppy->getPropertyByName("Proxy");
|
||||
if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) {
|
||||
Py::Object vp = static_cast<App::PropertyPythonObject*>(proxy)->getValue();
|
||||
if (vp.hasAttr(std::string("removeObject"))) {
|
||||
Py::Callable method(vp.getAttr(std::string("removeObject")));
|
||||
Py::Tuple args(1);
|
||||
args[0] = Py::Object(object);
|
||||
method.apply(args);
|
||||
Py_Return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
grp->removeObject(docObj->getDocumentObjectPtr());
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
|
||||
@@ -437,7 +437,6 @@ void TreeWidget::dropEvent(QDropEvent *event)
|
||||
// Open command
|
||||
App::Document* doc = grp->getDocument();
|
||||
Gui::Document* gui = Gui::Application::Instance->getDocument(doc);
|
||||
Base::Type DOGPython = Base::Type::fromName("App::DocumentObjectGroupPython");
|
||||
gui->openCommand("Move object");
|
||||
for (QList<QTreeWidgetItem*>::Iterator it = items.begin(); it != items.end(); ++it) {
|
||||
// get document object
|
||||
@@ -448,38 +447,21 @@ void TreeWidget::dropEvent(QDropEvent *event)
|
||||
if (par) {
|
||||
// allow an object to be in one group only
|
||||
QString cmd;
|
||||
if (par->getTypeId().isDerivedFrom(DOGPython)) {
|
||||
// if this is a python group, call the method of its Proxy
|
||||
cmd = QString::fromAscii("App.getDocument(\"%1\").getObject(\"%2\").Proxy.removeObject("
|
||||
"App.getDocument(\"%1\").getObject(\"%3\"))")
|
||||
.arg(QString::fromAscii(doc->getName()))
|
||||
.arg(QString::fromAscii(par->getNameInDocument()))
|
||||
.arg(QString::fromAscii(obj->getNameInDocument()));
|
||||
} else {
|
||||
cmd = QString::fromAscii("App.getDocument(\"%1\").getObject(\"%2\").removeObject("
|
||||
"App.getDocument(\"%1\").getObject(\"%3\"))")
|
||||
.arg(QString::fromAscii(doc->getName()))
|
||||
.arg(QString::fromAscii(par->getNameInDocument()))
|
||||
.arg(QString::fromAscii(obj->getNameInDocument()));
|
||||
}
|
||||
cmd = QString::fromAscii("App.getDocument(\"%1\").getObject(\"%2\").removeObject("
|
||||
"App.getDocument(\"%1\").getObject(\"%3\"))")
|
||||
.arg(QString::fromAscii(doc->getName()))
|
||||
.arg(QString::fromAscii(par->getNameInDocument()))
|
||||
.arg(QString::fromAscii(obj->getNameInDocument()));
|
||||
Gui::Application::Instance->runPythonCode(cmd.toUtf8());
|
||||
}
|
||||
|
||||
// build Python command for execution
|
||||
QString cmd;
|
||||
if (grp->getTypeId().isDerivedFrom(DOGPython)) {
|
||||
cmd = QString::fromAscii("App.getDocument(\"%1\").getObject(\"%2\").Proxy.addObject("
|
||||
"App.getDocument(\"%1\").getObject(\"%3\"))")
|
||||
.arg(QString::fromAscii(doc->getName()))
|
||||
.arg(QString::fromAscii(grp->getNameInDocument()))
|
||||
.arg(QString::fromAscii(obj->getNameInDocument()));
|
||||
} else {
|
||||
cmd = QString::fromAscii("App.getDocument(\"%1\").getObject(\"%2\").addObject("
|
||||
"App.getDocument(\"%1\").getObject(\"%3\"))")
|
||||
.arg(QString::fromAscii(doc->getName()))
|
||||
.arg(QString::fromAscii(grp->getNameInDocument()))
|
||||
.arg(QString::fromAscii(obj->getNameInDocument()));
|
||||
}
|
||||
cmd = QString::fromAscii("App.getDocument(\"%1\").getObject(\"%2\").addObject("
|
||||
"App.getDocument(\"%1\").getObject(\"%3\"))")
|
||||
.arg(QString::fromAscii(doc->getName()))
|
||||
.arg(QString::fromAscii(grp->getNameInDocument()))
|
||||
.arg(QString::fromAscii(obj->getNameInDocument()));
|
||||
Gui::Application::Instance->runPythonCode(cmd.toUtf8());
|
||||
}
|
||||
gui->commitCommand();
|
||||
|
||||
@@ -270,7 +270,7 @@ QIcon ViewProviderPythonFeatureImp::getIcon() const
|
||||
return QIcon();
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> ViewProviderPythonFeatureImp::claimChildren() const
|
||||
std::vector<App::DocumentObject*> ViewProviderPythonFeatureImp::claimChildren(const std::vector<App::DocumentObject*>& base) const
|
||||
{
|
||||
std::vector<App::DocumentObject*> children;
|
||||
Base::PyGILStateLocker lock;
|
||||
@@ -290,6 +290,9 @@ std::vector<App::DocumentObject*> ViewProviderPythonFeatureImp::claimChildren()
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
children = base;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
|
||||
// Returns the icon
|
||||
QIcon getIcon() const;
|
||||
std::vector<App::DocumentObject*> claimChildren() const;
|
||||
std::vector<App::DocumentObject*> claimChildren(const std::vector<App::DocumentObject*>&) const;
|
||||
std::string getElement(const SoDetail *det) const;
|
||||
std::vector<Base::Vector3d> getSelectionShape(const char* Element) const;
|
||||
bool setEdit(int ModNum);
|
||||
@@ -103,7 +103,7 @@ public:
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> claimChildren() const {
|
||||
return imp->claimChildren();
|
||||
return imp->claimChildren(ViewProviderT::claimChildren());
|
||||
}
|
||||
|
||||
/** @name Nodes */
|
||||
|
||||
Reference in New Issue
Block a user