1 // Copyright (C) 2007-2021 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, or (at your option) any later version.
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"
30 #include "SALOME_Comm_i.hxx"
31 #include "SALOMEMultiComm.hxx"
32 #include "SenderFactory.hxx"
36 %typemap(in) SALOME::SenderDouble_ptr
38 PyObject* pdict = PyDict_New();
39 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
40 PyRun_String("from omniORB import CORBA", Py_single_input, pdict, pdict);
42 PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
45 PyObject* orb = PyDict_GetItemString(pdict, "o");
47 // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
49 PyObject* iorSupport = PyObject_CallMethod(orb, (char*)"object_to_string", (char*)"O", $input);
51 if (iorSupport == Py_None)
53 char * s = PyString_AsString(PyObject_Str(iorSupport));
55 // Ask omniORB to convert IOR string to SALOME::SenderDouble_ptr
57 CORBA::ORB_var ORB = KERNEL::GetRefToORB();
58 CORBA::Object_var O = ORB->string_to_object(s);
59 SALOME::SenderDouble_ptr t = SALOME::SenderDouble::_narrow(O);
63 %typemap(in) SALOME::SenderInt_ptr
65 PyObject* pdict = PyDict_New();
66 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
67 PyRun_String("from omniORB import CORBA", Py_single_input, pdict, pdict);
69 PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
72 PyObject* orb = PyDict_GetItemString(pdict, "o");
74 // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
76 PyObject* iorSupport = PyObject_CallMethod(orb, (char*)"object_to_string", (char*)"O", $input);
78 if (iorSupport == Py_None)
80 char * s = PyString_AsString(PyObject_Str(iorSupport));
82 // Ask omniORB to convert IOR string to SALOME::SenderInt_ptr
84 CORBA::ORB_var ORB = KERNEL::GetRefToORB();
85 CORBA::Object_var O = ORB->string_to_object(s);
86 SALOME::SenderInt_ptr t = SALOME::SenderInt::_narrow(O);
90 %typemap(out) SALOME::SenderDouble_ptr
92 PyObject* pdict = PyDict_New();
93 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
94 PyRun_String("from omniORB import CORBA", Py_single_input, pdict, pdict);
95 PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
97 PyObject* orb = PyDict_GetItemString(pdict, "o");
98 // Get the orb Corba C++
99 CORBA::ORB_var ORB = KERNEL::GetRefToORB();
100 std::string s = ORB->object_to_string($1);
101 PyObject * tmp = PyString_FromString(s.c_str());
102 $result = PyObject_CallMethod(orb, (char*)"string_to_object", (char*)"O", tmp);
105 %typemap(out) SALOME::SenderInt_ptr
107 PyObject* pdict = PyDict_New();
108 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
109 PyRun_String("from omniORB import CORBA", Py_single_input, pdict, pdict);
110 PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
112 PyObject* orb = PyDict_GetItemString(pdict, "o");
113 // Get the orb Corba C++
114 CORBA::ORB_var ORB = KERNEL::GetRefToORB();
115 std::string s = ORB->object_to_string($1);
116 PyObject * tmp = PyString_FromString(s.c_str());
117 $result = PyObject_CallMethod(orb, (char*)"string_to_object", (char*)"O", tmp);
120 PyObject * getValueForSenderDouble(SALOME::SenderDouble_ptr senderDouble);
123 PyObject * getValueForSenderDouble(SALOME::SenderDouble_ptr senderDouble)
127 double *ret=ReceiverFactory::getValue(senderDouble,size);
128 py_list = PyList_New(size);
129 for (int i=0; i < size; i++)
131 int err = PyList_SetItem(py_list, i, Py_BuildValue("d", (double) ret[i]));
134 const char * message = "Error in SUPPORT::getTypes";
135 PyErr_SetString(PyExc_RuntimeError, message);
139 PyObject * result = Py_BuildValue("O", py_list);
147 PyObject * getValueForSenderInt(SALOME::SenderInt_ptr senderInt);
150 PyObject * getValueForSenderInt(SALOME::SenderInt_ptr senderInt)
154 int *ret=ReceiverFactory::getValue(senderInt,size);
155 py_list = PyList_New(size);
156 for (int i=0; i < size; i++)
158 int err = PyList_SetItem(py_list, i, Py_BuildValue("i", (int) ret[i]));
161 const char * message = "Error in SUPPORT::getTypes";
162 PyErr_SetString(PyExc_RuntimeError, message);
166 PyObject * result = Py_BuildValue("O", py_list);
173 PyObject * getValueForMatrix(SALOME::Matrix_ptr matrix);
175 PyObject * getValueForMatrix(SALOME::Matrix_ptr matrix)
179 double *ret=MatrixClient::getValue(matrix,column,row);
180 py_list = PyList_New(row);
181 for(int i=0;i<row;i++)
183 PyObject *tmpRow=PyList_New(column);
184 for(int j=0;j<column;j++)
186 int err = PyList_SetItem(tmpRow, j, Py_BuildValue("d", (double) ret[i*column+j]));
189 const char * message = "PyList_SetItem matrix sent may be invalid";
190 PyErr_SetString(PyExc_RuntimeError, message);
194 PyList_SetItem(py_list,i,tmpRow);
203 SALOME::SenderDouble_ptr buildSenderDoubleFromList(PyObject *pylist);
205 SALOME::SenderDouble_ptr buildSenderDoubleFromList(PyObject *pylist)
207 if (PyList_Check(pylist))
209 int listLgth = PyList_Size(pylist);
210 double *tab=new double[listLgth];
211 for (int i=0;i<listLgth;i++)
213 tab[i]=PyFloat_AsDouble(PyList_GetItem(pylist,i));
215 SALOMEMultiComm communicator;
216 return SenderFactory::buildSender(communicator,tab,listLgth,true);
220 PyErr_SetString(PyExc_TypeError,"not a list");
221 return SALOME::SenderDouble::_nil();
226 SALOME::SenderInt_ptr buildSenderIntFromList(PyObject *pylist);
228 SALOME::SenderInt_ptr buildSenderIntFromList(PyObject *pylist)
230 if (PyList_Check(pylist))
232 int listLgth = PyList_Size(pylist);
233 int *tab=new int[listLgth];
234 for (int i=0;i<listLgth;i++)
236 tab[i]=PyInt_AsLong(PyList_GetItem(pylist,i));
238 SALOMEMultiComm communicator;
239 return SenderFactory::buildSender(communicator,tab,listLgth,true);
243 PyErr_SetString(PyExc_TypeError,"not a list");
244 return SALOME::SenderInt::_nil();