Gui: [skip ci] fix Gui.subgraphFromObject and improve error text if wrapping fails

This commit is contained in:
wmayer
2020-06-19 15:07:57 +02:00
parent 664c641f3c
commit 3ca859acf7
3 changed files with 16 additions and 4 deletions

View File

@@ -24,6 +24,7 @@
#include "PreCompiled.h"
#include "PyExport.h"
#include "Exception.h"
#include <sstream>
#if (defined(HAVE_SWIG) && (HAVE_SWIG == 1))
#if defined(__clang__)
# pragma clang diagnostic push

View File

@@ -29,8 +29,11 @@ int createSWIGPointerObj_T(const char* TypeName, void* obj, PyObject** ptr, int
swig_type_info * swig_type = 0;
swig_type = SWIG_TypeQuery(TypeName);
if (!swig_type)
throw Base::RuntimeError("Cannot find type information for requested type");
if (!swig_type) {
std::stringstream str;
str << "SWIG: Cannot find type information for requested type: " << TypeName;
throw Base::RuntimeError(str.str());
}
*ptr = SWIG_NewPointerObj(obj,swig_type,own);
if (*ptr == 0)

View File

@@ -201,8 +201,16 @@ FreeCADGui_subgraphFromObject(PyObject * /*self*/, PyObject *args)
vp->setDisplayMode(modes.front().c_str());
node = vp->getRoot()->copy();
node->ref();
std::string type = "So";
type += node->getTypeId().getName().getString();
std::string prefix = "So";
std::string type = node->getTypeId().getName().getString();
// doesn't start with the prefix 'So'
if (type.rfind("So", 0) != 0) {
type = prefix + type;
}
else if (type == "SoFCSelectionRoot") {
type = "SoSeparator";
}
type += " *";
PyObject* proxy = 0;
proxy = Base::Interpreter().createSWIGPointerObj("pivy.coin", type.c_str(), (void*)node, 1);