[907636] | 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 |
|
---|
[7c7c4a] | 18 | #include <vector>
|
---|
| 19 | #include <boost/any.hpp>
|
---|
| 20 |
|
---|
[2ad1ec] | 21 | #include "CodePatterns/Observer/Observer.hpp"
|
---|
[009e2e2] | 22 | #include "CodePatterns/ObservedValue.hpp"
|
---|
| 23 |
|
---|
| 24 | #include "LinearAlgebra/Vector.hpp"
|
---|
[2ad1ec] | 25 |
|
---|
[88c8ec] | 26 | #include "Bond/bond.hpp"
|
---|
[2ad1ec] | 27 | #include "types.hpp"
|
---|
| 28 |
|
---|
[70db8f] | 29 | class atom;
|
---|
[907636] | 30 |
|
---|
[ce4126] | 31 | class GLWorldScene;
|
---|
| 32 |
|
---|
[2ad1ec] | 33 | class GLMoleculeObject_bond : public GLMoleculeObject, public Observer
|
---|
[907636] | 34 | {
|
---|
[06ebf5] | 35 | Q_OBJECT
|
---|
[907636] | 36 | public:
|
---|
[06ebf5] | 37 | enum SideOfBond { left, right };
|
---|
[907636] | 38 |
|
---|
[009e2e2] | 39 | typedef std::pair<atomId_t, atomId_t> bondIds_t;
|
---|
| 40 |
|
---|
[026bef] | 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);
|
---|
[2ad1ec] | 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);
|
---|
[907636] | 58 |
|
---|
[2ad1ec] | 59 | signals:
|
---|
| 60 | void BondRemoved(const atomId_t leftnr, const atomId_t rightnr);
|
---|
[009e2e2] | 61 | void elementChanged();
|
---|
| 62 | void positionChanged();
|
---|
| 63 | void degreeChanged();
|
---|
[907636] | 64 |
|
---|
[009e2e2] | 65 | private slots:
|
---|
[8c001a] | 66 | //!> grant GLMoleculeObject_molecule acess to reset functions
|
---|
| 67 | friend class GLMoleculeObject_molecule;
|
---|
[ce4126] | 68 |
|
---|
[009e2e2] | 69 | /** Recalculates the element of the cylinder representing the bond.
|
---|
| 70 | *
|
---|
| 71 | */
|
---|
| 72 | void resetElement();
|
---|
| 73 |
|
---|
[4b62d3] | 74 | /** Recalculates the position of the cylinder representing the bond.
|
---|
| 75 | *
|
---|
| 76 | */
|
---|
[343a4b] | 77 | void resetPosition();
|
---|
[4b62d3] | 78 |
|
---|
| 79 | /** Recalculates the width of the cylinder representing the bond's degree.
|
---|
| 80 | *
|
---|
| 81 | */
|
---|
| 82 | void resetWidth();
|
---|
| 83 |
|
---|
[009e2e2] | 84 | private:
|
---|
[026bef] | 85 |
|
---|
| 86 | void init();
|
---|
| 87 |
|
---|
[c60665] | 88 | void removeChannels();
|
---|
[009e2e2] | 89 |
|
---|
[099f67] | 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);
|
---|
[009e2e2] | 102 |
|
---|
| 103 | static const atom * const getAtomConst(const atomId_t _id);
|
---|
| 104 | static atom * const getAtom(const atomId_t _id);
|
---|
[c60665] | 105 |
|
---|
| 106 | private:
|
---|
[7e2adc] | 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;
|
---|
[009e2e2] | 111 | //!> temporary variable used in cstor
|
---|
[7e2adc] | 112 | const Observable * const bondowner;
|
---|
[009e2e2] | 113 |
|
---|
[2ad1ec] | 114 | const enum SideOfBond BondSide;
|
---|
[c60665] | 115 |
|
---|
[7c7c4a] | 116 |
|
---|
| 117 | private:
|
---|
| 118 | /** Observed Values **/
|
---|
| 119 |
|
---|
| 120 | //!> enumeration of observed values to match with entries in ObservedValues
|
---|
| 121 | enum ObservedTypes {
|
---|
[099f67] | 122 | //!> contains the id of the left atom
|
---|
| 123 | leftIndex,
|
---|
| 124 | //!> contains the id of the right atom
|
---|
| 125 | rightIndex,
|
---|
[7c7c4a] | 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 | *
|
---|
[099f67] | 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
|
---|
[026bef] | 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
|
---|
[7c7c4a] | 154 | */
|
---|
[099f67] | 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,
|
---|
[026bef] | 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);
|
---|
[7c7c4a] | 165 |
|
---|
| 166 | /** Destroys all \a ObservedValues entries.
|
---|
| 167 | *
|
---|
[099f67] | 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
|
---|
[7c7c4a] | 182 | */
|
---|
[099f67] | 183 | atomId_t getrightIndex() const;
|
---|
[7c7c4a] | 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 | *
|
---|
[026bef] | 221 | * \param _bondIds bond ids whose bond has called subjectKilled()
|
---|
[7c7c4a] | 222 | */
|
---|
[026bef] | 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 |
|
---|
[7c7c4a] | 235 | void countsubjectKilled();
|
---|
| 236 |
|
---|
| 237 | //!> counts how many ObservedValues have already been subjectKilled()
|
---|
| 238 | mutable size_t subjectKilledCount;
|
---|
| 239 |
|
---|
| 240 | private:
|
---|
[009e2e2] | 241 |
|
---|
[c60665] | 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;
|
---|
[009e2e2] | 246 | //!> indicate whether we are signed in to bond itself
|
---|
[c60665] | 247 | bool bond_enabled;
|
---|
[009e2e2] | 248 |
|
---|
[099f67] | 249 | //!> list of channels when id needs to update
|
---|
| 250 | static const Observable::channels_t IndexChannels;
|
---|
[009e2e2] | 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;
|
---|
[907636] | 257 | };
|
---|
| 258 |
|
---|
| 259 |
|
---|
| 260 |
|
---|
| 261 | #endif /* GLMOLECULEOBJECT_BOND_HPP_ */
|
---|