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