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