// Copyright (C) 2012-2015 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 // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // Author : Anthony Geay (EDF R&D) %define EVALYFXDOCSTRING "Module to evaluate Y=f(X) easily." %enddef %module(docstring=EVALYFXDOCSTRING) evalyfx %feature("autodoc", "1"); %include "engtypemaps.i" %{ #include "YACSEvalYFX.hxx" #include "YACSEvalPort.hxx" #include "YACSEvalSeqAny.hxx" #include "YACSEvalResource.hxx" #include "YACSEvalSession.hxx" static void convertPyToIntArr(PyObject *pyLi, std::vector& arr) { if(PyList_Check(pyLi)) { int size=PyList_Size(pyLi); arr.resize(size); for(int i=0;i& arr) { if(PyList_Check(pyLi)) { int size=PyList_Size(pyLi); arr.resize(size); for(int i=0;i { std::vector::const_iterator it; $result = PyList_New($1.size()); int i = 0; for (it = $1.begin(); it != $1.end(); ++it, ++i) { PyList_SetItem($result,i,SWIG_NewPointerObj(SWIG_as_voidptr(*it),SWIGTYPE_p_YACSEvalInputPort, 0 | 0 )); } } %typemap(out) std::vector { std::vector::const_iterator it; $result = PyList_New($1.size()); int i = 0; for (it = $1.begin(); it != $1.end(); ++it, ++i) { PyList_SetItem($result,i,SWIG_NewPointerObj(SWIG_as_voidptr(*it),SWIGTYPE_p_YACSEvalOutputPort, 0 | 0 )); } } %typemap(out) YACSEvalAny * { $result = 0; YACSEvalAnyDouble *val0(dynamic_cast($1)); YACSEvalAnyInt *val1(dynamic_cast($1)); if(val0) { $result = PyFloat_FromDouble(val0->toDouble()); delete $1; } else if(val1) { $result = PyInt_FromLong(val1->toInt()); delete $1; } else { delete $1; throw YACS::Exception("PyWrap of YACSEvalInputPort::getDefaultValueDefined : unrecognized type !"); } } %typemap(in) const std::list< YACSEvalOutputPort * >& { } class YACSEvalPort { public: virtual std::string getTypeOfData() const; private: YACSEvalPort(); }; class YACSEvalInputPort : public YACSEvalPort { public: std::string getName() const; bool hasDefaultValueDefined() const; YACSEvalAny *getDefaultValueDefined() const; bool isRandomVar() const; void declareRandomnessStatus(bool isRandom); bool hasSequenceOfValuesToEval() const; %extend { void setDefaultValue(PyObject *parameter) { if(parameter==Py_None) self->setDefaultValue(0); else if(PyFloat_Check(parameter)) { YACSEvalAnyDouble tmp(PyFloat_AsDouble(parameter)); self->setDefaultValue(&tmp); } else if(PyInt_Check(parameter)) { YACSEvalAnyInt tmp((int)PyInt_AsLong(parameter)); self->setDefaultValue(&tmp); } else throw YACS::Exception("PyWrap of YACSEvalInputPort::setParameter : unrecognized type !"); } void setSequenceOfValuesToEval(PyObject *vals) { if(!PyList_Check(vals)) { PyErr_SetString(PyExc_TypeError,"not a list"); return ; } int size(PyList_Size(vals)); YACSEvalSeqAny *valsCpp(0); if(size>0) { PyObject *elt0(PyList_GetItem(vals,0)); if(PyFloat_Check(elt0)) { std::vector zeVals; convertPyToDblArr(vals,zeVals); valsCpp=new YACSEvalSeqAnyDouble(zeVals); } else if(PyInt_Check(elt0)) { std::vector zeVals; convertPyToIntArr(vals,zeVals); valsCpp=new YACSEvalSeqAnyInt(zeVals); } else throw YACS::Exception("YACSEvalInputPort::setSequenceOfValuesToEval : only list[float] and list[int] actualy supported !"); } else valsCpp=YACSEvalSeqAny::BuildEmptyFromType(self->getTypeOfData()); self->setSequenceOfValuesToEval(valsCpp); delete valsCpp; } } private: YACSEvalInputPort(); }; class YACSEvalOutputPort : public YACSEvalPort { public: std::string getName() const; private: YACSEvalOutputPort(); }; class YACSEvalVirtualYACSContainer { public: std::string getChosenMachine() const; void setWantedMachine(const std::string& machine); std::vector listOfPropertyKeys() const; std::string getValueOfKey(const char *key) const; void setProperty(const std::string& key, const std::string &value); private: YACSEvalVirtualYACSContainer(); }; class YACSEvalResource { public: std::vector getAllChosenMachines() const; std::vector getAllFittingMachines() const; void setWantedMachine(const std::string& machine); std::size_t size() const; YACSEvalVirtualYACSContainer *at(std::size_t i) const; %extend { std::size_t __len__() const { return self->size(); } YACSEvalVirtualYACSContainer *__getitem__(std::size_t i) const { return self->at(i); } } private: YACSEvalResource(); }; class YACSEvalListOfResources { public: std::vector getAllChosenMachines() const; std::vector getAllFittingMachines() const; void setWantedMachine(const std::string& machine); std::size_t size() const; bool isInteractive() const; YACSEvalResource *at(std::size_t i) const; unsigned int getNumberOfProcsDeclared() const; %extend { std::size_t __len__() const { return self->size(); } YACSEvalResource *__getitem__(std::size_t i) const { return self->at(i); } } private: YACSEvalListOfResources(); }; class YACSEvalSession { public: YACSEvalSession(); ~YACSEvalSession(); void launch(); bool isLaunched() const; void checkLaunched() const; int getPort() const; std::string getCorbaConfigFileName() const; }; class YACSEvalExecParams { public: bool getStopASAPAfterErrorStatus() const; void setStopASAPAfterErrorStatus(bool newStatus); private: YACSEvalExecParams(); }; class YACSEvalYFX { public: static YACSEvalYFX *BuildFromFile(const std::string& xmlOfScheme); static YACSEvalYFX *BuildFromScheme(YACS::ENGINE::Proc *schema); YACSEvalExecParams *getParams() const; std::vector getFreeInputPorts() const; std::vector getFreeOutputPorts() const; void unlockAll(); bool isLocked() const; YACS::ENGINE::Proc *getUndergroundGeneratedGraph() const; YACSEvalListOfResources *giveResources(); void setParallelizeStatus(bool newVal); bool getParallelizeStatus() const; //void registerObserver(YACSEvalObserver *observer); %extend { void lockPortsForEvaluation(PyObject *inputsOfInterest, PyObject *outputsOfInterest) { std::vector outputsOfInterestCpp; if(PyList_Check(outputsOfInterest)) { int size(PyList_Size(outputsOfInterest)); for(int i=0;i(argp)); } } else { PyErr_SetString(PyExc_TypeError,"not a list"); return ; } // std::vector< YACSEvalInputPort * > inputsOfInterestCpp; if(PyList_Check(inputsOfInterest)) { int size(PyList_Size(inputsOfInterest)); for(int i=0;i(argp)); } } else { PyErr_SetString(PyExc_TypeError,"not a list"); return ; } self->lockPortsForEvaluation(inputsOfInterestCpp,outputsOfInterestCpp); } PyObject *getResults() const { std::vector retCpp(self->getResults()); std::size_t sz(retCpp.size()); PyObject *ret(PyList_New(sz)); for(std::size_t i=0;i(elt)); YACSEvalSeqAnyInt *elt2(dynamic_cast(elt)); if(elt1) { std::vector *zeArr(elt1->getInternal()); std::size_t sz2(zeArr->size()); PyObject *ret2(PyList_New(sz2)); for(std::size_t i2=0;i2 *zeArr(elt2->getInternal()); std::size_t sz2(zeArr->size()); PyObject *ret2(PyList_New(sz2)); for(std::size_t i2=0;i2run(session,ret1)); PyObject *ret(PyTuple_New(2)); PyObject *ret0Py(ret0?Py_True:Py_False); Py_XINCREF(ret0Py); PyTuple_SetItem(ret,0,ret0Py); PyTuple_SetItem(ret,1,PyInt_FromLong(ret1)); return ret; } } private: YACSEvalYFX(); };