| 1 | /*
|
|---|
| 2 | * GLMoleculeView.hpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Auf 11, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #ifndef GLMOLECULEVIEW_HPP_
|
|---|
| 9 | #define GLMOLECULEVIEW_HPP_
|
|---|
| 10 |
|
|---|
| 11 | // include config.h
|
|---|
| 12 | #ifdef HAVE_CONFIG_H
|
|---|
| 13 | #include <config.h>
|
|---|
| 14 | #endif
|
|---|
| 15 |
|
|---|
| 16 | #include <qgl.h>
|
|---|
| 17 | #include <qdialog.h>
|
|---|
| 18 | #include <qlabel.h>
|
|---|
| 19 | #include <qlineedit.h>
|
|---|
| 20 | //#include <qwidgetfactory.h>
|
|---|
| 21 |
|
|---|
| 22 | #include "CodePatterns/Observer.hpp"
|
|---|
| 23 | #include "LinearAlgebra/Vector.hpp"
|
|---|
| 24 | #include "changetypes.hpp"
|
|---|
| 25 |
|
|---|
| 26 | class atom;
|
|---|
| 27 | class element;
|
|---|
| 28 | class molecule;
|
|---|
| 29 |
|
|---|
| 30 | class GLMoleculeView : public QGLWidget, public Observer
|
|---|
| 31 | {
|
|---|
| 32 | Q_OBJECT
|
|---|
| 33 |
|
|---|
| 34 | public:
|
|---|
| 35 |
|
|---|
| 36 | GLMoleculeView( QWidget* parent);
|
|---|
| 37 | ~GLMoleculeView();
|
|---|
| 38 |
|
|---|
| 39 | public slots:
|
|---|
| 40 |
|
|---|
| 41 | void setXRotation( int degrees );
|
|---|
| 42 | void setYRotation( int degrees );
|
|---|
| 43 | void setZRotation( int degrees );
|
|---|
| 44 | void setScale( int distance );
|
|---|
| 45 | void setLightPosition( int *light );
|
|---|
| 46 | void setLightDiffuse( int *light );
|
|---|
| 47 | void setLightAmbient( int *light );
|
|---|
| 48 | void createDialogLight();
|
|---|
| 49 | void toggleMultiViewEnabled();
|
|---|
| 50 |
|
|---|
| 51 | void init( QLabel *ptr );
|
|---|
| 52 | void initCoordinates(QLabel *ptr);
|
|---|
| 53 | void createView();
|
|---|
| 54 | void hearMoleculeSelected(molecule *mol);
|
|---|
| 55 | void hearAtomSelected(molecule *mol, atom *Walker);
|
|---|
| 56 | void hearMoleculeChanged(molecule *mol, enum ChangesinMolecule type);
|
|---|
| 57 | void hearAtomChanged(molecule *mol, atom *Walker, enum ChangesinAtom type);
|
|---|
| 58 | void hearElementChanged(element *Runner, enum ChangesinElement type);
|
|---|
| 59 | void hearMoleculeAdded(molecule *mol);
|
|---|
| 60 | void hearAtomAdded(molecule *mol, atom *Walker);
|
|---|
| 61 | void hearMoleculeRemoved(molecule *mol);
|
|---|
| 62 | void hearAtomRemoved(molecule *mol, atom *Walker);
|
|---|
| 63 |
|
|---|
| 64 | signals:
|
|---|
| 65 | void notifyMoleculeSelected( molecule *mol );
|
|---|
| 66 | void notifyAtomSelected( molecule *mol, atom *Walker );
|
|---|
| 67 | void notifyMoleculeChanged( molecule *mol, enum ChangesinMolecule type );
|
|---|
| 68 | void notifyAtomChanged( molecule *mol, atom *Walker, enum ChangesinAtom type );
|
|---|
| 69 | void notifyElementChanged( element *Runner, enum ChangesinElement type );
|
|---|
| 70 | void notifyMoleculeAdded( molecule *mol);
|
|---|
| 71 | void notifyElementAdded( element *Runner);
|
|---|
| 72 | void notifyAtomAdded( molecule *mol, atom *Walker );
|
|---|
| 73 | void notifyMoleculeRemoved( molecule *mol );
|
|---|
| 74 | void notifyAtomRemoved( molecule *mol, atom *Walker );
|
|---|
| 75 |
|
|---|
| 76 | protected:
|
|---|
| 77 |
|
|---|
| 78 | void initializeGL();
|
|---|
| 79 | void paintGL();
|
|---|
| 80 | void resizeGL( int w, int h );
|
|---|
| 81 | void makeSphere(const Vector &x, double radius, const unsigned char color[3]);
|
|---|
| 82 | void makeCylinder(const Vector &x, const Vector &y, double radius, double height, const unsigned char color[3]);
|
|---|
| 83 | void mousePressEvent(QMouseEvent* event);
|
|---|
| 84 | void mouseReleaseEvent(QMouseEvent* event);
|
|---|
| 85 |
|
|---|
| 86 | public:
|
|---|
| 87 |
|
|---|
| 88 | /** Update function as we are an Observer.
|
|---|
| 89 | *
|
|---|
| 90 | * @param publisher ref to Observable
|
|---|
| 91 | */
|
|---|
| 92 | void update(Observable *publisher);
|
|---|
| 93 |
|
|---|
| 94 | /**
|
|---|
| 95 | * This method is called when a special named change
|
|---|
| 96 | * of the Observable occured
|
|---|
| 97 | */
|
|---|
| 98 | void recieveNotification(Observable *publisher, Notification_ptr notification);
|
|---|
| 99 |
|
|---|
| 100 | /**
|
|---|
| 101 | * This method is called when the observed object is destroyed.
|
|---|
| 102 | */
|
|---|
| 103 | void subjectKilled(Observable *publisher);
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 | private:
|
|---|
| 107 |
|
|---|
| 108 | GLuint object; // call list for the scene to be rendered
|
|---|
| 109 | GLfloat xRot, yRot, zRot, scale; // rotation angles and scaling (zoom)
|
|---|
| 110 | Vector position; //!< position of observer
|
|---|
| 111 | Vector view; //!< point along line of view
|
|---|
| 112 | Vector top; //!< giving upwards direction
|
|---|
| 113 | Vector X,Y,Z; //!< vectors defining the coordinate system
|
|---|
| 114 | int width; //!< width of window
|
|---|
| 115 | int height; //!< height of window
|
|---|
| 116 |
|
|---|
| 117 | QLabel *StatusBar; //!< pointer to status bar for messages
|
|---|
| 118 | QLabel *CoordinatesBar; //!< pointer to coordinates bar for view port
|
|---|
| 119 |
|
|---|
| 120 | GLfloat LightPosition[4]; //!< Light Position
|
|---|
| 121 | GLfloat LightDiffuse[4]; //!< Diffuse Light Values
|
|---|
| 122 | GLfloat LightAmbient[4]; //!< Ambient Light Values
|
|---|
| 123 |
|
|---|
| 124 | QPoint LeftButtonPos; //!< mouse position on mousePressEvent for LeftButton
|
|---|
| 125 | QPoint MiddleButtonPos; //!< mouse position on mousePressEvent for MidButton
|
|---|
| 126 | QPoint RightButtonPos; //!< mouse position on mousePressEvent for RightButton
|
|---|
| 127 |
|
|---|
| 128 | unsigned char SelectionColor[3] ; //!< highlight color
|
|---|
| 129 |
|
|---|
| 130 | bool isSignaller;
|
|---|
| 131 |
|
|---|
| 132 | bool MultiViewEnabled; //!< if true, split screen into four parts with additional xy,xz,yz views
|
|---|
| 133 | };
|
|---|
| 134 |
|
|---|
| 135 | #endif /* GLMOLECULEVIEW_HPP_ */
|
|---|