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