itom 2.2.1
|
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 PYTHONWORKSPACE_H 00024 #define PYTHONWORKSPACE_H 00025 00026 #ifndef Q_MOC_RUN 00027 #define PY_ARRAY_UNIQUE_SYMBOL itom_ARRAY_API //see numpy help ::array api :: Miscellaneous :: Importing the api (this line must bebefore include global.h) 00028 #define NO_IMPORT_ARRAY 00029 00030 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION 00031 00032 //python 00033 // see http://vtk.org/gitweb?p=VTK.git;a=commitdiff;h=7f3f750596a105d48ea84ebfe1b1c4ca03e0bab3 00034 #if (defined _DEBUG) && (defined WIN32) 00035 #undef _DEBUG 00036 #if (defined linux) | (defined CMAKE) 00037 #include "Python.h" 00038 #include "numpy/arrayobject.h" 00039 #elif (defined __APPLE__) | (defined CMAKE) 00040 #include "Python.h" 00041 #include "numpy/arrayobject.h" 00042 #else 00043 #include "Python.h" 00044 #include "../Lib/site-packages/numpy/core/include/numpy/arrayobject.h" //for numpy arrays 00045 #endif 00046 #define _DEBUG 00047 #else 00048 #ifdef linux 00049 #include "Python.h" 00050 #include "numpy/arrayobject.h" 00051 #elif (defined __APPLE__) 00052 #include "Python.h" 00053 #include "numpy/arrayobject.h" 00054 #else 00055 #include "Python.h" 00056 #include "../Lib/site-packages/numpy/core/include/numpy/arrayobject.h" //for numpy arrays 00057 #endif 00058 #endif 00059 #endif 00060 00061 #include "../global.h" 00062 00063 #include <qstring.h> 00064 #include <qhash.h> 00065 #include <qmutex.h> 00066 #include <qset.h> 00067 #include <qchar.h> 00068 #include <qstringlist.h> 00069 00070 #define PY_LIST_TUPLE 'l' 00071 #define PY_MAPPING 'm' 00072 #define PY_ATTR 'a' 00073 #define PY_DICT 'd' 00074 #define PY_NUMBER 'n' 00075 #define PY_STRING 's' 00076 00077 namespace ito 00078 { 00079 00080 class PyWorkspaceItem; 00081 00082 //---------------------------------------------------------------------------------------------------------------------------------- 00087 class PyWorkspaceItem 00088 { 00089 public: 00090 PyWorkspaceItem() : m_compatibleParamBaseType(0), m_exist(false), m_isarrayelement(false), m_childState(stateNoChilds) 00091 { 00092 } 00093 ~PyWorkspaceItem(); 00094 PyWorkspaceItem(const PyWorkspaceItem &other); 00095 00096 enum ChildState 00097 { 00098 stateNoChilds = 0x00, 00099 stateChilds = 0x01 00100 }; 00101 00102 QString m_name; 00103 QString m_key; 00104 QString m_type; 00105 QString m_value; 00106 QString m_extendedValue; 00107 int m_compatibleParamBaseType; 00108 bool m_exist; 00109 bool m_isarrayelement; 00110 ChildState m_childState; 00111 QHash<QString, PyWorkspaceItem*> m_childs; 00112 }; 00113 00114 00115 class PyWorkspaceContainer : public QObject //each container has one view 00116 { 00117 Q_OBJECT 00118 public: 00119 00120 PyWorkspaceContainer(bool globalNotLocal); 00121 ~PyWorkspaceContainer(); 00122 00123 void clear(); 00124 void loadDictionary(PyObject *obj, const QString &fullNameParentItem = ""); 00125 00126 inline bool isGlobalWorkspace() const { return m_globalNotLocal; } 00127 inline bool isRoot(PyWorkspaceItem *item) const { return item == &m_rootItem; } 00128 inline void emitGetChildNodes(PyWorkspaceContainer *container, QString fullNameParentItem) { emit getChildNodes(container,fullNameParentItem); } 00129 00130 ito::PyWorkspaceItem* getItemByFullName(const QString &fullname); 00131 00132 QMutex m_accessMutex; 00133 QSet<QString> m_expandedFullNames; //this full names are recently expanded in the corresponding view (full name is "." + name + "." + subname + "." + subsubname ...) 00134 PyWorkspaceItem m_rootItem; 00135 00136 static QChar delimiter; 00137 00138 private: 00139 void loadDictionaryRec(PyObject *obj, const QString &fullNameParentItem, PyWorkspaceItem *parentItem, QStringList &deletedKeys); 00140 void parseSinglePyObject(PyWorkspaceItem *item, PyObject *value, QString &fullName, QStringList &deletedKeys, int &m_compatibleParamBaseType); 00141 00142 QSet<QByteArray> m_blackListType; 00143 bool m_globalNotLocal; 00144 00145 PyObject *dictUnicode; 00146 00147 signals: 00148 void updateAvailable(PyWorkspaceItem *rootItem, QString fullNameRoot, QStringList recentlyDeletedFullNames); //TODO 00149 void getChildNodes(PyWorkspaceContainer *container, QString fullNameParentItem); //signal catched by python //TODO 00150 }; 00151 00152 } //end namespace ito 00153 00154 00155 #endif