rtVTK  0.6.0
glWidget.h
00001 
00002 /******************************************************************************
00003  * Copyright (c) 2012, Grove City College
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are
00008  * met:
00009  * 
00010  *  * Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  *
00013  *  * Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in
00015  *    the documentation and/or other materials provided with the
00016  *    distribution.
00017  *
00018  *  * Neither the name of Grove City College nor the names of its
00019  *    contributors may be used to endorse or promote products derived
00020  *    from this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00025  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00026  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00027  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00028  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00029  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00030  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00031  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00032  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  */
00035 
00036 
00047 #ifndef StandAlone_glWidget_h
00048 #define StandAlone_glWidget_h
00049 
00050 #include <map>
00051 using std::map;
00052 
00053 #include <string>
00054 using std::string;
00055 
00056 #include <vector>
00057 using std::vector;
00058 
00059 #include <QGLWidget>
00060 
00061 #include <Core/ioCore/Scene.h>
00062 
00063 #include <Core/uiCore/Trackball.h>
00064 
00065 #include <Core/RGB.t>
00066 
00067 #include <Math/Math.h>
00068 
00069 #include <StandAlone/Plugin.h>
00070 
00071 
00073 // Forward declarations
00074 
00075 class QLayout;
00076 class QMouseEvent;
00077 class QWidget;
00078 class QTimer;
00079 
00080 namespace Core
00081 {
00082 
00083   class Mesh;
00084 
00085 } // namespace Core
00086 
00087 namespace rtVTK
00088 {
00089 
00091   // Using declarations
00092 
00093   using ioCore::Scene;
00094 
00095   using uiCore::Mouse;
00096   using uiCore::CameraMode;
00097   using uiCore::Trackball;
00098 
00099   using CoreF::RGB;
00100 
00101   using Core::Mesh;
00102 
00103   using MathF::Point;
00104   using MathF::Vector;
00105 
00106 
00108   // Class definition
00109 
00111   class glWidget : public QGLWidget
00112   {
00113     Q_OBJECT
00114 
00115   public:
00116 
00118     // Static member definitions
00119 
00120     static const uint MinimumWidth;
00121     static const uint MinimumHeight;
00122 
00123 
00125     // Public members
00126 
00127     glWidget(const vector<Plugin*>&, const RGB& = RGB::One);
00128 
00129     ~glWidget();
00130 
00131     Trackball& getTrackball() { return trackball; }
00132 
00133     // Calls the idle functions of each plugin.
00134     void idle();
00135 
00136 
00138     // Signals
00139 
00140   signals:
00141     void sgnlUpdateCoords(const Camera&);
00142     void sgnlUpdateTitle();
00143     void sgnlRender();
00144     void sgnlResetRL();
00145 
00151     void sgnlMousePressEvent(QMouseEvent*);
00152     void sgnlMouseMoveEvent(QMouseEvent*);
00153     void sgnlMouseReleaseEvent(QMouseEvent*);
00154     void sgnlMouseInactive();
00156 
00157 
00159     // Public slots
00160 
00161   public slots:
00162     void slotSetView(const Scene::ViewParameters&);
00163     void slotSetLookMode(uiCore::CameraMode);
00164     void slotSetRotate(float);
00165     void slotSetTranslate(float);
00166     void slotSetDolly(float);
00167     void slotSetFOV(float);
00168     void slotResetView();
00169     void slotSetBG(float, float, float);
00170     void slotRender();
00171 
00172     void slotTimerEvent();
00173     void slotSetIdle(bool);
00174     void slotToggleMouseActive();
00175 
00176 
00177   protected:
00178 
00180     // Helper functions
00181 
00182     void initializeGL();
00183     void resizeGL(int, int);
00184     void paintGL();
00185 
00187     void render();
00188 
00190 
00191     void mousePressEvent(  QMouseEvent*);
00192     void mouseMoveEvent(   QMouseEvent*);
00193     void mouseReleaseEvent(QMouseEvent*);
00195 
00196 
00198     // Data members
00199 
00200     bool refresh;
00201 
00203 
00204     uint w;
00205     uint h;
00207 
00208     RGB bg;
00209 
00210     Trackball trackball;
00211     bool      tbValid;
00212 
00213     float rscale;
00214     float tscale;
00215     float dscale;
00216 
00222     const vector<Plugin*>& plugins;
00223 
00228     QTimer* timer;
00229 
00230     /*
00231       A flag to enable/disable the ability of the mouse to move the camera. May
00232       be toggled by calling slotToggleMouseActive(). A control+click will still
00233       be listened for and acted upon if a mouse event is caught.
00234     */
00235     bool mouseActive;
00236 
00244     Mouse::Button button;
00245   }; // class glWidget
00246 
00247 } // namespace rtVTK
00248 
00249 #endif // StandAlone_glWidget_h
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends