| 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 "qglview.h"
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #include "CodePatterns/Observer.hpp"
 | 
|---|
| 19 | 
 | 
|---|
| 20 | #include "World.hpp"
 | 
|---|
| 21 | 
 | 
|---|
| 22 | class QKeyEvent;
 | 
|---|
| 23 | class GLWorldScene;
 | 
|---|
| 24 | class QGLPainter;
 | 
|---|
| 25 | 
 | 
|---|
| 26 | /** This class is the view on the 3D representation of the World, i.e. the whole
 | 
|---|
| 27 |  * of all molecules (consisting of atoms).
 | 
|---|
| 28 |  *
 | 
|---|
| 29 |  */
 | 
|---|
| 30 | class GLWorldView : public QGLView, public Observer
 | 
|---|
| 31 | {
 | 
|---|
| 32 |   Q_OBJECT
 | 
|---|
| 33 | public:
 | 
|---|
| 34 |   GLWorldView(QWidget *parent=0);
 | 
|---|
| 35 |   virtual ~GLWorldView();
 | 
|---|
| 36 | 
 | 
|---|
| 37 |   // Observer functions
 | 
|---|
| 38 |   void update(Observable *publisher);
 | 
|---|
| 39 |   void subjectKilled(Observable *publisher);
 | 
|---|
| 40 |   void recieveNotification(Observable *publisher, Notification_ptr notification);
 | 
|---|
| 41 | 
 | 
|---|
| 42 | public slots:
 | 
|---|
| 43 |   void changeSignalled();
 | 
|---|
| 44 | 
 | 
|---|
| 45 | signals:
 | 
|---|
| 46 |   void changed();
 | 
|---|
| 47 |   void atomInserted(const atom *_atom);
 | 
|---|
| 48 |   void atomRemoved(const atom *_atom);
 | 
|---|
| 49 | 
 | 
|---|
| 50 | protected:
 | 
|---|
| 51 |   void initializeGL(QGLPainter *painter);
 | 
|---|
| 52 |   void paintGL(QGLPainter *painter);
 | 
|---|
| 53 |   void keyPressEvent(QKeyEvent *e);
 | 
|---|
| 54 | 
 | 
|---|
| 55 | private:
 | 
|---|
| 56 |   GLWorldScene *worldscene;
 | 
|---|
| 57 | 
 | 
|---|
| 58 |   bool changesPresent;
 | 
|---|
| 59 | };
 | 
|---|
| 60 | 
 | 
|---|
| 61 | 
 | 
|---|
| 62 | 
 | 
|---|
| 63 | //#include "CodePatterns/Observer.hpp"
 | 
|---|
| 64 | //#include "LinearAlgebra/Vector.hpp"
 | 
|---|
| 65 | //#include "changetypes.hpp"
 | 
|---|
| 66 | //
 | 
|---|
| 67 | //class atom;
 | 
|---|
| 68 | //class element;
 | 
|---|
| 69 | //class molecule;
 | 
|---|
| 70 | //
 | 
|---|
| 71 | //class GLMoleculeView : public QGLWidget, public Observer
 | 
|---|
| 72 | //{
 | 
|---|
| 73 | //    Q_OBJECT
 | 
|---|
| 74 | //
 | 
|---|
| 75 | //public:
 | 
|---|
| 76 | //
 | 
|---|
| 77 | //    GLMoleculeView( QWidget* parent);
 | 
|---|
| 78 | //    ~GLMoleculeView();
 | 
|---|
| 79 | //
 | 
|---|
| 80 | //public slots:
 | 
|---|
| 81 | //
 | 
|---|
| 82 | //    void    setXRotation( int degrees );
 | 
|---|
| 83 | //    void    setYRotation( int degrees );
 | 
|---|
| 84 | //    void    setZRotation( int degrees );
 | 
|---|
| 85 | //    void    setScale( int distance );
 | 
|---|
| 86 | //    void    setLightPosition( int *light );
 | 
|---|
| 87 | //    void    setLightDiffuse( int *light );
 | 
|---|
| 88 | //    void    setLightAmbient( int *light );
 | 
|---|
| 89 | //    void    createDialogLight();
 | 
|---|
| 90 | //    void    toggleMultiViewEnabled();
 | 
|---|
| 91 | //
 | 
|---|
| 92 | //    void    init( QLabel *ptr );
 | 
|---|
| 93 | //    void    initCoordinates(QLabel *ptr);
 | 
|---|
| 94 | //    void    createView();
 | 
|---|
| 95 | //    void    hearMoleculeSelected(molecule *mol);
 | 
|---|
| 96 | //    void    hearAtomSelected(molecule *mol, atom *Walker);
 | 
|---|
| 97 | //    void    hearMoleculeChanged(molecule *mol, enum ChangesinMolecule type);
 | 
|---|
| 98 | //    void    hearAtomChanged(molecule *mol, atom *Walker, enum ChangesinAtom type);
 | 
|---|
| 99 | //    void    hearElementChanged(element *Runner, enum ChangesinElement type);
 | 
|---|
| 100 | //    void    hearMoleculeAdded(molecule *mol);
 | 
|---|
| 101 | //    void    hearAtomAdded(molecule *mol, atom *Walker);
 | 
|---|
| 102 | //    void    hearMoleculeRemoved(molecule *mol);
 | 
|---|
| 103 | //    void    hearAtomRemoved(molecule *mol, atom *Walker);
 | 
|---|
| 104 | //
 | 
|---|
| 105 | //signals:
 | 
|---|
| 106 | //    void    notifyMoleculeSelected( molecule *mol );
 | 
|---|
| 107 | //    void    notifyAtomSelected( molecule *mol, atom *Walker );
 | 
|---|
| 108 | //    void    notifyMoleculeChanged( molecule *mol, enum ChangesinMolecule type );
 | 
|---|
| 109 | //    void    notifyAtomChanged( molecule *mol, atom *Walker, enum ChangesinAtom type );
 | 
|---|
| 110 | //    void    notifyElementChanged( element *Runner, enum ChangesinElement type );
 | 
|---|
| 111 | //    void    notifyMoleculeAdded( molecule *mol);
 | 
|---|
| 112 | //    void    notifyElementAdded( element *Runner);
 | 
|---|
| 113 | //    void    notifyAtomAdded( molecule *mol, atom *Walker );
 | 
|---|
| 114 | //    void    notifyMoleculeRemoved( molecule *mol );
 | 
|---|
| 115 | //    void    notifyAtomRemoved( molecule *mol, atom *Walker );
 | 
|---|
| 116 | //
 | 
|---|
| 117 | //protected:
 | 
|---|
| 118 | //
 | 
|---|
| 119 | //    void    initializeGL();
 | 
|---|
| 120 | //    void    paintGL();
 | 
|---|
| 121 | //    void    resizeGL( int w, int h );
 | 
|---|
| 122 | //    void    makeSphere(const Vector &x, double radius, const unsigned char color[3]);
 | 
|---|
| 123 | //    void    makeCylinder(const Vector &x, const Vector &y, double radius, double height, const unsigned char color[3]);
 | 
|---|
| 124 | //    void mousePressEvent(QMouseEvent* event);
 | 
|---|
| 125 | //    void mouseReleaseEvent(QMouseEvent* event);
 | 
|---|
| 126 | //
 | 
|---|
| 127 | //public:
 | 
|---|
| 128 | //
 | 
|---|
| 129 | //    /** Update function as we are an Observer.
 | 
|---|
| 130 | //     *
 | 
|---|
| 131 | //     * @param publisher ref to Observable
 | 
|---|
| 132 | //     */
 | 
|---|
| 133 | //    void update(Observable *publisher);
 | 
|---|
| 134 | //
 | 
|---|
| 135 | //    /**
 | 
|---|
| 136 | //     * This method is called when a special named change
 | 
|---|
| 137 | //     * of the Observable occured
 | 
|---|
| 138 | //     */
 | 
|---|
| 139 | //    void recieveNotification(Observable *publisher, Notification_ptr notification);
 | 
|---|
| 140 | //
 | 
|---|
| 141 | //    /**
 | 
|---|
| 142 | //     * This method is called when the observed object is destroyed.
 | 
|---|
| 143 | //     */
 | 
|---|
| 144 | //    void subjectKilled(Observable *publisher);
 | 
|---|
| 145 | //
 | 
|---|
| 146 | //
 | 
|---|
| 147 | //private:
 | 
|---|
| 148 | //
 | 
|---|
| 149 | //    typedef std::map< size_t, node > AtomNodeMap;
 | 
|---|
| 150 | //    typedef std::map< std::pair< size_t, size_t> , node > BondNodeMap;
 | 
|---|
| 151 | //    typedef std::map< size_t, QGLMaterial *> ElementMaterialMap;
 | 
|---|
| 152 | //
 | 
|---|
| 153 | //    ElementMaterialMap ElementNoMaterialMap;
 | 
|---|
| 154 | //    AtomNodeMap AtomsinSceneMap;
 | 
|---|
| 155 | //    BondNodeMap BondsinSceneMap;
 | 
|---|
| 156 | //
 | 
|---|
| 157 | //    QGLMaterial* getMaterial(size_t);
 | 
|---|
| 158 | //    QGLSceneNode* getAtom(size_t);
 | 
|---|
| 159 | //    QGLSceneNode* getBond(size_t, size_t);
 | 
|---|
| 160 | //
 | 
|---|
| 161 | //    // old stuff
 | 
|---|
| 162 | //
 | 
|---|
| 163 | //    GLuint object;  // call list for the scene to be rendered
 | 
|---|
| 164 | //    GLfloat xRot, yRot, zRot, scale;  // rotation angles and scaling (zoom)
 | 
|---|
| 165 | //    Vector position;  //!< position of observer
 | 
|---|
| 166 | //    Vector view;      //!< point along line of view
 | 
|---|
| 167 | //    Vector top;       //!< giving upwards direction
 | 
|---|
| 168 | //    Vector X,Y,Z;     //!< vectors defining the coordinate system
 | 
|---|
| 169 | //    int width;        //!< width of window
 | 
|---|
| 170 | //    int height;       //!< height of window
 | 
|---|
| 171 | //
 | 
|---|
| 172 | //  QLabel *StatusBar;  //!< pointer to status bar for messages
 | 
|---|
| 173 | //  QLabel *CoordinatesBar; //!< pointer to coordinates bar for view port
 | 
|---|
| 174 | //
 | 
|---|
| 175 | //  GLfloat LightPosition[4];        //!< Light Position
 | 
|---|
| 176 | //  GLfloat LightDiffuse[4];         //!< Diffuse Light Values
 | 
|---|
| 177 | //  GLfloat LightAmbient[4];        //!< Ambient Light Values
 | 
|---|
| 178 | //
 | 
|---|
| 179 | //  QPoint LeftButtonPos;     //!< mouse position on mousePressEvent for LeftButton
 | 
|---|
| 180 | //  QPoint MiddleButtonPos;   //!< mouse position on mousePressEvent for MidButton
 | 
|---|
| 181 | //  QPoint RightButtonPos;    //!< mouse position on mousePressEvent for RightButton
 | 
|---|
| 182 | //
 | 
|---|
| 183 | //  unsigned char SelectionColor[3] ; //!< highlight color
 | 
|---|
| 184 | //
 | 
|---|
| 185 | //  bool isSignaller;
 | 
|---|
| 186 | //
 | 
|---|
| 187 | //  bool MultiViewEnabled;    //!< if true, split screen into four parts with additional xy,xz,yz views
 | 
|---|
| 188 | //};
 | 
|---|
| 189 | 
 | 
|---|
| 190 | #endif /* GLWORLDVIEW_HPP_ */
 | 
|---|