itom  4.1.0
pythonWorkspace.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 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  #include "pythonWrapper.h"
37  #include "numpy/arrayobject.h"
38  #define _DEBUG
39  #else
40  #include "pythonWrapper.h"
41  #include "numpy/arrayobject.h"
42  #endif
43 #endif
44 
45 #include "../global.h"
46 
47 #include <qstring.h>
48 #include <qhash.h>
49 #include <qmutex.h>
50 #include <qset.h>
51 #include <qchar.h>
52 #include <qstringlist.h>
53 
54 #define PY_LIST_TUPLE 'l'
55 #define PY_MAPPING 'm'
56 #define PY_ATTR 'a'
57 #define PY_DICT 'd'
58 #define PY_NUMBER 'n'
59 #define PY_STRING 's'
60 
61 namespace ito
62 {
63 
64 class PyWorkspaceItem;
65 
66 //----------------------------------------------------------------------------------------------------------------------------------
72 {
73 public:
75  {
76  }
77  ~PyWorkspaceItem();
78  PyWorkspaceItem(const PyWorkspaceItem &other);
79 
80  enum ChildState
81  {
82  stateNoChilds = 0x00,
83  stateChilds = 0x01
84  };
85 
86  QString m_name;
87  QString m_key;
88  QString m_type;
89  QString m_value;
90  QString m_extendedValue;
92  bool m_exist;
95  QHash<QString, PyWorkspaceItem*> m_childs;
96 };
97 
98 
99 class PyWorkspaceContainer : public QObject //each container has one view
100 {
101  Q_OBJECT
102 public:
103 
104  PyWorkspaceContainer(bool globalNotLocal);
106 
107  void clear();
108  void loadDictionary(PyObject *obj, const QString &fullNameParentItem = "");
109 
110  inline bool isGlobalWorkspace() const { return m_globalNotLocal; }
111  inline bool isRoot(PyWorkspaceItem *item) const { return item == &m_rootItem; }
112  inline void emitGetChildNodes(PyWorkspaceContainer *container, QString fullNameParentItem) { emit getChildNodes(container,fullNameParentItem); }
113 
114  ito::PyWorkspaceItem* getItemByFullName(const QString &fullname);
115 
116  QMutex m_accessMutex;
117  QSet<QString> m_expandedFullNames; //this full names are recently expanded in the corresponding view (full name is "." + name + "." + subname + "." + subsubname ...)
118  PyWorkspaceItem m_rootItem;
119 
120  static QChar delimiter;
121 
122 private:
123  void loadDictionaryRec(PyObject *obj, const QString &fullNameParentItem, PyWorkspaceItem *parentItem, QStringList &deletedKeys);
124  void parseSinglePyObject(PyWorkspaceItem *item, PyObject *value, QString &fullName, QStringList &deletedKeys, int &m_compatibleParamBaseType);
125 
126  QSet<QByteArray> m_blackListType;
127  bool m_globalNotLocal;
128 
129  PyObject *dictUnicode;
130  PyObject *slotsUnicode;
131 
132 signals:
133  void updateAvailable(PyWorkspaceItem *rootItem, QString fullNameRoot, QStringList recentlyDeletedFullNames); //TODO
134  void getChildNodes(PyWorkspaceContainer *container, QString fullNameParentItem); //signal catched by python //TODO
135 };
136 
137 } //end namespace ito
138 
139 
140 #endif
Definition: pythonWorkspace.h:83
QString m_name
Definition: pythonWorkspace.h:86
QString m_key
Definition: pythonWorkspace.h:87
int m_compatibleParamBaseType
Definition: pythonWorkspace.h:91
Definition: pythonWorkspace.h:82
Definition: apiFunctionsGraph.cpp:39
QString m_type
Definition: pythonWorkspace.h:88
bool m_isarrayelement
Definition: pythonWorkspace.h:93
static QChar delimiter
Definition: pythonWorkspace.h:120
every item in the workspace is represented by one PyWorkspaceItem
Definition: pythonWorkspace.h:71
ChildState m_childState
Definition: pythonWorkspace.h:94
Definition: pythonWorkspace.h:99
ChildState
Definition: pythonWorkspace.h:80