| 1 | /* | 
|---|
| 2 | * GLMoleculeObject.hpp | 
|---|
| 3 | * | 
|---|
| 4 | *  This is based on the Qt3D example "teaservice", specifically meshobject.h. | 
|---|
| 5 | * | 
|---|
| 6 | *  Created on: Aug 17, 2011 | 
|---|
| 7 | *      Author: heber | 
|---|
| 8 | */ | 
|---|
| 9 |  | 
|---|
| 10 | #ifndef GLMOLECULEOBJECT_HPP_ | 
|---|
| 11 | #define GLMOLECULEOBJECT_HPP_ | 
|---|
| 12 |  | 
|---|
| 13 | // include config.h | 
|---|
| 14 | #ifdef HAVE_CONFIG_H | 
|---|
| 15 | #include <config.h> | 
|---|
| 16 | #endif | 
|---|
| 17 |  | 
|---|
| 18 |  | 
|---|
| 19 | #include <QtCore/qobject.h> | 
|---|
| 20 | #include <QtGui/qevent.h> | 
|---|
| 21 |  | 
|---|
| 22 | #include <Qt3D/qglpainter.h> | 
|---|
| 23 | #include <Qt3D/qglabstractscene.h> | 
|---|
| 24 |  | 
|---|
| 25 | class QGLView; | 
|---|
| 26 | class QGLSceneNode; | 
|---|
| 27 | class GLMoleculeScene; | 
|---|
| 28 |  | 
|---|
| 29 | /** This class represents a single object within a molecule, e.g. atom or bond. | 
|---|
| 30 | * | 
|---|
| 31 | */ | 
|---|
| 32 | class GLMoleculeObject : public QObject | 
|---|
| 33 | { | 
|---|
| 34 | Q_OBJECT | 
|---|
| 35 |  | 
|---|
| 36 | //!> Allow it to call cleanMaterialMap() | 
|---|
| 37 | friend class GLWorldScene; | 
|---|
| 38 | public: | 
|---|
| 39 | explicit GLMoleculeObject(QGLSceneNode *mesh[], QObject *parent=0); | 
|---|
| 40 | explicit GLMoleculeObject(QGLSceneNode *mesh, QObject *parent=0); | 
|---|
| 41 | explicit GLMoleculeObject(QGLAbstractScene *scene, QObject *parent=0); | 
|---|
| 42 | virtual ~GLMoleculeObject(); | 
|---|
| 43 |  | 
|---|
| 44 | QVector3D position() const { return m_position; } | 
|---|
| 45 | void setPosition(const QVector3D& value) { m_position = value; } | 
|---|
| 46 |  | 
|---|
| 47 | qreal scale() const { return m_scale; } | 
|---|
| 48 | void setScale(qreal value) { m_scale = value; } | 
|---|
| 49 |  | 
|---|
| 50 | qreal scaleZ() const { return m_scaleZ; } | 
|---|
| 51 | void setScaleZ(qreal value) { m_scaleZ = value; } | 
|---|
| 52 |  | 
|---|
| 53 | qreal rotationAngle() const { return m_rotationAngle; } | 
|---|
| 54 | void setRotationAngle(qreal value) { m_rotationAngle = value; } | 
|---|
| 55 |  | 
|---|
| 56 | QVector3D rotationVector() const { return m_rotationVector; } | 
|---|
| 57 | void setRotationVector(const QVector3D& value) { m_rotationVector = value; } | 
|---|
| 58 |  | 
|---|
| 59 | QGLMaterial *material() const { return m_material; } | 
|---|
| 60 | void setMaterial(QGLMaterial *value) { m_material = value; } | 
|---|
| 61 |  | 
|---|
| 62 | QGLAbstractEffect *effect() const { return m_effect; } | 
|---|
| 63 | void setEffect(QGLAbstractEffect *value) { m_effect = value; } | 
|---|
| 64 |  | 
|---|
| 65 | int objectId() const { return m_objectId; } | 
|---|
| 66 | void setObjectId(int id) { m_objectId = id; } | 
|---|
| 67 |  | 
|---|
| 68 | bool selected() const { return m_selected; } | 
|---|
| 69 | void setSelected(bool value); | 
|---|
| 70 |  | 
|---|
| 71 | void initStaticMaterials(); | 
|---|
| 72 | void initialize(QGLView *view, QGLPainter *painter); | 
|---|
| 73 | virtual void draw(QGLPainter *painter, const QVector4D &cameraPlane); | 
|---|
| 74 | void drawSelectionBox(QGLPainter *painter); | 
|---|
| 75 |  | 
|---|
| 76 | signals: | 
|---|
| 77 | void pressed(); | 
|---|
| 78 | void released(); | 
|---|
| 79 | void clicked(); | 
|---|
| 80 | void doubleClicked(); | 
|---|
| 81 | void hoverChanged(GLMoleculeObject *ob); | 
|---|
| 82 | void selectionChanged(); | 
|---|
| 83 | void changed(); | 
|---|
| 84 |  | 
|---|
| 85 | protected: | 
|---|
| 86 | bool event(QEvent *e); | 
|---|
| 87 |  | 
|---|
| 88 | static QGLMaterial* getMaterial(size_t); | 
|---|
| 89 | static void cleanMaterialMap(); | 
|---|
| 90 |  | 
|---|
| 91 | typedef std::map< size_t, QGLMaterial *> ElementMaterialMap; | 
|---|
| 92 | static ElementMaterialMap ElementNoMaterialMap; | 
|---|
| 93 |  | 
|---|
| 94 | public: | 
|---|
| 95 | enum{DETAIL_HIGHEST, DETAIL_HIGH, DETAIL_MEDIUM, DETAIL_LOW, DETAILTYPES_MAX} DetailType; | 
|---|
| 96 |  | 
|---|
| 97 | protected: | 
|---|
| 98 |  | 
|---|
| 99 | static double detailMinDistance[DETAILTYPES_MAX]; | 
|---|
| 100 |  | 
|---|
| 101 | QGLSceneNode *m_mesh[DETAILTYPES_MAX]; | 
|---|
| 102 | QGLAbstractScene *m_scene; | 
|---|
| 103 | QVector3D m_position; | 
|---|
| 104 | qreal m_scale; | 
|---|
| 105 | qreal m_scaleZ; | 
|---|
| 106 | qreal m_rotationAngle; | 
|---|
| 107 | QVector3D m_rotationVector; | 
|---|
| 108 | QGLMaterial *m_material; | 
|---|
| 109 | static QGLMaterial *m_hoverMaterial; | 
|---|
| 110 | static QGLMaterial *m_selectionMaterial; | 
|---|
| 111 | static QGLMaterial *m_selectionBoxMaterial; | 
|---|
| 112 | QGLAbstractEffect *m_effect; | 
|---|
| 113 | int m_objectId; | 
|---|
| 114 | bool m_hovering; | 
|---|
| 115 | bool m_selected; | 
|---|
| 116 | }; | 
|---|
| 117 |  | 
|---|
| 118 |  | 
|---|
| 119 | #endif /* GLMOLECULEOBJECT_HPP_ */ | 
|---|