1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 %module libSALOME_Comm
25 %feature("autodoc", "1");
28 #include "ReceiverFactory.hxx"
29 #include "MatrixClient.hxx"
33 #include "SALOME_Comm_i.hxx"
34 #include "SALOMEMultiComm.hxx"
35 #include "SenderFactory.hxx"
38 %typemap(python,in) SALOME::SenderDouble_ptr
40 PyObject* pdict = PyDict_New();
41 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
42 PyRun_String("import CORBA", Py_single_input, pdict, pdict);
44 PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
47 PyObject* orb = PyDict_GetItemString(pdict, "o");
49 // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
51 PyObject* iorSupport = PyObject_CallMethod(orb, (char*)"object_to_string", (char*)"O", $input);
53 if (iorSupport == Py_None)
55 char * s = PyString_AsString(PyObject_Str(iorSupport));
57 // Ask omniORB to convert IOR string to SALOME::SenderDouble_ptr
60 char *xargv = (char*)"";
62 CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
63 CORBA::Object_var O = ORB->string_to_object(s);
64 SALOME::SenderDouble_ptr t = SALOME::SenderDouble::_narrow(O);
68 %typemap(python,in) SALOME::SenderInt_ptr
70 PyObject* pdict = PyDict_New();
71 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
72 PyRun_String("import CORBA", Py_single_input, pdict, pdict);
74 PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
77 PyObject* orb = PyDict_GetItemString(pdict, "o");
79 // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
81 PyObject* iorSupport = PyObject_CallMethod(orb, (char*)"object_to_string", (char*)"O", $input);
83 if (iorSupport == Py_None)
85 char * s = PyString_AsString(PyObject_Str(iorSupport));
87 // Ask omniORB to convert IOR string to SALOME::SenderInt_ptr
90 char *xargv = (char*)"";
92 CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
93 CORBA::Object_var O = ORB->string_to_object(s);
94 SALOME::SenderInt_ptr t = SALOME::SenderInt::_narrow(O);
98 %typemap(python,out) SALOME::SenderDouble_ptr
100 PyObject* pdict = PyDict_New();
101 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
102 PyRun_String("import CORBA", Py_single_input, pdict, pdict);
103 PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
105 PyObject* orb = PyDict_GetItemString(pdict, "o");
106 // Get the orb Corba C++
108 char *xargv = (char*)"";
109 char **argv = &xargv;
110 CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
111 std::string s = ORB->object_to_string($1);
112 PyObject * tmp = PyString_FromString(s.c_str());
113 $result = PyObject_CallMethod(orb, (char*)"string_to_object", (char*)"O", tmp);
116 %typemap(python,out) SALOME::SenderInt_ptr
118 PyObject* pdict = PyDict_New();
119 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
120 PyRun_String("import CORBA", Py_single_input, pdict, pdict);
121 PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
123 PyObject* orb = PyDict_GetItemString(pdict, "o");
124 // Get the orb Corba C++
126 char *xargv = (char*)"";
127 char **argv = &xargv;
128 CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
129 std::string s = ORB->object_to_string($1);
130 PyObject * tmp = PyString_FromString(s.c_str());
131 $result = PyObject_CallMethod(orb, (char*)"string_to_object", (char*)"O", tmp);
134 PyObject * getValueForSenderDouble(SALOME::SenderDouble_ptr senderDouble);
137 PyObject * getValueForSenderDouble(SALOME::SenderDouble_ptr senderDouble)
141 double *ret=ReceiverFactory::getValue(senderDouble,size);
142 py_list = PyList_New(size);
143 for (int i=0; i < size; i++)
145 int err = PyList_SetItem(py_list, i, Py_BuildValue("d", (double) ret[i]));
148 const char * message = "Error in SUPPORT::getTypes";
149 PyErr_SetString(PyExc_RuntimeError, message);
153 PyObject * result = Py_BuildValue("O", py_list);
161 PyObject * getValueForSenderInt(SALOME::SenderInt_ptr senderInt);
164 PyObject * getValueForSenderInt(SALOME::SenderInt_ptr senderInt)
168 int *ret=ReceiverFactory::getValue(senderInt,size);
169 py_list = PyList_New(size);
170 for (int i=0; i < size; i++)
172 int err = PyList_SetItem(py_list, i, Py_BuildValue("i", (int) ret[i]));
175 const char * message = "Error in SUPPORT::getTypes";
176 PyErr_SetString(PyExc_RuntimeError, message);
180 PyObject * result = Py_BuildValue("O", py_list);
187 PyObject * getValueForMatrix(SALOME::Matrix_ptr matrix);
189 PyObject * getValueForMatrix(SALOME::Matrix_ptr matrix)
193 double *ret=MatrixClient::getValue(matrix,column,row);
194 py_list = PyList_New(row);
195 for(int i=0;i<row;i++)
197 PyObject *tmpRow=PyList_New(column);
198 for(int j=0;j<column;j++)
200 int err = PyList_SetItem(tmpRow, j, Py_BuildValue("d", (double) ret[i*column+j]));
203 const char * message = "PyList_SetItem matrix sent may be invalid";
204 PyErr_SetString(PyExc_RuntimeError, message);
208 PyList_SetItem(py_list,i,tmpRow);
217 SALOME::SenderDouble_ptr buildSenderDoubleFromList(PyObject *pylist);
219 SALOME::SenderDouble_ptr buildSenderDoubleFromList(PyObject *pylist)
221 if (PyList_Check(pylist))
223 int listLgth = PyList_Size(pylist);
224 double *tab=new double[listLgth];
225 for (int i=0;i<listLgth;i++)
227 tab[i]=PyFloat_AsDouble(PyList_GetItem(pylist,i));
229 SALOMEMultiComm communicator;
230 return SenderFactory::buildSender(communicator,tab,listLgth,true);
234 PyErr_SetString(PyExc_TypeError,"not a list");
235 return SALOME::SenderDouble::_nil();
240 SALOME::SenderInt_ptr buildSenderIntFromList(PyObject *pylist);
242 SALOME::SenderInt_ptr buildSenderIntFromList(PyObject *pylist)
244 if (PyList_Check(pylist))
246 int listLgth = PyList_Size(pylist);
247 int *tab=new int[listLgth];
248 for (int i=0;i<listLgth;i++)
250 tab[i]=PyInt_AsLong(PyList_GetItem(pylist,i));
252 SALOMEMultiComm communicator;
253 return SenderFactory::buildSender(communicator,tab,listLgth,true);
257 PyErr_SetString(PyExc_TypeError,"not a list");
258 return SALOME::SenderInt::_nil();