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 | Vector updateLeftPosition() const;
|
---|
78 | Vector updateRightPosition() const;
|
---|
79 | atomicNumber_t updateLeftElement() const;
|
---|
80 | atomicNumber_t updateRightElement() const;
|
---|
81 | int updateDegree() const;
|
---|
82 |
|
---|
83 | static const atom * const getAtomConst(const atomId_t _id);
|
---|
84 | static atom * const getAtom(const atomId_t _id);
|
---|
85 |
|
---|
86 | private:
|
---|
87 | //!> id of left bond partner for safely emitting BondRemoved signal
|
---|
88 | const atomId_t leftatomId;
|
---|
89 | //!> id of right bond partner for safely emitting BondRemoved signal
|
---|
90 | const atomId_t rightatomId;
|
---|
91 |
|
---|
92 | //!> contains ref to Observable of left atom
|
---|
93 | const Observable * const leftowner;
|
---|
94 | //!> contains ref to Observable of right atom
|
---|
95 | const Observable * const rightowner;
|
---|
96 | //!> temporary variable used in cstor
|
---|
97 | const Observable * const bondowner;
|
---|
98 |
|
---|
99 | const enum SideOfBond BondSide;
|
---|
100 |
|
---|
101 |
|
---|
102 | private:
|
---|
103 | /** Observed Values **/
|
---|
104 |
|
---|
105 | //!> enumeration of observed values to match with entries in ObservedValues
|
---|
106 | enum ObservedTypes {
|
---|
107 | //!> contains the position of the left atom
|
---|
108 | leftPosition,
|
---|
109 | //!> contains the position of the right atom
|
---|
110 | rightPosition,
|
---|
111 | //!> contains the element of the left atom
|
---|
112 | leftElement,
|
---|
113 | //!> contains the element of the right atom
|
---|
114 | rightElement,
|
---|
115 | //!> contains the degree of the bond
|
---|
116 | Degree,
|
---|
117 | //!> gives the size of the enumeration
|
---|
118 | MAX_ObservedTypes
|
---|
119 | };
|
---|
120 |
|
---|
121 | //!> vector with all observed values
|
---|
122 | std::vector<boost::any> ObservedValues;
|
---|
123 |
|
---|
124 | /** Initializes all \a ObservedValues entries.
|
---|
125 | *
|
---|
126 | */
|
---|
127 | void initObservedValues();
|
---|
128 |
|
---|
129 | /** Destroys all \a ObservedValues entries.
|
---|
130 | *
|
---|
131 | */
|
---|
132 | void destroyObservedValues();
|
---|
133 |
|
---|
134 | /** Getter to left atom's position contained in \a ObservedValues.
|
---|
135 | *
|
---|
136 | * \return left atom's position
|
---|
137 | */
|
---|
138 | Vector getleftPosition() const;
|
---|
139 |
|
---|
140 | /** Getter to right atom's position contained in \a ObservedValues.
|
---|
141 | *
|
---|
142 | * \return right atom's position
|
---|
143 | */
|
---|
144 | Vector getrightPosition() const;
|
---|
145 |
|
---|
146 | /** Getter to left atom's element contained in \a ObservedValues.
|
---|
147 | *
|
---|
148 | * \return left atom's element
|
---|
149 | */
|
---|
150 | atomicNumber_t getleftElement() const;
|
---|
151 |
|
---|
152 | /** Getter to rightatom's element contained in \a ObservedValues.
|
---|
153 | *
|
---|
154 | * \return right atom's element
|
---|
155 | */
|
---|
156 | atomicNumber_t getrightElement() const;
|
---|
157 |
|
---|
158 | /** Getter to bond's degree contained in \a ObservedValues.
|
---|
159 | *
|
---|
160 | * \return bond's degree
|
---|
161 | */
|
---|
162 | int getDegree() const;
|
---|
163 |
|
---|
164 | /** Counts how many ObservedValues got subjectKilled.
|
---|
165 | *
|
---|
166 | * This is used to give InstanceRemoved() signal only when each and every
|
---|
167 | * ObservedValue (and the instance itself) has been subjectKilled by the
|
---|
168 | * monitored Observable. Only then can we safely remove the instance.
|
---|
169 | *
|
---|
170 | */
|
---|
171 | void countsubjectKilled();
|
---|
172 |
|
---|
173 | //!> counts how many ObservedValues have already been subjectKilled()
|
---|
174 | mutable size_t subjectKilledCount;
|
---|
175 |
|
---|
176 | private:
|
---|
177 |
|
---|
178 | //!> indicate whether we are signed in to leftobservable
|
---|
179 | bool leftobservable_enabled;
|
---|
180 | //!> indicate whether we are signed in to rightobservable
|
---|
181 | bool rightobservable_enabled;
|
---|
182 | //!> indicate whether we are signed in to bond itself
|
---|
183 | bool bond_enabled;
|
---|
184 |
|
---|
185 | //!> list of channels when position needs to update
|
---|
186 | static const Observable::channels_t BondPositionChannels;
|
---|
187 | //!>list of channels when degree needs to update
|
---|
188 | static const Observable::channels_t BondDegreeChannels;
|
---|
189 | //!> list of channels when element needs to update
|
---|
190 | static const Observable::channels_t BondElementChannels;
|
---|
191 | };
|
---|
192 |
|
---|
193 |
|
---|
194 |
|
---|
195 | #endif /* GLMOLECULEOBJECT_BOND_HPP_ */
|
---|