Mercurial > hg > orthanc-python
diff Sources/Plugin.cpp @ 63:32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 10 Jun 2021 18:19:27 +0200 |
parents | 23f3099bed47 |
children | 091fb1903bfc |
line wrap: on
line diff
--- a/Sources/Plugin.cpp Fri May 28 10:53:18 2021 +0200 +++ b/Sources/Plugin.cpp Thu Jun 10 18:19:27 2021 +0200 @@ -24,6 +24,7 @@ // https://fr.slideshare.net/YiLungTsai/embed-python +#include "DicomScpCallbacks.h" #include "IncomingHttpRequestFilter.h" #include "OnChangeCallback.h" #include "OnStoredInstanceCallback.h" @@ -51,6 +52,54 @@ +PyObject* CreateDicom(PyObject* module, PyObject* args) +{ + // The GIL is locked at this point (no need to create "PythonLock") + const char* json = NULL; + PyObject* pixelData = NULL; + long int flags = 0; + + if (!PyArg_ParseTuple(args, "sOl", &json, &pixelData, &flags)) + { + PyErr_SetString(PyExc_TypeError, "Please provide a JSON string, an orthanc.Image object, and a set of orthanc.CreateDicomFlags"); + return NULL; + } + else + { + OrthancPluginImage* image = NULL; + + if (pixelData == Py_None) + { + // No pixel data + } + else if (Py_TYPE(pixelData) == GetOrthancPluginImageType()) + { + image = reinterpret_cast<sdk_OrthancPluginImage_Object*>(pixelData)->object_; + } + else + { + PyErr_SetString(PyExc_TypeError, "Second parameter is not a valid orthanc.Image"); + return NULL; + } + + OrthancPlugins::MemoryBuffer buffer; + OrthancPluginErrorCode code = OrthancPluginCreateDicom(OrthancPlugins::GetGlobalContext(), *buffer, json, image, + static_cast<OrthancPluginCreateDicomFlags>(flags)); + + if (code == OrthancPluginErrorCode_Success) + { + return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); + } + else + { + PyErr_SetString(PyExc_ValueError, "Cannot create the DICOM instance"); + return NULL; + } + } +} + + + static bool pythonEnabled_ = false; static std::string userScriptName_; static std::vector<PyMethodDef> globalFunctions_; @@ -91,11 +140,36 @@ functions.push_back(f); } + + /** + * New in release 3.0 + **/ + { - // New in release 3.0 PyMethodDef f = { "RegisterIncomingHttpRequestFilter", RegisterIncomingHttpRequestFilter, METH_VARARGS, "" }; functions.push_back(f); } + + + /** + * New in release 3.1 + **/ + + { + PyMethodDef f = { "CreateDicom", CreateDicom, METH_VARARGS, "" }; + functions.push_back(f); + } + + { + PyMethodDef f = { "RegisterFindCallback", RegisterFindCallback, METH_VARARGS, "" }; + functions.push_back(f); + } + + { + PyMethodDef f = { "RegisterMoveCallback", RegisterMoveCallback, METH_VARARGS, "" }; + functions.push_back(f); + } + /** * Append all the global functions that were automatically generated @@ -298,6 +372,7 @@ FinalizeRestCallbacks(); FinalizeOnStoredInstanceCallback(); FinalizeIncomingHttpRequestFilter(); + FinalizeDicomScpCallbacks(); PythonLock::GlobalFinalize(); }