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 <vector>
|
---|
21 | #include <boost/any.hpp>
|
---|
22 |
|
---|
23 | #include "CodePatterns/Cacheable.hpp"
|
---|
24 | #include "CodePatterns/Observer/Observer.hpp"
|
---|
25 | #include "CodePatterns/ObservedValue.hpp"
|
---|
26 |
|
---|
27 | #include "GLMoleculeObject_bond.hpp"
|
---|
28 |
|
---|
29 | #include "molecule.hpp"
|
---|
30 |
|
---|
31 | class atom;
|
---|
32 | class bond;
|
---|
33 | class GLMoleculeObject_atom;
|
---|
34 | class GLWorldScene;
|
---|
35 |
|
---|
36 | class GLMoleculeObject_molecule : public GLMoleculeObject, public Observer
|
---|
37 | {
|
---|
38 | Q_OBJECT
|
---|
39 | public:
|
---|
40 | GLMoleculeObject_molecule(QObject *parent, const moleculeId_t molid);
|
---|
41 | GLMoleculeObject_molecule(QGLSceneNode *mesh[], QObject *parent, const moleculeId_t molid);
|
---|
42 | virtual ~GLMoleculeObject_molecule();
|
---|
43 |
|
---|
44 | // Observer functions
|
---|
45 | void update(Observable *publisher);
|
---|
46 | void subjectKilled(Observable *publisher);
|
---|
47 | void recieveNotification(Observable *publisher, Notification_ptr notification);
|
---|
48 |
|
---|
49 | void initialize(QGLView *view, QGLPainter *painter);
|
---|
50 | void draw(QGLPainter *painter, const QVector4D &cameraPlane);
|
---|
51 |
|
---|
52 | typedef std::pair< atomId_t, atomId_t> BondIds;
|
---|
53 | friend std::ostream &operator<<(std::ostream &ost, const BondIds &t);
|
---|
54 |
|
---|
55 | static BondIds getBondIds(
|
---|
56 | const bond::ptr _bond,
|
---|
57 | const enum GLMoleculeObject_bond::SideOfBond side);
|
---|
58 |
|
---|
59 | signals:
|
---|
60 | void changed();
|
---|
61 | void changeOccured();
|
---|
62 | void hoverChanged(const atomId_t);
|
---|
63 | void hoverChanged(const moleculeId_t, int);
|
---|
64 | void indexChanged(GLMoleculeObject_molecule *, const moleculeId_t, const moleculeId_t);
|
---|
65 | void atomClicked(atomId_t no);
|
---|
66 | void moleculeClicked(moleculeId_t no);
|
---|
67 | void TesselationHullChanged();
|
---|
68 | void BoundingBoxChanged();
|
---|
69 | void IsSelectedChanged();
|
---|
70 | void AtomInserted(const atomId_t _id);
|
---|
71 | void AtomRemoved(const atomId_t _id);
|
---|
72 | void IdChanged();
|
---|
73 | void InstanceRemoved(const moleculeId_t);
|
---|
74 |
|
---|
75 | private slots:
|
---|
76 | //!> grant GLWorldScene access to private slots
|
---|
77 | friend class GLWorldScene;
|
---|
78 |
|
---|
79 | void wasClicked();
|
---|
80 | void atomInserted(const atomId_t _id);
|
---|
81 | void atomRemoved(const atomId_t _id);
|
---|
82 | void bondInserted(const atomId_t, const atomId_t, const GLMoleculeObject_bond::SideOfBond side);
|
---|
83 | void bondRemoved(const atomId_t leftnr, const atomId_t rightnr);
|
---|
84 | void hoverChangedSignalled(GLMoleculeObject *ob);
|
---|
85 | void changeAtomId(GLMoleculeObject_atom *, const atomId_t, const atomId_t);
|
---|
86 |
|
---|
87 | void setVisible(bool value);
|
---|
88 |
|
---|
89 | void activateObserver();
|
---|
90 | void deactivateObserver();
|
---|
91 |
|
---|
92 | void resetTesselationHull();
|
---|
93 | void resetBoundingBox();
|
---|
94 | void resetAtoms();
|
---|
95 | void resetIndex();
|
---|
96 | void resetName();
|
---|
97 |
|
---|
98 | void AtomSelected(const atomId_t _id);
|
---|
99 | void AtomUnselected(const atomId_t _id);
|
---|
100 | void Selected();
|
---|
101 | void Unselected();
|
---|
102 |
|
---|
103 | private:
|
---|
104 | static const molecule * const getMolecule(const moleculeId_t _id);
|
---|
105 |
|
---|
106 | private:
|
---|
107 | void addAtomBonds(
|
---|
108 | const bond::ptr &_bond,
|
---|
109 | const GLMoleculeObject_bond::SideOfBond _side
|
---|
110 | );
|
---|
111 | void addAtomBonds(const atomId_t _id);
|
---|
112 |
|
---|
113 | //!> typedef for the internal set of atoms
|
---|
114 | typedef std::set<atomId_t> atoms_t;
|
---|
115 |
|
---|
116 | molecule::BoundingBoxInfo initBoundingBox() const;
|
---|
117 |
|
---|
118 | QGeometryData updateTesselationHull() const;
|
---|
119 | molecule::BoundingBoxInfo updateBoundingBox() const;
|
---|
120 | atoms_t updateAtoms();
|
---|
121 | moleculeId_t updateIndex() const;
|
---|
122 | std::string updateName() const;
|
---|
123 |
|
---|
124 | //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
|
---|
125 | const Observable * owner;
|
---|
126 |
|
---|
127 | //!> internal variable for caching molecule ref in cstor
|
---|
128 | const molecule * const molref;
|
---|
129 |
|
---|
130 | //!> list of channels when contained atoms needs to update
|
---|
131 | static const Observable::channels_t AtomsChannels;
|
---|
132 | //!> list of channels when tesselation hull needs to update
|
---|
133 | static const Observable::channels_t HullChannels;
|
---|
134 | //!> list of channels when bounding box needs to update
|
---|
135 | static const Observable::channels_t BoundingBoxChannels;
|
---|
136 | //!> list of channels when the index needs to update
|
---|
137 | static const Observable::channels_t IndexChannels;
|
---|
138 | //!> list of channels when the name needs to update
|
---|
139 | static const Observable::channels_t NameChannels;
|
---|
140 |
|
---|
141 | boost::function<moleculeId_t ()> MolIndexUpdater;
|
---|
142 | boost::function<std::string ()> MolNameUpdater;
|
---|
143 | boost::function<QGeometryData ()> TesselationHullUpdater;
|
---|
144 | boost::function<molecule::BoundingBoxInfo ()> BoundingBoxUpdater;
|
---|
145 | boost::function<atoms_t ()> PresentAtomsUpdater;
|
---|
146 |
|
---|
147 | private:
|
---|
148 | /** Observed Values **/
|
---|
149 |
|
---|
150 | //!> enumeration of observed values to match with entries in ObservedValues
|
---|
151 | enum ObservedTypes {
|
---|
152 | //!> contains the current molecule index
|
---|
153 | MolIndex,
|
---|
154 | //!> contains the current molecule name
|
---|
155 | MolName,
|
---|
156 | //!> contains newest version of the bounding box on request
|
---|
157 | BoundingBox,
|
---|
158 | //!> contains the current live set of atoms for the molecule
|
---|
159 | PresentAtoms,
|
---|
160 | //!> gives the size of the enumeration
|
---|
161 | MAX_ObservedTypes
|
---|
162 | };
|
---|
163 |
|
---|
164 | //!> vector with all observed values
|
---|
165 | std::vector<boost::any> ObservedValues;
|
---|
166 |
|
---|
167 | /** Initializes all \a ObservedValues entries.
|
---|
168 | *
|
---|
169 | * \param _moid molecule id
|
---|
170 | */
|
---|
171 | void initObservedValues(const moleculeId_t _molid);
|
---|
172 |
|
---|
173 | /** Destroys all \a ObservedValues entries.
|
---|
174 | *
|
---|
175 | */
|
---|
176 | void destroyObservedValues();
|
---|
177 |
|
---|
178 | /** Getter to molecule index contained in \a ObservedValues.
|
---|
179 | *
|
---|
180 | * \return molecule's index
|
---|
181 | */
|
---|
182 | moleculeId_t getMolIndex() const;
|
---|
183 |
|
---|
184 | /** Getter to molecule name contained in \a ObservedValues.
|
---|
185 | *
|
---|
186 | * \return molecule's name
|
---|
187 | */
|
---|
188 | std::string getMolName() const;
|
---|
189 |
|
---|
190 | /** Getter to molecule's bounding box contained in \a ObservedValues.
|
---|
191 | *
|
---|
192 | * \return molecule's bounding box
|
---|
193 | */
|
---|
194 | molecule::BoundingBoxInfo getBoundingBox() const;
|
---|
195 |
|
---|
196 | /** Getter to contained atoms contained in \a ObservedValues.
|
---|
197 | *
|
---|
198 | * \return molecule's contained atoms
|
---|
199 | */
|
---|
200 | atoms_t getPresentAtoms() const;
|
---|
201 |
|
---|
202 | /** Counts how many ObservedValues got subjectKilled.
|
---|
203 | *
|
---|
204 | * This is used to give InstanceRemoved() signal only when each and every
|
---|
205 | * ObservedValue (and the instance itself) has been subjectKilled by the
|
---|
206 | * monitored Observable. Only then can we safely remove the instance.
|
---|
207 | *
|
---|
208 | */
|
---|
209 | void countsubjectKilled();
|
---|
210 |
|
---|
211 | //!> counts how many ObservedValues have already been subjectKilled()
|
---|
212 | mutable size_t subjectKilledCount;
|
---|
213 |
|
---|
214 | //!> contains current version of the tesselation hull on request
|
---|
215 | Cacheable<QGeometryData> TesselationHull;
|
---|
216 |
|
---|
217 | private:
|
---|
218 | //!> contains the set of atoms displayed
|
---|
219 | atoms_t DisplayedAtoms;
|
---|
220 |
|
---|
221 | typedef std::map< atomId_t, GLMoleculeObject_atom* > AtomNodeMap;
|
---|
222 | typedef std::map< BondIds , GLMoleculeObject_bond* > BondNodeMap;
|
---|
223 | AtomNodeMap AtomsinSceneMap;
|
---|
224 | BondNodeMap BondsinSceneMap;
|
---|
225 |
|
---|
226 | atomId_t hoverAtomId;
|
---|
227 | };
|
---|
228 |
|
---|
229 | std::ostream &operator<<(std::ostream &ost, const GLMoleculeObject_molecule::BondIds &t);
|
---|
230 |
|
---|
231 |
|
---|
232 | #endif /* GLMOLECULEOBJECT_MOLECULE_HPP_ */
|
---|