itom 1.4.0
D:/git-itom/sources/itom/Qitom/python/pythonWorkspace.h
00001 /* ********************************************************************
00002     itom software
00003     URL: http://www.uni-stuttgart.de/ito
00004     Copyright (C) 2013, 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     #ifndef ITOM_NPDATAOBJECT
00031         #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION //see comment in pythonNpDataObject.cpp
00032     #endif
00033 
00034     //python
00035     // see http://vtk.org/gitweb?p=VTK.git;a=commitdiff;h=7f3f750596a105d48ea84ebfe1b1c4ca03e0bab3
00036     #if (defined _DEBUG) && (!defined linux)
00037         #undef _DEBUG
00038         #if (defined linux) | (defined CMAKE)
00039             #include "Python.h"
00040             #include "numpy/arrayobject.h"
00041         #else
00042             #include "Python.h"
00043             #include "../Lib/site-packages/numpy/core/include/numpy/arrayobject.h" //for numpy arrays
00044         #endif
00045         #define _DEBUG
00046     #else
00047         #ifdef linux
00048             #include "Python.h"
00049             #include "numpy/arrayobject.h"
00050         #else
00051             #include "Python.h"
00052             #include "../Lib/site-packages/numpy/core/include/numpy/arrayobject.h" //for numpy arrays
00053         #endif
00054     #endif
00055 #endif
00056 
00057 #include "../global.h"
00058 
00059 #include <qstring.h>
00060 #include <qhash.h>
00061 #include <qmutex.h>
00062 #include <qset.h>
00063 #include <qstringlist.h>
00064 
00065 #define PY_LIST 'l'
00066 #define PY_MAPPING 'm'
00067 #define PY_ATTR 'a'
00068 #define PY_DICT 'd'
00069 #define PY_NUMBER 'n'
00070 #define PY_STRING 's'
00071 
00072 namespace ito
00073 {
00074 
00075 class PyWorkspaceItem;
00076 
00077 class PyWorkspaceItem
00078 {
00079 public:
00080     PyWorkspaceItem() : m_compatibleParamBaseType(0), m_exist(false), m_isarrayelement(false), m_childState(stateNoChilds)
00081     {
00082     }
00083     ~PyWorkspaceItem();
00084     PyWorkspaceItem(const PyWorkspaceItem &other);
00085 
00086     enum childState { stateNoChilds = 0x00, stateChilds = 0x01};
00087 
00088     QString m_name;
00089     QString m_key;
00090     QString m_type;
00091     QString m_value;
00092     QString m_extendedValue;
00093     int m_compatibleParamBaseType;
00094     bool m_exist;
00095     bool m_isarrayelement;
00096     int m_childState;
00097     QHash<QString, PyWorkspaceItem*> m_childs;
00098 };
00099 
00100 
00101 class PyWorkspaceContainer : public QObject //each container has one view
00102 {
00103     Q_OBJECT
00104 public:
00105 
00106     PyWorkspaceContainer(bool globalNotLocal);
00107     ~PyWorkspaceContainer();
00108 
00109     void clear();
00110     void loadDictionary(PyObject *obj, const QString &fullNameParentItem = "");
00111 
00112     inline bool isGlobalWorkspace() const { return m_globalNotLocal; }
00113     inline bool isRoot(PyWorkspaceItem *item) const { return item == &m_rootItem; }
00114     inline void emitGetChildNodes(PyWorkspaceContainer *container, QString fullNameParentItem) { emit getChildNodes(container,fullNameParentItem); }
00115 
00116     inline QString getDelimiter() const { return m_delimiter; };
00117 
00118     ito::PyWorkspaceItem* getItemByFullName(const QString &fullname);
00119 
00120     QMutex m_accessMutex;
00121     QSet<QString> m_expandedFullNames; //this full names are recently expanded in the corresponding view (full name is "." + name + "." + subname + "." + subsubname ...)
00122     PyWorkspaceItem m_rootItem;
00123 
00124 private:
00125     void loadDictionaryRec(PyObject *obj, const QString &fullNameParentItem, PyWorkspaceItem *parentItem, QStringList &deletedKeys);
00126     void parseSinglePyObject(PyWorkspaceItem *item, PyObject *value, QString &fullName, QStringList &deletedKeys, int &m_compatibleParamBaseType);
00127 
00128     QSet<QByteArray> m_blackListType;
00129     bool m_globalNotLocal;
00130 
00131     QString m_delimiter;
00132 
00133     PyObject *dictUnicode;
00134 
00135 signals:
00136     void updateAvailable(PyWorkspaceItem *rootItem, QString fullNameRoot, QStringList recentlyDeletedFullNames);   //TODO
00137     void getChildNodes(PyWorkspaceContainer *container, QString fullNameParentItem); //signal catched by python    //TODO
00138 };
00139 
00140 } //end namespace ito
00141 
00142 
00143 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends