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