| 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 atom *_atom); | 
|---|
| 54 | void changeDreiBein(); | 
|---|
| 55 | void changeDomain(); | 
|---|
| 56 |  | 
|---|
| 57 | signals: | 
|---|
| 58 | void changed(); | 
|---|
| 59 | void atomInserted(const atomicNumber_t _id); | 
|---|
| 60 | void atomRemoved(const atomicNumber_t _id); | 
|---|
| 61 | void moleculeInserted(const molecule *_molecule); | 
|---|
| 62 | void moleculeRemoved(const molecule *_molecule); | 
|---|
| 63 | void worldSelectionChanged(); | 
|---|
| 64 | void hoverChanged(const atom *_atom); | 
|---|
| 65 | void ShapeAdded(); | 
|---|
| 66 | void ShapeRemoved(); | 
|---|
| 67 |  | 
|---|
| 68 | protected: | 
|---|
| 69 | void initializeGL(QGLPainter *painter); | 
|---|
| 70 | void paintGL(QGLPainter *painter); | 
|---|
| 71 | void drawDomainBox(QGLPainter *painter) const; | 
|---|
| 72 | void drawDreiBein(QGLPainter *painter); | 
|---|
| 73 |  | 
|---|
| 74 | // input functions | 
|---|
| 75 | void mousePressEvent(QMouseEvent *event); | 
|---|
| 76 | void mouseMoveEvent(QMouseEvent *event); | 
|---|
| 77 | void keyPressEvent(QKeyEvent *event); | 
|---|
| 78 | void wheelEvent(QWheelEvent *event); | 
|---|
| 79 |  | 
|---|
| 80 | // camera functions | 
|---|
| 81 | enum CameraControlModeType{ | 
|---|
| 82 | Rotate, | 
|---|
| 83 | Translate | 
|---|
| 84 | }; | 
|---|
| 85 |  | 
|---|
| 86 | void setCameraControlMode(CameraControlModeType mode); | 
|---|
| 87 | CameraControlModeType getCameraControlMode(bool inverted = false); | 
|---|
| 88 | public slots: | 
|---|
| 89 | void fitCameraToDomain(); | 
|---|
| 90 | void setCameraControlModeRotation(); | 
|---|
| 91 | void setCameraControlModeTranslation(); | 
|---|
| 92 | void setCameraStereoModeDisable(); | 
|---|
| 93 | void setCameraStereoModeHardware(); | 
|---|
| 94 | void setCameraStereoModeLeftRight(); | 
|---|
| 95 | void setCameraStereoModeRightLeft(); | 
|---|
| 96 | void setCameraStereoModeTopBottom(); | 
|---|
| 97 | void setCameraStereoModeBottomTop(); | 
|---|
| 98 | void setCameraStereoModeAnaglyph(); | 
|---|
| 99 |  | 
|---|
| 100 | protected: | 
|---|
| 101 | CameraControlModeType cameraControlMode; | 
|---|
| 102 |  | 
|---|
| 103 | private: | 
|---|
| 104 | void setdreiBeinStatus(const bool status); | 
|---|
| 105 | void setDomainStatus(const bool status); | 
|---|
| 106 |  | 
|---|
| 107 | private: | 
|---|
| 108 |  | 
|---|
| 109 | GLWorldScene *worldscene; | 
|---|
| 110 |  | 
|---|
| 111 | bool changesPresent; | 
|---|
| 112 | bool processingSelectionChanged; // workaround to prevent a loop in (atom_iterator <-> observer) | 
|---|
| 113 |  | 
|---|
| 114 | QPointF lastMousePos; | 
|---|
| 115 |  | 
|---|
| 116 | QGLSceneNode *meshDomainBox; | 
|---|
| 117 | QGLSceneNode *meshDreiBein; | 
|---|
| 118 |  | 
|---|
| 119 | QGLMaterial *domainBoxMaterial; | 
|---|
| 120 | QGLMaterial *dreiBeinMaterial[3]; | 
|---|
| 121 |  | 
|---|
| 122 | QTimer *redrawTimer; | 
|---|
| 123 | bool needsRedraw; | 
|---|
| 124 |  | 
|---|
| 125 | double defaultEyeSeparation; | 
|---|
| 126 | }; | 
|---|
| 127 |  | 
|---|
| 128 |  | 
|---|
| 129 |  | 
|---|
| 130 | //#include "CodePatterns/Observer/Observer.hpp" | 
|---|
| 131 | //#include "LinearAlgebra/Vector.hpp" | 
|---|
| 132 | //#include "changetypes.hpp" | 
|---|
| 133 | // | 
|---|
| 134 | //class atom; | 
|---|
| 135 | //class element; | 
|---|
| 136 | //class molecule; | 
|---|
| 137 | // | 
|---|
| 138 | //class GLMoleculeView : public QGLWidget, public Observer | 
|---|
| 139 | //{ | 
|---|
| 140 | //    Q_OBJECT | 
|---|
| 141 | // | 
|---|
| 142 | //public: | 
|---|
| 143 | // | 
|---|
| 144 | //    GLMoleculeView( QWidget* parent); | 
|---|
| 145 | //    ~GLMoleculeView(); | 
|---|
| 146 | // | 
|---|
| 147 | //public slots: | 
|---|
| 148 | // | 
|---|
| 149 | //    void    setXRotation( int degrees ); | 
|---|
| 150 | //    void    setYRotation( int degrees ); | 
|---|
| 151 | //    void    setZRotation( int degrees ); | 
|---|
| 152 | //    void    setScale( int distance ); | 
|---|
| 153 | //    void    setLightPosition( int *light ); | 
|---|
| 154 | //    void    setLightDiffuse( int *light ); | 
|---|
| 155 | //    void    setLightAmbient( int *light ); | 
|---|
| 156 | //    void    createDialogLight(); | 
|---|
| 157 | //    void    toggleMultiViewEnabled(); | 
|---|
| 158 | // | 
|---|
| 159 | //    void    init( QLabel *ptr ); | 
|---|
| 160 | //    void    initCoordinates(QLabel *ptr); | 
|---|
| 161 | //    void    createView(); | 
|---|
| 162 | //    void    hearMoleculeSelected(molecule *mol); | 
|---|
| 163 | //    void    hearAtomSelected(molecule *mol, atom *Walker); | 
|---|
| 164 | //    void    hearMoleculeChanged(molecule *mol, enum ChangesinMolecule type); | 
|---|
| 165 | //    void    hearAtomChanged(molecule *mol, atom *Walker, enum ChangesinAtom type); | 
|---|
| 166 | //    void    hearElementChanged(element *Runner, enum ChangesinElement type); | 
|---|
| 167 | //    void    hearMoleculeAdded(molecule *mol); | 
|---|
| 168 | //    void    hearAtomAdded(molecule *mol, atom *Walker); | 
|---|
| 169 | //    void    hearMoleculeRemoved(molecule *mol); | 
|---|
| 170 | //    void    hearAtomRemoved(molecule *mol, atom *Walker); | 
|---|
| 171 | // | 
|---|
| 172 | //signals: | 
|---|
| 173 | //    void    notifyMoleculeSelected( molecule *mol ); | 
|---|
| 174 | //    void    notifyAtomSelected( molecule *mol, atom *Walker ); | 
|---|
| 175 | //    void    notifyMoleculeChanged( molecule *mol, enum ChangesinMolecule type ); | 
|---|
| 176 | //    void    notifyAtomChanged( molecule *mol, atom *Walker, enum ChangesinAtom type ); | 
|---|
| 177 | //    void    notifyElementChanged( element *Runner, enum ChangesinElement type ); | 
|---|
| 178 | //    void    notifyMoleculeAdded( molecule *mol); | 
|---|
| 179 | //    void    notifyElementAdded( element *Runner); | 
|---|
| 180 | //    void    notifyAtomAdded( molecule *mol, atom *Walker ); | 
|---|
| 181 | //    void    notifyMoleculeRemoved( molecule *mol ); | 
|---|
| 182 | //    void    notifyAtomRemoved( molecule *mol, atom *Walker ); | 
|---|
| 183 | // | 
|---|
| 184 | //protected: | 
|---|
| 185 | // | 
|---|
| 186 | //    void    initializeGL(); | 
|---|
| 187 | //    void    paintGL(); | 
|---|
| 188 | //    void    resizeGL( int w, int h ); | 
|---|
| 189 | //    void    makeSphere(const Vector &x, double radius, const unsigned char color[3]); | 
|---|
| 190 | //    void    makeCylinder(const Vector &x, const Vector &y, double radius, double height, const unsigned char color[3]); | 
|---|
| 191 | //    void mousePressEvent(QMouseEvent* event); | 
|---|
| 192 | //    void mouseReleaseEvent(QMouseEvent* event); | 
|---|
| 193 | // | 
|---|
| 194 | //public: | 
|---|
| 195 | // | 
|---|
| 196 | //    /** Update function as we are an Observer. | 
|---|
| 197 | //     * | 
|---|
| 198 | //     * @param publisher ref to Observable | 
|---|
| 199 | //     */ | 
|---|
| 200 | //    void update(Observable *publisher); | 
|---|
| 201 | // | 
|---|
| 202 | //    /** | 
|---|
| 203 | //     * This method is called when a special named change | 
|---|
| 204 | //     * of the Observable occured | 
|---|
| 205 | //     */ | 
|---|
| 206 | //    void recieveNotification(Observable *publisher, Notification_ptr notification); | 
|---|
| 207 | // | 
|---|
| 208 | //    /** | 
|---|
| 209 | //     * This method is called when the observed object is destroyed. | 
|---|
| 210 | //     */ | 
|---|
| 211 | //    void subjectKilled(Observable *publisher); | 
|---|
| 212 | // | 
|---|
| 213 | // | 
|---|
| 214 | //private: | 
|---|
| 215 | // | 
|---|
| 216 | //    typedef std::map< size_t, node > AtomNodeMap; | 
|---|
| 217 | //    typedef std::map< std::pair< size_t, size_t> , node > BondNodeMap; | 
|---|
| 218 | //    typedef std::map< size_t, QGLMaterial *> ElementMaterialMap; | 
|---|
| 219 | // | 
|---|
| 220 | //    ElementMaterialMap ElementNoMaterialMap; | 
|---|
| 221 | //    AtomNodeMap AtomsinSceneMap; | 
|---|
| 222 | //    BondNodeMap BondsinSceneMap; | 
|---|
| 223 | // | 
|---|
| 224 | //    QGLMaterial* getMaterial(size_t); | 
|---|
| 225 | //    QGLSceneNode* getAtom(size_t); | 
|---|
| 226 | //    QGLSceneNode* getBond(size_t, size_t); | 
|---|
| 227 | // | 
|---|
| 228 | //    // old stuff | 
|---|
| 229 | // | 
|---|
| 230 | //    GLuint object;  // call list for the scene to be rendered | 
|---|
| 231 | //    GLfloat xRot, yRot, zRot, scale;  // rotation angles and scaling (zoom) | 
|---|
| 232 | //    Vector position;  //!< position of observer | 
|---|
| 233 | //    Vector view;      //!< point along line of view | 
|---|
| 234 | //    Vector top;       //!< giving upwards direction | 
|---|
| 235 | //    Vector X,Y,Z;     //!< vectors defining the coordinate system | 
|---|
| 236 | //    int width;        //!< width of window | 
|---|
| 237 | //    int height;       //!< height of window | 
|---|
| 238 | // | 
|---|
| 239 | //  QLabel *StatusBar;  //!< pointer to status bar for messages | 
|---|
| 240 | //  QLabel *CoordinatesBar; //!< pointer to coordinates bar for view port | 
|---|
| 241 | // | 
|---|
| 242 | //  GLfloat LightPosition[4];        //!< Light Position | 
|---|
| 243 | //  GLfloat LightDiffuse[4];         //!< Diffuse Light Values | 
|---|
| 244 | //  GLfloat LightAmbient[4];        //!< Ambient Light Values | 
|---|
| 245 | // | 
|---|
| 246 | //  QPoint LeftButtonPos;     //!< mouse position on mousePressEvent for LeftButton | 
|---|
| 247 | //  QPoint MiddleButtonPos;   //!< mouse position on mousePressEvent for MidButton | 
|---|
| 248 | //  QPoint RightButtonPos;    //!< mouse position on mousePressEvent for RightButton | 
|---|
| 249 | // | 
|---|
| 250 | //  unsigned char SelectionColor[3] ; //!< highlight color | 
|---|
| 251 | // | 
|---|
| 252 | //  bool isSignaller; | 
|---|
| 253 | // | 
|---|
| 254 | //  bool MultiViewEnabled;    //!< if true, split screen into four parts with additional xy,xz,yz views | 
|---|
| 255 | //}; | 
|---|
| 256 |  | 
|---|
| 257 | #endif /* GLWORLDVIEW_HPP_ */ | 
|---|