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) ( gdcm::DicomDir::Method *,
133 gdcm::DicomDir::Method * = NULL )
138 $1=gdcmPythonVoidFunc;
140 $3=gdcmPythonVoidFuncArgDelete;
150 //////////////////// STL string versus Python str ////////////////////////
151 // Convertion returning a C++ string.
152 %typemap(out) std::string
154 $result = PyString_FromString(($1).c_str());
159 $result = PyString_FromString(($1).c_str());
162 %typemap(out) std::string const &
164 $result = PyString_FromString(($1)->c_str());
167 // Convertion of incoming Python str to STL string
168 %typemap(python, in) const std::string, std::string
170 $1 = PyString_AsString($input);
173 // Same convertion as above but references (since swig converts C++
174 // refererences to pointers)
175 %typemap(python, in) std::string const &
177 $1 = new std::string( PyString_AsString( $input ) );
180 //////////////////// gdcm.TagName versus Python str //////////////////////
181 %typemap(out) gdcm::TagName, const gdcm::TagName &
183 $result = PyString_FromString(($1)->c_str());
186 // Convertion of incoming Python str to STL string
187 %typemap(python, in) const gdcm::TagName, gdcm::TagName
189 $1 = PyString_AsString($input);
192 // Same convertion as above but references (since swig converts C++
193 // refererences to pointers)
194 %typemap(python, in) gdcm::TagName const &
196 $1 = new std::string( PyString_AsString( $input ) );
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
205 %ignore gdcm::binary_write(std::ostream &,uint32_t const &);
206 %ignore gdcm::binary_write(std::ostream &,uint16_t const &);
208 //%ignore gdcm::File::File();
209 //%ignore gdcm::DicomDir::DicomDir();
211 // Ignore all placed in gdcmCommon.h
212 %ignore GDCM_UNKNOWN;
213 %ignore GDCM_UNFOUND;
214 %ignore GDCM_BINLOADED;
215 %ignore GDCM_NOTLOADED;
218 %constant const char *UNKNOWN = "gdcm::Unknown";
219 %constant const char *UNFOUND = "gdcm::Unfound";
220 %constant const char *BINLOADED = "gdcm::Binary data loaded";
221 %constant const char *NOTLOADED = "gdcm::NotLoaded";
222 %constant const char *UNREAD = "gdcm::UnRead";
224 ////////////////////////////////////////////////////////////////////////////
225 // Warning: Order matters !
226 %include "gdcmCommon.h"
227 %include "gdcmBase.h"
228 %include "gdcmDictEntry.h"
229 %include "gdcmDict.h"
230 %include "gdcmDictSet.h"
231 %include "gdcmDocEntrySet.h"
232 %include "gdcmElementSet.h"
233 %include "gdcmSQItem.h"
234 %include "gdcmDicomDirElement.h"
235 %include "gdcmDicomDirObject.h"
236 %include "gdcmDicomDirImage.h"
237 %include "gdcmDicomDirSerie.h"
238 %include "gdcmDicomDirStudy.h"
239 %include "gdcmDicomDirPatient.h"
240 %include "gdcmDicomDirMeta.h"
241 %include "gdcmDocument.h"
242 %include "gdcmFile.h"
243 %include "gdcmSerieHelper.h"
244 %include "gdcmFileHelper.h"
245 %include "gdcmUtil.h"
246 %include "gdcmGlobal.h"
247 %include "gdcmDicomDir.h"
248 %include "gdcmDocEntry.h"
249 %include "gdcmContentEntry.h"
250 %include "gdcmValEntry.h"
251 %include "gdcmBinEntry.h"
252 %include "gdcmSeqEntry.h"
255 %include "gdcmDictGroupName.h"
257 ////////////////////////////////////////////////////////////////////////////
258 // Notes on swig and this file gdcm.i:
260 /////////////////////////////////////
261 // Note 1: swig collision of method overloading and %typemap
262 // Consider the following junk.i file:
266 // #include <iostream>
267 // void Junk(std::string const & bozo) { std::cout << bozo << std::endl; }
268 // void Junk() { std::cout << "Renamed Junk()" << std::endl; }
271 // %typemap(python, in) std::string const &
273 // $1 = new std::string( PyString_AsString( $input ) );
276 // void Junk(std::string const & bozo);
278 // that we compile on linux with:
279 // swig -c++ -python junk.i
280 // g++ -g -I/usr/include/python2.3/ -o junk_wrap.o -c junk_wrap.cxx
281 // g++ junk_wrap.o -shared -g -o _junk.so -L/usr/lib/python2.3/config \
284 // python -c 'from junk import *; Junk("aaa") '
285 // then we get the following unexpected (for novice) python TypeError:
286 // TypeError: No matching function for overloaded 'Junk'
288 // This happens because the swig generated code (at least for python) does
289 // the following two stage process:
290 // 1/ first do a dynamic dispatch ON THE NUMBER OF ARGUMENTS of the overloaded
291 // Junk function (the same happens with method of course). [Note that the
292 // dispatch is NOT done on the type of the arguments].
293 // 2/ second apply the typemap.
294 // When the first dynamic dispatch is executed, the swig generated code
295 // has no knowledge of the typemap, and thus expects a pointer to a std::string
296 // type i.e. an argument to Junk of the form _p_std__int<address>. But this
297 // is not what python handles to Junk ! An invocation of the form 'Junk("aaa")'
298 // will make Python pass a PyString to swig (and this is precisely why we
299 // wrote the typemap). And this will fail....
300 /////////////////////////////////////