Salome HOME
faac758321c176b8785116a543f60447d3088d2f
[modules/med.git] / src / MEDCoupling_Swig / MEDCouplingTypemaps.i
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifdef WITH_NUMPY2
21 #include <numpy/arrayobject.h>
22 #endif
23
24 static PyObject *convertMesh(ParaMEDMEM::MEDCouplingMesh *mesh, int owner) throw(INTERP_KERNEL::Exception)
25 {
26   PyObject *ret=0;
27   if(dynamic_cast<ParaMEDMEM::MEDCouplingUMesh *>(mesh))
28     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,owner);
29   if(dynamic_cast<ParaMEDMEM::MEDCouplingExtrudedMesh *>(mesh))
30     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingExtrudedMesh,owner);
31   if(dynamic_cast<ParaMEDMEM::MEDCouplingCMesh *>(mesh))
32     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCMesh,owner);
33   if(dynamic_cast<ParaMEDMEM::MEDCouplingCurveLinearMesh *>(mesh))
34     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCurveLinearMesh,owner);
35   if(!ret)
36     throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !");
37   return ret;
38 }
39
40 static PyObject *convertFieldDiscretization(ParaMEDMEM::MEDCouplingFieldDiscretization *fd, int owner) throw(INTERP_KERNEL::Exception)
41 {
42   PyObject *ret=0;
43   if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP0 *>(fd))
44     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP0,owner);
45   if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP1 *>(fd))
46     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP1,owner);
47   if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGauss *>(fd))
48     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGauss,owner);
49   if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGaussNE *>(fd))
50     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGaussNE,owner);
51   if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationKriging *>(fd))
52     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationKriging,owner);
53   if(!ret)
54     throw INTERP_KERNEL::Exception("Not recognized type of field discretization on downcast !");
55   return ret;
56 }
57
58 static PyObject* convertMultiFields(ParaMEDMEM::MEDCouplingMultiFields *mfs, int owner) throw(INTERP_KERNEL::Exception)
59 {
60   PyObject *ret=0;
61   if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldOverTime *>(mfs))
62     ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldOverTime,owner);
63   else
64     ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingMultiFields,owner);
65   return ret;
66 }
67
68 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
69 {
70 #ifndef WITH_NUMPY2
71   PyObject *ret=PyList_New(size);
72   for(int i=0;i<size;i++)
73     PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
74   return ret;
75 #else
76   npy_intp dim = (npy_intp) size;
77   int *tmp=new int[size];
78   std::copy(ptr,ptr+size,tmp);
79   return PyArray_SimpleNewFromData(1,&dim,NPY_INT,const_cast<int *>(tmp));
80 #endif
81 }
82
83 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
84 {
85 #ifndef WITH_NUMPY2
86   int size=v.size();
87   PyObject *ret=PyList_New(size);
88   for(int i=0;i<size;i++)
89     PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
90   return ret;
91 #else
92   npy_intp dim = (npy_intp) v.size();
93   int *tmp=new int[v.size()];
94   std::copy(v.begin(),v.end(),tmp);
95   return PyArray_SimpleNewFromData(1,&dim,NPY_INT,tmp);
96 #endif
97 }
98
99 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
100 {
101   int size=v.size();
102   PyObject *ret=PyList_New(size);
103   std::set<int>::const_iterator it=v.begin();
104   for(int i=0;i<size;i++,it++)
105     PyList_SetItem(ret,i,PyInt_FromLong(*it));
106   return ret;
107 }
108
109 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
110 {
111   PyObject *ret=PyList_New(nbOfTuples);
112   for(int i=0;i<nbOfTuples;i++)
113     {
114       PyObject *t=PyTuple_New(nbOfComp);
115       for(int j=0;j<nbOfComp;j++)
116         PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
117       PyList_SetItem(ret,i,t);
118     }
119   return ret;
120 }
121
122 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
123 {
124   if(PyList_Check(pyLi))
125     {
126       *size=PyList_Size(pyLi);
127       int *tmp=new int[*size];
128       for(int i=0;i<*size;i++)
129         {
130           PyObject *o=PyList_GetItem(pyLi,i);
131           if(PyInt_Check(o))
132             {
133               int val=(int)PyInt_AS_LONG(o);
134               tmp[i]=val;
135             }
136           else
137             {
138               delete [] tmp;
139               throw INTERP_KERNEL::Exception("list must contain integers only");
140             }
141         }
142       return tmp;
143     }
144   else if(PyTuple_Check(pyLi))
145     {
146       *size=PyTuple_Size(pyLi);
147       int *tmp=new int[*size];
148       for(int i=0;i<*size;i++)
149         {
150           PyObject *o=PyTuple_GetItem(pyLi,i);
151           if(PyInt_Check(o))
152             {
153               int val=(int)PyInt_AS_LONG(o);
154               tmp[i]=val;
155             }
156           else
157             {
158               delete [] tmp;
159               throw INTERP_KERNEL::Exception("tuple must contain integers only");
160             }
161         }
162       return tmp;
163     }
164   else
165     {
166 #ifndef WITH_NUMPY2
167       throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
168 #else
169       if(PyArray_Check(pyLi))
170         {
171           npy_intp mySize = PyArray_SIZE(pyLi);
172           int *ret=(int *)PyArray_BYTES(pyLi);
173           *size=mySize;
174           return ret;
175         }
176       else
177         {
178           throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list nor PyArray");
179         }
180 #endif
181     }
182 }
183
184 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
185 {
186   const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
187   if(PyList_Check(pyLi))
188     {
189       int size=PyList_Size(pyLi);
190       arr.resize(size);
191       for(int i=0;i<size;i++)
192         {
193           PyObject *o=PyList_GetItem(pyLi,i);
194           if(PyTuple_Check(o))
195             {
196               int sz2=PyTuple_Size(o);
197               if(sz2!=2)
198                 throw INTERP_KERNEL::Exception(msg);
199               PyObject *o_0=PyTuple_GetItem(o,0);
200               if(!PyInt_Check(o_0))
201                 throw INTERP_KERNEL::Exception(msg);
202               PyObject *o_1=PyTuple_GetItem(o,1);
203               if(!PyInt_Check(o_1))
204                 throw INTERP_KERNEL::Exception(msg);
205               arr[i].first=(int)PyInt_AS_LONG(o_0);
206               arr[i].second=(int)PyInt_AS_LONG(o_1);
207             }
208           else
209             throw INTERP_KERNEL::Exception(msg);
210         }
211     }
212   else if(PyTuple_Check(pyLi))
213     {
214       int size=PyTuple_Size(pyLi);
215       arr.resize(size);
216       for(int i=0;i<size;i++)
217         {
218           PyObject *o=PyTuple_GetItem(pyLi,i);
219           if(PyTuple_Check(o))
220             {
221               int sz2=PyTuple_Size(o);
222               if(sz2!=2)
223                 throw INTERP_KERNEL::Exception(msg);
224               PyObject *o_0=PyTuple_GetItem(o,0);
225               if(!PyInt_Check(o_0))
226                 throw INTERP_KERNEL::Exception(msg);
227               PyObject *o_1=PyTuple_GetItem(o,1);
228               if(!PyInt_Check(o_1))
229                 throw INTERP_KERNEL::Exception(msg);
230               arr[i].first=(int)PyInt_AS_LONG(o_0);
231               arr[i].second=(int)PyInt_AS_LONG(o_1);
232             }
233           else
234             throw INTERP_KERNEL::Exception(msg);
235         }
236     }
237   else
238     throw INTERP_KERNEL::Exception(msg);
239 }
240
241 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
242 {
243   if(PyList_Check(pyLi))
244     {
245       int size=PyList_Size(pyLi);
246       arr.resize(size);
247       for(int i=0;i<size;i++)
248         {
249           PyObject *o=PyList_GetItem(pyLi,i);
250           if(PyInt_Check(o))
251             {
252               int val=(int)PyInt_AS_LONG(o);
253               arr[i]=val;
254             }
255           else
256             throw INTERP_KERNEL::Exception("list must contain integers only");
257         }
258     }
259   else if(PyTuple_Check(pyLi))
260     {
261       int size=PyTuple_Size(pyLi);
262       arr.resize(size);
263       for(int i=0;i<size;i++)
264         {
265           PyObject *o=PyTuple_GetItem(pyLi,i);
266           if(PyInt_Check(o))
267             {
268               int val=(int)PyInt_AS_LONG(o);
269               arr[i]=val;
270             }
271           else
272             throw INTERP_KERNEL::Exception("tuple must contain integers only");
273         }
274     }
275   else
276     {
277 #ifndef WITH_NUMPY2
278       throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
279 #else
280       if(PyArray_Check(pyLi))
281         {
282           npy_intp mySize = PyArray_SIZE(pyLi);
283           int *ret=(int *)PyArray_BYTES(pyLi);
284           arr.resize(mySize);
285           std::copy(ret,ret+mySize,arr.begin());
286           return ;
287         }
288       else
289         throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple nor PyArray");
290 #endif
291     }
292 }
293
294 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
295 {
296   if(recurseLev<0)
297     throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
298   arr.clear();
299   if(PyList_Check(pyLi))
300     {
301       int size=PyList_Size(pyLi);
302       for(int i=0;i<size;i++)
303         {
304           PyObject *o=PyList_GetItem(pyLi,i);
305           if(PyInt_Check(o))
306             {
307               int val=(int)PyInt_AS_LONG(o);
308               arr.push_back(val);
309             }
310           else
311             {
312               std::vector<int> arr2;
313               convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
314               if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
315                   {
316                     std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " <<  recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
317                     throw INTERP_KERNEL::Exception(oss.str().c_str());
318                   }
319               arr.insert(arr.end(),arr2.begin(),arr2.end());
320             }
321         }
322     }
323   else if(PyTuple_Check(pyLi))
324     {
325       int size=PyTuple_Size(pyLi);
326       for(int i=0;i<size;i++)
327         {
328           PyObject *o=PyTuple_GetItem(pyLi,i);
329           if(PyInt_Check(o))
330             {
331               int val=(int)PyInt_AS_LONG(o);
332               arr.push_back(val);
333             }
334           else
335             {
336               std::vector<int> arr2;
337               convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
338               if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
339                   {
340                     std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " <<  recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
341                     throw INTERP_KERNEL::Exception(oss.str().c_str());
342                   }
343               arr.insert(arr.end(),arr2.begin(),arr2.end());
344             }
345         }
346     }
347   else
348     throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
349 }
350
351 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
352 {
353   if(nbOfTuples==-1)
354     {
355       if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
356       else { if(nbOfComp==size2) { nbOfTuples=size1; } else
357           {
358             std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
359             oss << " whereas nb of components expected is " << nbOfComp << " !";
360             throw INTERP_KERNEL::Exception(oss.str().c_str());
361           } }
362     }
363   else
364     {
365       if(nbOfComp!=-1)
366         {
367           if((nbOfTuples!=size1 || nbOfComp!=size2))
368             {
369               if(size2!=1 || size1!=nbOfComp*nbOfTuples)
370                 {
371                   std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
372                   oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
373                   throw INTERP_KERNEL::Exception(oss.str().c_str());
374                 }
375             }
376         }
377       else
378         {
379           if(nbOfTuples==size1)
380             nbOfComp=size2;
381           else
382             {
383               std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
384               oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
385               throw INTERP_KERNEL::Exception(oss.str().c_str());
386             }
387         }
388     }
389 }
390
391 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
392 {
393   static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
394   if(PyInt_Check(pyLi))
395     {
396       long val=PyInt_AS_LONG(pyLi);
397       if(nbOfElt==-1)
398         nbOfElt=1;
399       else
400         if(nbOfElt!=1)
401           throw INTERP_KERNEL::Exception(MSG);
402       ret.push_back(val);
403     }
404   else if(PyList_Check(pyLi))
405     {
406       int size=PyList_Size(pyLi);
407       int tmp=0;
408       for(int i=0;i<size;i++)
409         {
410           PyObject *o=PyList_GetItem(pyLi,i);
411           int tmp1=-1;
412           fillArrayWithPyListInt3(o,tmp1,ret);
413           tmp+=tmp1;
414         }
415       if(nbOfElt==-1)
416         nbOfElt=tmp;
417       else
418         {
419           if(nbOfElt!=tmp)
420             throw INTERP_KERNEL::Exception(MSG);
421         }
422     }
423   else if(PyTuple_Check(pyLi))
424     {
425       int size=PyTuple_Size(pyLi);
426       int tmp=0;
427       for(int i=0;i<size;i++)
428         {
429           PyObject *o=PyTuple_GetItem(pyLi,i);
430           int tmp1=-1;
431           fillArrayWithPyListInt3(o,tmp1,ret);
432           tmp+=tmp1;
433         }
434       if(nbOfElt==-1)
435         nbOfElt=tmp;
436       else
437         {
438           if(nbOfElt!=tmp)
439             throw INTERP_KERNEL::Exception(MSG);
440         }
441     }
442   else
443     throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
444 }
445
446 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
447 {
448   std::vector<int> ret;
449   int size1=-1,size2=-1;
450   if(PyList_Check(pyLi))
451     {
452       size1=PyList_Size(pyLi);
453       for(int i=0;i<size1;i++)
454         {
455           PyObject *o=PyList_GetItem(pyLi,i);
456           fillArrayWithPyListInt3(o,size2,ret);
457         }
458       if(size1==0)
459         size2=1;
460     }
461   else if(PyTuple_Check(pyLi))
462     {
463       size1=PyTuple_Size(pyLi);
464       for(int i=0;i<size1;i++)
465         {
466           PyObject *o=PyTuple_GetItem(pyLi,i);
467           fillArrayWithPyListInt3(o,size2,ret);
468         }
469       if(size1==0)
470         size2=1;
471     }
472   else
473     throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
474   //
475   checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
476   return ret;
477 }
478
479 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
480 {
481   PyObject *ret=PyList_New(size);
482   for(int i=0;i<size;i++)
483     PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
484   return ret;
485 }
486
487 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
488 {
489   int size=v.size();
490   PyObject *ret=PyList_New(size);
491   for(int i=0;i<size;i++)
492     PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
493   return ret;
494 }
495
496 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
497 {
498   PyObject *ret=PyList_New(nbOfTuples);
499   for(int i=0;i<nbOfTuples;i++)
500     {
501       PyObject *t=PyTuple_New(nbOfComp);
502       for(int j=0;j<nbOfComp;j++)
503         PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
504       PyList_SetItem(ret,i,t);
505     }
506   return ret;
507 }
508
509 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
510 {
511   if(PyList_Check(pyLi))
512     {
513       *size=PyList_Size(pyLi);
514       double *tmp=new double[*size];
515       for(int i=0;i<*size;i++)
516         {
517           PyObject *o=PyList_GetItem(pyLi,i);
518           if(PyFloat_Check(o))
519             {
520               double val=PyFloat_AS_DOUBLE(o);
521               tmp[i]=val;
522             }
523           else if(PyInt_Check(o))
524             {
525               long val0=PyInt_AS_LONG(o);
526               double val=val0;
527               tmp[i]=val;
528             }
529           else
530             {
531               delete [] tmp;
532               throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
533             }
534         }
535       return tmp;
536     }
537   else if(PyTuple_Check(pyLi))
538     {
539       *size=PyTuple_Size(pyLi);
540       double *tmp=new double[*size];
541       for(int i=0;i<*size;i++)
542         {
543           PyObject *o=PyTuple_GetItem(pyLi,i);
544           if(PyFloat_Check(o))
545             {
546               double val=PyFloat_AS_DOUBLE(o);
547               tmp[i]=val;
548             }
549           else if(PyInt_Check(o))
550             {
551               long val0=PyInt_AS_LONG(o);
552               double val=val0;
553               tmp[i]=val;
554             }
555           else
556             {
557               delete [] tmp;
558               throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
559             }
560         }
561       return tmp;
562     }
563   else
564     throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
565 }
566
567 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
568 {
569   static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
570   if(PyFloat_Check(pyLi))
571     {
572       if(nbOfElt==-1)
573         nbOfElt=1;
574       else
575         if(nbOfElt!=1)
576           throw INTERP_KERNEL::Exception(MSG);
577       double val=PyFloat_AS_DOUBLE(pyLi);
578       ret.push_back(val);
579     }
580   else if(PyInt_Check(pyLi))
581     {
582       long val0=PyInt_AS_LONG(pyLi);
583       double val=val0;
584       if(nbOfElt==-1)
585         nbOfElt=1;
586       else
587         if(nbOfElt!=1)
588           throw INTERP_KERNEL::Exception(MSG);
589       ret.push_back(val);
590     }
591   else if(PyList_Check(pyLi))
592     {
593       int size=PyList_Size(pyLi);
594       int tmp=0;
595       for(int i=0;i<size;i++)
596         {
597           PyObject *o=PyList_GetItem(pyLi,i);
598           int tmp1=-1;
599           fillArrayWithPyListDbl3(o,tmp1,ret);
600           tmp+=tmp1;
601         }
602       if(nbOfElt==-1)
603         nbOfElt=tmp;
604       else
605         {
606           if(nbOfElt!=tmp)
607             throw INTERP_KERNEL::Exception(MSG);
608         }
609     }
610   else if(PyTuple_Check(pyLi))
611     {
612       int size=PyTuple_Size(pyLi);
613       int tmp=0;
614       for(int i=0;i<size;i++)
615         {
616           PyObject *o=PyTuple_GetItem(pyLi,i);
617           int tmp1=-1;
618           fillArrayWithPyListDbl3(o,tmp1,ret);
619           tmp+=tmp1;
620         }
621       if(nbOfElt==-1)
622         nbOfElt=tmp;
623       else
624         {
625           if(nbOfElt!=tmp)
626             throw INTERP_KERNEL::Exception(MSG);
627         }
628     }
629   else
630     throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
631 }
632
633 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
634 {
635   std::vector<double> ret;
636   int size1=-1,size2=-1;
637   if(PyList_Check(pyLi))
638     {
639       size1=PyList_Size(pyLi);
640       for(int i=0;i<size1;i++)
641         {
642           PyObject *o=PyList_GetItem(pyLi,i);
643           fillArrayWithPyListDbl3(o,size2,ret);
644         }
645       if(size1==0)
646         size2=1;
647     }
648   else if(PyTuple_Check(pyLi))
649     {
650       size1=PyTuple_Size(pyLi);
651       for(int i=0;i<size1;i++)
652         {
653           PyObject *o=PyTuple_GetItem(pyLi,i);
654           fillArrayWithPyListDbl3(o,size2,ret);
655         }
656       if(size1==0)
657         size2=1;
658     }
659   else
660     throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
661   //
662   checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
663   return ret;
664 }
665
666 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
667 template<class T>
668 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
669 {
670   void *argp=0;
671   if(PyList_Check(pyLi))
672     {
673       int size=PyList_Size(pyLi);
674       ret.resize(size);
675       for(int i=0;i<size;i++)
676         {
677           PyObject *obj=PyList_GetItem(pyLi,i);
678           int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
679           if(!SWIG_IsOK(status))
680             throw INTERP_KERNEL::Exception("list must contain only MEDCouplingUMesh");
681           T arg=reinterpret_cast< T >(argp);
682           ret[i]=arg;
683         }
684     }
685   else if(PyTuple_Check(pyLi))
686     {
687       int size=PyTuple_Size(pyLi);
688       ret.resize(size);
689       for(int i=0;i<size;i++)
690         {
691           PyObject *obj=PyTuple_GetItem(pyLi,i);
692           int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
693           if(!SWIG_IsOK(status))
694             {
695               std::ostringstream oss; oss << "tuple must contain only " << typeStr;
696               throw INTERP_KERNEL::Exception(oss.str().c_str());
697             }
698           T arg=reinterpret_cast< T >(argp);
699           ret[i]=arg;
700         }
701     }
702   else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
703     {
704       ret.resize(1);
705       T arg=reinterpret_cast< T >(argp);
706       ret[0]=arg;
707     }
708   else
709     throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
710 }
711
712 /*!
713  * if python int -> cpp int sw=1
714  * if python list[int] -> cpp vector<int> sw=2
715  * if python tuple[int] -> cpp vector<int> sw=2
716  * if python DataArrayInt -> cpp DataArrayInt sw=3
717  * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
718  *
719  * switch between (int,vector<int>,DataArrayInt)
720  */
721 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
722 {
723   sw=-1;
724   if(PyInt_Check(value))
725     {
726       iTyypp=(int)PyInt_AS_LONG(value);
727       sw=1;
728       return;
729     }
730   if(PyTuple_Check(value))
731     {
732       int size=PyTuple_Size(value);
733       stdvecTyypp.resize(size);
734       for(int i=0;i<size;i++)
735         {
736           PyObject *o=PyTuple_GetItem(value,i);
737           if(PyInt_Check(o))
738             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
739           else
740             {
741               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
742               throw INTERP_KERNEL::Exception(oss.str().c_str());
743             }
744         }
745       sw=2;
746       return;
747     }
748   if(PyList_Check(value))
749     {
750       int size=PyList_Size(value);
751       stdvecTyypp.resize(size);
752       for(int i=0;i<size;i++)
753         {
754           PyObject *o=PyList_GetItem(value,i);
755           if(PyInt_Check(o))
756             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
757           else
758             {
759               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
760               throw INTERP_KERNEL::Exception(oss.str().c_str());
761             }
762         }
763       sw=2;
764       return;
765     }
766   void *argp;
767   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
768   if(SWIG_IsOK(status))
769     {
770       daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
771       sw=3;
772       return;
773     }
774   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
775   if(SWIG_IsOK(status))
776     {  
777       daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
778       sw=4;
779       return ;
780     }
781   throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
782 }
783
784 /*!
785  * if python double -> cpp double sw=1
786  * if python int -> cpp double sw=1
787  * if python list[double] -> cpp vector<double> sw=2
788  * if python list[int] -> cpp vector<double> sw=2
789  * if python tuple[double] -> cpp vector<double> sw=2
790  * if python tuple[int] -> cpp vector<double> sw=2
791  * if python DataArrayDouble -> cpp DataArrayDouble sw=3
792  *
793  * switch between (int,vector<int>,DataArrayInt)
794  */
795 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
796 {
797   sw=-1;
798   if(PyFloat_Check(value))
799     {
800       iTyypp=PyFloat_AS_DOUBLE(value);
801       sw=1;
802       return;
803     }
804   if(PyInt_Check(value))
805     {
806       iTyypp=(double)PyInt_AS_LONG(value);
807       sw=1;
808       return;
809     }
810   if(PyTuple_Check(value))
811     {
812       int size=PyTuple_Size(value);
813       stdvecTyypp.resize(size);
814       for(int i=0;i<size;i++)
815         {
816           PyObject *o=PyTuple_GetItem(value,i);
817           if(PyFloat_Check(o))
818             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
819           else if(PyInt_Check(o))
820             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
821           else
822             {
823               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
824               throw INTERP_KERNEL::Exception(oss.str().c_str());
825             }
826         }
827       sw=2;
828       return;
829     }
830   if(PyList_Check(value))
831     {
832       int size=PyList_Size(value);
833       stdvecTyypp.resize(size);
834       for(int i=0;i<size;i++)
835         {
836           PyObject *o=PyList_GetItem(value,i);
837           if(PyFloat_Check(o))
838             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
839           else if(PyInt_Check(o))
840             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
841           else
842             {
843               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
844               throw INTERP_KERNEL::Exception(oss.str().c_str());
845             }
846         }
847       sw=2;
848       return;
849     }
850   void *argp;
851   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
852   if(!SWIG_IsOK(status))
853     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
854   daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
855   sw=3;
856 }
857
858 /*!
859  * if python double -> cpp double sw=1
860  * if python int -> cpp double sw=1
861  * if python list[double] -> cpp vector<double> sw=2
862  * if python list[int] -> cpp vector<double> sw=2
863  * if python tuple[double] -> cpp vector<double> sw=2
864  * if python tuple[int] -> cpp vector<double> sw=2
865  * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
866  *
867  * switch between (int,vector<int>,DataArrayInt)
868  */
869 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
870 {
871   sw=-1;
872   if(PyFloat_Check(value))
873     {
874       iTyypp=PyFloat_AS_DOUBLE(value);
875       sw=1;
876       return;
877     }
878   if(PyInt_Check(value))
879     {
880       iTyypp=(double)PyInt_AS_LONG(value);
881       sw=1;
882       return;
883     }
884   if(PyTuple_Check(value))
885     {
886       int size=PyTuple_Size(value);
887       stdvecTyypp.resize(size);
888       for(int i=0;i<size;i++)
889         {
890           PyObject *o=PyTuple_GetItem(value,i);
891           if(PyFloat_Check(o))
892             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
893           else if(PyInt_Check(o))
894             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
895           else
896             {
897               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
898               throw INTERP_KERNEL::Exception(oss.str().c_str());
899             }
900         }
901       sw=2;
902       return;
903     }
904   if(PyList_Check(value))
905     {
906       int size=PyList_Size(value);
907       stdvecTyypp.resize(size);
908       for(int i=0;i<size;i++)
909         {
910           PyObject *o=PyList_GetItem(value,i);
911           if(PyFloat_Check(o))
912             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
913           else if(PyInt_Check(o))
914             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
915           else
916             {
917               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
918               throw INTERP_KERNEL::Exception(oss.str().c_str());
919             }
920         }
921       sw=2;
922       return;
923     }
924   void *argp;
925   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
926   if(!SWIG_IsOK(status))
927     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
928   daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
929   sw=3;
930 }
931
932 /*!
933  * if python int -> cpp int sw=1
934  * if python list[int] -> cpp vector<int> sw=2
935  * if python tuple[int] -> cpp vector<int> sw=2
936  * if python slicp -> cpp pair sw=3
937  * if python DataArrayInt -> cpp DataArrayInt sw=4
938  *
939  * switch between (int,vector<int>,DataArrayInt)
940  */
941 static void convertObjToPossibleCpp2(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, ParaMEDMEM::DataArrayInt *& daIntTyypp) throw(INTERP_KERNEL::Exception)
942 {
943   const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
944   sw=-1;
945   if(PyInt_Check(value))
946     {
947       iTyypp=(int)PyInt_AS_LONG(value);
948       sw=1;
949       return;
950     }
951   if(PyTuple_Check(value))
952     {
953       int size=PyTuple_Size(value);
954       stdvecTyypp.resize(size);
955       for(int i=0;i<size;i++)
956         {
957           PyObject *o=PyTuple_GetItem(value,i);
958           if(PyInt_Check(o))
959             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
960           else
961             {
962               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
963               throw INTERP_KERNEL::Exception(oss.str().c_str());
964             }
965         }
966       sw=2;
967       return;
968     }
969   if(PyList_Check(value))
970     {
971       int size=PyList_Size(value);
972       stdvecTyypp.resize(size);
973       for(int i=0;i<size;i++)
974         {
975           PyObject *o=PyList_GetItem(value,i);
976           if(PyInt_Check(o))
977             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
978           else
979             {
980               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
981               throw INTERP_KERNEL::Exception(oss.str().c_str());
982             }
983         }
984       sw=2;
985       return;
986     }
987   if(PySlice_Check(value))
988     {
989       Py_ssize_t strt=2,stp=2,step=2;
990       PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
991       if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
992         if(nbelem!=0 || strt!=0 || stp!=0)
993           {
994             std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
995             throw INTERP_KERNEL::Exception(oss.str().c_str());
996           }
997       p.first=strt;
998       p.second.first=stp;
999       p.second.second=step;
1000       sw=3;
1001       return ;
1002     }
1003   void *argp;
1004   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1005   if(SWIG_IsOK(status))
1006     {
1007       daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1008       if(!daIntTyypp)
1009         {
1010           std::ostringstream oss; oss << msg << " Instance in null !";
1011           throw INTERP_KERNEL::Exception(oss.str().c_str());
1012         }
1013       sw=4;
1014       return ;
1015     }
1016   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);;
1017   if(SWIG_IsOK(status))
1018     {
1019       ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1020       if(!tmp)
1021         {
1022           std::ostringstream oss; oss << msg << " Instance in null !";
1023           throw INTERP_KERNEL::Exception(oss.str().c_str());
1024         }
1025       stdvecTyypp.resize(tmp->getNumberOfCompo());
1026       std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1027       sw=2;
1028       return ;
1029     }
1030   throw INTERP_KERNEL::Exception(msg);
1031 }
1032
1033 static void convertObjToPossibleCpp22(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, ParaMEDMEM::DataArrayIntTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1034 {
1035   sw=-1;
1036   if(PyInt_Check(value))
1037     {
1038       iTyypp=(int)PyInt_AS_LONG(value);
1039       sw=1;
1040       return;
1041     }
1042   if(PyTuple_Check(value))
1043     {
1044       int size=PyTuple_Size(value);
1045       stdvecTyypp.resize(size);
1046       for(int i=0;i<size;i++)
1047         {
1048           PyObject *o=PyTuple_GetItem(value,i);
1049           if(PyInt_Check(o))
1050             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1051           else
1052             {
1053               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1054               throw INTERP_KERNEL::Exception(oss.str().c_str());
1055             }
1056         }
1057       sw=2;
1058       return;
1059     }
1060   if(PyList_Check(value))
1061     {
1062       int size=PyList_Size(value);
1063       stdvecTyypp.resize(size);
1064       for(int i=0;i<size;i++)
1065         {
1066           PyObject *o=PyList_GetItem(value,i);
1067           if(PyInt_Check(o))
1068             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1069           else
1070             {
1071               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1072               throw INTERP_KERNEL::Exception(oss.str().c_str());
1073             }
1074         }
1075       sw=2;
1076       return;
1077     }
1078   if(PySlice_Check(value))
1079     {
1080       Py_ssize_t strt=2,stp=2,step=2;
1081       PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1082       if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1083         if(nbelem!=0 || strt!=0 || stp!=0)
1084           {
1085             std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1086             throw INTERP_KERNEL::Exception(oss.str().c_str());
1087           }
1088       p.first=strt;
1089       p.second.first=stp;
1090       p.second.second=step;
1091       sw=3;
1092       return ;
1093     }
1094   void *argp;
1095   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1096   if(!SWIG_IsOK(status))
1097     throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1098   daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1099   sw=4;
1100 }
1101
1102 /*!
1103  * if value int -> cpp it sw=1
1104  * if value list[int] -> vt sw=2
1105  * if value tuple[int] -> vt sw=2
1106  * if value slice -> pt sw=3
1107  * if value DataArrayInt -> dt sw=4
1108  * if value tuple [int,int] -> cpp it,ip sw=5
1109  * if value tuple [list[int],int] -> cpp vt,ip sw=6
1110  * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1111  * if value tuple [slice,int] -> cpp pt,ip sw=7
1112  * if value tuple [DaI,int] -> cpp dt,ip sw=8
1113  * if value tuple [int,list[int]] -> cpp it,vc sw=9
1114  * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1115  * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1116  * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1117  * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1118  * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1119  * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1120  * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1121  * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1122  * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1123  * if value tuple [int,slice] -> cpp it,pc sw=13
1124  * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1125  * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1126  * if value tuple [slice,slice] -> cpp pt,pc sw=15
1127  * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1128  *
1129  * switch between (int,vector<int>,DataArrayInt)
1130  */
1131 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1132                                      std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1133                                      ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1134 {
1135   if(!PyTuple_Check(value))
1136     {
1137       convertObjToPossibleCpp2(value,nbTuple,sw,it,vt,pt,dt);
1138       return ;
1139     }
1140   else
1141     {
1142       int sz=PyTuple_Size(value);
1143       if(sz!=2)
1144         throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1145       PyObject *ob0=PyTuple_GetItem(value,0);
1146       int sw1,sw2;
1147       convertObjToPossibleCpp2(ob0,nbTuple,sw1,it,vt,pt,dt);
1148       PyObject *ob1=PyTuple_GetItem(value,1);
1149       convertObjToPossibleCpp2(ob1,nbCompo,sw2,ic,vc,pc,dc);
1150       sw=4*sw2+sw1;
1151     }
1152 }
1153
1154 /*!
1155  * if value int -> cpp val sw=1
1156  * if value double -> cpp val sw=1
1157  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1158  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1159  * if value list[int,double] -> cpp std::vector<double> sw=4
1160  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1161  */
1162 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1163 {
1164   sw=-1;
1165   if(PyFloat_Check(value))
1166     {
1167       val=PyFloat_AS_DOUBLE(value);
1168       sw=1;
1169       return;
1170     }
1171   if(PyInt_Check(value))
1172     {
1173       val=(double)PyInt_AS_LONG(value);
1174       sw=1;
1175       return;
1176     }
1177   if(PyTuple_Check(value))
1178     {
1179       int size=PyTuple_Size(value);
1180       f.resize(size);
1181       for(int i=0;i<size;i++)
1182         {
1183           PyObject *o=PyTuple_GetItem(value,i);
1184           if(PyFloat_Check(o))
1185             f[i]=PyFloat_AS_DOUBLE(o);
1186           else if(PyInt_Check(o))
1187             f[i]=(double)PyInt_AS_LONG(o);
1188           else
1189             {
1190               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1191               throw INTERP_KERNEL::Exception(oss.str().c_str());
1192             }
1193         }
1194       sw=4;
1195       return;
1196     }
1197   if(PyList_Check(value))
1198     {
1199       int size=PyList_Size(value);
1200       f.resize(size);
1201       for(int i=0;i<size;i++)
1202         {
1203           PyObject *o=PyList_GetItem(value,i);
1204           if(PyFloat_Check(o))
1205             f[i]=PyFloat_AS_DOUBLE(o);
1206           else if(PyInt_Check(o))
1207             f[i]=(double)PyInt_AS_LONG(o);
1208           else
1209             {
1210               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1211               throw INTERP_KERNEL::Exception(oss.str().c_str());
1212             }
1213         }
1214       sw=4;
1215       return;
1216     }
1217   void *argp;
1218   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1219   if(SWIG_IsOK(status))
1220     {  
1221       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1222       sw=2;
1223       return ;
1224     }
1225   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1226   if(SWIG_IsOK(status))
1227     {  
1228       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1229       sw=3;
1230       return ;
1231     }
1232   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1233 }
1234
1235 /*!
1236  * if value int -> cpp val sw=1
1237  * if value double -> cpp val sw=1
1238  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1239  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1240  * if value list[int,double] -> cpp std::vector<double> sw=4
1241  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1242  */
1243 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1244                                                    const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1245 {
1246   sw=-1;
1247   if(PyFloat_Check(value))
1248     {
1249       val=PyFloat_AS_DOUBLE(value);
1250       sw=1;
1251       if(nbTuplesExpected*nbCompExpected!=1)
1252         {
1253           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !"; 
1254           throw INTERP_KERNEL::Exception(oss.str().c_str());
1255         }
1256       return &val;
1257     }
1258   if(PyInt_Check(value))
1259     {
1260       val=(double)PyInt_AS_LONG(value);
1261       sw=1;
1262       if(nbTuplesExpected*nbCompExpected!=1)
1263         {
1264           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !"; 
1265           throw INTERP_KERNEL::Exception(oss.str().c_str());
1266         }
1267       return &val;
1268     }
1269   if(PyTuple_Check(value) || PyList_Check(value))
1270     {
1271       try
1272         {
1273           int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
1274           std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
1275           sw=4;
1276           f=ret;
1277           return &f[0];
1278         }
1279       catch(INTERP_KERNEL::Exception& e) { throw e; }
1280     }
1281   void *argp;
1282   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1283   if(SWIG_IsOK(status))
1284     {  
1285       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1286       sw=2;
1287       if(d)
1288         {
1289           if(d->getNumberOfTuples()==nbTuplesExpected)
1290             {
1291               if(d->getNumberOfComponents()==nbCompExpected)
1292                 {
1293                   return d->getConstPointer();
1294                 }
1295               else
1296                 {
1297                   std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1298                   throw INTERP_KERNEL::Exception(oss.str().c_str());
1299                 }
1300             }
1301           else
1302             {
1303               std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
1304               throw INTERP_KERNEL::Exception(oss.str().c_str());
1305             }
1306         }
1307       else
1308         {
1309           if(throwIfNullPt)
1310             {
1311               std::ostringstream oss; oss << msg << " null pointer not accepted!";
1312               throw INTERP_KERNEL::Exception(oss.str().c_str());
1313             }
1314           else
1315             return 0;
1316         }
1317     }
1318   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1319   if(SWIG_IsOK(status))
1320     {  
1321       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1322       sw=3;
1323       if(e->getNumberOfCompo()==nbCompExpected)
1324         {
1325           if(nbTuplesExpected==1)
1326             return e->getConstPointer();
1327           else
1328             {
1329               std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
1330               throw INTERP_KERNEL::Exception(oss.str().c_str());
1331             }
1332         }
1333       else
1334         {
1335           std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1336           throw INTERP_KERNEL::Exception(oss.str().c_str());
1337         }
1338     }
1339   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1340 }
1341
1342 /*!
1343  * if value int -> cpp val sw=1
1344  * if value double -> cpp val sw=1
1345  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1346  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1347  * if value list[int,double] -> cpp std::vector<double> sw=4
1348  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1349  */
1350 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1351                                                     const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1352 {
1353   sw=-1;
1354   if(PyFloat_Check(value))
1355     {
1356       val=PyFloat_AS_DOUBLE(value);
1357       sw=1;
1358       if(nbCompExpected!=1)
1359         {
1360           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !"; 
1361           throw INTERP_KERNEL::Exception(oss.str().c_str());
1362         }
1363       nbTuples=1;
1364       return &val;
1365     }
1366   if(PyInt_Check(value))
1367     {
1368       val=(double)PyInt_AS_LONG(value);
1369       sw=1;
1370       if(nbCompExpected!=1)
1371         {
1372           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !"; 
1373           throw INTERP_KERNEL::Exception(oss.str().c_str());
1374         }
1375       nbTuples=1;
1376       return &val;
1377     }
1378   if(PyTuple_Check(value))
1379     {
1380       int size=PyTuple_Size(value);
1381       f.resize(size);
1382       for(int i=0;i<size;i++)
1383         {
1384           PyObject *o=PyTuple_GetItem(value,i);
1385           if(PyFloat_Check(o))
1386             f[i]=PyFloat_AS_DOUBLE(o);
1387           else if(PyInt_Check(o))
1388             f[i]=(double)PyInt_AS_LONG(o);
1389           else
1390             {
1391               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1392               throw INTERP_KERNEL::Exception(oss.str().c_str());
1393             }
1394         }
1395       sw=4;
1396       if(size%nbCompExpected!=0)
1397         {
1398           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !"; 
1399           throw INTERP_KERNEL::Exception(oss.str().c_str());
1400         }
1401       nbTuples=size/nbCompExpected;
1402       return &f[0];
1403     }
1404   if(PyList_Check(value))
1405     {
1406       int size=PyList_Size(value);
1407       f.resize(size);
1408       for(int i=0;i<size;i++)
1409         {
1410           PyObject *o=PyList_GetItem(value,i);
1411           if(PyFloat_Check(o))
1412             f[i]=PyFloat_AS_DOUBLE(o);
1413           else if(PyInt_Check(o))
1414             f[i]=(double)PyInt_AS_LONG(o);
1415           else
1416             {
1417               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1418               throw INTERP_KERNEL::Exception(oss.str().c_str());
1419             }
1420         }
1421       sw=4;
1422       if(size%nbCompExpected!=0)
1423         {
1424           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !"; 
1425           throw INTERP_KERNEL::Exception(oss.str().c_str());
1426         }
1427       nbTuples=size/nbCompExpected;
1428       return &f[0];
1429     }
1430   void *argp;
1431   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1432   if(SWIG_IsOK(status))
1433     {  
1434       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1435       sw=2;
1436       if(d)
1437         {
1438           if(d->getNumberOfComponents()==nbCompExpected)
1439             {
1440               nbTuples=d->getNumberOfTuples();
1441               return d->getConstPointer();
1442             }
1443           else
1444             {
1445               std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1446               throw INTERP_KERNEL::Exception(oss.str().c_str());
1447             }
1448         }
1449       else
1450         {
1451           if(throwIfNullPt)
1452             {
1453               std::ostringstream oss; oss << msg << " null pointer not accepted!";
1454               throw INTERP_KERNEL::Exception(oss.str().c_str());
1455             }
1456           else
1457             return 0;
1458         }
1459     }
1460   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1461   if(SWIG_IsOK(status))
1462     {  
1463       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1464       sw=3;
1465       if(e->getNumberOfCompo()==nbCompExpected)
1466         {
1467           nbTuples=1;
1468           return e->getConstPointer();
1469         }
1470       else
1471         {
1472           std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1473           throw INTERP_KERNEL::Exception(oss.str().c_str());
1474         }
1475     }
1476   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1477 }
1478
1479 /*!
1480  * if python int -> cpp int sw=1
1481  * if python list[int] -> cpp vector<int> sw=2
1482  * if python tuple[int] -> cpp vector<int> sw=2
1483  * if python DataArrayInt -> cpp DataArrayInt sw=3
1484  * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1485  *
1486  * switch between (int,vector<int>,DataArrayInt)
1487  */
1488 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
1489 {
1490   sw=-1;
1491   if(PyInt_Check(value))
1492     {
1493       iTyypp=(int)PyInt_AS_LONG(value);
1494       sw=1; sz=1;
1495       return &iTyypp;
1496     }
1497   if(PyTuple_Check(value))
1498     {
1499       int size=PyTuple_Size(value);
1500       stdvecTyypp.resize(size);
1501       for(int i=0;i<size;i++)
1502         {
1503           PyObject *o=PyTuple_GetItem(value,i);
1504           if(PyInt_Check(o))
1505             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1506           else
1507             {
1508               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1509               throw INTERP_KERNEL::Exception(oss.str().c_str());
1510             }
1511         }
1512       sw=2; sz=size;
1513       return &stdvecTyypp[0];
1514     }
1515   if(PyList_Check(value))
1516     {
1517       int size=PyList_Size(value);
1518       stdvecTyypp.resize(size);
1519       for(int i=0;i<size;i++)
1520         {
1521           PyObject *o=PyList_GetItem(value,i);
1522           if(PyInt_Check(o))
1523             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1524           else
1525             {
1526               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1527               throw INTERP_KERNEL::Exception(oss.str().c_str());
1528             }
1529         }
1530       sw=2; sz=size;
1531       return &stdvecTyypp[0];
1532     }
1533   void *argp;
1534   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1535   if(SWIG_IsOK(status))
1536     {
1537       ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1538       if(daIntTyypp)
1539         {
1540           sw=3; sz=daIntTyypp->getNbOfElems();
1541           return daIntTyypp->begin();
1542         }
1543       else
1544         {
1545           sz=0;
1546           return 0;
1547         }
1548     }
1549   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1550   if(SWIG_IsOK(status))
1551     {  
1552       ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1553       sw=4; sz=daIntTuple->getNumberOfCompo();
1554       return daIntTuple->getConstPointer();
1555     }
1556   throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1557 }