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 |
|
---|
19 | #include <boost/function.hpp>
|
---|
20 | #include <boost/shared_ptr.hpp>
|
---|
21 |
|
---|
22 | #include "CodePatterns/Observer/Observable.hpp"
|
---|
23 | #include "CodePatterns/Observer/Observer.hpp"
|
---|
24 |
|
---|
25 | #include "molecule.hpp"
|
---|
26 | #include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
|
---|
27 | #include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp"
|
---|
28 | #include "types.hpp"
|
---|
29 |
|
---|
30 | class QtObservedInstanceBoard;
|
---|
31 |
|
---|
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 |
|
---|
46 | public:
|
---|
47 |
|
---|
48 | //!> typedef for instance wrapped in shared ptr
|
---|
49 | typedef boost::shared_ptr<QtObservedMolecule> ptr;
|
---|
50 |
|
---|
51 | private:
|
---|
52 | //!> ObservedValuesContainer needs to access private cstor and dstor
|
---|
53 | friend class ObservedValuesContainer<QtObservedMolecule, moleculeId_t>;
|
---|
54 | //!> QtObservedInstanceBoard needs to access private cstor and dstor
|
---|
55 | friend class QtObservedInstanceBoard;
|
---|
56 |
|
---|
57 | /** Cstor of QtObservedMolecule.
|
---|
58 | *
|
---|
59 | * \param _ObservedValues ref to set of observed values for this instance
|
---|
60 | * \param _board ref to InstanceBoard for callbacks on occasion of subjectKilled()
|
---|
61 | * \param _parent Qt parent to automatically destroy when parent is destroyed
|
---|
62 | */
|
---|
63 | QtObservedMolecule(
|
---|
64 | const ObservedValues_t &_ObservedValues,
|
---|
65 | QtObservedInstanceBoard &_board,
|
---|
66 | QWidget * _parent=0);
|
---|
67 |
|
---|
68 | public:
|
---|
69 |
|
---|
70 | /** Dstor of QtObservedMolecule.
|
---|
71 | *
|
---|
72 | */
|
---|
73 | ~QtObservedMolecule();
|
---|
74 |
|
---|
75 | // Observer functions
|
---|
76 | void update(Observable *publisher);
|
---|
77 | void subjectKilled(Observable *publisher);
|
---|
78 | void recieveNotification(Observable *publisher, Notification_ptr notification);
|
---|
79 |
|
---|
80 | /** Getter to molecule atom count contained in \a ObservedValues.
|
---|
81 | *
|
---|
82 | * \return molecule's atom count
|
---|
83 | */
|
---|
84 | int getAtomCount() const;
|
---|
85 |
|
---|
86 | /** Getter to molecule index contained in \a ObservedValues.
|
---|
87 | *
|
---|
88 | * \return molecule's index
|
---|
89 | */
|
---|
90 | moleculeId_t getMolIndex() const;
|
---|
91 |
|
---|
92 | /** Getter to molecule name contained in \a ObservedValues.
|
---|
93 | *
|
---|
94 | * \return molecule's name
|
---|
95 | */
|
---|
96 | std::string getMolName() const;
|
---|
97 |
|
---|
98 | /** Getter to molecule formula contained in \a ObservedValues.
|
---|
99 | *
|
---|
100 | * \return molecule's formula
|
---|
101 | */
|
---|
102 | std::string getMolFormula() const;
|
---|
103 |
|
---|
104 | /** Getter to molecule's bounding box contained in \a ObservedValues.
|
---|
105 | *
|
---|
106 | * \return molecule's bounding box
|
---|
107 | */
|
---|
108 | molecule::BoundingBoxInfo getBoundingBox() const;
|
---|
109 |
|
---|
110 | static const molecule * const getMolecule(const moleculeId_t _id);
|
---|
111 |
|
---|
112 | signals:
|
---|
113 | void atomcountChanged();
|
---|
114 | void formulaChanged();
|
---|
115 | void indexChanged();
|
---|
116 | void nameChanged();
|
---|
117 | void tesselationhullChanged();
|
---|
118 | void boundingboxChanged();
|
---|
119 | void atomInserted(const atomId_t);
|
---|
120 | void atomRemoved(const atomId_t);
|
---|
121 |
|
---|
122 | private:
|
---|
123 |
|
---|
124 | void activateObserver();
|
---|
125 | void deactivateObserver();
|
---|
126 |
|
---|
127 | private:
|
---|
128 | static int updateAtomCount(
|
---|
129 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
---|
130 | static molecule::BoundingBoxInfo updateBoundingBox(
|
---|
131 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
---|
132 | static std::string updateFormulaString(
|
---|
133 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
---|
134 | static moleculeId_t updateIndex();
|
---|
135 | static std::string updateName(
|
---|
136 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
---|
137 |
|
---|
138 | //!> list of channels when atom count needs to update
|
---|
139 | static const Observable::channels_t AtomCountChannels;
|
---|
140 | //!> list of channels when bounding box needs to update
|
---|
141 | static const Observable::channels_t BoundingBoxChannels;
|
---|
142 | //!> list of channels when formula needs to update
|
---|
143 | static const Observable::channels_t FormulaStringChannels;
|
---|
144 | //!> list of channels when the index needs to update
|
---|
145 | static const Observable::channels_t IndexChannels;
|
---|
146 | //!> list of channels when the name needs to update
|
---|
147 | static const Observable::channels_t NameChannels;
|
---|
148 |
|
---|
149 | private:
|
---|
150 | /** Observed Values **/
|
---|
151 |
|
---|
152 | //!> enumeration of observed values to match with entries in ObservedValues
|
---|
153 | enum ObservedTypes {
|
---|
154 | //!> contains the current molecule's atom count
|
---|
155 | AtomCount,
|
---|
156 | //!> contains the current molecule's formula
|
---|
157 | FormulaString,
|
---|
158 | //!> contains the current molecule index
|
---|
159 | MolIndex,
|
---|
160 | //!> contains the current molecule name
|
---|
161 | MolName,
|
---|
162 | //!> contains newest version of the bounding box on request
|
---|
163 | BoundingBox,
|
---|
164 | //!> gives the size of the enumeration
|
---|
165 | MAX_ObservedTypes
|
---|
166 | };
|
---|
167 |
|
---|
168 | /** Initializes all \a _ObservedValues entries.
|
---|
169 | *
|
---|
170 | * \param _ObservedValues vector of ObservedValue to be filled
|
---|
171 | * \param _moid molecule id
|
---|
172 | * \param _molref reference to molecule
|
---|
173 | * \param _subjectKilled ref to function to call on subjectKilled()
|
---|
174 | */
|
---|
175 | static void initObservedValues(
|
---|
176 | ObservedValues_t &_ObservedValues,
|
---|
177 | const moleculeId_t _molid,
|
---|
178 | const molecule * const _molref,
|
---|
179 | const boost::function<void(const moleculeId_t)> &_subjectKilled);
|
---|
180 |
|
---|
181 | /** Destroys all \a ObservedValues entries.
|
---|
182 | *
|
---|
183 | * \param _ObservedValues vector of ObservedValue to be destroyed
|
---|
184 | */
|
---|
185 | static void destroyObservedValues(
|
---|
186 | std::vector<boost::any> &_ObservedValues);
|
---|
187 |
|
---|
188 | //!> counts how many ObservedValues have already been subjectKilled()
|
---|
189 | mutable size_t subjectKilledCount;
|
---|
190 |
|
---|
191 | private:
|
---|
192 |
|
---|
193 | //!> we get multiple subjectKilled(), count and call callback() only on last
|
---|
194 | const unsigned int AllsignedOnChannels;
|
---|
195 | unsigned int signedOffChannels;
|
---|
196 |
|
---|
197 | //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
|
---|
198 | const Observable *owner;
|
---|
199 |
|
---|
200 | private:
|
---|
201 |
|
---|
202 | //!> reference to InstanceBoard for callbacks on subjectKilled()
|
---|
203 | QtObservedInstanceBoard & board;
|
---|
204 |
|
---|
205 | //!> internal reference to ObservedValues held by QtObservedInstanceBoard
|
---|
206 | ObservedValues_t ObservedValues;
|
---|
207 | };
|
---|
208 |
|
---|
209 |
|
---|
210 | #endif /* QTOBSERVEDMOLECULE_HPP_ */
|
---|