Salome HOME
Merge from V6_main 01/04/2013
[modules/yacs.git] / src / runtime_swig / SALOMERuntime.i
1 // Copyright (C) 2006-2013  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // ----------------------------------------------------------------------------
21 //
22 %define SALOMEDOCSTRING
23 "Implementation of nodes for SALOME platform."
24 %enddef
25
26 %module(directors="1",docstring=SALOMEDOCSTRING) SALOMERuntime
27
28 //work around SWIG bug #1863647
29 #if SWIG_VERSION >= 0x010336
30 #define SwigPyIterator SALOMERuntime_PySwigIterator
31 #else
32 #define PySwigIterator SALOMERuntime_PySwigIterator
33 #endif
34
35 %feature("autodoc", "1");
36
37 %include engtypemaps.i
38
39 #ifdef DOXYGEN_IS_OK
40 %include docruntime.i
41 #endif
42
43 // ----------------------------------------------------------------------------
44
45 %{
46 #include "SalomeContainer.hxx"
47 #include "RuntimeSALOME.hxx"
48 #include "SALOMEDispatcher.hxx"
49 #include "SalomeProc.hxx"
50 #include "PythonNode.hxx"
51 #include "PythonPorts.hxx"
52 #include "PresetNode.hxx"
53 #include "PresetPorts.hxx"
54 #include "CORBANode.hxx"
55 #include "CORBAPorts.hxx"
56 #include "StudyNodes.hxx"
57 #include "StudyPorts.hxx"
58 #include "TypeConversions.hxx"
59 #include "TypeCode.hxx"
60 #include "VisitorSaveSalomeSchema.hxx"
61 #include "SalomeOptimizerLoop.hxx"
62 #include "DistributedPythonNode.hxx"
63 #include "PyOptimizerAlg.hxx"
64 #include "PyStdout.hxx"
65 #include <sstream>
66 %}
67
68 // ----------------------------------------------------------------------------
69
70 %init
71 %{
72   // init section
73
74   PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy");
75   if (!omnipy)
76   {
77     PyErr_SetString(PyExc_ImportError,(char*)"Cannot import _omnipy");
78     return;
79   }
80   PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API");
81   api = (omniORBPYAPI*)PyCObject_AsVoidPtr(pyapi);
82   Py_DECREF(pyapi);
83 %}
84
85 // ----------------------------------------------------------------------------
86
87 #ifdef SWIGPYTHON
88 %typemap(out) YACS_ORB::Observer_ptr
89 {
90   $result = api->cxxObjRefToPyObjRef($1, 1);
91 }
92
93 %typemap(in) YACS_ORB::Observer_ptr
94 {
95   try
96   {
97      CORBA::Object_ptr obj = api->pyObjRefToCxxObjRef($input,1);
98      $1 = YACS_ORB::Observer::_narrow(obj);
99   }
100   catch (...)
101   {
102      PyErr_SetString(PyExc_RuntimeError, "not a valid CORBA object ptr");
103      return NULL;
104   }
105 }
106
107 %typemap(out) YACS::ENGINE::PyObj * "Py_INCREF($1); $result = $1;";
108
109 #endif
110
111 // ----------------------------------------------------------------------------
112
113 %import "pilot.i"
114
115 %rename(getSALOMERuntime) YACS::ENGINE::getSALOMERuntime; // to suppress a 503 warning
116 %ignore omniORBpyAPI;
117
118 %include <YACSRuntimeSALOMEExport.hxx>
119 %include "SalomeContainer.hxx"
120 %include "RuntimeSALOME.hxx"
121 %include "SALOMEDispatcher.hxx"
122 %include "SalomeProc.hxx"
123 %include "PythonNode.hxx"
124 %include "PythonPorts.hxx"
125 %include "XMLPorts.hxx"
126 %include "PresetNode.hxx"
127 %include "PresetPorts.hxx"
128 %include "CORBANode.hxx"
129 %include "CORBAPorts.hxx"
130 %include "StudyNodes.hxx"
131 %include "StudyPorts.hxx"
132 %include "SalomeOptimizerLoop.hxx"
133 %include "DistributedPythonNode.hxx"
134
135 %extend YACS::ENGINE::OutputPresetPort
136 {
137   void setDataPy(PyObject *ob)
138   {
139     std::string sss = convertPyObjectXml(self->edGetType(),ob);
140     self->setData(sss);
141   }
142 }
143
144
145 // Define the methods that can (default) or cannot (nodirector) be overloaded in Python
146 %feature("director") YACS::ENGINE::PyOptimizerAlgBase;
147 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::getTCForInProxy;
148 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::getTCForOutProxy;
149 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::initializeProxy;
150 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::startProxy;
151 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::takeDecisionProxy;
152 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::finishProxy;
153 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::hasError;
154 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::getError;
155 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::setError;
156 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::getTCForAlgoInitProxy;
157 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::getTCForAlgoResultProxy;
158 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::getAlgoResultProxy;
159 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::setProc;
160
161 %feature("director") YACS::ENGINE::PyOptimizerAlgASync;
162 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::getTCForInProxy;
163 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::getTCForOutProxy;
164 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::initializeProxy;
165 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::startProxy;
166 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::takeDecisionProxy;
167 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::finishProxy;
168 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::hasError;
169 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::getError;
170 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::setError;
171 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::signalMasterAndWait;
172 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::signalSlaveAndWait;
173 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::start;
174 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::takeDecision;
175 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::run;
176 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::getTCForAlgoInitProxy;
177 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::getTCForAlgoResultProxy;
178 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::getAlgoResultProxy;
179 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::setProc;
180
181 %feature("director:except") {
182     if ($error != NULL) {
183         std::string errorMessage;
184         PyObject* new_stderr = YACS::ENGINE::newPyStdOut(errorMessage);
185         PySys_SetObject((char*)"stderr", new_stderr);
186         PyErr_Print();
187         PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
188         Py_DECREF(new_stderr);
189         throw YACS::Exception(errorMessage);
190     }
191 }
192
193 // Warning: as PyOptimizerAlgSync is only a typedef in PyOptimizerAlg.hxx, we have to
194 // directly rename PyOptimizerAlgBase in OptimizerAlgSync. If someday PyOptimizerAlgSync
195 // becomes a real derived class, this will have to be changed.
196 %rename(OptimizerAlgSync) YACS::ENGINE::PyOptimizerAlgBase;
197 %rename(OptimizerAlgASync) YACS::ENGINE::PyOptimizerAlgASync;
198 %include "PyOptimizerAlg.hxx"