itom  3.0.0
pythonWorkspace.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 PYTHONWORKSPACE_H
24 #define PYTHONWORKSPACE_H
25 
26 #ifndef Q_MOC_RUN
27  #define PY_ARRAY_UNIQUE_SYMBOL itom_ARRAY_API //see numpy help ::array api :: Miscellaneous :: Importing the api (this line must bebefore include global.h)
28  #define NO_IMPORT_ARRAY
29 
30  #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
31 
32  //python
33  // see http://vtk.org/gitweb?p=VTK.git;a=commitdiff;h=7f3f750596a105d48ea84ebfe1b1c4ca03e0bab3
34  #if (defined _DEBUG) && (defined WIN32)
35  #undef _DEBUG
36  #if (defined linux) | (defined CMAKE)
37  #include "Python.h"
38  #include "numpy/arrayobject.h"
39  #elif (defined __APPLE__) | (defined CMAKE)
40  #include "Python.h"
41  #include "numpy/arrayobject.h"
42  #else
43  #include "Python.h"
44  #include "../Lib/site-packages/numpy/core/include/numpy/arrayobject.h" //for numpy arrays
45  #endif
46  #define _DEBUG
47  #else
48  #ifdef linux
49  #include "Python.h"
50  #include "numpy/arrayobject.h"
51  #elif (defined __APPLE__)
52  #include "Python.h"
53  #include "numpy/arrayobject.h"
54  #else
55  #include "Python.h"
56  #include "../Lib/site-packages/numpy/core/include/numpy/arrayobject.h" //for numpy arrays
57  #endif
58  #endif
59 #endif
60 
61 #include "../global.h"
62 
63 #include <qstring.h>
64 #include <qhash.h>
65 #include <qmutex.h>
66 #include <qset.h>
67 #include <qchar.h>
68 #include <qstringlist.h>
69 
70 #define PY_LIST_TUPLE 'l'
71 #define PY_MAPPING 'm'
72 #define PY_ATTR 'a'
73 #define PY_DICT 'd'
74 #define PY_NUMBER 'n'
75 #define PY_STRING 's'
76 
77 namespace ito
78 {
79 
80 class PyWorkspaceItem;
81 
82 //----------------------------------------------------------------------------------------------------------------------------------
88 {
89 public:
91  {
92  }
93  ~PyWorkspaceItem();
94  PyWorkspaceItem(const PyWorkspaceItem &other);
95 
96  enum ChildState
97  {
98  stateNoChilds = 0x00,
99  stateChilds = 0x01
100  };
101 
102  QString m_name;
103  QString m_key;
104  QString m_type;
105  QString m_value;
106  QString m_extendedValue;
108  bool m_exist;
111  QHash<QString, PyWorkspaceItem*> m_childs;
112 };
113 
114 
115 class PyWorkspaceContainer : public QObject //each container has one view
116 {
117  Q_OBJECT
118 public:
119 
120  PyWorkspaceContainer(bool globalNotLocal);
122 
123  void clear();
124  void loadDictionary(PyObject *obj, const QString &fullNameParentItem = "");
125 
126  inline bool isGlobalWorkspace() const { return m_globalNotLocal; }
127  inline bool isRoot(PyWorkspaceItem *item) const { return item == &m_rootItem; }
128  inline void emitGetChildNodes(PyWorkspaceContainer *container, QString fullNameParentItem) { emit getChildNodes(container,fullNameParentItem); }
129 
130  ito::PyWorkspaceItem* getItemByFullName(const QString &fullname);
131 
132  QMutex m_accessMutex;
133  QSet<QString> m_expandedFullNames; //this full names are recently expanded in the corresponding view (full name is "." + name + "." + subname + "." + subsubname ...)
134  PyWorkspaceItem m_rootItem;
135 
136  static QChar delimiter;
137 
138 private:
139  void loadDictionaryRec(PyObject *obj, const QString &fullNameParentItem, PyWorkspaceItem *parentItem, QStringList &deletedKeys);
140  void parseSinglePyObject(PyWorkspaceItem *item, PyObject *value, QString &fullName, QStringList &deletedKeys, int &m_compatibleParamBaseType);
141 
142  QSet<QByteArray> m_blackListType;
143  bool m_globalNotLocal;
144 
145  PyObject *dictUnicode;
146 
147 signals:
148  void updateAvailable(PyWorkspaceItem *rootItem, QString fullNameRoot, QStringList recentlyDeletedFullNames); //TODO
149  void getChildNodes(PyWorkspaceContainer *container, QString fullNameParentItem); //signal catched by python //TODO
150 };
151 
152 } //end namespace ito
153 
154 
155 #endif
Definition: pythonWorkspace.h:99
QString m_name
Definition: pythonWorkspace.h:102
QString m_key
Definition: pythonWorkspace.h:103
int m_compatibleParamBaseType
Definition: pythonWorkspace.h:107
Definition: pythonWorkspace.h:98
Definition: apiFunctionsGraph.cpp:39
QString m_type
Definition: pythonWorkspace.h:104
bool m_isarrayelement
Definition: pythonWorkspace.h:109
static QChar delimiter
Definition: pythonWorkspace.h:136
every item in the workspace is represented by one PyWorkspaceItem
Definition: pythonWorkspace.h:87
ChildState m_childState
Definition: pythonWorkspace.h:110
Definition: pythonWorkspace.h:115
ChildState
Definition: pythonWorkspace.h:96