]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine_swig/pilot.i
Salome HOME
98a7296db3b0330b204bd02fc2a3b40e79146ec2
[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;
76   }
77   PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API");
78   api = (omniORBPYAPI*)PyCObject_AsVoidPtr(pyapi);
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   int __cmp__(Port* other)
245     {
246       if(self==other)
247         return 0;
248       else 
249         return 1;
250     }
251   long ptr()
252     {
253       return (long)self;
254     }
255 }
256 %include <DataPort.hxx>
257 %include <InPort.hxx>
258 %include <OutPort.hxx>
259 %include <InGate.hxx>
260 %include <OutGate.hxx>
261 %include <DataFlowPort.hxx>
262 %include <DataStreamPort.hxx>
263
264 %include <LinkInfo.hxx>
265 %include <Logger.hxx>
266
267 %include <ComponentInstance.hxx>
268 %include <Container.hxx>
269 %include <HomogeneousPoolContainer.hxx>
270 %include <InputPort.hxx>
271 %extend YACS::ENGINE::InputPort
272 {
273   void edInitXML(const char * s)
274     {
275       self->edInit("XML",s);
276     }
277   void edInitPy(PyObject* ob)
278     {
279       self->edInit("Python",ob);
280     }
281 }
282 %include <InPropertyPort.hxx>
283 %extend YACS::ENGINE::InPropertyPort
284 {
285   void edInitXML(const char * s)
286     {
287       self->edInit("XML",s);
288     }
289   void edInitPy(PyObject* ob)
290     {
291       self->edInit("Python",ob);
292     }
293 }
294
295 %template(edInitInt)       YACS::ENGINE::InputPort::edInit<int>;
296 %template(edInitBool)      YACS::ENGINE::InputPort::edInit<bool>;
297 %template(edInitString)    YACS::ENGINE::InputPort::edInit<std::string>;
298 %template(edInitDbl)       YACS::ENGINE::InputPort::edInit<double>;
299
300 %include <AnyInputPort.hxx>
301 %include <ConditionInputPort.hxx>
302 %include <OutputPort.hxx>
303 %include <AnyOutputPort.hxx>
304 %include <InputDataStreamPort.hxx>
305 %include <OutputDataStreamPort.hxx>
306 %include <DataPort.hxx>
307
308 %include <Node.hxx>
309 %extend YACS::ENGINE::Node 
310 {
311   int __cmp__(Node* other)
312     {
313       if(self==other)
314         return 0;
315       else 
316         return 1;
317     }
318   long ptr()
319     {
320           return (long)self;
321     }
322 }
323
324 %include <ElementaryNode.hxx>
325 %include <InlineNode.hxx>
326 %include <ServiceNode.hxx>
327 %include <ServiceInlineNode.hxx>
328 %include <ServerNode.hxx>
329 %include <DataNode.hxx>
330
331 %include <ComposedNode.hxx>
332 %include <StaticDefinedComposedNode.hxx>
333 %include <Bloc.hxx>
334 %include <Proc.hxx>
335
336 %include <Loop.hxx>
337 %include <ForLoop.hxx>
338 %include <DynParaLoop.hxx>
339 %include <WhileLoop.hxx>
340 %include <ForEachLoop.hxx>
341 %include <OptimizerLoop.hxx>
342 %include <Switch.hxx>
343 %include <Visitor.hxx>
344 %include <VisitorSaveSchema.hxx>
345 %include <ComponentDefinition.hxx>
346 %include <Catalog.hxx>
347 %include <Pool.hxx>
348
349 %include <AlternateThread.hxx>
350 %include <AlternateThreadPT.hxx>
351
352 // Ignore class OptimizerAlgASync to avoid confusion with class
353 // OptimizerAlgASync in module SALOMERuntime
354 %ignore YACS::ENGINE::OptimizerAlgASync;
355 %include <OptimizerAlg.hxx>
356 %include "PlayGround.i"
357
358 %extend YACS::ENGINE::ConditionInputPort
359 {
360   bool getPyObj()
361   {
362     return self->getValue();
363   }
364 }
365
366 %extend YACS::ENGINE::AnyInputPort
367 {
368   PyObject * getPyObj()
369   {
370     return (PyObject *)getRuntime()->convertNeutral(self->edGetType(),self->getValue());
371   }
372 }
373
374 %extend YACS::ENGINE::AnyOutputPort
375 {
376   PyObject * getPyObj()
377   {
378     return (PyObject *)getRuntime()->convertNeutral(self->edGetType(),self->getValue());
379   }
380 }
381
382 %extend YACS::ENGINE::Any
383 {
384   PyObject *getPyObj()
385   {
386     return (PyObject *)getRuntime()->convertNeutral(const_cast<YACS::ENGINE::TypeCode *>(self->getType()),self);
387   }
388 }
389
390 %newobject YACS::ENGINE::SequenceAny::__getitem__;
391 %extend YACS::ENGINE::SequenceAny
392 {
393   Any* __getitem__(int i)
394   {
395     if (i < self->size())
396       {
397         AnyPtr a=(*self)[i];
398         a->incrRef();
399         return a;
400       }
401     else
402       throw std::length_error("index too large");
403   }
404 }
405
406 %newobject YACS::ENGINE::StructAny::__getitem__;
407 %extend YACS::ENGINE::StructAny
408 {
409   Any* __getitem__(const char * key)
410   {
411     AnyPtr a=(*self)[key];
412     a->incrRef();
413     return a;
414   }
415 }
416
417 %extend YACS::ENGINE::ForEachLoop
418 {
419   PyObject *getPassedResults(Executor *execut) const
420   {
421     std::vector<SequenceAny *> ret1;
422     std::vector<std::string> ret2;
423     std::vector<unsigned int> ret0(self->getPassedResults(execut,ret1,ret2));
424     PyObject *ret(PyTuple_New(3));
425     // param 0
426     PyObject *ret0Py(PyList_New(ret0.size()));
427     for(std::size_t i=0;i<ret0.size();i++)
428       PyList_SetItem(ret0Py,i,PyInt_FromLong(ret0[i]));
429     PyTuple_SetItem(ret,0,ret0Py);
430     // param 1
431     PyObject *ret1Py(PyList_New(ret1.size()));
432     for(std::size_t i=0;i<ret1.size();i++)
433       PyList_SetItem(ret1Py,i,SWIG_NewPointerObj(SWIG_as_voidptr(ret1[i]),SWIGTYPE_p_YACS__ENGINE__SequenceAny, SWIG_POINTER_OWN | 0 ));
434     PyTuple_SetItem(ret,1,ret1Py);
435     // param 2
436     PyObject *ret2Py(PyList_New(ret2.size()));
437     for(std::size_t i=0;i<ret2.size();i++)
438       PyList_SetItem(ret2Py,i,PyString_FromString(ret2[i].c_str()));
439     PyTuple_SetItem(ret,2,ret2Py);
440     return ret;
441   }
442
443   void assignPassedResults(const std::vector<unsigned int>& passedIds, PyObject *passedOutputs, const std::vector<std::string>& nameOfOutputs)
444   {
445     std::vector<SequenceAny *> passedOutputsCpp;
446     convertFromPyObjVectorOfObj<YACS::ENGINE::SequenceAny *>(passedOutputs,SWIGTYPE_p_YACS__ENGINE__SequenceAny,"SequenceAny",passedOutputsCpp);
447     self->assignPassedResults(passedIds,passedOutputsCpp,nameOfOutputs);
448   }
449 }