Salome HOME
Use pyobj type in optimizer loop.
[modules/yacs.git] / src / engine_swig / pilot.i
index d760c97d7609b6f63a02a9c44a04c7d42eeb903b..4d5ef483353036d58b9def0905c138171aa2514b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006-2016  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #include "ComponentInstance.hxx"
 #include "DataNode.hxx"
 #include "PlayGround.hxx"
+#include "SetOfPoints.hxx"
+#include "PointVisitor.hxx"
+#include "ForkBlocPoint.hxx"
+#include "LinkedBlocPoint.hxx"
+#include "NotSimpleCasePoint.hxx"
+#include "ElementaryPoint.hxx"
+#include "ObserverAsPlugin.hxx"
+#include "InGate.hxx"
   
 using namespace YACS::ENGINE;
 
@@ -106,12 +114,15 @@ using namespace YACS::ENGINE;
 %template()              std::pair<YACS::ENGINE::OutPort *,YACS::ENGINE::InPort *>;
 %template()              std::pair<YACS::ENGINE::InPort *,YACS::ENGINE::OutPort *>;
 %template()              std::pair< std::string, int >;
+%template()              std::pair< YACS::ENGINE::InGate *, bool>;
+%template(ItPy3TC)       IteratorPy3<YACS::ENGINE::TypeCode *>;
 //%template(TCmap)         std::map<std::string, YACS::ENGINE::TypeCode *>;
 REFCOUNT_TEMPLATE(TCmap,YACS::ENGINE::TypeCode)
 %template(NODEmap)       std::map<std::string, YACS::ENGINE::Node *>;
 %template(INODEmap)      std::map<std::string, YACS::ENGINE::InlineNode *>;
 %template(SNODEmap)      std::map<std::string, YACS::ENGINE::ServiceNode *>;
 //%template(CONTAINmap)    std::map<std::string, YACS::ENGINE::Container *>;
+%template(ItPy3Cont)     IteratorPy3<YACS::ENGINE::Container * >;
 REFCOUNT_TEMPLATE(CONTAINmap,YACS::ENGINE::Container)
 %template(strvec)        std::vector<std::string>;
 %template(uivec)         std::vector<unsigned int>;
@@ -130,9 +141,13 @@ REFCOUNT_TEMPLATE(CONTAINmap,YACS::ENGINE::Container)
 %template(compomap)      std::map<std::string, YACS::ENGINE::ComponentDefinition *>;
 %template()              std::pair<std::string, std::string>;
 %template(propmap)       std::map<std::string, std::string>;
+%template(ItPy3Comp)     IteratorPy3<YACS::ENGINE::ComponentInstance *>;
+%template(listpairingatebool) std::list< std::pair< YACS::ENGINE::InGate *, bool> >;
 
 REFCOUNT_TEMPLATE(CompoInstmap,YACS::ENGINE::ComponentInstance)
 
+%include "exception.i"
+
 /*
  * End of Template section
  */
@@ -229,6 +244,7 @@ EXCEPTION(YACS::ENGINE::ExecutorSwig::waitPause)
 
 %include <RefCounter.hxx>
 
+%feature("unref") YACS::ENGINE::Any "$this->decrRef();"
 %include <Any.hxx>
 
 %ignore YACS::ENGINE::TypeCode::getOrBuildAnyFromZippedData;
@@ -394,7 +410,7 @@ EXCEPTION(YACS::ENGINE::ExecutorSwig::waitPause)
           return (long)self;
     }
 }
-
+%include <ComplexWeight.hxx>
 %include <ElementaryNode.hxx>
 %include <InlineNode.hxx>
 %include <ServiceNode.hxx>
@@ -436,6 +452,18 @@ EXCEPTION(YACS::ENGINE::ExecutorSwig::waitPause)
     return self->getValue();
   }
 }
+%extend YACS::ENGINE::Any
+{
+  PyObject *getBytes()
+  {
+    YACS::ENGINE::AtomAny *self2(dynamic_cast<YACS::ENGINE::AtomAny *>(self));
+    if(!self2)
+      throw YACS::Exception("getBytes : self is not an AtomAny !");
+    std::size_t len(0);
+    const char *pt(self2->getBytesValue(len));
+    return PyBytes_FromStringAndSize(pt,len);
+  }
+}
 
 %extend YACS::ENGINE::AnyInputPort
 {
@@ -509,7 +537,7 @@ EXCEPTION(YACS::ENGINE::ExecutorSwig::waitPause)
     // param 2
     PyObject *ret2Py(PyList_New(ret2.size()));
     for(std::size_t i=0;i<ret2.size();i++)
-      PyList_SetItem(ret2Py,i,PyBytes_FromString(ret2[i].c_str()));
+      PyList_SetItem(ret2Py,i,PyUnicode_FromString(ret2[i].c_str()));
     PyTuple_SetItem(ret,2,ret2Py);
     return ret;
   }
@@ -521,3 +549,174 @@ EXCEPTION(YACS::ENGINE::ExecutorSwig::waitPause)
     self->assignPassedResults(passedIds,passedOutputsCpp,nameOfOutputs);
   }
 }
+
+namespace YACS
+{
+  namespace ENGINE
+  {
+    class AbstractPoint
+    {
+    protected:
+      virtual ~AbstractPoint();
+      AbstractPoint();
+      AbstractPoint(const AbstractPoint&);
+    };
+
+    class ElementaryPoint : public AbstractPoint
+    {
+    public:
+      Node *getFirstNode();
+    private:
+      ~ElementaryPoint();
+      ElementaryPoint();
+      ElementaryPoint(const ElementaryPoint&);
+    };
+
+    class BlocPoint : public AbstractPoint
+    {
+    protected:
+      ~BlocPoint();
+      BlocPoint();
+      BlocPoint(const BlocPoint&);
+    };
+
+    class LinkedBlocPoint : public BlocPoint
+    {
+    private:
+      ~LinkedBlocPoint();
+      LinkedBlocPoint();
+      LinkedBlocPoint(const LinkedBlocPoint&);
+    };
+
+    class ForkBlocPoint : public BlocPoint
+    {
+    private:
+      ~ForkBlocPoint();
+      ForkBlocPoint();
+      ForkBlocPoint(const ForkBlocPoint&);
+    };
+
+    class NotSimpleCasePoint : public BlocPoint
+    {
+    private:
+      ~NotSimpleCasePoint();
+      NotSimpleCasePoint();
+      NotSimpleCasePoint(const NotSimpleCasePoint&);
+    };
+    
+    class SetOfPoints
+    {
+    public:
+      SetOfPoints(const std::list<Node *>& nodes);
+      ~SetOfPoints();
+      void simplify();
+      std::string getRepr() const;
+      %extend
+      {
+      void accept(PyObject *pv)
+      {
+        class MyPointVisitor : public YACS::ENGINE::PointVisitor
+        {
+        public:
+          MyPointVisitor(PyObject *py):_py(py) { }
+          void beginForkBlocPoint(ForkBlocPoint *pt)
+          {
+            PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__ForkBlocPoint,0));
+            PyObject *meth(PyString_FromString("beginForkBlocPoint"));
+            PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
+            Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
+          }
+          void endForkBlocPoint(ForkBlocPoint *pt)
+          {
+            PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__ForkBlocPoint,0));
+            PyObject *meth(PyString_FromString("endForkBlocPoint"));
+            PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
+            Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
+          }
+          void beginLinkedBlocPoint(LinkedBlocPoint *pt)
+          {
+            PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__LinkedBlocPoint,0));
+            PyObject *meth(PyString_FromString("beginLinkedBlocPoint"));
+            PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
+            Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
+          }
+          void endLinkedBlocPoint(LinkedBlocPoint *pt)
+          {
+            PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__LinkedBlocPoint,0));
+            PyObject *meth(PyString_FromString("endLinkedBlocPoint"));
+            PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
+            Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
+          }
+          void beginElementaryPoint(ElementaryPoint *pt)
+          {
+            PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__ElementaryPoint,0));//$descriptor(YACS::ENGINE::ElementaryPoint *)
+            PyObject *meth(PyString_FromString("beginElementaryPoint"));
+            PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
+            Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
+          }
+          void endElementaryPoint(ElementaryPoint *pt)
+          {
+            PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__ElementaryPoint,0));
+            PyObject *meth(PyString_FromString("endElementaryPoint"));
+            PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
+            Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
+          }
+          void beginNotSimpleCasePoint(NotSimpleCasePoint *pt)
+          {
+            PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__NotSimpleCasePoint,0));//$descriptor(YACS::ENGINE::NotSimpleCasePoint *)
+            PyObject *meth(PyString_FromString("beginNotSimpleCasePoint"));
+            PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
+            Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
+          }
+          void endNotSimpleCasePoint(NotSimpleCasePoint *pt)
+          {
+            PyObject *ptPy(SWIG_NewPointerObj((void*)pt,SWIGTYPE_p_YACS__ENGINE__NotSimpleCasePoint,0));
+            PyObject *meth(PyString_FromString("endNotSimpleCasePoint"));
+            PyObject *ret(PyObject_CallMethodObjArgs(_py,meth,ptPy,nullptr));
+            Py_XDECREF(ret); Py_XDECREF(meth); Py_XDECREF(ptPy);
+          }
+        private:
+          PyObject *_py;
+        };
+        MyPointVisitor mpv(pv);
+        self->accept(&mpv);
+        }
+      }
+    };
+  }
+}
+
+%rename(LoadObserversPluginIfAny) LoadObserversPluginIfAnySwig;
+%rename(UnLoadObserversPluginIfAny) UnLoadObserversPluginIfAnySwig;
+                                  
+%inline{
+  void LoadObserversPluginIfAnySwig(YACS::ENGINE::ComposedNode *rootNode, YACS::ENGINE::ExecutorSwig *executor)
+  {
+    YACS::ENGINE::LoadObserversPluginIfAny(rootNode,executor);
+  }
+
+  void UnLoadObserversPluginIfAnySwig()
+  {
+    YACS::ENGINE::UnLoadObserversPluginIfAny();
+  }
+
+  PyObject *ToBase64Swig(PyObject *bytes)
+  {
+    char *pt = nullptr;
+    Py_ssize_t length=0;
+    PyBytes_AsStringAndSize(bytes,&pt,&length);
+    std::string input(pt,length);
+    std::string ret(YACS::ENGINE::ToBase64(input));
+    return PyBytes_FromStringAndSize(ret.c_str(),ret.size());
+  }
+
+  PyObject *FromBase64Swig(PyObject *base64Str)
+  {
+    char *pt = nullptr;
+    Py_ssize_t length=0;
+    PyBytes_AsStringAndSize(base64Str,&pt,&length);
+    std::string input(pt,length);
+    std::string ret(YACS::ENGINE::FromBase64(input));
+    return PyBytes_FromStringAndSize(ret.c_str(),ret.size());
+  }
+}