1 | /*
|
---|
2 | * GLMoleculeObject_bond.hpp
|
---|
3 | *
|
---|
4 | * Created on: Aug 17, 2011
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef GLMOLECULEOBJECT_BOND_HPP_
|
---|
9 | #define GLMOLECULEOBJECT_BOND_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 <vector>
|
---|
19 | #include <boost/any.hpp>
|
---|
20 | #include <boost/function.hpp>
|
---|
21 |
|
---|
22 | #include "CodePatterns/Observer/Observer.hpp"
|
---|
23 | #include "CodePatterns/ObservedValue.hpp"
|
---|
24 |
|
---|
25 | #include "LinearAlgebra/Vector.hpp"
|
---|
26 |
|
---|
27 | #include "Bond/bond.hpp"
|
---|
28 | #include "types.hpp"
|
---|
29 |
|
---|
30 | class atom;
|
---|
31 |
|
---|
32 | class GLWorldScene;
|
---|
33 |
|
---|
34 | class GLMoleculeObject_bond : public GLMoleculeObject, public Observer
|
---|
35 | {
|
---|
36 | Q_OBJECT
|
---|
37 | public:
|
---|
38 | enum SideOfBond { left, right };
|
---|
39 |
|
---|
40 | typedef std::pair<atomId_t, atomId_t> bondIds_t;
|
---|
41 |
|
---|
42 | GLMoleculeObject_bond(
|
---|
43 | QGLSceneNode *mesh[],
|
---|
44 | QObject *parent,
|
---|
45 | const bondIds_t bondIds,
|
---|
46 | const enum SideOfBond side);
|
---|
47 | GLMoleculeObject_bond(
|
---|
48 | QGLSceneNode *mesh[],
|
---|
49 | QObject *parent,
|
---|
50 | const bondIds_t bondIds,
|
---|
51 | const enum SideOfBond side,
|
---|
52 | std::vector<boost::any> &_ObservedValues,
|
---|
53 | const boost::function<void (const bondIds_t)> &_subjectKilled);
|
---|
54 | virtual ~GLMoleculeObject_bond();
|
---|
55 |
|
---|
56 | // Observer functions
|
---|
57 | void update(Observable *publisher);
|
---|
58 | void subjectKilled(Observable *publisher);
|
---|
59 | void recieveNotification(Observable *publisher, Notification_ptr notification);
|
---|
60 |
|
---|
61 | signals:
|
---|
62 | void BondRemoved(const atomId_t leftnr, const atomId_t rightnr);
|
---|
63 | void elementChanged();
|
---|
64 | void positionChanged();
|
---|
65 | void degreeChanged();
|
---|
66 |
|
---|
67 | private slots:
|
---|
68 | //!> grant GLMoleculeObject_molecule acess to reset functions
|
---|
69 | friend class GLMoleculeObject_molecule;
|
---|
70 |
|
---|
71 | /** Recalculates the element of the cylinder representing the bond.
|
---|
72 | *
|
---|
73 | */
|
---|
74 | void resetElement();
|
---|
75 |
|
---|
76 | /** Recalculates the position of the cylinder representing the bond.
|
---|
77 | *
|
---|
78 | */
|
---|
79 | void resetPosition();
|
---|
80 |
|
---|
81 | /** Recalculates the width of the cylinder representing the bond's degree.
|
---|
82 | *
|
---|
83 | */
|
---|
84 | void resetWidth();
|
---|
85 |
|
---|
86 | private:
|
---|
87 |
|
---|
88 | void init();
|
---|
89 |
|
---|
90 | void removeChannels();
|
---|
91 |
|
---|
92 | static atomId_t updateIndex();
|
---|
93 | static Vector updateLeftPosition(
|
---|
94 | const boost::function<const atomId_t ()> &_getLeftAtomIndex);
|
---|
95 | static Vector updateRightPosition(
|
---|
96 | const boost::function<const atomId_t ()> &_getRightAtomIndex);
|
---|
97 | static atomicNumber_t updateLeftElement(
|
---|
98 | const boost::function<const atomId_t ()> &_getLeftAtomIndex);
|
---|
99 | static atomicNumber_t updateRightElement(
|
---|
100 | const boost::function<const atomId_t ()> &_getRightAtomIndex);
|
---|
101 | static int updateDegree(
|
---|
102 | const boost::function<const atomId_t ()> &_getLeftAtomIndex,
|
---|
103 | const boost::function<const atomId_t ()> &_getRightAtomIndex);
|
---|
104 |
|
---|
105 | static const atom * const getAtomConst(const atomId_t _id);
|
---|
106 | static atom * const getAtom(const atomId_t _id);
|
---|
107 |
|
---|
108 | private:
|
---|
109 | //!> contains ref to Observable of left atom
|
---|
110 | const Observable * const leftowner;
|
---|
111 | //!> contains ref to Observable of right atom
|
---|
112 | const Observable * const rightowner;
|
---|
113 | //!> temporary variable used in cstor
|
---|
114 | const Observable * const bondowner;
|
---|
115 |
|
---|
116 | const enum SideOfBond BondSide;
|
---|
117 |
|
---|
118 |
|
---|
119 | private:
|
---|
120 | /** Observed Values **/
|
---|
121 |
|
---|
122 | //!> enumeration of observed values to match with entries in ObservedValues
|
---|
123 | enum ObservedTypes {
|
---|
124 | //!> contains the id of the left atom
|
---|
125 | leftIndex,
|
---|
126 | //!> contains the id of the right atom
|
---|
127 | rightIndex,
|
---|
128 | //!> contains the position of the left atom
|
---|
129 | leftPosition,
|
---|
130 | //!> contains the position of the right atom
|
---|
131 | rightPosition,
|
---|
132 | //!> contains the element of the left atom
|
---|
133 | leftElement,
|
---|
134 | //!> contains the element of the right atom
|
---|
135 | rightElement,
|
---|
136 | //!> contains the degree of the bond
|
---|
137 | Degree,
|
---|
138 | //!> gives the size of the enumeration
|
---|
139 | MAX_ObservedTypes
|
---|
140 | };
|
---|
141 |
|
---|
142 | //!> vector with all observed values
|
---|
143 | std::vector<boost::any> ObservedValues;
|
---|
144 |
|
---|
145 | /** Initializes all \a ObservedValues entries.
|
---|
146 | *
|
---|
147 | * \param _ObservedValues vector of ObservedValue to be filled
|
---|
148 | * \param _leftatomId left atom id
|
---|
149 | * \param _rightatomId right atom id
|
---|
150 | * \param _leftowner reference to left atom
|
---|
151 | * \param _rightowner reference to right atom
|
---|
152 | * \param _bondowner reference to bond
|
---|
153 | * \param _leftsubjectKilled ref to function to call on subjectKilled() for left atom
|
---|
154 | * \param _rightsubjectKilled ref to function to call on subjectKilled() for right atom
|
---|
155 | * \param _bondsubjectKilled ref to function to call on subjectKilled() for bond
|
---|
156 | */
|
---|
157 | static void initObservedValues(
|
---|
158 | std::vector<boost::any> &_ObservedValues,
|
---|
159 | const atomId_t _leftatomId,
|
---|
160 | const atomId_t _rightatomId,
|
---|
161 | const Observable * const _leftowner,
|
---|
162 | const Observable * const _rightowner,
|
---|
163 | const Observable * const _bondowner,
|
---|
164 | const boost::function<void(const atomId_t &)> &_leftsubjectKilled,
|
---|
165 | const boost::function<void(const atomId_t &)> &_rightsubjectKilled,
|
---|
166 | const boost::function<void(const bondIds_t &)> &_bondsubjectKilled);
|
---|
167 |
|
---|
168 | /** Destroys all \a ObservedValues entries.
|
---|
169 | *
|
---|
170 | * \param _ObservedValues vector of ObservedValue to be destroyed
|
---|
171 | */
|
---|
172 | static void destroyObservedValues(
|
---|
173 | std::vector<boost::any> &_ObservedValues);
|
---|
174 |
|
---|
175 | /** Getter to left atom's id contained in \a ObservedValues.
|
---|
176 | *
|
---|
177 | * \return left atom's id
|
---|
178 | */
|
---|
179 | const atomId_t& getleftIndex() const;
|
---|
180 |
|
---|
181 | /** Getter to right atom's id contained in \a ObservedValues.
|
---|
182 | *
|
---|
183 | * \return right atom's id
|
---|
184 | */
|
---|
185 | const atomId_t& getrightIndex() const;
|
---|
186 |
|
---|
187 | /** Getter to left atom's position contained in \a ObservedValues.
|
---|
188 | *
|
---|
189 | * \return left atom's position
|
---|
190 | */
|
---|
191 | const Vector& getleftPosition() const;
|
---|
192 |
|
---|
193 | /** Getter to right atom's position contained in \a ObservedValues.
|
---|
194 | *
|
---|
195 | * \return right atom's position
|
---|
196 | */
|
---|
197 | const Vector& getrightPosition() const;
|
---|
198 |
|
---|
199 | /** Getter to left atom's element contained in \a ObservedValues.
|
---|
200 | *
|
---|
201 | * \return left atom's element
|
---|
202 | */
|
---|
203 | const atomicNumber_t& getleftElement() const;
|
---|
204 |
|
---|
205 | /** Getter to rightatom's element contained in \a ObservedValues.
|
---|
206 | *
|
---|
207 | * \return right atom's element
|
---|
208 | */
|
---|
209 | const atomicNumber_t& getrightElement() const;
|
---|
210 |
|
---|
211 | /** Getter to bond's degree contained in \a ObservedValues.
|
---|
212 | *
|
---|
213 | * \return bond's degree
|
---|
214 | */
|
---|
215 | const int& getDegree() const;
|
---|
216 |
|
---|
217 | /** Counts how many ObservedValues got subjectKilled.
|
---|
218 | *
|
---|
219 | * This is used to give InstanceRemoved() signal only when each and every
|
---|
220 | * ObservedValue (and the instance itself) has been subjectKilled by the
|
---|
221 | * monitored Observable. Only then can we safely remove the instance.
|
---|
222 | *
|
---|
223 | * \param _bondIds bond ids whose bond has called subjectKilled()
|
---|
224 | */
|
---|
225 | void countsubjectKilled(
|
---|
226 | const bondIds_t &_bondIds)
|
---|
227 | {
|
---|
228 | countsubjectKilled();
|
---|
229 | }
|
---|
230 |
|
---|
231 | void countsubjectKilled(
|
---|
232 | const atomId_t &_atomid)
|
---|
233 | {
|
---|
234 | countsubjectKilled();
|
---|
235 | }
|
---|
236 |
|
---|
237 | void countsubjectKilled();
|
---|
238 |
|
---|
239 | //!> counts how many ObservedValues have already been subjectKilled()
|
---|
240 | mutable size_t subjectKilledCount;
|
---|
241 |
|
---|
242 | private:
|
---|
243 |
|
---|
244 | //!> indicate whether we are signed in to leftobservable
|
---|
245 | bool leftobservable_enabled;
|
---|
246 | //!> indicate whether we are signed in to rightobservable
|
---|
247 | bool rightobservable_enabled;
|
---|
248 | //!> indicate whether we are signed in to bond itself
|
---|
249 | bool bond_enabled;
|
---|
250 |
|
---|
251 | //!> list of channels when id needs to update
|
---|
252 | static const Observable::channels_t IndexChannels;
|
---|
253 | //!> list of channels when position needs to update
|
---|
254 | static const Observable::channels_t BondPositionChannels;
|
---|
255 | //!>list of channels when degree needs to update
|
---|
256 | static const Observable::channels_t BondDegreeChannels;
|
---|
257 | //!> list of channels when element needs to update
|
---|
258 | static const Observable::channels_t BondElementChannels;
|
---|
259 |
|
---|
260 | //!> callback function to inform about subjectKilled()
|
---|
261 | const boost::function<void (const bondIds_t)> board_subjectKilled;
|
---|
262 | };
|
---|
263 |
|
---|
264 |
|
---|
265 |
|
---|
266 | #endif /* GLMOLECULEOBJECT_BOND_HPP_ */
|
---|