Salome HOME
SWP12966 - MutiFile is not saved correctly
[modules/kernel.git] / src / Communication / libSALOME_Comm.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/ or email : webmaster.salome@opencascade.com
19 //
20 %{
21   #include "ReceiverFactory.hxx"
22   #include "SALOME_Comm_i.hxx"
23 %}
24
25 %typemap(python,in) SALOME::SenderDouble_ptr
26 {
27   PyObject* pdict = PyDict_New();
28   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
29   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
30  
31   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
32                    pdict, pdict);
33  
34   PyObject* orb = PyDict_GetItemString(pdict, "o");
35
36   // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
37
38   PyObject* iorSupport = PyObject_CallMethod(orb, "object_to_string", "O", $input);
39  
40   if (iorSupport == Py_None)
41     return NULL;
42   char * s = PyString_AsString(PyObject_Str(iorSupport));
43  
44   // Ask omniORB to convert IOR string to SALOME::SenderDouble_ptr
45
46   int argc = 0;
47   char *xargv = "";
48   char **argv = &xargv;
49   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
50   CORBA::Object_var O =  ORB->string_to_object(s);
51   SALOME::SenderDouble_ptr t = SALOME::SenderDouble::_narrow(O);
52   $1 = t;
53 }
54
55 %typemap(python,in) SALOME::SenderInt_ptr
56 {
57   PyObject* pdict = PyDict_New();
58   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
59   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
60  
61   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
62                    pdict, pdict);
63  
64   PyObject* orb = PyDict_GetItemString(pdict, "o");
65
66   // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
67
68   PyObject* iorSupport = PyObject_CallMethod(orb, "object_to_string", "O", $input);
69  
70   if (iorSupport == Py_None)
71     return NULL;
72   char * s = PyString_AsString(PyObject_Str(iorSupport));
73  
74   // Ask omniORB to convert IOR string to SALOME::SenderInt_ptr
75
76   int argc = 0;
77   char *xargv = "";
78   char **argv = &xargv;
79   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
80   CORBA::Object_var O =  ORB->string_to_object(s);
81   SALOME::SenderInt_ptr t = SALOME::SenderInt::_narrow(O);
82   $1 = t;
83 }
84
85 PyObject * getValueForSenderDouble(SALOME::SenderDouble_ptr senderDouble);
86
87 %{
88 PyObject * getValueForSenderDouble(SALOME::SenderDouble_ptr senderDouble)
89 {
90   PyObject *py_list;
91   long size;
92   double *ret=ReceiverFactory::getValue(senderDouble,size);
93   py_list = PyList_New(size);
94   for (int i=0; i < size; i++)
95     {
96             int err = PyList_SetItem(py_list, i, Py_BuildValue("d", (double) ret[i]));
97             if(err)
98               {
99                 char * message = "Error in SUPPORT::getTypes";
100                 PyErr_SetString(PyExc_RuntimeError, message);
101                 return NULL;
102               }
103     }
104   PyObject * result = Py_BuildValue("O", py_list);
105   delete [] ret;
106   Py_DECREF(py_list);
107   return result;
108 }
109 %}
110
111
112 PyObject * getValueForSenderInt(SALOME::SenderInt_ptr senderInt);
113
114 %{
115 PyObject * getValueForSenderInt(SALOME::SenderInt_ptr senderInt)
116 {
117   PyObject *py_list;
118   long size;
119   int *ret=ReceiverFactory::getValue(senderInt,size);
120   py_list = PyList_New(size);
121   for (int i=0; i < size; i++)
122     {
123             int err = PyList_SetItem(py_list, i, Py_BuildValue("i", (int) ret[i]));
124             if(err)
125               {
126                 char * message = "Error in SUPPORT::getTypes";
127                 PyErr_SetString(PyExc_RuntimeError, message);
128                 return NULL;
129               }
130     }
131   PyObject * result = Py_BuildValue("O", py_list);
132   delete [] ret;
133   Py_DECREF(py_list);
134   return result;
135 }
136 %}