[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 |
|
---|
[9e9100] | 130 | /** Getter to molecule's selected status.
|
---|
| 131 | *
|
---|
| 132 | * \return true - molecule selected, false - else
|
---|
| 133 | */
|
---|
| 134 | const bool& getMolSelected() const;
|
---|
| 135 |
|
---|
[494478] | 136 | static const molecule * const getMolecule(const moleculeId_t _id);
|
---|
| 137 |
|
---|
[0070aa] | 138 | signals:
|
---|
[1b6415a] | 139 | void atomcountChanged();
|
---|
[5a9e34] | 140 | void bondcountChanged();
|
---|
[1b6415a] | 141 | void formulaChanged();
|
---|
[494478] | 142 | void indexChanged();
|
---|
| 143 | void nameChanged();
|
---|
[5a9e34] | 144 | void nononhydrogenChanged();
|
---|
| 145 | void centerChanged();
|
---|
[494478] | 146 | void tesselationhullChanged();
|
---|
| 147 | void boundingboxChanged();
|
---|
| 148 | void atomInserted(const atomId_t);
|
---|
| 149 | void atomRemoved(const atomId_t);
|
---|
[5a9e34] | 150 | void moleculeRemoved();
|
---|
[9e9100] | 151 | void selectedChanged();
|
---|
[494478] | 152 |
|
---|
| 153 | private:
|
---|
| 154 |
|
---|
| 155 | void activateObserver();
|
---|
| 156 | void deactivateObserver();
|
---|
| 157 |
|
---|
| 158 | private:
|
---|
[1b6415a] | 159 | static int updateAtomCount(
|
---|
| 160 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
---|
[5a9e34] | 161 | static int updateBondCount(
|
---|
| 162 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
---|
[494478] | 163 | static molecule::BoundingBoxInfo updateBoundingBox(
|
---|
| 164 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
---|
[1b6415a] | 165 | static std::string updateFormulaString(
|
---|
| 166 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
---|
[5a9e34] | 167 | static Vector updateCenter(
|
---|
| 168 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
---|
[494478] | 169 | static moleculeId_t updateIndex();
|
---|
| 170 | static std::string updateName(
|
---|
| 171 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
---|
[5a9e34] | 172 | static int updateNonHydrogenCount(
|
---|
| 173 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
---|
[9e9100] | 174 | static bool updateSelected(
|
---|
| 175 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
---|
[494478] | 176 |
|
---|
[1b6415a] | 177 | //!> list of channels when atom count needs to update
|
---|
| 178 | static const Observable::channels_t AtomCountChannels;
|
---|
[5a9e34] | 179 | //!> list of channels when bond count needs to update
|
---|
| 180 | static const Observable::channels_t BondCountChannels;
|
---|
[494478] | 181 | //!> list of channels when bounding box needs to update
|
---|
| 182 | static const Observable::channels_t BoundingBoxChannels;
|
---|
[1b6415a] | 183 | //!> list of channels when formula needs to update
|
---|
| 184 | static const Observable::channels_t FormulaStringChannels;
|
---|
[5a9e34] | 185 | //!> list of channels when the center needs to update
|
---|
| 186 | static const Observable::channels_t CenterChannels;
|
---|
[494478] | 187 | //!> list of channels when the index needs to update
|
---|
| 188 | static const Observable::channels_t IndexChannels;
|
---|
| 189 | //!> list of channels when the name needs to update
|
---|
| 190 | static const Observable::channels_t NameChannels;
|
---|
[5a9e34] | 191 | //!> list of channels when the name needs to update
|
---|
| 192 | static const Observable::channels_t NonHydrogenCountChannels;
|
---|
[9e9100] | 193 | //!> list of channels when the name needs to update
|
---|
| 194 | static const Observable::channels_t SelectedChannels;
|
---|
[494478] | 195 |
|
---|
| 196 | private:
|
---|
| 197 | /** Observed Values **/
|
---|
| 198 |
|
---|
| 199 | //!> enumeration of observed values to match with entries in ObservedValues
|
---|
| 200 | enum ObservedTypes {
|
---|
[04c3a3] | 201 | //!> contains the current molecule index
|
---|
| 202 | MolIndex,
|
---|
[1b6415a] | 203 | //!> contains the current molecule's atom count
|
---|
| 204 | AtomCount,
|
---|
[5a9e34] | 205 | //!> contains the current molecule's number of bonds
|
---|
| 206 | BondCount,
|
---|
| 207 | //!> contains newest version of the bounding box on request
|
---|
| 208 | BoundingBox,
|
---|
[1b6415a] | 209 | //!> contains the current molecule's formula
|
---|
| 210 | FormulaString,
|
---|
[5a9e34] | 211 | //!> contains the current molecule's center
|
---|
| 212 | MolCenter,
|
---|
[494478] | 213 | //!> contains the current molecule name
|
---|
| 214 | MolName,
|
---|
[5a9e34] | 215 | //!> contains the current molecule's non-hydrogen atom count
|
---|
| 216 | NonHydrogenCount,
|
---|
[9e9100] | 217 | //!> contains the current molecule's selection status
|
---|
| 218 | MolSelected,
|
---|
[494478] | 219 | //!> gives the size of the enumeration
|
---|
| 220 | MAX_ObservedTypes
|
---|
| 221 | };
|
---|
| 222 |
|
---|
| 223 | /** Initializes all \a _ObservedValues entries.
|
---|
| 224 | *
|
---|
| 225 | * \param _ObservedValues vector of ObservedValue to be filled
|
---|
| 226 | * \param _moid molecule id
|
---|
| 227 | * \param _molref reference to molecule
|
---|
| 228 | * \param _subjectKilled ref to function to call on subjectKilled()
|
---|
| 229 | */
|
---|
| 230 | static void initObservedValues(
|
---|
| 231 | ObservedValues_t &_ObservedValues,
|
---|
| 232 | const moleculeId_t _molid,
|
---|
| 233 | const molecule * const _molref,
|
---|
| 234 | const boost::function<void(const moleculeId_t)> &_subjectKilled);
|
---|
[0070aa] | 235 |
|
---|
[494478] | 236 | /** Destroys all \a ObservedValues entries.
|
---|
| 237 | *
|
---|
| 238 | * \param _ObservedValues vector of ObservedValue to be destroyed
|
---|
| 239 | */
|
---|
| 240 | static void destroyObservedValues(
|
---|
| 241 | std::vector<boost::any> &_ObservedValues);
|
---|
[0070aa] | 242 |
|
---|
[04c3a3] | 243 | /** Function is called by InstanceBoard to inform about its destruction.
|
---|
| 244 | *
|
---|
| 245 | * \note callbacks must not be used after this
|
---|
| 246 | */
|
---|
| 247 | void noteBoardIsGone()
|
---|
| 248 | { BoardIsGone = true; }
|
---|
| 249 |
|
---|
[494478] | 250 | //!> counts how many ObservedValues have already been subjectKilled()
|
---|
| 251 | mutable size_t subjectKilledCount;
|
---|
[0070aa] | 252 |
|
---|
| 253 | private:
|
---|
[494478] | 254 |
|
---|
| 255 | //!> we get multiple subjectKilled(), count and call callback() only on last
|
---|
| 256 | const unsigned int AllsignedOnChannels;
|
---|
| 257 | unsigned int signedOffChannels;
|
---|
| 258 |
|
---|
| 259 | //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
|
---|
| 260 | const Observable *owner;
|
---|
| 261 |
|
---|
| 262 | private:
|
---|
| 263 |
|
---|
| 264 | //!> reference to InstanceBoard for callbacks on subjectKilled()
|
---|
| 265 | QtObservedInstanceBoard & board;
|
---|
| 266 |
|
---|
[04c3a3] | 267 | //!> is board still alive or not, impacts callbacks
|
---|
| 268 | bool BoardIsGone;
|
---|
| 269 |
|
---|
[98c35c] | 270 | //!> internal reference to ObservedValues held by QtObservedInstanceBoard
|
---|
[494478] | 271 | ObservedValues_t ObservedValues;
|
---|
[0070aa] | 272 | };
|
---|
| 273 |
|
---|
| 274 |
|
---|
| 275 | #endif /* QTOBSERVEDMOLECULE_HPP_ */
|
---|