source: src/UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp@ d845bd

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 d845bd was c44763, checked in by Frederik Heber <heber@…>, 9 years ago

FIX: QtObserved... did not destroyObservedValues() so far.

  • Property mode set to 100644
File size: 7.9 KB
Line 
1/*
2 * QtObservedAtom.hpp
3 *
4 * Created on: Oct 28, 2015
5 * Author: heber
6 */
7
8
9#ifndef QTOBSERVEDATOM_HPP_
10#define QTOBSERVEDATOM_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 "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
28#include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp"
29#include "types.hpp"
30
31class atom;
32class QtObservedInstanceBoard;
33class QtObservedMolecule;
34
35/** This instance is the ObservedValue representation of a World's atom.
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 atom.
44 *
45 * Essentially, this is the interface between molecuilder's World (and a
46 * particular atom) and the QtGui part of the code.
47 */
48class QtObservedAtom : public QWidget, public Observer
49{
50 Q_OBJECT
51
52public:
53
54 //!> typedef for instance wrapped in shared ptr
55 typedef boost::shared_ptr<QtObservedAtom> ptr;
56
57private:
58 //!> ObservedValuesContainer needs to access private cstor and dstor
59 friend class ObservedValuesContainer<QtObservedAtom, atomId_t>;
60 //!> QtObservedInstanceBoard needs to access private cstor and dstor
61 friend class QtObservedInstanceBoard;
62
63 /** Cstor of QtObservedAtom.
64 *
65 * \param _id id of observed atom
66 * \param _atom ref to observed atom
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 QtObservedAtom(
71 const atomId_t _id,
72 const atom * const _atom,
73 QtObservedInstanceBoard &_board,
74 QWidget * _parent=0);
75
76public:
77
78 /** Dstor of QtObservedAtom.
79 *
80 */
81 ~QtObservedAtom();
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 to atom index contained in \a ObservedValues.
89 *
90 * \return atom's index
91 */
92 const atomId_t& getAtomIndex() const;
93
94 //!> typedef for list of bonds, defined by pairs of atom ids
95 typedef std::vector< std::pair<atomId_t, atomId_t> > ListOfBonds_t;
96
97 /** Getter to atom bonds contained in \a ObservedValues.
98 *
99 * \return atom's bonds
100 */
101 const ListOfBonds_t& getAtomBonds() const;
102
103 /** Getter to atom element contained in \a ObservedValues.
104 *
105 * \return atom's element
106 */
107 const atomicNumber_t& getAtomElement() const;
108
109 /** Getter to atom name contained in \a ObservedValues.
110 *
111 * \return atom's name
112 */
113 const std::string& getAtomName() const;
114
115 /** Getter to atom position contained in \a ObservedValues.
116 *
117 * \return atom's position
118 */
119 const Vector& getAtomPosition() const;
120
121 /** Getter to atom's molecule index contained in \a ObservedValues.
122 *
123 * \return atom's molecule index
124 */
125 QtObservedMolecule* const getAtomMolecule() const;
126
127 /** Getter to atom's selected status.
128 *
129 * \return true - atom selected, false - else
130 */
131 const bool getAtomSelected() const;
132
133signals:
134 void indexChanged(const atomId_t, const atomId_t);
135 void bondsChanged();
136 void elementChanged();
137 void moleculeChanged();
138 void nameChanged();
139 void positionChanged();
140 void atomRemoved();
141 void selectedChanged();
142
143//private slots:
144
145private:
146 void activateObserver();
147 void deactivateObserver();
148
149 static const atom * const getAtomConst(const atomId_t _id);
150 static atom * const getAtom(const atomId_t _id);
151
152private:
153 static atomId_t updateIndex();
154 static ListOfBonds_t updateBonds(
155 const boost::function<const atomId_t ()> &_getAtomIndex);
156 static atomicNumber_t updateElement(
157 const boost::function<const atomId_t ()> &_getAtomIndex);
158 QtObservedMolecule* updateMoleculeIndex(
159 const boost::function<const atomId_t ()> &_getAtomIndex);
160 static std::string updateName(
161 const boost::function<const atomId_t ()> &_getAtomIndex);
162 static Vector updatePosition(
163 const boost::function<const atomId_t ()> &_getAtomIndex);
164 static bool updateSelected(
165 const boost::function<const atomId_t ()> &_getAtomIndex);
166
167 //!> enumeration of observed values to match with entries in ObservedValues
168 enum ObservedTypes {
169 //!> contains the current atom index
170 AtomIndex,
171 //!> contains the current set of bonds atoms for the atom
172 AtomBonds,
173 //!> contains the current atom element
174 AtomElement,
175 //!> contains the current atom's molecule index
176 AtomMolecule,
177 //!> contains the current atom position
178 AtomName,
179 //!> contains the current atom position
180 AtomPosition,
181 //!> contains the current atom's selection status
182 AtomSelected,
183 //!> gives the size of the enumeration
184 MAX_ObservedTypes
185 };
186
187 /** Initializes all \a ObservedValues entries.
188 *
189 * \param _ObservedValues vector of ObservedValue to be filled
190 * \param _id atom id
191 * \param _atomref reference to atom
192 * \param _subjectKilled ref to function to call on subjectKilled()
193 */
194 void initObservedValues(
195 ObservedValues_t &_ObservedValues,
196 const atomId_t _id,
197 const atom * const _atomref,
198 const boost::function<void(const atomId_t)> &_subjectKilled);
199
200 /** Destroys all \a ObservedValues entries.
201 *
202 * \param _ObservedValues vector of ObservedValue to be destroyed
203 */
204 void destroyObservedValues(
205 std::vector<boost::any> &_ObservedValues);
206
207 /** Function is called by InstanceBoard to inform about its destruction.
208 *
209 * \note callbacks must not be used after this
210 */
211 void noteBoardIsGone()
212 { BoardIsGone = true; }
213
214 /** Counts the number of subject killed received from the observed values.
215 *
216 * \param _id id to check against ours
217 */
218 void countValuesSubjectKilled(const atomId_t _id);
219
220 //!> counts how many ObservedValues have already been subjectKilled()
221 mutable size_t subjectKilledCount;
222
223 /** Helper function to check that all subjectKilled have been received for both
224 * this instance and all its internal observed values.
225 *
226 */
227 void checkForRemoval();
228
229private:
230
231 //!> list of channels when index needs to update
232 static const Observable::channels_t AtomIndexChannels;
233 //!> list of channels when bonds needs to update
234 static const Observable::channels_t AtomBondsChannels;
235 //!> list of channels when element needs to update
236 static const Observable::channels_t AtomElementChannels;
237 //!> list of channels when molecule index needs to update
238 static const Observable::channels_t AtomMoleculeChannels;
239 //!> list of channels when name needs to update
240 static const Observable::channels_t AtomNameChannels;
241 //!> list of channels when position needs to update
242 static const Observable::channels_t AtomPositionChannels;
243 //!> list of channels when selection needs to update
244 static const Observable::channels_t AtomSelectedChannels;
245
246 //!> we get multiple subjectKilled(), count and call callback() only on last
247 const unsigned int AllsignedOnChannels;
248 unsigned int signedOffChannels;
249
250 //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
251 const Observable *owner;
252
253private:
254 //!> contains still the old id after the index of the atom changed
255 atomId_t oldId;
256
257 //!> reference to InstanceBoard for callbacks on subjectKilled()
258 QtObservedInstanceBoard & board;
259
260 //!> is board still alive or not, impacts callbacks
261 bool BoardIsGone;
262
263 //!> internal reference to ObservedValues held by QtObservedInstanceBoard
264 ObservedValues_t ObservedValues;
265};
266
267
268#endif /* QTOBSERVEDATOM_HPP_ */
Note: See TracBrowser for help on using the repository browser.