]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime_swig/SALOMERuntime.i
Salome HOME
e8a5df23e42b5eb063181cb1792a45f06f238d8d
[modules/yacs.git] / src / runtime_swig / SALOMERuntime.i
1 // Copyright (C) 2006-2024  CEA, EDF
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, or (at your option) any later version.
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 "SalomeHPContainer.hxx"
48 #include "RuntimeSALOME.hxx"
49 #include "SALOMEDispatcher.hxx"
50 #include "SalomeProc.hxx"
51 #include "PythonNode.hxx"
52 #include "PythonPorts.hxx"
53 #include "PresetNode.hxx"
54 #include "PresetPorts.hxx"
55 #include "CORBANode.hxx"
56 #include "CORBAPorts.hxx"
57 #include "StudyNodes.hxx"
58 #include "StudyPorts.hxx"
59 #include "TypeConversions.hxx"
60 #include "TypeCode.hxx"
61 #include "VisitorSaveSalomeSchema.hxx"
62 #include "VisitorSalomeSaveState.hxx"
63 #include "SalomeOptimizerLoop.hxx"
64 #include "DistributedPythonNode.hxx"
65 #include "PyOptimizerAlg.hxx"
66 #include "PyStdout.hxx"
67 #include "ExecutorSwig.hxx"
68 #include <sstream>
69 #include "Catalog.hxx"
70 #include "ThreadLauncher.hxx"
71 %}
72
73 // ----------------------------------------------------------------------------
74
75 %init
76 %{
77   // init section
78
79   PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy");
80   if (!omnipy)
81   {
82     PyErr_SetString(PyExc_ImportError,(char*)"Cannot import _omnipy");
83     return NULL;
84   }
85   PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API");
86   api = (omniORBpyAPI*)PyCapsule_GetPointer(pyapi,"_omnipy.API");
87   Py_DECREF(pyapi);
88 %}
89
90 %{
91 static PyObject *convertContainer2(YACS::ENGINE::Container *cont, int owner=0)
92 {
93   if(!cont)
94     return SWIG_NewPointerObj((void*)cont,SWIGTYPE_p_YACS__ENGINE__Container, owner);
95   if(dynamic_cast<YACS::ENGINE::SalomeHPContainer *>(cont))
96     {
97       return SWIG_NewPointerObj((void*)dynamic_cast<YACS::ENGINE::SalomeHPContainer *>(cont),SWIGTYPE_p_YACS__ENGINE__SalomeHPContainer, owner);
98     }
99   if(dynamic_cast<YACS::ENGINE::SalomeContainer *>(cont))
100     {
101       return SWIG_NewPointerObj((void*)dynamic_cast<YACS::ENGINE::SalomeContainer *>(cont),SWIGTYPE_p_YACS__ENGINE__SalomeContainer, owner);
102     }
103   return SWIG_NewPointerObj((void*)cont,SWIGTYPE_p_YACS__ENGINE__Container, owner);
104 }
105 %}
106
107 %{
108 #include "Proc.hxx"
109
110 #include <thread>
111 #include <memory>
112 #include <string>
113 using namespace YACS::ENGINE;
114 class ThreadDumpState
115 {
116  public:
117    ThreadDumpState(Proc *proc, int nbSeconds, const std::string& dumpFile, const std::string& lockFile);
118    ~ThreadDumpState();
119    void start();
120    void join();
121 };
122 %}
123
124 // ----------------------------------------------------------------------------
125
126 #ifdef SWIGPYTHON
127 %typemap(out) YACS_ORB::Observer_ptr
128 {
129   $result = api->cxxObjRefToPyObjRef($1, 1);
130 }
131
132 %typemap(in) YACS_ORB::Observer_ptr
133 {
134   try
135   {
136      CORBA::Object_ptr obj = api->pyObjRefToCxxObjRef($input,1);
137      $1 = YACS_ORB::Observer::_narrow(obj);
138   }
139   catch (...)
140   {
141      PyErr_SetString(PyExc_RuntimeError, "not a valid CORBA object ptr");
142      return NULL;
143   }
144 }
145
146 %typemap(out) YACS::ENGINE::PyObj * "Py_INCREF($1); $result = $1;";
147
148 #endif
149
150 // ----------------------------------------------------------------------------
151
152 %import "pilot.i"
153
154 %rename(getSALOMERuntime) YACS::ENGINE::getSALOMERuntime; // to suppress a 503 warning
155 %ignore omniORBpyAPI;
156
157 %include <YACSRuntimeSALOMEExport.hxx>
158 %include "SalomeContainer.hxx"
159 %include "SalomeHPContainer.hxx"
160 %include "RuntimeSALOME.hxx"
161 %include "SALOMEDispatcher.hxx"
162 %include "SalomeProc.hxx"
163 %include "PythonNode.hxx"
164 %include "PythonPorts.hxx"
165 %include "XMLPorts.hxx"
166 %include "PresetNode.hxx"
167 %include "PresetPorts.hxx"
168 %include "CORBANode.hxx"
169 %include "CORBAPorts.hxx"
170 %include "StudyNodes.hxx"
171 %include "StudyPorts.hxx"
172 %include "SalomeOptimizerLoop.hxx"
173 %include "DistributedPythonNode.hxx"
174
175 namespace YACS
176 {
177   namespace ENGINE
178   {
179     void schemaSaveState(Proc* proc,
180                          Executor* exec,
181                          const std::string& xmlSchemaFile);
182     void schemaSaveStateUnsafe(Proc* proc, const std::string& xmlSchemaFile);
183     
184     void VisitorSaveSalomeSchemaUnsafe(Proc* proc, const std::string& xmlSchema);
185   }
186 }
187
188
189 %extend YACS::ENGINE::OutputPresetPort
190 {
191   void setDataPy(PyObject *ob)
192   {
193     std::string sss = convertPyObjectXml(self->edGetType(),ob);
194     self->setData(sss);
195   }
196 }
197
198
199 // Define the methods that can (default) or cannot (nodirector) be overloaded in Python
200 %feature("director") YACS::ENGINE::PyOptimizerAlgBase;
201 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::getTCForInProxy;
202 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::getTCForOutProxy;
203 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::initializeProxy;
204 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::startProxy;
205 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::takeDecisionProxy;
206 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::finishProxy;
207 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::hasError;
208 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::getError;
209 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::setError;
210 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::getTCForAlgoInitProxy;
211 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::getTCForAlgoResultProxy;
212 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::getAlgoResultProxy;
213 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgBase::setProc;
214
215 %feature("director") YACS::ENGINE::PyOptimizerAlgASync;
216 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::getTCForInProxy;
217 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::getTCForOutProxy;
218 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::initializeProxy;
219 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::startProxy;
220 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::takeDecisionProxy;
221 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::finishProxy;
222 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::hasError;
223 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::getError;
224 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::setError;
225 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::signalMasterAndWait;
226 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::signalSlaveAndWait;
227 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::start;
228 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::takeDecision;
229 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::run;
230 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::getTCForAlgoInitProxy;
231 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::getTCForAlgoResultProxy;
232 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::getAlgoResultProxy;
233 %feature("nodirector") YACS::ENGINE::PyOptimizerAlgASync::setProc;
234
235 %feature("director:except") {
236     if ($error != NULL) {
237         std::string errorMessage;
238         PyObject* new_stderr = YACS::ENGINE::newPyStdOut(errorMessage);
239         PySys_SetObject((char*)"stderr", new_stderr);
240         PyErr_Print();
241         PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
242         Py_DECREF(new_stderr);
243         throw YACS::Exception(errorMessage);
244     }
245 }
246
247 // Warning: as PyOptimizerAlgSync is only a typedef in PyOptimizerAlg.hxx, we have to
248 // directly rename PyOptimizerAlgBase in OptimizerAlgSync. If someday PyOptimizerAlgSync
249 // becomes a real derived class, this will have to be changed.
250 %rename(OptimizerAlgSync) YACS::ENGINE::PyOptimizerAlgBase;
251 %rename(OptimizerAlgASync) YACS::ENGINE::PyOptimizerAlgASync;
252
253 %include "PyOptimizerAlg.hxx"
254
255 %newobject YACS::ENGINE::RuntimeSALOME::createAnyPyObject;
256
257 %extend YACS::ENGINE::RuntimeSALOME
258 {
259   PyObject *createContainer(const std::string& kind="")
260   {
261     YACS::ENGINE::Container *ret(self->createContainer(kind));
262     return convertContainer2(ret,SWIG_POINTER_OWN | 0);
263   }
264
265   Any* createAnyPyObject(PyObject * pyobj)
266   {
267     return convertPyObjectNeutral(self->getBuiltinCatalog()->_typeMap["pyobj"],
268                                   pyobj);
269   }
270 }
271