itom 2.2.1
K:/git-itom/sources/itom/plot/AbstractFigure.h
00001 /* ********************************************************************
00002     itom software
00003     URL: http://www.uni-stuttgart.de/ito
00004     Copyright (C) 2016, Institut fuer Technische Optik (ITO),
00005     Universitaet Stuttgart, Germany
00006 
00007     This file is part of itom and its software development toolkit (SDK).
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     In addition, as a special exception, the Institut fuer Technische
00015     Optik (ITO) gives you certain additional rights.
00016     These rights are described in the ITO LGPL Exception version 1.0,
00017     which can be found in the file LGPL_EXCEPTION.txt in this package.
00018 
00019     itom is distributed in the hope that it will be useful, but
00020     WITHOUT ANY WARRANTY; without even the implied warranty of
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library
00022     General Public Licence for more details.
00023 
00024     You should have received a copy of the GNU Library General Public License
00025     along with itom. If not, see <http://www.gnu.org/licenses/>.
00026 *********************************************************************** */
00027 
00028 #ifndef ABSTRACTFIGURE_H
00029 #define ABSTRACTFIGURE_H
00030 
00031 #include "plotCommon.h"
00032 #include "AbstractNode.h"
00033 
00034 #include "../common/apiFunctionsGraphInc.h"
00035 #include "../common/apiFunctionsInc.h"
00036 
00037 #include <qmainwindow.h>
00038 #include <qlabel.h>
00039 #include <qtoolbar.h>
00040 #include <qevent.h>
00041 #include <qdockwidget.h>
00042 
00043 class QPropertyEditorWidget; //forward declaration
00044 
00045 #if !defined(Q_MOC_RUN) || defined(ITOMCOMMONPLOT_MOC) //only moc this file in itomCommonQtLib but not in other libraries or executables linking against this itomCommonQtLib
00046 
00047 //place this macro in the header file of the designer plugin widget class right before the first section (e.g. public:)
00048 #define DESIGNER_PLUGIN_ITOM_API \
00049             protected: \
00050                 void importItomApi(void** apiPtr) \
00051                 {ito::ITOM_API_FUNCS = apiPtr;} \
00052                 void importItomApiGraph(void** apiPtr) \
00053                 { ito::ITOM_API_FUNCS_GRAPH = apiPtr;} \
00054             public: \
00055                 //.
00056 
00057 namespace ito {
00058 
00059 class AbstractFigure; //forward declaration
00060 class AbstractFigurePrivate; //forward declaration
00061 
00062 class ITOMCOMMONPLOT_EXPORT AbstractFigure : public QMainWindow, public AbstractNode
00063 {
00064     Q_OBJECT
00065     Q_ENUMS(WindowMode)
00066     Q_ENUMS(UnitLabelStyle)
00067 
00068     Q_PROPERTY(bool toolbarVisible READ getToolbarVisible WRITE setToolbarVisible DESIGNABLE true USER true)
00069     Q_PROPERTY(bool contextMenuEnabled READ getContextMenuEnabled WRITE setContextMenuEnabled DESIGNABLE true)
00070     Q_PROPERTY(bool renderLegend READ getLegendRender WRITE setLegendRender DESIGNABLE true)
00071 
00072     Q_CLASSINFO("prop://toolbarVisible", "Toggles the visibility of the toolbar of the plot.")
00073     Q_CLASSINFO("prop://contextMenuEnabled", "Defines whether the context menu of the plot should be enabled or not.")
00074     Q_CLASSINFO("prop://renderLegend", "If this property is true, the legend are included in pixelmaps renderings.")
00075 
00076     Q_CLASSINFO("slot://getPlotID", "Return window ID of this plot {int}.")
00077     Q_CLASSINFO("slot://refreshPlot", "Triggers an update of the current plot window.")
00078 
00079     public:
00080         enum WindowMode 
00081         { 
00082             ModeInItomFigure, 
00083             ModeStandaloneInUi, 
00084             ModeStandaloneWindow 
00085         };
00086         
00087         enum CompilerFeatures 
00088         { 
00089             tOpenCV        = 0x01,
00090             tPointCloudLib = 0x02
00091         };
00092 
00093         enum tChildPlotStates
00094         {
00095             tNoChildPlot            = 0x00,
00096             tExternChild            = 0x01,
00097             tOwnChild               = 0x02,
00098             tUninitilizedExtern     = 0x10,
00099             tVisibleOnInit          = 0x20
00100         };
00101 
00102         enum UnitLabelStyle 
00103         { 
00104             UnitLabelSlash,              // x-axis / m  -> corresponds to DIN461
00105             UnitLabelKeywordIn,          // x-axis in m -> corresponds to DIN461
00106             UnitLabelSquareBrackets      // x-axis [m]  -> does not correspond to DIN461
00107         };
00108 
00109         int getCompilerFeatures(void) const 
00110         {
00111             int retval = tOpenCV;
00112             #if defined USEPCL || ITOM_POINTCLOUDLIBRARY
00113             retval |= tPointCloudLib;
00114             #endif
00115             return retval;
00116         }
00117 
00118         struct ToolBarItem {
00119             ToolBarItem() : toolbar(NULL), visible(1), section(0), key("") {}
00120             QToolBar *toolbar;
00121             bool visible;
00122             int section;
00123             Qt::ToolBarArea area;
00124             QString key;
00125         };
00126 
00127         struct ToolboxItem {
00128             ToolboxItem() : toolbox(NULL), key("") {}
00129             QDockWidget *toolbox;
00130             Qt::DockWidgetArea area;
00131             QString key;
00132         };
00133 
00134         AbstractFigure(const QString &itomSettingsFile, WindowMode windowMode = ModeStandaloneInUi, QWidget *parent = 0);
00135         virtual ~AbstractFigure();
00136 
00137         virtual bool event(QEvent *e);
00138         void setApiFunctionGraphBasePtr(void **apiFunctionGraphBasePtr);
00139         void setApiFunctionBasePtr(void **apiFunctionBasePtr);
00140         void ** getApiFunctionGraphBasePtr(void) { return m_apiFunctionsGraphBasePtr; }
00141         void ** getApiFunctionBasePtr(void) { return m_apiFunctionsBasePtr; }
00142 
00143         virtual RetVal addChannel(AbstractNode *child, ito::Param* parentParam, ito::Param* childParam, Channel::ChanDirection direction, bool deleteOnParentDisconnect, bool deleteOnChildDisconnect);
00144         virtual RetVal addChannel(Channel *newChannel);
00145         virtual RetVal removeChannelFromList(unsigned int uniqueID);
00146         virtual RetVal removeChannel(Channel *delChannel);
00147 
00148         virtual RetVal update(void) = 0; 
00150         //properties
00151         virtual void setToolbarVisible(bool visible);
00152         virtual bool getToolbarVisible() const;
00153         virtual void setContextMenuEnabled(bool show) = 0; 
00154         virtual bool getContextMenuEnabled() const = 0;
00155 
00156         QDockWidget *getPropertyDockWidget() const;
00157 
00158         virtual bool getLegendRender() const { return false;}
00159         virtual void setLegendRender(const bool val) { return;}
00160 
00161         QList<QMenu*> getMenus() const;
00162         QList<AbstractFigure::ToolBarItem> getToolbars() const;
00163         QList<AbstractFigure::ToolboxItem> getToolboxes() const; //the first toolbox is always the property dock widget
00164 
00165     protected:
00166 
00167         virtual RetVal init() { return retOk; } //this method is called from after construction and after that the api pointers have been transmitted
00168 
00169         virtual void importItomApi(void** apiPtr) = 0;      
00170         virtual void importItomApiGraph(void** apiPtr) = 0; 
00172         void addToolBar(QToolBar *toolbar, const QString &key, Qt::ToolBarArea area = Qt::TopToolBarArea, int section = 1); 
00173         void addToolBarBreak(const QString &key, Qt::ToolBarArea area = Qt::TopToolBarArea); 
00175         void addToolbox(QDockWidget *toolbox, const QString &key, Qt::DockWidgetArea area = Qt::RightDockWidgetArea); 
00176                 bool removeToolbox(const QString &key); 
00178                 void showToolBar(const QString &key); 
00179         void hideToolBar(const QString &key); 
00181         void addMenu(QMenu *menu); 
00183         void updatePropertyDock(); 
00184         void setPropertyObservedObject(QObject* obj); 
00186         RetVal initialize();
00187 
00188         RetVal registerShortcutActions(); 
00190         WindowMode m_windowMode;
00191         QString m_itomSettingsFile;
00192         QWidget *m_mainParent; //the parent of this figure is only set to m_mainParent, if the stay-on-top behaviour is set to the right value
00193 
00194         void **m_apiFunctionsGraphBasePtr;
00195         void **m_apiFunctionsBasePtr;
00196 
00197         ito::uint8 m_lineCutType;
00198         ito::uint8 m_zSliceType;
00199         ito::uint8 m_zoomCutType;
00200 
00201     private:
00202         AbstractFigurePrivate *d;
00203 
00204     private slots:
00205         inline void mnuShowToolbar(bool /*checked*/) { setToolbarVisible(true); } 
00206         void mnuShowProperties(bool checked); 
00208                 void toolBoxDestroyed(QObject *object);
00209                 void toolBarDestroyed(QObject *object);
00210 
00211         void actionChanged();
00212 
00213     public slots:
00214 
00215         int getPlotID() 
00216         { 
00217             if(!ito::ITOM_API_FUNCS_GRAPH) return 0;
00218             ito::uint32 thisID = 0;
00219             ito::RetVal retval = apiGetFigureIDbyHandle(this, thisID);
00220 
00221             if(retval.containsError())
00222             {
00223                 return 0;
00224             }
00225             return thisID; 
00226         }
00227 
00228         void refreshPlot() { update(); }
00229 };
00230 
00231 } // namespace ito
00232 
00233 #endif //#if !defined(Q_MOC_RUN) || defined(ITOMCOMMONQT_MOC)
00234 
00235 #endif // ABSTRACTFIGURE_H
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Friends