[15c8a9] | 1 | /*
|
---|
[2f7988] | 2 | * QtObservedInstanceBoard.hpp
|
---|
[15c8a9] | 3 | *
|
---|
| 4 | * Created on: Oct 17, 2015
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 |
|
---|
[2f7988] | 9 | #ifndef QTOBSERVEDINSTANCEBOARD_HPP_
|
---|
| 10 | #define QTOBSERVEDINSTANCEBOARD_HPP_
|
---|
[15c8a9] | 11 |
|
---|
| 12 | // include config.h
|
---|
| 13 | #ifdef HAVE_CONFIG_H
|
---|
| 14 | #include <config.h>
|
---|
| 15 | #endif
|
---|
| 16 |
|
---|
| 17 | #include <QtGui/QWidget>
|
---|
| 18 |
|
---|
[98c35c] | 19 | #include "UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp"
|
---|
| 20 | #include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp"
|
---|
[15c8a9] | 21 |
|
---|
[98c35c] | 22 | #include <map>
|
---|
| 23 | #include <boost/function.hpp>
|
---|
[15c8a9] | 24 |
|
---|
| 25 | #include "CodePatterns/Observer/Observer.hpp"
|
---|
| 26 |
|
---|
[98c35c] | 27 | #include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
|
---|
[41e287] | 28 | #include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp"
|
---|
[15c8a9] | 29 | #include "types.hpp"
|
---|
| 30 |
|
---|
| 31 | class GLWorldScene;
|
---|
| 32 | class GLMoleculeObject_bond;
|
---|
| 33 | class GLMoleculeObject_molecule;
|
---|
| 34 |
|
---|
[2f7988] | 35 | /** The QtObservedInstanceBoard is the central class for communicating instance
|
---|
[15c8a9] | 36 | * creation and destruction from MoleCuilder into the QtGui realm. It should be
|
---|
| 37 | * thought of as an interface to allow for safe multi-threaded computing.
|
---|
| 38 | *
|
---|
| 39 | * The idea is as follows: As soon as a molecule is instantiated, all the QtGui
|
---|
| 40 | * needs to access the instance (for displaying it) is wrapped up in a
|
---|
| 41 | * ObservedValue. This ObservedValue separates the lifetime of the molecule object
|
---|
| 42 | * from the information contained therein and thus makes the visual representation
|
---|
| 43 | * independent of the life time. The Observer/Observable signal from the World,
|
---|
| 44 | * i.e. World::MoleculeInserted, is caught (directly within the same thread) by
|
---|
[2f7988] | 45 | * the QtObservedInstanceBoard. Here, we instantiate all ObservedValue's needed
|
---|
[15c8a9] | 46 | * for this specific molecule and store them in an internal map. Next, we emit
|
---|
| 47 | * a Qt signal informing the QtGui part about the new molecule.
|
---|
| 48 | * At some later stage, the QtGui will (probably in a different thread)
|
---|
| 49 | * instantiate a GLMoleculeObject_molecule as a visual representation of the
|
---|
[2f7988] | 50 | * molecule. It requests the ObservedValues from the QtObservedInstanceBoard
|
---|
[15c8a9] | 51 | * and uses these directly.
|
---|
[2f7988] | 52 | * The QtObservedInstanceBoard also records all subjectKilled() signals from
|
---|
[15c8a9] | 53 | * each ObservedValue. Additionally, each class using the ObservedValues
|
---|
[2f7988] | 54 | * additionally informs the QtObservedInstanceBoard when subjectKilled() was
|
---|
[15c8a9] | 55 | * called. If subjectKilled() for each ObservedValue of a molecule and from the
|
---|
| 56 | * visual representation have been received, a removal Qt signal is emitted.
|
---|
| 57 | *
|
---|
| 58 | * The same holds for the atom
|
---|
| 59 | */
|
---|
[2f7988] | 60 | class QtObservedInstanceBoard : public QWidget, public Observer
|
---|
[15c8a9] | 61 | {
|
---|
| 62 | Q_OBJECT
|
---|
| 63 |
|
---|
| 64 | public:
|
---|
[2f7988] | 65 | /** Cstor of QtObservedInstanceBoard.
|
---|
[15c8a9] | 66 | *
|
---|
[2f7988] | 67 | * \param _parent Qt parent to automatically destroy when parent is destroyed
|
---|
[15c8a9] | 68 | */
|
---|
[2f7988] | 69 | QtObservedInstanceBoard(QWidget * _parent=0);
|
---|
[15c8a9] | 70 |
|
---|
[2f7988] | 71 | /** Dstor of QtObservedInstanceBoard.
|
---|
[15c8a9] | 72 | *
|
---|
| 73 | */
|
---|
[2f7988] | 74 | ~QtObservedInstanceBoard();
|
---|
[15c8a9] | 75 |
|
---|
| 76 | // Observer functions
|
---|
| 77 | void update(Observable *publisher);
|
---|
| 78 | void subjectKilled(Observable *publisher);
|
---|
| 79 | void recieveNotification(Observable *publisher, Notification_ptr notification);
|
---|
| 80 |
|
---|
[98c35c] | 81 | QtObservedAtom::ptr getObservedAtom(const atomId_t _id);
|
---|
| 82 | QtObservedMolecule::ptr getObservedMolecule(const moleculeId_t _id);
|
---|
[68418e] | 83 | void markObservedAtomAsConnected(const atomId_t _id);
|
---|
| 84 | void markObservedAtomAsDisconnected(const atomId_t _id);
|
---|
[4e6ffe] | 85 | void markObservedAtomForErase(const atomId_t _id);
|
---|
[68418e] | 86 | void markObservedMoleculeAsConnected(const moleculeId_t _id);
|
---|
| 87 | void markObservedMoleculeAsDisconnected(const moleculeId_t _id);
|
---|
[4e6ffe] | 88 | void markObservedMoleculeForErase(const moleculeId_t _id);
|
---|
[15c8a9] | 89 |
|
---|
| 90 | signals:
|
---|
[1b07b1] | 91 | void atomInserted(QtObservedAtom::ptr _atom);
|
---|
| 92 | void atomRemoved(const atomId_t _atomid);
|
---|
[15c8a9] | 93 | void atomIndexChanged(const atomId_t _oldid, const atomId_t _newid);
|
---|
[1b07b1] | 94 | void moleculeInserted(QtObservedMolecule::ptr _mol);
|
---|
[15c8a9] | 95 | void moleculeRemoved(const moleculeId_t _molid);
|
---|
| 96 | void moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid);
|
---|
| 97 |
|
---|
| 98 | private:
|
---|
| 99 | friend class GLWorldScene;
|
---|
| 100 | friend class GLMoleculeObject_bond;
|
---|
[65c323] | 101 | friend class QtObservedAtom;
|
---|
[494478] | 102 | friend class QtObservedMolecule;
|
---|
[15c8a9] | 103 |
|
---|
| 104 | //!> indicating whether we are still signedOn to World or not
|
---|
| 105 | bool WorldSignedOn;
|
---|
| 106 |
|
---|
| 107 | typedef std::multiset<Observable *> SignedOn_t;
|
---|
| 108 | //!> map indicating to which atom we are currently signed on
|
---|
| 109 | SignedOn_t AtomSignedOn;
|
---|
| 110 | //!> map indicating to which molecule we are currently signed on
|
---|
| 111 | SignedOn_t MoleculeSignedOn;
|
---|
| 112 |
|
---|
| 113 | /** Counts how many atom's ObservedValues got subjectKilled.
|
---|
| 114 | *
|
---|
| 115 | * This is used to give removal signal only when each and every
|
---|
| 116 | * ObservedValue (and the instance itself) has been subjectKilled by the
|
---|
| 117 | * monitored Observable. Only then can we safely remove the instance.
|
---|
| 118 | *
|
---|
| 119 | * \param _atomid id of the atom
|
---|
| 120 | */
|
---|
| 121 | void atomcountsubjectKilled(const atomId_t _atomid);
|
---|
| 122 |
|
---|
| 123 | /** Counts how many molecule's ObservedValues got subjectKilled.
|
---|
| 124 | *
|
---|
| 125 | * This is used to give removal signal only when each and every
|
---|
| 126 | * ObservedValue (and the instance itself) has been subjectKilled by the
|
---|
| 127 | * monitored Observable. Only then can we safely remove the instance.
|
---|
| 128 | *
|
---|
| 129 | * \param _molid id of the molecule
|
---|
| 130 | */
|
---|
| 131 | void moleculecountsubjectKilled(const moleculeId_t _molid);
|
---|
| 132 |
|
---|
[41e287] | 133 | //!> container with all ObservedValues for each atom, associated by id
|
---|
| 134 | ObservedValuesContainer<QtObservedAtom, atomId_t> atomObservedValues;
|
---|
| 135 | //!> container with all ObservedValues for each molecule, associated by id
|
---|
| 136 | ObservedValuesContainer<QtObservedMolecule, moleculeId_t> moleculeObservedValues;
|
---|
[15c8a9] | 137 |
|
---|
| 138 | //!> note down atom id of last removed atom to drop its ObservedValues
|
---|
| 139 | atomId_t lastremovedatom;
|
---|
| 140 |
|
---|
| 141 | //!> note down molecule id of last removed molecule to drop its ObservedValues
|
---|
| 142 | moleculeId_t lastremovedmolecule;
|
---|
| 143 |
|
---|
[6d4925] | 144 | //!> map keyed to atomId_t for atoms who are associated to a molecule but not yet inserted
|
---|
| 145 | typedef std::map<atomId_t, moleculeId_t> atomInsertionDelayed_t;
|
---|
| 146 | //!> map to contain atoms whose insertion is known from the molecule but not yet from the World
|
---|
| 147 | atomInsertionDelayed_t atomInsertionDelayed;
|
---|
[15c8a9] | 148 | };
|
---|
| 149 |
|
---|
[2f7988] | 150 | #endif /* QTOBSERVEDINSTANCEBOARD_HPP_ */
|
---|