]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM_SWIG/libMEDMEM_Swig.i
Salome HOME
Join modifications from branch CEAFor_V3_2_0
[modules/med.git] / src / MEDMEM_SWIG / libMEDMEM_Swig.i
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20 %module libMEDMEM_Swig
21
22 %{
23 #include <sstream>
24 #include <string>
25 #include "MEDMEM_CellModel.hxx"
26 #include "MEDMEM_GenDriver.hxx"
27 #include "MEDMEM_MedMeshDriver.hxx"
28 #include "MEDMEM_GibiMeshDriver.hxx"
29 #include "MEDMEM_PorflowMeshDriver.hxx"
30 #include "MEDMEM_Connectivity.hxx"
31 #include "MEDMEM_Group.hxx"
32 #include "MEDMEM_SkyLineArray.hxx"
33 #include "MEDMEM_Coordinate.hxx"
34 #include "MEDMEM_Array.hxx"
35 #include "MEDMEM_Mesh.hxx"
36 #include "MEDMEM_define.hxx"
37 #include "MEDMEM_Exception.hxx"
38 #include "MEDMEM_STRING.hxx"
39 #include "MEDMEM_DriversDef.hxx"
40 #include "MEDMEM_MedFieldDriver.hxx"
41 #include "MEDMEM_Support.hxx"
42 #include "MEDMEM_Family.hxx"
43 #include "MEDMEM_Med.hxx"
44 #include "MEDMEM_Unit.hxx"
45 #include "MEDMEM_Field.hxx"
46 #include "MEDMEM_FieldConvert.hxx"
47 #include "MEDMEM_MedMedDriver.hxx"
48 #include "MEDMEM_Grid.hxx"
49 #include "MEDMEM_Meshing.hxx"
50 #include "MEDMEM_DriverFactory.hxx"
51 #include "MEDMEM_GaussLocalization.hxx"
52 #include "MEDMEM_ArrayInterface.hxx"
53 #include "MEDMEM_SWIG_Templates.hxx"
54
55   using namespace MEDMEM;
56   using namespace MED_EN;
57
58   /*  typedef FIELD <double, FullInterlace> FIELDDOUBLEFULLINTERLACE;*/
59   /*  typedef FIELD <int, FullInterlace> FIELDINTFULLINTERLACE;*/
60   typedef FIELD <double, FullInterlace> FIELDDOUBLE;
61   typedef FIELD <int, FullInterlace> FIELDINT;
62   typedef FIELD <double, NoInterlace> FIELDDOUBLENOINTERLACE;
63   typedef FIELD <int, NoInterlace> FIELDINTNOINTERLACE;
64
65 %}
66
67 /*
68   SWIG needs these typedefs to wrap FIELDDOUBLE*, for ex., to something like
69   <C++ FIELD<double> instance at _d0709808_p_FIELDDOUBLE>, not to
70   <SWIG Object at _d0709808_p_FIELDDOUBLE> which has no attributes
71 */
72
73 /*typedef FIELD <double, FullInterlace> FIELDDOUBLEFULLINTERLACE;*/
74 /*typedef FIELD <int, FullInterlace> FIELDINTFULLINTERLACE;*/
75 typedef FIELD <double, FullInterlace> FIELDDOUBLE;
76 typedef FIELD <int, FullInterlace> FIELDINT;
77 typedef FIELD <double, NoInterlace> FIELDDOUBLENOINTERLACE;
78 typedef FIELD <int, NoInterlace> FIELDINTNOINTERLACE;
79
80 %include "typemaps.i"
81 %include "my_typemap.i"
82
83 %typecheck(SWIG_TYPECHECK_POINTER) double *, const double *,
84  const double * const, int *, const int *, const int * const, string *,
85  const string *, const string * const, medGeometryElement *,
86  const medGeometryElement *, const medGeometryElement * const
87 {
88   $1 = ($input != 0);
89 }
90
91 /*
92   mapping between stl string and python string 
93 */
94
95 %include "std_string.i"
96
97
98 /*
99   managing C++ exception in the Python API
100 */
101
102 %exception
103 {
104   try
105     {
106       $action
107     }
108   catch(MEDEXCEPTION& exception)
109     {
110       PyErr_SetString(PyExc_RuntimeError,exception.what());
111       return NULL;
112     }
113 }
114
115 /*
116   managing the use of operator= of any class by renaming it assign()
117   because assignment can't be overloaded in python.
118
119   In python, you would then use
120
121   a.assign(b)              # a = b
122 */
123
124 %rename(assign) *::operator=;
125
126 /*
127   typemap for vector<FAMILY *> C++ object
128 */
129
130 %typemap(python,in) vector< FAMILY * >, const vector< FAMILY * >
131 {
132   /* typemap in for vector<FAMILY *> */
133   /* Check if is a list */
134
135   if (PyList_Check($input)) {
136     int size = PyList_Size($input);
137     $1 = vector<FAMILY *>(size);
138
139     for (int i=0; i < size; i++)
140       {
141         PyObject * tmp = PyList_GetItem($input,i);
142         FAMILY * f;
143
144         int err = SWIG_ConvertPtr(tmp, (void **) &f, $descriptor(FAMILY *),
145                                   SWIG_POINTER_EXCEPTION);
146
147         if (err == -1)
148           {
149             char * message = "Error in typemap(python,in) for vector<FAMILY *> each component should be a FAMILY pointer";
150             PyErr_SetString(PyExc_RuntimeError, message);
151             return NULL;
152           }
153         // mpv: for compatibility with SWIG 1.3.24 SwigValueWrapper
154         // $1[i] = f;
155         $1.at(i) = f;
156       }
157   }
158   else
159     {
160       PyErr_SetString(PyExc_TypeError,"not a list");
161       return NULL;
162     }
163 }
164
165 %typemap(python,out) vector< FAMILY * >
166 {
167   /* typemap out for vector<FAMILY *> */
168   int size = $1.size();
169   $result = PyList_New(size);
170
171   for (int i=0;i<size;i++)
172     {
173       // mpv: for compatibility with SWIG 1.3.24 SwigValueWrapper
174       //PyObject * tmp = SWIG_NewPointerObj($1[i],$descriptor(FAMILY *),0);
175       PyObject * tmp = SWIG_NewPointerObj($1.at(i),$descriptor(FAMILY *),0);
176
177       PyList_SetItem($result,i,tmp);
178     }
179 }
180
181 /*
182   typemap for vector<SUPPORT *> C++ object
183 */
184
185 %typemap(python,in) vector< SUPPORT * >, const vector< SUPPORT * >
186 {
187   /* typemap in for vector<SUPPORT *> */
188   /* Check if is a list */
189
190   if (PyList_Check($input)) {
191     int size = PyList_Size($input);
192     $1 = vector<SUPPORT *>(size);
193
194     for (int i=0; i < size; i++)
195       {
196         PyObject * tmp = PyList_GetItem($input,i);
197         SUPPORT * s;
198
199         int err = SWIG_ConvertPtr(tmp, (void **) &s, $descriptor(SUPPORT *),
200                                   SWIG_POINTER_EXCEPTION);
201
202         if (err == -1)
203           {
204             char * message = "Error in typemap(python,in) for vector<SUPPORT *> each component should be a SUPPORT pointer";
205             PyErr_SetString(PyExc_RuntimeError, message);
206             return NULL;
207           }
208         // mpv: for compatibility with SWIG 1.3.24 SwigValueWrapper
209         //$1[i] = s;
210         $1.at(i) = s;
211       }
212   }
213   else
214     {
215       PyErr_SetString(PyExc_TypeError,"not a list");
216       return NULL;
217     }
218 }
219
220 %typemap(python,out) vector< SUPPORT * >
221 {
222   /* typemap out for vector<SUPPORT *> */
223   int size = $1.size();
224   $result = PyList_New(size);
225
226   for (int i=0;i<size;i++)
227     {
228       // mpv: for compatibility with SWIG 1.3.24 SwigValueWrapper
229       //PyObject * tmp = SWIG_NewPointerObj($1[i],$descriptor(SUPPORT *),0);
230       PyObject * tmp = SWIG_NewPointerObj($1.at(i),$descriptor(SUPPORT *),0);
231
232       PyList_SetItem($result,i,tmp);
233     }
234 }
235
236
237 %typemap(python,in) vector< FIELD< double > * >, const vector< FIELD< double > * >
238 {
239     /* typemap in for vector<FIELD<double> *> */
240   /* Check if is a list */
241
242   if (PyList_Check($input)) {
243     int size = PyList_Size($input);
244     $1.resize(size);
245
246     for (int i=0; i < size; i++)
247       {
248         PyObject * tmp = PyList_GetItem($input,i);
249         FIELD<double> * s;
250
251         int err = SWIG_ConvertPtr(tmp, (void **) &s, $descriptor(FIELD<double> *),
252                                   SWIG_POINTER_EXCEPTION);
253
254         if (err == -1)
255           {
256             char * message = "Error in typemap(python,in) for vector<FIELD<double> *> each component should be a SUPPORT pointer";
257             PyErr_SetString(PyExc_RuntimeError, message);
258             return NULL;
259           }
260
261         // mpv: for compatibility with SWIG 1.3.24 SwigValueWrapper
262         //$1[i] = s;
263         $1.at(i) = s;
264       }
265   }
266   else
267     {
268       PyErr_SetString(PyExc_TypeError,"not a list");
269       return NULL;
270     }
271 }
272
273 %typemap(python,out) vector< FIELD< double > * >
274 {
275   /* typemap out for vector<FIELD<double> *> */
276   int size = $1.size();
277   $result = PyList_New(size);
278
279   for (int i=0;i<size;i++)
280     {
281       // mpv: for compatibility with SWIG 1.3.24 SwigValueWrapper
282       //PyObject * tmp = SWIG_NewPointerObj($1[i],$descriptor(FIELD<double> *),0);
283       PyObject * tmp = SWIG_NewPointerObj($1.at(i),$descriptor(FIELD<double> *),0);
284
285       PyList_SetItem($result,i,tmp);
286     }
287 }
288
289 %typemap(python,in) vector< FIELD< int > * >, const vector< FIELD< int > * >
290 {
291     /* typemap in for vector<FIELD<int> *> */
292   /* Check if is a list */
293
294   if (PyList_Check($input)) {
295     int size = PyList_Size($input);
296     $1.resize(size);
297
298     for (int i=0; i < size; i++)
299       {
300         PyObject * tmp = PyList_GetItem($input,i);
301         FIELD<int> * s;
302
303         int err = SWIG_ConvertPtr(tmp, (void **) &s, $descriptor(FIELD<int> *),
304                                   SWIG_POINTER_EXCEPTION);
305
306         if (err == -1)
307           {
308             char * message = "Error in typemap(python,in) for vector<FIELD<int> *> each component should be a SUPPORT pointer";
309             PyErr_SetString(PyExc_RuntimeError, message);
310             return NULL;
311           }
312
313         // mpv: for compatibility with SWIG 1.3.24 SwigValueWrapper
314         //$1[i] = s;
315         $1.at(i) = s;
316       }
317   }
318   else
319     {
320       PyErr_SetString(PyExc_TypeError,"not a list");
321       return NULL;
322     }
323 }
324
325 %typemap(python,out) vector< FIELD< int > * >
326 {
327   /* typemap out for vector<FIELD<int> *> */
328   int size = $1.size();
329   $result = PyList_New(size);
330
331   for (int i=0;i<size;i++)
332     {
333       // mpv: for compatibility with SWIG 1.3.24 SwigValueWrapper
334       //PyObject * tmp = SWIG_NewPointerObj($1[i],$descriptor(FIELD<int> *),0);
335       PyObject * tmp = SWIG_NewPointerObj($1.at(i),$descriptor(FIELD<int> *),0);
336
337       PyList_SetItem($result,i,tmp);
338     }
339 }
340
341
342 /*
343   typemap in for PyObject * fonction Python wrapping of a
344   double or int fonction pointeur
345 */
346
347 %typemap(python,in) PyObject * double_function, PyObject * integer_function
348 {
349   /* typemap in for double or integer callable fonction pointeur */
350   /* Check if it is a callable fonction pointer */
351
352   if(PyCallable_Check($input) == 0)
353     {
354       char * message = "Error in typemap(python,in) for double or integer callable fonction pointeur : the argument should be a callable object";
355       PyErr_SetString(PyExc_RuntimeError, message);
356       return NULL;
357     }
358
359   $1 = $input;
360 }
361
362 /*
363   MACRO converting C++ MEDMEM::FIELD_ pointer into a PyObject pointer rightly
364   casted following its value type (int or double) and its interlacing mode
365   (FullInterlace or NoInterlace) by calling the function SWIG_NewPointer with
366   the appropriate $descriptor(...)
367 */
368
369 %define TYPEMAP_OUTPUT_FIELDT(myField)
370 {
371   FIELD_ *arg1=myField;
372   PyObject *myResult=NULL;
373   if(arg1)
374     {
375       FIELD<double> *try1=dynamic_cast<FIELD<double> *>(arg1);
376       if(try1)
377         myResult = SWIG_NewPointerObj((void *) try1, $descriptor(FIELD<double, FullInterlace> *), 0);
378       else
379         {
380           FIELD<int> *try2=dynamic_cast<FIELD<int> *>(arg1);
381           if(try2)
382             myResult = SWIG_NewPointerObj((void *) try2, $descriptor(FIELD<int, FullInterlace> *), 0);
383           else
384             {
385               FIELD<double, NoInterlace> *try3=dynamic_cast<FIELD<double, NoInterlace> *>(arg1);
386               if(try3)
387                 myResult = SWIG_NewPointerObj((void *) try3, $descriptor(FIELD<double, NoInterlace> *), 0);
388               else
389                 {
390                    FIELD<int, NoInterlace> *try4=dynamic_cast<FIELD<int, NoInterlace> *>(arg1);
391                    if(try4)
392                      myResult = SWIG_NewPointerObj((void *) try4, $descriptor(FIELD<int, NoInterlace> *), 0);
393                    else
394                      {
395                        myResult = SWIG_NewPointerObj((void *) arg1, $descriptor(FIELD_ *), 0);
396                      }
397                 }
398             }
399         }
400      }
401   return myResult;
402 }
403 %enddef
404
405 /*
406   MACRO to transforme a C++ deque<string> object into a proper Python List
407 */
408
409 %define TYPEMAP_OUTPUT_DEQUE_STRING(myDeque)
410 {
411    PyObject *py_list = PyList_New(myDeque.size());
412    deque<string>::iterator iter4;
413    int i4=0;
414    for(iter4=myDeque.begin();iter4!=myDeque.end();iter4++,i4++)
415      {
416          PyList_SetItem(py_list, i4, PyString_FromString((*iter4).c_str()));
417      }
418    return py_list;
419 }
420 %enddef
421
422 /*
423   MACRO converting C array <arrayvar> of length <size> into a PyList
424   by calling type_converter() for each array element.
425   It reports error in <method> in failure case
426 */
427
428 %define TYPEMAP_OUTPUT_ARRAY(arrayvar, size, type_converter, method)
429 {
430   PyObject *py_list = PyList_New(size);
431   for (int i=0; i < size; i++)
432     {
433       int err = PyList_SetItem(py_list, i, type_converter( arrayvar[ i ]));
434       if(err)
435         {
436           char * message = "Error in " #method;
437           PyErr_SetString(PyExc_RuntimeError, message);
438           return NULL;
439         }
440     }
441
442   PyObject * result = Py_BuildValue("O", py_list);
443   Py_DECREF(py_list);
444   return result;
445 }
446 %enddef
447
448 /*
449   Helper function to be used as type_converter in TYPEMAP_OUTPUT_ARRAY
450 */
451
452 %{
453   PyObject *PyString_FromStdString(const std::string &str)
454     {
455       return PyString_FromString(str.c_str());
456     }
457 %}
458
459
460 /*
461   enum of the C++ MED used in the Python API
462 */
463
464 typedef enum {MED_CARTESIAN, MED_POLAR, MED_BODY_FITTED} med_grid_type;
465
466 typedef enum {MED_FULL_INTERLACE, MED_NO_INTERLACE} medModeSwitch;
467
468 typedef enum {MED_LECT, MED_ECRI, MED_REMP} med_mode_acces;
469
470 typedef enum {ASCENDING=7,DESCENDING=77} med_sort_direc;
471
472 typedef enum {MED_CELL, MED_FACE, MED_EDGE, MED_NODE,
473               MED_ALL_ENTITIES} medEntityMesh;
474
475 typedef enum {MED_NONE=0, MED_POINT1=1, MED_SEG2=102, MED_SEG3=103,
476               MED_TRIA3=203, MED_QUAD4=204, MED_TRIA6=206, MED_QUAD8=208,
477               MED_TETRA4=304, MED_PYRA5=305, MED_PENTA6=306,
478               MED_HEXA8=308, MED_TETRA10=310, MED_PYRA13=313,
479               MED_PENTA15=315, MED_HEXA20=320, MED_POLYGON = 400, MED_POLYHEDRA = 500,
480               MED_ALL_ELEMENTS=999} medGeometryElement;
481
482 typedef enum {MED_NODAL, MED_DESCENDING} medConnectivity ;
483
484 typedef enum {MED_DRIVER=0, GIBI_DRIVER=1, PORFLOW_DRIVER = 2, VTK_DRIVER=254,
485               NO_DRIVER=255, ASCII_DRIVER = 3} driverTypes;
486
487 typedef enum {MED_REEL64=6, MED_INT32=24, MED_INT64=26} med_type_champ;
488
489 typedef struct { int dt; int it; } DT_IT_;
490
491 typedef enum {V21 = 26, V22 = 75} medFileVersion;
492
493 medFileVersion getMedFileVersionForWriting();
494
495 void setMedFileVersionForWriting(medFileVersion version);
496
497 %{
498   medFileVersion getMedFileVersionForWriting()
499     {
500       return (medFileVersion) DRIVERFACTORY::getMedFileVersionForWriting();
501     }
502
503   void setMedFileVersionForWriting(medFileVersion version)
504     {
505       DRIVERFACTORY::setMedFileVersionForWriting((medFileVersion) version);
506     }
507 %}
508
509 %extend DT_IT_ {
510   int getdt()
511     {
512       return self->dt;
513     }
514
515   int getit()
516     {
517       return self->it;
518     }
519 }
520
521 %typecheck(SWIG_TYPECHECK_POINTER) vector< SUPPORT * >, const vector< SUPPORT * >
522 {
523   $1 = ($input != 0);
524 }
525
526 /*
527   Class et methodes du MED++ que l'on utilise dans l'API Python
528 */
529
530 class CELLMODEL
531 {
532  public:
533   CELLMODEL();
534
535   CELLMODEL(medGeometryElement t);
536
537   CELLMODEL(const CELLMODEL &m);
538
539   int getNumberOfVertexes();
540
541   int getNumberOfNodes();
542
543   int getDimension();
544
545   medGeometryElement getType();
546
547   int getNumberOfConstituents(int dim);
548
549   int getNodeConstituent(int dim,int num,int nodes_index);
550
551   medGeometryElement getConstituentType(int dim,int num);
552
553   int getNumberOfConstituentsType();
554
555   std::string getName() const;
556
557   ~CELLMODEL();
558
559   %extend {
560     %newobject __str__();
561     const char* __str__()
562       {
563         ostringstream mess;
564         mess << "Python Printing CELLMODEL : " << *self << endl;
565         return strdup(mess.str().c_str());
566       }
567   }
568 };
569
570 class SUPPORT
571 {
572  public:
573   SUPPORT();
574
575   SUPPORT(const SUPPORT & m);
576
577   ~SUPPORT();
578
579   void update ( void );
580
581   MESH * getMesh() const;
582
583   std::string getMeshName() const;
584
585   void setMesh(MESH * Mesh) const;
586
587   medEntityMesh getEntity() const;
588
589   void setEntity(medEntityMesh Entity);
590
591   bool isOnAllElements() const;
592
593   void setAll(bool All);
594
595   int getNumberOfTypes() const;
596
597   void setNumberOfGeometricType(int NumberOfGeometricType);
598
599   int getNumberOfElements(medGeometryElement GeometricType) const;
600
601   void setGeometricType(medGeometryElement *GeometricType);
602
603   void setNumberOfElements(int *NumberOfElements);
604
605   void setTotalNumberOfElements(int TotalNumberOfElements);
606
607   void getBoundaryElements();
608
609   void setNumber(const int * index, const int* value);
610
611   bool deepCompare(const SUPPORT &support) const;
612
613   SUPPORT(MESH* Mesh, std::string Name="", medEntityMesh Entity=MED_CELL);
614
615   void setpartial(std::string Description, int NumberOfGeometricType,
616                   int TotalNumberOfElements, medGeometryElement *GeometricType,
617                   int *NumberOfElements, int *NumberValue);
618
619   std::string getName() const;
620
621   void setName(std::string Name);
622
623   std::string getDescription();
624
625   void setDescription(std::string Description);
626
627   %extend {
628     %newobject __str__();
629     const char* __str__()
630       {
631         ostringstream mess;
632         mess << "Python Printing SUPPORT : " << *self << endl;
633         char * tmp = const_cast <char *> (mess.str().c_str());
634         char * returned = strdup(tmp);
635         return returned;
636       }
637
638     PyObject * getTypes()
639       {
640         const medGeometryElement * types = self->getTypes();
641         int size = self->getNumberOfTypes();
642         TYPEMAP_OUTPUT_ARRAY(types, size, PyInt_FromLong, SUPPORT::getTypes);
643       }
644
645     PyObject * getNumber(medGeometryElement GeometricType)
646       {
647         const int * number = self->getNumber(GeometricType);
648         int size = self->getNumberOfElements(GeometricType);
649         TYPEMAP_OUTPUT_ARRAY(number, size, PyInt_FromLong,
650                              SUPPORT::getNumber);
651       }
652
653     PyObject * getNumberIndex()
654       {
655         const int * numberindex = self->getNumberIndex();
656         int size = (self->getNumberOfElements(MED_ALL_ELEMENTS))+1;
657         TYPEMAP_OUTPUT_ARRAY(numberindex, size, PyInt_FromLong,
658                              SUPPORT::getNumberIndex);
659       }
660
661     %newobject getComplement() const;
662     SUPPORT *getComplement() const
663       {
664         return self->getComplement();
665       }
666
667     %newobject substract(const SUPPORT& other) const;
668     SUPPORT *substract(const SUPPORT& other) const
669       {
670         return self->substract(other);
671       }
672
673     %newobject getBoundaryElements(medEntityMesh Entity) const;
674     SUPPORT *getBoundaryElements(medEntityMesh Entity) const
675       {
676         return self->getBoundaryElements(Entity);
677       }
678   }
679 };
680
681 class FAMILY : public SUPPORT
682 {
683  public:
684   FAMILY();
685
686   FAMILY(const FAMILY & m);
687
688   ~FAMILY();
689
690   FAMILY & operator=(const FAMILY &fam);
691
692   void setIdentifier(int Identifier);
693
694   void setNumberOfAttributes(int NumberOfAttribute);
695
696   void setAttributesIdentifiers(int * AttributeIdentifier);
697
698   void setAttributesValues(int * AttributeValue);
699
700   void setAttributesDescriptions(string * AttributeDescription);
701
702   void setNumberOfGroups(int NumberOfGroups);
703
704   void setGroupsNames(string * GroupName);
705
706   int getIdentifier() const;
707
708   int getNumberOfAttributes() const;
709
710   int getNumberOfGroups() const;
711
712   FAMILY(MESH* Mesh, int Identifier, std::string Name, int NumberOfAttribute,
713          int *AttributeIdentifier, int *AttributeValue,
714          std::string AttributeDescription, int NumberOfGroup,
715          std::string GroupName, int * MEDArrayNodeFamily,
716          int ** MEDArrayCellFamily, int ** MEDArrayFaceFamily,
717          int ** MEDArrayEdgeFamily);
718
719   std::string getAttributeDescription(int i);
720
721   std::string getGroupName(int i);
722
723   %extend {
724     %newobject __str__();
725     const char* __str__()
726       {
727         ostringstream mess;
728         mess << "Python Printing Family : " << *self << endl;
729         return strdup(mess.str().c_str());
730       }
731
732     PyObject * getAttributesIdentifiers()
733       {
734         const int * attributesids = self->getAttributesIdentifiers();
735         int size = self->getNumberOfAttributes();
736         TYPEMAP_OUTPUT_ARRAY(attributesids,size,PyInt_FromLong,
737                              FAMILY::getAttributesIdentifiers);
738       }
739
740     PyObject * getAttributesValues()
741       {
742         const int * attributesvals = self->getAttributesValues();
743         int size = self->getNumberOfAttributes();
744         TYPEMAP_OUTPUT_ARRAY(attributesvals,size,PyInt_FromLong,
745                              FAMILY::getAttributesValues);
746       }
747   }
748 };
749
750 class FIELD_
751 {
752 public:
753   FIELD_(const SUPPORT * Support, const int NumberOfComponents);
754
755   ~FIELD_();
756
757   void rmDriver(int index=0);
758
759   void setIterationNumber (int IterationNumber);
760   int getIterationNumber() const;
761
762   void setTime(double Time);
763   double   getTime() const;
764
765   void setOrderNumber (int OrderNumber);
766   int getOrderNumber() const;
767
768   med_type_champ getValueType() ;
769
770   medModeSwitch getInterlacingType();
771
772   SUPPORT * getSupport();
773   void setSupport(SUPPORT * support);
774
775   void  setNumberOfComponents(int NumberOfComponents);
776   int getNumberOfComponents() const;
777
778   void setNumberOfValues(int NumberOfValues);
779   int getNumberOfValues() const;
780
781   std::string   getName() const;
782
783   std::string   getDescription() const;
784
785   std::string   getComponentName(int i) const;
786
787   std::string   getComponentDescription(int i) const;
788
789   std::string   getMEDComponentUnit(int i) const;
790
791   void     setName(std::string Name);
792
793   void     setComponentName(int i, std::string ComponentName);
794
795   void     setMEDComponentUnit(int i, std::string MEDComponentUnit);
796
797   void     setDescription(std::string Description);
798
799   void     setComponentDescription(int i, std::string ComponentDescription);
800
801   int addDriver(driverTypes driverType,
802                 const std::string& fileName="Default File Name.med",
803                 const std::string& driverName="Default Field Name",
804                 med_mode_acces access=MED_REMP);
805
806   %extend {
807     %newobject getSupportAndOwner();
808     SUPPORT * getSupportAndOwner()
809       {
810         return (SUPPORT *)self->getSupport();
811       }
812   }
813 };
814
815 /*
816   Class FIELD has now two template parameters T1 is a double or an int
817   INTERLACING_TAG is FullInterlace or NoInterlace
818 */
819
820 template<class T1, class INTERLACING_TAG> class FIELD : public FIELD_
821 {
822 public:
823   ~FIELD();
824
825   FIELD(const SUPPORT * Support, const int NumberOfComponents);
826
827   FIELD();
828
829   FIELD(const FIELD & m);
830
831   FIELD(const SUPPORT * Support, driverTypes driverType,
832         const std::string& fileName, const std::string& fieldName,
833         const int iterationNumber, const int orderNumber);
834
835   FIELD(driverTypes driverType, const std::string& fileName,
836         const std::string& fieldName, const int iterationNumber,
837         const int orderNumber);
838
839   void read(int index=0);
840
841   T1 getValueIJ(int i,int j) const;
842
843   void setValue(T1* value);
844
845   void setRow( int i, T1 * value);
846
847   void setColumn( int i, T1 * value);
848
849   void setValueIJ(int i, int j, T1 value);
850
851   void allocValue(const int NumberOfComponents);
852
853   void deallocValue();
854
855   void applyLin(T1 a, T1 n);
856
857   void applyPow(T1 scalar);
858
859   double normMax();
860
861   double norm2();
862
863   double normL2(int component,const FIELD<double, FullInterlace> *
864                 p_field_volume=NULL) const;
865
866   double normL2(const FIELD<double, FullInterlace> *
867                 p_field_volume=NULL) const;
868
869   double normL1(int component, const FIELD<double, FullInterlace> *
870                 p_field_volume=NULL) const;
871
872   double normL1(const FIELD<double, FullInterlace> *
873                 p_field_volume=NULL) const;
874
875   void write(int index=0, const std::string& driverName="");
876
877   void writeAppend(int index=0, const std::string& driverName="");
878
879   bool getGaussPresence();
880
881   GAUSS_LOCALIZATION<INTERLACING_TAG> * getGaussLocalizationPtr(MED_EN::medGeometryElement geomElement);
882
883   %extend {
884     PyObject *  applyPyFunc( PyObject * func )
885       {
886         MESSAGE("Appel de applyPyFunc");
887         if (!PyCallable_Check(func)) {
888           PyErr_SetString(PyExc_TypeError, "FIELD.applyPyFunc prend en argument une fonction");
889           return NULL;
890         }
891
892         int nComp=self->getNumberOfComponents();
893         int nVal=self->getNumberOfValues();
894         for (int i=1; i!=nVal+1; ++i)
895           for ( int j=1 ;j!=nComp+1 ;++j )
896             {
897               self->setValueIJ(i,j, Binding<T1>::Functor( func, self->getValueIJ(i,j) ) );
898             }
899
900         PyObject * result = Binding<double>::Traducer(nComp*nVal);
901         return result;
902       }
903
904     %newobject __add__(const FIELD<T1, INTERLACING_TAG> & );
905     FIELD<T1, INTERLACING_TAG> * __add__(const FIELD<T1, INTERLACING_TAG> & m)
906       {
907         MESSAGE("operator +  : Creation of the addition of two FIELDs");
908         
909         FIELD<T1, INTERLACING_TAG>* result =
910           FIELD<T1, INTERLACING_TAG>::add( *(FIELD<T1, INTERLACING_TAG>*)self ,
911                                            (FIELD<T1, INTERLACING_TAG>&)m );
912         return (FIELD<T1, INTERLACING_TAG>*) result;
913       }
914
915     %newobject __sub__(const FIELD<T1, INTERLACING_TAG> & );
916     FIELD<T1, INTERLACING_TAG> * __sub__(const FIELD<T1, INTERLACING_TAG> & m)
917       {
918         MESSAGE("operator -  : Creation of the substraction of two FIELDs");
919         FIELD<T1, INTERLACING_TAG>* result =
920           FIELD<T1, INTERLACING_TAG>::sub( *(FIELD<T1, INTERLACING_TAG>*)self ,
921                                            (FIELD<T1, INTERLACING_TAG>&)m );
922         return (FIELD<T1, INTERLACING_TAG>*) result;
923       }
924
925     %newobject __mul__(const FIELD<T1, INTERLACING_TAG> & );
926     FIELD<T1, INTERLACING_TAG> * __mul__(const FIELD<T1, INTERLACING_TAG> & m)
927       {
928         MESSAGE("operator *  : Creation of the multiplication of two FIELDs");
929         FIELD<T1, INTERLACING_TAG>* result =
930           FIELD<T1, INTERLACING_TAG>::mul( *(FIELD<T1, INTERLACING_TAG>*)self ,
931                                            (FIELD<T1, INTERLACING_TAG>&)m );
932         return (FIELD<T1, INTERLACING_TAG>*) result;
933       }
934
935     %newobject __div__(const FIELD<T1, INTERLACING_TAG> & );
936     FIELD<T1, INTERLACING_TAG> * __div__(const FIELD<T1, INTERLACING_TAG> & m)
937       {
938         MESSAGE("operator /  : Creation of the division of two FIELDs");
939         FIELD<T1, INTERLACING_TAG>* result =
940           FIELD<T1, INTERLACING_TAG>::div( *(FIELD<T1, INTERLACING_TAG>*)self ,
941                                            (FIELD<T1, INTERLACING_TAG>&)m );
942         return (FIELD<T1, INTERLACING_TAG>*) result;
943       }
944
945     %newobject addDeep(const FIELD<T1, INTERLACING_TAG> & );
946     FIELD<T1, INTERLACING_TAG> * addDeep(const FIELD<T1, INTERLACING_TAG> & m)
947       {
948         MESSAGE("operator +  : Creation of the addition of two FIELDINTs");
949         FIELD<T1, INTERLACING_TAG>* result =
950           FIELD<T1, INTERLACING_TAG>::addDeep( *(FIELD<T1, INTERLACING_TAG>*)self ,
951                                                (FIELD<T1, INTERLACING_TAG>&)m );
952         return (FIELD<T1, INTERLACING_TAG>*) result;
953       }
954
955     %newobject subDeep(const FIELD<T1, INTERLACING_TAG> & );
956     FIELD<T1, INTERLACING_TAG> * subDeep(const FIELD<T1, INTERLACING_TAG> & m)
957       {
958         MESSAGE("operator -  : Creation of the substraction of two FIELDs");
959         FIELD<T1, INTERLACING_TAG>* result =
960           FIELD<T1, INTERLACING_TAG>::subDeep( *(FIELD<T1, INTERLACING_TAG>*)self ,
961                                                (FIELD<T1, INTERLACING_TAG>&)m );
962         return (FIELD<T1, INTERLACING_TAG>*) result;
963       }
964
965     %newobject mulDeep(const FIELD<T1, INTERLACING_TAG> & );
966     FIELD<T1, INTERLACING_TAG> * mulDeep(const FIELD<T1, INTERLACING_TAG> & m)
967       {
968         MESSAGE("operator *  : Creation of the multiplication of two FIELDs");
969         FIELD<T1, INTERLACING_TAG>* result =
970           FIELD<T1, INTERLACING_TAG>::mulDeep( *(FIELD<T1, INTERLACING_TAG>*)self ,
971                                                (FIELD<T1, INTERLACING_TAG>&)m );
972         return (FIELD<T1, INTERLACING_TAG>*) result;
973       }
974
975     %newobject divDeep(const FIELD<T1, INTERLACING_TAG> & );
976     FIELD<T1, INTERLACING_TAG> * divDeep(const FIELD<T1, INTERLACING_TAG> & m)
977       {
978         MESSAGE("operator /  : Creation of the division of two FIELDs");
979         FIELD<T1, INTERLACING_TAG>* result =
980           FIELD<T1, INTERLACING_TAG>::divDeep( *(FIELD<T1, INTERLACING_TAG>*)self ,
981                                                (FIELD<T1, INTERLACING_TAG>&)m );
982         return (FIELD<T1, INTERLACING_TAG>*) result;
983       }
984
985     PyObject * getValue()
986       {
987         int size = (self->getNumberOfComponents())*
988           ((self->getSupport())->getNumberOfElements(MED_ALL_ELEMENTS));
989
990         const T1 * value = self->getValue();
991
992         TYPEMAP_OUTPUT_ARRAY(value, size, Binding< T1 >::Traducer,
993                              FIELD::getValue);
994       }
995
996     // this method replaces getValueI() in FullInterlace mode
997     /* %newobject getRow(int );*/
998     PyObject * getRow(int index)
999       {
1000         int size = self->getNumberOfComponents();
1001
1002         const T1 * value = self->getRow(index);
1003
1004         TYPEMAP_OUTPUT_ARRAY(value, size, Binding< T1 >::Traducer,
1005                              FIELD::getRow);
1006       }
1007
1008     // this method replaces getValueI() in NoInterlace mode
1009     /*%newobject getColum(int );*/
1010     PyObject * getColumn(int index)
1011       {
1012         int size = (self->getSupport())->getNumberOfElements(MED_ALL_ELEMENTS);
1013
1014         const T1 * value = self->getColumn(index);
1015
1016         TYPEMAP_OUTPUT_ARRAY(value, size, Binding< T1 >::Traducer,
1017                              FIELD::getColumn);
1018       }
1019
1020     /*
1021     %newobject getValueI(int );
1022     PyObject * getValueI(int index)
1023       {
1024         int size = self->getNumberOfComponents();
1025
1026         medModeSwitch  Mode = self->getInterlacingType();
1027
1028         if ( Mode == MED_NO_INTERLACE ) size = (self->getSupport())->getNumberOfElements(MED_ALL_ELEMENTS);
1029
1030         const T1 * value = self->getValueI(index);
1031
1032         TYPEMAP_OUTPUT_ARRAY(value, size, Binding< T1 >::Traducer,
1033                              FIELD::getValueI);
1034       }
1035     */
1036
1037     void allocValue2(int NumberOfComponents, int LengthValue)
1038       {
1039         self->allocValue(NumberOfComponents, LengthValue);
1040       }
1041
1042     %newobject extract(const SUPPORT *subSupport);
1043     FIELD<T1, INTERLACING_TAG> *extract(const SUPPORT *subSupport)
1044       {
1045         FIELD<T1, INTERLACING_TAG>* result=self->extract(subSupport);
1046         return (FIELD<T1, INTERLACING_TAG> *)result;
1047       }
1048   }
1049 };
1050
1051 /*%template(FIELDDOUBLEFULLINTERLACE) FIELD<double, FullInterlace>;*/
1052 %template(FIELDDOUBLE) FIELD<double, FullInterlace>;
1053 %template(FIELDDOUBLENOINTERLACE) FIELD<double, NoInterlace>;
1054 /*%template(FIELDINTFULLINTERLACE) FIELD<int, FullInterlace>;*/
1055 %template(FIELDINT) FIELD<int, FullInterlace>;
1056 %template(FIELDINTNOINTERLACE) FIELD<int, NoInterlace>;
1057
1058 class GROUP : public SUPPORT
1059 {
1060 public:
1061   GROUP();
1062
1063   ~GROUP();
1064
1065   void setNumberOfFamilies(int numberOfFamilies);
1066   void setFamilies(vector< FAMILY * > Family);
1067
1068   int getNumberOfFamilies() const ;
1069   vector< FAMILY * > getFamilies() const ;
1070   FAMILY * getFamily(int i) const ;
1071 };
1072
1073 class MESH
1074 {
1075 public :
1076   MESH();
1077
1078   ~MESH();
1079
1080   void rmDriver(int index=0);
1081
1082   void read(int index=0);
1083
1084   int getSpaceDimension();
1085
1086   int getMeshDimension();
1087
1088   int getNumberOfNodes();
1089
1090   bool getIsAGrid();
1091
1092   const double getCoordinate(int Number, int Axis);
1093
1094   int getNumberOfTypes(medEntityMesh Entity);
1095
1096   void calculateConnectivity(medModeSwitch Mode,medConnectivity ConnectivityType,medEntityMesh Entity);
1097
1098   int  getNumberOfElements(medEntityMesh Entity,medGeometryElement Type);
1099
1100   int getNumberOfFamilies(medEntityMesh Entity);
1101
1102   int getElementNumber(medConnectivity ConnectivityType, medEntityMesh Entity, medGeometryElement Type, int * connectivity);
1103
1104   CELLMODEL * getCellsTypes(medEntityMesh Entity);
1105
1106   FAMILY* getFamily(medEntityMesh Entity,int i);
1107
1108   int getNumberOfGroups(medEntityMesh Entity);
1109
1110   GROUP * getGroup(medEntityMesh Entity,int i);
1111
1112   medGeometryElement getElementType(medEntityMesh Entity,int Number);
1113
1114   int getElementContainingPoint(const double *coord);
1115
1116   int getNumberOfTypesWithPoly(medEntityMesh Entity);
1117
1118   int getNumberOfPolygons();
1119
1120   int getNumberOfPolyhedronFaces();
1121
1122   int getNumberOfPolyhedron();
1123
1124   int getNumberOfElementsWithPoly(medEntityMesh Entity,
1125                                   medGeometryElement Type);
1126
1127   bool existPolygonsConnectivity(medConnectivity ConnectivityType,
1128                                  medEntityMesh Entity);
1129
1130   bool existPolyhedronConnectivity(medConnectivity ConnectivityType,
1131                                    medEntityMesh Entity);
1132
1133   medGeometryElement getElementTypeWithPoly(medEntityMesh Entity,int Number);
1134
1135   std::string getName() const;
1136   
1137   %extend {
1138     %newobject getBoundaryElements(medEntityMesh );
1139     SUPPORT * getBoundaryElements(medEntityMesh Entity)
1140       {
1141         return self->getBoundaryElements(Entity);
1142       }
1143
1144     %newobject getSkin(const SUPPORT * );
1145     SUPPORT * getSkin(const SUPPORT * Support3D)
1146       {
1147         return self->getSkin(Support3D);
1148       }
1149
1150     %newobject mergeSupports(const vector< SUPPORT * > );
1151     SUPPORT * mergeSupports(const vector< SUPPORT * > Supports)
1152       {
1153         return self->mergeSupports(Supports);
1154       }
1155
1156     %newobject intersectSupports(const vector< SUPPORT * > );
1157     SUPPORT * intersectSupports(const vector< SUPPORT * > Supports)
1158       {
1159         return self->intersectSupports(Supports);
1160       }
1161
1162     %newobject mergeFieldsDouble(const vector< FIELD<double>* > others);
1163     FIELD<double, FullInterlace> * mergeFieldsDouble(const vector< FIELD<double>* > others)
1164       {
1165         return (FIELD<double, FullInterlace> *)self->mergeFields<double>(others);
1166       }
1167
1168     %newobject mergeFieldsInt(const vector< FIELD<int>* > others);
1169     FIELD<int, FullInterlace> * mergeFieldsInt(const vector< FIELD<int>* > others)
1170       {
1171         return (FIELD<int, FullInterlace> *)self->mergeFields<int>(others);
1172       }
1173
1174     CELLMODEL getCellType(medEntityMesh Entity,int i)
1175       {
1176         return self->getCellsTypes(Entity)[i];
1177       }
1178
1179     MESH (driverTypes driverType, char * fileName, char * meshName)
1180       {
1181         return new MESH(driverType, string(fileName), string(meshName));
1182       }
1183
1184     int addDriver(driverTypes driverType,
1185                   char * fileName="Default File Name.med",
1186                   char * driverName="Default Mesh Name",
1187                   med_mode_acces access=MED_REMP)
1188       {
1189         return self->addDriver(driverType,string(fileName),
1190                                string(driverName),access);
1191       }
1192
1193     void write(int index=0, char * driverName="")
1194       {
1195         self->write(index, string(driverName));
1196       }
1197
1198     void setName(char * name)
1199       {
1200         self->setName(string(name));
1201       }
1202
1203     %newobject getCoordinatesSystem();
1204     const char * getCoordinatesSystem()
1205       {
1206         string tmp_str = self->getCoordinatesSystem();
1207         char * tmp = new char[strlen(tmp_str.c_str())+1];
1208         strcpy(tmp,tmp_str.c_str());
1209         return tmp;
1210       }
1211
1212     %newobject __str__();
1213     const char* __str__()
1214       {
1215         ostringstream mess;
1216         mess << "Python Printing MESH : " << *self << endl;
1217         return strdup(mess.str().c_str());
1218       }
1219
1220     %newobject getCoordinateName(int );
1221     const char * getCoordinateName(int i)
1222       {
1223         string tmp_str = self->getCoordinatesNames()[i];
1224         char * tmp = new char[strlen(tmp_str.c_str())+1];
1225         strcpy(tmp,tmp_str.c_str());
1226         return tmp;
1227       }
1228
1229     %newobject getCoordinateUnit(int );
1230     const char * getCoordinateUnit(int i)
1231       {
1232         string tmp_str = self->getCoordinatesUnits()[i];
1233         char * tmp = new char[strlen(tmp_str.c_str())+1];
1234         strcpy(tmp,tmp_str.c_str());
1235         return tmp;
1236       }
1237
1238     PyObject * getCoordinatesNames()
1239       {
1240         const string * array = self->getCoordinatesNames();
1241         int size = self->getSpaceDimension();
1242         TYPEMAP_OUTPUT_ARRAY(array, size, PyString_FromStdString,
1243                              MESH::getCoordinatesNames);
1244       }
1245
1246     PyObject * getCoordinatesUnits()
1247       {
1248         const string * array = self->getCoordinatesUnits();
1249         int size = self->getSpaceDimension();
1250         TYPEMAP_OUTPUT_ARRAY(array, size, PyString_FromStdString,
1251                              MESH::getCoordinatesUnits);
1252       }
1253
1254     PyObject * getCoordinates(medModeSwitch Mode)
1255       {
1256         const double * array = self->getCoordinates(Mode);
1257         int size = (self->getSpaceDimension())*(self->getNumberOfNodes());
1258         TYPEMAP_OUTPUT_ARRAY(array, size, PyFloat_FromDouble,
1259                              MESH::getCoordinates);
1260       }
1261
1262     PyObject * getTypes(medEntityMesh Entity)
1263       {
1264         const medGeometryElement * types = self->getTypes(Entity);
1265         int size = self->getNumberOfTypes(Entity);
1266         TYPEMAP_OUTPUT_ARRAY(types, size, PyInt_FromLong, MESH::getTypes);
1267       }
1268
1269     PyObject * getConnectivity(medModeSwitch Mode,
1270                                medConnectivity ConnectivityType,
1271                                medEntityMesh Entity,
1272                                medGeometryElement Type)
1273       {
1274         const int * connectivity = self->getConnectivity(Mode,ConnectivityType,
1275                                                    Entity,Type);
1276         int size = self->getConnectivityLength(Mode,ConnectivityType,Entity,Type);
1277         TYPEMAP_OUTPUT_ARRAY(connectivity, size, PyInt_FromLong,
1278                              MESH::getConnectivity );
1279       }
1280
1281     PyObject * getConnectivityIndex(medConnectivity ConnectivityType,
1282                                     medEntityMesh Entity)
1283       {
1284         const int * connectivity_index =
1285           self->getConnectivityIndex(ConnectivityType,Entity);
1286         int size = (self->getNumberOfElements(Entity,MED_ALL_ELEMENTS))+1;
1287         TYPEMAP_OUTPUT_ARRAY(connectivity_index,size,PyInt_FromLong,
1288                              MESH::getConnectivityIndex);
1289       }
1290
1291     PyObject * getReverseConnectivity(medConnectivity ConnectivityType,
1292                                       medEntityMesh Entity=MED_CELL)
1293       {
1294         const int * reverseconnectivity =
1295           self->getReverseConnectivity(ConnectivityType,Entity);
1296         int size = self->getReverseConnectivityLength(ConnectivityType,Entity);
1297         TYPEMAP_OUTPUT_ARRAY(reverseconnectivity, size, PyInt_FromLong,
1298                              MESH::getReverseConnectivity);
1299       }
1300
1301     PyObject * getReverseConnectivityIndex(medConnectivity ConnectivityType,
1302                                            medEntityMesh Entity=MED_CELL)
1303       {
1304         const int * reverseconnectivity_index =
1305           self->getReverseConnectivityIndex(ConnectivityType,Entity);
1306         int size=self->getReverseConnectivityIndexLength(ConnectivityType,Entity);
1307         TYPEMAP_OUTPUT_ARRAY(reverseconnectivity_index,size, PyInt_FromLong,
1308                              MESH::getReverseConnectivityIndex);
1309       }
1310
1311     PyObject * getGlobalNumberingIndex(medEntityMesh Entity)
1312       {
1313         const int * numberingIndex = self->getGlobalNumberingIndex(Entity);
1314         int nbOfTypes = self->getNumberOfTypes(Entity);
1315         int size = nbOfTypes+1;
1316         TYPEMAP_OUTPUT_ARRAY(numberingIndex, size, PyInt_FromLong,
1317                              MESH::getGlobalNumberingIndex);
1318       }
1319
1320     PyObject * getPolygonsConnectivity(medConnectivity ConnectivityType,
1321                                        medEntityMesh   Entity)
1322       {
1323         const int * array = self->getPolygonsConnectivity(ConnectivityType,Entity);
1324         int size = self->getPolygonsConnectivityLength(ConnectivityType, Entity);
1325         TYPEMAP_OUTPUT_ARRAY(array, size, PyInt_FromLong,
1326                              MESH::getPolygonsConnectivity);
1327       }
1328
1329     PyObject * getPolygonsConnectivityIndex(medConnectivity ConnectivityType,
1330                                             medEntityMesh   Entity)
1331       {
1332         const int * array = self->getPolygonsConnectivityIndex(ConnectivityType,Entity);
1333         int size = self->getNumberOfPolygons() + 1;
1334         TYPEMAP_OUTPUT_ARRAY(array, size, PyInt_FromLong,
1335                              MESH::getPolygonsConnectivity);
1336       }
1337
1338     PyObject * getPolyhedronConnectivity(medConnectivity ConnectivityType)
1339       {
1340         const int * array = self->getPolyhedronConnectivity(ConnectivityType);
1341         int size = self->getPolyhedronConnectivityLength(ConnectivityType);
1342         TYPEMAP_OUTPUT_ARRAY(array, size, PyInt_FromLong,
1343                              MESH::getPolygonsConnectivity);
1344       }
1345
1346     PyObject * getPolyhedronIndex(medConnectivity ConnectivityType)
1347       {
1348         const int * array = self->getPolyhedronIndex(ConnectivityType);
1349         int size = self->getNumberOfPolyhedron() + 1;
1350         TYPEMAP_OUTPUT_ARRAY(array, size, PyInt_FromLong,
1351                              MESH::getPolyhedronIndex);
1352       }
1353
1354     PyObject * getPolyhedronFacesIndex()
1355       {
1356         const int * array = self->getPolyhedronFacesIndex();
1357         int size = self->getNumberOfPolyhedronFaces() + 1;
1358         TYPEMAP_OUTPUT_ARRAY(array, size, PyInt_FromLong,
1359                              MESH::getPolyhedronFacesIndex);
1360       }
1361
1362     PyObject * getTypesWithPoly(medEntityMesh Entity)
1363       {
1364         medGeometryElement * array = self->getTypesWithPoly(Entity);
1365         int size = self->getNumberOfTypesWithPoly(Entity);
1366         TYPEMAP_OUTPUT_ARRAY(array, size, PyInt_FromLong,
1367                              MESH::getTypesWithPoly);
1368         delete [] array;
1369       }
1370       
1371
1372     %newobject getVolume(const SUPPORT * );
1373     FIELD<double, FullInterlace> * getVolume(const SUPPORT * Support)
1374       {
1375         return (FIELD<double, FullInterlace> *) self->getVolume(Support);
1376       }
1377
1378     %newobject getArea(const SUPPORT * );
1379     FIELD<double, FullInterlace> * getArea(const SUPPORT * Support)
1380       {
1381         return (FIELD<double, FullInterlace> *) self->getArea(Support);
1382       }
1383
1384     %newobject getLength(const SUPPORT * );
1385     FIELD<double, FullInterlace> * getLength(const SUPPORT * Support)
1386       {
1387         return (FIELD<double, FullInterlace> *) self->getLength(Support);
1388       }
1389
1390     %newobject getNormal(const SUPPORT * );
1391     FIELD<double, FullInterlace> * getNormal(const SUPPORT * Support)
1392       {
1393         return (FIELD<double, FullInterlace> *) self->getNormal(Support);
1394       }
1395
1396     %newobject getBarycenter(const SUPPORT * );
1397     FIELD<double, FullInterlace> * getBarycenter(const SUPPORT * Support)
1398       {
1399         return (FIELD<double, FullInterlace> *) self->getBarycenter(Support);
1400       }
1401   }
1402 } ;
1403
1404 class MESHING: public MESH
1405 {
1406 public :
1407   MESHING();
1408   ~MESHING();
1409
1410   void setSpaceDimension   (const int SpaceDimension) ;
1411
1412   void setMeshDimension    (const int MeshDimension) ;
1413
1414   void setNumberOfNodes    (const int NumberOfNodes) ;
1415
1416   void setNumberOfTypes    (const int NumberOfTypes,
1417                             const medEntityMesh Entity) ;
1418
1419   void setTypes            (const medGeometryElement * Types,
1420                             const medEntityMesh Entity) ;
1421
1422   void setNumberOfElements (const int * NumberOfElements,
1423                             const medEntityMesh Entity) ;
1424
1425   void setConnectivity     (const int * Connectivity,
1426                             const medEntityMesh Entity,
1427                             const medGeometryElement Type) ;
1428
1429   void setConnectivities   (const int * ConnectivityIndex,
1430                             const int * ConnectivityValue,
1431                             const medConnectivity ConnectivityType,
1432                             const medEntityMesh Entity) ;
1433
1434   void addGroup            (const GROUP & Group) ;
1435
1436   void setPolygonsConnectivity     (const int * ConnectivityIndex,
1437                                     const int * ConnectivityValue,
1438                                     int nbOfPolygons,
1439                                     const medEntityMesh Entity);
1440
1441   void setPolyhedraConnectivity     (const int * PolyhedronIndex,
1442                                      const int * FacesIndex,
1443                                      const int * Nodes,
1444                                      int nbOfPolyhedra,
1445                                      const MED_EN::medEntityMesh Entity);
1446
1447   %extend {
1448     void setCoordinates(const int SpaceDimension, const int NumberOfNodes,
1449                         const double * Coordinates, const char * System,
1450                         const medModeSwitch Mode)
1451       {
1452         self->setCoordinates(SpaceDimension, NumberOfNodes, Coordinates,
1453                              string(System), Mode);
1454       }
1455
1456     void setCoordinatesSystem(const char * System)
1457       {
1458         self->setCoordinatesSystem(string(System));
1459       }
1460
1461     void setCoordinateName (const char * name, const int i)
1462       {
1463         self->setCoordinateName(string(name), i);
1464       }
1465
1466     void setCoordinateUnit (const char* unit, const int i)
1467     {
1468       self->setCoordinateUnit (string(unit), i) ;
1469     }
1470   }
1471 };
1472
1473 class GRID : public MESH
1474 {
1475  public:
1476   GRID();
1477
1478   GRID(const GRID &m);
1479
1480   ~GRID();
1481
1482   int getNodeNumber(const int i, const int j=0, const int k=0) const ;
1483
1484   int getCellNumber(const int i, const int j=0, const int k=0) const ;
1485
1486   int getEdgeNumber(const int Axis, const int i, const int j=0, const int k=0) const ;
1487
1488   int getFaceNumber(const int Axis, const int i, const int j=0, const int k=0) const ;
1489
1490   med_grid_type getGridType();
1491
1492   int getArrayLength( const int Axis );
1493
1494   const double getArrayValue (const int Axis, const int i);
1495
1496   void setGridType(med_grid_type gridType);
1497
1498   %extend {
1499     GRID(driverTypes driverType, const char * fileName="", const char * meshName="")
1500       {
1501         return new GRID(driverType, string(fileName), string(meshName));
1502       }
1503
1504     PyObject * getEntityPosition(const medEntityMesh Entity, const int Number)
1505     {
1506       int ijk[3], Axis;
1507       int i=0, size = self->getSpaceDimension();
1508       int j=0;
1509       switch (Entity) {
1510       case MED_CELL:
1511         self->getCellPosition(Number, ijk[0], ijk[1], ijk[2]);
1512         break;
1513       case MED_NODE:
1514         self->getNodePosition(Number, ijk[0], ijk[1], ijk[2]);
1515         break;
1516       case MED_FACE:
1517         self->getFacePosition(Number, Axis, ijk[0], ijk[1], ijk[2]);
1518         size++;
1519         i++;
1520         break;
1521       case MED_EDGE:
1522         self->getEdgePosition(Number, Axis, ijk[0], ijk[1], ijk[2]);
1523         size++;
1524         i++;
1525         break;
1526       default:
1527         char * message = "Error in GRID::getEntityPosition: wrong Entity";
1528         PyErr_SetString(PyExc_RuntimeError, message);
1529         return NULL;
1530       }
1531       PyObject *py_list = PyList_New( size );
1532       for (; i < size; ++i)
1533       {
1534         int err = PyList_SetItem(py_list, i,
1535                                  Py_BuildValue("i", ijk[j++]));
1536         if(err)
1537         {
1538           char * message = "Error in GRID::getNodePosition";
1539           PyErr_SetString(PyExc_RuntimeError, message);
1540           return NULL;
1541         }
1542       }
1543       if (Entity == MED_FACE || Entity == MED_EDGE)
1544         PyList_SetItem(py_list, 0, Py_BuildValue("i", Axis));
1545
1546       PyObject * result = Py_BuildValue("O", py_list);
1547       Py_DECREF(py_list);
1548       return result;
1549     }
1550   }
1551 };
1552
1553 class MED
1554 {
1555  public:
1556   MED();
1557
1558   ~MED();
1559
1560   void rmDriver (int index=0);
1561
1562   int getNumberOfMeshes ( void ) const;
1563
1564   int getNumberOfFields ( void ) const;
1565
1566   void updateSupport () ;
1567
1568   void write (int index=0);
1569
1570   void read (int index=0);
1571
1572   void addField ( FIELD_  * const ptrField  );
1573
1574   void addMesh  ( MESH    * const ptrMesh   );
1575
1576   %extend {
1577     MED(driverTypes driverType, char * fileName)
1578       {
1579         return new MED(driverType,string(fileName));
1580       }
1581
1582     int addDriver(driverTypes driverType,
1583                   char * fileName="Default File Name.med",
1584                   med_mode_acces access=MED_REMP)
1585       {
1586         return self->addDriver(driverType,string(fileName),access);
1587       }
1588
1589     PyObject *getMeshNames()
1590       {
1591         deque<string> list_string = self->getMeshNames();
1592         TYPEMAP_OUTPUT_DEQUE_STRING(list_string);
1593       }
1594
1595     %newobject getMeshName(int );
1596     const char * getMeshName(int i)
1597       {
1598         deque<string> list_string = self->getMeshNames();
1599         char * tmp = new char[strlen(list_string[i].c_str())+1];
1600         strcpy(tmp,list_string[i].c_str());
1601         return tmp;
1602       }
1603
1604     PyObject *getFieldNames()
1605       {
1606         deque<string> list_string = self->getFieldNames();
1607         TYPEMAP_OUTPUT_DEQUE_STRING(list_string);
1608       }
1609
1610     %newobject getFieldName(int );
1611     const char * getFieldName(int i)
1612       {
1613         deque<string> list_string = self->getFieldNames();
1614         char * tmp = new char[strlen(list_string[i].c_str())+1];
1615         strcpy(tmp,list_string[i].c_str());
1616         return tmp;
1617       }
1618
1619     MESH * getMesh(char * meshName)
1620       {
1621         MESH * myMesh = self->getMesh(string(meshName));
1622         return myMesh;
1623       }
1624
1625     int getFieldNumberOfIteration(char * fieldName)
1626       {
1627         deque<DT_IT_> list_dtit =
1628           self->getFieldIteration(string(fieldName));
1629         return list_dtit.size();
1630       }
1631
1632     DT_IT_ getFieldIteration(char * fieldName, int i)
1633       {
1634         deque<DT_IT_> list_dtit =
1635           self->getFieldIteration(string(fieldName));
1636         return list_dtit[i];
1637       }
1638
1639     FIELD_ * getField(char * fieldName, int dt, int it)
1640       {
1641         return self->getField(string(fieldName),dt,it);
1642       }
1643
1644     PyObject *getFieldT(char * fieldName, int dt, int it)
1645       {
1646         FIELD_ *ret=self->getField(string(fieldName),dt,it);
1647         TYPEMAP_OUTPUT_FIELDT(ret);
1648       }
1649
1650     FIELD_ * getField2(char * fieldName,double time, int it=0)
1651       {
1652         return self->getField2(string(fieldName),time,it);
1653       }
1654
1655     SUPPORT * getSupport(char * meshName, medEntityMesh entity)
1656       {
1657         return self->getSupport(string(meshName),entity);
1658       }
1659   }
1660 };
1661
1662 /*
1663   API de MED_MED_[RDONLY,WRONLY,RDWR]_DRIVER
1664 */
1665
1666 class MED_MED_RDONLY_DRIVER
1667 {
1668  public :
1669   void open();
1670   void close();
1671
1672   void read           ( void ) ;
1673   void readFileStruct ( void ) ;
1674
1675   virtual ~MED_MED_RDONLY_DRIVER();
1676
1677   %extend {
1678     MED_MED_RDONLY_DRIVER(char * fileName,  MED * ptrMed)
1679       {
1680         return new MED_MED_RDONLY_DRIVER(string(fileName), ptrMed);
1681       }
1682
1683     %newobject __str__();
1684     const char* __str__()
1685       {
1686         ostringstream mess;
1687         mess << "Python Printing MED_MED_RDONLY_DRIVER : " << *self << endl;
1688         return strdup(mess.str().c_str());
1689       }
1690   }
1691 };
1692
1693 class MED_MED_WRONLY_DRIVER
1694 {
1695  public :
1696   void open();
1697   void close();
1698
1699   void write          ( void ) const ;
1700   void writeFrom      ( void ) const ;
1701
1702   virtual ~MED_MED_WRONLY_DRIVER();
1703
1704   %extend {
1705     MED_MED_WRONLY_DRIVER(char * fileName,  MED * ptrMed)
1706       {
1707         return new MED_MED_WRONLY_DRIVER(string(fileName), ptrMed);
1708       }
1709
1710     %newobject __str__();
1711     const char* __str__()
1712       {
1713         ostringstream mess;
1714         mess << "Python Printing MED_MED_WRONLY_DRIVER : " << *self << endl;
1715         return strdup(mess.str().c_str());
1716       }
1717   }
1718 };
1719
1720 class MED_MED_RDWR_DRIVER : public virtual MED_MED_RDONLY_DRIVER,
1721                             public virtual MED_MED_WRONLY_DRIVER
1722 {
1723  public :
1724   void open();
1725   void close();
1726
1727   void write          ( void ) const ;
1728   void writeFrom      ( void ) const ;
1729   void read           ( void ) ;
1730   void readFileStruct ( void ) ;
1731
1732   ~MED_MED_RDWR_DRIVER();
1733
1734   %extend {
1735     MED_MED_RDWR_DRIVER(char * fileName,  MED * ptrMed)
1736       {
1737         return new MED_MED_RDWR_DRIVER(string(fileName), ptrMed);
1738       }
1739
1740     %newobject __str__();
1741     const char* __str__()
1742       {
1743         ostringstream mess;
1744         mess << "Python Printing MED_MED_RDWR_DRIVER : " << *self << endl;
1745         return strdup(mess.str().c_str());
1746       }
1747   }
1748 };
1749
1750 /*
1751   API de GIBI_MESH_[RDONLY,WRONLY,RDWR]_DRIVER
1752 */
1753
1754 class GIBI_MESH_RDONLY_DRIVER
1755 {
1756 public :
1757   GIBI_MESH_RDONLY_DRIVER() ;
1758
1759   GIBI_MESH_RDONLY_DRIVER(const GIBI_MESH_RDONLY_DRIVER & driver) ;
1760
1761   ~GIBI_MESH_RDONLY_DRIVER() ;
1762
1763   void open();
1764
1765   void write( void );
1766
1767   void read ( void );
1768
1769   void close();
1770
1771   %extend {
1772     GIBI_MESH_RDONLY_DRIVER(char * fileName, MESH * ptrMesh)
1773       {
1774         return new GIBI_MESH_RDONLY_DRIVER(string(fileName), ptrMesh) ;
1775       }
1776
1777     %newobject __str__();
1778     const char* __str__()
1779       {
1780         ostringstream mess;
1781         mess << "Python Printing GIBI_MESH_RDONLY_DRIVER : " << *self << endl;
1782         return strdup(mess.str().c_str());
1783       }
1784
1785     void setMeshName(char * meshName)
1786       {
1787         self->setMeshName(string(meshName));
1788       }
1789
1790     %newobject getMeshName();
1791     char * getMeshName()
1792       {
1793         string tmp_str = self->getMeshName();
1794         char * tmp = new char[strlen(tmp_str.c_str()) + 1];
1795         strcpy(tmp,tmp_str.c_str());
1796         return tmp;
1797       }
1798   }
1799 };
1800
1801 class GIBI_MESH_WRONLY_DRIVER
1802 {
1803 public :
1804   GIBI_MESH_WRONLY_DRIVER() ;
1805
1806   GIBI_MESH_WRONLY_DRIVER(const GIBI_MESH_WRONLY_DRIVER & driver) ;
1807
1808   ~GIBI_MESH_WRONLY_DRIVER() ;
1809
1810   void open();
1811
1812   void write( void );
1813
1814   void read ( void );
1815
1816   void close();
1817
1818   %extend {
1819     GIBI_MESH_WRONLY_DRIVER(char * fileName, MESH * ptrMesh)
1820       {
1821         return new GIBI_MESH_WRONLY_DRIVER(string(fileName), ptrMesh) ;
1822       }
1823
1824     %newobject __str__();
1825     const char* __str__()
1826       {
1827         ostringstream mess;
1828         mess << "Python Printing GIBI_MESH_WRONLY_DRIVER : " << *self << endl;
1829         return strdup(mess.str().c_str());
1830       }
1831
1832     void setMeshName(char * meshName)
1833       {
1834         self->setMeshName(string(meshName));
1835       }
1836
1837     %newobject getMeshName();
1838     char * getMeshName()
1839       {
1840         string tmp_str = self->getMeshName();
1841         char * tmp = new char[strlen(tmp_str.c_str()) + 1];
1842         strcpy(tmp,tmp_str.c_str());
1843         return tmp;
1844       }
1845   }
1846 };
1847
1848 class GIBI_MESH_RDWR_DRIVER : public virtual GIBI_MESH_RDONLY_DRIVER,
1849                               public virtual GIBI_MESH_WRONLY_DRIVER
1850 {
1851 public :
1852   GIBI_MESH_RDWR_DRIVER() ;
1853
1854   GIBI_MESH_RDWR_DRIVER(const GIBI_MESH_RDWR_DRIVER & driver) ;
1855
1856   ~GIBI_MESH_RDWR_DRIVER() ;
1857
1858   void open();
1859
1860   void write( void );
1861
1862   void read ( void );
1863
1864   void close();
1865
1866   %extend {
1867     GIBI_MESH_RDWR_DRIVER(char * fileName, MESH * ptrMesh)
1868       {
1869         return new GIBI_MESH_RDWR_DRIVER(string(fileName), ptrMesh) ;
1870       }
1871
1872     %newobject __str__();
1873     const char* __str__()
1874       {
1875         ostringstream mess;
1876         mess << "Python Printing GIBI_MESH_RDWR_DRIVER : " << *self << endl;
1877         return strdup(mess.str().c_str());
1878       }
1879
1880     void setMeshName(char * meshName)
1881       {
1882         self->setMeshName(string(meshName));
1883       }
1884
1885     %newobject getMeshName();
1886     char * getMeshName()
1887       {
1888         string tmp_str = self->getMeshName();
1889         char * tmp = new char[strlen(tmp_str.c_str()) + 1];
1890         strcpy(tmp,tmp_str.c_str());
1891         return tmp;
1892       }
1893   }
1894 };
1895
1896 class GIBI_MED_RDONLY_DRIVER
1897 {
1898 public :
1899   GIBI_MED_RDONLY_DRIVER() ;
1900
1901   GIBI_MED_RDONLY_DRIVER(const GIBI_MED_RDONLY_DRIVER & driver) ;
1902
1903   ~GIBI_MED_RDONLY_DRIVER() ;
1904
1905   void open();
1906
1907   void write( void );
1908
1909   void read ( void );
1910
1911   void close();
1912
1913   %extend {
1914     GIBI_MED_RDONLY_DRIVER(char * fileName, MED * ptrMed)
1915       {
1916         return new GIBI_MED_RDONLY_DRIVER(string(fileName), ptrMed) ;
1917       }
1918
1919     %newobject __str__();
1920     const char* __str__()
1921       {
1922         ostringstream mess;
1923         mess << "Python Printing GIBI_MED_RDONLY_DRIVER : " << *self << endl;
1924         return strdup(mess.str().c_str());
1925       }
1926
1927   }
1928 };
1929
1930 class GIBI_MED_WRONLY_DRIVER
1931 {
1932 public :
1933   GIBI_MED_WRONLY_DRIVER() ;
1934
1935   GIBI_MED_WRONLY_DRIVER(const GIBI_MED_WRONLY_DRIVER & driver) ;
1936
1937   ~GIBI_MED_WRONLY_DRIVER() ;
1938
1939   void open();
1940
1941   void write( void );
1942
1943   void read ( void );
1944
1945   void close();
1946
1947   %extend {
1948     GIBI_MED_WRONLY_DRIVER(char * fileName, MED * ptrMed, MESH * ptrMesh)
1949       {
1950         return new GIBI_MED_WRONLY_DRIVER(string(fileName), ptrMed, ptrMesh) ;
1951       }
1952
1953     %newobject __str__();
1954     const char* __str__()
1955       {
1956         ostringstream mess;
1957         mess << "Python Printing GIBI_MED_WRONLY_DRIVER : " << *self << endl;
1958         return strdup(mess.str().c_str());
1959       }
1960
1961   }
1962 };
1963
1964 /*
1965   API de PORFLOW_MESH_[RDONLY,WRONLY,RDWR]_DRIVER
1966 */
1967
1968 class PORFLOW_MESH_RDONLY_DRIVER
1969 {
1970 public :
1971   PORFLOW_MESH_RDONLY_DRIVER() ;
1972
1973   PORFLOW_MESH_RDONLY_DRIVER(const PORFLOW_MESH_RDONLY_DRIVER & driver) ;
1974
1975   ~PORFLOW_MESH_RDONLY_DRIVER() ;
1976
1977   void open();
1978
1979   void write( void );
1980
1981   void read ( void );
1982
1983   void close();
1984
1985   %extend {
1986     PORFLOW_MESH_RDONLY_DRIVER(char * fileName, MESH * ptrMesh)
1987       {
1988         return new PORFLOW_MESH_RDONLY_DRIVER(string(fileName), ptrMesh) ;
1989       }
1990
1991     %newobject __str__();
1992     const char* __str__()
1993       {
1994         ostringstream mess;
1995         mess << "Python Printing PORFLOW_MESH_RDONLY_DRIVER : " << *self << endl;
1996         return strdup(mess.str().c_str());
1997       }
1998
1999     void setMeshName(char * meshName)
2000       {
2001         self->setMeshName(string(meshName));
2002       }
2003
2004     %newobject getMeshName();
2005     char * getMeshName()
2006       {
2007         string tmp_str = self->getMeshName();
2008         char * tmp = new char[strlen(tmp_str.c_str()) + 1];
2009         strcpy(tmp,tmp_str.c_str());
2010         return tmp;
2011       }
2012   }
2013 };
2014
2015 class PORFLOW_MESH_WRONLY_DRIVER
2016 {
2017 public :
2018   PORFLOW_MESH_WRONLY_DRIVER() ;
2019
2020   PORFLOW_MESH_WRONLY_DRIVER(const PORFLOW_MESH_WRONLY_DRIVER & driver) ;
2021
2022   ~PORFLOW_MESH_WRONLY_DRIVER() ;
2023
2024   void open();
2025
2026   void write( void );
2027
2028   void read ( void );
2029
2030   void close();
2031
2032   %extend {
2033     PORFLOW_MESH_WRONLY_DRIVER(char * fileName, MESH * ptrMesh)
2034       {
2035         return new PORFLOW_MESH_WRONLY_DRIVER(string(fileName), ptrMesh) ;
2036       }
2037
2038     %newobject __str__();
2039     const char* __str__()
2040       {
2041         ostringstream mess;
2042         mess << "Python Printing PORFLOW_MESH_WRONLY_DRIVER : " << *self << endl;
2043         return strdup(mess.str().c_str());
2044       }
2045
2046     void setMeshName(char * meshName)
2047       {
2048         self->setMeshName(string(meshName));
2049       }
2050
2051     %newobject getMeshName();
2052     char * getMeshName()
2053       {
2054         string tmp_str = self->getMeshName();
2055         char * tmp = new char[strlen(tmp_str.c_str()) + 1];
2056         strcpy(tmp,tmp_str.c_str());
2057         return tmp;
2058       }
2059   }
2060 };
2061
2062 class PORFLOW_MESH_RDWR_DRIVER : public virtual PORFLOW_MESH_RDONLY_DRIVER,
2063                                  public virtual PORFLOW_MESH_WRONLY_DRIVER
2064 {
2065 public :
2066   PORFLOW_MESH_RDWR_DRIVER() ;
2067
2068   PORFLOW_MESH_RDWR_DRIVER(const PORFLOW_MESH_RDWR_DRIVER & driver) ;
2069
2070   ~PORFLOW_MESH_RDWR_DRIVER() ;
2071
2072   void open();
2073
2074   void write( void );
2075
2076   void read ( void );
2077
2078   void close();
2079
2080   %extend {
2081     PORFLOW_MESH_RDWR_DRIVER(char * fileName, MESH * ptrMesh)
2082       {
2083         return new PORFLOW_MESH_RDWR_DRIVER(string(fileName), ptrMesh) ;
2084       }
2085
2086     %newobject __str__();
2087     const char* __str__()
2088       {
2089         ostringstream mess;
2090         mess << "Python Printing PORFLOW_MESH_RDWR_DRIVER : " << *self << endl;
2091         return strdup(mess.str().c_str());
2092       }
2093
2094     void setMeshName(char * meshName)
2095       {
2096         self->setMeshName(string(meshName));
2097       }
2098
2099     %newobject getMeshName();
2100     char * getMeshName()
2101       {
2102         string tmp_str = self->getMeshName();
2103         char * tmp = new char[strlen(tmp_str.c_str()) + 1];
2104         strcpy(tmp,tmp_str.c_str());
2105         return tmp;
2106       }
2107   }
2108 };
2109
2110 /*
2111   API de MED_MESH_[RDONLY,WRONLY,RDWR]_DRIVER
2112 */
2113
2114 class MED_MESH_RDONLY_DRIVER
2115 {
2116  public :
2117
2118   ~MED_MESH_RDONLY_DRIVER();
2119
2120   void open();
2121
2122   void close();
2123
2124   void write( void ) ;
2125
2126   void read ( void ) ;
2127
2128   %extend {
2129     MED_MESH_RDONLY_DRIVER(char * fileName,  MESH * ptrMesh)
2130       {
2131         return new MED_MESH_RDONLY_DRIVER(string(fileName), ptrMesh);
2132       }
2133
2134     %newobject __str__();
2135     const char* __str__()
2136       {
2137         ostringstream mess;
2138         mess << "Python Printing MED_MESH_RDONLY_DRIVER : " << *self << endl;
2139         return strdup(mess.str().c_str());
2140       }
2141
2142     void setMeshName(char * meshName)
2143       {
2144         self->setMeshName(string(meshName));
2145       }
2146
2147     %newobject getMeshName();
2148     char * getMeshName()
2149       {
2150         string tmp_str = self->getMeshName();
2151         char * tmp = new char[strlen(tmp_str.c_str()) + 1];
2152         strcpy(tmp,tmp_str.c_str());
2153         return tmp;
2154       }
2155   }
2156 };
2157
2158 class MED_MESH_WRONLY_DRIVER
2159 {
2160  public :
2161   ~MED_MESH_WRONLY_DRIVER();
2162
2163   void write( void ) const ;
2164
2165   void read ( void ) ;
2166
2167   void open();
2168
2169   void close();
2170
2171   %extend {
2172     MED_MESH_WRONLY_DRIVER(char * fileName,  MESH * ptrMesh)
2173       {
2174         return new MED_MESH_WRONLY_DRIVER(string(fileName), ptrMesh);
2175       }
2176
2177     %newobject __str__();
2178     const char* __str__()
2179       {
2180         ostringstream mess;
2181         mess << "Python Printing MED_MESH_WRONLY_DRIVER : " << *self << endl;
2182         return strdup(mess.str().c_str());
2183       }
2184
2185     void setMeshName(char * meshName)
2186       {
2187         self->setMeshName(string(meshName));
2188       }
2189
2190     %newobject getMeshName();
2191     char * getMeshName()
2192       {
2193         string tmp_str = self->getMeshName();
2194         char * tmp = new char[strlen(tmp_str.c_str()) + 1];
2195         strcpy(tmp,tmp_str.c_str());
2196         return tmp;
2197       }
2198   }
2199 };
2200
2201 class MED_MESH_RDWR_DRIVER : public virtual MED_MESH_RDONLY_DRIVER,
2202                              public virtual MED_MESH_WRONLY_DRIVER
2203 {
2204  public :
2205
2206   ~MED_MESH_RDWR_DRIVER();
2207
2208   void write(void) const ;
2209
2210   void read (void)       ;
2211
2212   void open();
2213
2214   void close();
2215
2216   %extend {
2217     MED_MESH_RDWR_DRIVER(char * fileName,  MESH * ptrMesh)
2218       {
2219         return new MED_MESH_RDWR_DRIVER(string(fileName), ptrMesh);
2220       }
2221
2222     %newobject __str__();
2223     const char* __str__()
2224       {
2225         ostringstream mess;
2226         mess << "Python Printing MED_MESH_RDWR_DRIVER : " << *self << endl;
2227         return strdup(mess.str().c_str());
2228       }
2229
2230     void setMeshName(char * meshName)
2231       {
2232         self->setMeshName(string(meshName));
2233       }
2234
2235     %newobject getMeshName();
2236     char * getMeshName()
2237       {
2238         string tmp_str = self->getMeshName();
2239         char * tmp = new char[strlen(tmp_str.c_str()) + 1];
2240         strcpy(tmp,tmp_str.c_str());
2241         return tmp;
2242       }
2243   }
2244 };
2245
2246 /*
2247   API de MED_FIELD_[RDONLY,WRONLY,RDWR]_DRIVER
2248 */
2249
2250 template< class T1 >
2251 class MED_FIELD_RDONLY_DRIVER
2252 {
2253 public:
2254
2255   ~MED_FIELD_RDONLY_DRIVER();
2256
2257   void open();
2258
2259   void close();
2260
2261   void write( void ) const ;
2262
2263   void read ( void ) ;
2264
2265   %extend {
2266     MED_FIELD_RDONLY_DRIVER(char * fileName, FIELD<T1, FullInterlace > * ptrField)
2267       {
2268         return new MED_FIELD_RDONLY_DRIVER< T1 >(string(fileName), ptrField);
2269       }
2270
2271     %newobject __str__();
2272     const char* __str__()
2273       {
2274         ostringstream mess;
2275         mess << "Python Printing MED_FIELD_RDONLY_DRIVER : " << *self << endl;
2276         return strdup(mess.str().c_str());
2277       }
2278
2279     void setFieldName(char * fieldName)
2280       {
2281         self->setFieldName(string(fieldName));
2282       }
2283
2284     %newobject getFieldName();
2285     char * getFieldName()
2286       {
2287         string tmp_str = self->getFieldName();
2288         char * tmp = new char[strlen(tmp_str.c_str()) + 1];
2289         strcpy(tmp,tmp_str.c_str());
2290         return tmp;
2291       }
2292   }
2293 };
2294 %template ( MED_FIELDDOUBLE_RDONLY_DRIVER ) MED_FIELD_RDONLY_DRIVER< double >;
2295 %template ( MED_FIELDINT_RDONLY_DRIVER ) MED_FIELD_RDONLY_DRIVER< int >;
2296
2297
2298 template < class T1 >
2299 class MED_FIELD_WRONLY_DRIVER
2300 {
2301 public:
2302
2303   ~MED_FIELD_WRONLY_DRIVER();
2304
2305   void open();
2306
2307   void close();
2308
2309   void write( void ) const ;
2310
2311   void read ( void ) ;
2312
2313   %extend {
2314     MED_FIELD_WRONLY_DRIVER(char * fileName, FIELD<T1, FullInterlace> * ptrField)
2315       {
2316         return new MED_FIELD_WRONLY_DRIVER< T1 >(string(fileName), ptrField);
2317       }
2318
2319     %newobject __str__();
2320     const char* __str__()
2321       {
2322         ostringstream mess;
2323         mess << "Python Printing MED_FIELD_WRONLY_DRIVER : " << *self << endl;
2324         return strdup(mess.str().c_str());
2325       }
2326
2327     void setFieldName(char * fieldName)
2328       {
2329         self->setFieldName(string(fieldName));
2330       }
2331
2332     %newobject getFieldName();
2333     char * getFieldName()
2334       {
2335         string tmp_str = self->getFieldName();
2336         char * tmp = new char[strlen(tmp_str.c_str()) + 1];
2337         strcpy(tmp,tmp_str.c_str());
2338         return tmp;
2339       }
2340   }
2341 };
2342 %template ( MED_FIELDDOUBLE_WRONLY_DRIVER ) MED_FIELD_WRONLY_DRIVER< double >;
2343 %template ( MED_FIELDINT_WRONLY_DRIVER ) MED_FIELD_WRONLY_DRIVER< int >;
2344
2345
2346 template< class T1 >
2347 class MED_FIELD_RDWR_DRIVER : public virtual MED_FIELD_RDONLY_DRIVER< T1 >, public virtual MED_FIELD_WRONLY_DRIVER< T1 >
2348 {
2349 public:
2350
2351   ~MED_FIELD_RDWR_DRIVER();
2352
2353   void open();
2354
2355   void close();
2356
2357   void write( void ) const ;
2358
2359   void read ( void ) ;
2360
2361   %extend {
2362     MED_FIELD_RDWR_DRIVER(char * fileName, FIELD<T1, FullInterlace> * ptrField)
2363       {
2364         return new MED_FIELD_RDWR_DRIVER< T1 >(string(fileName), ptrField);
2365       }
2366
2367     %newobject __str__();
2368     const char* __str__()
2369       {
2370         ostringstream mess;
2371         mess << "Python Printing MED_FIELD_RDWR_DRIVER : " << *self << endl;
2372         return strdup(mess.str().c_str());
2373       }
2374
2375     void setFieldName(char * fieldName)
2376       {
2377         self->setFieldName(string(fieldName));
2378       }
2379
2380     %newobject getFieldName();
2381     char * getFieldName()
2382       {
2383         string tmp_str = self->getFieldName();
2384         char * tmp = new char[strlen(tmp_str.c_str()) + 1];
2385         strcpy(tmp,tmp_str.c_str());
2386         return tmp;
2387       }
2388   }
2389 };
2390 %template ( MED_FIELDDOUBLE_RDWR_DRIVER ) MED_FIELD_RDWR_DRIVER< double >;
2391 %template ( MED_FIELDINT_RDWR_DRIVER ) MED_FIELD_RDWR_DRIVER< int >;
2392
2393
2394 template< class T1 >
2395 class ASCII_FIELD_DRIVER {
2396 public:
2397   ~ASCII_FIELD_DRIVER();
2398
2399   void open();
2400
2401   void close();
2402
2403   void write( void ) const ;
2404
2405
2406   %extend {
2407     ASCII_FIELD_DRIVER(const char *fileName, FIELD<T1, FullInterlace> * ptrField, med_sort_direc direction, const char *priority)
2408       {
2409         return new ASCII_FIELD_DRIVER<T1>(string(fileName), ptrField, (MED_EN::med_sort_direc)direction, priority);
2410       }
2411   }
2412 };
2413
2414 %template (ASCII_FIELDDOUBLE_DRIVER) ASCII_FIELD_DRIVER< double >;
2415 %template (ASCII_FIELDINT_DRIVER) ASCII_FIELD_DRIVER< int >;
2416
2417 /*
2418 */
2419
2420
2421 template <class INTERLACING_TAG> class GAUSS_LOCALIZATION
2422 {
2423  public:
2424
2425   GAUSS_LOCALIZATION();
2426
2427   ~GAUSS_LOCALIZATION();
2428
2429   std::string getName() const ;
2430
2431   medGeometryElement getType() const ;
2432
2433   int getNbGauss() const ;
2434
2435   medModeSwitch  getInterlacingType() const;
2436
2437   %extend {
2438     GAUSS_LOCALIZATION<INTERLACING_TAG>(char * locName,
2439                                         const medGeometryElement
2440                                         typeGeo,
2441                                         const int  nGauss,
2442                                         const double * cooRef,
2443                                         const double * cooGauss,
2444                                         const double * wg)
2445       {
2446         return new GAUSS_LOCALIZATION<INTERLACING_TAG>(string(locName),
2447                                                        typeGeo, nGauss, cooRef,
2448                                                        cooGauss, wg);
2449       }
2450
2451     %newobject __str__();
2452     const char* __str__()
2453       {
2454         ostringstream mess;
2455         mess << "Python Printing GAUSS_LOCALIZATION : " << *self << endl;
2456         return strdup(mess.str().c_str());
2457       }
2458
2459     PyObject * getRefCoo () const
2460       {
2461         typedef  MEDMEM_ArrayInterface<double,INTERLACING_TAG,NoGauss>::Array ArrayNoGauss;
2462
2463         ArrayNoGauss cooRef = self->getRefCoo();
2464         int size = cooRef.getArraySize();
2465         double * cooRefPtr = cooRef.getPtr();
2466         TYPEMAP_OUTPUT_ARRAY(cooRefPtr, size, PyFloat_FromDouble,
2467                              GAUSS_LOCALIZATION::getRefCoo);
2468       }
2469
2470     PyObject * getGsCoo () const
2471       {
2472         typedef  MEDMEM_ArrayInterface<double,INTERLACING_TAG,NoGauss>::Array ArrayNoGauss;
2473         ArrayNoGauss cooGauss = self->getGsCoo();
2474         int size = cooGauss.getArraySize();
2475         double * cooGaussPtr = cooGauss.getPtr();
2476         TYPEMAP_OUTPUT_ARRAY(cooGaussPtr, size, PyFloat_FromDouble,
2477                              GAUSS_LOCALIZATION::getGsCoo);
2478       }
2479
2480     PyObject * getWeight () const
2481       {
2482         vector<double> wg = self->getWeight();
2483         int size = wg.size();
2484         double * wgPtr = new double [size];
2485         for (int index = 0; index<size; index++)
2486           wgPtr[index] = wg[index];
2487         TYPEMAP_OUTPUT_ARRAY(wgPtr, size, PyFloat_FromDouble,
2488                              GAUSS_LOCALIZATION::getWeight);
2489         delete wgPtr;
2490       }
2491   }
2492 };
2493
2494 %template (GAUSS_LOCALIZATION_FULL) GAUSS_LOCALIZATION<FullInterlace> ;
2495 %template (GAUSS_LOCALIZATION_NO) GAUSS_LOCALIZATION<NoInterlace> ;
2496
2497 %{
2498   template <class T, class INTERLACING_TAG>
2499     FIELD<T, INTERLACING_TAG> * createFieldScalarProduct(FIELD<T, INTERLACING_TAG> * field1,
2500                                                          FIELD<T, INTERLACING_TAG> * field2)
2501     {
2502       return (FIELD<T, INTERLACING_TAG> *)
2503         FIELD<T, INTERLACING_TAG>::scalarProduct((FIELD<T, INTERLACING_TAG>)*field1,
2504                                                  (FIELD<T, INTERLACING_TAG>)*field2);
2505     }
2506
2507   template <class T, class INTERLACING_TAG>
2508     FIELD<T, INTERLACING_TAG> * createFieldScalarProductDeep(FIELD<T, INTERLACING_TAG> * field1,
2509                                                              FIELD<T, INTERLACING_TAG> * field2)
2510     {
2511       return (FIELD<T, INTERLACING_TAG>*) FIELD<T, INTERLACING_TAG>::scalarProduct((FIELD<T, INTERLACING_TAG>)*field1,
2512                                                                                    (FIELD<T, INTERLACING_TAG>)*field2, true);
2513     }
2514
2515   template<class T, class INTERLACING_TAG>
2516     FIELD<T, INTERLACING_TAG> * createTypedFieldFromField(FIELD_ * field)
2517     {
2518       MESSAGE("createTypedFieldFromField : Constructor (for Python API) FIELD<T> with parameter FIELD_");
2519       MESSAGE("Its returns a proper cast of the input pointer :: FIELD_ --> FIELD<T>");
2520       return (FIELD<T, INTERLACING_TAG> *) field;
2521     }
2522
2523   template <class T> FIELD<T, FullInterlace> *
2524     createTypedFieldConvertFullInterlace(const FIELD<T, NoInterlace> & field )
2525     {
2526       return FieldConvert(field);
2527     }
2528
2529   template <class T> FIELD<T, NoInterlace> *
2530     createTypedFieldConvertNoInterlace(const FIELD<T, FullInterlace> & field )
2531     {
2532       return FieldConvert(field);
2533     }
2534 %}
2535
2536 template<class T, class INTERLACING_TAG> FIELD<T, INTERLACING_TAG> * createTypedFieldFromField(FIELD_ * field);
2537 %template ( createFieldDoubleFromField ) createTypedFieldFromField < double, FullInterlace>;
2538 %template ( createFieldIntFromField ) createTypedFieldFromField < int, FullInterlace >;
2539 %template ( createFieldDoubleNoInterlaceFromField ) createTypedFieldFromField < double, NoInterlace>;
2540 %template ( createFieldIntNoInterlaceFromField ) createTypedFieldFromField < int, NoInterlace >;
2541
2542 template <class T, class INTERLACING_TAG> FIELD<T, INTERLACING_TAG> * createFieldScalarProduct(FIELD<T, INTERLACING_TAG> * field1, FIELD<T, INTERLACING_TAG> * field2);
2543 %newobject createFieldDoubleScalarProduct ;
2544 %newobject createFieldIntScalarProduct ;
2545 %newobject createFieldDoubleNoInterlaceScalarProduct ;
2546 %newobject createFieldIntNoInterlaceScalarProduct ;
2547 %template ( createFieldDoubleScalarProduct ) createFieldScalarProduct < double, FullInterlace >;
2548 %template ( createFieldIntScalarProduct ) createFieldScalarProduct < int, FullInterlace >;
2549 %template ( createFieldDoubleNoInterlaceScalarProduct ) createFieldScalarProduct < double, NoInterlace >;
2550 %template ( createFieldIntNoInterlaceScalarProduct ) createFieldScalarProduct < int, NoInterlace >;
2551
2552 template <class T, class INTERLACING_TAG> FIELD<T, INTERLACING_TAG> * createFieldScalarProductDeep(FIELD<T, INTERLACING_TAG> * field1, FIELD<T, INTERLACING_TAG> * field2);
2553 %newobject createFieldDoubleScalarProductDeep ;
2554 %newobject createFieldIntScalarProductDeep ;
2555 %newobject createFieldDoubleNoInterlaceScalarProductDeep ;
2556 %newobject createFieldIntNoInterlaceScalarProductDeep ;
2557 %template ( createFieldDoubleScalarProductDeep ) createFieldScalarProductDeep < double, FullInterlace >;
2558 %template ( createFieldIntScalarProductDeep ) createFieldScalarProductDeep < int, FullInterlace >;
2559 %template ( createFieldDoubleNoInterlaceScalarProductDeep ) createFieldScalarProductDeep < double, NoInterlace >;
2560 %template ( createFieldIntNoInterlaceScalarProductDeep ) createFieldScalarProductDeep < int, NoInterlace >;
2561
2562 template<class T, class INTERLACING_TAG> FIELD<T, INTERLACING_TAG> * createFieldFromAnalytic(SUPPORT * Support, int NumberOfComponents, PyObject * double_function);
2563
2564 template <class T> FIELD<T, FullInterlace> * createTypedFieldConvertFullInterlace(const FIELD<T, NoInterlace> & field );
2565
2566 %template (createFieldDoubleConvertFullInterlace) createTypedFieldConvertFullInterlace<double>;
2567
2568 %template (createFieldIntConvertFullInterlace) createTypedFieldConvertFullInterlace<int>;
2569
2570 template <class T> FIELD<T, NoInterlace> * createTypedFieldConvertNoInterlace(const FIELD<T, FullInterlace> & field );
2571
2572 %template (createFieldDoubleConvertNoInterlace) createTypedFieldConvertNoInterlace<double>;
2573
2574 %template (createFieldIntConvertNoInterlace) createTypedFieldConvertNoInterlace<int>;
2575
2576 %newobject createFieldDoubleConvertFullInterlace ;
2577 %newobject createFieldIntConvertFullInterlace ;
2578
2579 %newobject createFieldDoubleConvertNoInterlace ;
2580 %newobject createFieldIntConvertNoInterlace ;
2581
2582 GRID * createGridFromMesh( MESH * aMesh );
2583
2584 %{
2585   GRID * createGridFromMesh( MESH * aMesh )
2586     {
2587       MESSAGE("createGridFromMesh : Constructor (for Python API) GRID with parameter MESH *");
2588       MESSAGE("Its returns a proper cast of the input pointer :: MESH --> GRID");
2589
2590       if (aMesh->getIsAGrid())
2591         return (GRID *) aMesh;
2592
2593       char * message = "Error in GRID(mesh): mesh is not a grid";
2594       PyErr_SetString(PyExc_RuntimeError, message);
2595       return NULL;
2596     }
2597
2598   template<class T, class INTERLACING_TAG>
2599     FIELD<T, INTERLACING_TAG> * createFieldFromAnalytic(SUPPORT * Support,
2600                                                         int NumberOfComponents,
2601                                                         PyObject * double_function)
2602     {
2603       MESSAGE("createFieldFromAnalytic : Constructor (for Python API) FIELD from an analytic fonction");
2604
2605       FIELD<T, INTERLACING_TAG> * fieldAnalytic =
2606         new FIELD<T, INTERLACING_TAG>(Support, NumberOfComponents);
2607
2608       MyFunction<T>::_pyFunc=double_function;
2609       MyFunction<T>::_nbOfComponent=NumberOfComponents;
2610       MyFunction<T>::_spaceDim=Support->getMesh()->getSpaceDimension();
2611       fieldAnalytic->fillFromAnalytic(MyFunction<T>::EvalPy2Cpp);
2612       return fieldAnalytic;
2613     }
2614 %}
2615
2616 %template (createFieldDoubleFromAnalytic) createFieldFromAnalytic<double, FullInterlace>;
2617 %template (createFieldIntFromAnalytic) createFieldFromAnalytic<int, FullInterlace>;
2618 %template (createFieldDoubleNoInterlaceFromAnalytic) createFieldFromAnalytic<double, NoInterlace>;
2619 %template (createFieldIntNoInterlaceFromAnalytic) createFieldFromAnalytic<int, NoInterlace>;