[907636] | 1 | /*
|
---|
| 2 | * GLMoleculeObject_atom.hpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Aug 17, 2011
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #ifndef GLMOLECULEOBJECT_ATOM_HPP_
|
---|
| 9 | #define GLMOLECULEOBJECT_ATOM_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 |
|
---|
[534374] | 21 | #include "CodePatterns/ObservedValue.hpp"
|
---|
[02ce36] | 22 | #include "CodePatterns/Observer/Observer.hpp"
|
---|
[7188b1] | 23 |
|
---|
[534374] | 24 | #include "LinearAlgebra/Vector.hpp"
|
---|
| 25 |
|
---|
[88c8ec] | 26 | #include "Bond/bond.hpp"
|
---|
[917659] | 27 | #include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp"
|
---|
| 28 | #include "types.hpp"
|
---|
[907636] | 29 |
|
---|
[ce4126] | 30 | class GLWorldScene;
|
---|
[2f7988] | 31 | class QtObservedInstanceBoard;
|
---|
[ce4126] | 32 |
|
---|
[534374] | 33 | class GLMoleculeObject_atom : public GLMoleculeObject, Observer
|
---|
[907636] | 34 | {
|
---|
[06ebf5] | 35 | Q_OBJECT
|
---|
[907636] | 36 | public:
|
---|
[026bef] | 37 | GLMoleculeObject_atom(
|
---|
| 38 | QGLSceneNode *mesh[],
|
---|
| 39 | QObject *parent,
|
---|
| 40 | const atomId_t id,
|
---|
[2f7988] | 41 | QtObservedInstanceBoard * _board,
|
---|
[026bef] | 42 | std::vector<boost::any> _ObservedValues
|
---|
| 43 | );
|
---|
[9c18e4] | 44 | virtual ~GLMoleculeObject_atom();
|
---|
[7188b1] | 45 |
|
---|
[f115cc] | 46 | void draw(QGLPainter *painter, const QVector4D &cameraPlane);
|
---|
| 47 |
|
---|
[7188b1] | 48 | // Observer functions
|
---|
| 49 | void update(Observable *publisher);
|
---|
| 50 | void subjectKilled(Observable *publisher);
|
---|
| 51 | void recieveNotification(Observable *publisher, Notification_ptr notification);
|
---|
[06ebf5] | 52 |
|
---|
[015f8c] | 53 | public slots:
|
---|
| 54 | void Selected();
|
---|
| 55 | void Unselected();
|
---|
| 56 |
|
---|
[06ebf5] | 57 | private slots:
|
---|
| 58 | void wasClicked();
|
---|
[534374] | 59 | void resetIndex();
|
---|
| 60 | void resetElement();
|
---|
| 61 | void resetPosition();
|
---|
| 62 | void resetBonds();
|
---|
[06ebf5] | 63 |
|
---|
| 64 | signals:
|
---|
| 65 | void clicked(atomId_t);
|
---|
[534374] | 66 | void BondsAdded(const atomId_t _left, const atomId_t _right, const GLMoleculeObject_bond::SideOfBond side);
|
---|
| 67 | void BondsRemoved(const atomId_t _left, const atomId_t _right);
|
---|
| 68 | void indexChanged(GLMoleculeObject_atom *ob, const atomId_t oldId, const atomId_t newId);
|
---|
| 69 | void idChanged();
|
---|
| 70 | void positionChanged();
|
---|
| 71 | void elementChanged();
|
---|
| 72 | void bondsChanged();
|
---|
[907636] | 73 |
|
---|
[ce4126] | 74 | private:
|
---|
[8c001a] | 75 | //!> grant GLMoleculeObject_molecule acess to reset functions
|
---|
| 76 | friend class GLMoleculeObject_molecule;
|
---|
[ce4126] | 77 |
|
---|
[534374] | 78 | //!> typedef for list of bonds, defined by pairs of atom ids
|
---|
| 79 | typedef std::vector< std::pair<atomId_t, atomId_t> > ListOfBonds_t;
|
---|
[89b992] | 80 |
|
---|
[534374] | 81 | static const atom * const getAtomConst(const atomId_t _id);
|
---|
| 82 | static atom * const getAtom(const atomId_t _id);
|
---|
| 83 |
|
---|
[16bd37] | 84 | static atomId_t updateIndex();
|
---|
| 85 | static Vector updatePosition(
|
---|
| 86 | const boost::function<const atomId_t ()> &_getAtomIndex);
|
---|
| 87 | static atomicNumber_t updateElement(
|
---|
| 88 | const boost::function<const atomId_t ()> &_getAtomIndex);
|
---|
| 89 | static ListOfBonds_t updateBonds(
|
---|
| 90 | const boost::function<const atomId_t ()> &_getAtomIndex);
|
---|
[7188b1] | 91 |
|
---|
[534374] | 92 | void activateObserver();
|
---|
| 93 | void deactivateObserver();
|
---|
| 94 |
|
---|
[026bef] | 95 | void init(const atomId_t _id);
|
---|
| 96 |
|
---|
[534374] | 97 | private:
|
---|
[f115cc] | 98 |
|
---|
[534374] | 99 | //!> current list of bonds to compare new onw against for changes
|
---|
| 100 | ListOfBonds_t ListOfBonds;
|
---|
| 101 |
|
---|
| 102 | //!> temporary variable used in cstor
|
---|
| 103 | atom * const atomref;
|
---|
| 104 |
|
---|
[7c7c4a] | 105 | private:
|
---|
[2f7988] | 106 | friend class QtObservedInstanceBoard;
|
---|
[7c7c4a] | 107 | /** Observed Values **/
|
---|
| 108 |
|
---|
| 109 | //!> enumeration of observed values to match with entries in ObservedValues
|
---|
| 110 | enum ObservedTypes {
|
---|
| 111 | //!> contains the current atom index
|
---|
| 112 | AtomIndex,
|
---|
| 113 | //!> contains the current atom position
|
---|
| 114 | AtomPosition,
|
---|
| 115 | //!> contains the current atom element
|
---|
| 116 | AtomElement,
|
---|
| 117 | //!> contains the current set of bonds atoms fort the atom
|
---|
| 118 | AtomBonds,
|
---|
| 119 | //!> gives the size of the enumeration
|
---|
| 120 | MAX_ObservedTypes
|
---|
| 121 | };
|
---|
| 122 |
|
---|
| 123 | //!> vector with all observed values
|
---|
| 124 | std::vector<boost::any> ObservedValues;
|
---|
| 125 |
|
---|
| 126 | /** Initializes all \a ObservedValues entries.
|
---|
| 127 | *
|
---|
[16bd37] | 128 | * \param _ObservedValues vector of ObservedValue to be filled
|
---|
[7c7c4a] | 129 | * \param _id atom id
|
---|
[16bd37] | 130 | * \param _atomref reference to atom
|
---|
| 131 | * \param _subjectKilled ref to function to call on subjectKilled()
|
---|
[7c7c4a] | 132 | */
|
---|
[16bd37] | 133 | static void initObservedValues(
|
---|
| 134 | std::vector<boost::any> &_ObservedValues,
|
---|
| 135 | const atomId_t _id,
|
---|
| 136 | const atom * const _atomref,
|
---|
[026bef] | 137 | const boost::function<void(const atomId_t)> &_subjectKilled);
|
---|
[7c7c4a] | 138 |
|
---|
| 139 | /** Destroys all \a ObservedValues entries.
|
---|
| 140 | *
|
---|
[16bd37] | 141 | * \param _ObservedValues vector of ObservedValue to be destroyed
|
---|
[7c7c4a] | 142 | */
|
---|
[16bd37] | 143 | static void destroyObservedValues(
|
---|
| 144 | std::vector<boost::any> &_ObservedValues);
|
---|
[7c7c4a] | 145 |
|
---|
| 146 | /** Getter to atom index contained in \a ObservedValues.
|
---|
| 147 | *
|
---|
| 148 | * \return atom's index
|
---|
| 149 | */
|
---|
| 150 | atomId_t getAtomIndex() const;
|
---|
| 151 |
|
---|
| 152 | /** Getter to atom position contained in \a ObservedValues.
|
---|
| 153 | *
|
---|
| 154 | * \return atom's position
|
---|
| 155 | */
|
---|
| 156 | Vector getAtomPosition() const;
|
---|
| 157 |
|
---|
| 158 | /** Getter to atom element contained in \a ObservedValues.
|
---|
| 159 | *
|
---|
| 160 | * \return atom's elemnt
|
---|
| 161 | */
|
---|
| 162 | atomicNumber_t getAtomElement() const;
|
---|
| 163 |
|
---|
| 164 | /** Getter to atom bonds contained in \a ObservedValues.
|
---|
| 165 | *
|
---|
| 166 | * \return atom's bonds
|
---|
| 167 | */
|
---|
| 168 | ListOfBonds_t getAtomBonds() const;
|
---|
| 169 |
|
---|
| 170 | //!> counts how many ObservedValues have already been subjectKilled()
|
---|
| 171 | mutable size_t subjectKilledCount;
|
---|
| 172 |
|
---|
| 173 | private:
|
---|
[534374] | 174 |
|
---|
| 175 | //!> list of channels when index needs to update
|
---|
| 176 | static const Observable::channels_t AtomIndexChannels;
|
---|
| 177 | //!> list of channels when position needs to update
|
---|
| 178 | static const Observable::channels_t AtomPositionChannels;
|
---|
| 179 | //!> list of channels when element needs to update
|
---|
| 180 | static const Observable::channels_t AtomElementChannels;
|
---|
| 181 | //!> list of channels when bonds needs to update
|
---|
| 182 | static const Observable::channels_t AtomBondsChannels;
|
---|
| 183 |
|
---|
| 184 | //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
|
---|
| 185 | const Observable *owner;
|
---|
[8d5fbf1] | 186 |
|
---|
| 187 | //!> we get multiple subjectKilled(), count and call callback() only on last
|
---|
| 188 | const unsigned int AllsignedOnChannels;
|
---|
| 189 | unsigned int signedOnChannels;
|
---|
| 190 |
|
---|
[2f7988] | 191 | QtObservedInstanceBoard * board;
|
---|
[907636] | 192 | };
|
---|
| 193 |
|
---|
| 194 |
|
---|
| 195 |
|
---|
| 196 | #endif /* GLMOLECULEOBJECT_ATOM_HPP_ */
|
---|