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