GuiPy: [skip ci] expose function to Python to replace Switch with Separator nodes
This commit is contained in:
@@ -230,6 +230,47 @@ FreeCADGui_subgraphFromObject(PyObject * /*self*/, PyObject *args)
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
FreeCADGui_replaceSwitchNodes(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
PyObject* proxy;
|
||||
if (!PyArg_ParseTuple(args, "O", &proxy))
|
||||
return nullptr;
|
||||
|
||||
void* ptr = 0;
|
||||
try {
|
||||
Base::Interpreter().convertSWIGPointerObj("pivy.coin", "SoNode *", proxy, &ptr, 0);
|
||||
SoNode* node = reinterpret_cast<SoNode*>(ptr);
|
||||
SoNode* replace = SoFCDB::replaceSwitches(node);
|
||||
if (replace) {
|
||||
replace->ref();
|
||||
|
||||
std::string prefix = "So";
|
||||
std::string type = replace->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*)replace, 1);
|
||||
return Py::new_reference_to(Py::Object(proxy, true));
|
||||
}
|
||||
else {
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
PyErr_SetString(PyExc_RuntimeError, e.what());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
FreeCADGui_getSoDBVersion(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
@@ -293,6 +334,9 @@ struct PyMethodDef FreeCADGui_methods[] = {
|
||||
{"subgraphFromObject",FreeCADGui_subgraphFromObject,METH_VARARGS,
|
||||
"subgraphFromObject(object) -> Node\n\n"
|
||||
"Return the Inventor subgraph to an object"},
|
||||
{"replaceSwitchNodes",FreeCADGui_replaceSwitchNodes,METH_VARARGS,
|
||||
"replaceSwitchNodes(Node) -> Node\n\n"
|
||||
"Replace Switch nodes with Separators"},
|
||||
{"getSoDBVersion",FreeCADGui_getSoDBVersion,METH_VARARGS,
|
||||
"getSoDBVersion() -> String\n\n"
|
||||
"Return a text string containing the name\n"
|
||||
|
||||
@@ -295,6 +295,11 @@ SoNode* replaceSwitchesInSceneGraph(SoNode* node)
|
||||
return node;
|
||||
}
|
||||
|
||||
SoNode* Gui::SoFCDB::replaceSwitches(SoNode* node)
|
||||
{
|
||||
return replaceSwitchesInSceneGraph(node);
|
||||
}
|
||||
|
||||
bool Gui::SoFCDB::writeToVRML(SoNode* node, const char* filename, bool binary)
|
||||
{
|
||||
SoNode* noSwitches = replaceSwitchesInSceneGraph(node);
|
||||
|
||||
@@ -40,6 +40,7 @@ public:
|
||||
static SbBool isInitialized(void);
|
||||
static void init();
|
||||
static void finish();
|
||||
static SoNode* replaceSwitches(SoNode* node);
|
||||
/// helper to apply a SoWriteAction to a node and write it to a string
|
||||
static const std::string& writeNodesToString(SoNode * root);
|
||||
static bool writeToVRML(SoNode* node, const char* filename, bool binary);
|
||||
|
||||
Reference in New Issue
Block a user