[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 |
|
---|
| 41 | GLMoleculeObject_bond(QGLSceneNode *mesh[], QObject *parent, const bondIds_t bondIds, const enum SideOfBond side);
|
---|
[2ad1ec] | 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);
|
---|
[907636] | 48 |
|
---|
[2ad1ec] | 49 | signals:
|
---|
| 50 | void BondRemoved(const atomId_t leftnr, const atomId_t rightnr);
|
---|
[009e2e2] | 51 | void elementChanged();
|
---|
| 52 | void positionChanged();
|
---|
| 53 | void degreeChanged();
|
---|
[907636] | 54 |
|
---|
[009e2e2] | 55 | private slots:
|
---|
[8c001a] | 56 | //!> grant GLMoleculeObject_molecule acess to reset functions
|
---|
| 57 | friend class GLMoleculeObject_molecule;
|
---|
[ce4126] | 58 |
|
---|
[009e2e2] | 59 | /** Recalculates the element of the cylinder representing the bond.
|
---|
| 60 | *
|
---|
| 61 | */
|
---|
| 62 | void resetElement();
|
---|
| 63 |
|
---|
[4b62d3] | 64 | /** Recalculates the position of the cylinder representing the bond.
|
---|
| 65 | *
|
---|
| 66 | */
|
---|
[343a4b] | 67 | void resetPosition();
|
---|
[4b62d3] | 68 |
|
---|
| 69 | /** Recalculates the width of the cylinder representing the bond's degree.
|
---|
| 70 | *
|
---|
| 71 | */
|
---|
| 72 | void resetWidth();
|
---|
| 73 |
|
---|
[009e2e2] | 74 | private:
|
---|
[c60665] | 75 | void removeChannels();
|
---|
[009e2e2] | 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);
|
---|
[c60665] | 85 |
|
---|
| 86 | private:
|
---|
[009e2e2] | 87 | //!> id of left bond partner for safely emitting BondRemoved signal
|
---|
[70db8f] | 88 | const atomId_t leftatomId;
|
---|
[009e2e2] | 89 | //!> id of right bond partner for safely emitting BondRemoved signal
|
---|
[70db8f] | 90 | const atomId_t rightatomId;
|
---|
[009e2e2] | 91 |
|
---|
[7e2adc] | 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;
|
---|
[009e2e2] | 96 | //!> temporary variable used in cstor
|
---|
[7e2adc] | 97 | const Observable * const bondowner;
|
---|
[009e2e2] | 98 |
|
---|
[2ad1ec] | 99 | const enum SideOfBond BondSide;
|
---|
[c60665] | 100 |
|
---|
[7c7c4a] | 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:
|
---|
[009e2e2] | 177 |
|
---|
[c60665] | 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;
|
---|
[009e2e2] | 182 | //!> indicate whether we are signed in to bond itself
|
---|
[c60665] | 183 | bool bond_enabled;
|
---|
[009e2e2] | 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;
|
---|
[907636] | 191 | };
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 |
|
---|
| 195 | #endif /* GLMOLECULEOBJECT_BOND_HPP_ */
|
---|