itom
Loading...
Searching...
No Matches
pythonQtConversion.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität 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
48Q_DECLARE_METATYPE(ito::PythonNone)
49
50namespace ito
51{
52
54{
55public:
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 unsigned int PyObjGetUInt(PyObject* val, bool strict, bool &ok);
94 static qint64 PyObjGetLongLong(PyObject* val, bool strict, bool &ok);
96 static quint64 PyObjGetULongLong(PyObject* val, bool strict, bool &ok);
98 static double PyObjGetDouble(PyObject* val, bool strict, bool &ok);
100 static QVector<double> PyObjGetDoubleArray(PyObject* val, bool strict, bool &ok);
102 static complex128 PyObjGetComplex(PyObject* val, bool strict, bool &ok);
104 static QVector<complex128> PyObjGetComplexArray(PyObject* val, bool strict, bool &ok);
106 static QVector<int> PyObjGetIntArray(PyObject* val, bool strict, bool &ok);
108 static bool PyObjGetBool(PyObject* val, bool strict, bool &ok);
110 static QVector<ito::Shape> PyObjGetShapeVector(PyObject* val, bool &ok);
111
113 static QVector<ito::ByteArray> PyObjGetByteArrayList(PyObject *val, bool strict, bool &ok);
114
115#if ITOM_POINTCLOUDLIBRARY > 0
116 static ito::PCLPointCloud PyObjGetPointCloud(PyObject *val, bool strict, bool &ok);
117 static ito::PCLPoint PyObjGetPoint(PyObject *val, bool strict, bool &ok);
118 static ito::PCLPolygonMesh PyObjGetPolygonMesh(PyObject *val, bool strict, bool &ok);
119
120
121 static ito::PCLPointCloud* PyObjGetPointCloudNewPtr(PyObject *val, bool strict, bool &ok);
122 static ito::PCLPolygonMesh* PyObjGetPolygonMeshNewPtr(PyObject *val, bool strict, bool &ok);
123#endif
124
125 static ito::DataObject* PyObjGetDataObjectNewPtr(PyObject *val, bool strict, bool &ok, ito::RetVal *retVal = nullptr, bool addNumpyOrgTags = false);
126
131 static QSharedPointer<ito::DataObject> PyObjGetSharedDataObject(PyObject *val, bool strict, bool &ok, ito::RetVal *retVal = nullptr);
132
134 static QStringList PyObjToStringList(PyObject* val, bool strict, bool& ok);
135
136
139 static QVariant PyObjToQVariant(PyObject* val, int type = -1);
140
143 static bool PyObjToVoidPtr(PyObject* val, void **retPtr, int *retType, int type = -1, bool strict = false);
144
146 static PyObject* GetPyBool(bool val);
147 static PyObject* QVariantToPyObject(const QVariant& v);
148
149 static PyObject* QVariantMapToPyObject(const QVariantMap& m);
150 static PyObject* QVariantListToPyObject(const QVariantList& l);
151
152#if ITOM_POINTCLOUDLIBRARY > 0
153 static PyObject* PCLPointCloudToPyObject(const ito::PCLPointCloud& c);
154 static PyObject* PCLPointToPyObject(const ito::PCLPoint& c);
155 static PyObject* PCLPolygonMeshToPyObject(const ito::PCLPolygonMesh& c);
156#endif
157
158 static PyObject* DataObjectToPyObject(const ito::DataObject& dObj);
159 static PyObject* AddInBaseToPyObject(ito::AddInBase* aib);
160
161 static PyObject* ConvertQtValueToPythonInternal(int type, const void* data);
162
163 static PyObject* QByteArrayToPyUnicode(const QByteArray &ba, const char *errors = "replace");
164 static PyObject* QByteArrayToPyUnicodeSecure(const QByteArray &ba, const char *errors = "replace");
165 static PyObject* QByteArrayUtf8ToPyUnicode(const QByteArray &ba, const char *errors = "replace");
166 static PyObject* QByteArrayUtf8ToPyUnicodeSecure(const QByteArray &ba, const char *errors = "replace");
167 static PyObject* ByteArrayToPyUnicode(const char* byteArray, Py_ssize_t len = 0, const char *errors = "replace");
168
169 static PyObject* PyUnicodeToPyByteObject(PyObject *unicode, const char *errors = "replace");
170
171 friend class PythonEngine; //such that the pythonEngine can set the encoding values below
172
173private:
174 static UnicodeEncodings textEncoding;
175 static QByteArray textEncodingName;
176
177 static int guessQMetaTypeFromPyObject(PyObject* val);
178
187 static QHash<char*,PyObject*> m_pyBaseObjectStorage;
188 static void baseObjectDeleterDataObject(ito::DataObject *sharedObject);
189};
190
191} //end namespace ito
192
193#endif
Base class for all plugins.
Definition addInInterface.h:386
dataObject contains a n-dimensional matrix
Definition dataobj.h:591
generic class that covers one single point cloud of different possible types provided by the Point Cl...
Definition pclStructures.h:293
generic class that covers one single point of different possible types provided by the Point Cloud Li...
Definition pclStructures.h:74
generic class that covers a shared pointer to pcl::PolygonMesh that is a class for a polygonal mesh p...
Definition pclStructures.h:668
Definition pythonEngine.h:118
empty class that is the QVariant registered type for None in Python. Nothing more than this.
Definition pythonNone.h:34
Conversion class with mainly static methods, which convert values between Qt and standard C++ data ty...
Definition pythonQtConversion.h:54
static QVariant PyObjToQVariant(PyObject *val, int type=-1)
conversion from PyObject* to QVariant
Definition pythonQtConversion.cpp:1838
static PyObject * ConvertQtValueToPythonInternal(int type, const void *data)
method internally used for conversion from given type-id (QMetaType) and corresponding char*-pointer ...
Definition pythonQtConversion.cpp:3216
static qint64 PyObjGetLongLong(PyObject *val, bool strict, bool &ok)
get int64 from py object
Definition pythonQtConversion.cpp:788
static double PyObjGetDouble(PyObject *val, bool strict, bool &ok)
get double from py object
Definition pythonQtConversion.cpp:1062
static complex128 PyObjGetComplex(PyObject *val, bool strict, bool &ok)
get complex from py object
Definition pythonQtConversion.cpp:1165
static int PyObjGetInt(PyObject *val, bool strict, bool &ok)
get int from py object
Definition pythonQtConversion.cpp:487
static QVector< ito::ByteArray > PyObjGetByteArrayList(PyObject *val, bool strict, bool &ok)
get ito::ByteArray list from py object
Definition pythonQtConversion.cpp:379
static PyObject * QDateTimeToPyDateTime(const QDateTime &datetime)
converts QDateTime to Python datetime.datetime object
Definition pythonQtConversion.cpp:3007
static bool PyObjGetBool(PyObject *val, bool strict, bool &ok)
get bool from py object
Definition pythonQtConversion.cpp:426
static QVector< double > PyObjGetDoubleArray(PyObject *val, bool strict, bool &ok)
get double-array from py object
Definition pythonQtConversion.cpp:1129
static QVector< int > PyObjGetIntArray(PyObject *val, bool strict, bool &ok)
get int-array from py object
Definition pythonQtConversion.cpp:1267
static PyObject * QStringToPyObject(const QString &str)
converts QString to Python string (unicode!)
Definition pythonQtConversion.cpp:2934
static unsigned int PyObjGetUInt(PyObject *val, bool strict, bool &ok)
get unsigned int from py object
Definition pythonQtConversion.cpp:645
static PyObject * QVariantMapToPyObject(const QVariantMap &m)
conversion from given QVariantMap to python-dictionary.
Definition pythonQtConversion.cpp:3052
static QStringList PyObjToStringList(PyObject *val, bool strict, bool &ok)
create a string list from python sequence
Definition pythonQtConversion.cpp:77
static PyObject * QDateToPyDate(const QDate &date)
converts QDate to Python datetime.date object
Definition pythonQtConversion.cpp:2997
static QString PyObjGetRepresentation(PyObject *val)
get string representation of py object
Definition pythonQtConversion.cpp:112
static QSharedPointer< char > PyObjGetBytesShared(PyObject *val, bool strict, bool &ok)
get bytes from py object
Definition pythonQtConversion.cpp:315
static PyObject * QTimeToPyTime(const QTime &time)
converts QTime to Python datetime.time object
Definition pythonQtConversion.cpp:3019
static quint64 PyObjGetULongLong(PyObject *val, bool strict, bool &ok)
get int64 from py object
Definition pythonQtConversion.cpp:931
static QByteArray PyObjGetBytes(PyObject *val, bool strict, bool &ok)
get bytes from py object
Definition pythonQtConversion.cpp:266
static bool PyObjToVoidPtr(PyObject *val, void **retPtr, int *retType, int type=-1, bool strict=false)
tries to convert PyObject* to known data type and returns deep-copy of the value, given as char*
Definition pythonQtConversion.cpp:2336
static QVector< complex128 > PyObjGetComplexArray(PyObject *val, bool strict, bool &ok)
get complex-array from py object
Definition pythonQtConversion.cpp:1231
static QVector< ito::Shape > PyObjGetShapeVector(PyObject *val, bool &ok)
get shape vector from py object
Definition pythonQtConversion.cpp:1303
static PyObject * QStringListToPyObject(const QStringList &list)
converts QStringList to Python tuple
Definition pythonQtConversion.cpp:2960
static PyObject * QVariantListToPyObject(const QVariantList &l)
conversion from given QVariantList to python-tuple.
Definition pythonQtConversion.cpp:3182
static std::string PyObjGetStdStringAsLatin1(PyObject *val, bool strict, bool &ok)
get std::string value from py object. std::string has latin1 encoding
Definition pythonQtConversion.cpp:215
static PyObject * GetPyBool(bool val)
convert QVariant from PyObject
Definition pythonQtConversion.cpp:2918
static QString PyObjGetString(PyObject *val)
get string value from py object
Definition pythonQtConversion.h:80
static PyObject * QStringListToPyList(const QStringList &list)
converts QStringList to Python list
Definition pythonQtConversion.cpp:2984
static QHash< char *, PyObject * > m_pyBaseObjectStorage
Definition pythonQtConversion.h:187
static PyObject * QVariantToPyObject(const QVariant &v)
conversion from given QVariant to appropriate PyObject*
Definition pythonQtConversion.cpp:3037
static QSharedPointer< ito::DataObject > PyObjGetSharedDataObject(PyObject *val, bool strict, bool &ok, ito::RetVal *retVal=nullptr)
Definition pythonQtConversion.cpp:1538
Class for managing status values (like errors or warning)
Definition retVal.h:54
Definition apiFunctionsGraph.cpp:40