Salome HOME
6b93d661450955965b697322b4437cb6a6e8333e
[modules/yacs.git] / src / engine_swig / pilot.i
1 // Copyright (C) 2006-2016  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, 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 %define DOCSTRING
21 "All is needed to create and execute a calculation schema."
22 %enddef
23
24 %module(docstring=DOCSTRING) pilot
25
26 #ifndef SWIGIMPORTED
27 //work around SWIG bug #1863647
28 #if SWIG_VERSION >= 0x010336
29 #define SwigPyIterator pilot_PySwigIterator
30 #else
31 #define PySwigIterator pilot_PySwigIterator
32 #endif
33 #endif
34
35 %feature("autodoc", "1");
36
37 %include "engtypemaps.i"
38
39 #ifdef DOXYGEN_IS_OK
40 %include docengine.i
41 #endif
42
43 %{
44 #include "Any.hxx"
45 #include "TypeCode.hxx"
46 #include "ComponentDefinition.hxx"
47 #include "Visitor.hxx"
48 #include "VisitorSaveSchema.hxx"
49 #include "VisitorSaveState.hxx"
50 #include "LinkInfo.hxx"
51 #include "Catalog.hxx"
52 #include "Executor.hxx"
53 #include "ExecutorSwig.hxx"
54 #include "Dispatcher.hxx"
55 #include "Container.hxx"
56 #include "HomogeneousPoolContainer.hxx"
57 #include "Logger.hxx"
58 #include "DeploymentTree.hxx"
59 #include "ComponentInstance.hxx"
60 #include "DataNode.hxx"
61
62 using namespace YACS::ENGINE;
63
64 %}
65
66 %init
67 %{
68   // init section
69 #ifdef OMNIORB
70   PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy");
71   if (!omnipy)
72   {
73     PyErr_SetString(PyExc_ImportError,(char*)"Cannot import _omnipy");
74     return;
75   }
76   PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API");
77   api = (omniORBPYAPI*)PyCObject_AsVoidPtr(pyapi);
78   Py_DECREF(pyapi);
79 #endif
80 %}
81
82 %ignore YACS::ENGINE::Any::operator[];
83 %ignore YACS::ENGINE::TypeCode::operator=;
84 %ignore YACS::ENGINE::DeploymentTree::operator=;
85 %ignore operator<<;
86 %ignore YACS::ENGINE::Runtime::_tc_double;
87 %ignore YACS::ENGINE::Runtime::_tc_int;
88 %ignore YACS::ENGINE::Runtime::_tc_bool;
89 %ignore YACS::ENGINE::Runtime::_tc_string;
90 %ignore YACS::ENGINE::Runtime::_tc_file;
91 %rename(StateLoader) YACS::ENGINE::StateLoader; // to suppress a 503 warning
92 %rename(NbDoneLoader) YACS::ENGINE::NbDoneLoader; // to suppress a 503 warning
93 %rename(getRuntime) YACS::ENGINE::getRuntime; // to suppress a 503 warning
94 %rename(_from) YACS::ENGINE::DataLinkInfo::from ; // to suppress a 314 warning
95 %rename(_from) YACS::ENGINE::StreamLinkInfo::from ; // to suppress a 314 warning
96
97 /*
98  * Template section
99  */
100 %template()              std::pair<std::string, YACS::ENGINE::TypeCode *>;
101 %template()              std::pair<std::string, YACS::ENGINE::Node *>;
102 %template()              std::pair<std::string, YACS::ENGINE::InlineNode *>;
103 %template()              std::pair<std::string, YACS::ENGINE::ServiceNode *>;
104 %template()              std::pair<std::string, YACS::ENGINE::Container *>;
105 %template()              std::pair<YACS::ENGINE::OutPort *,YACS::ENGINE::InPort *>;
106 %template()              std::pair<YACS::ENGINE::InPort *,YACS::ENGINE::OutPort *>;
107 //%template(TCmap)         std::map<std::string, YACS::ENGINE::TypeCode *>;
108 REFCOUNT_TEMPLATE(TCmap,YACS::ENGINE::TypeCode)
109 %template(NODEmap)       std::map<std::string, YACS::ENGINE::Node *>;
110 %template(INODEmap)      std::map<std::string, YACS::ENGINE::InlineNode *>;
111 %template(SNODEmap)      std::map<std::string, YACS::ENGINE::ServiceNode *>;
112 //%template(CONTAINmap)    std::map<std::string, YACS::ENGINE::Container *>;
113 REFCOUNT_TEMPLATE(CONTAINmap,YACS::ENGINE::Container)
114 %template(strvec)        std::vector<std::string>;
115 %template(uivec)         std::vector<unsigned int>;
116 %template(linksvec)      std::vector< std::pair<YACS::ENGINE::OutPort *,YACS::ENGINE::InPort *> >;
117 %template(linkvec)       std::vector< std::pair<YACS::ENGINE::InPort *,YACS::ENGINE::OutPort *> >;
118 %template(instreamlist)  std::list<YACS::ENGINE::InputDataStreamPort *>;
119 %template(outstreamlist) std::list<YACS::ENGINE::OutputDataStreamPort *>;
120
121 %template()              std::pair<std::string, YACS::ENGINE::CatalogLoader *>;
122 %template(loadermap)     std::map<std::string,YACS::ENGINE::CatalogLoader *>;
123 %template()              std::pair<std::string, YACS::ENGINE::ComposedNode *>;
124 %template(composedmap)   std::map<std::string,YACS::ENGINE::ComposedNode *>;
125 %template()              std::pair<std::string, YACS::ENGINE::ComponentDefinition *>;
126 %template(compomap)      std::map<std::string, YACS::ENGINE::ComponentDefinition *>;
127 %template()              std::pair<std::string, std::string>;
128 %template(propmap)       std::map<std::string, std::string>;
129
130 REFCOUNT_TEMPLATE(CompoInstmap,YACS::ENGINE::ComponentInstance)
131
132 /*
133  * End of Template section
134  */
135
136 %typemap(out) Container *
137 {
138   $result=convertContainer($1,$owner);
139 }
140
141 %typemap(out) YACS::ENGINE::Container *
142 {
143   $result=convertContainer($1,$owner);
144 }
145
146 /*
147  * Ownership section
148  */
149 //Take ownership : it is not the default (constructor) as it is a factory
150 %newobject *::createProc;
151 %newobject *::createScriptNode;
152 %newobject *::createFuncNode;
153 %newobject *::createRefNode;
154 %newobject *::createCompoNode;
155 %newobject *::createSInlineNode;
156 %newobject *::createInDataNode;
157 %newobject *::createOutDataNode;
158 %newobject *::createBloc;
159 %newobject *::createForLoop;
160 %newobject *::createForEachLoop;
161 %newobject *::createWhileLoop;
162 %newobject *::createSwitch;
163 %newobject *::loadCatalog;
164 %newobject *::createComponentInstance;
165 %newobject *::createContainer;
166
167
168 %newobject *::createInputPort;
169 %newobject *::createOutputPort;
170 %newobject *::createInputDataStreamPort;
171 %newobject *::createOutputDataStreamPort;
172 %newobject *::clone;
173 %newobject *::cloneAlways;
174 %newobject *::cloneWithoutCompAndContDeepCpy;
175 %newobject *::New;
176
177 //Take ownership : transfer it from C++ (has to be completed)
178 %newobject YACS::ENGINE::Loop::edRemoveNode;
179 %newobject YACS::ENGINE::Switch::edReleaseDefaultNode;
180 %newobject YACS::ENGINE::Switch::edReleaseCase;
181 %newobject YACS::ENGINE::DynParaLoop::edRemoveNode;
182 %newobject YACS::ENGINE::DynParaLoop::edRemoveInitNode;
183 //No other way to do ??
184 %feature("pythonappend") YACS::ENGINE::Bloc::edRemoveChild(Node *node)%{
185         args[1].thisown=1
186 %}
187
188 %newobject *::createSequenceTc;
189 %newobject *::createInterfaceTc;
190 %newobject *::createStructTc;
191 %newobject *::createType;
192
193 %newobject YACS::ENGINE::SequenceAny::removeUnsetItemsFromThis;
194
195 %newobject YACS::ENGINE::TypeCode::interfaceTc;
196 %newobject YACS::ENGINE::TypeCode::sequenceTc;
197 %newobject YACS::ENGINE::TypeCode::structTc;
198
199 /*
200  * End of ownership section
201  */
202
203
204 %include <define.hxx>
205 %include <YACSBasesExport.hxx>
206 %include <Exception.hxx>
207 %include <YACSlibEngineExport.hxx>
208 %include <ConversionException.hxx>
209 %include <Runtime.hxx>
210 %include <PropertyInterface.hxx>
211
212 PYEXCEPTION(YACS::ENGINE::Executor::RunW)
213 PYEXCEPTION(YACS::ENGINE::Executor::RunB)
214 PYEXCEPTION(YACS::ENGINE::Executor::setExecMode)
215 PYEXCEPTION(YACS::ENGINE::Executor::resumeCurrentBreakPoint)
216 PYEXCEPTION(YACS::ENGINE::Executor::stopExecution)
217 PYEXCEPTION(YACS::ENGINE::Executor::waitPause)
218 PYEXCEPTION(YACS::ENGINE::ComponentInstance::load)
219
220 %include <Executor.hxx>
221
222 EXCEPTION(YACS::ENGINE::ExecutorSwig::RunPy)
223 EXCEPTION(YACS::ENGINE::ExecutorSwig::waitPause)
224 %include <ExecutorSwig.hxx>
225
226 %include <RefCounter.hxx>
227
228 %include <Any.hxx>
229
230 %ignore YACS::ENGINE::TypeCode::getOrBuildAnyFromZippedData;
231 %include <TypeCode.hxx>
232
233 %include <Scheduler.hxx>
234 %include <Task.hxx>
235 %include <Dispatcher.hxx>
236 %include <DeploymentTree.hxx>
237 %include <Port.hxx>
238 %extend YACS::ENGINE::Port
239 {
240   int __cmp__(Port* other)
241     {
242       if(self==other)
243         return 0;
244       else 
245         return 1;
246     }
247   long ptr()
248     {
249       return (long)self;
250     }
251 }
252 %include <DataPort.hxx>
253 %include <InPort.hxx>
254 %include <OutPort.hxx>
255 %include <InGate.hxx>
256 %include <OutGate.hxx>
257 %include <DataFlowPort.hxx>
258 %include <DataStreamPort.hxx>
259
260 %include <LinkInfo.hxx>
261 %include <Logger.hxx>
262
263 %include <ComponentInstance.hxx>
264 %include <Container.hxx>
265 %include <HomogeneousPoolContainer.hxx>
266 %include <InputPort.hxx>
267 %extend YACS::ENGINE::InputPort
268 {
269   void edInitXML(const char * s)
270     {
271       self->edInit("XML",s);
272     }
273   void edInitPy(PyObject* ob)
274     {
275       self->edInit("Python",ob);
276     }
277 }
278 %include <InPropertyPort.hxx>
279 %extend YACS::ENGINE::InPropertyPort
280 {
281   void edInitXML(const char * s)
282     {
283       self->edInit("XML",s);
284     }
285   void edInitPy(PyObject* ob)
286     {
287       self->edInit("Python",ob);
288     }
289 }
290
291 %template(edInitInt)       YACS::ENGINE::InputPort::edInit<int>;
292 %template(edInitBool)      YACS::ENGINE::InputPort::edInit<bool>;
293 %template(edInitString)    YACS::ENGINE::InputPort::edInit<std::string>;
294 %template(edInitDbl)       YACS::ENGINE::InputPort::edInit<double>;
295
296 %include <AnyInputPort.hxx>
297 %include <ConditionInputPort.hxx>
298 %include <OutputPort.hxx>
299 %include <AnyOutputPort.hxx>
300 %include <InputDataStreamPort.hxx>
301 %include <OutputDataStreamPort.hxx>
302 %include <DataPort.hxx>
303
304 %include <Node.hxx>
305 %extend YACS::ENGINE::Node 
306 {
307   int __cmp__(Node* other)
308     {
309       if(self==other)
310         return 0;
311       else 
312         return 1;
313     }
314   long ptr()
315     {
316           return (long)self;
317     }
318 }
319
320 %include <ElementaryNode.hxx>
321 %include <InlineNode.hxx>
322 %include <ServiceNode.hxx>
323 %include <ServiceInlineNode.hxx>
324 %include <ServerNode.hxx>
325 %include <DataNode.hxx>
326
327 %include <ComposedNode.hxx>
328 %include <StaticDefinedComposedNode.hxx>
329 %include <Bloc.hxx>
330 %include <Proc.hxx>
331
332 %include <Loop.hxx>
333 %include <ForLoop.hxx>
334 %include <DynParaLoop.hxx>
335 %include <WhileLoop.hxx>
336 %include <ForEachLoop.hxx>
337 %include <OptimizerLoop.hxx>
338 %include <Switch.hxx>
339 %include <Visitor.hxx>
340 %include <VisitorSaveSchema.hxx>
341 %include <ComponentDefinition.hxx>
342 %include <Catalog.hxx>
343 %include <Pool.hxx>
344
345 %include <AlternateThread.hxx>
346 %include <AlternateThreadPT.hxx>
347
348 // Ignore class OptimizerAlgASync to avoid confusion with class
349 // OptimizerAlgASync in module SALOMERuntime
350 %ignore YACS::ENGINE::OptimizerAlgASync;
351 %include <OptimizerAlg.hxx>
352
353 %extend YACS::ENGINE::ConditionInputPort
354 {
355   bool getPyObj()
356   {
357     return self->getValue();
358   }
359 }
360
361 %extend YACS::ENGINE::AnyInputPort
362 {
363   PyObject * getPyObj()
364   {
365     return (PyObject *)getRuntime()->convertNeutral(self->edGetType(),self->getValue());
366   }
367 }
368
369 %extend YACS::ENGINE::AnyOutputPort
370 {
371   PyObject * getPyObj()
372   {
373     return (PyObject *)getRuntime()->convertNeutral(self->edGetType(),self->getValue());
374   }
375 }
376
377 %extend YACS::ENGINE::Any
378 {
379   PyObject *getPyObj()
380   {
381     return (PyObject *)getRuntime()->convertNeutral(const_cast<YACS::ENGINE::TypeCode *>(self->getType()),self);
382   }
383 }
384
385 %newobject YACS::ENGINE::SequenceAny::__getitem__;
386 %extend YACS::ENGINE::SequenceAny
387 {
388   Any* __getitem__(int i)
389   {
390     if (i < self->size())
391       {
392         AnyPtr a=(*self)[i];
393         a->incrRef();
394         return a;
395       }
396     else
397       throw std::length_error("index too large");
398   }
399 }
400
401 %newobject YACS::ENGINE::StructAny::__getitem__;
402 %extend YACS::ENGINE::StructAny
403 {
404   Any* __getitem__(const char * key)
405   {
406     AnyPtr a=(*self)[key];
407     a->incrRef();
408     return a;
409   }
410 }
411
412 %extend YACS::ENGINE::ForEachLoop
413 {
414   PyObject *getPassedResults(Executor *execut) const
415   {
416     std::vector<SequenceAny *> ret1;
417     std::vector<std::string> ret2;
418     std::vector<unsigned int> ret0(self->getPassedResults(execut,ret1,ret2));
419     PyObject *ret(PyTuple_New(3));
420     // param 0
421     PyObject *ret0Py(PyList_New(ret0.size()));
422     for(std::size_t i=0;i<ret0.size();i++)
423       PyList_SetItem(ret0Py,i,PyInt_FromLong(ret0[i]));
424     PyTuple_SetItem(ret,0,ret0Py);
425     // param 1
426     PyObject *ret1Py(PyList_New(ret1.size()));
427     for(std::size_t i=0;i<ret1.size();i++)
428       PyList_SetItem(ret1Py,i,SWIG_NewPointerObj(SWIG_as_voidptr(ret1[i]),SWIGTYPE_p_YACS__ENGINE__SequenceAny, SWIG_POINTER_OWN | 0 ));
429     PyTuple_SetItem(ret,1,ret1Py);
430     // param 2
431     PyObject *ret2Py(PyList_New(ret2.size()));
432     for(std::size_t i=0;i<ret2.size();i++)
433       PyList_SetItem(ret2Py,i,PyString_FromString(ret2[i].c_str()));
434     PyTuple_SetItem(ret,2,ret2Py);
435     return ret;
436   }
437
438   void assignPassedResults(const std::vector<unsigned int>& passedIds, PyObject *passedOutputs, const std::vector<std::string>& nameOfOutputs)
439   {
440     std::vector<SequenceAny *> passedOutputsCpp;
441     convertFromPyObjVectorOfObj<YACS::ENGINE::SequenceAny *>(passedOutputs,SWIGTYPE_p_YACS__ENGINE__SequenceAny,"SequenceAny",passedOutputsCpp);
442     self->assignPassedResults(passedIds,passedOutputsCpp,nameOfOutputs);
443   }
444 }