itom  4.1.0
pythonQtConversion.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom.
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  itom is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17  General Public Licence for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with itom. If not, see <http://www.gnu.org/licenses/>.
21 *********************************************************************** */
22 
23 #ifndef PYTHONQTCONVERSION_H
24 #define PYTHONQTCONVERSION_H
25 
26 #include "pythonDataObject.h"
27 #include "pythonPlugins.h"
28 #include "pythonRegion.h"
29 #include "pythonPCL.h"
30 #include "pythonAutoInterval.h"
31 #include "pythonNone.h"
32 #include "datetime.h"
33 #include "patchlevel.h"
34 
35 #include "../global.h"
36 #include "../../common/itomPlotHandle.h"
37 #include "../../common/shape.h"
38 
39 #include "opencv2/opencv.hpp"
40 #include <qvariant.h>
41 #include <qmetaobject.h>
42 #include <qlist.h>
43 #include <qbytearray.h>
44 #include <qpointer.h>
45 
46 #include "../helper/qpropertyHelper.h"
47 
48 Q_DECLARE_METATYPE(ito::PythonNone)
49 
50 namespace ito
51 {
52 
54 {
55 public:
56  enum unicodeEncodings { utf_8, latin_1, iso_8859_1, mbcs, ascii, utf_16, utf_16_LE, utf_16_BE, utf_32, utf_32_BE, utf_32_LE, other };
57 
59  static PyObject* QStringToPyObject(const QString& str);
60 
62  static PyObject* QStringListToPyObject(const QStringList& list);
63 
65  static PyObject* QStringListToPyList(const QStringList& list);
66 
68  static PyObject* QDateToPyDate(const QDate& date);
69 
71  static PyObject* QDateTimeToPyDateTime(const QDateTime& datetime);
72 
74  static PyObject* QTimeToPyTime(const QTime& time);
75 
77  static QString PyObjGetRepresentation(PyObject* val);
78 
80  static QString PyObjGetString(PyObject* val) { bool ok; QString s = PyObjGetString(val, false, ok); return s; }
82  static QString PyObjGetString(PyObject* val, bool strict, bool &ok);
84  static std::string PyObjGetStdStringAsLatin1(PyObject* val, bool strict, bool &ok);
86  static QByteArray PyObjGetBytes(PyObject* val, bool strict, bool &ok);
88  static QSharedPointer<char> PyObjGetBytesShared(PyObject* val, bool strict, bool &ok);
90  static int PyObjGetInt(PyObject* val, bool strict, bool &ok);
92  static qint64 PyObjGetLongLong(PyObject* val, bool strict, bool &ok);
94  static quint64 PyObjGetULongLong(PyObject* val, bool strict, bool &ok);
96  static double PyObjGetDouble(PyObject* val, bool strict, bool &ok);
98  static QVector<double> PyObjGetDoubleArray(PyObject* val, bool strict, bool &ok);
100  static complex128 PyObjGetComplex(PyObject* val, bool strict, bool &ok);
102  static QVector<complex128> PyObjGetComplexArray(PyObject* val, bool strict, bool &ok);
104  static QVector<int> PyObjGetIntArray(PyObject* val, bool strict, bool &ok);
106  static bool PyObjGetBool(PyObject* val, bool strict, bool &ok);
108  static QVector<ito::Shape> PyObjGetShapeVector(PyObject* val, bool &ok);
109 
110 #if ITOM_POINTCLOUDLIBRARY > 0
111  static ito::PCLPointCloud PyObjGetPointCloud(PyObject *val, bool strict, bool &ok);
112  static ito::PCLPoint PyObjGetPoint(PyObject *val, bool strict, bool &ok);
113  static ito::PCLPolygonMesh PyObjGetPolygonMesh(PyObject *val, bool strict, bool &ok);
114 
115 
116  static ito::PCLPointCloud* PyObjGetPointCloudNewPtr(PyObject *val, bool strict, bool &ok);
117  static ito::PCLPolygonMesh* PyObjGetPolygonMeshNewPtr(PyObject *val, bool strict, bool &ok);
118 #endif
119 
120  static ito::DataObject* PyObjGetDataObjectNewPtr(PyObject *val, bool strict, bool &ok, ito::RetVal *retVal = NULL);
121 
122  static QSharedPointer<ito::DataObject> PyObjGetSharedDataObject(PyObject *val, bool &ok); //is always strict, only dataobjects are allowed
123 
125  static QStringList PyObjToStringList(PyObject* val, bool strict, bool& ok);
126 
127 
130  static QVariant PyObjToQVariant(PyObject* val, int type = -1);
131 
134  static bool PyObjToVoidPtr(PyObject* val, void **retPtr, int *retType, int type = -1, bool strict = false);
135 
137  static PyObject* GetPyBool(bool val);
138  static PyObject* QVariantToPyObject(const QVariant& v);
139 
140  static PyObject* QVariantMapToPyObject(const QVariantMap& m);
141  static PyObject* QVariantListToPyObject(const QVariantList& l);
142 
143 #if ITOM_POINTCLOUDLIBRARY > 0
144  static PyObject* PCLPointCloudToPyObject(const ito::PCLPointCloud& c);
145  static PyObject* PCLPointToPyObject(const ito::PCLPoint& c);
146  static PyObject* PCLPolygonMeshToPyObject(const ito::PCLPolygonMesh& c);
147 #endif
148 
149  static PyObject* DataObjectToPyObject(const ito::DataObject& dObj);
150  static PyObject* AddInBaseToPyObject(ito::AddInBase* aib);
151 
152  static PyObject* ConvertQtValueToPythonInternal(int type, const void* data);
153 
154  static PyObject* QByteArrayToPyUnicode(const QByteArray &ba, const char *errors = "replace");
155  static PyObject* QByteArrayToPyUnicodeSecure(const QByteArray &ba, const char *errors = "replace");
156  static PyObject* ByteArrayToPyUnicode(const char* byteArray, Py_ssize_t len = 0, const char *errors = "replace");
157 
158  static PyObject* PyUnicodeToPyByteObject(PyObject *unicode, const char *errors = "replace");
159 
160  friend class PythonEngine; //such that the pythonEngine can set the encoding values below
161 
162 private:
163  static unicodeEncodings textEncoding;
164  static QByteArray textEncodingName;
165 
174  static QHash<char*,PyObject*> m_pyBaseObjectStorage;
175  static void baseObjectDeleterDataObject(ito::DataObject *sharedObject);
176 };
177 
178 } //end namespace ito
179 
180 #endif
generic class that covers one single point of different possible types provided by the Point Cloud Li...
Definition: pclStructures.h:73
generic class that covers one single point cloud of different possible types provided by the Point Cl...
Definition: pclStructures.h:292
dataObject contains a n-dimensional matrix
Definition: dataobj.h:511
Definition: pythonEngine.h:114
static QString PyObjGetString(PyObject *val)
get string value from py object
Definition: pythonQtConversion.h:80
Class for managing status values (like errors or warning)
Definition: retVal.h:54
Base class for all plugins.
Definition: addInInterface.h:385
generic class that covers a shared pointer to pcl::PolygonMesh that is a class for a polygonal mesh p...
Definition: pclStructures.h:667
static QHash< char *, PyObject * > m_pyBaseObjectStorage
Definition: pythonQtConversion.h:174
Definition: apiFunctionsGraph.cpp:39
empty class that is the QVariant registered type for None in Python. Nothing more than this...
Definition: pythonNone.h:33
Conversion class with mainly static methods, which convert values between Qt and standard C++ data ty...
Definition: pythonQtConversion.h:53