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