00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef __QGLVIEWER_H_
00028 #define __QGLVIEWER_H_
00029
00030
00031
00033
00034 #include <qframe.h>
00035 #include <qpopupmenu.h>
00036 #include <qpoint.h>
00037 #include <qbitmap.h>
00038
00039
00040
00042
00043 #include <iostream.h>
00044
00045
00046
00048
00049 #include "CCamera.h"
00050 #include "CBoundingBox3D.h"
00051
00052
00053
00055
00056 class QFrame;
00057 class QCursor;
00058 class QIconSet;
00059 class QPixmap;
00060 class QStereoCtrl;
00061
00062
00063
00064 #if QT_VERSION >= 300
00065 #define CHECK_PTR Q_CHECK_PTR
00066 #endif
00067
00068
00070
00079 class QGLViewer: public QFrame {
00080 Q_OBJECT
00081
00082 public:
00084
00086
00087
00089 enum ProjectionMode {
00090 parallel,
00091 perspective
00092 };
00093
00095 enum CameraType {
00096 CurrentCam = 1,
00097 HomeCam = 2,
00098 BothCams = 3
00099 };
00100
00102 enum StereoMode {
00103 STEREO_ON,
00104 STEREO_OFF,
00105 STEREO_SIMULATE
00106 };
00112 enum StereoBuffer {
00113 MONO,
00114 STEREO_LEFT,
00115 STEREO_RIGHT
00116 };
00117
00119
00121
00122
00126 QGLViewer(QWidget * parent=0,
00127 const char * name=0, const QGLWidget * shareWidget = 0,
00128 WFlags f=0, bool viewertype=true,
00129 const QGLFormat &format=QGLFormat::defaultFormat());
00130
00135 QGLViewer(const CCamera &homecam, QWidget * parent=0,
00136 const char * name=0, const QGLWidget * shareWidget = 0,
00137 WFlags f=0, bool viewertype=true,
00138 const QGLFormat &format=QGLFormat::defaultFormat());
00139
00140
00145 QGLViewer(const CBoundingBox3D &bbox, QWidget * parent=0,
00146 const char * name=0, const QGLWidget * shareWidget = 0,
00147 WFlags f=0, bool viewertype=true,
00148 const QGLFormat &format=QGLFormat::defaultFormat());
00149
00150
00154 virtual ~QGLViewer() {};
00155
00156
00160 void setRefreshRate(int nFramesPerSecond);
00161
00163 int getRefreshRate() { return m_nRefreshRate; };
00164
00172 virtual void setBoundingBox(const CBoundingBox3D &cBBox,bool fUpdate=false);
00173
00177 virtual void setCamera(const CCamera &cCamera, CameraType which=CurrentCam);
00178
00182 CCamera& getCamera() { return m_cCurrentCamera; };
00183
00187 CCamera *getCameraPtr() { return &m_cCurrentCamera; };
00188
00192 virtual ProjectionMode getProjectionMode() {
00193 return (m_cCurrentCamera.getCameraType() == CCamera::orthographic) ? parallel : perspective;
00194 };
00195
00203 virtual void setFullViewer(bool state) {
00204 m_fFullViewer = state;
00205 };
00206
00211 bool isFullViewer() { return m_fFullViewer; };
00212
00216 QGLSignalWidget *getDrawArea() {
00217 return m_pQGLWidget;
00218 };
00219
00223 void makeCurrent() {
00224 m_pQGLWidget->makeCurrent();
00225 }
00226
00231 virtual void enableMouseEvents(bool fFlag) {
00232 m_fHandleMouseEvents = fFlag;
00233 };
00234
00238 GLenum getRenderMode() {
00239 return m_eRenderMode;
00240 }
00241
00245 QPopupMenu *getMainMenu() { return m_pqPopupMenu; };
00246
00250 int insertItem(const QString &text, const QObject *receiver, const char *member) {
00251 return m_pqPopupMenu->insertItem(text, receiver, member);
00252 };
00253
00257 int insertItem(const QIconSet &icon, const QString &text, const QObject *receiver, const char *member) {
00258 return m_pqPopupMenu->insertItem(icon, text, receiver, member);
00259 };
00260
00264 int insertItem(const QPixmap &pixmap, const QString &text, const QObject *receiver, const char *member) {
00265 return m_pqPopupMenu->insertItem(pixmap, text, receiver, member);
00266 };
00267
00271 int insertItem(const QString &text, QPopupMenu *pqPopup) {
00272 return m_pqPopupMenu->insertItem(text, pqPopup);
00273 };
00274
00278 int insertItem(const QPixmap &pixmap, QPopupMenu *pqPopup) {
00279 return m_pqPopupMenu->insertItem(pixmap, pqPopup);
00280 };
00281
00286 bool isItemEnabled(int nID) { return m_pqPopupMenu->isItemEnabled(nID); };
00287
00292 void setItemEnabled(int nID, bool fEnable) { m_pqPopupMenu->setItemEnabled(nID, fEnable); };
00293
00298 bool isItemChecked(int nID) { return m_pqPopupMenu->isItemChecked(nID); };
00299
00304 void setItemChecked(int nID, bool fCheck) { m_pqPopupMenu->setItemChecked(nID, fCheck); };
00305
00313 void allowStereoSimulation( bool flag ) { m_fAllowStereoSimulation = flag; }
00314
00319 StereoMode getStereoMode() { return m_stereoMode; }
00320
00321
00322 public slots:
00324
00326
00331 virtual void sltUpdateView() {
00332 m_fRefresh = true;
00333 };
00334
00339 virtual void sltToggleStereo();
00340
00345 virtual void sltViewAll();
00346
00347 signals:
00349
00351
00355 void sigProjModeToggled();
00356
00362 void sigRenderModeChanged();
00363
00373 void sigSelected(QMouseEvent *pqEvent);
00374
00381 void sigReleased(QMouseEvent *pqEvent);
00382
00389 void sigMoved(QMouseEvent *pqEvent);
00390
00397 void sigInitGL();
00398
00404 void sigRedrawGL();
00405
00412 void sigResizeGL(int nWidth, int nHeight);
00413
00419 void sigRatioChanged(double rdRatio);
00420
00426 void sigFovyChanged(double rdFovy);
00427
00428
00429
00430 protected slots:
00432
00434
00435
00439 virtual void sltSetProjectionMode();
00440
00445 virtual void sltSetHome();
00446
00450 virtual void sltGoHome();
00451
00455 virtual void sltToggleProjectionMode();
00456
00461 virtual void sltToggleRenderMode();
00462
00468 virtual void sltManageDrop(QDropEvent *pqEvent);
00469
00475 virtual void sltManageDragEnter(QDragEnterEvent *pqEvent);
00476
00481 virtual void sltManageDragLeave(QDragLeaveEvent *pqEvent);
00482
00483
00484 private slots:
00486
00488
00489
00495 void sltResizeGL(int w, int h);
00496
00502 void sltPaintGL();
00503
00507 void sltSwitchMousePress(QMouseEvent *event) {
00508 if (m_eRenderMode == GL_SELECT) {
00509 emit(sigSelected(event));
00510 }
00511 else {
00512 if (m_fHandleMouseEvents)
00513 ManageMousePress(event);
00514 }
00515 };
00516
00520 void sltSwitchMouseRelease(QMouseEvent *event) {
00521 if (m_eRenderMode == GL_SELECT) {
00522 emit(sigReleased(event));
00523 }
00524 else {
00525 if (m_fHandleMouseEvents)
00526 ManageMouseRelease(event);
00527 }
00528 };
00529
00533 void sltSwitchMouseMove(QMouseEvent *event) {
00534 if (m_eRenderMode == GL_SELECT) {
00535 emit(sigMoved(event));
00536 }
00537 else {
00538 if (m_fHandleMouseEvents)
00539 ManageMouseMove(event);
00540 }
00541 };
00542
00546 void sltPopMenu(QMouseEvent *pqEvent);
00547
00548
00549 protected:
00551
00553
00554
00559 virtual void initQFrame(const char * name, const QGLWidget * shareWidget,
00560 WFlags f, const QGLFormat &format=QGLFormat::defaultFormat());
00561
00568 QFrame *getQFrame() {
00569 return m_pQFrame;
00570 }
00571
00576 void setFrustum(StereoBuffer buffer = QGLViewer::MONO);
00577
00579 void setFrustumMono();
00580
00582 void setFrustumStereoLeft();
00583
00585 void setFrustumStereoRight();
00586
00592 void setLookAt();
00593
00594
00600 virtual void ManageMouseMove(QMouseEvent *) {};
00601
00607 virtual void ManageMousePress(QMouseEvent *) {};
00608
00614 virtual void ManageMouseRelease(QMouseEvent *) {};
00615
00620 virtual void mousePressEvent (QMouseEvent *pqEvent);
00621
00624 virtual void timerEvent(QTimerEvent *pqEvent) {
00625 if (m_fRefresh && ((QTimerEvent *)pqEvent)->timerId() == m_nTimerID) {
00626 m_pQGLWidget->updateGL();
00627 m_fRefresh = false;
00628 }
00629 };
00630
00632
00633
00635
00636
00638
00639
00641
00642
00644
00645
00646
00647 private:
00649
00651
00652
00660 void initCursors();
00661
00665 void initPopupMenu();
00666
00670 void initConnects();
00671
00676 virtual void setVPRes( int nWidth, int nHeight );
00677
00678
00680
00682
00683 protected:
00684 CCamera m_cCurrentCamera;
00685 CCamera m_cHomeCamera;
00686
00687 GLenum m_eRenderMode;
00688
00689 bool m_fFullViewer;
00690
00691
00692 QFrame *m_pQFrame;
00693 QGLSignalWidget *m_pQGLWidget;
00694 QHBoxLayout *m_pQHBoxLayout;
00695
00696 QPopupMenu *m_pqPopupMenu;
00697
00698 QBitmap m_qMovePix, m_qSelectPix, m_qMoveMaskPix, m_qSelectMaskPix;
00699 QCursor *m_pqMoveCursor, *m_pqSelectCursor;
00700
00701
00702 StereoMode m_stereoMode;
00703 bool m_fAllowStereoSimulation;
00704 QStereoCtrl *m_pStereoCtrl;
00705
00706
00708
00710
00711 private:
00712 bool m_fRefresh, m_fHandleMouseEvents;
00713 int m_nRefreshRate,
00714 m_nTimerID;
00715 };
00716
00717
00718 #endif // __QGLVIEWER_H_