source: src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp

Candidate_v1.7.1 stable v1.7.1
Last change on this file was f2d5ce, checked in by Frederik Heber <frederik.heber@…>, 6 days ago

QtTimeLine no longers queries WorldTime directly.

  • Property mode set to 100644
File size: 7.8 KB
Line 
1/*
2 * QtObservedInstanceBoard.hpp
3 *
4 * Created on: Oct 17, 2015
5 * Author: heber
6 */
7
8
9#ifndef QTOBSERVEDINSTANCEBOARD_HPP_
10#define QTOBSERVEDINSTANCEBOARD_HPP_
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include <QtGui/QWidget>
18
19#include "UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp"
20#include "UIElements/Qt4/InstanceBoard/QtObservedBond.hpp"
21#include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp"
22
23#include <map>
24#include <boost/bimap.hpp>
25#include <boost/function.hpp>
26
27#include "CodePatterns/ObservedValue.hpp"
28#include "CodePatterns/Observer/Observer.hpp"
29
30#include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
31#include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp"
32#include "types.hpp"
33
34class GLWorldScene;
35class GLMoleculeObject_bond;
36class GLMoleculeObject_molecule;
37
38/** The QtObservedInstanceBoard is the central class for communicating instance
39 * creation and destruction from MoleCuilder into the QtGui realm. It should be
40 * thought of as an interface to allow for safe multi-threaded computing.
41 *
42 * The idea is as follows: As soon as a molecule is instantiated, all the QtGui
43 * needs to access the instance (for displaying it) is wrapped up in a
44 * ObservedValue. This ObservedValue separates the lifetime of the molecule object
45 * from the information contained therein and thus makes the visual representation
46 * independent of the life time. The Observer/Observable signal from the World,
47 * i.e. World::MoleculeInserted, is caught (directly within the same thread) by
48 * the QtObservedInstanceBoard. Here, we instantiate all ObservedValue's needed
49 * for this specific molecule and store them in an internal map. Next, we emit
50 * a Qt signal informing the QtGui part about the new molecule.
51 * At some later stage, the QtGui will (probably in a different thread)
52 * instantiate a GLMoleculeObject_molecule as a visual representation of the
53 * molecule. It requests the ObservedValues from the QtObservedInstanceBoard
54 * and uses these directly.
55 * The QtObservedInstanceBoard also records all subjectKilled() signals from
56 * each ObservedValue. Additionally, each class using the ObservedValues
57 * additionally informs the QtObservedInstanceBoard when subjectKilled() was
58 * called. If subjectKilled() for each ObservedValue of a molecule and from the
59 * visual representation have been received, a removal Qt signal is emitted.
60 *
61 * The same holds for the atom
62 */
63class QtObservedInstanceBoard : public QWidget, public Observer
64{
65 Q_OBJECT
66
67public:
68 //!> copy bond id type from QtObservedBond
69 typedef QtObservedBond::bondId_t bondId_t;
70
71 /** Cstor of QtObservedInstanceBoard.
72 *
73 * \param _parent Qt parent to automatically destroy when parent is destroyed
74 */
75 QtObservedInstanceBoard(QWidget * _parent=0);
76
77 /** Dstor of QtObservedInstanceBoard.
78 *
79 */
80 ~QtObservedInstanceBoard();
81
82 // Observer functions
83 void update(Observable *publisher);
84 void subjectKilled(Observable *publisher);
85 void recieveNotification(Observable *publisher, Notification_ptr notification);
86
87 const atomId_t getAtomIdToIndex(ObservedValue_Index_t _id) const;
88 const bondId_t getBondIdToIndex(ObservedValue_Index_t _id) const;
89 const moleculeId_t getMoleculeIdToIndex(ObservedValue_Index_t _id) const;
90
91 QtObservedAtom::ptr getObservedAtom(const atomId_t _id);
92 QtObservedAtom::ptr getObservedAtom(ObservedValue_Index_t _id);
93 QtObservedBond::ptr getObservedBond(const bondId_t _id);
94 QtObservedBond::ptr getObservedBond(ObservedValue_Index_t _id);
95 QtObservedMolecule::ptr getObservedMolecule(const moleculeId_t _id);
96 QtObservedMolecule::ptr getObservedMolecule(ObservedValue_Index_t _id);
97 const ObservedValue<unsigned int>& getObservedWorldTime();
98 const ObservedValue<int>& getObservedMaximumAtomTrajectorySize();
99 void markObservedAtomAsConnected(ObservedValue_Index_t _id);
100 void markObservedAtomAsDisconnected(ObservedValue_Index_t _id);
101 void markObservedAtomForErase(ObservedValue_Index_t _id);
102 void markObservedBondAsConnected(ObservedValue_Index_t _id);
103 void markObservedBondAsDisconnected(ObservedValue_Index_t _id);
104 void markObservedBondForErase(ObservedValue_Index_t _id);
105 void markObservedMoleculeAsConnected(ObservedValue_Index_t _id);
106 void markObservedMoleculeAsDisconnected(ObservedValue_Index_t _id);
107 void markObservedMoleculeForErase(ObservedValue_Index_t _id);
108
109signals:
110 void atomInserted(QtObservedAtom::ptr _atom);
111 void atomRemoved(ObservedValue_Index_t _atomid);
112 void atomIndexChanged(const atomId_t _oldid, const atomId_t _newid);
113 void bondInserted(QtObservedBond::ptr _bond);
114 void bondRemoved(ObservedValue_Index_t _bondid);
115 void bondIndexChanged(const bondId_t _oldid, const bondId_t _newid);
116 void moleculeInserted(QtObservedMolecule::ptr _mol);
117 void moleculeRemoved(ObservedValue_Index_t _molid);
118 void moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid);
119 void WorldTimeChanged();
120 void MaximumAtomTrajectoryChanged();
121
122private:
123 friend class GLWorldScene;
124 friend class GLMoleculeObject_bond;
125 friend class QtObservedAtom;
126 friend class QtObservedMolecule;
127
128 //!> indicating whether we are still signedOn to World or not
129 bool WorldSignedOn;
130
131 //!> indicating whether we are still signedOn to World or not
132 bool WorldTimeSignedOn;
133
134 //!> indicating whether we are still signedOn to MaximumAtomTrajectorySize observable
135 bool MaximumAtomTrajectorySizeSignedOn;
136
137 typedef std::multiset<Observable *> SignedOn_t;
138 //!> map indicating to which atom we are currently signed on
139 SignedOn_t AtomSignedOn;
140 //!> map indicating to which molecule we are currently signed on
141 SignedOn_t MoleculeSignedOn;
142
143
144 //!> "templated typedef" for an id to index map.
145 template <class id>
146 struct IdtoIndex_t : boost::bimap<id, ObservedValue_Index_t> {};
147 IdtoIndex_t<atomId_t> atomids_lookup;
148 IdtoIndex_t<bondId_t> bondids_lookup;
149 IdtoIndex_t<moleculeId_t> moleculeids_lookup;
150
151 /** Counts how many atom's ObservedValues got subjectKilled.
152 *
153 * This is used to give removal signal only when each and every
154 * ObservedValue (and the instance itself) has been subjectKilled by the
155 * monitored Observable. Only then can we safely remove the instance.
156 *
157 * \param _id observable that received the subjectKilled()
158 */
159 void atomcountsubjectKilled(ObservedValue_Index_t _id);
160
161 /** Counts how many bond's ObservedValues got subjectKilled.
162 *
163 * This is used to give removal signal only when each and every
164 * ObservedValue (and the instance itself) has been subjectKilled by the
165 * monitored Observable. Only then can we safely remove the instance.
166 *
167 * \param _bondid id of the bond
168 */
169 void bondcountsubjectKilled(ObservedValue_Index_t _bondid);
170
171 /** Counts how many molecule's ObservedValues got subjectKilled.
172 *
173 * This is used to give removal signal only when each and every
174 * ObservedValue (and the instance itself) has been subjectKilled by the
175 * monitored Observable. Only then can we safely remove the instance.
176 *
177 * \param _id observable that received the subjectKilled()
178 */
179 void moleculecountsubjectKilled(ObservedValue_Index_t _id);
180
181 //!> container with all ObservedValues for each atom, associated by id
182 ObservedValuesContainer<QtObservedAtom, ObservedValue_Index_t> atomObservedValues;
183 //!> container with all ObservedValues for each bond, associated by id pairs
184 ObservedValuesContainer<QtObservedBond, ObservedValue_Index_t> bondObservedValues;
185 //!> container with all ObservedValues for each molecule, associated by id
186 ObservedValuesContainer<QtObservedMolecule, ObservedValue_Index_t> moleculeObservedValues;
187 //!> observed value for the world's time
188 ObservedValue<unsigned int> worldTime;
189 //!> observed value for the largest atom trajectory siye (i.e., current number of world time steps)
190 ObservedValue<int> maximumAtomTrajectorySize;
191};
192
193#endif /* QTOBSERVEDINSTANCEBOARD_HPP_ */
Note: See TracBrowser for help on using the repository browser.