source: src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp@ bf6245

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since bf6245 was bf6245, checked in by Frederik Heber <heber@…>, 9 years ago

QtObservedMolecule also uses new index internally.

  • Property mode set to 100644
File size: 10.1 KB
Line 
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 "LinearAlgebra/Vector.hpp"
26
27#include "molecule.hpp"
28#include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
29#include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp"
30#include "UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp"
31#include "types.hpp"
32
33class QtObservedInstanceBoard;
34
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 */
45class QtObservedMolecule : public QWidget, public Observer
46{
47 Q_OBJECT
48
49public:
50
51 //!> typedef for instance wrapped in shared ptr
52 typedef boost::shared_ptr<QtObservedMolecule> ptr;
53
54 //!> typedef for instance wrapped in shared ptr
55 typedef boost::weak_ptr<QtObservedMolecule> weak_ptr;
56
57private:
58 //!> ObservedValuesContainer needs to access private cstor and dstor
59 friend class ObservedValuesContainer<QtObservedMolecule, ObservedValue_Index_t>;
60 //!> QtObservedInstanceBoard needs to access private cstor and dstor
61 friend class QtObservedInstanceBoard;
62
63 /** Cstor of QtObservedMolecule.
64 *
65 * \param _id id of observed molecule
66 * \param _mol ref to observed molecule
67 * \param _board ref to InstanceBoard for callbacks on occasion of subjectKilled()
68 * \param _parent Qt parent to automatically destroy when parent is destroyed
69 */
70 QtObservedMolecule(
71 const moleculeId_t _id,
72 const molecule * const _mol,
73 QtObservedInstanceBoard &_board,
74 QWidget * _parent=0);
75
76public:
77
78 /** Dstor of QtObservedMolecule.
79 *
80 */
81 ~QtObservedMolecule();
82
83 // Observer functions
84 void update(Observable *publisher);
85 void subjectKilled(Observable *publisher);
86 void recieveNotification(Observable *publisher, Notification_ptr notification);
87
88 /** Getter for a permanent and unique index of this instance.
89 *
90 * \note ALWAYS use this index if you need to store and identifier to this
91 * instance which you might need to retrieve at some later date.
92 *
93 * \warning DO NOT STORE the QtObserved...:ptr directly. This will possibly
94 * prevent their eventual destruction. Only store the ObservedValue_Index_t
95 * as means to obtain the ptr from the QtObservedInstanceBoard.
96 *
97 * \return returns a unique and permanent index that can be used to retrieve this
98 * instance from the QtObservedInstanceBoard as it must not be stored.
99 */
100 ObservedValue_Index_t getIndex() const;
101
102 /** Getter to molecule atom count contained in \a ObservedValues.
103 *
104 * \return molecule's atom count
105 */
106 const int& getAtomCount() const;
107
108 /** Getter to molecule bond count contained in \a ObservedValues.
109 *
110 * \return molecule's bond count
111 */
112 const int& getBondCount() const;
113
114 /** Getter to molecule center contained in \a ObservedValues.
115 *
116 * \return molecule's center
117 */
118 const Vector& getMolCenter() const;
119
120 /** Getter to molecule index contained in \a ObservedValues.
121 *
122 * \return molecule's index
123 */
124 const moleculeId_t& getMolIndex() const;
125
126 /** Getter to molecule name contained in \a ObservedValues.
127 *
128 * \return molecule's name
129 */
130 const std::string& getMolName() const;
131
132 /** Getter to molecule formula contained in \a ObservedValues.
133 *
134 * \return molecule's formula
135 */
136 const std::string& getMolFormula() const;
137
138 /** Getter to molecule non-hydrogen atom count contained in \a ObservedValues.
139 *
140 * \return molecule's non-hydrogen atom count
141 */
142 const int& getNonHydrogenCount() const;
143
144 /** Getter to molecule's bounding box contained in \a ObservedValues.
145 *
146 * \return molecule's bounding box
147 */
148 const molecule::BoundingBoxInfo& getBoundingBox() const;
149
150 /** Getter to molecule's selected status.
151 *
152 * \return true - molecule selected, false - else
153 */
154 const bool& getMolSelected() const;
155
156 static const molecule * const getMolecule(const moleculeId_t _id);
157
158signals:
159 void atomcountChanged();
160 void bondcountChanged();
161 void formulaChanged();
162 void indexChanged(const moleculeId_t, const moleculeId_t);
163 void nameChanged();
164 void nononhydrogenChanged();
165 void centerChanged();
166 void tesselationhullChanged();
167 void boundingboxChanged();
168 void atomInserted(QtObservedAtom::ptr, QtObservedMolecule *);
169 void atomRemoved(ObservedValue_Index_t, QtObservedMolecule *);
170 void moleculeRemoved();
171 void selectedChanged();
172
173private:
174
175 void activateObserver();
176 void deactivateObserver();
177
178private:
179 static int updateAtomCount(const molecule &mol);
180 static int updateBondCount(const molecule &mol);
181 static molecule::BoundingBoxInfo updateBoundingBox(const molecule &mol);
182 static std::string updateFormulaString(const molecule &mol);
183 static Vector updateCenter(const molecule &mol);
184 static moleculeId_t updateIndex(const molecule &mol);
185 static std::string updateName(const molecule &mol);
186 static int updateNonHydrogenCount(const molecule &mol);
187 static bool updateSelected(const molecule &mol);
188
189 //!> list of channels when atom count needs to update
190 static const Observable::channels_t AtomCountChannels;
191 //!> list of channels when bond count needs to update
192 static const Observable::channels_t BondCountChannels;
193 //!> list of channels when bounding box needs to update
194 static const Observable::channels_t BoundingBoxChannels;
195 //!> list of channels when formula needs to update
196 static const Observable::channels_t FormulaStringChannels;
197 //!> list of channels when the center needs to update
198 static const Observable::channels_t CenterChannels;
199 //!> list of channels when the index needs to update
200 static const Observable::channels_t IndexChannels;
201 //!> list of channels when the name needs to update
202 static const Observable::channels_t NameChannels;
203 //!> list of channels when the name needs to update
204 static const Observable::channels_t NonHydrogenCountChannels;
205 //!> list of channels when the name needs to update
206 static const Observable::channels_t SelectedChannels;
207
208private:
209 /** Observed Values **/
210
211 //!> enumeration of observed values to match with entries in ObservedValues
212 enum ObservedTypes {
213 //!> contains the current molecule index
214 MolIndex,
215 //!> contains the current molecule's atom count
216 AtomCount,
217 //!> contains the current molecule's number of bonds
218 BondCount,
219 //!> contains newest version of the bounding box on request
220 BoundingBox,
221 //!> contains the current molecule's formula
222 FormulaString,
223 //!> contains the current molecule's center
224 MolCenter,
225 //!> contains the current molecule name
226 MolName,
227 //!> contains the current molecule's non-hydrogen atom count
228 NonHydrogenCount,
229 //!> contains the current molecule's selection status
230 MolSelected,
231 //!> gives the size of the enumeration
232 MAX_ObservedTypes
233 };
234
235 /** Initializes all \a _ObservedValues entries.
236 *
237 * \param _ObservedValues vector of ObservedValue to be filled
238 * \param _moid molecule id
239 * \param _molref reference to molecule
240 * \param _subjectKilled ref to function to call on subjectKilled()
241 */
242 void initObservedValues(
243 ObservedValues_t &_ObservedValues,
244 const moleculeId_t _molid,
245 const molecule * const _molref,
246 const boost::function<void(ObservedValue_Index_t)> &_subjectKilled);
247
248 /** Destroys all \a ObservedValues entries.
249 *
250 * \param _ObservedValues vector of ObservedValue to be destroyed
251 */
252 void destroyObservedValues(
253 std::vector<boost::any> &_ObservedValues);
254
255 /** Function is called by InstanceBoard to inform about its destruction.
256 *
257 * \note callbacks must not be used after this
258 */
259 void noteBoardIsGone()
260 { BoardIsGone = true; }
261
262
263 /** Counts the number of subject killed received from the observed values.
264 *
265 * \param _id id to check against ours
266 */
267 void countValuesSubjectKilled(ObservedValue_Index_t _id);
268
269 //!> counts how many ObservedValues have already been subjectKilled()
270 mutable size_t subjectKilledCount;
271
272 /** Helper function to check that all subjectKilled have been received for both
273 * this instance and all its internal observed values.
274 *
275 * \param _id id to check against ours
276 */
277 void checkForRemoval(ObservedValue_Index_t _id);
278
279private:
280
281 //!> we get multiple subjectKilled(), count and call callback() only on last
282 const unsigned int AllsignedOnChannels;
283 unsigned int signedOffChannels;
284
285 //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
286 const Observable *owner;
287
288private:
289
290 /** Internal setter for the weak shared_ptr instance that we sometimes
291 * need to convert the ref to this instance into an shared ptr instance that
292 * is safe to hand around.
293 *
294 * \param _selfref ref to shared ptr instance that is internally stored
295 */
296 void setSelfRef(const weak_ptr &_selfref)
297 { const_cast<weak_ptr &>(selfref) = _selfref; }
298
299 //!> reference to this instance wrapped in a shared ptr for handing around
300 const weak_ptr selfref;
301
302public:
303
304 /** Getter for this instance safely wrapped in a shared ptr instance for
305 * handing arount.
306 *
307 * \return shared ptr of this instance
308 */
309 ptr getRef() const
310 { return ptr(selfref); }
311
312private:
313 //!> contains still the old index after the index changed
314 moleculeId_t oldId;
315
316 //!> reference to InstanceBoard for callbacks on subjectKilled()
317 QtObservedInstanceBoard & board;
318
319 //!> is board still alive or not, impacts callbacks
320 bool BoardIsGone;
321
322 //!> internal reference to ObservedValues held by QtObservedInstanceBoard
323 ObservedValues_t ObservedValues;
324};
325
326
327#endif /* QTOBSERVEDMOLECULE_HPP_ */
Note: See TracBrowser for help on using the repository browser.