]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine_swig/pilot.i
Salome HOME
[PY3] Fixing test in progress
[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 NULL;
75   }
76   PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API");
77   api = (omniORBpyAPI*)PyCapsule_GetPointer(pyapi,"_omnipy.API");
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   /* __cmp__ does not exist in Python 3 */
241   int  __lt__(Port* other)
242     {
243       if(self==other)
244         return 0;
245       else 
246         return 1;
247     }
248   int  __gt__(Port* other)
249     {
250       if(self==other)
251         return 0;
252       else 
253         return 1;
254     }
255   int __ne__(Port* other)
256     {
257       if(self==other)
258         return 0;
259       else 
260         return 1;
261     }
262   int __eq__(Port* other)
263     {
264       if(self==other)
265         return 0;
266       else 
267         return 1;
268     }
269   int __le__(Port* other)
270     {
271       if(self==other)
272         return 0;
273       else 
274         return 1;
275     }
276   int __ge__(Port* other)
277     {
278       if(self==other)
279         return 0;
280       else 
281         return 1;
282     }
283   
284   long ptr()
285     {
286       return (long)self;
287     }
288 }
289 %include <DataPort.hxx>
290 %include <InPort.hxx>
291 %include <OutPort.hxx>
292 %include <InGate.hxx>
293 %include <OutGate.hxx>
294 %include <DataFlowPort.hxx>
295 %include <DataStreamPort.hxx>
296
297 %include <LinkInfo.hxx>
298 %include <Logger.hxx>
299
300 %include <ComponentInstance.hxx>
301 %include <Container.hxx>
302 %include <HomogeneousPoolContainer.hxx>
303 %include <InputPort.hxx>
304 %extend YACS::ENGINE::InputPort
305 {
306   void edInitXML(const char * s)
307     {
308       self->edInit("XML",s);
309     }
310   void edInitPy(PyObject* ob)
311     {
312       self->edInit("Python",ob);
313     }
314 }
315 %include <InPropertyPort.hxx>
316 %extend YACS::ENGINE::InPropertyPort
317 {
318   void edInitXML(const char * s)
319     {
320       self->edInit("XML",s);
321     }
322   void edInitPy(PyObject* ob)
323     {
324       self->edInit("Python",ob);
325     }
326 }
327
328 %template(edInitInt)       YACS::ENGINE::InputPort::edInit<int>;
329 %template(edInitBool)      YACS::ENGINE::InputPort::edInit<bool>;
330 %template(edInitString)    YACS::ENGINE::InputPort::edInit<std::string>;
331 %template(edInitDbl)       YACS::ENGINE::InputPort::edInit<double>;
332
333 %include <AnyInputPort.hxx>
334 %include <ConditionInputPort.hxx>
335 %include <OutputPort.hxx>
336 %include <AnyOutputPort.hxx>
337 %include <InputDataStreamPort.hxx>
338 %include <OutputDataStreamPort.hxx>
339 %include <DataPort.hxx>
340
341 %include <Node.hxx>
342 %extend YACS::ENGINE::Node 
343 {
344   /* __cmp__ does not exist in Python 3 */
345   int  __lt__(Node* other)
346     {
347       if(self==other)
348         return 0;
349       else 
350         return 1;
351     }
352   int  __gt__(Node* other)
353     {
354       if(self==other)
355         return 0;
356       else 
357         return 1;
358     }
359   int __ne__(Node* other)
360     {
361       if(self==other)
362         return 0;
363       else 
364         return 1;
365     }
366   int __eq__(Node* other)
367     {
368       if(self==other)
369         return 0;
370       else 
371         return 1;
372     }
373   int __le__(Node* other)
374     {
375       if(self==other)
376         return 0;
377       else 
378         return 1;
379     }
380   int __ge__(Node* other)
381     {
382       if(self==other)
383         return 0;
384       else 
385         return 1;
386     }
387
388   long ptr()
389     {
390           return (long)self;
391     }
392 }
393
394 %include <ElementaryNode.hxx>
395 %include <InlineNode.hxx>
396 %include <ServiceNode.hxx>
397 %include <ServiceInlineNode.hxx>
398 %include <ServerNode.hxx>
399 %include <DataNode.hxx>
400
401 %include <ComposedNode.hxx>
402 %include <StaticDefinedComposedNode.hxx>
403 %include <Bloc.hxx>
404 %include <Proc.hxx>
405
406 %include <Loop.hxx>
407 %include <ForLoop.hxx>
408 %include <DynParaLoop.hxx>
409 %include <WhileLoop.hxx>
410 %include <ForEachLoop.hxx>
411 %include <OptimizerLoop.hxx>
412 %include <Switch.hxx>
413 %include <Visitor.hxx>
414 %include <VisitorSaveSchema.hxx>
415 %include <ComponentDefinition.hxx>
416 %include <Catalog.hxx>
417 %include <Pool.hxx>
418
419 %include <AlternateThread.hxx>
420 %include <AlternateThreadPT.hxx>
421
422 // Ignore class OptimizerAlgASync to avoid confusion with class
423 // OptimizerAlgASync in module SALOMERuntime
424 %ignore YACS::ENGINE::OptimizerAlgASync;
425 %include <OptimizerAlg.hxx>
426
427 %extend YACS::ENGINE::ConditionInputPort
428 {
429   bool getPyObj()
430   {
431     return self->getValue();
432   }
433 }
434
435 %extend YACS::ENGINE::AnyInputPort
436 {
437   PyObject * getPyObj()
438   {
439     return (PyObject *)getRuntime()->convertNeutral(self->edGetType(),self->getValue());
440   }
441 }
442
443 %extend YACS::ENGINE::AnyOutputPort
444 {
445   PyObject * getPyObj()
446   {
447     return (PyObject *)getRuntime()->convertNeutral(self->edGetType(),self->getValue());
448   }
449 }
450
451 %extend YACS::ENGINE::Any
452 {
453   PyObject *getPyObj()
454   {
455     return (PyObject *)getRuntime()->convertNeutral(const_cast<YACS::ENGINE::TypeCode *>(self->getType()),self);
456   }
457 }
458
459 %newobject YACS::ENGINE::SequenceAny::__getitem__;
460 %extend YACS::ENGINE::SequenceAny
461 {
462   Any* __getitem__(int i)
463   {
464     if (i < self->size())
465       {
466         AnyPtr a=(*self)[i];
467         a->incrRef();
468         return a;
469       }
470     else
471       throw std::length_error("index too large");
472   }
473 }
474
475 %newobject YACS::ENGINE::StructAny::__getitem__;
476 %extend YACS::ENGINE::StructAny
477 {
478   Any* __getitem__(const char * key)
479   {
480     AnyPtr a=(*self)[key];
481     a->incrRef();
482     return a;
483   }
484 }
485
486 %extend YACS::ENGINE::ForEachLoop
487 {
488   PyObject *getPassedResults(Executor *execut) const
489   {
490     std::vector<SequenceAny *> ret1;
491     std::vector<std::string> ret2;
492     std::vector<unsigned int> ret0(self->getPassedResults(execut,ret1,ret2));
493     PyObject *ret(PyTuple_New(3));
494     // param 0
495     PyObject *ret0Py(PyList_New(ret0.size()));
496     for(std::size_t i=0;i<ret0.size();i++)
497       PyList_SetItem(ret0Py,i,PyLong_FromLong(ret0[i]));
498     PyTuple_SetItem(ret,0,ret0Py);
499     // param 1
500     PyObject *ret1Py(PyList_New(ret1.size()));
501     for(std::size_t i=0;i<ret1.size();i++)
502       PyList_SetItem(ret1Py,i,SWIG_NewPointerObj(SWIG_as_voidptr(ret1[i]),SWIGTYPE_p_YACS__ENGINE__SequenceAny, SWIG_POINTER_OWN | 0 ));
503     PyTuple_SetItem(ret,1,ret1Py);
504     // param 2
505     PyObject *ret2Py(PyList_New(ret2.size()));
506     for(std::size_t i=0;i<ret2.size();i++)
507       PyList_SetItem(ret2Py,i,PyBytes_FromString(ret2[i].c_str()));
508     PyTuple_SetItem(ret,2,ret2Py);
509     return ret;
510   }
511
512   void assignPassedResults(const std::vector<unsigned int>& passedIds, PyObject *passedOutputs, const std::vector<std::string>& nameOfOutputs)
513   {
514     std::vector<SequenceAny *> passedOutputsCpp;
515     convertFromPyObjVectorOfObj<YACS::ENGINE::SequenceAny *>(passedOutputs,SWIGTYPE_p_YACS__ENGINE__SequenceAny,"SequenceAny",passedOutputsCpp);
516     self->assignPassedResults(passedIds,passedOutputsCpp,nameOfOutputs);
517   }
518 }