FEM: Handle python vtk user installs that conflict with FreeCAD VTK

This commit is contained in:
Stefan Tröger
2025-04-30 19:08:22 +02:00
parent 96e9e7a17a
commit 0304faa2bc
6 changed files with 293 additions and 0 deletions

View File

@@ -40,6 +40,11 @@
#ifdef FC_USE_VTK
#include "FemPostPipeline.h"
#include "FemVTKTools.h"
#include <LibraryVersions.h>
#endif
#ifdef FC_USE_VTK_PYTHON
#include <vtkPythonUtil.h>
#endif
@@ -75,6 +80,14 @@ public:
&Module::writeResult,
"write a CFD or FEM result (auto detect) to a file (file format "
"detected from file suffix)");
add_varargs_method("getVtkVersion",
&Module::getVtkVersion,
"Returns the VTK version freeCAD is linked against");
#ifdef FC_USE_VTK_PYTHON
add_varargs_method("isVtkCompatible",
&Module::isVtkCompatible,
"Checks if the passed vtkObject is compatible with the c++ VTK version freecad uses");
#endif
#endif
add_varargs_method("show",
&Module::show,
@@ -318,6 +331,34 @@ private:
return Py::None();
}
Py::Object getVtkVersion(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(),"")) {
throw Py::Exception();
}
return Py::String(fcVtkVersion);
}
#ifdef FC_USE_VTK_PYTHON
Py::Object isVtkCompatible(const Py::Tuple& args)
{
PyObject* pcObj = nullptr;
if (!PyArg_ParseTuple(args.ptr(),"O", &pcObj)) {
throw Py::Exception();
}
// if non is returned the vtk object was created by annother vtk library, and the
// python api used to create it cannot be used with FreeCAD
vtkObjectBase *obj = vtkPythonUtil::GetPointerFromObject(pcObj, "vtkObject");
if (!obj) {
PyErr_Clear();
return Py::False();
}
return Py::True();
}
#endif
#endif
Py::Object show(const Py::Tuple& args)