1 // Copyright (C) 2006-2022 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 "All is needed to create and execute a calculation schema."
24 %module(docstring=DOCSTRING) pilot
27 //work around SWIG bug #1863647
28 #if SWIG_VERSION >= 0x010336
29 #define SwigPyIterator pilot_PySwigIterator
31 #define PySwigIterator pilot_PySwigIterator
35 %feature("autodoc", "1");
37 %include "engtypemaps.i"
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"
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 "NotSimpleCasePoint.hxx"
67 #include "ElementaryPoint.hxx"
68 #include "ObserverAsPlugin.hxx"
71 using namespace YACS::ENGINE;
79 PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy");
82 PyErr_SetString(PyExc_ImportError,(char*)"Cannot import _omnipy");
85 PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API");
86 api = (omniORBpyAPI*)PyCapsule_GetPointer(pyapi,"_omnipy.API");
91 %ignore YACS::ENGINE::Any::operator[];
92 %ignore YACS::ENGINE::TypeCode::operator=;
93 %ignore YACS::ENGINE::DeploymentTree::operator=;
95 %ignore YACS::ENGINE::Runtime::_tc_double;
96 %ignore YACS::ENGINE::Runtime::_tc_int;
97 %ignore YACS::ENGINE::Runtime::_tc_bool;
98 %ignore YACS::ENGINE::Runtime::_tc_string;
99 %ignore YACS::ENGINE::Runtime::_tc_file;
100 %rename(StateLoader) YACS::ENGINE::StateLoader; // to suppress a 503 warning
101 %rename(NbDoneLoader) YACS::ENGINE::NbDoneLoader; // to suppress a 503 warning
102 %rename(getRuntime) YACS::ENGINE::getRuntime; // to suppress a 503 warning
103 %rename(_from) YACS::ENGINE::DataLinkInfo::from ; // to suppress a 314 warning
104 %rename(_from) YACS::ENGINE::StreamLinkInfo::from ; // to suppress a 314 warning
109 %template() std::pair<std::string, YACS::ENGINE::TypeCode *>;
110 %template() std::pair<std::string, YACS::ENGINE::Node *>;
111 %template() std::pair<std::string, YACS::ENGINE::InlineNode *>;
112 %template() std::pair<std::string, YACS::ENGINE::ServiceNode *>;
113 %template() std::pair<std::string, YACS::ENGINE::Container *>;
114 %template() std::pair<YACS::ENGINE::OutPort *,YACS::ENGINE::InPort *>;
115 %template() std::pair<YACS::ENGINE::InPort *,YACS::ENGINE::OutPort *>;
116 %template() std::pair< std::string, int >;
117 %template() std::pair< YACS::ENGINE::InGate *, bool>;
118 %template(ItPy3TC) IteratorPy3<YACS::ENGINE::TypeCode *>;
119 //%template(TCmap) std::map<std::string, YACS::ENGINE::TypeCode *>;
120 REFCOUNT_TEMPLATE(TCmap,YACS::ENGINE::TypeCode)
121 %template(NODEmap) std::map<std::string, YACS::ENGINE::Node *>;
122 %template(INODEmap) std::map<std::string, YACS::ENGINE::InlineNode *>;
123 %template(SNODEmap) std::map<std::string, YACS::ENGINE::ServiceNode *>;
124 //%template(CONTAINmap) std::map<std::string, YACS::ENGINE::Container *>;
125 %template(ItPy3Cont) IteratorPy3<YACS::ENGINE::Container * >;
126 REFCOUNT_TEMPLATE(CONTAINmap,YACS::ENGINE::Container)
127 %template(strvec) std::vector<std::string>;
128 %template(uivec) std::vector<unsigned int>;
129 %template(ivec) std::vector<int>;
130 %template(linksvec) std::vector< std::pair<YACS::ENGINE::OutPort *,YACS::ENGINE::InPort *> >;
131 %template(linkvec) std::vector< std::pair<YACS::ENGINE::InPort *,YACS::ENGINE::OutPort *> >;
132 %template(instreamlist) std::list<YACS::ENGINE::InputDataStreamPort *>;
133 %template(outstreamlist) std::list<YACS::ENGINE::OutputDataStreamPort *>;
134 %template(vpsi) std::vector< std::pair< std::string, int > >;
136 %template() std::pair<std::string, YACS::ENGINE::CatalogLoader *>;
137 %template(loadermap) std::map<std::string,YACS::ENGINE::CatalogLoader *>;
138 %template() std::pair<std::string, YACS::ENGINE::ComposedNode *>;
139 %template(composedmap) std::map<std::string,YACS::ENGINE::ComposedNode *>;
140 %template() std::pair<std::string, YACS::ENGINE::ComponentDefinition *>;
141 %template(compomap) std::map<std::string, YACS::ENGINE::ComponentDefinition *>;
142 %template() std::pair<std::string, std::string>;
143 %template(propmap) std::map<std::string, std::string>;
144 %template(ItPy3Comp) IteratorPy3<YACS::ENGINE::ComponentInstance *>;
145 %template(listpairingatebool) std::list< std::pair< YACS::ENGINE::InGate *, bool> >;
147 REFCOUNT_TEMPLATE(CompoInstmap,YACS::ENGINE::ComponentInstance)
149 %include "exception.i"
152 * End of Template section
155 %typemap(out) Container *
157 $result=convertContainer($1,$owner);
160 %typemap(out) YACS::ENGINE::Container *
162 $result=convertContainer($1,$owner);
168 //Take ownership : it is not the default (constructor) as it is a factory
169 %newobject *::createProc;
170 %newobject *::createScriptNode;
171 %newobject *::createFuncNode;
172 %newobject *::createRefNode;
173 %newobject *::createCompoNode;
174 %newobject *::createSInlineNode;
175 %newobject *::createInDataNode;
176 %newobject *::createOutDataNode;
177 %newobject *::createBloc;
178 %newobject *::createForLoop;
179 %newobject *::createForEachLoop;
180 %newobject *::createForEachLoopDyn;
181 %newobject *::createWhileLoop;
182 %newobject *::createSwitch;
183 %newobject *::loadCatalog;
184 %newobject *::createComponentInstance;
185 %newobject *::createContainer;
188 %newobject *::createInputPort;
189 %newobject *::createOutputPort;
190 %newobject *::createInputDataStreamPort;
191 %newobject *::createOutputDataStreamPort;
193 %newobject *::cloneAlways;
194 %newobject *::cloneWithoutCompAndContDeepCpy;
197 //Take ownership : transfer it from C++ (has to be completed)
198 %newobject YACS::ENGINE::Loop::edRemoveNode;
199 %newobject YACS::ENGINE::Switch::edReleaseDefaultNode;
200 %newobject YACS::ENGINE::Switch::edReleaseCase;
201 %newobject YACS::ENGINE::DynParaLoop::edRemoveNode;
202 %newobject YACS::ENGINE::DynParaLoop::edRemoveInitNode;
203 //No other way to do ??
204 %feature("pythonappend") YACS::ENGINE::Bloc::edRemoveChild(Node *node)%{
208 %newobject *::createSequenceTc;
209 %newobject *::createInterfaceTc;
210 %newobject *::createStructTc;
211 %newobject *::createType;
213 %newobject YACS::ENGINE::SequenceAny::removeUnsetItemsFromThis;
215 %newobject YACS::ENGINE::TypeCode::interfaceTc;
216 %newobject YACS::ENGINE::TypeCode::sequenceTc;
217 %newobject YACS::ENGINE::TypeCode::structTc;
220 * End of ownership section
224 %include <define.hxx>
225 %include <YACSBasesExport.hxx>
226 %include <Exception.hxx>
227 %include <YACSlibEngineExport.hxx>
228 %include <ConversionException.hxx>
229 %include <Runtime.hxx>
230 %include <PropertyInterface.hxx>
232 PYEXCEPTION(YACS::ENGINE::Executor::RunW)
233 PYEXCEPTION(YACS::ENGINE::Executor::RunB)
234 PYEXCEPTION(YACS::ENGINE::Executor::setExecMode)
235 PYEXCEPTION(YACS::ENGINE::Executor::resumeCurrentBreakPoint)
236 PYEXCEPTION(YACS::ENGINE::Executor::stopExecution)
237 PYEXCEPTION(YACS::ENGINE::Executor::waitPause)
238 PYEXCEPTION(YACS::ENGINE::ComponentInstance::load)
240 %include <Executor.hxx>
242 EXCEPTION(YACS::ENGINE::ExecutorSwig::RunPy)
243 EXCEPTION(YACS::ENGINE::ExecutorSwig::waitPause)
244 %include <ExecutorSwig.hxx>
246 %include <RefCounter.hxx>
248 %feature("unref") YACS::ENGINE::Any "$this->decrRef();"
251 %ignore YACS::ENGINE::TypeCode::getOrBuildAnyFromZippedData;
252 %include <TypeCode.hxx>
254 %include <Scheduler.hxx>
256 %include <Dispatcher.hxx>
257 %include <DeploymentTree.hxx>
259 %extend YACS::ENGINE::Port
261 /* __cmp__ does not exist in Python 3 */
262 int __lt__(Port* other)
269 int __gt__(Port* other)
276 int __ne__(Port* other)
283 int __eq__(Port* other)
290 int __le__(Port* other)
297 int __ge__(Port* other)
310 %include <DataPort.hxx>
311 %include <InPort.hxx>
312 %include <OutPort.hxx>
313 %include <InGate.hxx>
314 %include <OutGate.hxx>
315 %include <DataFlowPort.hxx>
316 %include <DataStreamPort.hxx>
318 %include <LinkInfo.hxx>
319 %include <Logger.hxx>
321 %include <ComponentInstance.hxx>
322 %include <Container.hxx>
323 %include <HomogeneousPoolContainer.hxx>
324 %include <InputPort.hxx>
325 %extend YACS::ENGINE::InputPort
327 void edInitXML(const char * s)
329 self->edInit("XML",s);
331 void edInitPy(PyObject* ob)
333 self->edInit("Python",ob);
336 %include <InPropertyPort.hxx>
337 %extend YACS::ENGINE::InPropertyPort
339 void edInitXML(const char * s)
341 self->edInit("XML",s);
343 void edInitPy(PyObject* ob)
345 self->edInit("Python",ob);
349 %template(edInitInt) YACS::ENGINE::InputPort::edInit<int>;
350 %template(edInitBool) YACS::ENGINE::InputPort::edInit<bool>;
351 %template(edInitString) YACS::ENGINE::InputPort::edInit<std::string>;
352 %template(edInitDbl) YACS::ENGINE::InputPort::edInit<double>;
354 %include <AnyInputPort.hxx>
355 %include <ConditionInputPort.hxx>
356 %include <OutputPort.hxx>
357 %include <AnyOutputPort.hxx>
358 %include <InputDataStreamPort.hxx>
359 %include <OutputDataStreamPort.hxx>
360 %include <DataPort.hxx>
363 %extend YACS::ENGINE::Node
365 /* __cmp__ does not exist in Python 3 */
366 int __lt__(Node* other)
373 int __gt__(Node* other)
380 int __ne__(Node* other)
387 int __eq__(Node* other)
394 int __le__(Node* other)
401 int __ge__(Node* other)
414 %include <ComplexWeight.hxx>
415 %include <ElementaryNode.hxx>
416 %include <InlineNode.hxx>
417 %include <ServiceNode.hxx>
418 %include <ServiceInlineNode.hxx>
419 %include <ServerNode.hxx>
420 %include <DataNode.hxx>
422 %include <ComposedNode.hxx>
423 %include <StaticDefinedComposedNode.hxx>
428 %include <ForLoop.hxx>
429 %include <DynParaLoop.hxx>
430 %include <WhileLoop.hxx>
431 %include <ForEachLoop.hxx>
432 %include <OptimizerLoop.hxx>
433 %include <Switch.hxx>
434 %include <Visitor.hxx>
435 %include <VisitorSaveSchema.hxx>
436 %include <ComponentDefinition.hxx>
437 %include <Catalog.hxx>
440 %include <AlternateThread.hxx>
441 %include <AlternateThreadPT.hxx>
443 // Ignore class OptimizerAlgASync to avoid confusion with class
444 // OptimizerAlgASync in module SALOMERuntime
445 %ignore YACS::ENGINE::OptimizerAlgASync;
446 %include <OptimizerAlg.hxx>
447 %include "PlayGround.i"
449 %extend YACS::ENGINE::ConditionInputPort
453 return self->getValue();
456 %extend YACS::ENGINE::Any
460 YACS::ENGINE::AtomAny *self2(dynamic_cast<YACS::ENGINE::AtomAny *>(self));
462 throw YACS::Exception("getBytes : self is not an AtomAny !");
464 const char *pt(self2->getBytesValue(len));
465 return PyBytes_FromStringAndSize(pt,len);
469 %extend YACS::ENGINE::AnyInputPort
471 PyObject * getPyObj()
473 return (PyObject *)getRuntime()->convertNeutral(self->edGetType(),self->getValue());
477 %extend YACS::ENGINE::AnyOutputPort
479 PyObject * getPyObj()
481 return (PyObject *)getRuntime()->convertNeutral(self->edGetType(),self->getValue());
485 %extend YACS::ENGINE::Any
489 return (PyObject *)getRuntime()->convertNeutral(const_cast<YACS::ENGINE::TypeCode *>(self->getType()),self);
493 %newobject YACS::ENGINE::SequenceAny::__getitem__;
494 %extend YACS::ENGINE::SequenceAny
496 Any* __getitem__(int i)
498 if (i < self->size())
505 throw std::length_error("index too large");
509 %newobject YACS::ENGINE::StructAny::__getitem__;
510 %extend YACS::ENGINE::StructAny
512 Any* __getitem__(const char * key)
514 AnyPtr a=(*self)[key];
520 %extend YACS::ENGINE::ForEachLoop
522 PyObject *getPassedResults(Executor *execut) const
524 std::vector<SequenceAny *> ret1;
525 std::vector<std::string> ret2;
526 std::vector<unsigned int> ret0(self->getPassedResults(execut,ret1,ret2));
527 PyObject *ret(PyTuple_New(3));
529 PyObject *ret0Py(PyList_New(ret0.size()));
530 for(std::size_t i=0;i<ret0.size();i++)
531 PyList_SetItem(ret0Py,i,PyLong_FromLong(ret0[i]));
532 PyTuple_SetItem(ret,0,ret0Py);
534 PyObject *ret1Py(PyList_New(ret1.size()));
535 for(std::size_t i=0;i<ret1.size();i++)
536 PyList_SetItem(ret1Py,i,SWIG_NewPointerObj(SWIG_as_voidptr(ret1[i]),SWIGTYPE_p_YACS__ENGINE__SequenceAny, SWIG_POINTER_OWN | 0 ));
537 PyTuple_SetItem(ret,1,ret1Py);
539 PyObject *ret2Py(PyList_New(ret2.size()));
540 for(std::size_t i=0;i<ret2.size();i++)
541 PyList_SetItem(ret2Py,i,PyUnicode_FromString(ret2[i].c_str()));
542 PyTuple_SetItem(ret,2,ret2Py);
546 void assignPassedResults(const std::vector<unsigned int>& passedIds, PyObject *passedOutputs, const std::vector<std::string>& nameOfOutputs)
548 std::vector<SequenceAny *> passedOutputsCpp;
549 convertFromPyObjVectorOfObj<YACS::ENGINE::SequenceAny *>(passedOutputs,SWIGTYPE_p_YACS__ENGINE__SequenceAny,"SequenceAny",passedOutputsCpp);
550 self->assignPassedResults(passedIds,passedOutputsCpp,nameOfOutputs);
561 virtual ~AbstractPoint();
563 AbstractPoint(const AbstractPoint&);
566 class ElementaryPoint : public AbstractPoint
569 Node *getFirstNode();
573 ElementaryPoint(const ElementaryPoint&);
576 class BlocPoint : public AbstractPoint
581 BlocPoint(const BlocPoint&);
584 class LinkedBlocPoint : public BlocPoint
589 LinkedBlocPoint(const LinkedBlocPoint&);
592 class ForkBlocPoint : public BlocPoint
597 ForkBlocPoint(const ForkBlocPoint&);
600 class NotSimpleCasePoint : public BlocPoint
603 ~NotSimpleCasePoint();
604 NotSimpleCasePoint();
605 NotSimpleCasePoint(const NotSimpleCasePoint&);
611 SetOfPoints(const std::list<Node *>& nodes);
614 std::string getRepr() const;
617 void accept(PyObject *pv)
619 class MyPointVisitor : public YACS::ENGINE::PointVisitor
622 MyPointVisitor(PyObject *py):_py(py) { }
623 void beginForkBlocPoint(ForkBlocPoint *pt)
625 PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__ForkBlocPoint,0));
626 PyObject *meth(PyString_FromString("beginForkBlocPoint"));
627 PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
628 Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
630 void endForkBlocPoint(ForkBlocPoint *pt)
632 PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__ForkBlocPoint,0));
633 PyObject *meth(PyString_FromString("endForkBlocPoint"));
634 PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
635 Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
637 void beginLinkedBlocPoint(LinkedBlocPoint *pt)
639 PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__LinkedBlocPoint,0));
640 PyObject *meth(PyString_FromString("beginLinkedBlocPoint"));
641 PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
642 Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
644 void endLinkedBlocPoint(LinkedBlocPoint *pt)
646 PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__LinkedBlocPoint,0));
647 PyObject *meth(PyString_FromString("endLinkedBlocPoint"));
648 PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
649 Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
651 void beginElementaryPoint(ElementaryPoint *pt)
653 PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__ElementaryPoint,0));//$descriptor(YACS::ENGINE::ElementaryPoint *)
654 PyObject *meth(PyString_FromString("beginElementaryPoint"));
655 PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
656 Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
658 void endElementaryPoint(ElementaryPoint *pt)
660 PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__ElementaryPoint,0));
661 PyObject *meth(PyString_FromString("endElementaryPoint"));
662 PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
663 Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
665 void beginNotSimpleCasePoint(NotSimpleCasePoint *pt)
667 PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__NotSimpleCasePoint,0));//$descriptor(YACS::ENGINE::NotSimpleCasePoint *)
668 PyObject *meth(PyString_FromString("beginNotSimpleCasePoint"));
669 PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
670 Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
672 void endNotSimpleCasePoint(NotSimpleCasePoint *pt)
674 PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__NotSimpleCasePoint,0));
675 PyObject *meth(PyString_FromString("endNotSimpleCasePoint"));
676 PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
677 Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
682 MyPointVisitor mpv(pv);
690 %rename(LoadObserversPluginIfAny) LoadObserversPluginIfAnySwig;
691 %rename(UnLoadObserversPluginIfAny) UnLoadObserversPluginIfAnySwig;
694 void LoadObserversPluginIfAnySwig(YACS::ENGINE::ComposedNode *rootNode, YACS::ENGINE::ExecutorSwig *executor)
696 YACS::ENGINE::LoadObserversPluginIfAny(rootNode,executor);
699 void UnLoadObserversPluginIfAnySwig()
701 YACS::ENGINE::UnLoadObserversPluginIfAny();
704 PyObject *ToBase64Swig(PyObject *bytes)
708 PyBytes_AsStringAndSize(bytes,&pt,&length);
709 std::string input(pt,length);
710 std::string ret(YACS::ENGINE::ToBase64(input));
711 return PyBytes_FromStringAndSize(ret.c_str(),ret.size());
714 PyObject *FromBase64Swig(PyObject *base64Str)
718 PyBytes_AsStringAndSize(base64Str,&pt,&length);
719 std::string input(pt,length);
720 std::string ret(YACS::ENGINE::FromBase64(input));
721 return PyBytes_FromStringAndSize(ret.c_str(),ret.size());