diff --git a/src/misc/closesimulation.cpp.inl b/src/misc/closesimulation.cpp.inl new file mode 100644 index 0000000000..40c918480b --- /dev/null +++ b/src/misc/closesimulation.cpp.inl @@ -0,0 +1,40 @@ +static PyObject * closeSimulation(PyObject *pSelf, PyObject *pArgs) +{ + Q_UNUSED(pSelf) + + // Close a simulation + + if (PyTuple_Size(pArgs) > 0) { +#include "pythonbegin.h" + PythonQtInstanceWrapper *wrappedSimulation = PythonQtSupport::getInstanceWrapper(PyTuple_GET_ITEM(pArgs, 0)); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast) +#include "pythonend.h" + + if (wrappedSimulation != nullptr) { +#ifdef GUI_SUPPORT + // Close the simulation by closing its file, raising an exception if + // we were unable to do so + + auto simulation = static_cast(wrappedSimulation->_objPointerCopy); + + if (!Core::centralWidget()->closeFile(simulation->fileName())) { + PyErr_SetString(PyExc_IOError, qPrintable(QObject::tr("unable to close the simulation"))); + + return nullptr; + } +#else + // Close the simulation by asking our file and simulation managers + // to umanage it + + auto simulation = static_cast(wrappedSimulation->_objPointerCopy); + QString fileName = simulation->fileName(); + + Core::FileManager::instance()->unmanage(fileName); + SimulationManager::instance()->unmanage(fileName); +#endif + } + } + +#include "pythonbegin.h" + Py_RETURN_NONE; +#include "pythonend.h" +} diff --git a/src/plugins/simulation/SimulationExperimentView/src/simulationexperimentviewpythonwrapper.cpp b/src/plugins/simulation/SimulationExperimentView/src/simulationexperimentviewpythonwrapper.cpp index 16cf6a4cbd..0958a21acd 100644 --- a/src/plugins/simulation/SimulationExperimentView/src/simulationexperimentviewpythonwrapper.cpp +++ b/src/plugins/simulation/SimulationExperimentView/src/simulationexperimentviewpythonwrapper.cpp @@ -115,35 +115,9 @@ static PyObject * initializeSimulation(const QString &pFileName) //============================================================================== -static PyObject * closeSimulation(PyObject *pSelf, PyObject *pArgs) -{ - Q_UNUSED(pSelf) - - // Close a simulation - - if (PyTuple_Size(pArgs) > 0) { -#include "pythonbegin.h" - PythonQtInstanceWrapper *wrappedSimulation = PythonQtSupport::getInstanceWrapper(PyTuple_GET_ITEM(pArgs, 0)); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast) -#include "pythonend.h" - - if (wrappedSimulation != nullptr) { - // Close the simulation by closing its file, raising an exception if - // we were unable to do so - - auto simulation = static_cast(wrappedSimulation->_objPointerCopy); - - if (!Core::centralWidget()->closeFile(simulation->fileName())) { - PyErr_SetString(PyExc_IOError, qPrintable(QObject::tr("unable to close the simulation"))); - - return nullptr; - } - } - } - -#include "pythonbegin.h" - Py_RETURN_NONE; -#include "pythonend.h" -} +#define GUI_SUPPORT + #include "closesimulation.cpp.inl" +#undef GUI_SUPPORT //============================================================================== diff --git a/src/plugins/support/SimulationSupport/src/simulationsupportpythonwrapper.cpp b/src/plugins/support/SimulationSupport/src/simulationsupportpythonwrapper.cpp index 77cd6f9c20..5f32f21d34 100644 --- a/src/plugins/support/SimulationSupport/src/simulationsupportpythonwrapper.cpp +++ b/src/plugins/support/SimulationSupport/src/simulationsupportpythonwrapper.cpp @@ -198,33 +198,7 @@ static PyObject * initializeSimulation(const QString &pFileName) //============================================================================== -static PyObject * closeSimulation(PyObject *pSelf, PyObject *pArgs) -{ - Q_UNUSED(pSelf) - - // Close a simulation - - if (PyTuple_Size(pArgs) > 0) { -#include "pythonbegin.h" - PythonQtInstanceWrapper *wrappedSimulation = PythonQtSupport::getInstanceWrapper(PyTuple_GET_ITEM(pArgs, 0)); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast) -#include "pythonend.h" - - if (wrappedSimulation != nullptr) { - // Close the simulation by asking our file and simulation managers - // to umanage it - - auto simulation = static_cast(wrappedSimulation->_objPointerCopy); - QString fileName = simulation->fileName(); - - Core::FileManager::instance()->unmanage(fileName); - SimulationManager::instance()->unmanage(fileName); - } - } - -#include "pythonbegin.h" - Py_RETURN_NONE; -#include "pythonend.h" -} +#include "closesimulation.cpp.inl" //==============================================================================