itom 2.0.0
|
00001 /* ******************************************************************** 00002 itom software 00003 URL: http://www.uni-stuttgart.de/ito 00004 Copyright (C) 2013, Institut für Technische Optik (ITO), 00005 Universität 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 UIORGANIZER_H 00024 #define UIORGANIZER_H 00025 00026 //#include "../python/pythonQtConversion.h" 00027 #include "../python/pythonItomMetaObject.h" 00028 00029 #include <qwidget.h> 00030 00031 #include "../common/sharedStructuresQt.h" 00032 #include "../DataObject/dataobj.h" 00033 #if ITOM_POINTCLOUDLIBRARY > 0 00034 #include "../../PointCloud/pclStructures.h" 00035 #endif 00036 00037 #include "../widgets/userUiDialog.h" 00038 #include "../widgets/figureWidget.h" 00039 00040 #include "../global.h" 00041 #include "../common/sharedStructuresGraphics.h" 00042 #include "../common/addInInterface.h" 00043 00044 #include "../../plot/AbstractFigure.h" 00045 00046 #include <qmap.h> 00047 #include <qsharedpointer.h> 00048 #include <qstring.h> 00049 #include <qvariant.h> 00050 #include <qhash.h> 00051 #include <qtimer.h> 00052 #include <qfiledialog.h> 00053 #include <qmainwindow.h> 00054 #include <QtUiTools/quiloader.h> 00055 #include <qthread.h> 00056 #include <qtranslator.h> 00057 00058 namespace ito 00059 { 00060 class WidgetWrapper; //forward declaration 00061 00067 struct UiContainer 00068 { 00069 public: 00070 enum tUiType 00071 { 00072 uiTypeUiDialog = 0x0001, 00073 uiTypeQDialog = 0x0002, 00074 uiTypeQMainWindow = 0x0003, 00075 uiTypeQDockWidget = 0x0004, 00076 uiTypeFigure = 0x0005 00077 }; 00078 00080 00085 UiContainer(UserUiDialog *uiDialog) : 00086 m_type(uiTypeUiDialog) 00087 { 00088 m_weakDialog = QPointer<QWidget>(uiDialog); 00089 } 00090 00092 00097 UiContainer(QDialog *dialog) : 00098 m_type(uiTypeQDialog) 00099 { 00100 m_weakDialog = QPointer<QDialog>(dialog); 00101 } 00102 00104 00109 UiContainer(QMainWindow *mainWindow) : 00110 m_type(uiTypeQMainWindow) 00111 { 00112 m_weakDialog = QPointer<QWidget>(mainWindow); 00113 } 00114 00116 00121 UiContainer(FigureWidget *figureWidget) : 00122 m_type(uiTypeFigure) 00123 { 00124 m_weakDialog = QPointer<QWidget>(figureWidget); 00125 } 00126 00128 00133 UiContainer(QDockWidget *dockWidget) : 00134 m_type(uiTypeQDockWidget) 00135 { 00136 m_weakDialog = QPointer<QWidget>(dockWidget); 00137 } 00138 00140 00146 UiContainer(QWidget *widget, tUiType type) : 00147 m_type(type) 00148 { 00149 m_weakDialog = QPointer<QWidget>(widget); 00150 } 00151 00153 UiContainer(const UiContainer &cpy) 00154 { 00155 m_weakDialog = QPointer<QWidget>(cpy.getUiWidget()); 00156 m_type = cpy.m_type; 00157 } 00158 00159 00160 ~UiContainer(); //comment in source file 00161 00162 00164 inline UserUiDialog *getUiDialog() const 00165 { 00166 if(m_type == uiTypeUiDialog) 00167 { 00168 if(m_weakDialog.isNull()) return NULL; 00169 return qobject_cast<UserUiDialog*>(m_weakDialog.data()); 00170 } 00171 return NULL; 00172 } 00173 00175 00179 inline QWidget *getUiWidget() const 00180 { 00181 if(m_weakDialog.isNull()) return NULL; 00182 return m_weakDialog.data(); 00183 } 00184 00186 inline tUiType getType() const { return m_type; } 00187 00188 private: 00189 QPointer<QWidget> m_weakDialog; 00190 tUiType m_type; 00191 }; 00192 00193 struct UiContainerItem 00194 { 00195 public: 00196 UiContainerItem() : container(NULL) {} 00197 00198 UiContainerItem(const UiContainerItem &cpy) 00199 { 00200 guardedHandle = cpy.guardedHandle; 00201 container = cpy.container; 00202 } 00203 00204 QWeakPointer< unsigned int > guardedHandle; 00205 UiContainer *container; 00206 }; 00207 00208 class UiDataContainer 00209 { 00210 private: 00211 ito::ParamBase::Type m_dataType; 00212 QSharedPointer<ito::DataObject> m_dObjPtr; 00213 #if ITOM_POINTCLOUDLIBRARY > 0 00214 QSharedPointer<ito::PCLPointCloud> m_dPCPtr; 00215 QSharedPointer<ito::PCLPolygonMesh> m_dPMPtr; 00216 #endif 00217 00218 public: 00219 UiDataContainer() : m_dataType(ito::ParamBase::DObjPtr) {}; 00220 ~UiDataContainer() {}; 00221 UiDataContainer(const QSharedPointer<ito::DataObject> &sharedDataObject) : m_dataType(ito::ParamBase::DObjPtr), m_dObjPtr(sharedDataObject) {} 00222 #if ITOM_POINTCLOUDLIBRARY > 0 00223 UiDataContainer(const QSharedPointer<ito::PCLPointCloud> &sharedPointCloud) : m_dataType(ito::ParamBase::PointCloudPtr), m_dPCPtr(sharedPointCloud) {} 00224 UiDataContainer(const QSharedPointer<ito::PCLPolygonMesh> &sharedPolygonMesh) : m_dataType(ito::ParamBase::PolygonMeshPtr), m_dPMPtr(sharedPolygonMesh) {} 00225 00226 inline UiDataContainer & operator = (QSharedPointer<ito::PCLPointCloud> sharedPointCloud) 00227 { 00228 m_dataType = ito::ParamBase::PointCloudPtr; 00229 m_dPCPtr = sharedPointCloud; 00230 m_dObjPtr.clear(); 00231 m_dPMPtr.clear(); 00232 return *this; 00233 } 00234 00235 inline UiDataContainer & operator = (QSharedPointer<ito::PCLPolygonMesh> sharedPolygonMesh) 00236 { 00237 m_dataType = ito::ParamBase::PolygonMeshPtr; 00238 m_dPMPtr = sharedPolygonMesh; 00239 m_dObjPtr.clear(); 00240 m_dPCPtr.clear(); 00241 return *this; 00242 } 00243 #endif 00244 00245 inline UiDataContainer & operator = (QSharedPointer<ito::DataObject> sharedDataObject) 00246 { 00247 m_dataType = ito::ParamBase::DObjPtr; 00248 m_dObjPtr = sharedDataObject; 00249 #if ITOM_POINTCLOUDLIBRARY > 0 00250 m_dPCPtr.clear(); 00251 m_dPMPtr.clear(); 00252 #endif 00253 return *this; 00254 } 00255 00256 inline ito::ParamBase::Type getType() const { return m_dataType; } 00257 inline QSharedPointer<ito::DataObject> getDataObject() const { return m_dObjPtr; } 00258 #if ITOM_POINTCLOUDLIBRARY > 0 00259 inline QSharedPointer<ito::PCLPointCloud> getPointCloud() const { return m_dPCPtr; } 00260 inline QSharedPointer<ito::PCLPolygonMesh> getPolygonMesh() const { return m_dPMPtr; } 00261 #endif 00262 }; 00263 00264 class UiOrganizer : public QObject 00265 { 00266 Q_OBJECT 00267 public: 00268 enum tPropertyFlags 00269 { 00270 propValid = 0x0001, 00271 propConstant = 0x0002, 00272 propFinal = 0x0004, 00273 propReadable = 0x0008, 00274 propWritable = 0x0010, 00275 propResettable = 0x0020 00276 }; 00277 00278 enum tErrorCode 00279 { 00280 errorUiHandleInvalid = 0x1001, 00281 errorObjDoesNotExist = 0x1002, 00282 errorObjPropWrite = 0x1003, 00283 errorObjPropRead = 0x1004, 00284 errorObjPropDoesNotExist = 0x1005, 00285 errorUnregisteredType = 0x1006, 00286 errorSlotDoesNotExist = 0x1007, 00287 errorSignalDoesNotExist = 0x1008, 00288 errorConnectionError = 0x1009 00289 }; 00290 00291 enum tWinType 00292 { 00293 typeDialog = 0x0000, 00294 typeMainWindow = 0x0001, 00295 typeDockWidget = 0x0002 00296 }; 00297 00298 enum tObjectInfo 00299 { 00300 infoShowNoInheritance = 0x0001, 00301 infoShowItomInheritance = 0x0002, 00302 infoShowInheritanceUpToWidget = 0x0004, 00303 infoShowAllInheritance =0x0008 00304 }; 00305 00306 typedef QMap<QString,QString> tQMapArg; 00307 00308 UiOrganizer(ito::RetVal &retval); 00309 ~UiOrganizer(); 00310 00311 void showDialog(QWidget *parent); 00312 inline QObject *getPluginReference(unsigned int objectID) { return getWeakObjectReference(objectID); } 00313 00314 static inline void parseUiDescription(int uiDescription, int* uiType = NULL, int* buttonBarType = NULL, bool* childOfMainWindow = NULL, bool* deleteOnClose = NULL, int* dockWidgetArea = NULL) 00315 { 00316 if(uiType) *uiType = (uiDescription & 0x000000FF); //bits 1-8 00317 if(buttonBarType) *buttonBarType = ((uiDescription & 0x0000FF00) >> 8); //bits 9-16 00318 if(childOfMainWindow) *childOfMainWindow = ((uiDescription & 0x000F0000) > 0); //bits 17-20 00319 if(deleteOnClose) *deleteOnClose = ((uiDescription & 0x00F00000) > 0); //bits 21-24 00320 if(dockWidgetArea) *dockWidgetArea = ((uiDescription & 0xFF000000) >> 24); //bits 25-32 00321 } 00322 00323 static inline int createUiDescription(int uiType, int buttonBarType, bool childOfMainWindow, bool deleteOnClose, int dockWidgetArea) 00324 { 00325 int v = uiType; //bits 1-8 00326 v += (buttonBarType << 8); //bits 9-16 00327 if(childOfMainWindow) v += (1 << 16); //bits 17-24 00328 if(deleteOnClose) v+= (1 << 20); //bits 21-24 00329 v += (dockWidgetArea << 24); //bits 25-32 00330 00331 return v; 00332 } 00333 00334 RetVal getNewPluginWindow(const QString &pluginName, unsigned int &objectID, QWidget** newWidget, QWidget *parent = NULL); 00335 00336 QWidget* loadDesignerPluginWidget(const QString &name, RetVal &retValue, AbstractFigure::WindowMode winMode, QWidget *parent = NULL); 00337 00338 protected: 00339 00340 static void threadSafeDeleteUi(unsigned int *handle); 00341 00342 void startGarbageCollectorTimer(); 00343 00344 private: 00345 void execGarbageCollection(); 00346 00347 unsigned int addObjectToList(QObject* objPtr); 00348 QObject *getWeakObjectReference(unsigned int objectID); 00349 00350 void timerEvent(QTimerEvent *event); 00351 00352 WidgetWrapper *m_widgetWrapper; 00354 QHash<unsigned int, UiContainerItem> m_dialogList; 00355 QHash<unsigned int, QPointer<QObject> > m_objectList; 00356 int m_garbageCollectorTimer; 00357 QMap<QObject*, QThread*> m_watcherThreads; 00359 static unsigned int autoIncUiDialogCounter; 00360 static unsigned int autoIncObjectCounter; 00362 void setApiPointersToWidgetAndChildren(QWidget *widget); 00363 //moved the uiLoader object to here from loadDesignerPluginWidget and createNewDialog methods as according 00364 //to valgrind it causes memory leaks. So better have only one instance created and maintain mem leaks low ;-) 00365 QUiLoader m_uiLoader; 00366 QHash<QString, QTranslator*> m_transFiles; 00367 00368 signals: 00369 00370 public slots: 00371 void pythonKeyboardInterrupt(bool checked); 00372 00373 RetVal loadPluginWidget(void* algoWidgetFunc, QVector<ito::ParamBase> *paramsMand, QVector<ito::ParamBase> *paramsOpt, QSharedPointer<unsigned int>dialogHandle, QSharedPointer<unsigned int>initSlotCount, QSharedPointer<unsigned int> objectID, QSharedPointer<QByteArray> className, ItomSharedSemaphore *semaphore = NULL); 00374 RetVal addWidgetToOrganizer(QWidget *widget, QSharedPointer<unsigned int>dialogHandle, QSharedPointer<unsigned int>initSlotCount, QWidget *parent = NULL, ItomSharedSemaphore *semaphore = NULL); 00375 RetVal createNewDialog(const QString &filename, int uiDescription, const StringMap &dialogButtons, QSharedPointer<unsigned int> dialogHandle, QSharedPointer<unsigned int> initSlotCount, QSharedPointer<unsigned int> objectID, QSharedPointer<QByteArray> className, ItomSharedSemaphore *semaphore = NULL); 00376 RetVal deleteDialog(unsigned int handle, ItomSharedSemaphore *semaphore = NULL); 00377 RetVal showDialog(unsigned int handle, int modalLevel, QSharedPointer<int> retCodeIfModal, ItomSharedSemaphore *semaphore = NULL); 00378 RetVal hideDialog(unsigned int handle, ItomSharedSemaphore *semaphore = NULL); 00379 RetVal setAttribute(unsigned int handle, Qt::WidgetAttribute attribute, bool on = true, ItomSharedSemaphore *semaphore = NULL); 00380 RetVal isVisible(unsigned int handle, QSharedPointer<bool> visible, ItomSharedSemaphore *semaphore = NULL); 00381 00382 UiContainer* getUiDialogByHandle(unsigned int uiHandle); 00383 00384 RetVal getDockedStatus(unsigned int uiHandle, QSharedPointer<bool> docked, ItomSharedSemaphore *semaphore = NULL); 00385 RetVal setDockedStatus(unsigned int uiHandle, bool docked, ItomSharedSemaphore *semaphore = NULL); 00386 00387 RetVal showInputDialogGetDouble(const QString &title, const QString &label, double defaultValue, QSharedPointer<bool> ok, QSharedPointer<double> value, double min = -2147483647, double max = 2147483647, int decimals = 1, ItomSharedSemaphore *semaphore = NULL ); 00388 RetVal showInputDialogGetInt(const QString &title, const QString &label, int defaultValue, QSharedPointer<bool> ok, QSharedPointer<int> value, int min = -2147483647, int max = 2147483647, int step = 1, ItomSharedSemaphore *semaphore = NULL ); 00389 RetVal showInputDialogGetItem(const QString &title, const QString &label, const QStringList &stringList, QSharedPointer<bool> ok, QSharedPointer<QString> value, int currentIndex = 0, bool editable = false, ItomSharedSemaphore *semaphore = NULL ); 00390 RetVal showInputDialogGetText(const QString &title, const QString &label, const QString &defaultString, QSharedPointer<bool> ok, QSharedPointer<QString> value, ItomSharedSemaphore *semaphore = NULL ); 00391 RetVal showMessageBox(unsigned int uiHandle, int type, const QString &title, const QString &text, int buttons, int defaultButton, QSharedPointer<int> retButton, QSharedPointer<QString> retButtonText, ItomSharedSemaphore *semaphore = NULL ); 00392 00393 RetVal showFileDialogExistingDir(unsigned int uiHandle, const QString &caption, QSharedPointer<QString> directory, int options = QFileDialog::ShowDirsOnly, ItomSharedSemaphore *semaphore = NULL); //options are of type QFileDialog::Options 00394 RetVal showFileOpenDialog(unsigned int uiHandle, const QString &caption, const QString &directory, const QString &filter, QSharedPointer<QString> file, int selectedFilterIndex = 0, int options = 0, ItomSharedSemaphore *semaphore = NULL); 00395 RetVal showFileSaveDialog(unsigned int uiHandle, const QString &caption, const QString &directory, const QString &filter, QSharedPointer<QString> file, int selectedFilterIndex = 0, int options = 0, ItomSharedSemaphore *semaphore = NULL); 00396 00397 RetVal exists(unsigned int objectID, QSharedPointer<bool> exists, ItomSharedSemaphore *semaphore = NULL); 00398 RetVal getPropertyInfos(unsigned int objectID, QSharedPointer<QVariantMap> retPropertyMap, ItomSharedSemaphore *semaphore = NULL); 00399 RetVal readProperties(unsigned int objectID, QSharedPointer<QVariantMap> properties, ItomSharedSemaphore *semaphore = NULL); 00400 RetVal writeProperties(unsigned int objectID, const QVariantMap &properties, ItomSharedSemaphore *semaphore = NULL); 00401 RetVal readProperties(unsigned int handle, const QString &widgetName, QSharedPointer<QVariantMap> properties, ItomSharedSemaphore *semaphore = NULL); 00402 RetVal writeProperties(unsigned int handle, const QString &widgetName, const QVariantMap &properties, ItomSharedSemaphore *semaphore = NULL); 00403 RetVal getAttribute(unsigned int objectID, int attributeNumber, QSharedPointer<bool> value, ItomSharedSemaphore *semaphore = NULL); 00404 RetVal setAttribute(unsigned int objectID, int attributeNumber, bool value, ItomSharedSemaphore *semaphore = NULL); 00405 RetVal getWindowFlags(unsigned int objectID, QSharedPointer<int> flags, ItomSharedSemaphore *semaphore = NULL); 00406 RetVal setWindowFlags(unsigned int objectID, int flags, ItomSharedSemaphore *semaphore = NULL); 00407 RetVal widgetMetaObjectCounts(unsigned int objectID, QSharedPointer<int> classInfoCount, QSharedPointer<int> enumeratorCount, QSharedPointer<int> methodCount, QSharedPointer<int> propertyCount, ItomSharedSemaphore *semaphore = NULL ); 00408 00409 RetVal getChildObject(unsigned int uiHandle, const QString &objectName, QSharedPointer<unsigned int> objectID, ItomSharedSemaphore *semaphore = NULL); 00410 RetVal getChildObject2(unsigned int parentObjectID, const QString &objectName, QSharedPointer<unsigned int> objectID, ItomSharedSemaphore *semaphore = NULL); 00411 RetVal getChildObject3(unsigned int parentObjectID, const QString &objectName, QSharedPointer<unsigned int> objectID, QSharedPointer<QByteArray> widgetClassName, ItomSharedSemaphore *semaphore = NULL); 00412 RetVal getSignalIndex(unsigned int objectID, const QString &signalSignature, QSharedPointer<int> signalIndex, QSharedPointer<QObject*> objPtr, QSharedPointer<IntList> argTypes, ItomSharedSemaphore *semaphore = NULL); 00413 RetVal callSlotOrMethod(bool slotNotMethod, unsigned int objectID, int slotOrMethodIndex, QSharedPointer<FctCallParamContainer> args, ItomSharedSemaphore *semaphore = NULL); 00414 00415 RetVal getObjectInfo(const QString &classname, ito::UiOrganizer::tQMapArg *objInfo, ItomSharedSemaphore *semaphore = NULL); 00416 RetVal getObjectInfo(const QObject *obj, int type, ito::UiOrganizer::tQMapArg* propMap, ItomSharedSemaphore *semaphore = NULL); 00417 inline RetVal getObjectInfo(unsigned int objectID, int type, ito::UiOrganizer::tQMapArg *propMap, ItomSharedSemaphore *semaphore = NULL) 00418 { 00419 return getObjectInfo(getWeakObjectReference(objectID), type, propMap, semaphore); 00420 } 00421 RetVal getObjectInfo(unsigned int objectID, QSharedPointer<QByteArray> objectName, QSharedPointer<QByteArray> widgetClassName, ItomSharedSemaphore *semaphore = NULL); 00422 RetVal getObjectChildrenInfo(unsigned int objectID, bool recursive, QSharedPointer<QStringList> objectNames, QSharedPointer<QStringList> classNames, ItomSharedSemaphore *semaphore = NULL); 00423 00424 RetVal getObjectID(const QObject *obj, QSharedPointer<unsigned int> objectID, ItomSharedSemaphore *semaphore = NULL); 00425 00426 RetVal connectWithKeyboardInterrupt(unsigned int objectID, const QString &signalSignature, ItomSharedSemaphore *semaphore = NULL); 00427 RetVal getMethodDescriptions(unsigned int objectID, QSharedPointer<MethodDescriptionList> methodList, ItomSharedSemaphore *semaphore = NULL); 00428 00429 RetVal createFigure(QSharedPointer< QSharedPointer<unsigned int> > guardedFigureHandle, QSharedPointer<unsigned int> initSlotCount, QSharedPointer<unsigned int> objectID, QSharedPointer<int> rows, QSharedPointer<int> cols, ItomSharedSemaphore *semaphore = NULL); 00430 RetVal getSubplot(QSharedPointer<unsigned int> figHandle, unsigned int subplotIndex, QSharedPointer<unsigned int> objectID, QSharedPointer<QByteArray> objectName, QSharedPointer<QByteArray> widgetClassName, ItomSharedSemaphore *semaphore = NULL); 00431 00432 RetVal figurePlot(ito::UiDataContainer &dataCont, QSharedPointer<unsigned int> figHandle, QSharedPointer<unsigned int> objectID, int areaRow, int areaCol, QString className, QVariantMap properties, ItomSharedSemaphore *semaphore = NULL); 00433 RetVal figureLiveImage(AddInDataIO* dataIO, QSharedPointer<unsigned int> figHandle, QSharedPointer<unsigned int> objectID, int areaRow, int areaCol, QString className, QVariantMap properties, ItomSharedSemaphore *semaphore = NULL); 00434 00435 RetVal figureRemoveGuardedHandle(unsigned int figHandle, ItomSharedSemaphore *semaphore = NULL); 00436 RetVal figureClose(unsigned int figHandle, ItomSharedSemaphore *semaphore = NULL); 00437 RetVal figurePickPoints(unsigned int objectID, QSharedPointer<ito::DataObject> coords, int maxNrPoints, ItomSharedSemaphore *semaphore); 00438 RetVal figureDrawGeometricElements(unsigned int objectID, QSharedPointer<ito::DataObject> coords, int elementType, int maxNrElements, ItomSharedSemaphore *semaphore); 00439 RetVal figurePickPointsInterrupt(unsigned int objectID); 00440 RetVal isFigureItem(unsigned int objectID, QSharedPointer<unsigned int> isFigureItem, ItomSharedSemaphore *semaphore); 00441 00442 00443 00444 void figureDestroyed(QObject *obj) 00445 { 00446 qDebug() << obj; 00447 } 00448 00449 private slots: 00450 void watcherThreadFinished(); 00451 00452 }; 00453 00454 } //namespace ito 00455 00456 Q_DECLARE_METATYPE(ito::UiOrganizer::tQMapArg*) 00457 00458 #endif