2 #pragma SWIG nowarn=504
6 #include "gdcmCommon.h"
9 #include "gdcmDictEntry.h"
10 #include "gdcmDictSet.h"
11 #include "gdcmDicomDir.h"
12 #include "gdcmDicomDirElement.h"
13 #include "gdcmDicomDirImage.h"
14 #include "gdcmDicomDirMeta.h"
15 #include "gdcmDicomDirObject.h"
16 #include "gdcmDicomDirPatient.h"
17 #include "gdcmDicomDirStudy.h"
18 #include "gdcmDicomDirSerie.h"
19 #include "gdcmDocEntrySet.h"
20 #include "gdcmDocument.h"
21 #include "gdcmElementSet.h"
22 #include "gdcmFileHelper.h"
23 #include "gdcmGlobal.h"
25 #include "gdcmSerieHelper.h"
26 #include "gdcmRLEFramesInfo.h"
27 #include "gdcmJPEGFragmentsInfo.h"
28 #include "gdcmSQItem.h"
30 #include "gdcmDocEntry.h"
31 #include "gdcmContentEntry.h"
32 #include "gdcmValEntry.h"
33 #include "gdcmBinEntry.h"
34 #include "gdcmSeqEntry.h"
37 #include "gdcmDictGroupName.h"
39 ////////////////////////////////////////////////////////////////////////////
40 /// Refer (below) to the definition of multi-argument typemap
41 /// %typemap(python, in)
42 /// ( gdcm::DicomDir::Method*, void*, gdcm::DicomDir::Method*)
43 /// for detail on gdcmPythonVoidFunc() and gdcmPythonVoidFuncArgDelete().
44 void gdcmPythonVoidFunc(void *arg)
46 PyObject *arglist, *result;
47 PyObject *func = (PyObject *)arg;
49 arglist = Py_BuildValue("()");
51 result = PyEval_CallObject(func, arglist);
60 if (PyErr_ExceptionMatches(PyExc_KeyboardInterrupt))
62 std::cerr << "Caught a Ctrl-C within python, exiting program.\n";
69 void gdcmPythonVoidFuncArgDelete(void *arg)
71 PyObject *func = (PyObject *)arg;
78 /// This is required in order to avoid %including all the gdcm include files.
83 /////////////////////// typemap section ////////////////////////////////////
85 ////////////////////////////////////////////////
86 // Redefine all types used
88 typedef unsigned char uint8_t;
89 typedef short int16_t;
90 typedef unsigned short uint16_t;
92 typedef unsigned int uint32_t;
93 typedef long long int64_t;
94 typedef unsigned long long uint64_t;
96 ////////////////////////////////////////////////
97 // Convert a DocEntry * to the real derived class
98 %typemap(out) gdcm::DocEntry *
104 if(dynamic_cast<SeqEntry *>($1)) // SeqEntry *
105 newEntry = SWIG_NewPointerObj($1,SWIGTYPE_p_gdcm__SeqEntry,0);
106 else if(dynamic_cast<BinEntry *>($1)) // BinEntry *
107 newEntry = SWIG_NewPointerObj($1,SWIGTYPE_p_gdcm__BinEntry,0);
109 newEntry = SWIG_NewPointerObj($1,SWIGTYPE_p_gdcm__ValEntry,0);
113 newEntry = Py_BuildValue("");
118 ////////////////////////////////////////////////////////////////////////////
119 // Multi-argument typemap designed for wrapping the progress related methods
120 // in order to control from an external application the computation of
121 // a DicomDir object (see DicomDir::SetStartMethod*,
122 // DicomDir::SetProgressMethod* and DicomDir::SetEndMethod*).
123 // Motivation: since DicomDir parsing can be quite long, a GUI application
124 // needs to display the avancement and potentially offer a
125 // cancel method to the user (when this one feels things are
126 // longer than expected).
127 // Example of usage: refer to demo/DicomDirProgressMethod.py
128 // Note: Uses gdcmPythonVoidFunc and gdcmPythonVoidFuncArgDelete defined
129 // in the Swig verbatim section of this gdcm.i i.e. in the above section
130 // enclosed within the %{ ... %} scope operator ).
131 %typemap(python, in) (void(*method)(void *),void *arg,void(*argDelete)(void *))
136 $1=gdcmPythonVoidFunc;
138 $3=gdcmPythonVoidFuncArgDelete;
148 //////////////////// STL string versus Python str ////////////////////////
149 // Convertion returning a C++ string.
150 %typemap(out) std::string
152 $result = PyString_FromString(($1).c_str());
157 $result = PyString_FromString(($1).c_str());
160 %typemap(out) std::string const &
162 $result = PyString_FromString(($1)->c_str());
165 // Convertion of incoming Python str to STL string
166 %typemap(python, in) const std::string, std::string
168 $1 = PyString_AsString($input);
171 // Same convertion as above but references (since swig converts C++
172 // refererences to pointers)
173 %typemap(python, in) std::string const &
175 $1 = new std::string( PyString_AsString( $input ) );
178 //////////////////// gdcm.TagName versus Python str //////////////////////
179 %typemap(out) gdcm::TagName, const gdcm::TagName &
181 $result = PyString_FromString(($1)->c_str());
184 // Convertion of incoming Python str to STL string
185 %typemap(python, in) const gdcm::TagName, gdcm::TagName
187 $1 = PyString_AsString($input);
190 // Same convertion as above but references (since swig converts C++
191 // refererences to pointers)
192 %typemap(python, in) gdcm::TagName const &
194 $1 = new std::string( PyString_AsString( $input ) );
197 ////////////////////////////////////////////////////////////////////////////
198 // Because overloading and %rename don't work together (see below Note 1)
199 // we need to ignore some methods (e.g. the overloaded default constructor).
200 // The gdcm::File class doesn't have any SetFilename method anyhow, and
201 // this constructor is only used internaly (not from the API) so this is
203 %ignore gdcm::binary_write(std::ostream &,uint32_t const &);
204 %ignore gdcm::binary_write(std::ostream &,uint16_t const &);
206 %ignore gdcm::DicomDir::SetStartMethod(DicomDir::Method *method,void *arg = NULL);
207 %ignore gdcm::DicomDir::SetProgressMethod(DicomDir::Method *method,void *arg = NULL);
208 %ignore gdcm::DicomDir::SetEndMethod(DicomDir::Method *method,void *arg = NULL);
210 // Ignore all placed in gdcmCommon.h
211 %ignore GDCM_UNKNOWN;
212 %ignore GDCM_UNFOUND;
213 %ignore GDCM_BINLOADED;
214 %ignore GDCM_NOTLOADED;
217 %constant const char *UNKNOWN = "gdcm::Unknown";
218 %constant const char *UNFOUND = "gdcm::Unfound";
219 %constant const char *BINLOADED = "gdcm::Binary data loaded";
220 %constant const char *NOTLOADED = "gdcm::NotLoaded";
221 %constant const char *UNREAD = "gdcm::UnRead";
223 ////////////////////////////////////////////////////////////////////////////
224 // Warning: Order matters !
225 %include "gdcmCommon.h"
226 %include "gdcmBase.h"
227 %include "gdcmDictEntry.h"
228 %include "gdcmDict.h"
229 %include "gdcmDictSet.h"
230 %include "gdcmDocEntrySet.h"
231 %include "gdcmElementSet.h"
232 %include "gdcmSQItem.h"
233 %include "gdcmDicomDirElement.h"
234 %include "gdcmDicomDirObject.h"
235 %include "gdcmDicomDirImage.h"
236 %include "gdcmDicomDirSerie.h"
237 %include "gdcmDicomDirStudy.h"
238 %include "gdcmDicomDirPatient.h"
239 %include "gdcmDicomDirMeta.h"
240 %include "gdcmDocument.h"
241 %include "gdcmFile.h"
242 %include "gdcmSerieHelper.h"
243 %include "gdcmFileHelper.h"
244 %include "gdcmUtil.h"
245 %include "gdcmGlobal.h"
246 %include "gdcmDicomDir.h"
247 %include "gdcmDocEntry.h"
248 %include "gdcmContentEntry.h"
249 %include "gdcmValEntry.h"
250 %include "gdcmBinEntry.h"
251 %include "gdcmSeqEntry.h"
254 %include "gdcmDictGroupName.h"
256 ////////////////////////////////////////////////////////////////////////////
257 // Notes on swig and this file gdcm.i:
259 /////////////////////////////////////
260 // Note 1: swig collision of method overloading and %typemap
261 // Consider the following junk.i file:
265 // #include <iostream>
266 // void Junk(std::string const & bozo) { std::cout << bozo << std::endl; }
267 // void Junk() { std::cout << "Renamed Junk()" << std::endl; }
270 // %typemap(python, in) std::string const &
272 // $1 = new std::string( PyString_AsString( $input ) );
275 // void Junk(std::string const & bozo);
277 // that we compile on linux with:
278 // swig -c++ -python junk.i
279 // g++ -g -I/usr/include/python2.3/ -o junk_wrap.o -c junk_wrap.cxx
280 // g++ junk_wrap.o -shared -g -o _junk.so -L/usr/lib/python2.3/config \
283 // python -c 'from junk import *; Junk("aaa") '
284 // then we get the following unexpected (for novice) python TypeError:
285 // TypeError: No matching function for overloaded 'Junk'
287 // This happens because the swig generated code (at least for python) does
288 // the following two stage process:
289 // 1/ first do a dynamic dispatch ON THE NUMBER OF ARGUMENTS of the overloaded
290 // Junk function (the same happens with method of course). [Note that the
291 // dispatch is NOT done on the type of the arguments].
292 // 2/ second apply the typemap.
293 // When the first dynamic dispatch is executed, the swig generated code
294 // has no knowledge of the typemap, and thus expects a pointer to a std::string
295 // type i.e. an argument to Junk of the form _p_std__int<address>. But this
296 // is not what python handles to Junk ! An invocation of the form 'Junk("aaa")'
297 // will make Python pass a PyString to swig (and this is precisely why we
298 // wrote the typemap). And this will fail....
299 /////////////////////////////////////