itom 2.2.1
K:/git-itom/sources/itom/Qitom/python/pythonCommon.h
00001 /* ********************************************************************
00002     itom software
00003     URL: http://www.uni-stuttgart.de/ito
00004     Copyright (C) 2016, Institut fuer Technische Optik (ITO),
00005     Universitaet Stuttgart, Germany
00006 
00007     This file is part of itom.
00008   
00009     itom is free software; you can redistribute it and/or modify it
00010     under the terms of the GNU Library General Public Licence as published by
00011     the Free Software Foundation; either version 2 of the Licence, or (at
00012     your option) any later version.
00013 
00014     itom is distributed in the hope that it will be useful, but
00015     WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library
00017     General Public Licence for more details.
00018 
00019     You should have received a copy of the GNU Library General Public License
00020     along with itom. If not, see <http://www.gnu.org/licenses/>.
00021 *********************************************************************** */
00022 
00023 #ifndef PYTHONCOMMON_H
00024 #define PYTHONCOMMON_H
00025 
00026 #ifndef NPY_1_7_API_VERSION
00027     #define NPY_1_7_API_VERSION 0x00000007
00028 #endif
00029 #ifndef NPY_1_8_API_VERSION
00030     #define NPY_1_8_API_VERSION 0x00000008
00031 #endif
00032 
00033 #ifndef Q_MOC_RUN
00034     /* includes */
00035     //python
00036     // see http://vtk.org/gitweb?p=VTK.git;a=commitdiff;h=7f3f750596a105d48ea84ebfe1b1c4ca03e0bab3
00037     #if (defined _DEBUG) && (defined WIN32)
00038         #undef _DEBUG
00039         #include "Python.h"
00040         #define _DEBUG
00041     #else
00042         #include "Python.h"
00043     #endif
00044 #endif
00045 
00046 #include "../../common/sharedStructures.h"
00047 
00048 #include <qvector.h>
00049 #include <qvariant.h>
00050 
00051 namespace ito
00052 {
00053 
00054     ito::RetVal checkAndSetParamVal(PyObject *tempObj, ito::Param *param, int *set);
00055     ito::RetVal checkAndSetParamVal(PyObject *pyObj, const ito::Param *defaultParam, ito::ParamBase &outParam, int *set);
00057     PyObject* PrntOutParams(const QVector<ito::Param> *params, bool asErr, bool addInfos, const int num, bool printToStdStream = true);
00058     PyObject *parseParamMetaAsDict(const ito::ParamMeta *meta);
00059     void errOutInitParams(const QVector<ito::Param> *params, const int num, const char *reason);
00060     ito::RetVal parseInitParams(const QVector<ito::Param> *defaultParamListMand, const QVector<ito::Param> *defaultParamListOpt, PyObject *args, PyObject *kwds, QVector<ito::ParamBase> &paramListMandOut, QVector<ito::ParamBase> &paramListOptOut);
00061     ito::RetVal copyParamVector(const QVector<ito::ParamBase> *paramVecIn, QVector<ito::ParamBase> &paramVecOut);
00062     ito::RetVal copyParamVector(const QVector<ito::Param> *paramVecIn, QVector<ito::Param> &paramVecOut);
00063     ito::RetVal copyParamVector(const QVector<ito::Param> *paramVecIn, QVector<ito::ParamBase> &paramVecOut);
00064     ito::RetVal createEmptyParamBaseFromParamVector(const QVector<ito::Param> *paramVecIn, QVector<ito::ParamBase> &paramVecOut);
00065 
00067     ito::RetVal findAndDeleteReservedInitKeyWords(PyObject *kwds, bool * enableAutoLoadParams);
00068 
00069     PyObject* buildFilterOutputValues(QVector<QVariant> *outVals, ito::RetVal &retValue);
00070 
00071     class PythonCommon
00072     {
00073         public:
00074 
00075             enum tErrMsg
00076             {
00077                 noMsg = 0,
00078                 loadPlugin = 1,
00079                 execFunc = 2,
00080                 invokeFunc = 3,
00081                 getProperty = 4,
00082                 runFunc = 5
00083             
00084             };
00085 
00086             static bool transformRetValToPyException(ito::RetVal &retVal, PyObject *exceptionIfError = PyExc_RuntimeError, PyObject *exceptionIfWarning = PyExc_RuntimeWarning);
00087             static bool setReturnValueMessage(ito::RetVal &retVal, const QString &objName, const tErrMsg &errorMSG, PyObject *exceptionIfError = PyExc_RuntimeError, PyObject *exceptionIfWarning = PyExc_RuntimeWarning);
00088             static bool setReturnValueMessage(ito::RetVal &retVal, const char *objName, const tErrMsg &errorMSG, PyObject *exceptionIfError = PyExc_RuntimeError, PyObject *exceptionIfWarning = PyExc_RuntimeWarning);
00089     };
00090 
00091 } //end namespace ito
00092 
00093 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Friends