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