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