qglviewer.h
1 /****************************************************************************
2 
3  Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
4 
5  This file is part of the QGLViewer library version 2.5.2.
6 
7  http://www.libqglviewer.com - contact@libqglviewer.com
8 
9  This file may be used under the terms of the GNU General Public License
10  versions 2.0 or 3.0 as published by the Free Software Foundation and
11  appearing in the LICENSE file included in the packaging of this file.
12  In addition, as a special exception, Gilles Debunne gives you certain
13  additional rights, described in the file GPL_EXCEPTION in this package.
14 
15  libQGLViewer uses dual licensing. Commercial/proprietary software must
16  purchase a libQGLViewer Commercial License.
17 
18  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
19  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 
21 *****************************************************************************/
22 
23 #ifndef QGLVIEWER_QGLVIEWER_H
24 #define QGLVIEWER_QGLVIEWER_H
25 
26 #include "camera.h"
27 
28 #include <QMap>
29 #include <QClipboard>
30 #include <QTime>
31 
32 class QTabWidget;
33 
34 namespace qglviewer {
35 class MouseGrabber;
36 class ManipulatedFrame;
37 class ManipulatedCameraFrame;
38 }
39 
62 class QGLVIEWER_EXPORT QGLViewer : public QGLWidget
63 {
64  Q_OBJECT
65 
66 public:
67  // Complete implementation is provided so that the constructor is defined with QT3_SUPPORT when .h is included.
68  // (Would not be available otherwise since lib is compiled without QT3_SUPPORT).
69 #ifdef QT3_SUPPORT
70  explicit QGLViewer(QWidget* parent=NULL, const char* name=0, const QGLWidget* shareWidget=0, Qt::WindowFlags flags=0)
71  : QGLWidget(parent, name, shareWidget, flags)
72  { defaultConstructor(); }
73 
74  explicit QGLViewer(const QGLFormat& format, QWidget* parent=0, const char* name=0, const QGLWidget* shareWidget=0,Qt::WindowFlags flags=0)
75  : QGLWidget(format, parent, name, shareWidget, flags)
76  { defaultConstructor(); }
77 
78  QGLViewer(QGLContext* context, QWidget* parent, const char* name=0, const QGLWidget* shareWidget=0, Qt::WindowFlags flags=0)
79  : QGLWidget(context, parent, name, shareWidget, flags) {
80  defaultConstructor(); }
81 
82 #else
83 
84  explicit QGLViewer(QWidget* parent=0, const QGLWidget* shareWidget=0, Qt::WindowFlags flags=0);
85  explicit QGLViewer(QGLContext *context, QWidget* parent=0, const QGLWidget* shareWidget=0, Qt::WindowFlags flags=0);
86  explicit QGLViewer(const QGLFormat& format, QWidget* parent=0, const QGLWidget* shareWidget=0, Qt::WindowFlags flags=0);
87 #endif
88 
89  virtual ~QGLViewer();
90 
93 public:
97  bool axisIsDrawn() const { return axisIsDrawn_; }
101  bool gridIsDrawn() const { return gridIsDrawn_; }
108  bool FPSIsDisplayed() const { return FPSIsDisplayed_; }
113  bool textIsEnabled() const { return textIsEnabled_; }
114 
123  bool cameraIsEdited() const { return cameraIsEdited_; }
124 
125 
126 public Q_SLOTS:
128  void setAxisIsDrawn(bool draw=true) { axisIsDrawn_ = draw; Q_EMIT axisIsDrawnChanged(draw); update(); }
130  void setGridIsDrawn(bool draw=true) { gridIsDrawn_ = draw; Q_EMIT gridIsDrawnChanged(draw); update(); }
132  void setFPSIsDisplayed(bool display=true) { FPSIsDisplayed_ = display; Q_EMIT FPSIsDisplayedChanged(display); update(); }
134  void setTextIsEnabled(bool enable=true) { textIsEnabled_ = enable; Q_EMIT textIsEnabledChanged(enable); update(); }
135  void setCameraIsEdited(bool edit=true);
136 
138  void toggleAxisIsDrawn() { setAxisIsDrawn(!axisIsDrawn()); }
140  void toggleGridIsDrawn() { setGridIsDrawn(!gridIsDrawn()); }
142  void toggleFPSIsDisplayed() { setFPSIsDisplayed(!FPSIsDisplayed()); }
144  void toggleTextIsEnabled() { setTextIsEnabled(!textIsEnabled()); }
146  void toggleCameraIsEdited() { setCameraIsEdited(!cameraIsEdited()); }
148 
149 
152 public:
168  QColor backgroundColor() const { return backgroundColor_; }
169 
182  QColor foregroundColor() const { return foregroundColor_; }
183 public Q_SLOTS:
186  void setBackgroundColor(const QColor& color) { backgroundColor_=color; qglClearColor(color); }
188  void setForegroundColor(const QColor& color) { foregroundColor_ = color; }
190 
191 
194 public:
206  float sceneRadius() const { return camera()->sceneRadius(); }
215  qglviewer::Vec sceneCenter() const { return camera()->sceneCenter(); }
216 
217 public Q_SLOTS:
222  virtual void setSceneRadius(float radius) { camera()->setSceneRadius(radius); }
223 
228  virtual void setSceneCenter(const qglviewer::Vec& center) { camera()->setSceneCenter(center); }
229 
237  void setSceneBoundingBox(const qglviewer::Vec& min, const qglviewer::Vec& max) { camera()->setSceneBoundingBox(min,max); }
238 
242  void showEntireScene() { camera()->showEntireScene(); update(); }
244 
245 
248 public:
250  qglviewer::Camera* camera() const { return camera_; }
251 
262  qglviewer::ManipulatedFrame* manipulatedFrame() const { return manipulatedFrame_; }
263 
264 public Q_SLOTS:
265  void setCamera(qglviewer::Camera* const camera);
266  void setManipulatedFrame(qglviewer::ManipulatedFrame* frame);
268 
269 
272 public:
289  qglviewer::MouseGrabber* mouseGrabber() const { return mouseGrabber_; }
290 
291  void setMouseGrabberIsEnabled(const qglviewer::MouseGrabber* const mouseGrabber, bool enabled=true);
301  bool mouseGrabberIsEnabled(const qglviewer::MouseGrabber* const mouseGrabber) { return !disabledMouseGrabbers_.contains(reinterpret_cast<size_t>(mouseGrabber)); }
302 public Q_SLOTS:
303  void setMouseGrabber(qglviewer::MouseGrabber* mouseGrabber);
305 
306 
309 public:
311  float aspectRatio() const { return static_cast<float>(width())/static_cast<float>(height()); }
322  float currentFPS() { return f_p_s_; }
329  bool isFullScreen() const { return fullScreen_; }
349  bool displaysInStereo() const { return stereo_; }
351  virtual QSize sizeHint() const { return QSize(600, 400); }
352 
353 public Q_SLOTS:
354  void setFullScreen(bool fullScreen=true);
355  void setStereoDisplay(bool stereo=true);
357  void toggleFullScreen() { setFullScreen(!isFullScreen()); }
359  void toggleStereoDisplay() { setStereoDisplay(!stereo_); }
360  void toggleCameraMode();
361 
362 private:
363  bool cameraIsInRotateMode() const;
365 
366 
369 public:
370  static void drawArrow(float length=1.0f, float radius=-1.0f, int nbSubdivisions=12);
371  static void drawArrow(const qglviewer::Vec& from, const qglviewer::Vec& to, float radius=-1.0f, int nbSubdivisions=12);
372  static void drawAxis(float length=1.0f);
373  static void drawGrid(float size=1.0f, int nbSubdivisions=10);
374 
375  virtual void startScreenCoordinatesSystem(bool upward=false) const;
376  virtual void stopScreenCoordinatesSystem() const;
377 
378  void drawText(int x, int y, const QString& text, const QFont& fnt=QFont());
379  void displayMessage(const QString& message, int delay=2000);
380  // void draw3DText(const qglviewer::Vec& pos, const qglviewer::Vec& normal, const QString& string, GLfloat height=0.1f);
381 
382 protected:
383  virtual void drawLight(GLenum light, float scale = 1.0f) const;
384 
385 private:
386  void displayFPS();
388  void drawVectorial() { paintGL(); }
389 
390 #ifndef DOXYGEN
391  friend void drawVectorial(void* param);
392 #endif
393 
394 
395 
396 #ifdef DOXYGEN
397 
399 public:
401  int width() const;
403  int height() const;
405  virtual void updateGL();
408  static QImage convertToGLFormat(const QImage & image);
410  void qglColor(const QColor& color) const;
412  void qglClearColor(const QColor& color) const;
415  bool isValid() const;
418  bool isSharing() const;
421  virtual void makeCurrent();
426  bool hasMouseTracking () const;
427 public Q_SLOTS:
429  virtual void resize(int width, int height);
431  virtual void setMouseTracking(bool enable);
432 protected:
435  bool autoBufferSwap() const;
436 protected Q_SLOTS:
438  void setAutoBufferSwap(bool on);
440 #endif
441 
442 
445 public:
455  const QString& snapshotFileName() const { return snapshotFileName_; }
456 #ifndef DOXYGEN
457  const QString& snapshotFilename() const;
458 #endif
459 
487  const QString& snapshotFormat() const { return snapshotFormat_; }
493  int snapshotCounter() const { return snapshotCounter_; }
502  int snapshotQuality() { return snapshotQuality_; }
503 
504  // Qt 2.3 does not support double default value parameters in slots.
505  // Remove "Q_SLOTS" from the following line to compile with Qt 2.3
506 public Q_SLOTS:
507  void saveSnapshot(bool automatic=true, bool overwrite=false);
508 
509 public Q_SLOTS:
510  void saveSnapshot(const QString& fileName, bool overwrite=false);
511  void setSnapshotFileName(const QString& name);
512 
514  void setSnapshotFormat(const QString& format) { snapshotFormat_ = format; }
516  void setSnapshotCounter(int counter) { snapshotCounter_ = counter; }
518  void setSnapshotQuality(int quality) { snapshotQuality_ = quality; }
519  bool openSnapshotFormatDialog();
520  void snapshotToClipboard();
521 
522 private:
523  bool saveImageSnapshot(const QString& fileName);
524 
525 #ifndef DOXYGEN
526  /* This class is used internally for screenshot that require tiling (image size size different
527  from window size). Only in that case, is the private tileRegion_ pointer non null.
528  It then contains the current tiled region, which is used by startScreenCoordinatesSystem
529  to adapt the coordinate system. Not using it would result in a tiled drawing of the parts
530  that use startScreenCoordinatesSystem. Also used by scaledFont for same purposes. */
531  class TileRegion { public : double xMin, yMin, xMax, yMax, textScale; };
532 #endif
533 
534 public:
552  QFont scaledFont(const QFont& font) const {
553  if (tileRegion_ == NULL)
554  return font;
555  else {
556  QFont f(font);
557  if (f.pixelSize() == -1)
558  f.setPointSizeF(f.pointSizeF() * tileRegion_->textScale);
559  else
560  f.setPixelSize(f.pixelSize() * tileRegion_->textScale);
561  return f;
562  }
563  }
565 
566 
569 public:
570  GLuint bufferTextureId() const;
579  float bufferTextureMaxU() const { return bufferTextureMaxU_; }
581  float bufferTextureMaxV() const { return bufferTextureMaxV_; }
582 public Q_SLOTS:
583  void copyBufferToTexture(GLint internalFormat, GLenum format=GL_NONE);
585 
588 public:
597  bool animationIsStarted() const { return animationStarted_; }
612  int animationPeriod() const { return animationPeriod_; }
613 
614 public Q_SLOTS:
616  void setAnimationPeriod(int period) { animationPeriod_ = period; }
617  virtual void startAnimation();
618  virtual void stopAnimation();
630  virtual void animate() { Q_EMIT animateNeeded(); }
632  void toggleAnimation() { if (animationIsStarted()) stopAnimation(); else startAnimation(); }
634 
635 public:
636 Q_SIGNALS:
640  void viewerInitialized();
641 
646  void drawNeeded();
647 
659  void drawFinished(bool automatic);
660 
664  void animateNeeded();
665 
669  void helpRequired();
670 
672  void axisIsDrawnChanged(bool drawn);
674  void gridIsDrawnChanged(bool drawn);
676  void FPSIsDisplayedChanged(bool displayed);
678  void textIsEnabledChanged(bool enabled);
680  void cameraIsEditedChanged(bool edited);
682  void stereoChanged(bool on);
687  void pointSelected(const QMouseEvent* e);
688 
693  void mouseGrabberChanged(qglviewer::MouseGrabber* mouseGrabber);
694 
697 public:
713  virtual QString helpString() const { return tr("No help available."); }
714 
715  virtual QString mouseString() const;
716  virtual QString keyboardString() const;
717 
718 #ifndef DOXYGEN
719 
720  virtual QString mouseBindingsString () const { return mouseString(); }
722  virtual QString shortcutBindingsString () const { return keyboardString(); }
723 #endif
724 
725 public Q_SLOTS:
726  virtual void help();
727  virtual void aboutQGLViewer();
728 
729 protected:
735  QTabWidget* helpWidget() { return helpWidget_; }
737 
738 
741 protected:
742  virtual void resizeGL(int width, int height);
743  virtual void initializeGL();
744 
762  virtual void init() { Q_EMIT viewerInitialized(); }
763 
764  virtual void paintGL();
765  virtual void preDraw();
766  virtual void preDrawStereo(bool leftBuffer=true);
767 
783  virtual void draw() {}
784  virtual void fastDraw();
785  virtual void postDraw();
787 
790 protected:
791  virtual void mousePressEvent(QMouseEvent *);
792  virtual void mouseMoveEvent(QMouseEvent *);
793  virtual void mouseReleaseEvent(QMouseEvent *);
794  virtual void mouseDoubleClickEvent(QMouseEvent *);
795  virtual void wheelEvent(QWheelEvent *);
796  virtual void keyPressEvent(QKeyEvent *);
797  virtual void keyReleaseEvent(QKeyEvent *);
798  virtual void timerEvent(QTimerEvent *);
799  virtual void closeEvent(QCloseEvent *);
801 
804 public:
812  int selectedName() const { return selectedObjectId_; }
820  int selectBufferSize() const { return selectBufferSize_; }
821 
835  int selectRegionWidth() const { return selectRegionWidth_; }
837  int selectRegionHeight() const { return selectRegionHeight_; }
838 
844  GLuint* selectBuffer() { return selectBuffer_; }
845 
846 public Q_SLOTS:
847  virtual void select(const QMouseEvent* event);
848  virtual void select(const QPoint& point);
849 
850  void setSelectBufferSize(int size);
852  void setSelectRegionWidth(int width) { selectRegionWidth_ = width; }
854  void setSelectRegionHeight(int height) { selectRegionHeight_ = height; }
859  void setSelectedName(int id) { selectedObjectId_=id; }
860 
861 protected:
862  virtual void beginSelection(const QPoint& point);
885  virtual void drawWithNames() {}
886  virtual void endSelection(const QPoint& point);
894  virtual void postSelection(const QPoint& point) { Q_UNUSED(point); }
896 
897 
900 public:
905  enum KeyboardAction { DRAW_AXIS, DRAW_GRID, DISPLAY_FPS, ENABLE_TEXT, EXIT_VIEWER,
906  SAVE_SCREENSHOT, CAMERA_MODE, FULL_SCREEN, STEREO, ANIMATION, HELP, EDIT_CAMERA,
907  MOVE_CAMERA_LEFT, MOVE_CAMERA_RIGHT, MOVE_CAMERA_UP, MOVE_CAMERA_DOWN,
908  INCREASE_FLYSPEED, DECREASE_FLYSPEED, SNAPSHOT_TO_CLIPBOARD };
909 
910  unsigned int shortcut(KeyboardAction action) const;
911 #ifndef DOXYGEN
912  // QGLViewer 1.x
913  int keyboardAccelerator(KeyboardAction action) const;
914  Qt::Key keyFrameKey(int index) const;
915  Qt::KeyboardModifiers playKeyFramePathStateKey() const;
916  // QGLViewer 2.0 without Qt4 support
917  Qt::KeyboardModifiers addKeyFrameStateKey() const;
918  Qt::KeyboardModifiers playPathStateKey() const;
919 #endif
920  Qt::Key pathKey(int index) const;
921  Qt::KeyboardModifiers addKeyFrameKeyboardModifiers() const;
922  Qt::KeyboardModifiers playPathKeyboardModifiers() const;
923 
924 public Q_SLOTS:
925  void setShortcut(KeyboardAction action, unsigned int key);
926 #ifndef DOXYGEN
927  void setKeyboardAccelerator(KeyboardAction action, int key);
928 #endif
929  void setKeyDescription(int key, QString description);
930  void clearShortcuts();
931 
932  // Key Frames shortcut keys
933 #ifndef DOXYGEN
934  // QGLViewer 1.x compatibility methods
935  virtual void setKeyFrameKey(int index, int key);
936  virtual void setPlayKeyFramePathStateKey(int buttonState);
937  // QGLViewer 2.0 without Qt4 support
938  virtual void setPlayPathStateKey(int buttonState);
939  virtual void setAddKeyFrameStateKey(int buttonState);
940 #endif
941  virtual void setPathKey(int key, int index = 0);
942  virtual void setPlayPathKeyboardModifiers(Qt::KeyboardModifiers modifiers);
943  virtual void setAddKeyFrameKeyboardModifiers(Qt::KeyboardModifiers modifiers);
945 
946 
947 public:
954  enum MouseHandler { CAMERA, FRAME };
955 
960  enum ClickAction { NO_CLICK_ACTION, ZOOM_ON_PIXEL, ZOOM_TO_FIT, SELECT, RAP_FROM_PIXEL, RAP_IS_CENTER,
961  CENTER_FRAME, CENTER_SCENE, SHOW_ENTIRE_SCENE, ALIGN_FRAME, ALIGN_CAMERA };
962 
963 
969  enum MouseAction { NO_MOUSE_ACTION,
970  ROTATE, ZOOM, TRANSLATE,
971  MOVE_FORWARD, LOOK_AROUND, MOVE_BACKWARD,
972  SCREEN_ROTATE, ROLL, DRIVE,
973  SCREEN_TRANSLATE, ZOOM_ON_REGION };
974 
975 #ifndef DOXYGEN
976  MouseAction mouseAction(int state) const;
977  int mouseHandler(int state) const;
978  int mouseButtonState(MouseHandler handler, MouseAction action, bool withConstraint=true) const;
979  ClickAction clickAction(int state, bool doubleClick, Qt::MouseButtons buttonsBefore) const;
980  void getClickButtonState(ClickAction action, int& state, bool& doubleClick, Qt::MouseButtons& buttonsBefore) const;
981  int wheelButtonState(MouseHandler handler, MouseAction action, bool withConstraint=true) const;
982 #endif
983 
984  MouseAction mouseAction(Qt::Key key, Qt::KeyboardModifiers modifiers, Qt::MouseButton button) const;
985  int mouseHandler(Qt::Key key, Qt::KeyboardModifiers modifiers, Qt::MouseButton button) const;
986 
987  void getMouseActionBinding(MouseHandler handler, MouseAction action, bool withConstraint,
988  Qt::Key& key, Qt::KeyboardModifiers& modifiers, Qt::MouseButton& button) const;
989 
990  ClickAction clickAction(Qt::Key key, Qt::KeyboardModifiers modifiers, Qt::MouseButton button,
991  bool doubleClick=false, Qt::MouseButtons buttonsBefore=Qt::NoButton) const;
992 
993  void getClickActionBinding(ClickAction action, Qt::Key& key, Qt::KeyboardModifiers& modifiers,
994  Qt::MouseButton& button, bool& doubleClick, Qt::MouseButtons& buttonsBefore) const;
995 
996  MouseAction wheelAction(Qt::Key key, Qt::KeyboardModifiers modifiers) const;
997  int wheelHandler(Qt::Key key, Qt::KeyboardModifiers modifiers) const;
998 
999  void getWheelActionBinding(MouseHandler handler, MouseAction action, bool withConstraint,
1000  Qt::Key& key, Qt::KeyboardModifiers& modifiers) const;
1001 
1002 public Q_SLOTS:
1003 #ifndef DOXYGEN
1004  void setMouseBinding(int state, MouseHandler handler, MouseAction action, bool withConstraint=true);
1005  void setMouseBinding(int state, ClickAction action, bool doubleClick=false, Qt::MouseButtons buttonsBefore=Qt::NoButton);
1006  void setMouseBindingDescription(int state, QString description, bool doubleClick=false, Qt::MouseButtons buttonsBefore=Qt::NoButton);
1007 #endif
1008 
1009  void setMouseBinding(Qt::KeyboardModifiers modifiers, Qt::MouseButton buttons, MouseHandler handler, MouseAction action, bool withConstraint=true);
1010  void setMouseBinding(Qt::KeyboardModifiers modifiers, Qt::MouseButton button, ClickAction action, bool doubleClick=false, Qt::MouseButtons buttonsBefore=Qt::NoButton);
1011  void setWheelBinding(Qt::KeyboardModifiers modifiers, MouseHandler handler, MouseAction action, bool withConstraint=true);
1012  void setMouseBindingDescription(Qt::KeyboardModifiers modifiers, Qt::MouseButton button, QString description, bool doubleClick=false, Qt::MouseButtons buttonsBefore=Qt::NoButton);
1013 
1014  void setMouseBinding(Qt::Key key, Qt::KeyboardModifiers modifiers, Qt::MouseButton buttons, MouseHandler handler, MouseAction action, bool withConstraint=true);
1015  void setMouseBinding(Qt::Key key, Qt::KeyboardModifiers modifiers, Qt::MouseButton button, ClickAction action, bool doubleClick=false, Qt::MouseButtons buttonsBefore=Qt::NoButton);
1016  void setWheelBinding(Qt::Key key, Qt::KeyboardModifiers modifiers, MouseHandler handler, MouseAction action, bool withConstraint=true);
1017  void setMouseBindingDescription(Qt::Key key, Qt::KeyboardModifiers modifiers, Qt::MouseButton button, QString description, bool doubleClick=false, Qt::MouseButtons buttonsBefore=Qt::NoButton);
1018 
1019  void clearMouseBindings();
1020 
1021 #ifndef DOXYGEN
1022  MouseAction wheelAction(Qt::KeyboardModifiers modifiers) const;
1023  int wheelHandler(Qt::KeyboardModifiers modifiers) const;
1024 
1025  void setHandlerKeyboardModifiers(MouseHandler handler, Qt::KeyboardModifiers modifiers);
1026  void setHandlerStateKey(MouseHandler handler, int buttonState);
1027  void setMouseStateKey(MouseHandler handler, int buttonState);
1028 #endif
1029 
1030 private:
1031  static QString mouseActionString(QGLViewer::MouseAction ma);
1032  static QString clickActionString(QGLViewer::ClickAction ca);
1034 
1035 
1038 public:
1039  QString stateFileName() const;
1040  virtual QDomElement domElement(const QString& name, QDomDocument& document) const;
1041 
1042 public Q_SLOTS:
1043  virtual void initFromDOMElement(const QDomElement& element);
1044  virtual void saveStateToFile(); // cannot be const because of QMessageBox
1045  virtual bool restoreStateFromFile();
1046 
1059  void setStateFileName(const QString& name) { stateFileName_ = name; }
1060 
1061 #ifndef DOXYGEN
1062  void saveToFile(const QString& fileName=QString::null);
1063  bool restoreFromFile(const QString& fileName=QString::null);
1064 #endif
1065 
1066 private:
1067  static void saveStateToFileForAllViewers();
1069 
1070 
1073 public:
1085  static const QList<QGLViewer*>& QGLViewerPool() { return QGLViewer::QGLViewerPool_; }
1086 
1087 
1095  static int QGLViewerIndex(const QGLViewer* const viewer) { return QGLViewer::QGLViewerPool_.indexOf(const_cast<QGLViewer*>(viewer)); }
1097 
1098 #ifndef DOXYGEN
1099 
1101 public:
1102  virtual void setVisualHintsMask(int mask, int delay = 2000);
1103  virtual void drawVisualHints();
1104 
1105 public Q_SLOTS:
1106  virtual void resetVisualHints();
1108 #endif
1109 
1110 private Q_SLOTS:
1111  // Patch for a Qt bug with fullScreen on startup
1112  void delayedFullScreen() { move(prevPos_); setFullScreen(); }
1113  void hideMessage();
1114 
1115 private:
1116  // Copy constructor and operator= are declared private and undefined
1117  // Prevents everyone from trying to use them
1118  QGLViewer(const QGLViewer& v);
1119  QGLViewer& operator=(const QGLViewer& v);
1120 
1121  // Set parameters to their default values. Called by the constructors.
1122  void defaultConstructor();
1123 
1124  void handleKeyboardAction(KeyboardAction id);
1125 
1126  // C a m e r a
1127  qglviewer::Camera* camera_;
1128  bool cameraIsEdited_;
1129  float previousCameraZClippingCoefficient_;
1130  int previousPathId_; // Double key press recognition
1131  void connectAllCameraKFIInterpolatedSignals(bool connection=true);
1132 
1133  // C o l o r s
1134  QColor backgroundColor_, foregroundColor_;
1135 
1136  // D i s p l a y f l a g s
1137  bool axisIsDrawn_; // world axis
1138  bool gridIsDrawn_; // world XY grid
1139  bool FPSIsDisplayed_; // Frame Per Seconds
1140  bool textIsEnabled_; // drawText() actually draws text or not
1141  bool stereo_; // stereo display
1142  bool fullScreen_; // full screen mode
1143  QPoint prevPos_; // Previous window position, used for full screen mode
1144 
1145  // A n i m a t i o n
1146  bool animationStarted_; // animation mode started
1147  int animationPeriod_; // period in msecs
1148  int animationTimerId_;
1149 
1150  // F P S d i s p l a y
1151  QTime fpsTime_;
1152  unsigned int fpsCounter_;
1153  QString fpsString_;
1154  float f_p_s_;
1155 
1156  // M e s s a g e s
1157  QString message_;
1158  bool displayMessage_;
1159  QTimer messageTimer_;
1160 
1161  // M a n i p u l a t e d f r a m e
1162  qglviewer::ManipulatedFrame* manipulatedFrame_;
1163  bool manipulatedFrameIsACamera_;
1164 
1165  // M o u s e G r a b b e r
1166  qglviewer::MouseGrabber* mouseGrabber_;
1167  bool mouseGrabberIsAManipulatedFrame_;
1168  bool mouseGrabberIsAManipulatedCameraFrame_;
1169  QMap<size_t, bool> disabledMouseGrabbers_;
1170 
1171  // S e l e c t i o n
1172  int selectRegionWidth_, selectRegionHeight_;
1173  int selectBufferSize_;
1174  GLuint* selectBuffer_;
1175  int selectedObjectId_;
1176 
1177  // V i s u a l h i n t s
1178  int visualHint_;
1179 
1180  // S h o r t c u t k e y s
1181  void setDefaultShortcuts();
1182  QString cameraPathKeysString() const;
1183  QMap<KeyboardAction, QString> keyboardActionDescription_;
1184  QMap<KeyboardAction, unsigned int> keyboardBinding_;
1185  QMap<int, QString> keyDescription_;
1186 
1187  // K e y F r a m e s s h o r t c u t s
1188  QMap<Qt::Key, int> pathIndex_;
1189  Qt::KeyboardModifiers addKeyFrameKeyboardModifiers_, playPathKeyboardModifiers_;
1190 
1191  // B u f f e r T e x t u r e
1192  GLuint bufferTextureId_;
1193  float bufferTextureMaxU_, bufferTextureMaxV_;
1194  int bufferTextureWidth_, bufferTextureHeight_;
1195  unsigned int previousBufferTextureFormat_;
1196  int previousBufferTextureInternalFormat_;
1197 
1198 #ifndef DOXYGEN
1199  // M o u s e a c t i o n s
1200  struct MouseActionPrivate {
1201  MouseHandler handler;
1202  MouseAction action;
1203  bool withConstraint;
1204  };
1205 
1206  // M o u s e b i n d i n g s
1207  struct MouseBindingPrivate {
1208  const Qt::KeyboardModifiers modifiers;
1209  const Qt::MouseButton button;
1210  const Qt::Key key;
1211 
1212  MouseBindingPrivate(Qt::KeyboardModifiers m, Qt::MouseButton b, Qt::Key k)
1213  : modifiers(m), button(b), key(k) {}
1214 
1215  // This sort order is used in mouseString() to display sorted mouse bindings
1216  bool operator<(const MouseBindingPrivate& mbp) const
1217  {
1218  if (key != mbp.key)
1219  return key < mbp.key;
1220  if (modifiers != mbp.modifiers)
1221  return modifiers < mbp.modifiers;
1222  return button < mbp.button;
1223  }
1224  };
1225 
1226  // W h e e l b i n d i n g s
1227  struct WheelBindingPrivate {
1228  const Qt::KeyboardModifiers modifiers;
1229  const Qt::Key key;
1230 
1231  WheelBindingPrivate(Qt::KeyboardModifiers m, Qt::Key k)
1232  : modifiers(m), key(k) {}
1233 
1234  // This sort order is used in mouseString() to display sorted wheel bindings
1235  bool operator<(const WheelBindingPrivate& wbp) const
1236  {
1237  if (key != wbp.key)
1238  return key < wbp.key;
1239  return modifiers < wbp.modifiers;
1240  }
1241  };
1242 
1243  // C l i c k b i n d i n g s
1244  struct ClickBindingPrivate {
1245  const Qt::KeyboardModifiers modifiers;
1246  const Qt::MouseButton button;
1247  const bool doubleClick;
1248  const Qt::MouseButtons buttonsBefore; // only defined when doubleClick is true
1249  const Qt::Key key;
1250 
1251  ClickBindingPrivate(Qt::KeyboardModifiers m, Qt::MouseButton b, bool dc, Qt::MouseButtons bb, Qt::Key k)
1252  : modifiers(m), button(b), doubleClick(dc), buttonsBefore(bb), key(k) {}
1253 
1254  // This sort order is used in mouseString() to display sorted mouse bindings
1255  bool operator<(const ClickBindingPrivate& cbp) const
1256  {
1257  if (key != cbp.key)
1258  return key < cbp.key;
1259  if (buttonsBefore != cbp.buttonsBefore)
1260  return buttonsBefore < cbp.buttonsBefore;
1261  if (modifiers != cbp.modifiers)
1262  return modifiers < cbp.modifiers;
1263  if (button != cbp.button)
1264  return button < cbp.button;
1265  return doubleClick != cbp.doubleClick;
1266  }
1267  };
1268 #endif
1269  static QString formatClickActionPrivate(ClickBindingPrivate cbp);
1270  static bool isValidShortcutKey(int key);
1271 
1272  QMap<ClickBindingPrivate, QString> mouseDescription_;
1273 
1274  void setDefaultMouseBindings();
1275  void performClickAction(ClickAction ca, const QMouseEvent* const e);
1276  QMap<MouseBindingPrivate, MouseActionPrivate> mouseBinding_;
1277  QMap<WheelBindingPrivate, MouseActionPrivate> wheelBinding_;
1278  QMap<ClickBindingPrivate, ClickAction> clickBinding_;
1279  Qt::Key currentlyPressedKey_;
1280 
1281  // S n a p s h o t s
1282  void initializeSnapshotFormats();
1283  QImage frameBufferSnapshot();
1284  QString snapshotFileName_, snapshotFormat_;
1285  int snapshotCounter_, snapshotQuality_;
1286  TileRegion* tileRegion_;
1287 
1288  // Q G L V i e w e r p o o l
1289  static QList<QGLViewer*> QGLViewerPool_;
1290 
1291  // S t a t e F i l e
1292  QString stateFileName_;
1293 
1294  // H e l p w i n d o w
1295  QTabWidget* helpWidget_;
1296 };
1297 
1298 #endif // QGLVIEWER_QGLVIEWER_H
QColor foregroundColor() const
Returns the foreground color used by the viewer.
Definition: qglviewer.h:182
QColor backgroundColor() const
Returns the background color of the viewer.
Definition: qglviewer.h:168
void setSceneBoundingBox(const qglviewer::Vec &min, const qglviewer::Vec &max)
Convenient way to call setSceneCenter() and setSceneRadius() from a (world axis aligned) bounding box...
Definition: qglviewer.h:237
void setSelectRegionWidth(int width)
Sets the selectRegionWidth().
Definition: qglviewer.h:852
float bufferTextureMaxV() const
Same as bufferTextureMaxU(), but for the v texture coordinate.
Definition: qglviewer.h:581
void setSnapshotCounter(int counter)
Sets the snapshotCounter().
Definition: qglviewer.h:516
virtual void drawWithNames()
This method is called by select() and should draw selectable entities.
Definition: qglviewer.h:885
A ManipulatedFrame is a Frame that can be rotated and translated using the mouse. ...
float sceneRadius() const
Returns the scene radius.
Definition: qglviewer.h:206
void toggleCameraIsEdited()
Toggles the state of cameraIsEdited().
Definition: qglviewer.h:146
void setForegroundColor(const QColor &color)
Sets the foregroundColor() of the viewer, used to draw visual hints.
Definition: qglviewer.h:188
MouseAction
Defines the possible actions that can be binded to a mouse action (a click, followed by a mouse displ...
Definition: qglviewer.h:969
QFont scaledFont(const QFont &font) const
Return a possibly scaled version of font, used for snapshot rendering.
Definition: qglviewer.h:552
void setStateFileName(const QString &name)
Defines the stateFileName() used by saveStateToFile() and restoreStateFromFile(). ...
Definition: qglviewer.h:1059
qglviewer::ManipulatedFrame * manipulatedFrame() const
Returns the viewer's qglviewer::ManipulatedFrame.
Definition: qglviewer.h:262
int snapshotCounter() const
Returns the value of the counter used to name snapshots in saveSnapshot() when automatic is true...
Definition: qglviewer.h:493
virtual void init()
Initializes the viewer OpenGL context.
Definition: qglviewer.h:762
GLuint * selectBuffer()
Returns a pointer to an array of GLuint.
Definition: qglviewer.h:844
FARSA_UTIL_TEMPLATE const T max(const T &t1, const U &t2)
KeyboardAction
Defines the different actions that can be associated with a keyboard shortcut using setShortcut()...
Definition: qglviewer.h:905
bool axisIsDrawn() const
Returns true if the world axis is drawn by the viewer.
Definition: qglviewer.h:97
virtual void setSceneCenter(const qglviewer::Vec &center)
Sets the sceneCenter(), defined in world coordinates.
Definition: qglviewer.h:228
Abstract class for objects that grab mouse focus in a QGLViewer.
Definition: mouseGrabber.h:130
bool textIsEnabled() const
Returns true if text display (see drawText()) is enabled.
Definition: qglviewer.h:113
void toggleFullScreen()
Toggles the state of isFullScreen().
Definition: qglviewer.h:357
bool isFullScreen() const
Returns true if the viewer is in fullScreen mode.
Definition: qglviewer.h:329
int animationPeriod() const
The animation loop period, in milliseconds.
Definition: qglviewer.h:612
The Vec class represents 3D positions and 3D vectors.
Definition: vec.h:65
bool gridIsDrawn() const
Returns true if a XY grid is drawn by the viewer.
Definition: qglviewer.h:101
float bufferTextureMaxU() const
Returns the texture coordinate corresponding to the u extremum of the bufferTexture.
Definition: qglviewer.h:579
virtual QString shortcutBindingsString() const
This method is deprecated, use keyboardString() instead.
Definition: qglviewer.h:722
bool displaysInStereo() const
Returns true if the viewer displays in stereo.
Definition: qglviewer.h:349
void setTextIsEnabled(bool enable=true)
Sets the state of textIsEnabled().
Definition: qglviewer.h:134
float currentFPS()
Returns the current averaged viewer frame rate.
Definition: qglviewer.h:322
int selectRegionHeight() const
See the selectRegionWidth() documentation.
Definition: qglviewer.h:837
float aspectRatio() const
Returns the aspect ratio of the viewer's widget (width() / height()).
Definition: qglviewer.h:311
virtual QString mouseBindingsString() const
This method is deprecated, use mouseString() instead.
Definition: qglviewer.h:720
void toggleStereoDisplay()
Toggles the state of displaysInStereo().
Definition: qglviewer.h:359
void setSnapshotQuality(int quality)
Sets the snapshotQuality().
Definition: qglviewer.h:518
int selectedName() const
Returns the name (an integer value) of the entity that was last selected by select().
Definition: qglviewer.h:812
void toggleAxisIsDrawn()
Toggles the state of axisIsDrawn().
Definition: qglviewer.h:138
void setAxisIsDrawn(bool draw=true)
Sets the state of axisIsDrawn().
Definition: qglviewer.h:128
void toggleGridIsDrawn()
Toggles the state of gridIsDrawn().
Definition: qglviewer.h:140
void setBackgroundColor(const QColor &color)
Sets the backgroundColor() of the viewer and calls qglClearColor().
Definition: qglviewer.h:186
virtual void postSelection(const QPoint &point)
This method is called at the end of the select() procedure.
Definition: qglviewer.h:894
A versatile 3D OpenGL viewer based on QGLWidget.
Definition: qglviewer.h:62
const QString & snapshotFileName() const
Returns the snapshot file name used by saveSnapshot().
Definition: qglviewer.h:455
MouseHandler
Defines the different mouse handlers: camera() or manipulatedFrame().
Definition: qglviewer.h:954
QTabWidget * helpWidget()
Returns a pointer to the help widget.
Definition: qglviewer.h:735
qglviewer::Camera * camera() const
Returns the associated qglviewer::Camera, never NULL.
Definition: qglviewer.h:250
bool FPSIsDisplayed() const
Returns true if the viewer displays the current frame rate (Frames Per Second).
Definition: qglviewer.h:108
A perspective or orthographic camera.
Definition: camera.h:84
void setGridIsDrawn(bool draw=true)
Sets the state of gridIsDrawn().
Definition: qglviewer.h:130
ClickAction
Defines the possible actions that can be binded to a mouse click using setMouseBinding(Qt::KeyboardMo...
Definition: qglviewer.h:960
const QString & snapshotFormat() const
Returns the snapshot file format used by saveSnapshot().
Definition: qglviewer.h:487
void toggleTextIsEnabled()
Toggles the state of textIsEnabled().
Definition: qglviewer.h:144
void showEntireScene()
Moves the camera so that the entire scene is visible.
Definition: qglviewer.h:242
void setSelectRegionHeight(int height)
Sets the selectRegionHeight().
Definition: qglviewer.h:854
static const QList< QGLViewer * > & QGLViewerPool()
Returns a QList that contains pointers to all the created QGLViewers.
Definition: qglviewer.h:1085
void setFPSIsDisplayed(bool display=true)
Sets the state of FPSIsDisplayed().
Definition: qglviewer.h:132
qglviewer::Vec sceneCenter() const
Returns the scene center, defined in world coordinates.
Definition: qglviewer.h:215
bool cameraIsEdited() const
Returns true if the camera() is being edited in the viewer.
Definition: qglviewer.h:123
int snapshotQuality()
Defines the image quality of the snapshots produced with saveSnapshot().
Definition: qglviewer.h:502
virtual void setSceneRadius(float radius)
Sets the sceneRadius().
Definition: qglviewer.h:222
void setSelectedName(int id)
Set the selectedName() value.
Definition: qglviewer.h:859
virtual void draw()
The core method of the viewer, that draws the scene.
Definition: qglviewer.h:783
FARSA_UTIL_TEMPLATE const T min(const T &t1, const U &t2)
bool mouseGrabberIsEnabled(const qglviewer::MouseGrabber *const mouseGrabber)
Returns true if mouseGrabber is enabled.
Definition: qglviewer.h:301
qglviewer::MouseGrabber * mouseGrabber() const
Returns the current qglviewer::MouseGrabber, or NULL if no qglviewer::MouseGrabber currently grabs mo...
Definition: qglviewer.h:289
void toggleFPSIsDisplayed()
Toggles the state of FPSIsDisplayed().
Definition: qglviewer.h:142
int selectRegionWidth() const
Returns the width (in pixels) of a selection frustum, centered on the mouse cursor, that is used to select objects.
Definition: qglviewer.h:835
void setAnimationPeriod(int period)
Sets the animationPeriod(), in milliseconds.
Definition: qglviewer.h:616
void toggleAnimation()
Calls startAnimation() or stopAnimation(), depending on animationIsStarted().
Definition: qglviewer.h:632
virtual void animate()
Scene animation method.
Definition: qglviewer.h:630
void setSnapshotFormat(const QString &format)
Sets the snapshotFormat().
Definition: qglviewer.h:514
int selectBufferSize() const
Returns the selectBuffer() size.
Definition: qglviewer.h:820
bool animationIsStarted() const
Return true when the animation loop is started.
Definition: qglviewer.h:597
virtual QString helpString() const
Returns the QString displayed in the help() window main tab.
Definition: qglviewer.h:713
virtual QSize sizeHint() const
Returns the recommended size for the QGLViewer.
Definition: qglviewer.h:351
static int QGLViewerIndex(const QGLViewer *const viewer)
Returns the index of the QGLViewer viewer in the QGLViewerPool().
Definition: qglviewer.h:1095