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 | 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; }
|
---|
54 |
|
---|
55 | qreal scaleZ() const { return m_scaleZ; }
|
---|
56 | void setScaleZ(qreal value) { m_scaleZ = value; }
|
---|
57 |
|
---|
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; }
|
---|
65 | void setMaterial(QGLMaterial *value) { m_material = value; }
|
---|
66 |
|
---|
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 |
|
---|
73 | bool selected() const { return m_selected; }
|
---|
74 | void setSelected(bool value);
|
---|
75 |
|
---|
76 | void initStaticMaterials();
|
---|
77 | void initialize(QGLView *view, QGLPainter *painter);
|
---|
78 | virtual void draw(QGLPainter *painter, const QVector4D &cameraPlane);
|
---|
79 | void drawSelectionBox(QGLPainter *painter);
|
---|
80 |
|
---|
81 | signals:
|
---|
82 | void pressed();
|
---|
83 | void released();
|
---|
84 | void clicked();
|
---|
85 | void doubleClicked();
|
---|
86 | void hoverChanged(GLMoleculeObject *ob);
|
---|
87 | void selectionChanged();
|
---|
88 | void changed();
|
---|
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 |
|
---|
99 | public:
|
---|
100 | enum{DETAIL_HIGHEST, DETAIL_HIGH, DETAIL_MEDIUM, DETAIL_LOW, DETAILTYPES_MAX} DetailType;
|
---|
101 |
|
---|
102 | protected:
|
---|
103 |
|
---|
104 | static double detailMinDistance[DETAILTYPES_MAX];
|
---|
105 |
|
---|
106 | QGLSceneNode *m_mesh[DETAILTYPES_MAX];
|
---|
107 | QGLAbstractScene *m_scene;
|
---|
108 | QVector3D m_position;
|
---|
109 | qreal m_scaleX;
|
---|
110 | qreal m_scaleY;
|
---|
111 | qreal m_scaleZ;
|
---|
112 | qreal m_rotationAngle;
|
---|
113 | QVector3D m_rotationVector;
|
---|
114 | QGLMaterial *m_material;
|
---|
115 | static QGLMaterial *m_hoverMaterial;
|
---|
116 | static QGLMaterial *m_selectionMaterial;
|
---|
117 | static QGLMaterial *m_selectionBoxMaterial;
|
---|
118 | QGLAbstractEffect *m_effect;
|
---|
119 | int m_objectId;
|
---|
120 | bool m_hovering;
|
---|
121 | bool m_selected;
|
---|
122 | };
|
---|
123 |
|
---|
124 |
|
---|
125 | #endif /* GLMOLECULEOBJECT_HPP_ */
|
---|