]> SALOME platform Git repositories - modules/med.git/blob - src/MedCorba_Swig/libMedCorba_Swig.i
Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/med.git] / src / MedCorba_Swig / libMedCorba_Swig.i
1 //  MED MedCorba_Swig : binding of MED CORBA objects woth Python
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : libMedCorba_Swig.i
25 //  Module : MED
26
27 %module libMedCorba_Swig
28
29 %include "libMEDMEM_Swig.i"
30
31 %{
32 #include "convert.hxx"
33 #include "Family_i.hxx"
34 #include "FieldDouble_i.hxx"
35 #include "Field_i.hxx"
36 #include "FieldInt_i.hxx"
37 #include "FieldOf_i.hxx"
38 #include "Group_i.hxx"
39 #include "Med_i.hxx"
40 #include "Mesh_i.hxx"
41 #include "Support_i.hxx"
42 #include "MEDMEM_SWIG_FieldDouble.hxx"
43 #include "MEDMEM_SWIG_FieldInt.hxx"
44 %}
45
46 /*
47   typemap in and out for Corba Objects (MESH, FIELDDOUBLE, FIELDINT and
48   Support) between C++ and Python
49
50   WARNING (NB) to the user of those typmaps (SWIG wrapping for C++ routines
51   -------------------------------------------------------------------------
52
53   You have to be quite careful about the SWIG version your are currently
54   using, because CORBA pointeur _ptr or _var could be wrapped by SWIG using
55   their reference rather than the pointeur itself (differences detected using
56   SWIG 1.1.x, SWIG 1.3.13 and SWIG 1.3.17)
57 */
58
59 %typemap(python,out) SALOME_MED::MESH_ptr, SALOME_MED::FIELDDOUBLE_ptr,
60   SALOME_MED::FIELDINT_ptr, SALOME_MED::SUPPORT_ptr,
61   const SALOME_MED::MESH_ptr, const SALOME_MED::FIELDDOUBLE_ptr,
62   const SALOME_MED::FIELDINT_ptr, const SALOME_MED::SUPPORT_ptr
63 {
64   MESSAGE("typemap out sur Objet Corba version ptr");
65
66   SCRUTE($1);
67
68   // Get the orb corba python
69
70   PyObject* pdict = PyDict_New();
71   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
72   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
73  
74   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
75                    pdict, pdict);
76  
77   PyObject* orb = PyDict_GetItemString(pdict, "o");
78
79   // Get the orb Corba C++
80
81   int argc = 0;
82   char *xargv = "";
83   char **argv = &xargv;
84   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
85
86   string s =  ORB->object_to_string($1);
87   SCRUTE(s);
88   PyObject * tmp = PyString_FromString(s.c_str());
89   SCRUTE(tmp);
90   $result = PyObject_CallMethod(orb, "string_to_object", "O", tmp);
91   SCRUTE($result);
92 }
93
94 %typemap(python,out) SALOME_MED::MESH_var, SALOME_MED::FIELDDOUBLE_var,
95   SALOME_MED::FIELDINT_var, SALOME_MED::SUPPORT_var,
96   const SALOME_MED::MESH_var, const SALOME_MED::FIELDDOUBLE_var,
97   const SALOME_MED::FIELDINT_var, const SALOME_MED::SUPPORT_var
98 {
99   MESSAGE("typemap out sur Objet Corba version var");
100
101   // Get the orb corba python
102
103   PyObject* pdict = PyDict_New();
104   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
105   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
106  
107   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
108                    pdict, pdict);
109  
110   PyObject* orb = PyDict_GetItemString(pdict, "o");
111
112   // Get the orb Corba C++
113
114   int argc = 0;
115   char *xargv = "";
116   char **argv = &xargv;
117   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
118
119   string s =  ORB->object_to_string(*$1);
120   SCRUTE(s);
121   PyObject * tmp = PyString_FromString(s.c_str());
122   SCRUTE(tmp);
123   $result = PyObject_CallMethod(orb, "string_to_object", "O", tmp);
124   SCRUTE($result);
125 }
126
127 %typemap(python,in) const SALOME_MED::MESH_ptr &, SALOME_MED::MESH_ptr &
128 {
129
130   MESSAGE("typemap in sur Objet Corba MESH avec reference");
131
132   PyObject* pdict = PyDict_New();
133   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
134   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
135  
136   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
137                    pdict, pdict);
138  
139   PyObject* orb = PyDict_GetItemString(pdict, "o");
140
141   // Ask omniORBpy to transform MESH (python Corba) ptr to IOR string
142
143   PyObject* iorMesh
144     = PyObject_CallMethod(orb, "object_to_string", "O", $input);
145  
146   if (iorMesh == Py_None)
147     return NULL;
148   char * s = PyString_AsString(PyObject_Str(iorMesh));
149  
150   // Ask omniORB to convert IOR string to MESH (C++ Corba) ptr
151
152   int argc = 0;
153   char *xargv = "";
154   char **argv = &xargv;
155   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
156   CORBA::Object_var O =  ORB->string_to_object(s);
157   SCRUTE(O);
158   SALOME_MED::MESH_ptr t = SALOME_MED::MESH::_narrow(O);
159
160   $1 = &t;
161   SCRUTE(*$1);
162 }
163
164 %typemap(python,in) const SALOME_MED::FIELDDOUBLE_ptr &,
165                     SALOME_MED::FIELDDOUBLE_ptr &
166 {
167
168   MESSAGE("typemap in sur Objet Corba FIELDDOUBLE avec reference");
169
170   PyObject* pdict = PyDict_New();
171   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
172   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
173  
174   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
175                    pdict, pdict);
176  
177   PyObject* orb = PyDict_GetItemString(pdict, "o");
178
179   // Ask omniORBpy to transform FIELDDOUBLE (python Corba) ptr to IOR string
180
181   PyObject* iorFieldDouble
182     = PyObject_CallMethod(orb, "object_to_string", "O", $input);
183  
184   if (iorFieldDouble == Py_None)
185     return NULL;
186   char * s = PyString_AsString(PyObject_Str(iorFieldDouble));
187  
188   // Ask omniORB to convert IOR string to FIELDDOUBLE (C++ Corba) ptr
189
190   int argc = 0;
191   char *xargv = "";
192   char **argv = &xargv;
193   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
194   CORBA::Object_var O =  ORB->string_to_object(s);
195   SCRUTE(O);
196   SALOME_MED::FIELDDOUBLE_ptr t = SALOME_MED::FIELDDOUBLE::_narrow(O);
197
198   $1 = &t;
199   SCRUTE(*$1);
200 }
201
202 %typemap(python,in) const SALOME_MED::FIELDINT_ptr &,
203                     SALOME_MED::FIELDINT_ptr &
204 {
205
206   MESSAGE("typemap in sur Objet Corba FIELDINT avec reference");
207
208   PyObject* pdict = PyDict_New();
209   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
210   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
211  
212   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
213                    pdict, pdict);
214  
215   PyObject* orb = PyDict_GetItemString(pdict, "o");
216
217   // Ask omniORBpy to transform FIELDINT (python Corba) ptr to IOR string
218
219   PyObject* iorFieldInt
220     = PyObject_CallMethod(orb, "object_to_string", "O", $input);
221  
222   if (iorFieldInt == Py_None)
223     return NULL;
224   char * s = PyString_AsString(PyObject_Str(iorFieldInt));
225  
226   // Ask omniORB to convert IOR string to FIELDINT (C++ Corba) ptr
227
228   int argc = 0;
229   char *xargv = "";
230   char **argv = &xargv;
231   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
232   CORBA::Object_var O =  ORB->string_to_object(s);
233   SCRUTE(O);
234   SALOME_MED::FIELDINT_ptr t = SALOME_MED::FIELDINT::_narrow(O);
235
236   $1 = &t;
237   SCRUTE(*$1);
238 }
239
240 %typemap(python,in) const SALOME_MED::SUPPORT_ptr &, SALOME_MED::SUPPORT_ptr &
241 {
242
243   MESSAGE("typemap in sur Objet Corba SUPPORT avec reference");
244
245   PyObject* pdict = PyDict_New();
246   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
247   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
248  
249   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
250                    pdict, pdict);
251  
252   PyObject* orb = PyDict_GetItemString(pdict, "o");
253
254   // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
255
256   PyObject* iorSupport
257     = PyObject_CallMethod(orb, "object_to_string", "O", $input);
258  
259   if (iorSupport == Py_None)
260     return NULL;
261   char * s = PyString_AsString(PyObject_Str(iorSupport));
262  
263   // Ask omniORB to convert IOR string to SUPPORT (C++ Corba) ptr
264
265   int argc = 0;
266   char *xargv = "";
267   char **argv = &xargv;
268   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
269   CORBA::Object_var O =  ORB->string_to_object(s);
270   SCRUTE(O);
271   SALOME_MED::SUPPORT_ptr t = SALOME_MED::SUPPORT::_narrow(O);
272
273   $1 = &t;
274   SCRUTE(*$1);
275 }
276
277 %typemap(python,in) const SALOME_MED::SUPPORT_ptr, SALOME_MED::SUPPORT_ptr
278 {
279
280   MESSAGE("typemap in sur Objet Corba SUPPORT sans reference");
281
282   SCRUTE($input);
283
284   PyObject* pdict = PyDict_New();
285   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
286   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
287  
288   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
289                    pdict, pdict);
290  
291   PyObject* orb = PyDict_GetItemString(pdict, "o");
292
293   // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
294
295   PyObject* iorSupport
296     = PyObject_CallMethod(orb, "object_to_string", "O", $input);
297  
298   if (iorSupport == Py_None)
299     return NULL;
300   char * s = PyString_AsString(PyObject_Str(iorSupport));
301  
302   // Ask omniORB to convert IOR string to SUPPORT (C++ Corba) ptr
303
304   int argc = 0;
305   char *xargv = "";
306   char **argv = &xargv;
307   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
308   CORBA::Object_var O =  ORB->string_to_object(s);
309   SCRUTE(O);
310   SALOME_MED::SUPPORT_ptr t = SALOME_MED::SUPPORT::_narrow(O);
311
312   $1 = t;
313   SCRUTE($1);
314 }
315
316 %typemap(python,in) const SALOME_MED::MESH_ptr, SALOME_MED::MESH_ptr
317 {
318
319   MESSAGE("typemap in sur Objet Corba MESH sans reference");
320
321   SCRUTE($input);
322
323   PyObject* pdict = PyDict_New();
324   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
325   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
326  
327   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
328                    pdict, pdict);
329  
330   PyObject* orb = PyDict_GetItemString(pdict, "o");
331
332   // Ask omniORBpy to transform MESH (python Corba) ptr to IOR string
333
334   PyObject* iorMesh
335     = PyObject_CallMethod(orb, "object_to_string", "O", $input);
336  
337   if (iorMesh == Py_None)
338     return NULL;
339   char * s = PyString_AsString(PyObject_Str(iorMesh));
340  
341   // Ask omniORB to convert IOR string to MESH (C++ Corba) ptr
342
343   int argc = 0;
344   char *xargv = "";
345   char **argv = &xargv;
346   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
347   CORBA::Object_var O =  ORB->string_to_object(s);
348   SCRUTE(O);
349   SALOME_MED::MESH_ptr t = SALOME_MED::MESH::_narrow(O);
350
351   $1 = t;
352   SCRUTE($1);
353 }
354
355 %typemap(python,in) const SALOME_MED::FIELDDOUBLE_ptr,
356                     SALOME_MED::FIELDDOUBLE_ptr &
357 {
358
359   MESSAGE("typemap in sur Objet Corba FIELDDOUBLE sans reference");
360
361   SCRUTE($input);
362
363   PyObject* pdict = PyDict_New();
364   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
365   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
366  
367   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
368                    pdict, pdict);
369  
370   PyObject* orb = PyDict_GetItemString(pdict, "o");
371
372   // Ask omniORBpy to transform FIELDDOUBLE (python Corba) ptr to IOR string
373
374   PyObject* iorFieldDouble
375     = PyObject_CallMethod(orb, "object_to_string", "O", $input);
376  
377   if (iorFieldDouble == Py_None)
378     return NULL;
379   char * s = PyString_AsString(PyObject_Str(iorFieldDouble));
380  
381   // Ask omniORB to convert IOR string to FIELDDOUBLE (C++ Corba) ptr
382
383   int argc = 0;
384   char *xargv = "";
385   char **argv = &xargv;
386   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
387   CORBA::Object_var O =  ORB->string_to_object(s);
388   SCRUTE(O);
389   SALOME_MED::FIELDDOUBLE_ptr t = SALOME_MED::FIELDDOUBLE::_narrow(O);
390
391   $1 = t;
392   SCRUTE($1);
393 }
394
395 %typemap(python,in) const SALOME_MED::FIELDINT_ptr,
396                     SALOME_MED::FIELDINT_ptr
397 {
398
399   MESSAGE("typemap in sur Objet Corba FIELDINT sans reference");
400
401   SCRUTE($input);
402
403   PyObject* pdict = PyDict_New();
404   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
405   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
406  
407   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
408                    pdict, pdict);
409  
410   PyObject* orb = PyDict_GetItemString(pdict, "o");
411
412   // Ask omniORBpy to transform FIELDINT (python Corba) ptr to IOR string
413
414   PyObject* iorFieldInt
415     = PyObject_CallMethod(orb, "object_to_string", "O", $input);
416  
417   if (iorFieldInt == Py_None)
418     return NULL;
419   char * s = PyString_AsString(PyObject_Str(iorFieldInt));
420  
421   // Ask omniORB to convert IOR string to FIELDINT (C++ Corba) ptr
422
423   int argc = 0;
424   char *xargv = "";
425   char **argv = &xargv;
426   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
427   CORBA::Object_var O =  ORB->string_to_object(s);
428   SCRUTE(O);
429   SALOME_MED::FIELDINT_ptr t = SALOME_MED::FIELDINT::_narrow(O);
430
431   $1 = t;
432   SCRUTE($1);
433 }
434
435 SALOME_MED::FIELDDOUBLE_ptr createCorbaFieldDouble(SALOME_MED::SUPPORT_ptr,
436                                                    FIELDDOUBLE *);
437
438 SALOME_MED::FIELDINT_ptr createCorbaFieldInt(SALOME_MED::SUPPORT_ptr,
439                                              FIELDINT *);
440
441 SALOME_MED::SUPPORT_ptr createCorbaSupport(const SUPPORT *);
442
443 FIELDDOUBLE * createLocalFieldDouble(const int, const int);
444
445 FIELDINT * createLocalFieldInt(const int, const int);
446
447 %{
448   SALOME_MED::FIELDDOUBLE_ptr createCorbaFieldDouble(SALOME_MED::SUPPORT_ptr mySupportIOR,FIELDDOUBLE * field)
449     {
450       BEGIN_OF("SALOME_MED::FIELDDOUBLE_ptr createCorbaFieldDouble from libMedCorba_Swig");
451
452       SCRUTE(mySupportIOR);
453
454       SCRUTE(field);
455
456       field->setName("Corba Double Field");
457
458       field->setDescription("Got From A Local One");
459
460       FIELDDOUBLE_i * fieldimpl = new FIELDDOUBLE_i(mySupportIOR,field);
461
462       POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i> * fieldcorba1 = 
463         new POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i>(fieldimpl,true);
464
465       SALOME_MED::FIELDDOUBLE_ptr fieldcorba2 = fieldcorba1->_this();
466
467       SALOME_MED::FIELDDOUBLE_ptr fieldcorba3 = SALOME_MED::FIELDDOUBLE::_duplicate(fieldcorba2);
468
469       fieldcorba1->_remove_ref();
470
471       SCRUTE(fieldimpl);
472
473       SCRUTE(fieldcorba1);
474
475       SCRUTE(fieldcorba2);
476
477       SCRUTE(fieldcorba3);
478
479       END_OF("SALOME_MED::FIELDDOUBLE_ptr createCorbaFieldDouble from libMedCorba_Swig");
480
481       MESSAGE("Test de tirarge sur le pointeur Corba Field dans le cxx");
482
483       char * name = fieldcorba3->getName();
484
485       SCRUTE(name);
486
487      return fieldcorba3;
488     }
489
490   SALOME_MED::FIELDINT_ptr createCorbaFieldInt(SALOME_MED::SUPPORT_ptr mySupportIOR,FIELDINT * field)
491     {
492       BEGIN_OF("SALOME_MED::FIELDINT_ptr createCorbaFieldInt from libMedCorba_Swig");
493
494       SCRUTE(mySupportIOR);
495
496       SCRUTE(field);
497
498       field->setName("Corba Integer Field");
499
500       field->setDescription("Got From A Local One");
501
502       FIELDINT_i * fieldimpl = new FIELDINT_i(mySupportIOR,field);
503
504       POA_SALOME_MED::FIELDINT_tie<FIELDINT_i> * fieldcorba1 = 
505         new POA_SALOME_MED::FIELDINT_tie<FIELDINT_i>(fieldimpl,true);
506
507       SALOME_MED::FIELDINT_ptr fieldcorba2 = fieldcorba1->_this();
508
509       SALOME_MED::FIELDINT_ptr fieldcorba3 = SALOME_MED::FIELDINT::_duplicate(fieldcorba2);
510
511       fieldcorba1->_remove_ref();
512
513       SCRUTE(fieldimpl);
514
515       SCRUTE(fieldcorba1);
516
517       SCRUTE(fieldcorba2);
518
519       SCRUTE(fieldcorba3);
520
521       END_OF("SALOME_MED::FIELDINT_ptr createCorbaFieldInt from libMedCorba_Swig");
522       MESSAGE("Test de tirarge sur le pointeur Corba Field dans le cxx");
523
524       char * name = fieldcorba3->getName();
525
526       SCRUTE(name);
527
528       return fieldcorba3;
529     }
530
531   SALOME_MED::SUPPORT_ptr createCorbaSupport(const SUPPORT * const support)
532     {
533       BEGIN_OF("SALOME_MED::SUPPORT_ptr createCorbaSupport from libMedCorba_Swig");
534
535       SCRUTE(support);
536
537       SUPPORT_i * supportimpl = new SUPPORT_i(support);
538
539       SALOME_MED::SUPPORT_ptr supportcorba =
540         supportimpl->POA_SALOME_MED::SUPPORT::_this();
541
542       SCRUTE(supportimpl);
543
544       SCRUTE(supportcorba);
545
546       supportimpl->_remove_ref();
547
548       END_OF("SALOME_MED::SUPPORT_ptr createCorbaSupport from libMedCorba_Swig");
549
550       return supportcorba;
551     }
552
553   FIELDDOUBLE * createLocalFieldDouble(const int NumberOfComponents,
554                                       const int LengthValue)
555     {
556       BEGIN_OF("FIELDDOUBLE createLocalFieldDouble from libMedCorba_Swig");
557
558       SCRUTE(NumberOfComponents);
559       SCRUTE(LengthValue);
560
561       //FIELD<double> * fieldloc =  new FIELD<double>();
562       FIELDDOUBLE * fieldloc =  new FIELDDOUBLE();
563       fieldloc -> allocValue(NumberOfComponents,LengthValue);
564
565       END_OF("FIELDDOUBLE createLocalFieldDouble from libMedCorba_Swig");
566
567       return fieldloc;
568     }
569
570   FIELDINT * createLocalFieldInt(const int NumberOfComponents,
571                                  const int LengthValue)
572     {
573       BEGIN_OF("FIELDINT createLocalFieldInt from libMedCorba_Swig");
574
575       SCRUTE(NumberOfComponents);
576       SCRUTE(LengthValue);
577
578       //FIELD<int> * fieldloc =  new FIELD<int>();
579       FIELDINT * fieldloc =  new FIELDINT();
580       fieldloc -> allocValue(NumberOfComponents,LengthValue);
581
582       END_OF("FIELDDOUBLE createLocalFieldInt from libMedCorba_Swig");
583
584       return fieldloc;
585     }
586 %}