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