[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:
|
---|
[bca99d] | 39 | explicit GLMoleculeObject(QGLSceneNode *mesh, QObject *parent=0);
|
---|
[907636] | 40 | explicit GLMoleculeObject(QGLAbstractScene *scene, QObject *parent=0);
|
---|
| 41 | virtual ~GLMoleculeObject();
|
---|
| 42 |
|
---|
| 43 | QVector3D position() const { return m_position; }
|
---|
| 44 | void setPosition(const QVector3D& value) { m_position = value; }
|
---|
| 45 |
|
---|
| 46 | qreal scale() const { return m_scale; }
|
---|
| 47 | void setScale(qreal value) { m_scale = value; }
|
---|
| 48 |
|
---|
[fbb1f1] | 49 | qreal scaleZ() const { return m_scaleZ; }
|
---|
| 50 | void setScaleZ(qreal value) { m_scaleZ = value; }
|
---|
| 51 |
|
---|
[907636] | 52 | qreal rotationAngle() const { return m_rotationAngle; }
|
---|
| 53 | void setRotationAngle(qreal value) { m_rotationAngle = value; }
|
---|
| 54 |
|
---|
| 55 | QVector3D rotationVector() const { return m_rotationVector; }
|
---|
| 56 | void setRotationVector(const QVector3D& value) { m_rotationVector = value; }
|
---|
| 57 |
|
---|
| 58 | QGLMaterial *material() const { return m_material; }
|
---|
[3b229e] | 59 | void setMaterial(QGLMaterial *value) { m_material = value; }
|
---|
[8a77ac] | 60 |
|
---|
[907636] | 61 | QGLAbstractEffect *effect() const { return m_effect; }
|
---|
| 62 | void setEffect(QGLAbstractEffect *value) { m_effect = value; }
|
---|
| 63 |
|
---|
| 64 | int objectId() const { return m_objectId; }
|
---|
| 65 | void setObjectId(int id) { m_objectId = id; }
|
---|
| 66 |
|
---|
[d53902] | 67 | bool selected() const { return m_selected; }
|
---|
[c67518] | 68 | void setSelected(bool value);
|
---|
[d53902] | 69 |
|
---|
[3b229e] | 70 | void initStaticMaterials();
|
---|
[907636] | 71 | void initialize(QGLView *view, QGLPainter *painter);
|
---|
| 72 | void draw(QGLPainter *painter);
|
---|
[225cf5] | 73 | void drawSelectionBox(QGLPainter *painter);
|
---|
[907636] | 74 |
|
---|
| 75 | signals:
|
---|
| 76 | void pressed();
|
---|
| 77 | void released();
|
---|
| 78 | void clicked();
|
---|
| 79 | void doubleClicked();
|
---|
[407638e] | 80 | void hoverChanged(GLMoleculeObject *ob);
|
---|
[5a2a06] | 81 | void selectionChanged();
|
---|
| 82 | void changed();
|
---|
[907636] | 83 |
|
---|
| 84 | protected:
|
---|
| 85 | bool event(QEvent *e);
|
---|
| 86 |
|
---|
| 87 | static QGLMaterial* getMaterial(size_t);
|
---|
| 88 | static void cleanMaterialMap();
|
---|
| 89 |
|
---|
| 90 | typedef std::map< size_t, QGLMaterial *> ElementMaterialMap;
|
---|
| 91 | static ElementMaterialMap ElementNoMaterialMap;
|
---|
| 92 |
|
---|
| 93 | private:
|
---|
| 94 |
|
---|
| 95 | QGLSceneNode *m_mesh;
|
---|
| 96 | QGLAbstractScene *m_scene;
|
---|
| 97 | QVector3D m_position;
|
---|
| 98 | qreal m_scale;
|
---|
[fbb1f1] | 99 | qreal m_scaleZ;
|
---|
[907636] | 100 | qreal m_rotationAngle;
|
---|
| 101 | QVector3D m_rotationVector;
|
---|
| 102 | QGLMaterial *m_material;
|
---|
[3b229e] | 103 | static QGLMaterial *m_hoverMaterial;
|
---|
| 104 | static QGLMaterial *m_selectionMaterial;
|
---|
| 105 | static QGLMaterial *m_selectionBoxMaterial;
|
---|
[907636] | 106 | QGLAbstractEffect *m_effect;
|
---|
| 107 | int m_objectId;
|
---|
| 108 | bool m_hovering;
|
---|
[8a77ac] | 109 | bool m_selected;
|
---|
[907636] | 110 | };
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 | #endif /* GLMOLECULEOBJECT_HPP_ */
|
---|