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