| 1 | /*
 | 
|---|
| 2 |  * GLWorldView.hpp
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  *  Created on: Auf 11, 2010
 | 
|---|
| 5 |  *      Author: heber
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #ifndef GLWORLDVIEW_HPP_
 | 
|---|
| 9 | #define GLWORLDVIEW_HPP_
 | 
|---|
| 10 | 
 | 
|---|
| 11 | // include config.h
 | 
|---|
| 12 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 13 | #include <config.h>
 | 
|---|
| 14 | #endif
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include <Qt3D/qglview.h>
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #include "CodePatterns/Observer/Observer.hpp"
 | 
|---|
| 19 | 
 | 
|---|
| 20 | #include "World.hpp"
 | 
|---|
| 21 | 
 | 
|---|
| 22 | class molecule;
 | 
|---|
| 23 | class QKeyEvent;
 | 
|---|
| 24 | class GLWorldScene;
 | 
|---|
| 25 | class QGLPainter;
 | 
|---|
| 26 | class QToolBar;
 | 
|---|
| 27 | class QTimer;
 | 
|---|
| 28 | 
 | 
|---|
| 29 | /** This class is the view on the 3D representation of the World, i.e. the whole
 | 
|---|
| 30 |  * of all molecules (consisting of atoms).
 | 
|---|
| 31 |  *
 | 
|---|
| 32 |  */
 | 
|---|
| 33 | class GLWorldView : public QGLView, public Observer
 | 
|---|
| 34 | {
 | 
|---|
| 35 |   Q_OBJECT
 | 
|---|
| 36 | public:
 | 
|---|
| 37 |   GLWorldView(QWidget *parent=0);
 | 
|---|
| 38 |   virtual ~GLWorldView();
 | 
|---|
| 39 | 
 | 
|---|
| 40 |   void addToolBarActions(QToolBar *toolbar);
 | 
|---|
| 41 |   void createDomainBox();
 | 
|---|
| 42 |   void createDreiBein();
 | 
|---|
| 43 | 
 | 
|---|
| 44 |   // Observer functions
 | 
|---|
| 45 |   void update(Observable *publisher);
 | 
|---|
| 46 |   void subjectKilled(Observable *publisher);
 | 
|---|
| 47 |   void recieveNotification(Observable *publisher, Notification_ptr notification);
 | 
|---|
| 48 | 
 | 
|---|
| 49 | public slots:
 | 
|---|
| 50 |   void changeSignalled();
 | 
|---|
| 51 |   void checkChanges();
 | 
|---|
| 52 |   void sceneChangeSignalled();
 | 
|---|
| 53 |   void sceneHoverSignalled(const atomId_t _id);
 | 
|---|
| 54 |   void sceneHoverSignalled(const moleculeId_t _id, int);
 | 
|---|
| 55 |   void changeDreiBein();
 | 
|---|
| 56 |   void changeDomain();
 | 
|---|
| 57 | 
 | 
|---|
| 58 | signals:
 | 
|---|
| 59 |   void changed();
 | 
|---|
| 60 |   void TimeChanged();
 | 
|---|
| 61 |   void atomInserted(const moleculeId_t _molid, const atomId_t _atomid);
 | 
|---|
| 62 |   void atomRemoved(const moleculeId_t _molid, const atomId_t _atomid);
 | 
|---|
| 63 |   void moleculeInserted(const moleculeId_t _id);
 | 
|---|
| 64 |   void moleculeRemoved(const moleculeId_t _id);
 | 
|---|
| 65 |   void worldSelectionChanged();
 | 
|---|
| 66 |   void hoverChanged(const atomId_t _id);
 | 
|---|
| 67 |   void hoverChanged(const moleculeId_t _id, int);
 | 
|---|
| 68 |   void ShapeAdded();
 | 
|---|
| 69 |   void ShapeRemoved();
 | 
|---|
| 70 |   void moleculesVisibilityChanged(const moleculeId_t,bool);
 | 
|---|
| 71 | 
 | 
|---|
| 72 | protected:
 | 
|---|
| 73 |   void initializeGL(QGLPainter *painter);
 | 
|---|
| 74 |   void paintGL(QGLPainter *painter);
 | 
|---|
| 75 |   void drawDomainBox(QGLPainter *painter) const;
 | 
|---|
| 76 |   void drawDreiBein(QGLPainter *painter);
 | 
|---|
| 77 | 
 | 
|---|
| 78 |   // input functions
 | 
|---|
| 79 |   void mousePressEvent(QMouseEvent *event);
 | 
|---|
| 80 |   void mouseMoveEvent(QMouseEvent *event);
 | 
|---|
| 81 |   void keyPressEvent(QKeyEvent *event);
 | 
|---|
| 82 |   void wheelEvent(QWheelEvent *event);
 | 
|---|
| 83 | 
 | 
|---|
| 84 |   // camera functions
 | 
|---|
| 85 |   enum CameraControlModeType{
 | 
|---|
| 86 |     Rotate,
 | 
|---|
| 87 |     Translate
 | 
|---|
| 88 |   };
 | 
|---|
| 89 | 
 | 
|---|
| 90 |   void setCameraControlMode(CameraControlModeType mode);
 | 
|---|
| 91 |   CameraControlModeType getCameraControlMode(bool inverted = false);
 | 
|---|
| 92 | public slots:
 | 
|---|
| 93 |   void fitCameraToDomain();
 | 
|---|
| 94 |   void setCameraControlModeRotation();
 | 
|---|
| 95 |   void setCameraControlModeTranslation();
 | 
|---|
| 96 |   void setCameraStereoModeDisable();
 | 
|---|
| 97 |   void setCameraStereoModeHardware();
 | 
|---|
| 98 |   void setCameraStereoModeLeftRight();
 | 
|---|
| 99 |   void setCameraStereoModeRightLeft();
 | 
|---|
| 100 |   void setCameraStereoModeTopBottom();
 | 
|---|
| 101 |   void setCameraStereoModeBottomTop();
 | 
|---|
| 102 |   void setCameraStereoModeAnaglyph();
 | 
|---|
| 103 | 
 | 
|---|
| 104 | protected:
 | 
|---|
| 105 |   CameraControlModeType cameraControlMode;
 | 
|---|
| 106 | 
 | 
|---|
| 107 | private:
 | 
|---|
| 108 |   void setdreiBeinStatus(const bool status);
 | 
|---|
| 109 |   void setDomainStatus(const bool status);
 | 
|---|
| 110 | 
 | 
|---|
| 111 |   void signOnToMolecule(const molecule *_mol);
 | 
|---|
| 112 |   void signOffFromMolecule(const molecule *_mol);
 | 
|---|
| 113 | 
 | 
|---|
| 114 | private:
 | 
|---|
| 115 | 
 | 
|---|
| 116 |   GLWorldScene *worldscene;
 | 
|---|
| 117 | 
 | 
|---|
| 118 |   bool changesPresent;
 | 
|---|
| 119 |   bool processingSelectionChanged; // workaround to prevent a loop in (atom_iterator <-> observer)
 | 
|---|
| 120 | 
 | 
|---|
| 121 |   QPointF lastMousePos;
 | 
|---|
| 122 | 
 | 
|---|
| 123 |   QGLSceneNode *meshDomainBox;
 | 
|---|
| 124 |   QGLSceneNode *meshDreiBein;
 | 
|---|
| 125 | 
 | 
|---|
| 126 |   QGLMaterial *domainBoxMaterial;
 | 
|---|
| 127 |   QGLMaterial *dreiBeinMaterial[3];
 | 
|---|
| 128 | 
 | 
|---|
| 129 |   QTimer *redrawTimer;
 | 
|---|
| 130 |   bool needsRedraw;
 | 
|---|
| 131 | 
 | 
|---|
| 132 |   double defaultEyeSeparation;
 | 
|---|
| 133 | 
 | 
|---|
| 134 |   typedef std::multiset<molecule *> ObservedMolecules_t;
 | 
|---|
| 135 |   //!> sorted list of molecules we are sign on to
 | 
|---|
| 136 |   ObservedMolecules_t ObservedMolecules;
 | 
|---|
| 137 | };
 | 
|---|
| 138 | 
 | 
|---|
| 139 | #endif /* GLWORLDVIEW_HPP_ */
 | 
|---|