Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

QGLViewer.h

Go to the documentation of this file.
00001 /*
00002  * QGLViewer.h
00003  * $Id: QGLViewer.h,v 1.10 2001/11/20 16:23:48 guenth Exp $
00004  *
00005  * Copyright (C) 1999, 2000 Markus Janich
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  * As a special exception to the GPL, the QGLViewer authors (Markus
00022  * Janich, Michael Meissner, Richard Guenther, Alexander Buck and Thomas
00023  * Woerner) give permission to link this program with Qt (non-)commercial
00024  * edition, and distribute the resulting executable, without including
00025  * the source code for the Qt (non-)commercial edition in the source
00026  * distribution.
00027  *
00028  */
00029 
00030 //  Description : Class QGLViewer
00031 //  Purpose     : Abstract class of a OpenGL viewer
00032 
00033 
00034 #ifndef __QGLVIEWER_H_
00035 #define __QGLVIEWER_H_
00036 
00037 
00038 // Qt
00040 #include <qgl.h>
00041 #include <qframe.h>
00042 #include <qpopupmenu.h>
00043 #include <qpoint.h>
00044 #include <qbitmap.h>
00045 
00046 
00047 // System
00049 #include <stdlib.h>     // for exit()-calls and 'getenv()'
00050 #include <iostream.h>
00051 
00052 
00053 // Own
00055 #include "QGLSignalWidget.h"
00056 #include "CCamera.h"
00057 #include "CBoundingBox3D.h"
00058 
00059 
00060 // Forward declarations
00062 class QHBoxLayout;
00063 class QFrame;
00064 class QCursor;
00065 class QIconSet;
00066 class QPixmap;
00067 class QStereoCtrl;
00068 
00069 
00070 // for Qt 2.x compatibility
00071 #if QT_VERSION < 300
00072 #define Q_CHECK_PTR CHECK_PTR
00073 #endif
00074 
00075 
00077 
00086 class QGLViewer: public QFrame {
00087   Q_OBJECT
00088 
00089 public:
00091   // PUBLIC ENUMS //
00093 
00094 
00096   enum ProjectionMode {
00097     parallel,           
00098     perspective         
00099   };
00100 
00102   enum CameraType {
00103     CurrentCam = 1,       
00104     HomeCam    = 2,       
00105     BothCams   = 3        
00106   };
00107 
00109   enum StereoMode {
00110     STEREO_ON,            
00111     STEREO_OFF,           
00112     STEREO_SIMULATE       
00113   };                      
00119   enum StereoBuffer {
00120     MONO,                 
00121     STEREO_LEFT,          
00122     STEREO_RIGHT          
00123   };
00124 
00126   // PUBLIC METHODS //
00128 
00129 
00133   QGLViewer(QWidget * parent=0, 
00134             const char * name=0, const QGLWidget * shareWidget = 0, 
00135             WFlags f=0, bool viewertype=true,
00136             const QGLFormat &format=QGLFormat::defaultFormat());
00137 
00142   QGLViewer(const CCamera &homecam, QWidget * parent=0,
00143             const char * name=0, const QGLWidget * shareWidget = 0, 
00144             WFlags f=0, bool viewertype=true,
00145             const QGLFormat &format=QGLFormat::defaultFormat());
00146 
00147 
00152   QGLViewer(const CBoundingBox3D &bbox, QWidget * parent=0,
00153             const char * name=0, const QGLWidget * shareWidget = 0, 
00154             WFlags f=0, bool viewertype=true,
00155             const QGLFormat &format=QGLFormat::defaultFormat());
00156 
00157 
00161   virtual ~QGLViewer() {};
00162 
00163 
00167   void setRefreshRate(int nFramesPerSecond);
00168 
00170   int getRefreshRate() { return m_nRefreshRate; };
00171 
00179   virtual void setBoundingBox(const CBoundingBox3D &cBBox,bool fUpdate=false);
00180 
00184   virtual void setCamera(const CCamera &cCamera, CameraType which=CurrentCam);
00185 
00189   CCamera& getCamera() {  return m_cCurrentCamera; };
00190 
00194   CCamera *getCameraPtr() { return &m_cCurrentCamera; };
00195 
00199   virtual ProjectionMode getProjectionMode() {
00200     return (m_cCurrentCamera.getCameraType() == CCamera::orthographic) ? parallel : perspective;
00201   };
00202 
00210   virtual void setFullViewer(bool state) {
00211     m_fFullViewer = state;
00212   };
00213 
00218   bool isFullViewer() { return m_fFullViewer; };
00219 
00223   QGLSignalWidget *getDrawArea() {
00224     return m_pQGLWidget;
00225   };
00226 
00230   void makeCurrent() {
00231     m_pQGLWidget->makeCurrent();
00232   }
00233 
00238   virtual void enableMouseEvents(bool fFlag) {
00239     m_fHandleMouseEvents = fFlag;
00240   };
00241 
00245   GLenum getRenderMode() {
00246     return m_eRenderMode;
00247   }
00248 
00252   QPopupMenu *getMainMenu() { return m_pqPopupMenu; };
00253 
00257   int insertItem(const QString &text, const QObject *receiver, const char *member) {
00258     return m_pqPopupMenu->insertItem(text, receiver, member);
00259   };
00260 
00264   int insertItem(const QIconSet &icon, const QString &text, const QObject *receiver, const char *member) {
00265     return m_pqPopupMenu->insertItem(icon, text, receiver, member);
00266   };
00267 
00271   int insertItem(const QPixmap &pixmap, const QString &text, const QObject *receiver, const char *member) {
00272     return m_pqPopupMenu->insertItem(pixmap, text, receiver, member);
00273   };
00274 
00278   int insertItem(const QString &text, QPopupMenu *pqPopup) {
00279     return m_pqPopupMenu->insertItem(text, pqPopup);
00280   };
00281 
00285   int insertItem(const QPixmap &pixmap, QPopupMenu *pqPopup) {
00286     return m_pqPopupMenu->insertItem(pixmap, pqPopup);
00287   };
00288 
00293   bool isItemEnabled(int nID) { return m_pqPopupMenu->isItemEnabled(nID); };
00294 
00299   void setItemEnabled(int nID, bool fEnable) { m_pqPopupMenu->setItemEnabled(nID, fEnable); };
00300 
00305   bool isItemChecked(int nID) { return m_pqPopupMenu->isItemChecked(nID); };
00306 
00311   void setItemChecked(int nID, bool fCheck) { m_pqPopupMenu->setItemChecked(nID, fCheck); }; 
00312 
00320   void allowStereoSimulation( bool flag ) { m_fAllowStereoSimulation = flag; }
00321 
00326   StereoMode getStereoMode() { return m_stereoMode; }
00327 
00328 
00329 public slots:
00331   // PUBLIC SLOTS //
00333 
00338   virtual void sltUpdateView() {
00339     m_fRefresh = true;
00340   };
00341 
00346   virtual void sltToggleStereo();
00347 
00352   virtual void sltViewAll();
00353 
00354 signals:
00356   // SIGNALS //
00358 
00362   void sigProjModeToggled();
00363 
00369   void sigRenderModeChanged();
00370 
00380   void sigSelected(QMouseEvent *pqEvent);
00381 
00388   void sigReleased(QMouseEvent *pqEvent);
00389 
00396   void sigMoved(QMouseEvent *pqEvent);
00397 
00404   void sigInitGL();
00405 
00411   void sigRedrawGL();
00412 
00419   void sigResizeGL(int nWidth, int nHeight);
00420 
00426   void sigRatioChanged(double rdRatio);
00427 
00433   void sigFovyChanged(double rdFovy);
00434 
00435 
00436 
00437 protected slots:
00439   // PROTECTED SLOTS //
00441 
00442 
00446   virtual void sltSetProjectionMode();
00447 
00452   virtual void sltSetHome();
00453 
00457   virtual void sltGoHome();
00458 
00462   virtual void sltToggleProjectionMode();
00463 
00468   virtual void sltToggleRenderMode();
00469 
00475   virtual void sltManageDrop(QDropEvent *pqEvent);
00476 
00482   virtual void sltManageDragEnter(QDragEnterEvent *pqEvent);
00483 
00488   virtual void sltManageDragLeave(QDragLeaveEvent *pqEvent);
00489 
00490 
00491 private slots:
00493   // PRIVATE SLOTS //
00495 
00496 
00502   void sltResizeGL(int w, int h);
00503 
00509   void sltPaintGL();
00510 
00514   void sltSwitchMousePress(QMouseEvent *event) {
00515     if (m_eRenderMode == GL_SELECT) {
00516       emit(sigSelected(event));
00517     }
00518     else {
00519       if (m_fHandleMouseEvents)
00520         ManageMousePress(event);
00521     }
00522   };
00523 
00527   void sltSwitchMouseRelease(QMouseEvent *event) {
00528     if (m_eRenderMode == GL_SELECT) {
00529       emit(sigReleased(event));
00530     }
00531     else {
00532       if (m_fHandleMouseEvents)
00533         ManageMouseRelease(event);
00534     }
00535   };
00536 
00540   void sltSwitchMouseMove(QMouseEvent *event) {
00541     if (m_eRenderMode == GL_SELECT) {
00542       emit(sigMoved(event));
00543     }
00544     else {
00545       if (m_fHandleMouseEvents)
00546         ManageMouseMove(event);
00547     }
00548   };
00549     
00553   void sltPopMenu(QMouseEvent *pqEvent);
00554 
00555 
00556 protected: 
00558   // PROTECTED METHODS //
00560 
00561 
00566   virtual void initQFrame(const char * name, const QGLWidget * shareWidget,
00567                           WFlags f, const QGLFormat &format=QGLFormat::defaultFormat());
00568 
00575   QFrame *getQFrame() {
00576     return m_pQFrame;
00577   }
00578 
00583   void setFrustum(StereoBuffer buffer = QGLViewer::MONO);
00584 
00586   void setFrustumMono();
00587 
00589   void setFrustumStereoLeft();
00590 
00592   void setFrustumStereoRight();
00593 
00599   void setLookAt();
00600 
00601 
00607   virtual void ManageMouseMove(QMouseEvent *) {};
00608 
00614   virtual void ManageMousePress(QMouseEvent *) {};
00615 
00621   virtual void ManageMouseRelease(QMouseEvent *) {};
00622 
00627   virtual void mousePressEvent (QMouseEvent *pqEvent);
00628 
00631   virtual void timerEvent(QTimerEvent *pqEvent) {
00632     if (m_fRefresh && ((QTimerEvent *)pqEvent)->timerId() == m_nTimerID) {
00633       m_pQGLWidget->updateGL();
00634       m_fRefresh = false;
00635     }
00636   };
00637 
00639   //virtual void keyPressEvent( QKeyEvent * ) {};
00640 
00642   //virtual void paintEvent(QPaintEvent *) {};
00643 
00645   //virtual void resizeEvent(QResizeEvent *) {};
00646 
00648   //virtual void mouseReleaseEvent (QMouseEvent *event) {};
00649 
00651   //virtual void mouseMoveEvent (QMouseEvent *event) {};
00652 
00653 
00654 private:
00656   // PRIVATE METHODS //
00658 
00659 
00667   void initCursors();
00668 
00672   void initPopupMenu();
00673 
00677   void initConnects();
00678 
00683   virtual void setVPRes( int nWidth, int nHeight );
00684 
00685 
00687   // PROTECTED MEMBERS //
00689 
00690 protected:
00691   CCamera m_cCurrentCamera;
00692   CCamera m_cHomeCamera;
00693 
00694   GLenum  m_eRenderMode;
00695 
00696   bool   m_fFullViewer;
00697 
00698   // GUI stuff
00699   QFrame *m_pQFrame;
00700   QGLSignalWidget *m_pQGLWidget;
00701   QHBoxLayout *m_pQHBoxLayout;
00702 
00703   QPopupMenu *m_pqPopupMenu;           // pointer to the popupmenu
00704 
00705   QBitmap m_qMovePix, m_qSelectPix, m_qMoveMaskPix, m_qSelectMaskPix;
00706   QCursor *m_pqMoveCursor, *m_pqSelectCursor;
00707 
00708   /* Stereo stuff */
00709   StereoMode  m_stereoMode;
00710   bool        m_fAllowStereoSimulation;
00711   QStereoCtrl *m_pStereoCtrl;
00712 
00713 
00715   // PRIVATE MEMBERS //
00717 
00718 private:
00719   bool   m_fRefresh, m_fHandleMouseEvents;
00720   int    m_nRefreshRate,
00721          m_nTimerID;
00722 };
00723 
00724 
00725 #endif // __QGLVIEWER_H_

Generated on Wed Mar 5 18:23:25 2003 for QGLViewer by doxygen1.3-rc3