Salome HOME
Merge Python 3 porting.
[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 #include "PlayGround.hxx"
62   
63 using namespace YACS::ENGINE;
64
65 %}
66
67 %init
68 %{
69   // init section
70 #ifdef OMNIORB
71   PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy");
72   if (!omnipy)
73   {
74     PyErr_SetString(PyExc_ImportError,(char*)"Cannot import _omnipy");
75     return NULL;
76   }
77   PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API");
78   api = (omniORBpyAPI*)PyCapsule_GetPointer(pyapi,"_omnipy.API");
79   Py_DECREF(pyapi);
80 #endif
81 %}
82
83 %ignore YACS::ENGINE::Any::operator[];
84 %ignore YACS::ENGINE::TypeCode::operator=;
85 %ignore YACS::ENGINE::DeploymentTree::operator=;
86 %ignore operator<<;
87 %ignore YACS::ENGINE::Runtime::_tc_double;
88 %ignore YACS::ENGINE::Runtime::_tc_int;
89 %ignore YACS::ENGINE::Runtime::_tc_bool;
90 %ignore YACS::ENGINE::Runtime::_tc_string;
91 %ignore YACS::ENGINE::Runtime::_tc_file;
92 %rename(StateLoader) YACS::ENGINE::StateLoader; // to suppress a 503 warning
93 %rename(NbDoneLoader) YACS::ENGINE::NbDoneLoader; // to suppress a 503 warning
94 %rename(getRuntime) YACS::ENGINE::getRuntime; // to suppress a 503 warning
95 %rename(_from) YACS::ENGINE::DataLinkInfo::from ; // to suppress a 314 warning
96 %rename(_from) YACS::ENGINE::StreamLinkInfo::from ; // to suppress a 314 warning
97
98 /*
99  * Template section
100  */
101 %template()              std::pair<std::string, YACS::ENGINE::TypeCode *>;
102 %template()              std::pair<std::string, YACS::ENGINE::Node *>;
103 %template()              std::pair<std::string, YACS::ENGINE::InlineNode *>;
104 %template()              std::pair<std::string, YACS::ENGINE::ServiceNode *>;
105 %template()              std::pair<std::string, YACS::ENGINE::Container *>;
106 %template()              std::pair<YACS::ENGINE::OutPort *,YACS::ENGINE::InPort *>;
107 %template()              std::pair<YACS::ENGINE::InPort *,YACS::ENGINE::OutPort *>;
108 %template()              std::pair< std::string, int >;
109 //%template(TCmap)         std::map<std::string, YACS::ENGINE::TypeCode *>;
110 REFCOUNT_TEMPLATE(TCmap,YACS::ENGINE::TypeCode)
111 %template(NODEmap)       std::map<std::string, YACS::ENGINE::Node *>;
112 %template(INODEmap)      std::map<std::string, YACS::ENGINE::InlineNode *>;
113 %template(SNODEmap)      std::map<std::string, YACS::ENGINE::ServiceNode *>;
114 //%template(CONTAINmap)    std::map<std::string, YACS::ENGINE::Container *>;
115 REFCOUNT_TEMPLATE(CONTAINmap,YACS::ENGINE::Container)
116 %template(strvec)        std::vector<std::string>;
117 %template(uivec)         std::vector<unsigned int>;
118 %template(ivec)          std::vector<int>;
119 %template(linksvec)      std::vector< std::pair<YACS::ENGINE::OutPort *,YACS::ENGINE::InPort *> >;
120 %template(linkvec)       std::vector< std::pair<YACS::ENGINE::InPort *,YACS::ENGINE::OutPort *> >;
121 %template(instreamlist)  std::list<YACS::ENGINE::InputDataStreamPort *>;
122 %template(outstreamlist) std::list<YACS::ENGINE::OutputDataStreamPort *>;
123 %template(vpsi)          std::vector< std::pair< std::string, int > >;
124           
125 %template()              std::pair<std::string, YACS::ENGINE::CatalogLoader *>;
126 %template(loadermap)     std::map<std::string,YACS::ENGINE::CatalogLoader *>;
127 %template()              std::pair<std::string, YACS::ENGINE::ComposedNode *>;
128 %template(composedmap)   std::map<std::string,YACS::ENGINE::ComposedNode *>;
129 %template()              std::pair<std::string, YACS::ENGINE::ComponentDefinition *>;
130 %template(compomap)      std::map<std::string, YACS::ENGINE::ComponentDefinition *>;
131 %template()              std::pair<std::string, std::string>;
132 %template(propmap)       std::map<std::string, std::string>;
133
134 REFCOUNT_TEMPLATE(CompoInstmap,YACS::ENGINE::ComponentInstance)
135
136 /*
137  * End of Template section
138  */
139
140 %typemap(out) Container *
141 {
142   $result=convertContainer($1,$owner);
143 }
144
145 %typemap(out) YACS::ENGINE::Container *
146 {
147   $result=convertContainer($1,$owner);
148 }
149
150 /*
151  * Ownership section
152  */
153 //Take ownership : it is not the default (constructor) as it is a factory
154 %newobject *::createProc;
155 %newobject *::createScriptNode;
156 %newobject *::createFuncNode;
157 %newobject *::createRefNode;
158 %newobject *::createCompoNode;
159 %newobject *::createSInlineNode;
160 %newobject *::createInDataNode;
161 %newobject *::createOutDataNode;
162 %newobject *::createBloc;
163 %newobject *::createForLoop;
164 %newobject *::createForEachLoop;
165 %newobject *::createWhileLoop;
166 %newobject *::createSwitch;
167 %newobject *::loadCatalog;
168 %newobject *::createComponentInstance;
169 %newobject *::createContainer;
170
171
172 %newobject *::createInputPort;
173 %newobject *::createOutputPort;
174 %newobject *::createInputDataStreamPort;
175 %newobject *::createOutputDataStreamPort;
176 %newobject *::clone;
177 %newobject *::cloneAlways;
178 %newobject *::cloneWithoutCompAndContDeepCpy;
179 %newobject *::New;
180
181 //Take ownership : transfer it from C++ (has to be completed)
182 %newobject YACS::ENGINE::Loop::edRemoveNode;
183 %newobject YACS::ENGINE::Switch::edReleaseDefaultNode;
184 %newobject YACS::ENGINE::Switch::edReleaseCase;
185 %newobject YACS::ENGINE::DynParaLoop::edRemoveNode;
186 %newobject YACS::ENGINE::DynParaLoop::edRemoveInitNode;
187 //No other way to do ??
188 %feature("pythonappend") YACS::ENGINE::Bloc::edRemoveChild(Node *node)%{
189         args[1].thisown=1
190 %}
191
192 %newobject *::createSequenceTc;
193 %newobject *::createInterfaceTc;
194 %newobject *::createStructTc;
195 %newobject *::createType;
196
197 %newobject YACS::ENGINE::SequenceAny::removeUnsetItemsFromThis;
198
199 %newobject YACS::ENGINE::TypeCode::interfaceTc;
200 %newobject YACS::ENGINE::TypeCode::sequenceTc;
201 %newobject YACS::ENGINE::TypeCode::structTc;
202
203 /*
204  * End of ownership section
205  */
206
207
208 %include <define.hxx>
209 %include <YACSBasesExport.hxx>
210 %include <Exception.hxx>
211 %include <YACSlibEngineExport.hxx>
212 %include <ConversionException.hxx>
213 %include <Runtime.hxx>
214 %include <PropertyInterface.hxx>
215
216 PYEXCEPTION(YACS::ENGINE::Executor::RunW)
217 PYEXCEPTION(YACS::ENGINE::Executor::RunB)
218 PYEXCEPTION(YACS::ENGINE::Executor::setExecMode)
219 PYEXCEPTION(YACS::ENGINE::Executor::resumeCurrentBreakPoint)
220 PYEXCEPTION(YACS::ENGINE::Executor::stopExecution)
221 PYEXCEPTION(YACS::ENGINE::Executor::waitPause)
222 PYEXCEPTION(YACS::ENGINE::ComponentInstance::load)
223
224 %include <Executor.hxx>
225
226 EXCEPTION(YACS::ENGINE::ExecutorSwig::RunPy)
227 EXCEPTION(YACS::ENGINE::ExecutorSwig::waitPause)
228 %include <ExecutorSwig.hxx>
229
230 %include <RefCounter.hxx>
231
232 %include <Any.hxx>
233
234 %ignore YACS::ENGINE::TypeCode::getOrBuildAnyFromZippedData;
235 %include <TypeCode.hxx>
236
237 %include <Scheduler.hxx>
238 %include <Task.hxx>
239 %include <Dispatcher.hxx>
240 %include <DeploymentTree.hxx>
241 %include <Port.hxx>
242 %extend YACS::ENGINE::Port
243 {
244   /* __cmp__ does not exist in Python 3 */
245   int  __lt__(Port* other)
246     {
247       if(self==other)
248         return 0;
249       else 
250         return 1;
251     }
252   int  __gt__(Port* other)
253     {
254       if(self==other)
255         return 0;
256       else 
257         return 1;
258     }
259   int __ne__(Port* other)
260     {
261       if(self==other)
262         return 0;
263       else 
264         return 1;
265     }
266   int __eq__(Port* other)
267     {
268       if(self==other)
269         return 0;
270       else 
271         return 1;
272     }
273   int __le__(Port* other)
274     {
275       if(self==other)
276         return 0;
277       else 
278         return 1;
279     }
280   int __ge__(Port* other)
281     {
282       if(self==other)
283         return 0;
284       else 
285         return 1;
286     }
287   
288   long ptr()
289     {
290       return (long)self;
291     }
292 }
293 %include <DataPort.hxx>
294 %include <InPort.hxx>
295 %include <OutPort.hxx>
296 %include <InGate.hxx>
297 %include <OutGate.hxx>
298 %include <DataFlowPort.hxx>
299 %include <DataStreamPort.hxx>
300
301 %include <LinkInfo.hxx>
302 %include <Logger.hxx>
303
304 %include <ComponentInstance.hxx>
305 %include <Container.hxx>
306 %include <HomogeneousPoolContainer.hxx>
307 %include <InputPort.hxx>
308 %extend YACS::ENGINE::InputPort
309 {
310   void edInitXML(const char * s)
311     {
312       self->edInit("XML",s);
313     }
314   void edInitPy(PyObject* ob)
315     {
316       self->edInit("Python",ob);
317     }
318 }
319 %include <InPropertyPort.hxx>
320 %extend YACS::ENGINE::InPropertyPort
321 {
322   void edInitXML(const char * s)
323     {
324       self->edInit("XML",s);
325     }
326   void edInitPy(PyObject* ob)
327     {
328       self->edInit("Python",ob);
329     }
330 }
331
332 %template(edInitInt)       YACS::ENGINE::InputPort::edInit<int>;
333 %template(edInitBool)      YACS::ENGINE::InputPort::edInit<bool>;
334 %template(edInitString)    YACS::ENGINE::InputPort::edInit<std::string>;
335 %template(edInitDbl)       YACS::ENGINE::InputPort::edInit<double>;
336
337 %include <AnyInputPort.hxx>
338 %include <ConditionInputPort.hxx>
339 %include <OutputPort.hxx>
340 %include <AnyOutputPort.hxx>
341 %include <InputDataStreamPort.hxx>
342 %include <OutputDataStreamPort.hxx>
343 %include <DataPort.hxx>
344
345 %include <Node.hxx>
346 %extend YACS::ENGINE::Node 
347 {
348   /* __cmp__ does not exist in Python 3 */
349   int  __lt__(Node* other)
350     {
351       if(self==other)
352         return 0;
353       else 
354         return 1;
355     }
356   int  __gt__(Node* other)
357     {
358       if(self==other)
359         return 0;
360       else 
361         return 1;
362     }
363   int __ne__(Node* other)
364     {
365       if(self==other)
366         return 0;
367       else 
368         return 1;
369     }
370   int __eq__(Node* other)
371     {
372       if(self==other)
373         return 0;
374       else 
375         return 1;
376     }
377   int __le__(Node* other)
378     {
379       if(self==other)
380         return 0;
381       else 
382         return 1;
383     }
384   int __ge__(Node* other)
385     {
386       if(self==other)
387         return 0;
388       else 
389         return 1;
390     }
391
392   long ptr()
393     {
394           return (long)self;
395     }
396 }
397
398 %include <ElementaryNode.hxx>
399 %include <InlineNode.hxx>
400 %include <ServiceNode.hxx>
401 %include <ServiceInlineNode.hxx>
402 %include <ServerNode.hxx>
403 %include <DataNode.hxx>
404
405 %include <ComposedNode.hxx>
406 %include <StaticDefinedComposedNode.hxx>
407 %include <Bloc.hxx>
408 %include <Proc.hxx>
409
410 %include <Loop.hxx>
411 %include <ForLoop.hxx>
412 %include <DynParaLoop.hxx>
413 %include <WhileLoop.hxx>
414 %include <ForEachLoop.hxx>
415 %include <OptimizerLoop.hxx>
416 %include <Switch.hxx>
417 %include <Visitor.hxx>
418 %include <VisitorSaveSchema.hxx>
419 %include <ComponentDefinition.hxx>
420 %include <Catalog.hxx>
421 %include <Pool.hxx>
422
423 %include <AlternateThread.hxx>
424 %include <AlternateThreadPT.hxx>
425
426 // Ignore class OptimizerAlgASync to avoid confusion with class
427 // OptimizerAlgASync in module SALOMERuntime
428 %ignore YACS::ENGINE::OptimizerAlgASync;
429 %include <OptimizerAlg.hxx>
430 %include "PlayGround.i"
431
432 %extend YACS::ENGINE::ConditionInputPort
433 {
434   bool getPyObj()
435   {
436     return self->getValue();
437   }
438 }
439
440 %extend YACS::ENGINE::AnyInputPort
441 {
442   PyObject * getPyObj()
443   {
444     return (PyObject *)getRuntime()->convertNeutral(self->edGetType(),self->getValue());
445   }
446 }
447
448 %extend YACS::ENGINE::AnyOutputPort
449 {
450   PyObject * getPyObj()
451   {
452     return (PyObject *)getRuntime()->convertNeutral(self->edGetType(),self->getValue());
453   }
454 }
455
456 %extend YACS::ENGINE::Any
457 {
458   PyObject *getPyObj()
459   {
460     return (PyObject *)getRuntime()->convertNeutral(const_cast<YACS::ENGINE::TypeCode *>(self->getType()),self);
461   }
462 }
463
464 %newobject YACS::ENGINE::SequenceAny::__getitem__;
465 %extend YACS::ENGINE::SequenceAny
466 {
467   Any* __getitem__(int i)
468   {
469     if (i < self->size())
470       {
471         AnyPtr a=(*self)[i];
472         a->incrRef();
473         return a;
474       }
475     else
476       throw std::length_error("index too large");
477   }
478 }
479
480 %newobject YACS::ENGINE::StructAny::__getitem__;
481 %extend YACS::ENGINE::StructAny
482 {
483   Any* __getitem__(const char * key)
484   {
485     AnyPtr a=(*self)[key];
486     a->incrRef();
487     return a;
488   }
489 }
490
491 %extend YACS::ENGINE::ForEachLoop
492 {
493   PyObject *getPassedResults(Executor *execut) const
494   {
495     std::vector<SequenceAny *> ret1;
496     std::vector<std::string> ret2;
497     std::vector<unsigned int> ret0(self->getPassedResults(execut,ret1,ret2));
498     PyObject *ret(PyTuple_New(3));
499     // param 0
500     PyObject *ret0Py(PyList_New(ret0.size()));
501     for(std::size_t i=0;i<ret0.size();i++)
502       PyList_SetItem(ret0Py,i,PyLong_FromLong(ret0[i]));
503     PyTuple_SetItem(ret,0,ret0Py);
504     // param 1
505     PyObject *ret1Py(PyList_New(ret1.size()));
506     for(std::size_t i=0;i<ret1.size();i++)
507       PyList_SetItem(ret1Py,i,SWIG_NewPointerObj(SWIG_as_voidptr(ret1[i]),SWIGTYPE_p_YACS__ENGINE__SequenceAny, SWIG_POINTER_OWN | 0 ));
508     PyTuple_SetItem(ret,1,ret1Py);
509     // param 2
510     PyObject *ret2Py(PyList_New(ret2.size()));
511     for(std::size_t i=0;i<ret2.size();i++)
512       PyList_SetItem(ret2Py,i,PyBytes_FromString(ret2[i].c_str()));
513     PyTuple_SetItem(ret,2,ret2Py);
514     return ret;
515   }
516
517   void assignPassedResults(const std::vector<unsigned int>& passedIds, PyObject *passedOutputs, const std::vector<std::string>& nameOfOutputs)
518   {
519     std::vector<SequenceAny *> passedOutputsCpp;
520     convertFromPyObjVectorOfObj<YACS::ENGINE::SequenceAny *>(passedOutputs,SWIGTYPE_p_YACS__ENGINE__SequenceAny,"SequenceAny",passedOutputsCpp);
521     self->assignPassedResults(passedIds,passedOutputsCpp,nameOfOutputs);
522   }
523 }