| [0070aa] | 1 | /*
|
|---|
| 2 | * QtObservedMolecule.hpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Oct 28, 2015
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 | #ifndef QTOBSERVEDMOLECULE_HPP_
|
|---|
| 10 | #define QTOBSERVEDMOLECULE_HPP_
|
|---|
| 11 |
|
|---|
| 12 | // include config.h
|
|---|
| 13 | #ifdef HAVE_CONFIG_H
|
|---|
| 14 | #include <config.h>
|
|---|
| 15 | #endif
|
|---|
| 16 |
|
|---|
| 17 | #include <QtGui/QWidget>
|
|---|
| 18 |
|
|---|
| [494478] | 19 | #include <boost/function.hpp>
|
|---|
| [98c35c] | 20 | #include <boost/shared_ptr.hpp>
|
|---|
| [0070aa] | 21 |
|
|---|
| [494478] | 22 | #include "CodePatterns/Observer/Observable.hpp"
|
|---|
| [0070aa] | 23 | #include "CodePatterns/Observer/Observer.hpp"
|
|---|
| 24 |
|
|---|
| [5a9e34] | 25 | #include "LinearAlgebra/Vector.hpp"
|
|---|
| 26 |
|
|---|
| [494478] | 27 | #include "molecule.hpp"
|
|---|
| [98c35c] | 28 | #include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
|
|---|
| [41e287] | 29 | #include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp"
|
|---|
| [0070aa] | 30 | #include "types.hpp"
|
|---|
| 31 |
|
|---|
| [98c35c] | 32 | class QtObservedInstanceBoard;
|
|---|
| 33 |
|
|---|
| [0070aa] | 34 | /** This instance is the ObservedValue representation of a World's molecule.
|
|---|
| 35 | *
|
|---|
| 36 | * Due to the signal/slot mechanism and its delays, lifetime of objects in the
|
|---|
| 37 | * World and their QtGui representation cannot directly be related (without
|
|---|
| 38 | * slowing down Actions just for having the representation up to speed).
|
|---|
| 39 | * Hence, the required information for displaying and representing these
|
|---|
| 40 | * objects must be contained in an extra instance.
|
|---|
| 41 | *
|
|---|
| 42 | * This is the instance for information about a particular molecule.
|
|---|
| 43 | */
|
|---|
| 44 | class QtObservedMolecule : public QWidget, public Observer
|
|---|
| 45 | {
|
|---|
| 46 | Q_OBJECT
|
|---|
| 47 |
|
|---|
| [494478] | 48 | public:
|
|---|
| 49 |
|
|---|
| 50 | //!> typedef for instance wrapped in shared ptr
|
|---|
| 51 | typedef boost::shared_ptr<QtObservedMolecule> ptr;
|
|---|
| 52 |
|
|---|
| 53 | private:
|
|---|
| [41e287] | 54 | //!> ObservedValuesContainer needs to access private cstor and dstor
|
|---|
| 55 | friend class ObservedValuesContainer<QtObservedMolecule, moleculeId_t>;
|
|---|
| [98c35c] | 56 | //!> QtObservedInstanceBoard needs to access private cstor and dstor
|
|---|
| 57 | friend class QtObservedInstanceBoard;
|
|---|
| 58 |
|
|---|
| [0070aa] | 59 | /** Cstor of QtObservedMolecule.
|
|---|
| 60 | *
|
|---|
| [494478] | 61 | * \param _ObservedValues ref to set of observed values for this instance
|
|---|
| 62 | * \param _board ref to InstanceBoard for callbacks on occasion of subjectKilled()
|
|---|
| [0070aa] | 63 | * \param _parent Qt parent to automatically destroy when parent is destroyed
|
|---|
| 64 | */
|
|---|
| [98c35c] | 65 | QtObservedMolecule(
|
|---|
| [494478] | 66 | const ObservedValues_t &_ObservedValues,
|
|---|
| 67 | QtObservedInstanceBoard &_board,
|
|---|
| [98c35c] | 68 | QWidget * _parent=0);
|
|---|
| 69 |
|
|---|
| 70 | public:
|
|---|
| [0070aa] | 71 |
|
|---|
| 72 | /** Dstor of QtObservedMolecule.
|
|---|
| 73 | *
|
|---|
| 74 | */
|
|---|
| 75 | ~QtObservedMolecule();
|
|---|
| 76 |
|
|---|
| [98c35c] | 77 | // Observer functions
|
|---|
| 78 | void update(Observable *publisher);
|
|---|
| 79 | void subjectKilled(Observable *publisher);
|
|---|
| 80 | void recieveNotification(Observable *publisher, Notification_ptr notification);
|
|---|
| 81 |
|
|---|
| [1b6415a] | 82 | /** Getter to molecule atom count contained in \a ObservedValues.
|
|---|
| 83 | *
|
|---|
| 84 | * \return molecule's atom count
|
|---|
| 85 | */
|
|---|
| [3b9aa1] | 86 | const int& getAtomCount() const;
|
|---|
| [1b6415a] | 87 |
|
|---|
| [5a9e34] | 88 | /** Getter to molecule bond count contained in \a ObservedValues.
|
|---|
| 89 | *
|
|---|
| 90 | * \return molecule's bond count
|
|---|
| 91 | */
|
|---|
| [3b9aa1] | 92 | const int& getBondCount() const;
|
|---|
| [5a9e34] | 93 |
|
|---|
| 94 | /** Getter to molecule center contained in \a ObservedValues.
|
|---|
| 95 | *
|
|---|
| 96 | * \return molecule's center
|
|---|
| 97 | */
|
|---|
| [3b9aa1] | 98 | const Vector& getMolCenter() const;
|
|---|
| [5a9e34] | 99 |
|
|---|
| [494478] | 100 | /** Getter to molecule index contained in \a ObservedValues.
|
|---|
| 101 | *
|
|---|
| 102 | * \return molecule's index
|
|---|
| 103 | */
|
|---|
| [3b9aa1] | 104 | const moleculeId_t& getMolIndex() const;
|
|---|
| [494478] | 105 |
|
|---|
| 106 | /** Getter to molecule name contained in \a ObservedValues.
|
|---|
| 107 | *
|
|---|
| 108 | * \return molecule's name
|
|---|
| 109 | */
|
|---|
| [3b9aa1] | 110 | const std::string& getMolName() const;
|
|---|
| [494478] | 111 |
|
|---|
| [1b6415a] | 112 | /** Getter to molecule formula contained in \a ObservedValues.
|
|---|
| 113 | *
|
|---|
| 114 | * \return molecule's formula
|
|---|
| 115 | */
|
|---|
| [3b9aa1] | 116 | const std::string& getMolFormula() const;
|
|---|
| [1b6415a] | 117 |
|
|---|
| [5a9e34] | 118 | /** Getter to molecule non-hydrogen atom count contained in \a ObservedValues.
|
|---|
| 119 | *
|
|---|
| 120 | * \return molecule's non-hydrogen atom count
|
|---|
| 121 | */
|
|---|
| [3b9aa1] | 122 | const int& getNonHydrogenCount() const;
|
|---|
| [5a9e34] | 123 |
|
|---|
| [494478] | 124 | /** Getter to molecule's bounding box contained in \a ObservedValues.
|
|---|
| 125 | *
|
|---|
| 126 | * \return molecule's bounding box
|
|---|
| 127 | */
|
|---|
| [3b9aa1] | 128 | const molecule::BoundingBoxInfo& getBoundingBox() const;
|
|---|
| [494478] | 129 |
|
|---|
| 130 | static const molecule * const getMolecule(const moleculeId_t _id);
|
|---|
| 131 |
|
|---|
| [0070aa] | 132 | signals:
|
|---|
| [1b6415a] | 133 | void atomcountChanged();
|
|---|
| [5a9e34] | 134 | void bondcountChanged();
|
|---|
| [1b6415a] | 135 | void formulaChanged();
|
|---|
| [494478] | 136 | void indexChanged();
|
|---|
| 137 | void nameChanged();
|
|---|
| [5a9e34] | 138 | void nononhydrogenChanged();
|
|---|
| 139 | void centerChanged();
|
|---|
| [494478] | 140 | void tesselationhullChanged();
|
|---|
| 141 | void boundingboxChanged();
|
|---|
| 142 | void atomInserted(const atomId_t);
|
|---|
| 143 | void atomRemoved(const atomId_t);
|
|---|
| [5a9e34] | 144 | void moleculeRemoved();
|
|---|
| [494478] | 145 |
|
|---|
| 146 | private:
|
|---|
| 147 |
|
|---|
| 148 | void activateObserver();
|
|---|
| 149 | void deactivateObserver();
|
|---|
| 150 |
|
|---|
| 151 | private:
|
|---|
| [1b6415a] | 152 | static int updateAtomCount(
|
|---|
| 153 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
|---|
| [5a9e34] | 154 | static int updateBondCount(
|
|---|
| 155 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
|---|
| [494478] | 156 | static molecule::BoundingBoxInfo updateBoundingBox(
|
|---|
| 157 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
|---|
| [1b6415a] | 158 | static std::string updateFormulaString(
|
|---|
| 159 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
|---|
| [5a9e34] | 160 | static Vector updateCenter(
|
|---|
| 161 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
|---|
| [494478] | 162 | static moleculeId_t updateIndex();
|
|---|
| 163 | static std::string updateName(
|
|---|
| 164 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
|---|
| [5a9e34] | 165 | static int updateNonHydrogenCount(
|
|---|
| 166 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
|---|
| [494478] | 167 |
|
|---|
| [1b6415a] | 168 | //!> list of channels when atom count needs to update
|
|---|
| 169 | static const Observable::channels_t AtomCountChannels;
|
|---|
| [5a9e34] | 170 | //!> list of channels when bond count needs to update
|
|---|
| 171 | static const Observable::channels_t BondCountChannels;
|
|---|
| [494478] | 172 | //!> list of channels when bounding box needs to update
|
|---|
| 173 | static const Observable::channels_t BoundingBoxChannels;
|
|---|
| [1b6415a] | 174 | //!> list of channels when formula needs to update
|
|---|
| 175 | static const Observable::channels_t FormulaStringChannels;
|
|---|
| [5a9e34] | 176 | //!> list of channels when the center needs to update
|
|---|
| 177 | static const Observable::channels_t CenterChannels;
|
|---|
| [494478] | 178 | //!> list of channels when the index needs to update
|
|---|
| 179 | static const Observable::channels_t IndexChannels;
|
|---|
| 180 | //!> list of channels when the name needs to update
|
|---|
| 181 | static const Observable::channels_t NameChannels;
|
|---|
| [5a9e34] | 182 | //!> list of channels when the name needs to update
|
|---|
| 183 | static const Observable::channels_t NonHydrogenCountChannels;
|
|---|
| [494478] | 184 |
|
|---|
| 185 | private:
|
|---|
| 186 | /** Observed Values **/
|
|---|
| 187 |
|
|---|
| 188 | //!> enumeration of observed values to match with entries in ObservedValues
|
|---|
| 189 | enum ObservedTypes {
|
|---|
| [04c3a3] | 190 | //!> contains the current molecule index
|
|---|
| 191 | MolIndex,
|
|---|
| [1b6415a] | 192 | //!> contains the current molecule's atom count
|
|---|
| 193 | AtomCount,
|
|---|
| [5a9e34] | 194 | //!> contains the current molecule's number of bonds
|
|---|
| 195 | BondCount,
|
|---|
| 196 | //!> contains newest version of the bounding box on request
|
|---|
| 197 | BoundingBox,
|
|---|
| [1b6415a] | 198 | //!> contains the current molecule's formula
|
|---|
| 199 | FormulaString,
|
|---|
| [5a9e34] | 200 | //!> contains the current molecule's center
|
|---|
| 201 | MolCenter,
|
|---|
| [494478] | 202 | //!> contains the current molecule name
|
|---|
| 203 | MolName,
|
|---|
| [5a9e34] | 204 | //!> contains the current molecule's non-hydrogen atom count
|
|---|
| 205 | NonHydrogenCount,
|
|---|
| [494478] | 206 | //!> gives the size of the enumeration
|
|---|
| 207 | MAX_ObservedTypes
|
|---|
| 208 | };
|
|---|
| 209 |
|
|---|
| 210 | /** Initializes all \a _ObservedValues entries.
|
|---|
| 211 | *
|
|---|
| 212 | * \param _ObservedValues vector of ObservedValue to be filled
|
|---|
| 213 | * \param _moid molecule id
|
|---|
| 214 | * \param _molref reference to molecule
|
|---|
| 215 | * \param _subjectKilled ref to function to call on subjectKilled()
|
|---|
| 216 | */
|
|---|
| 217 | static void initObservedValues(
|
|---|
| 218 | ObservedValues_t &_ObservedValues,
|
|---|
| 219 | const moleculeId_t _molid,
|
|---|
| 220 | const molecule * const _molref,
|
|---|
| 221 | const boost::function<void(const moleculeId_t)> &_subjectKilled);
|
|---|
| [0070aa] | 222 |
|
|---|
| [494478] | 223 | /** Destroys all \a ObservedValues entries.
|
|---|
| 224 | *
|
|---|
| 225 | * \param _ObservedValues vector of ObservedValue to be destroyed
|
|---|
| 226 | */
|
|---|
| 227 | static void destroyObservedValues(
|
|---|
| 228 | std::vector<boost::any> &_ObservedValues);
|
|---|
| [0070aa] | 229 |
|
|---|
| [04c3a3] | 230 | /** Function is called by InstanceBoard to inform about its destruction.
|
|---|
| 231 | *
|
|---|
| 232 | * \note callbacks must not be used after this
|
|---|
| 233 | */
|
|---|
| 234 | void noteBoardIsGone()
|
|---|
| 235 | { BoardIsGone = true; }
|
|---|
| 236 |
|
|---|
| [494478] | 237 | //!> counts how many ObservedValues have already been subjectKilled()
|
|---|
| 238 | mutable size_t subjectKilledCount;
|
|---|
| [0070aa] | 239 |
|
|---|
| 240 | private:
|
|---|
| [494478] | 241 |
|
|---|
| 242 | //!> we get multiple subjectKilled(), count and call callback() only on last
|
|---|
| 243 | const unsigned int AllsignedOnChannels;
|
|---|
| 244 | unsigned int signedOffChannels;
|
|---|
| 245 |
|
|---|
| 246 | //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
|
|---|
| 247 | const Observable *owner;
|
|---|
| 248 |
|
|---|
| 249 | private:
|
|---|
| 250 |
|
|---|
| 251 | //!> reference to InstanceBoard for callbacks on subjectKilled()
|
|---|
| 252 | QtObservedInstanceBoard & board;
|
|---|
| 253 |
|
|---|
| [04c3a3] | 254 | //!> is board still alive or not, impacts callbacks
|
|---|
| 255 | bool BoardIsGone;
|
|---|
| 256 |
|
|---|
| [98c35c] | 257 | //!> internal reference to ObservedValues held by QtObservedInstanceBoard
|
|---|
| [494478] | 258 | ObservedValues_t ObservedValues;
|
|---|
| [0070aa] | 259 | };
|
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 | #endif /* QTOBSERVEDMOLECULE_HPP_ */
|
|---|