itom  3.0.0
pythonQtConversion.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2016, 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 
34 #include "../global.h"
35 #include "../../common/itomPlotHandle.h"
36 #include "../../common/shape.h"
37 
38 #include "opencv/cv.h"
39 #include <qvariant.h>
40 #include <qmetaobject.h>
41 #include <qlist.h>
42 #include <qbytearray.h>
43 #include <qpointer.h>
44 
45 #include "../helper/qpropertyHelper.h"
46 
47 //#if ITOM_POINTCLOUDLIBRARY > 0
48 //Q_DECLARE_METATYPE(ito::PCLPointCloud)
49 //Q_DECLARE_METATYPE(QSharedPointer<ito::PCLPointCloud>)
50 //Q_DECLARE_METATYPE(QSharedPointer<ito::PCLPolygonMesh>)
51 //Q_DECLARE_METATYPE(ito::PCLPoint)
52 //Q_DECLARE_METATYPE(ito::PCLPolygonMesh)
53 //#endif
54 //
55 //Q_DECLARE_METATYPE(QSharedPointer<ito::DataObject>)
56 //Q_DECLARE_METATYPE(QPointer<ito::AddInDataIO>)
57 //Q_DECLARE_METATYPE(QPointer<ito::AddInActuator>)
58 //Q_DECLARE_METATYPE(ito::Shape)
59 //Q_DECLARE_METATYPE(QVector<ito::Shape>)
60 
61 
62 Q_DECLARE_METATYPE(ito::ItomPlotHandle)
63 Q_DECLARE_METATYPE(ito::PythonNone)
64 
65 namespace ito
66 {
67 
69 {
70 public:
71  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 };
72 
74  static PyObject* QStringToPyObject(const QString& str);
75 
77  static PyObject* QStringListToPyObject(const QStringList& list);
78 
80  static PyObject* QStringListToPyList(const QStringList& list);
81 
83  static PyObject* QDateToPyDate(const QDate& date);
84 
86  static PyObject* QDateTimeToPyDateTime(const QDateTime& datetime);
87 
89  static PyObject* QTimeToPyTime(const QTime& time);
90 
92  static QString PyObjGetRepresentation(PyObject* val);
93 
95  static QString PyObjGetString(PyObject* val) { bool ok; QString s = PyObjGetString(val, false, ok); return s; }
97  static QString PyObjGetString(PyObject* val, bool strict, bool &ok);
99  static std::string PyObjGetStdStringAsLatin1(PyObject* val, bool strict, bool &ok);
101  static QByteArray PyObjGetBytes(PyObject* val, bool strict, bool &ok);
103  static QSharedPointer<char> PyObjGetBytesShared(PyObject* val, bool strict, bool &ok);
105  static int PyObjGetInt(PyObject* val, bool strict, bool &ok);
107  static qint64 PyObjGetLongLong(PyObject* val, bool strict, bool &ok);
109  static quint64 PyObjGetULongLong(PyObject* val, bool strict, bool &ok);
111  static double PyObjGetDouble(PyObject* val, bool strict, bool &ok);
113  static QVector<double> PyObjGetDoubleArray(PyObject* val, bool strict, bool &ok);
115  static complex128 PyObjGetComplex(PyObject* val, bool strict, bool &ok);
117  static QVector<complex128> PyObjGetComplexArray(PyObject* val, bool strict, bool &ok);
119  static QVector<int> PyObjGetIntArray(PyObject* val, bool strict, bool &ok);
121  static bool PyObjGetBool(PyObject* val, bool strict, bool &ok);
123  static QVector<ito::Shape> PyObjGetShapeVector(PyObject* val, bool &ok);
124 
125 #if ITOM_POINTCLOUDLIBRARY > 0
126  static ito::PCLPointCloud PyObjGetPointCloud(PyObject *val, bool strict, bool &ok);
127  static ito::PCLPoint PyObjGetPoint(PyObject *val, bool strict, bool &ok);
128  static ito::PCLPolygonMesh PyObjGetPolygonMesh(PyObject *val, bool strict, bool &ok);
129 
130 
131  static ito::PCLPointCloud* PyObjGetPointCloudNewPtr(PyObject *val, bool strict, bool &ok);
132  static ito::PCLPolygonMesh* PyObjGetPolygonMeshNewPtr(PyObject *val, bool strict, bool &ok);
133 #endif
134 
135  static ito::DataObject* PyObjGetDataObjectNewPtr(PyObject *val, bool strict, bool &ok);
136 
137  static QSharedPointer<ito::DataObject> PyObjGetSharedDataObject(PyObject *val, bool &ok); //is always strict, only dataobjects are allowed
138 
140  static QStringList PyObjToStringList(PyObject* val, bool strict, bool& ok);
141 
142 
145  static QVariant PyObjToQVariant(PyObject* val, int type = -1);
146 
149  static bool PyObjToVoidPtr(PyObject* val, void **retPtr, int *retType, int type = -1, bool strict = false);
150 
152  static PyObject* GetPyBool(bool val);
153  static PyObject* QVariantToPyObject(const QVariant& v);
154 
155  static PyObject* QVariantMapToPyObject(const QVariantMap& m);
156  static PyObject* QVariantListToPyObject(const QVariantList& l);
157 
158 #if ITOM_POINTCLOUDLIBRARY > 0
159  static PyObject* PCLPointCloudToPyObject(const ito::PCLPointCloud& c);
160  static PyObject* PCLPointToPyObject(const ito::PCLPoint& c);
161  static PyObject* PCLPolygonMeshToPyObject(const ito::PCLPolygonMesh& c);
162 #endif
163 
164  static PyObject* DataObjectToPyObject(const ito::DataObject& dObj);
165  static PyObject* AddInBaseToPyObject(ito::AddInBase* aib);
166 
167  static PyObject* ConvertQtValueToPythonInternal(int type, const void* data);
168 
169  static PyObject* QByteArrayToPyUnicode(const QByteArray &ba, const char *errors = "replace");
170  static PyObject* QByteArrayToPyUnicodeSecure(const QByteArray &ba, const char *errors = "replace");
171  static PyObject* ByteArrayToPyUnicode(const char* byteArray, Py_ssize_t len = 0, const char *errors = "replace");
172 
173  static PyObject* PyUnicodeToPyByteObject(PyObject *unicode, const char *errors = "replace");
174 
175  friend class PythonEngine; //such that the pythonEngine can set the encoding values below
176 
177 private:
178  static unicodeEncodings textEncoding;
179  static QByteArray textEncodingName;
180 
185  static QHash<char*,PyObject*> m_pyBaseObjectStorage;
186  static void baseObjectDeleterDataObject(ito::DataObject *sharedObject)
187  {
188  QHash<char*,PyObject*>::iterator i = m_pyBaseObjectStorage.find((char*)sharedObject);
189  if(i != m_pyBaseObjectStorage.end())
190  {
191  Py_XDECREF(i.value());
192  m_pyBaseObjectStorage.erase(i);
193  }
194 
195  delete sharedObject;
196  }
197 };
198 
199 } //end namespace ito
200 
201 #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:496
Definition: pythonEngine.h:128
static QString PyObjGetString(PyObject *val)
get string value from py object
Definition: pythonQtConversion.h:95
Base class for all plugins.
Definition: addInInterface.h:356
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:185
Definition: apiFunctionsGraph.cpp:39
Conversion class with mainly static methods, which convert values between Qt and standard C++ data ty...
Definition: pythonQtConversion.h:68
class for a interval type containing the plot handle / unique id and name.
Definition: itomPlotHandle.h:48