| [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 | 
 | 
|---|
| [739ee9] | 76 |    bool visible() const { return m_visible; }
 | 
|---|
| [34e7fdb] | 77 |    virtual void setVisible(bool value);
 | 
|---|
| [739ee9] | 78 | 
 | 
|---|
| [3b229e] | 79 |    void initStaticMaterials();
 | 
|---|
| [8c001a] | 80 |    virtual void initialize(QGLView *view, QGLPainter *painter);
 | 
|---|
| [615eee] | 81 |    virtual void draw(QGLPainter *painter, const QVector4D &cameraPlane);
 | 
|---|
| [225cf5] | 82 |    void drawSelectionBox(QGLPainter *painter);
 | 
|---|
| [907636] | 83 | 
 | 
|---|
 | 84 | signals:
 | 
|---|
 | 85 |    void pressed();
 | 
|---|
 | 86 |    void released();
 | 
|---|
 | 87 |    void clicked();
 | 
|---|
 | 88 |    void doubleClicked();
 | 
|---|
| [407638e] | 89 |    void hoverChanged(GLMoleculeObject *ob);
 | 
|---|
| [5a2a06] | 90 |    void selectionChanged();
 | 
|---|
 | 91 |    void changed();
 | 
|---|
| [907636] | 92 | 
 | 
|---|
 | 93 | protected:
 | 
|---|
 | 94 |    bool event(QEvent *e);
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 |    static QGLMaterial* getMaterial(size_t);
 | 
|---|
 | 97 |    static void cleanMaterialMap();
 | 
|---|
 | 98 | 
 | 
|---|
| [34e7fdb] | 99 |    void updateMesh(QGLSceneNode *scene);
 | 
|---|
 | 100 | 
 | 
|---|
| [907636] | 101 |    typedef std::map< size_t, QGLMaterial *> ElementMaterialMap;
 | 
|---|
 | 102 |    static ElementMaterialMap ElementNoMaterialMap;
 | 
|---|
 | 103 | 
 | 
|---|
| [72a4c1] | 104 | public:
 | 
|---|
 | 105 |    enum{DETAIL_HIGHEST, DETAIL_HIGH, DETAIL_MEDIUM, DETAIL_LOW, DETAILTYPES_MAX} DetailType;
 | 
|---|
 | 106 | 
 | 
|---|
| [8c001a] | 107 |    static QGLSceneNode *meshEmpty[DETAILTYPES_MAX];
 | 
|---|
 | 108 |    static QGLSceneNode *meshSphere[DETAILTYPES_MAX];
 | 
|---|
 | 109 |    static QGLSceneNode *meshCylinder[DETAILTYPES_MAX];
 | 
|---|
| [897a01] | 110 |    static QGLSceneNode *meshArrow[DETAILTYPES_MAX];
 | 
|---|
| [8c001a] | 111 | 
 | 
|---|
| [615eee] | 112 | protected:
 | 
|---|
| [907636] | 113 | 
 | 
|---|
| [72a4c1] | 114 |    static double detailMinDistance[DETAILTYPES_MAX];
 | 
|---|
 | 115 | 
 | 
|---|
 | 116 |    QGLSceneNode *m_mesh[DETAILTYPES_MAX];
 | 
|---|
| [7b93f9] | 117 |    enum enum_MeshFreeType {
 | 
|---|
 | 118 |      free_all,
 | 
|---|
 | 119 |      free_single,
 | 
|---|
 | 120 |      free_none
 | 
|---|
 | 121 |    } MeshFreeType;
 | 
|---|
| [907636] | 122 |    QGLAbstractScene *m_scene;
 | 
|---|
 | 123 |    QVector3D m_position;
 | 
|---|
| [2d5137] | 124 |    qreal m_scaleX;
 | 
|---|
 | 125 |    qreal m_scaleY;
 | 
|---|
| [fbb1f1] | 126 |    qreal m_scaleZ;
 | 
|---|
| [907636] | 127 |    qreal m_rotationAngle;
 | 
|---|
 | 128 |    QVector3D m_rotationVector;
 | 
|---|
 | 129 |    QGLMaterial *m_material;
 | 
|---|
| [3b229e] | 130 |    static QGLMaterial *m_hoverMaterial;
 | 
|---|
 | 131 |    static QGLMaterial *m_selectionMaterial;
 | 
|---|
 | 132 |    static QGLMaterial *m_selectionBoxMaterial;
 | 
|---|
| [897a01] | 133 |    static QGLMaterial *m_velocityMaterial;
 | 
|---|
 | 134 |    static QGLMaterial *m_forceMaterial;
 | 
|---|
| [907636] | 135 |    QGLAbstractEffect *m_effect;
 | 
|---|
 | 136 |    int m_objectId;
 | 
|---|
 | 137 |    bool m_hovering;
 | 
|---|
| [8a77ac] | 138 |    bool m_selected;
 | 
|---|
| [739ee9] | 139 |    bool m_visible;
 | 
|---|
| [907636] | 140 | };
 | 
|---|
 | 141 | 
 | 
|---|
 | 142 | 
 | 
|---|
 | 143 | #endif /* GLMOLECULEOBJECT_HPP_ */
 | 
|---|