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