Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python support: merge duplicated code (#2225).
- Loading branch information
Showing
3 changed files
with
44 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<SimulationSupport::Simulation *>(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<SimulationSupport::Simulation *>(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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters