[907636] | 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 |
|
---|
[4269ca] | 22 | #include <Qt3D/qglpainter.h>
|
---|
| 23 | #include <Qt3D/qglabstractscene.h>
|
---|
[907636] | 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()
|
---|
[7188b1] | 37 | friend class GLWorldScene;
|
---|
[907636] | 38 | public:
|
---|
[72a4c1] | 39 | explicit GLMoleculeObject(QGLSceneNode *mesh[], QObject *parent=0);
|
---|
[615eee] | 40 | explicit GLMoleculeObject(QGLSceneNode *mesh, QObject *parent=0);
|
---|
[907636] | 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 |
|
---|
[2d5137] | 47 | void setScale(qreal value) { m_scaleX = m_scaleY = m_scaleZ = value; }
|
---|
| 48 |
|
---|
| 49 | qreal scaleX() const { return m_scaleX; }
|
---|
| 50 | void setScaleX(qreal value) { m_scaleX = value; }
|
---|
| 51 |
|
---|
| 52 | qreal scaleY() const { return m_scaleY; }
|
---|
| 53 | void setScaleY(qreal value) { m_scaleY = value; }
|
---|
[907636] | 54 |
|
---|
[fbb1f1] | 55 | qreal scaleZ() const { return m_scaleZ; }
|
---|
| 56 | void setScaleZ(qreal value) { m_scaleZ = value; }
|
---|
| 57 |
|
---|
[907636] | 58 | qreal rotationAngle() const { return m_rotationAngle; }
|
---|
| 59 | void setRotationAngle(qreal value) { m_rotationAngle = value; }
|
---|
| 60 |
|
---|
| 61 | QVector3D rotationVector() const { return m_rotationVector; }
|
---|
| 62 | void setRotationVector(const QVector3D& value) { m_rotationVector = value; }
|
---|
| 63 |
|
---|
| 64 | QGLMaterial *material() const { return m_material; }
|
---|
[3b229e] | 65 | void setMaterial(QGLMaterial *value) { m_material = value; }
|
---|
[8a77ac] | 66 |
|
---|
[907636] | 67 | QGLAbstractEffect *effect() const { return m_effect; }
|
---|
| 68 | void setEffect(QGLAbstractEffect *value) { m_effect = value; }
|
---|
| 69 |
|
---|
| 70 | int objectId() const { return m_objectId; }
|
---|
| 71 | void setObjectId(int id) { m_objectId = id; }
|
---|
| 72 |
|
---|
[d53902] | 73 | bool selected() const { return m_selected; }
|
---|
[c67518] | 74 | void setSelected(bool value);
|
---|
[d53902] | 75 |
|
---|
[3b229e] | 76 | void initStaticMaterials();
|
---|
[907636] | 77 | void initialize(QGLView *view, QGLPainter *painter);
|
---|
[615eee] | 78 | virtual void draw(QGLPainter *painter, const QVector4D &cameraPlane);
|
---|
[225cf5] | 79 | void drawSelectionBox(QGLPainter *painter);
|
---|
[907636] | 80 |
|
---|
| 81 | signals:
|
---|
| 82 | void pressed();
|
---|
| 83 | void released();
|
---|
| 84 | void clicked();
|
---|
| 85 | void doubleClicked();
|
---|
[407638e] | 86 | void hoverChanged(GLMoleculeObject *ob);
|
---|
[5a2a06] | 87 | void selectionChanged();
|
---|
| 88 | void changed();
|
---|
[907636] | 89 |
|
---|
| 90 | protected:
|
---|
| 91 | bool event(QEvent *e);
|
---|
| 92 |
|
---|
| 93 | static QGLMaterial* getMaterial(size_t);
|
---|
| 94 | static void cleanMaterialMap();
|
---|
| 95 |
|
---|
| 96 | typedef std::map< size_t, QGLMaterial *> ElementMaterialMap;
|
---|
| 97 | static ElementMaterialMap ElementNoMaterialMap;
|
---|
| 98 |
|
---|
[72a4c1] | 99 | public:
|
---|
| 100 | enum{DETAIL_HIGHEST, DETAIL_HIGH, DETAIL_MEDIUM, DETAIL_LOW, DETAILTYPES_MAX} DetailType;
|
---|
| 101 |
|
---|
[615eee] | 102 | protected:
|
---|
[907636] | 103 |
|
---|
[72a4c1] | 104 | static double detailMinDistance[DETAILTYPES_MAX];
|
---|
| 105 |
|
---|
| 106 | QGLSceneNode *m_mesh[DETAILTYPES_MAX];
|
---|
[907636] | 107 | QGLAbstractScene *m_scene;
|
---|
| 108 | QVector3D m_position;
|
---|
[2d5137] | 109 | qreal m_scaleX;
|
---|
| 110 | qreal m_scaleY;
|
---|
[fbb1f1] | 111 | qreal m_scaleZ;
|
---|
[907636] | 112 | qreal m_rotationAngle;
|
---|
| 113 | QVector3D m_rotationVector;
|
---|
| 114 | QGLMaterial *m_material;
|
---|
[3b229e] | 115 | static QGLMaterial *m_hoverMaterial;
|
---|
| 116 | static QGLMaterial *m_selectionMaterial;
|
---|
| 117 | static QGLMaterial *m_selectionBoxMaterial;
|
---|
[907636] | 118 | QGLAbstractEffect *m_effect;
|
---|
| 119 | int m_objectId;
|
---|
| 120 | bool m_hovering;
|
---|
[8a77ac] | 121 | bool m_selected;
|
---|
[907636] | 122 | };
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 | #endif /* GLMOLECULEOBJECT_HPP_ */
|
---|