Salome HOME
MEDMEM suppression
[modules/med.git] / src / MedCorba_Swig / libMedCorba_Swig.i
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 %module libMedCorba_Swig
24
25 %include "libMEDMEM_Swig.i"
26
27 %{
28 #include "MEDMEM_convert.hxx"
29 #include "MEDMEM_Family_i.hxx"
30 #include "MEDMEM_Field_i.hxx"
31 #include "MEDMEM_FieldTemplate_i.hxx"
32 #include "MEDMEM_Group_i.hxx"
33 #include "MEDMEM_Med_i.hxx"
34 #include "MEDMEM_GMesh_i.hxx"
35 #include "MEDMEM_Mesh_i.hxx"
36 #include "MEDMEM_Support_i.hxx"
37 #include "Med_Gen_i.hxx"
38
39   using namespace MEDMEM;
40   using namespace MED_EN;
41 %}
42
43 /*
44   typemap in, out and typecheck for Corba Objects (MESH, FIELDDOUBLE, FIELDINT and
45   Support) between C++ and Python
46
47   WARNING (NB) to the user of those typmaps (SWIG wrapping for C++ routines
48   -------------------------------------------------------------------------
49
50   You have to be quite careful about the SWIG version your are currently
51   using, because CORBA pointeur _ptr or _var could be wrapped by SWIG using
52   their reference rather than the pointeur itself (differences detected using
53   SWIG 1.1.x, SWIG 1.3.13 and SWIG 1.3.17)
54
55   typecheck always says OK, as currently all overloaded methods HERE differ
56   only in nb of parameters (there are default ones)
57 */
58
59 #if defined(SWIGPYTHON)
60 %typemap(out) SALOME_MED::GMESH_ptr, SALOME_MED::MESH_ptr, SALOME_MED::FIELDDOUBLE_ptr,
61    SALOME_MED::FIELDINT_ptr, SALOME_MED::SUPPORT_ptr,
62    const SALOME_MED::GMESH_ptr, const SALOME_MED::MESH_ptr, const SALOME_MED::FIELDDOUBLE_ptr,
63    const SALOME_MED::FIELDINT_ptr, const SALOME_MED::SUPPORT_ptr
64 {
65   MESSAGE("typemap out sur Objet Corba version ptr");
66
67   SCRUTE($1);
68
69   // Get the orb corba python
70
71   PyObject* pdict = PyDict_New();
72   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
73   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
74  
75   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
76                    pdict, pdict);
77  
78   PyObject* orb = PyDict_GetItemString(pdict, "o");
79
80   // Get the orb Corba C++
81
82   int argc = 0;
83   char *xargv = (char*)"";
84   char **argv = &xargv;
85   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
86
87   string s =  ORB->object_to_string($1);
88   SCRUTE(s);
89   PyObject * tmp = PyString_FromString(s.c_str());
90   SCRUTE(tmp);
91   PyObject * corbaObj = PyObject_CallMethod(orb, (char*)"string_to_object", (char*)"O", tmp);
92   $result = corbaObj;
93
94   // cast CORBA object, if necessary
95
96   // make target class name
97 //   string className = "$1_type";
98 //   className.replace( className.find(':'), 2, ".");
99 //   className.erase( className.find("_ptr"));
100
101 //   // get target class object
102 //   string getClassCmd = ( "cls = " + className );
103 //   PyRun_String("import SALOME_MED", Py_single_input, pdict, pdict);
104 //   PyRun_String(getClassCmd.c_str(), Py_single_input, pdict, pdict);
105 //   PyObject* cls = PyDict_GetItemString(pdict, "cls");
106
107 //   // cast
108 //   $result = PyObject_CallMethod(corbaObj, (char*)"_narrow", (char*)"O", cls);
109
110   SCRUTE($result);
111 }
112 #endif
113
114 #if defined(SWIGPYTHON)
115 %typemap(out) SALOME_MED::GMESH_var, SALOME_MED::MESH_var, SALOME_MED::FIELDDOUBLE_var,
116    SALOME_MED::FIELDINT_var, SALOME_MED::SUPPORT_var,
117    const SALOME_MED::GMESH_var, const SALOME_MED::MESH_var, const SALOME_MED::FIELDDOUBLE_var,
118    const SALOME_MED::FIELDINT_var, const SALOME_MED::SUPPORT_var
119 {
120   MESSAGE("typemap out sur Objet Corba version var");
121
122   // Get the orb corba python
123
124   PyObject* pdict = PyDict_New();
125   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
126   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
127  
128   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
129                    pdict, pdict);
130  
131   PyObject* orb = PyDict_GetItemString(pdict, "o");
132
133   // Get the orb Corba C++
134
135   int argc = 0;
136   char *xargv = (char*)"";
137   char **argv = &xargv;
138   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
139
140   string s =  ORB->object_to_string(*$1);
141   SCRUTE(s);
142   PyObject * tmp = PyString_FromString(s.c_str());
143   SCRUTE(tmp);
144   $result = PyObject_CallMethod(orb, (char*)"string_to_object", (char*)"O", tmp);
145   SCRUTE($result);
146 }
147 #endif
148
149 #if defined(SWIGPYTHON)
150 %typemap(typecheck) SALOME_MED::GMESH_ptr, SALOME_MED::MESH_ptr, SALOME_MED::FIELDDOUBLE_ptr,
151                     SALOME_MED::FIELDINT_ptr, SALOME_MED::SUPPORT_ptr,
152                     const SALOME_MED::MESH_ptr, const SALOME_MED::FIELDDOUBLE_ptr,
153                     const SALOME_MED::FIELDINT_ptr, const SALOME_MED::SUPPORT_ptr,
154                     SALOME_MED::GMESH_var, SALOME_MED::MESH_var, SALOME_MED::FIELDDOUBLE_var,
155                     SALOME_MED::FIELDINT_var, SALOME_MED::SUPPORT_var,
156                     const SALOME_MED::MESH_var, const SALOME_MED::FIELDDOUBLE_var,
157                     const SALOME_MED::FIELDINT_var, const SALOME_MED::SUPPORT_var
158 {
159   $1 = 1;
160 }
161 #endif
162
163 #if defined(SWIGPYTHON)
164 %typemap(in) const SALOME_MED::MESH_ptr &, SALOME_MED::MESH_ptr &
165 {
166
167   MESSAGE("typemap in sur Objet Corba MESH avec reference");
168
169   PyObject* pdict = PyDict_New();
170   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
171   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
172  
173   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
174                    pdict, pdict);
175  
176   PyObject* orb = PyDict_GetItemString(pdict, "o");
177
178   // Ask omniORBpy to transform MESH (python Corba) ptr to IOR string
179
180   PyObject* iorMesh
181     = PyObject_CallMethod(orb, (char*)"object_to_string", (char*)"O", $input);
182  
183   if (iorMesh == Py_None)
184     return NULL;
185   char * s = PyString_AsString(PyObject_Str(iorMesh));
186  
187   // Ask omniORB to convert IOR string to MESH (C++ Corba) ptr
188
189   int argc = 0;
190   char *xargv = (char*)"";
191   char **argv = &xargv;
192   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
193   CORBA::Object_var O =  ORB->string_to_object(s);
194   SCRUTE(O);
195   SALOME_MED::MESH_ptr t = SALOME_MED::MESH::_narrow(O);
196   SCRUTE(CORBA::is_nil(t));
197
198   $1 = &t;
199   SCRUTE(*$1);
200 }
201 #endif
202
203 #if defined(SWIGPYTHON)
204 %typemap(in) const SALOME_MED::FIELDDOUBLE_ptr &,
205                     SALOME_MED::FIELDDOUBLE_ptr &
206 {
207
208   MESSAGE("typemap in sur Objet Corba FIELDDOUBLE avec reference");
209
210   PyObject* pdict = PyDict_New();
211   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
212   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
213  
214   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
215                    pdict, pdict);
216  
217   PyObject* orb = PyDict_GetItemString(pdict, "o");
218
219   // Ask omniORBpy to transform FIELDDOUBLE (python Corba) ptr to IOR string
220
221   PyObject* iorFieldDouble
222     = PyObject_CallMethod(orb, (char*)"object_to_string", (char*)"O", $input);
223  
224   if (iorFieldDouble == Py_None)
225     return NULL;
226   char * s = PyString_AsString(PyObject_Str(iorFieldDouble));
227  
228   // Ask omniORB to convert IOR string to FIELDDOUBLE (C++ Corba) ptr
229
230   int argc = 0;
231   char *xargv = (char*)"";
232   char **argv = &xargv;
233   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
234   CORBA::Object_var O =  ORB->string_to_object(s);
235   SCRUTE(O);
236   SALOME_MED::FIELDDOUBLE_ptr t = SALOME_MED::FIELDDOUBLE::_narrow(O);
237   SCRUTE(CORBA::is_nil(t));
238
239   $1 = &t;
240   SCRUTE(*$1);
241 }
242 #endif
243
244 #if defined(SWIGPYTHON)
245 %typemap(in) const SALOME_MED::FIELDINT_ptr &,
246                     SALOME_MED::FIELDINT_ptr &
247 {
248
249   MESSAGE("typemap in sur Objet Corba FIELDINT avec reference");
250
251   PyObject* pdict = PyDict_New();
252   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
253   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
254  
255   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
256                    pdict, pdict);
257  
258   PyObject* orb = PyDict_GetItemString(pdict, "o");
259
260   // Ask omniORBpy to transform FIELDINT (python Corba) ptr to IOR string
261
262   PyObject* iorFieldInt
263     = PyObject_CallMethod(orb, (char*)"object_to_string", (char*)"O", $input);
264  
265   if (iorFieldInt == Py_None)
266     return NULL;
267   char * s = PyString_AsString(PyObject_Str(iorFieldInt));
268  
269   // Ask omniORB to convert IOR string to FIELDINT (C++ Corba) ptr
270
271   int argc = 0;
272   char *xargv = (char*)"";
273   char **argv = &xargv;
274   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
275   CORBA::Object_var O =  ORB->string_to_object(s);
276   SCRUTE(O);
277   SALOME_MED::FIELDINT_ptr t = SALOME_MED::FIELDINT::_narrow(O);
278   SCRUTE(CORBA::is_nil(t));
279
280   $1 = &t;
281   SCRUTE(*$1);
282 }
283 #endif
284
285 #if defined(SWIGPYTHON)
286 %typemap(in) const SALOME_MED::FIELDDOUBLE_ptr,
287                     SALOME_MED::FIELDDOUBLE_ptr
288 {
289
290   MESSAGE("typemap in sur Objet Corba FIELDDOUBLE sans reference");
291
292   PyObject* pdict = PyDict_New();
293   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
294   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
295  
296   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
297                    pdict, pdict);
298  
299   PyObject* orb = PyDict_GetItemString(pdict, "o");
300
301   // Ask omniORBpy to transform FIELDDOUBLE (python Corba) ptr to IOR string
302
303   PyObject* iorFieldDouble
304     = PyObject_CallMethod(orb, (char*)"object_to_string", (char*)"O", $input);
305  
306   if (iorFieldDouble == Py_None)
307     return NULL;
308   char * s = PyString_AsString(PyObject_Str(iorFieldDouble));
309  
310   // Ask omniORB to convert IOR string to FIELDDOUBLE (C++ Corba) ptr
311
312   int argc = 0;
313   char *xargv = (char*)"";
314   char **argv = &xargv;
315   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
316   CORBA::Object_var O =  ORB->string_to_object(s);
317   SCRUTE(O);
318   SALOME_MED::FIELDDOUBLE_ptr t = SALOME_MED::FIELDDOUBLE::_narrow(O);
319   SCRUTE(CORBA::is_nil(t));
320
321   $1 = t;
322   SCRUTE($1);
323 }
324 #endif
325
326 #if defined(SWIGPYTHON)
327 %typemap(in) const SALOME_MED::FIELDINT_ptr,
328                     SALOME_MED::FIELDINT_ptr
329 {
330
331   MESSAGE("typemap in sur Objet Corba FIELDINT sans reference");
332
333   PyObject* pdict = PyDict_New();
334   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
335   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
336  
337   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
338                    pdict, pdict);
339  
340   PyObject* orb = PyDict_GetItemString(pdict, "o");
341
342   // Ask omniORBpy to transform FIELDINT (python Corba) ptr to IOR string
343
344   PyObject* iorFieldInt
345     = PyObject_CallMethod(orb, (char*)"object_to_string", (char*)"O", $input);
346  
347   if (iorFieldInt == Py_None)
348     return NULL;
349   char * s = PyString_AsString(PyObject_Str(iorFieldInt));
350  
351   // Ask omniORB to convert IOR string to FIELDINT (C++ Corba) ptr
352
353   int argc = 0;
354   char *xargv = (char*)"";
355   char **argv = &xargv;
356   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
357   CORBA::Object_var O =  ORB->string_to_object(s);
358   SCRUTE(O);
359   SALOME_MED::FIELDINT_ptr t = SALOME_MED::FIELDINT::_narrow(O);
360   SCRUTE(CORBA::is_nil(t));
361
362   $1 = t;
363   SCRUTE($1);
364 }
365 #endif
366
367 #if defined(SWIGPYTHON)
368 %typemap(in) const SALOME_MED::SUPPORT_ptr &, SALOME_MED::SUPPORT_ptr &
369 {
370
371   MESSAGE("typemap in sur Objet Corba SUPPORT avec reference");
372
373   PyObject* pdict = PyDict_New();
374   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
375   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
376  
377   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
378                    pdict, pdict);
379  
380   PyObject* orb = PyDict_GetItemString(pdict, "o");
381
382   // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
383
384   PyObject* iorSupport
385     = PyObject_CallMethod(orb, (char*)"object_to_string", (char*)"O", $input);
386  
387   if (iorSupport == Py_None)
388     return NULL;
389   char * s = PyString_AsString(PyObject_Str(iorSupport));
390  
391   // Ask omniORB to convert IOR string to SUPPORT (C++ Corba) ptr
392
393   int argc = 0;
394   char *xargv = (char*)"";
395   char **argv = &xargv;
396   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
397   CORBA::Object_var O =  ORB->string_to_object(s);
398   SCRUTE(O);
399   SALOME_MED::SUPPORT_ptr t = SALOME_MED::SUPPORT::_narrow(O);
400   SCRUTE(CORBA::is_nil(t));
401
402   $1 = &t;
403   SCRUTE(*$1);
404 }
405 #endif
406
407 #if defined(SWIGPYTHON)
408 %typemap(in) const SALOME_MED::SUPPORT_ptr, SALOME_MED::SUPPORT_ptr
409 {
410
411   MESSAGE("typemap in sur Objet Corba SUPPORT sans reference");
412
413   SCRUTE($input);
414
415   PyObject* pdict = PyDict_New();
416   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
417   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
418  
419   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
420                    pdict, pdict);
421  
422   PyObject* orb = PyDict_GetItemString(pdict, "o");
423
424   // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
425
426   PyObject* iorSupport
427     = PyObject_CallMethod(orb, (char*)"object_to_string", (char*)"O", $input);
428  
429   if (iorSupport == Py_None)
430     return NULL;
431   char * s = PyString_AsString(PyObject_Str(iorSupport));
432  
433   // Ask omniORB to convert IOR string to SUPPORT (C++ Corba) ptr
434
435   int argc = 0;
436   char *xargv = (char*)"";
437   char **argv = &xargv;
438   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
439   CORBA::Object_var O =  ORB->string_to_object(s);
440   SCRUTE(O);
441   SALOME_MED::SUPPORT_ptr t = SALOME_MED::SUPPORT::_narrow(O);
442   SCRUTE(CORBA::is_nil(t));
443
444   $1 = t;
445   SCRUTE($1);
446 }
447 #endif
448
449 #if defined(SWIGPYTHON)
450 %typemap(in) const SALOME_MED::GMESH_ptr, SALOME_MED::GMESH_ptr
451 {
452
453   MESSAGE("typemap in sur Objet Corba MESH sans reference");
454
455   SCRUTE($input);
456
457   PyObject* pdict = PyDict_New();
458   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
459   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
460  
461   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
462                    pdict, pdict);
463  
464   PyObject* orb = PyDict_GetItemString(pdict, "o");
465
466   // Ask omniORBpy to transform MESH (python Corba) ptr to IOR string
467
468   PyObject* iorMesh
469     = PyObject_CallMethod(orb, (char*)"object_to_string", (char*)"O", $input);
470  
471   if (iorMesh == Py_None)
472     return NULL;
473   char * s = PyString_AsString(PyObject_Str(iorMesh));
474  
475   // Ask omniORB to convert IOR string to MESH (C++ Corba) ptr
476
477   int argc = 0;
478   char *xargv = (char*)"";
479   char **argv = &xargv;
480   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
481   CORBA::Object_var O =  ORB->string_to_object(s);
482   SCRUTE(O);
483   SALOME_MED::GMESH_ptr t = SALOME_MED::GMESH::_narrow(O);
484   SCRUTE(CORBA::is_nil(t));
485
486   $1 = t;
487   SCRUTE($1);
488 }
489 #endif
490
491 #if defined(SWIGPYTHON)
492 %typemap(in) const SALOME_MED::MESH_ptr, SALOME_MED::MESH_ptr
493 {
494
495   MESSAGE("typemap in sur Objet Corba MESH sans reference");
496
497   SCRUTE($input);
498
499   PyObject* pdict = PyDict_New();
500   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
501   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
502  
503   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
504                    pdict, pdict);
505  
506   PyObject* orb = PyDict_GetItemString(pdict, "o");
507
508   // Ask omniORBpy to transform MESH (python Corba) ptr to IOR string
509
510   PyObject* iorMesh
511     = PyObject_CallMethod(orb, (char*)"object_to_string", (char*)"O", $input);
512  
513   if (iorMesh == Py_None)
514     return NULL;
515   char * s = PyString_AsString(PyObject_Str(iorMesh));
516  
517   // Ask omniORB to convert IOR string to MESH (C++ Corba) ptr
518
519   int argc = 0;
520   char *xargv = (char*)"";
521   char **argv = &xargv;
522   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
523   CORBA::Object_var O =  ORB->string_to_object(s);
524   SCRUTE(O);
525   SALOME_MED::MESH_ptr t = SALOME_MED::MESH::_narrow(O);
526   SCRUTE(CORBA::is_nil(t));
527
528   $1 = t;
529   SCRUTE($1);
530 }
531 #endif
532
533 #if defined(SWIGPYTHON)
534 %typemap(in) const SALOME_MED::FIELDDOUBLE_ptr,
535                     SALOME_MED::FIELDDOUBLE_ptr &
536 {
537
538   MESSAGE("typemap in sur Objet Corba FIELDDOUBLE sans reference");
539
540   SCRUTE($input);
541
542   PyObject* pdict = PyDict_New();
543   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
544   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
545  
546   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
547                    pdict, pdict);
548  
549   PyObject* orb = PyDict_GetItemString(pdict, "o");
550
551   // Ask omniORBpy to transform FIELDDOUBLE (python Corba) ptr to IOR string
552
553   PyObject* iorFieldDouble
554     = PyObject_CallMethod(orb, (char*)"object_to_string", (char*)"O", $input);
555  
556   if (iorFieldDouble == Py_None)
557     return NULL;
558   char * s = PyString_AsString(PyObject_Str(iorFieldDouble));
559  
560   // Ask omniORB to convert IOR string to FIELDDOUBLE (C++ Corba) ptr
561
562   int argc = 0;
563   char *xargv = (char*)"";
564   char **argv = &xargv;
565   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
566   CORBA::Object_var O =  ORB->string_to_object(s);
567   SCRUTE(O);
568   SALOME_MED::FIELDDOUBLE_ptr t = SALOME_MED::FIELDDOUBLE::_narrow(O);
569   SCRUTE(CORBA::is_nil(t));
570
571   $1 = t;
572   SCRUTE($1);
573 }
574 #endif
575
576 #if defined(SWIGPYTHON)
577 %typemap(in) const SALOME_MED::FIELDINT_ptr,
578                     SALOME_MED::FIELDINT_ptr
579 {
580
581   MESSAGE("typemap in sur Objet Corba FIELDINT sans reference");
582
583   SCRUTE($input);
584
585   PyObject* pdict = PyDict_New();
586   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
587   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
588  
589   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
590                    pdict, pdict);
591  
592   PyObject* orb = PyDict_GetItemString(pdict, "o");
593
594   // Ask omniORBpy to transform FIELDINT (python Corba) ptr to IOR string
595
596   PyObject* iorFieldInt
597     = PyObject_CallMethod(orb, (char*)"object_to_string", (char*)"O", $input);
598  
599   if (iorFieldInt == Py_None)
600     return NULL;
601   char * s = PyString_AsString(PyObject_Str(iorFieldInt));
602  
603   // Ask omniORB to convert IOR string to FIELDINT (C++ Corba) ptr
604
605   int argc = 0;
606   char *xargv = (char*)"";
607   char **argv = &xargv;
608   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
609   CORBA::Object_var O =  ORB->string_to_object(s);
610   SCRUTE(O);
611   SALOME_MED::FIELDINT_ptr t = SALOME_MED::FIELDINT::_narrow(O);
612   SCRUTE(CORBA::is_nil(t));
613
614   $1 = t;
615   SCRUTE($1);
616 }
617 #endif
618
619
620 /*
621   managing C++ exception in the Python API
622 */
623 /*%exception
624 {
625   class PyAllowThreadsGuard {
626    public:
627     PyAllowThreadsGuard() { _save = PyEval_SaveThread(); }
628     ~PyAllowThreadsGuard() { PyEval_RestoreThread(_save); }
629    private:
630     PyThreadState *_save;
631   };
632
633   PyAllowThreadsGuard guard;
634
635   $action
636 }*/
637
638 SALOME_MED::FIELDDOUBLE_ptr createCorbaFieldDouble(SALOME_MED::SUPPORT_ptr,
639                                                    FIELDDOUBLE *,
640                                                    bool ownCppPtr=false);
641
642 SALOME_MED::FIELDINT_ptr createCorbaFieldInt(SALOME_MED::SUPPORT_ptr,
643                                              FIELDINT *,
644                                              bool ownCppPtr=false);
645
646 SALOME_MED::SUPPORT_ptr createCorbaSupport(const SUPPORT *);
647
648 FIELDDOUBLE * createLocalFieldDouble(const int, const int);
649
650 FIELDINT * createLocalFieldInt(const int, const int);
651
652 SALOME_MED::MESH_ptr createCorbaMesh(MESH * mesh);
653
654 %{
655   SALOME_MED::FIELDDOUBLE_ptr createCorbaFieldDouble(SALOME_MED::SUPPORT_ptr mySupportIOR,FIELDDOUBLE * field, bool ownCppPtr=false)
656     {
657       SCRUTE(field);
658
659       // MT : Keep the local field name
660       //      field->setName("Corba Double Field");
661
662       field->setDescription("Got From A Local One");
663
664       FIELDTEMPLATE_I<double,FullInterlace> *fieldimpl = new FIELDTEMPLATE_I<double,FullInterlace>(field, ownCppPtr);
665
666       SALOME_MED::FIELDDOUBLE_ptr fieldcorba2 = fieldimpl->_this();
667
668       SCRUTE(fieldimpl);
669
670       SCRUTE(fieldcorba2);
671
672       MESSAGE("Test de tirarge sur le pointeur Corba Field dans le cxx");
673
674       char * name = fieldcorba2->getName();
675
676       SCRUTE(name);
677
678       delete [] name;
679
680       // try to set support to field
681       ::MEDMEM::SUPPORT * sup = 0;
682       if ( SUPPORT_i * sup_i = Med_Gen_i::DownCast< SUPPORT_i * >( mySupportIOR ))
683       {
684         std::map < int,::MEDMEM::SUPPORT *>::iterator index_supp = 
685           SUPPORT_i::supportMap.find( sup_i->getCorbaIndex() );
686         if ( index_supp != SUPPORT_i::supportMap.end() )
687           sup = index_supp->second;
688       }
689       SCRUTE( sup );
690       if ( sup )
691         field->setSupport( sup );
692
693       return fieldcorba2;
694     }
695
696   SALOME_MED::FIELDINT_ptr createCorbaFieldInt(SALOME_MED::SUPPORT_ptr mySupportIOR,FIELDINT * field, bool ownCppPtr=false)
697     {
698       SCRUTE(field);
699
700       // MT : Keep the local field name
701       //    field->setName("Corba Integer Field");
702
703       field->setDescription("Got From A Local One");
704
705       FIELDTEMPLATE_I<int,FullInterlace> * fieldimpl = new FIELDTEMPLATE_I<int,FullInterlace>(field, ownCppPtr);
706
707       SALOME_MED::FIELDINT_ptr fieldcorba2 = fieldimpl->_this();
708
709       SCRUTE(fieldimpl);
710
711       SCRUTE(fieldcorba2);
712
713       MESSAGE("Test de tirarge sur le pointeur Corba Field dans le cxx");
714
715       char * name = fieldcorba2->getName();
716
717       SCRUTE(name);
718
719       delete [] name;
720
721       // try to set support to field
722       ::MEDMEM::SUPPORT * sup = 0;
723       if ( SUPPORT_i * sup_i = Med_Gen_i::DownCast< SUPPORT_i * >( mySupportIOR ))
724       {
725         std::map < int,::MEDMEM::SUPPORT *>::iterator index_supp = 
726           SUPPORT_i::supportMap.find( sup_i->getCorbaIndex() );
727         if ( index_supp != SUPPORT_i::supportMap.end() )
728           sup = index_supp->second;
729       }
730       SCRUTE( sup );
731       if ( sup )
732         field->setSupport( sup );
733
734       return fieldcorba2;
735     }
736
737   SALOME_MED::SUPPORT_ptr createCorbaSupport(const SUPPORT * const support)
738     {
739       SCRUTE(support);
740
741       SUPPORT_i * supportimpl = new SUPPORT_i(support);
742
743       SALOME_MED::SUPPORT_ptr supportcorba =
744         supportimpl->POA_SALOME_MED::SUPPORT::_this();
745
746       SCRUTE(supportimpl);
747
748       SCRUTE(supportcorba);
749
750       return supportcorba;
751     }
752
753   SALOME_MED::MESH_ptr createCorbaMesh(MESH * mesh)
754     {
755       SCRUTE(mesh);
756
757       MESH_i * meshimpl = new MESH_i(mesh);
758
759       SALOME_MED::MESH_ptr meshcorba =
760         meshimpl->POA_SALOME_MED::MESH::_this();
761
762       SCRUTE(meshimpl);
763
764       SCRUTE(meshcorba);
765
766       return meshcorba;
767     }
768
769   FIELDDOUBLE * createLocalFieldDouble(const int NumberOfComponents,
770                                       const int LengthValue)
771     {
772       SCRUTE(NumberOfComponents);
773       SCRUTE(LengthValue);
774
775       //FIELD<double> * fieldloc =  new FIELD<double>();
776       FIELDDOUBLE * fieldloc =  new FIELDDOUBLE();
777       fieldloc -> allocValue(NumberOfComponents,LengthValue);
778
779       return fieldloc;
780     }
781
782   FIELDINT * createLocalFieldInt(const int NumberOfComponents,
783                                  const int LengthValue)
784     {
785       SCRUTE(NumberOfComponents);
786       SCRUTE(LengthValue);
787
788       //FIELD<int> * fieldloc =  new FIELD<int>();
789       FIELDINT * fieldloc =  new FIELDINT();
790       fieldloc -> allocValue(NumberOfComponents,LengthValue);
791
792       return fieldloc;
793     }
794 %}