Skip to content

Commit

Permalink
Simulation support: merged our openSimulation and openRemoteSimulatio…
Browse files Browse the repository at this point in the history
…n Python wrappers.
  • Loading branch information
agarny committed Nov 20, 2019
1 parent 9f0c9b2 commit ec90994
Showing 1 changed file with 22 additions and 40 deletions.
Expand Up @@ -194,75 +194,58 @@ static PyObject * initializeSimulation(const QString &pFileName)

//==============================================================================

static PyObject * openSimulation(PyObject *self, PyObject *args)
static PyObject * openSimulation(PyObject *pSelf, PyObject *pArgs)
{
Q_UNUSED(self)
Q_UNUSED(pSelf)

// Open a simulation

PyObject *bytes;
char *name;
Py_ssize_t len;
if (PyArg_ParseTuple(args, "O&", PyUnicode_FSConverter, &bytes) == 0) { // NOLINT(cppcoreguidelines-pro-type-vararg)

if (PyArg_ParseTuple(pArgs, "O&", PyUnicode_FSConverter, &bytes) == 0) { // NOLINT(cppcoreguidelines-pro-type-vararg)
#include "pythonbegin.h"
Py_RETURN_NONE;
#include "pythonend.h"
}
PyBytes_AsStringAndSize(bytes, &name, &len);
QString fileName = QString::fromUtf8(name, int(len));
#include "pythonbegin.h"
Py_DECREF(bytes);
#include "pythonend.h"

QString error = Core::openFile(fileName);

if (!error.isEmpty()) {
PyErr_SetString(PyExc_IOError, qPrintable(error));

return nullptr;
}
char *string;
Py_ssize_t len;

return initializeSimulation(QFileInfo(fileName).canonicalFilePath());
}
PyBytes_AsStringAndSize(bytes, &string, &len);

//==============================================================================
bool isLocalFile;
QString fileNameOrUrl;

static PyObject * openRemoteSimulation(PyObject *self, PyObject *args)
{
Q_UNUSED(self)
Core::checkFileNameOrUrl(QString::fromUtf8(string, int(len)), isLocalFile, fileNameOrUrl);

PyObject *bytes;
char *name;
Py_ssize_t len;
if (PyArg_ParseTuple(args, "O&", PyUnicode_FSConverter, &bytes) == 0) { // NOLINT(cppcoreguidelines-pro-type-vararg)
#include "pythonbegin.h"
Py_RETURN_NONE;
#include "pythonend.h"
}
PyBytes_AsStringAndSize(bytes, &name, &len);
QString url = QString::fromUtf8(name, int(len));
#include "pythonbegin.h"
Py_DECREF(bytes);
#include "pythonend.h"

QString error = Core::openRemoteFile(url);
QString error = isLocalFile?
Core::openFile(fileNameOrUrl):
Core::openRemoteFile(fileNameOrUrl);

if (!error.isEmpty()) {
PyErr_SetString(PyExc_IOError, qPrintable(error));

return nullptr;
}

return initializeSimulation(Core::localFileName(url));
return initializeSimulation(isLocalFile?
fileNameOrUrl:
Core::FileManager::instance()->fileName(fileNameOrUrl));
}

//==============================================================================

static PyObject * closeSimulation(PyObject *self, PyObject *args)
static PyObject * closeSimulation(PyObject *pSelf, PyObject *pArgs)
{
Q_UNUSED(self)
Q_UNUSED(pSelf)

if (PyTuple_Size(args) > 0) {
if (PyTuple_Size(pArgs) > 0) {
#include "pythonbegin.h"
PythonQtInstanceWrapper *wrappedSimulation = PythonQtSupport::getInstanceWrapper(PyTuple_GET_ITEM(args, 0)); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
PythonQtInstanceWrapper *wrappedSimulation = PythonQtSupport::getInstanceWrapper(PyTuple_GET_ITEM(pArgs, 0)); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
#include "pythonend.h"

if (wrappedSimulation != nullptr) {
Expand Down Expand Up @@ -305,7 +288,6 @@ SimulationSupportPythonWrapper::SimulationSupportPythonWrapper(PyObject *pModule

static std::array<PyMethodDef, 4> PythonSimulationSupportMethods = {{
{ "openSimulation", openSimulation, METH_VARARGS, "Open a simulation." },
{ "openRemoteSimulation", openRemoteSimulation, METH_VARARGS, "Open a remote simulation." },
{ "closeSimulation", closeSimulation, METH_VARARGS, "Close a simulation." },
{ nullptr, nullptr, 0, nullptr }
}};
Expand Down

0 comments on commit ec90994

Please sign in to comment.