1 | /*
|
---|
2 | * GLMoleculeObject_molecule.hpp
|
---|
3 | *
|
---|
4 | * Created on: Mar 30, 2012
|
---|
5 | * Author: ankele
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef GLMOLECULEOBJECT_MOLECULE_HPP_
|
---|
9 | #define GLMOLECULEOBJECT_MOLECULE_HPP_
|
---|
10 |
|
---|
11 | // include config.h
|
---|
12 | #ifdef HAVE_CONFIG_H
|
---|
13 | #include <config.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #include "GLMoleculeObject.hpp"
|
---|
17 |
|
---|
18 | #include <Qt3D/qgeometrydata.h>
|
---|
19 |
|
---|
20 | #include "CodePatterns/Cacheable.hpp"
|
---|
21 | #include "CodePatterns/Observer/Observer.hpp"
|
---|
22 | #include "CodePatterns/ObservedValue.hpp"
|
---|
23 |
|
---|
24 | #include "GLMoleculeObject_bond.hpp"
|
---|
25 |
|
---|
26 | #include "molecule.hpp"
|
---|
27 |
|
---|
28 | class atom;
|
---|
29 | class bond;
|
---|
30 | class GLMoleculeObject_atom;
|
---|
31 | class GLWorldScene;
|
---|
32 |
|
---|
33 | class GLMoleculeObject_molecule : public GLMoleculeObject, public Observer
|
---|
34 | {
|
---|
35 | Q_OBJECT
|
---|
36 | public:
|
---|
37 | GLMoleculeObject_molecule(QObject *parent, const moleculeId_t molid);
|
---|
38 | GLMoleculeObject_molecule(QGLSceneNode *mesh[], QObject *parent, const moleculeId_t molid);
|
---|
39 | virtual ~GLMoleculeObject_molecule();
|
---|
40 |
|
---|
41 | // Observer functions
|
---|
42 | void update(Observable *publisher);
|
---|
43 | void subjectKilled(Observable *publisher);
|
---|
44 | void recieveNotification(Observable *publisher, Notification_ptr notification);
|
---|
45 |
|
---|
46 | void initialize(QGLView *view, QGLPainter *painter);
|
---|
47 | void draw(QGLPainter *painter, const QVector4D &cameraPlane);
|
---|
48 |
|
---|
49 | typedef std::pair< atomId_t, atomId_t> BondIds;
|
---|
50 | friend std::ostream &operator<<(std::ostream &ost, const BondIds &t);
|
---|
51 |
|
---|
52 | static BondIds getBondIds(
|
---|
53 | const bond::ptr _bond,
|
---|
54 | const enum GLMoleculeObject_bond::SideOfBond side);
|
---|
55 |
|
---|
56 | signals:
|
---|
57 | void changed();
|
---|
58 | void changeOccured();
|
---|
59 | void hoverChanged(const atomId_t);
|
---|
60 | void hoverChanged(const moleculeId_t, int);
|
---|
61 | void indexChanged(GLMoleculeObject_molecule *, const moleculeId_t, const moleculeId_t);
|
---|
62 | void atomClicked(atomId_t no);
|
---|
63 | void moleculeClicked(moleculeId_t no);
|
---|
64 | void TesselationHullChanged();
|
---|
65 | void BoundingBoxChanged();
|
---|
66 | void IsSelectedChanged();
|
---|
67 | void AtomInserted(const atomId_t _id);
|
---|
68 | void AtomRemoved(const atomId_t _id);
|
---|
69 | void IdChanged();
|
---|
70 |
|
---|
71 | private slots:
|
---|
72 | //!> grant GLWorldScene access to private slots
|
---|
73 | friend class GLWorldScene;
|
---|
74 |
|
---|
75 | void wasClicked();
|
---|
76 | void atomInserted(const atomId_t _id);
|
---|
77 | void atomRemoved(const atomId_t _id);
|
---|
78 | void bondInserted(const atomId_t, const atomId_t, const GLMoleculeObject_bond::SideOfBond side);
|
---|
79 | void bondRemoved(const atomId_t leftnr, const atomId_t rightnr);
|
---|
80 | void hoverChangedSignalled(GLMoleculeObject *ob);
|
---|
81 | void changeAtomId(GLMoleculeObject_atom *, const atomId_t, const atomId_t);
|
---|
82 |
|
---|
83 | void setVisible(bool value);
|
---|
84 |
|
---|
85 | void activateObserver();
|
---|
86 | void deactivateObserver();
|
---|
87 |
|
---|
88 | void resetTesselationHull();
|
---|
89 | void resetBoundingBox();
|
---|
90 | void resetAtoms();
|
---|
91 | void resetIndex();
|
---|
92 | void resetName();
|
---|
93 |
|
---|
94 | void AtomSelected(const atomId_t _id);
|
---|
95 | void AtomUnselected(const atomId_t _id);
|
---|
96 | void Selected();
|
---|
97 | void Unselected();
|
---|
98 |
|
---|
99 | private:
|
---|
100 | static const molecule * const getMolecule(const moleculeId_t _id);
|
---|
101 |
|
---|
102 | private:
|
---|
103 | void addAtomBonds(
|
---|
104 | const bond::ptr &_bond,
|
---|
105 | const GLMoleculeObject_bond::SideOfBond _side
|
---|
106 | );
|
---|
107 | void addAtomBonds(const atomId_t _id);
|
---|
108 |
|
---|
109 | //!> typedef for the internal set of atoms
|
---|
110 | typedef std::set<atomId_t> atoms_t;
|
---|
111 |
|
---|
112 | molecule::BoundingBoxInfo initBoundingBox() const;
|
---|
113 |
|
---|
114 | QGeometryData updateTesselationHull() const;
|
---|
115 | molecule::BoundingBoxInfo updateBoundingBox() const;
|
---|
116 | atoms_t updateAtoms();
|
---|
117 | moleculeId_t updateIndex() const;
|
---|
118 | std::string updateName() const;
|
---|
119 |
|
---|
120 | //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
|
---|
121 | const Observable * owner;
|
---|
122 |
|
---|
123 | //!> internal variable for caching molecule ref in cstor
|
---|
124 | const molecule * const molref;
|
---|
125 |
|
---|
126 | //!> list of channels when contained atoms needs to update
|
---|
127 | static const Observable::channels_t AtomsChannels;
|
---|
128 | //!> list of channels when tesselation hull needs to update
|
---|
129 | static const Observable::channels_t HullChannels;
|
---|
130 | //!> list of channels when bounding box needs to update
|
---|
131 | static const Observable::channels_t BoundingBoxChannels;
|
---|
132 | //!> list of channels when the index needs to update
|
---|
133 | static const Observable::channels_t IndexChannels;
|
---|
134 | //!> list of channels when the name needs to update
|
---|
135 | static const Observable::channels_t NameChannels;
|
---|
136 |
|
---|
137 | boost::function<moleculeId_t ()> MolIndexUpdater;
|
---|
138 | boost::function<std::string ()> MolNameUpdater;
|
---|
139 | boost::function<QGeometryData ()> TesselationHullUpdater;
|
---|
140 | boost::function<molecule::BoundingBoxInfo ()> BoundingBoxUpdater;
|
---|
141 | boost::function<atoms_t ()> PresentAtomsUpdater;
|
---|
142 |
|
---|
143 | //!> contains the current molecule index
|
---|
144 | ObservedValue<moleculeId_t> MolIndex;
|
---|
145 | //!> contains the current molecule name
|
---|
146 | ObservedValue<std::string> MolName;
|
---|
147 | //!> contains current version of the tesselation hull on request
|
---|
148 | Cacheable<QGeometryData> TesselationHull;
|
---|
149 | //!> contains newest version of the bounding box on request
|
---|
150 | ObservedValue<molecule::BoundingBoxInfo> BoundingBox;
|
---|
151 | //!> contains the current live set of atoms for the molecule
|
---|
152 | ObservedValue<atoms_t> PresentAtoms;
|
---|
153 |
|
---|
154 | //!> contains the set of atoms displayed
|
---|
155 | atoms_t DisplayedAtoms;
|
---|
156 |
|
---|
157 | typedef std::map< atomId_t, GLMoleculeObject_atom* > AtomNodeMap;
|
---|
158 | typedef std::map< BondIds , GLMoleculeObject_bond* > BondNodeMap;
|
---|
159 | AtomNodeMap AtomsinSceneMap;
|
---|
160 | BondNodeMap BondsinSceneMap;
|
---|
161 |
|
---|
162 | atomId_t hoverAtomId;
|
---|
163 | };
|
---|
164 |
|
---|
165 | std::ostream &operator<<(std::ostream &ost, const GLMoleculeObject_molecule::BondIds &t);
|
---|
166 |
|
---|
167 |
|
---|
168 | #endif /* GLMOLECULEOBJECT_MOLECULE_HPP_ */
|
---|