itom 2.0.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     #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 <qstringlist.h>
00068 
00069 #define PY_LIST 'l'
00070 #define PY_MAPPING 'm'
00071 #define PY_ATTR 'a'
00072 #define PY_DICT 'd'
00073 #define PY_NUMBER 'n'
00074 #define PY_STRING 's'
00075 
00076 namespace ito
00077 {
00078 
00079 class PyWorkspaceItem;
00080 
00081 class PyWorkspaceItem
00082 {
00083 public:
00084     PyWorkspaceItem() : m_compatibleParamBaseType(0), m_exist(false), m_isarrayelement(false), m_childState(stateNoChilds)
00085     {
00086     }
00087     ~PyWorkspaceItem();
00088     PyWorkspaceItem(const PyWorkspaceItem &other);
00089 
00090     enum childState { stateNoChilds = 0x00, stateChilds = 0x01};
00091 
00092     QString m_name;
00093     QString m_key;
00094     QString m_type;
00095     QString m_value;
00096     QString m_extendedValue;
00097     int m_compatibleParamBaseType;
00098     bool m_exist;
00099     bool m_isarrayelement;
00100     int m_childState;
00101     QHash<QString, PyWorkspaceItem*> m_childs;
00102 };
00103 
00104 
00105 class PyWorkspaceContainer : public QObject //each container has one view
00106 {
00107     Q_OBJECT
00108 public:
00109 
00110     PyWorkspaceContainer(bool globalNotLocal);
00111     ~PyWorkspaceContainer();
00112 
00113     void clear();
00114     void loadDictionary(PyObject *obj, const QString &fullNameParentItem = "");
00115 
00116     inline bool isGlobalWorkspace() const { return m_globalNotLocal; }
00117     inline bool isRoot(PyWorkspaceItem *item) const { return item == &m_rootItem; }
00118     inline void emitGetChildNodes(PyWorkspaceContainer *container, QString fullNameParentItem) { emit getChildNodes(container,fullNameParentItem); }
00119 
00120     inline QString getDelimiter() const { return m_delimiter; };
00121 
00122     ito::PyWorkspaceItem* getItemByFullName(const QString &fullname);
00123 
00124     QMutex m_accessMutex;
00125     QSet<QString> m_expandedFullNames; //this full names are recently expanded in the corresponding view (full name is "." + name + "." + subname + "." + subsubname ...)
00126     PyWorkspaceItem m_rootItem;
00127 
00128 private:
00129     void loadDictionaryRec(PyObject *obj, const QString &fullNameParentItem, PyWorkspaceItem *parentItem, QStringList &deletedKeys);
00130     void parseSinglePyObject(PyWorkspaceItem *item, PyObject *value, QString &fullName, QStringList &deletedKeys, int &m_compatibleParamBaseType);
00131 
00132     QSet<QByteArray> m_blackListType;
00133     bool m_globalNotLocal;
00134 
00135     QString m_delimiter;
00136 
00137     PyObject *dictUnicode;
00138 
00139 signals:
00140     void updateAvailable(PyWorkspaceItem *rootItem, QString fullNameRoot, QStringList recentlyDeletedFullNames);   //TODO
00141     void getChildNodes(PyWorkspaceContainer *container, QString fullNameParentItem); //signal catched by python    //TODO
00142 };
00143 
00144 } //end namespace ito
00145 
00146 
00147 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends