| [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 |
|
|---|
| [494478] | 25 | #include "molecule.hpp"
|
|---|
| [98c35c] | 26 | #include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
|
|---|
| [41e287] | 27 | #include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp"
|
|---|
| [0070aa] | 28 | #include "types.hpp"
|
|---|
| 29 |
|
|---|
| [98c35c] | 30 | class QtObservedInstanceBoard;
|
|---|
| 31 |
|
|---|
| [0070aa] | 32 | /** This instance is the ObservedValue representation of a World's molecule.
|
|---|
| 33 | *
|
|---|
| 34 | * Due to the signal/slot mechanism and its delays, lifetime of objects in the
|
|---|
| 35 | * World and their QtGui representation cannot directly be related (without
|
|---|
| 36 | * slowing down Actions just for having the representation up to speed).
|
|---|
| 37 | * Hence, the required information for displaying and representing these
|
|---|
| 38 | * objects must be contained in an extra instance.
|
|---|
| 39 | *
|
|---|
| 40 | * This is the instance for information about a particular molecule.
|
|---|
| 41 | */
|
|---|
| 42 | class QtObservedMolecule : public QWidget, public Observer
|
|---|
| 43 | {
|
|---|
| 44 | Q_OBJECT
|
|---|
| 45 |
|
|---|
| [494478] | 46 | public:
|
|---|
| 47 |
|
|---|
| 48 | //!> typedef for instance wrapped in shared ptr
|
|---|
| 49 | typedef boost::shared_ptr<QtObservedMolecule> ptr;
|
|---|
| 50 |
|
|---|
| 51 | private:
|
|---|
| [41e287] | 52 | //!> ObservedValuesContainer needs to access private cstor and dstor
|
|---|
| 53 | friend class ObservedValuesContainer<QtObservedMolecule, moleculeId_t>;
|
|---|
| [98c35c] | 54 | //!> QtObservedInstanceBoard needs to access private cstor and dstor
|
|---|
| 55 | friend class QtObservedInstanceBoard;
|
|---|
| 56 |
|
|---|
| [0070aa] | 57 | /** Cstor of QtObservedMolecule.
|
|---|
| 58 | *
|
|---|
| [494478] | 59 | * \param _ObservedValues ref to set of observed values for this instance
|
|---|
| 60 | * \param _board ref to InstanceBoard for callbacks on occasion of subjectKilled()
|
|---|
| [0070aa] | 61 | * \param _parent Qt parent to automatically destroy when parent is destroyed
|
|---|
| 62 | */
|
|---|
| [98c35c] | 63 | QtObservedMolecule(
|
|---|
| [494478] | 64 | const ObservedValues_t &_ObservedValues,
|
|---|
| 65 | QtObservedInstanceBoard &_board,
|
|---|
| [98c35c] | 66 | QWidget * _parent=0);
|
|---|
| 67 |
|
|---|
| 68 | public:
|
|---|
| [0070aa] | 69 |
|
|---|
| 70 | /** Dstor of QtObservedMolecule.
|
|---|
| 71 | *
|
|---|
| 72 | */
|
|---|
| 73 | ~QtObservedMolecule();
|
|---|
| 74 |
|
|---|
| [98c35c] | 75 | // Observer functions
|
|---|
| 76 | void update(Observable *publisher);
|
|---|
| 77 | void subjectKilled(Observable *publisher);
|
|---|
| 78 | void recieveNotification(Observable *publisher, Notification_ptr notification);
|
|---|
| 79 |
|
|---|
| [494478] | 80 | /** Getter to molecule index contained in \a ObservedValues.
|
|---|
| 81 | *
|
|---|
| 82 | * \return molecule's index
|
|---|
| 83 | */
|
|---|
| 84 | moleculeId_t getMolIndex() const;
|
|---|
| 85 |
|
|---|
| 86 | /** Getter to molecule name contained in \a ObservedValues.
|
|---|
| 87 | *
|
|---|
| 88 | * \return molecule's name
|
|---|
| 89 | */
|
|---|
| 90 | std::string getMolName() const;
|
|---|
| 91 |
|
|---|
| 92 | /** Getter to molecule's bounding box contained in \a ObservedValues.
|
|---|
| 93 | *
|
|---|
| 94 | * \return molecule's bounding box
|
|---|
| 95 | */
|
|---|
| 96 | molecule::BoundingBoxInfo getBoundingBox() const;
|
|---|
| 97 |
|
|---|
| 98 | static const molecule * const getMolecule(const moleculeId_t _id);
|
|---|
| 99 |
|
|---|
| [0070aa] | 100 | signals:
|
|---|
| [494478] | 101 | void indexChanged();
|
|---|
| 102 | void nameChanged();
|
|---|
| 103 | void tesselationhullChanged();
|
|---|
| 104 | void boundingboxChanged();
|
|---|
| 105 | void atomInserted(const atomId_t);
|
|---|
| 106 | void atomRemoved(const atomId_t);
|
|---|
| 107 |
|
|---|
| 108 | private:
|
|---|
| 109 |
|
|---|
| 110 | void activateObserver();
|
|---|
| 111 | void deactivateObserver();
|
|---|
| 112 |
|
|---|
| 113 | private:
|
|---|
| 114 | static molecule::BoundingBoxInfo updateBoundingBox(
|
|---|
| 115 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
|---|
| 116 | static moleculeId_t updateIndex();
|
|---|
| 117 | static std::string updateName(
|
|---|
| 118 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
|---|
| 119 |
|
|---|
| 120 | //!> list of channels when bounding box needs to update
|
|---|
| 121 | static const Observable::channels_t BoundingBoxChannels;
|
|---|
| 122 | //!> list of channels when the index needs to update
|
|---|
| 123 | static const Observable::channels_t IndexChannels;
|
|---|
| 124 | //!> list of channels when the name needs to update
|
|---|
| 125 | static const Observable::channels_t NameChannels;
|
|---|
| 126 |
|
|---|
| 127 | private:
|
|---|
| 128 | /** Observed Values **/
|
|---|
| 129 |
|
|---|
| 130 | //!> enumeration of observed values to match with entries in ObservedValues
|
|---|
| 131 | enum ObservedTypes {
|
|---|
| 132 | //!> contains the current molecule index
|
|---|
| 133 | MolIndex,
|
|---|
| 134 | //!> contains the current molecule name
|
|---|
| 135 | MolName,
|
|---|
| 136 | //!> contains newest version of the bounding box on request
|
|---|
| 137 | BoundingBox,
|
|---|
| 138 | //!> gives the size of the enumeration
|
|---|
| 139 | MAX_ObservedTypes
|
|---|
| 140 | };
|
|---|
| 141 |
|
|---|
| 142 | /** Initializes all \a _ObservedValues entries.
|
|---|
| 143 | *
|
|---|
| 144 | * \param _ObservedValues vector of ObservedValue to be filled
|
|---|
| 145 | * \param _moid molecule id
|
|---|
| 146 | * \param _molref reference to molecule
|
|---|
| 147 | * \param _subjectKilled ref to function to call on subjectKilled()
|
|---|
| 148 | */
|
|---|
| 149 | static void initObservedValues(
|
|---|
| 150 | ObservedValues_t &_ObservedValues,
|
|---|
| 151 | const moleculeId_t _molid,
|
|---|
| 152 | const molecule * const _molref,
|
|---|
| 153 | const boost::function<void(const moleculeId_t)> &_subjectKilled);
|
|---|
| [0070aa] | 154 |
|
|---|
| [494478] | 155 | /** Destroys all \a ObservedValues entries.
|
|---|
| 156 | *
|
|---|
| 157 | * \param _ObservedValues vector of ObservedValue to be destroyed
|
|---|
| 158 | */
|
|---|
| 159 | static void destroyObservedValues(
|
|---|
| 160 | std::vector<boost::any> &_ObservedValues);
|
|---|
| [0070aa] | 161 |
|
|---|
| [494478] | 162 | //!> counts how many ObservedValues have already been subjectKilled()
|
|---|
| 163 | mutable size_t subjectKilledCount;
|
|---|
| [0070aa] | 164 |
|
|---|
| 165 | private:
|
|---|
| [494478] | 166 |
|
|---|
| 167 | //!> we get multiple subjectKilled(), count and call callback() only on last
|
|---|
| 168 | const unsigned int AllsignedOnChannels;
|
|---|
| 169 | unsigned int signedOffChannels;
|
|---|
| 170 |
|
|---|
| 171 | //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
|
|---|
| 172 | const Observable *owner;
|
|---|
| 173 |
|
|---|
| 174 | private:
|
|---|
| 175 |
|
|---|
| 176 | //!> reference to InstanceBoard for callbacks on subjectKilled()
|
|---|
| 177 | QtObservedInstanceBoard & board;
|
|---|
| 178 |
|
|---|
| [98c35c] | 179 | //!> internal reference to ObservedValues held by QtObservedInstanceBoard
|
|---|
| [494478] | 180 | ObservedValues_t ObservedValues;
|
|---|
| [0070aa] | 181 | };
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 | #endif /* QTOBSERVEDMOLECULE_HPP_ */
|
|---|