Gui: Clean up code in ViewProviderPyImp.cpp
This commit is contained in:
@@ -36,7 +36,7 @@
|
||||
#include "PythonWrapper.h"
|
||||
#include "SoFCDB.h"
|
||||
|
||||
// inclusion of the generated files (generated out of ViewProviderPy2.xml)
|
||||
// inclusion of the generated files (generated out of ViewProviderPy.xml)
|
||||
#include <Gui/ViewProviderPy.h>
|
||||
#include <Gui/ViewProviderPy.cpp>
|
||||
#include <Gui/View3DPy.h>
|
||||
@@ -128,88 +128,97 @@ PyObject* ViewProviderPy::show(PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
getViewProviderPtr()->show();
|
||||
Py_Return;
|
||||
} PY_CATCH;
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* ViewProviderPy::hide(PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
getViewProviderPtr()->hide();
|
||||
Py_Return;
|
||||
} PY_CATCH;
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* ViewProviderPy::isVisible(PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
return Py_BuildValue("O", (getViewProviderPtr()->isShow() ? Py_True : Py_False));
|
||||
} PY_CATCH;
|
||||
return Py::new_reference_to(Py::Boolean(getViewProviderPtr()->isShow()));
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* ViewProviderPy::canDragObject(PyObject *args)
|
||||
{
|
||||
PyObject *obj = Py_None;
|
||||
if (!PyArg_ParseTuple(args, "|O", &obj))
|
||||
PyObject *obj = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "|O!", &App::DocumentObjectPy::Type, &obj))
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
bool ret;
|
||||
if(obj == Py_None)
|
||||
if (!obj)
|
||||
ret = getViewProviderPtr()->canDragObjects();
|
||||
else if(!PyObject_TypeCheck(obj,&App::DocumentObjectPy::Type)) {
|
||||
PyErr_SetString(PyExc_TypeError, "exepcting a type of DocumentObject");
|
||||
return nullptr;
|
||||
}else
|
||||
else
|
||||
ret = getViewProviderPtr()->canDragObject(
|
||||
static_cast<App::DocumentObjectPy*>(obj)->getDocumentObjectPtr());
|
||||
|
||||
return Py::new_reference_to(Py::Boolean(ret));
|
||||
} PY_CATCH;
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* ViewProviderPy::canDropObject(PyObject *args)
|
||||
PyObject* ViewProviderPy::canDropObject(PyObject *args, PyObject *kw)
|
||||
{
|
||||
PyObject *obj = Py_None;
|
||||
PyObject *owner = Py_None;
|
||||
PyObject *pyElements = Py_None;
|
||||
PyObject *obj = nullptr;
|
||||
PyObject *owner = nullptr;
|
||||
PyObject *pyElements = nullptr;
|
||||
const char *subname = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "|OOsO", &obj,&owner,&subname,&pyElements))
|
||||
static char* kwlist[] = {"obj","owner","subname","elem",nullptr};
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "|O!O!sO", kwlist,
|
||||
&App::DocumentObjectPy::Type,&obj, &App::DocumentObjectPy::Type, &owner,
|
||||
&subname, &pyElements))
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
bool ret;
|
||||
if(obj == Py_None)
|
||||
ret = getViewProviderPtr()->canDropObjects();
|
||||
else if(!PyObject_TypeCheck(obj,&App::DocumentObjectPy::Type)) {
|
||||
PyErr_SetString(PyExc_TypeError, "exepcting 'obj' to be of type DocumentObject");
|
||||
App::DocumentObject* pcObject;
|
||||
App::DocumentObject* pcOwner = nullptr;
|
||||
App::PropertyStringList elements;
|
||||
if (!obj && (owner || pyElements || subname)) {
|
||||
PyErr_SetString(PyExc_ValueError, "'obj' must be specified if 'owner', 'subname' or 'elem' is given");
|
||||
return nullptr;
|
||||
}
|
||||
auto pcObject = static_cast<App::DocumentObjectPy*>(obj)->getDocumentObjectPtr();
|
||||
App::DocumentObject *pcOwner = nullptr;
|
||||
if(owner!=Py_None) {
|
||||
if(!PyObject_TypeCheck(owner,&App::DocumentObjectPy::Type)) {
|
||||
PyErr_SetString(PyExc_TypeError, "exepcting 'owner' to be of type DocumentObject");
|
||||
return nullptr;
|
||||
}
|
||||
pcOwner = static_cast<App::DocumentObjectPy*>(owner)->getDocumentObjectPtr();
|
||||
if(!obj) {
|
||||
ret = getViewProviderPtr()->canDropObjects();
|
||||
return Py::new_reference_to(Py::Boolean(ret));
|
||||
}
|
||||
App::PropertyStringList elements;
|
||||
if(pyElements!=Py_None) {
|
||||
pcObject = static_cast<App::DocumentObjectPy*>(obj)->getDocumentObjectPtr();
|
||||
if (owner)
|
||||
pcOwner = static_cast<App::DocumentObjectPy*>(owner)->getDocumentObjectPtr();
|
||||
if (pyElements) {
|
||||
try {
|
||||
elements.setPyObject(pyElements);
|
||||
}
|
||||
catch(...) {
|
||||
PyErr_SetString(PyExc_TypeError, "exepcting the forth argument to be of type sequence of strings");
|
||||
PyErr_SetString(PyExc_TypeError, "'elem' must be a sequence of strings");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
ret = getViewProviderPtr()->canDropObjectEx(pcObject,pcOwner,subname,elements.getValues());
|
||||
return Py::new_reference_to(Py::Boolean(ret));
|
||||
} PY_CATCH;
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* ViewProviderPy::canDragAndDropObject(PyObject *args)
|
||||
@@ -217,44 +226,46 @@ PyObject* ViewProviderPy::canDragAndDropObject(PyObject *args)
|
||||
PyObject *obj;
|
||||
if (!PyArg_ParseTuple(args, "O!", &App::DocumentObjectPy::Type,&obj))
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
bool ret = getViewProviderPtr()->canDragAndDropObject(
|
||||
static_cast<App::DocumentObjectPy*>(obj)->getDocumentObjectPtr());
|
||||
return Py::new_reference_to(Py::Boolean(ret));
|
||||
} PY_CATCH;
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* ViewProviderPy::dropObject(PyObject *args)
|
||||
PyObject* ViewProviderPy::dropObject(PyObject *args, PyObject *kw)
|
||||
{
|
||||
PyObject *obj;
|
||||
PyObject *owner = Py_None;
|
||||
PyObject *pyElements = Py_None;
|
||||
PyObject *owner = nullptr;
|
||||
PyObject *pyElements = nullptr;
|
||||
const char *subname = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "O!|OsO", &App::DocumentObjectPy::Type,&obj,&owner,&subname,&pyElements))
|
||||
static char* kwlist[] = {"obj","owner","subname","elem",nullptr};
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "O!|O!sO", kwlist,
|
||||
&App::DocumentObjectPy::Type,&obj, &App::DocumentObjectPy::Type, &owner,
|
||||
&subname, &pyElements))
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
auto pcObject = static_cast<App::DocumentObjectPy*>(obj)->getDocumentObjectPtr();
|
||||
App::DocumentObject *pcOwner = nullptr;
|
||||
if(owner!=Py_None) {
|
||||
if(!PyObject_TypeCheck(owner,&App::DocumentObjectPy::Type)) {
|
||||
PyErr_SetString(PyExc_TypeError, "exepcting 'owner' to be of type DocumentObject");
|
||||
return nullptr;
|
||||
}
|
||||
pcOwner = static_cast<App::DocumentObjectPy*>(owner)->getDocumentObjectPtr();
|
||||
}
|
||||
App::PropertyStringList elements;
|
||||
if(pyElements!=Py_None) {
|
||||
if (owner)
|
||||
pcOwner = static_cast<App::DocumentObjectPy*>(owner)->getDocumentObjectPtr();
|
||||
if (pyElements) {
|
||||
try {
|
||||
elements.setPyObject(pyElements);
|
||||
}catch(...) {
|
||||
PyErr_SetString(PyExc_TypeError, "exepcting the forth argument to be of type sequence of strings");
|
||||
}
|
||||
catch(...) {
|
||||
PyErr_SetString(PyExc_TypeError, "'elem' must be a sequence of strings");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
auto ret = getViewProviderPtr()->dropObjectEx(
|
||||
static_cast<App::DocumentObjectPy*>(obj)->getDocumentObjectPtr(),
|
||||
pcOwner, subname,elements.getValues());
|
||||
auto ret = getViewProviderPtr()->dropObjectEx(pcObject,pcOwner, subname,elements.getValues());
|
||||
return Py::new_reference_to(Py::String(ret));
|
||||
} PY_CATCH;
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* ViewProviderPy::dragObject(PyObject *args)
|
||||
@@ -262,11 +273,13 @@ PyObject* ViewProviderPy::dragObject(PyObject *args)
|
||||
PyObject *obj;
|
||||
if (!PyArg_ParseTuple(args, "O!", &App::DocumentObjectPy::Type,&obj))
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
getViewProviderPtr()->dragObject(
|
||||
static_cast<App::DocumentObjectPy*>(obj)->getDocumentObjectPtr());
|
||||
Py_Return;
|
||||
} PY_CATCH;
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* ViewProviderPy::replaceObject(PyObject *args)
|
||||
@@ -277,12 +290,14 @@ PyObject* ViewProviderPy::replaceObject(PyObject *args)
|
||||
&App::DocumentObjectPy::Type,&oldObj,
|
||||
&App::DocumentObjectPy::Type,&newObj))
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
int ret = getViewProviderPtr()->replaceObject(
|
||||
static_cast<App::DocumentObjectPy*>(oldObj)->getDocumentObjectPtr(),
|
||||
static_cast<App::DocumentObjectPy*>(newObj)->getDocumentObjectPtr());
|
||||
return Py::new_reference_to(Py::Int(ret));
|
||||
} PY_CATCH;
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* ViewProviderPy::addDisplayMode(PyObject * args)
|
||||
@@ -305,13 +320,15 @@ PyObject* ViewProviderPy::addDisplayMode(PyObject * args)
|
||||
SoNode* node = reinterpret_cast<SoNode*>(ptr);
|
||||
getViewProviderPtr()->addDisplayMaskMode(node,mode);
|
||||
Py_Return;
|
||||
} PY_CATCH;
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* ViewProviderPy::listDisplayModes(PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
std::vector<std::string> modes = getViewProviderPtr()->getDisplayModes();
|
||||
PyObject* pyList = PyList_New(modes.size());
|
||||
@@ -323,17 +340,20 @@ PyObject* ViewProviderPy::listDisplayModes(PyObject *args)
|
||||
}
|
||||
|
||||
return pyList;
|
||||
} PY_CATCH;
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* ViewProviderPy::toString(PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
std::string buffer = getViewProviderPtr()->toString();
|
||||
return Py::new_reference_to(Py::String(buffer));
|
||||
} PY_CATCH;
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject* ViewProviderPy::setTransformation(PyObject *args)
|
||||
@@ -346,13 +366,14 @@ PyObject* ViewProviderPy::setTransformation(PyObject *args)
|
||||
Py_Return;
|
||||
}
|
||||
PyErr_Clear();
|
||||
|
||||
if (PyArg_ParseTuple(args, "O!",&(Base::PlacementPy::Type),&p)) {
|
||||
Base::PlacementPy* plc = static_cast<Base::PlacementPy*>(p);
|
||||
getViewProviderPtr()->setTransformation(plc->getPlacementPtr()->toMatrix());
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "Either set matrix or placement to set transformation");
|
||||
PyErr_SetString(PyExc_TypeError, "The transformation must be a Base.Matrix or a Base.Placement");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -376,7 +397,7 @@ PyObject* ViewProviderPy::partialRender(PyObject* args)
|
||||
{
|
||||
PyObject *value = Py_None;
|
||||
PyObject *clear = Py_False;
|
||||
if (!PyArg_ParseTuple(args, "|OO",&value,&clear))
|
||||
if (!PyArg_ParseTuple(args, "|OO!",&value,&PyBool_Type,&clear))
|
||||
return nullptr;
|
||||
|
||||
std::vector<std::string> values;
|
||||
@@ -392,12 +413,13 @@ PyObject* ViewProviderPy::partialRender(PyObject* args)
|
||||
}
|
||||
values.resize(nSize);
|
||||
for (Py_ssize_t i = 0; i < nSize; ++i) {
|
||||
if(value) item = PySequence_GetItem(value, i);
|
||||
if(value)
|
||||
item = PySequence_GetItem(value, i);
|
||||
if (PyUnicode_Check(item)) {
|
||||
values[i] = PyUnicode_AsUTF8(item);
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("type must be str or unicode");
|
||||
std::string error = std::string("type must be str");
|
||||
error += " not, ";
|
||||
error += item->ob_type->tp_name;
|
||||
throw Base::TypeError(error);
|
||||
@@ -405,7 +427,7 @@ PyObject* ViewProviderPy::partialRender(PyObject* args)
|
||||
}
|
||||
}
|
||||
|
||||
Py::Int ret(getViewProviderPtr()->partialRender(values,PyObject_IsTrue(clear)));
|
||||
Py::Int ret(getViewProviderPtr()->partialRender(values, PyObject_IsTrue(clear) ? true : false));
|
||||
return Py::new_reference_to(ret);
|
||||
}
|
||||
|
||||
@@ -453,14 +475,17 @@ PyObject* ViewProviderPy::getElementPicked(PyObject* args)
|
||||
PyObject *obj;
|
||||
if (!PyArg_ParseTuple(args, "O",&obj))
|
||||
return nullptr;
|
||||
|
||||
void *ptr = nullptr;
|
||||
Base::Interpreter().convertSWIGPointerObj("pivy.coin", "_p_SoPickedPoint", obj, &ptr, 0);
|
||||
SoPickedPoint *pp = reinterpret_cast<SoPickedPoint*>(ptr);
|
||||
if(!pp)
|
||||
throw Base::TypeError("type must be of coin.SoPickedPoint");
|
||||
throw Base::TypeError("type must be coin.SoPickedPoint");
|
||||
|
||||
std::string name;
|
||||
if(!getViewProviderPtr()->getElementPicked(pp,name))
|
||||
Py_Return;
|
||||
|
||||
return Py::new_reference_to(Py::String(name));
|
||||
}
|
||||
|
||||
@@ -469,22 +494,21 @@ PyObject* ViewProviderPy::getDetailPath(PyObject* args)
|
||||
const char *sub;
|
||||
PyObject *path;
|
||||
PyObject *append = Py_True;
|
||||
if (!PyArg_ParseTuple(args, "sO|O",&sub,&path,&append))
|
||||
if (!PyArg_ParseTuple(args, "sO|O!",&sub,&path,&PyBool_Type,&append))
|
||||
return nullptr;
|
||||
|
||||
void *ptr = nullptr;
|
||||
Base::Interpreter().convertSWIGPointerObj("pivy.coin", "_p_SoPath", path, &ptr, 0);
|
||||
SoPath *pPath = reinterpret_cast<SoPath*>(ptr);
|
||||
if(!pPath)
|
||||
throw Base::TypeError("type must be of coin.SoPath");
|
||||
throw Base::TypeError("'path' must be a coin.SoPath");
|
||||
SoDetail *det = nullptr;
|
||||
if(!getViewProviderPtr()->getDetailPath(
|
||||
sub,static_cast<SoFullPath*>(pPath),PyObject_IsTrue(append),det))
|
||||
{
|
||||
if(det) delete det;
|
||||
if(!getViewProviderPtr()->getDetailPath(sub,static_cast<SoFullPath*>(pPath),append,det)) {
|
||||
delete det;
|
||||
Py_Return;
|
||||
}
|
||||
if(!det)
|
||||
return Py::new_reference_to(Py::True());
|
||||
Py_Return;
|
||||
return Base::Interpreter().createSWIGPointerObj("pivy.coin", "_p_SoDetail", (void*)det, 0);
|
||||
}
|
||||
|
||||
@@ -492,6 +516,7 @@ PyObject *ViewProviderPy::signalChangeIcon(PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return nullptr;
|
||||
|
||||
getViewProviderPtr()->signalChangeIcon();
|
||||
Py_Return;
|
||||
}
|
||||
@@ -500,24 +525,27 @@ PyObject *ViewProviderPy::getBoundingBox(PyObject *args) {
|
||||
PyObject *transform=Py_True;
|
||||
PyObject *pyView = nullptr;
|
||||
const char *subname = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "|sOO!", &subname,&transform,View3DInventorPy::type_object(),&pyView))
|
||||
if (!PyArg_ParseTuple(args, "|sO!O!", &subname,&PyBool_Type,&transform,View3DInventorPy::type_object(),&pyView))
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
View3DInventor *view = nullptr;
|
||||
if(pyView)
|
||||
view = static_cast<View3DInventorPy*>(pyView)->getView3DIventorPtr();
|
||||
auto bbox = getViewProviderPtr()->getBoundingBox(subname,PyObject_IsTrue(transform),view);
|
||||
Py::Object ret(new Base::BoundBoxPy(new Base::BoundBox3d(bbox)));
|
||||
return Py::new_reference_to(ret);
|
||||
} PY_CATCH;
|
||||
return new Base::BoundBoxPy(new Base::BoundBox3d(bbox));
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject *ViewProviderPy::doubleClicked(PyObject *args) {
|
||||
if(!PyArg_ParseTuple(args, ""))
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
return Py::new_reference_to(Py::Boolean(getViewProviderPtr()->doubleClicked()));
|
||||
}PY_CATCH;
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyObject *ViewProviderPy::getCustomAttributes(const char* attr) const
|
||||
@@ -551,7 +579,7 @@ int ViewProviderPy::setCustomAttributes(const char* attr, PyObject* value)
|
||||
}
|
||||
}
|
||||
|
||||
Py::Object ViewProviderPy::getAnnotation(void) const
|
||||
Py::Object ViewProviderPy::getAnnotation() const
|
||||
{
|
||||
try {
|
||||
auto node = getViewProviderPtr()->getAnnotation();
|
||||
@@ -569,7 +597,7 @@ void ViewProviderPy::setAnnotation(Py::Object)
|
||||
|
||||
}
|
||||
|
||||
Py::Object ViewProviderPy::getRootNode(void) const
|
||||
Py::Object ViewProviderPy::getRootNode() const
|
||||
{
|
||||
try {
|
||||
SoSeparator* node = getViewProviderPtr()->getRoot();
|
||||
@@ -587,7 +615,7 @@ void ViewProviderPy::setRootNode(Py::Object)
|
||||
|
||||
}
|
||||
|
||||
Py::Object ViewProviderPy::getSwitchNode(void) const
|
||||
Py::Object ViewProviderPy::getSwitchNode() const
|
||||
{
|
||||
try {
|
||||
SoSwitch* node = getViewProviderPtr()->getModeSwitch();
|
||||
@@ -605,13 +633,13 @@ void ViewProviderPy::setSwitchNode(Py::Object)
|
||||
|
||||
}
|
||||
|
||||
Py::String ViewProviderPy::getIV(void) const
|
||||
Py::String ViewProviderPy::getIV() const
|
||||
{
|
||||
std::string buf = Gui::SoFCDB::writeNodesToString(getViewProviderPtr()->getRoot());
|
||||
return Py::String(buf);
|
||||
}
|
||||
|
||||
Py::Object ViewProviderPy::getIcon(void) const
|
||||
Py::Object ViewProviderPy::getIcon() const
|
||||
{
|
||||
#if 0
|
||||
QByteArray ba;
|
||||
@@ -628,7 +656,7 @@ Py::Object ViewProviderPy::getIcon(void) const
|
||||
#endif
|
||||
}
|
||||
|
||||
Py::Int ViewProviderPy::getDefaultMode(void) const
|
||||
Py::Int ViewProviderPy::getDefaultMode() const
|
||||
{
|
||||
return Py::Int((long)getViewProviderPtr()->getDefaultMode());
|
||||
}
|
||||
@@ -643,14 +671,17 @@ Py::Boolean ViewProviderPy::getCanRemoveChildrenFromRoot() const
|
||||
return Py::Boolean(getViewProviderPtr()->canRemoveChildrenFromRoot());
|
||||
}
|
||||
|
||||
Py::Boolean ViewProviderPy::getLinkVisibility() const {
|
||||
Py::Boolean ViewProviderPy::getLinkVisibility() const
|
||||
{
|
||||
return Py::Boolean(getViewProviderPtr()->isLinkVisible());
|
||||
}
|
||||
|
||||
void ViewProviderPy::setLinkVisibility(Py::Boolean arg) {
|
||||
void ViewProviderPy::setLinkVisibility(Py::Boolean arg)
|
||||
{
|
||||
getViewProviderPtr()->setLinkVisible(arg);
|
||||
}
|
||||
|
||||
Py::String ViewProviderPy::getDropPrefix() const {
|
||||
Py::String ViewProviderPy::getDropPrefix() const
|
||||
{
|
||||
return Py::String(getViewProviderPtr()->getDropPrefix());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user