QGLViewer.h

Go to the documentation of this file.
00001 /*
00002  * QGLViewer.h
00003  * $Id: QGLViewer.h,v 1.11 2003/06/24 14:50:02 anxo 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 #if _MSC_VER >= 1300
00051 #include <iostream>
00052 #else
00053 #include <iostream.h>
00054 #endif
00055 
00056 
00057 // Own
00059 #include "QGLSignalWidget.h"
00060 #include "CCamera.h"
00061 #include "CBoundingBox3D.h"
00062 
00063 
00064 // Forward declarations
00066 class QHBoxLayout;
00067 class QFrame;
00068 class QCursor;
00069 class QIconSet;
00070 class QPixmap;
00071 class QStereoCtrl;
00072 
00073 
00074 // for Qt 2.x compatibility
00075 #if QT_VERSION < 300
00076 #define Q_CHECK_PTR CHECK_PTR
00077 #endif
00078 
00079 
00081 
00090 class QGLViewer: public QFrame {
00091   Q_OBJECT
00092 
00093 public:
00095   // PUBLIC ENUMS //
00097 
00098 
00100   enum ProjectionMode {
00101     parallel,           
00102     perspective         
00103   };
00104 
00106   enum CameraType {
00107     CurrentCam = 1,       
00108     HomeCam    = 2,       
00109     BothCams   = 3        
00110   };
00111 
00113   enum StereoMode {
00114     STEREO_ON,            
00115     STEREO_OFF,           
00116     STEREO_SIMULATE       
00117   };                      
00123   enum StereoBuffer {
00124     MONO,                 
00125     STEREO_LEFT,          
00126     STEREO_RIGHT          
00127   };
00128 
00130   // PUBLIC METHODS //
00132 
00133 
00137   QGLViewer(QWidget * parent=0, 
00138             const char * name=0, const QGLWidget * shareWidget = 0, 
00139             WFlags f=0, bool viewertype=true,
00140             const QGLFormat &format=QGLFormat::defaultFormat());
00141 
00146   QGLViewer(const CCamera &homecam, QWidget * parent=0,
00147             const char * name=0, const QGLWidget * shareWidget = 0, 
00148             WFlags f=0, bool viewertype=true,
00149             const QGLFormat &format=QGLFormat::defaultFormat());
00150 
00151 
00156   QGLViewer(const CBoundingBox3D &bbox, QWidget * parent=0,
00157             const char * name=0, const QGLWidget * shareWidget = 0, 
00158             WFlags f=0, bool viewertype=true,
00159             const QGLFormat &format=QGLFormat::defaultFormat());
00160 
00161 
00165   virtual ~QGLViewer() {};
00166 
00167 
00171   void setRefreshRate(int nFramesPerSecond);
00172 
00174   int getRefreshRate() { return m_nRefreshRate; };
00175 
00183   virtual void setBoundingBox(const CBoundingBox3D &cBBox,bool fUpdate=false);
00184 
00188   virtual void setCamera(const CCamera &cCamera, CameraType which=CurrentCam);
00189 
00193   CCamera& getCamera() {  return m_cCurrentCamera; };
00194 
00198   CCamera *getCameraPtr() { return &m_cCurrentCamera; };
00199 
00203   virtual ProjectionMode getProjectionMode() {
00204     return (m_cCurrentCamera.getCameraType() == CCamera::orthographic) ? parallel : perspective;
00205   };
00206 
00214   virtual void setFullViewer(bool state) {
00215     m_fFullViewer = state;
00216   };
00217 
00222   bool isFullViewer() { return m_fFullViewer; };
00223 
00227   QGLSignalWidget *getDrawArea() {
00228     return m_pQGLWidget;
00229   };
00230 
00234   void makeCurrent() {
00235     m_pQGLWidget->makeCurrent();
00236   }
00237 
00242   virtual void enableMouseEvents(bool fFlag) {
00243     m_fHandleMouseEvents = fFlag;
00244   };
00245 
00249   GLenum getRenderMode() {
00250     return m_eRenderMode;
00251   }
00252 
00256   QPopupMenu *getMainMenu() { return m_pqPopupMenu; };
00257 
00261   int insertItem(const QString &text, const QObject *receiver, const char *member) {
00262     return m_pqPopupMenu->insertItem(text, receiver, member);
00263   };
00264 
00268   int insertItem(const QIconSet &icon, const QString &text, const QObject *receiver, const char *member) {
00269     return m_pqPopupMenu->insertItem(icon, text, receiver, member);
00270   };
00271 
00275   int insertItem(const QPixmap &pixmap, const QString &text, const QObject *receiver, const char *member) {
00276     return m_pqPopupMenu->insertItem(pixmap, text, receiver, member);
00277   };
00278 
00282   int insertItem(const QString &text, QPopupMenu *pqPopup) {
00283     return m_pqPopupMenu->insertItem(text, pqPopup);
00284   };
00285 
00289   int insertItem(const QPixmap &pixmap, QPopupMenu *pqPopup) {
00290     return m_pqPopupMenu->insertItem(pixmap, pqPopup);
00291   };
00292 
00297   bool isItemEnabled(int nID) { return m_pqPopupMenu->isItemEnabled(nID); };
00298 
00303   void setItemEnabled(int nID, bool fEnable) { m_pqPopupMenu->setItemEnabled(nID, fEnable); };
00304 
00309   bool isItemChecked(int nID) { return m_pqPopupMenu->isItemChecked(nID); };
00310 
00315   void setItemChecked(int nID, bool fCheck) { m_pqPopupMenu->setItemChecked(nID, fCheck); }; 
00316 
00324   void allowStereoSimulation( bool flag ) { m_fAllowStereoSimulation = flag; }
00325 
00330   StereoMode getStereoMode() { return m_stereoMode; }
00331 
00332 
00333 public slots:
00335   // PUBLIC SLOTS //
00337 
00342   virtual void sltUpdateView() {
00343     m_fRefresh = true;
00344   };
00345 
00350   virtual void sltToggleStereo();
00351 
00356   virtual void sltViewAll();
00357 
00358 signals:
00360   // SIGNALS //
00362 
00366   void sigProjModeToggled();
00367 
00373   void sigRenderModeChanged();
00374 
00384   void sigSelected(QMouseEvent *pqEvent);
00385 
00392   void sigReleased(QMouseEvent *pqEvent);
00393 
00400   void sigMoved(QMouseEvent *pqEvent);
00401 
00408   void sigInitGL();
00409 
00415   void sigRedrawGL();
00416 
00423   void sigResizeGL(int nWidth, int nHeight);
00424 
00430   void sigRatioChanged(double rdRatio);
00431 
00437   void sigFovyChanged(double rdFovy);
00438 
00439 
00440 
00441 protected slots:
00443   // PROTECTED SLOTS //
00445 
00446 
00450   virtual void sltSetProjectionMode();
00451 
00456   virtual void sltSetHome();
00457 
00461   virtual void sltGoHome();
00462 
00466   virtual void sltToggleProjectionMode();
00467 
00472   virtual void sltToggleRenderMode();
00473 
00479   virtual void sltManageDrop(QDropEvent *pqEvent);
00480 
00486   virtual void sltManageDragEnter(QDragEnterEvent *pqEvent);
00487 
00492   virtual void sltManageDragLeave(QDragLeaveEvent *pqEvent);
00493 
00494 
00495 private slots:
00497   // PRIVATE SLOTS //
00499 
00500 
00506   void sltResizeGL(int w, int h);
00507 
00513   void sltPaintGL();
00514 
00518   void sltSwitchMousePress(QMouseEvent *event) {
00519     if (m_eRenderMode == GL_SELECT) {
00520       emit(sigSelected(event));
00521     }
00522     else {
00523       if (m_fHandleMouseEvents)
00524         ManageMousePress(event);
00525     }
00526   };
00527 
00531   void sltSwitchMouseRelease(QMouseEvent *event) {
00532     if (m_eRenderMode == GL_SELECT) {
00533       emit(sigReleased(event));
00534     }
00535     else {
00536       if (m_fHandleMouseEvents)
00537         ManageMouseRelease(event);
00538     }
00539   };
00540 
00544   void sltSwitchMouseMove(QMouseEvent *event) {
00545     if (m_eRenderMode == GL_SELECT) {
00546       emit(sigMoved(event));
00547     }
00548     else {
00549       if (m_fHandleMouseEvents)
00550         ManageMouseMove(event);
00551     }
00552   };
00553     
00557   void sltPopMenu(QMouseEvent *pqEvent);
00558 
00559 
00560 protected: 
00562   // PROTECTED METHODS //
00564 
00565 
00570   virtual void initQFrame(const char * name, const QGLWidget * shareWidget,
00571                           WFlags f, const QGLFormat &format=QGLFormat::defaultFormat());
00572 
00579   QFrame *getQFrame() {
00580     return m_pQFrame;
00581   }
00582 
00587   void setFrustum(StereoBuffer buffer = QGLViewer::MONO);
00588 
00590   void setFrustumMono();
00591 
00593   void setFrustumStereoLeft();
00594 
00596   void setFrustumStereoRight();
00597 
00603   void setLookAt();
00604 
00605 
00611   virtual void ManageMouseMove(QMouseEvent *) {};
00612 
00618   virtual void ManageMousePress(QMouseEvent *) {};
00619 
00625   virtual void ManageMouseRelease(QMouseEvent *) {};
00626 
00631   virtual void mousePressEvent (QMouseEvent *pqEvent);
00632 
00635   virtual void timerEvent(QTimerEvent *pqEvent) {
00636     if (m_fRefresh && ((QTimerEvent *)pqEvent)->timerId() == m_nTimerID) {
00637       m_pQGLWidget->updateGL();
00638       m_fRefresh = false;
00639     }
00640   };
00641 
00643   //virtual void keyPressEvent( QKeyEvent * ) {};
00644 
00646   //virtual void paintEvent(QPaintEvent *) {};
00647 
00649   //virtual void resizeEvent(QResizeEvent *) {};
00650 
00652   //virtual void mouseReleaseEvent (QMouseEvent *event) {};
00653 
00655   //virtual void mouseMoveEvent (QMouseEvent *event) {};
00656 
00657 
00658 private:
00660   // PRIVATE METHODS //
00662 
00663 
00671   void initCursors();
00672 
00676   void initPopupMenu();
00677 
00681   void initConnects();
00682 
00687   virtual void setVPRes( int nWidth, int nHeight );
00688 
00689 
00691   // PROTECTED MEMBERS //
00693 
00694 protected:
00695   CCamera m_cCurrentCamera;
00696   CCamera m_cHomeCamera;
00697 
00698   GLenum  m_eRenderMode;
00699 
00700   bool   m_fFullViewer;
00701 
00702   // GUI stuff
00703   QFrame *m_pQFrame;
00704   QGLSignalWidget *m_pQGLWidget;
00705   QHBoxLayout *m_pQHBoxLayout;
00706 
00707   QPopupMenu *m_pqPopupMenu;           // pointer to the popupmenu
00708 
00709   QBitmap m_qMovePix, m_qSelectPix, m_qMoveMaskPix, m_qSelectMaskPix;
00710   QCursor *m_pqMoveCursor, *m_pqSelectCursor;
00711 
00712   /* Stereo stuff */
00713   StereoMode  m_stereoMode;
00714   bool        m_fAllowStereoSimulation;
00715   QStereoCtrl *m_pStereoCtrl;
00716 
00717 
00719   // PRIVATE MEMBERS //
00721 
00722 private:
00723   bool   m_fRefresh, m_fHandleMouseEvents;
00724   int    m_nRefreshRate,
00725          m_nTimerID;
00726 };
00727 
00728 
00729 #endif // __QGLVIEWER_H_

Generated on Mon Jul 10 12:45:59 2006 for QGLViewer by  doxygen 1.4.7