]> Creatis software - gdcm.git/blob - gdcmPython/gdcm.i
* Fix compilation error for the Python part
[gdcm.git] / gdcmPython / gdcm.i
1 %module gdcm
2 #pragma SWIG nowarn=504
3 %{
4 #include <iostream>
5
6 #include "gdcmCommon.h"
7 #include "gdcmBase.h"
8 #include "gdcmRefCounter.h"
9 #include "gdcmTagKey.h"
10 #include "gdcmVRKey.h"
11 #include "gdcmDict.h"
12 #include "gdcmDicomEntry.h"
13 #include "gdcmDictEntry.h"
14 #include "gdcmDictSet.h"
15 #include "gdcmDicomDir.h"
16 #include "gdcmDicomDirElement.h"
17 #include "gdcmDicomDirImage.h"
18 #include "gdcmDicomDirMeta.h"
19 #include "gdcmDicomDirObject.h"
20 #include "gdcmDicomDirPatient.h"
21 #include "gdcmDicomDirStudy.h"
22 #include "gdcmDicomDirSerie.h"
23 #include "gdcmDocEntrySet.h"
24 #include "gdcmDocument.h"
25 #include "gdcmElementSet.h"
26 #include "gdcmFileHelper.h"
27 #include "gdcmGlobal.h"
28 #include "gdcmFile.h"
29 #include "gdcmSerieHelper.h"
30 #include "gdcmRLEFramesInfo.h"
31 #include "gdcmJPEGFragmentsInfo.h"
32 #include "gdcmSQItem.h"
33 #include "gdcmUtil.h"
34 #include "gdcmDocEntry.h"
35 #include "gdcmDataEntry.h"
36 #include "gdcmSeqEntry.h"
37 #include "gdcmVR.h"
38 #include "gdcmTS.h"
39 #include "gdcmDictGroupName.h"
40
41 ////////////////////////////////////////////////////////////////////////////
42 /// Refer (below) to the definition of multi-argument typemap
43 ///   %typemap(python, in)
44 ///      ( gdcm::DicomDir::Method*, void*, gdcm::DicomDir::Method*)
45 /// for detail on gdcmPythonVoidFunc() and gdcmPythonVoidFuncArgDelete().
46 void gdcmPythonVoidFunc(void *arg)
47 {
48    PyObject *arglist, *result;
49    PyObject *func = (PyObject *)arg;
50
51    arglist = Py_BuildValue("()");
52
53    result = PyEval_CallObject(func, arglist);
54    Py_DECREF(arglist);
55
56    if (result)
57    {
58       Py_XDECREF(result);
59    }
60    else
61    {
62       if (PyErr_ExceptionMatches(PyExc_KeyboardInterrupt))
63       {
64          std::cerr << "Caught a Ctrl-C within python, exiting program.\n";
65          Py_Exit(1);
66       }
67       PyErr_Print();
68    }
69 }
70
71 void gdcmPythonVoidFuncArgDelete(void *arg)
72 {
73    PyObject *func = (PyObject *)arg;
74    if (func)
75    {
76       Py_DECREF(func);
77    }
78 }
79
80 /// This is required in order to avoid %including all the gdcm include files.
81 using namespace gdcm;
82 %}
83
84
85 ///////////////////////  typemap section  ////////////////////////////////////
86
87 ////////////////////////////////////////////////
88 // Redefine all types used
89 typedef char int8_t;
90 typedef unsigned char uint8_t;
91 typedef short int16_t;
92 typedef unsigned short uint16_t;
93 typedef int int32_t;
94 typedef unsigned int uint32_t;
95 typedef long long int64_t;
96 typedef unsigned long long uint64_t;
97
98 ////////////////////////////////////////////////
99 // Convert a DocEntry * to the real derived class
100 %typemap(out) gdcm::DocEntry * 
101 {
102    PyObject *newEntry;
103
104    if($1)
105    {
106       if(dynamic_cast<SeqEntry *>($1)) // SeqEntry *
107          newEntry = SWIG_NewPointerObj($1,SWIGTYPE_p_gdcm__SeqEntry,0);
108       else if(dynamic_cast<DataEntry *>($1)) // DataEntry *
109          newEntry = SWIG_NewPointerObj($1,SWIGTYPE_p_gdcm__DataEntry,0);
110       else
111          newEntry = NULL;
112    }
113    else
114    {
115       newEntry = Py_BuildValue("");
116    }
117    $result = newEntry;
118 }
119
120 ////////////////////////////////////////////////////////////////////////////
121 // Multi-argument typemap designed for wrapping the progress related methods
122 // in order to control from an external application the computation of
123 // a DicomDir object (see DicomDir::SetStartMethod*,
124 // DicomDir::SetProgressMethod* and DicomDir::SetEndMethod*).
125 // Motivation: since DicomDir parsing can be quite long, a GUI application
126 //             needs to display the avancement and potentially offer a
127 //             cancel method to the user (when this one feels things are
128 //             longer than expected).
129 // Example of usage: refer to demo/DicomDirProgressMethod.py
130 // Note: Uses gdcmPythonVoidFunc and gdcmPythonVoidFuncArgDelete defined
131 //       in the Swig verbatim section of this gdcm.i i.e. in the above section
132 //       enclosed within the %{ ... %} scope operator ).
133 %typemap(python, in) (void(*method)(void *),void *arg,void(*argDelete)(void *))
134 {
135         if($input!=Py_None)
136         {
137                 Py_INCREF($input);
138                 $1=gdcmPythonVoidFunc;
139                 $2=$input;
140                 $3=gdcmPythonVoidFuncArgDelete;
141         }
142         else
143         {
144                 $1=NULL;
145                 $2=NULL;
146                 $3=NULL;
147         }
148 }
149
150 ////////////////////  STL string versus Python str  ////////////////////////
151 // Convertion returning a C++ string.
152 %typemap(out) std::string
153 {
154     $result = PyString_FromString(($1).c_str());
155 }
156
157 %typemap(out) string
158 {
159     $result = PyString_FromString(($1).c_str());
160 }
161
162 %typemap(out) std::string const &
163 {
164     $result = PyString_FromString(($1)->c_str());
165 }
166
167 // Convertion of incoming Python str to STL string
168 %typemap(python, in) const std::string, std::string
169 {
170   $1 = PyString_AsString($input);
171 }
172
173 // Same convertion as above but references (since swig converts C++
174 // refererences to pointers)
175 %typemap(python, in) std::string const &
176 {
177    $1 = new std::string( PyString_AsString( $input ) );
178 }
179
180 ////////////////////  gdcm.TagName versus Python str  //////////////////////
181 %typemap(out) gdcm::TagName, const gdcm::TagName &
182 {
183     $result = PyString_FromString(($1)->c_str());
184 }
185
186 // Convertion of incoming Python str to STL string
187 %typemap(python, in) const gdcm::TagName, gdcm::TagName
188 {
189   $1 = PyString_AsString($input);
190 }
191
192 // Same convertion as above but references (since swig converts C++
193 // refererences to pointers)
194 %typemap(python, in) gdcm::TagName const &
195 {
196    $1 = new std::string( PyString_AsString( $input ) );
197 }
198
199 ////////////////////////////////////////////////////////////////////////////
200 // Because overloading and %rename don't work together (see below Note 1)
201 // we need to ignore some methods (e.g. the overloaded default constructor).
202 // The gdcm::File class doesn't have any SetFilename method anyhow, and
203 // this constructor is only used internaly (not from the API) so this is
204 // not a big loss.
205 %ignore gdcm::binary_write(std::ostream &,uint32_t const &);
206 %ignore gdcm::binary_write(std::ostream &,uint16_t const &);
207
208 %ignore gdcm::VRKey::operator=(const VRKey &_val);
209 %ignore gdcm::VRKey::operator=(const std::string &_val);
210 %ignore gdcm::VRKey::operator=(const char *_val);
211 %ignore gdcm::VRKey::operator[](const unsigned int &_id) const;
212 %ignore gdcm::VRKey::operator[](const unsigned int &_id);
213
214 %ignore gdcm::TagKey::operator=(const TagKey &_val);
215 %ignore gdcm::TagKey::operator[](const unsigned int &_id) const;
216 %ignore gdcm::TagKey::operator[](const unsigned int &_id);
217
218 %ignore gdcm::DicomDir::SetStartMethod(DicomDir::Method *method,void *arg = NULL);
219 %ignore gdcm::DicomDir::SetProgressMethod(DicomDir::Method *method,void *arg = NULL);
220 %ignore gdcm::DicomDir::SetEndMethod(DicomDir::Method *method,void *arg = NULL);
221
222 // Ignore all placed in gdcmCommon.h
223 %ignore GDCM_UNKNOWN;
224 %ignore GDCM_UNFOUND;
225 %ignore GDCM_BINLOADED;
226 %ignore GDCM_NOTLOADED;
227 %ignore GDCM_UNREAD;
228 %ignore GDCM_NOTASCII;
229 %ignore GDCM_PIXELDATA;
230 %ignore GDCM_LEGACY;
231 %ignore GDCM_VRUNKNOWN;
232
233 %constant const char *UNKNOWN        = "gdcm::Unknown";
234 %constant const char *UNFOUND        = "gdcm::Unfound";
235 %constant const char *BINLOADED      = "gdcm::Binary data loaded";
236 %constant const char *NOTLOADED      = "gdcm::NotLoaded";
237 %constant const char *UNREAD         = "gdcm::UnRead";
238 %constant const char *GDCM_NOTASCII  = "gdcm::NotAscii";
239 %constant const char *GDCM_PIXELDATA = "gdcm::Pixel Data to be loaded";
240 %constant const char *VRUNKNOWN      = "  ";
241
242 ////////////////////////////////////////////////////////////////////////////
243 // Warning: Order matters !
244 %include "gdcmCommon.h"
245 %include "gdcmBase.h"
246 %include "gdcmRefCounter.h"
247 %include "gdcmTagKey.h"
248 %include "gdcmVRKey.h"
249 %include "gdcmDicomEntry.h"
250 %include "gdcmDictEntry.h"
251 %include "gdcmDict.h"
252 %include "gdcmDictSet.h"
253 %include "gdcmDocEntrySet.h"
254 %include "gdcmElementSet.h"
255 %include "gdcmSQItem.h"
256 %include "gdcmDicomDirElement.h"
257 %include "gdcmDicomDirObject.h"
258 %include "gdcmDicomDirImage.h"
259 %include "gdcmDicomDirSerie.h"
260 %include "gdcmDicomDirStudy.h"
261 %include "gdcmDicomDirPatient.h"
262 %include "gdcmDicomDirMeta.h"
263 %include "gdcmDocument.h"
264 %include "gdcmFile.h"
265 %include "gdcmSerieHelper.h"
266 %include "gdcmFileHelper.h"
267 %include "gdcmUtil.h"
268 %include "gdcmGlobal.h"
269 %include "gdcmDicomDir.h"
270 %include "gdcmDocEntry.h"
271 %include "gdcmDataEntry.h"
272 %include "gdcmSeqEntry.h"
273 %include "gdcmVR.h"
274 %include "gdcmTS.h"
275 %include "gdcmDictGroupName.h"