source: src/UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp@ 6d4925

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 6d4925 was 04c3a3, checked in by Frederik Heber <heber@…>, 9 years ago

QtObservedAtom, ..Molecule, and ObservedValue_wCallback have flag to indicate invalid callback.

  • due to Qt's signal/slot destruction, which follows no proper order, we need to invalidate callback when their owners are destroyed. Each has a note-function() that flips the boolean to show the callbacks invalidity.
  • TODO: So far this is not nice, especially w.r.t to ObservedValue_wCallback because of templatization. We cannot place them in a loop and this makes this very error-prone once more Values are added ...
  • Property mode set to 100644
File size: 7.0 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;
33
34/** This instance is the ObservedValue representation of a World's atom.
35 *
36 * Due to the signal/slot mechanism and its delays, lifetime of objects in the
37 * World and their QtGui representation cannot directly be related (without
38 * slowing down Actions just for having the representation up to speed).
39 * Hence, the required information for displaying and representing these
40 * objects must be contained in an extra instance.
41 *
42 * This is the instance for information about a particular atom.
43 *
44 * Essentially, this is the interface between molecuilder's World (and a
45 * particular atom) and the QtGui part of the code.
46 */
47class QtObservedAtom : public QWidget, public Observer
48{
49 Q_OBJECT
50
51public:
52
53 //!> typedef for instance wrapped in shared ptr
54 typedef boost::shared_ptr<QtObservedAtom> ptr;
55
56private:
57 //!> ObservedValuesContainer needs to access private cstor and dstor
58 friend class ObservedValuesContainer<QtObservedAtom, atomId_t>;
59 //!> QtObservedInstanceBoard needs to access private cstor and dstor
60 friend class QtObservedInstanceBoard;
61
62 /** Cstor of QtObservedAtom.
63 *
64 * \param _ObservedValues ref to set of observed values for this instance
65 * \param _board ref to InstanceBoard for callbacks on occasion of subjectKilled()
66 * \param _parent Qt parent to automatically destroy when parent is destroyed
67 */
68 QtObservedAtom(
69 const ObservedValues_t &_ObservedValues,
70 QtObservedInstanceBoard &_board,
71 QWidget * _parent=0);
72
73public:
74
75 /** Dstor of QtObservedAtom.
76 *
77 */
78 ~QtObservedAtom();
79
80 // Observer functions
81 void update(Observable *publisher);
82 void subjectKilled(Observable *publisher);
83 void recieveNotification(Observable *publisher, Notification_ptr notification);
84
85 /** Getter to atom index contained in \a ObservedValues.
86 *
87 * \return atom's index
88 */
89 const atomId_t& getAtomIndex() const;
90
91 //!> typedef for list of bonds, defined by pairs of atom ids
92 typedef std::vector< std::pair<atomId_t, atomId_t> > ListOfBonds_t;
93
94 /** Getter to atom bonds contained in \a ObservedValues.
95 *
96 * \return atom's bonds
97 */
98 const ListOfBonds_t& getAtomBonds() const;
99
100 /** Getter to atom element contained in \a ObservedValues.
101 *
102 * \return atom's element
103 */
104 const atomicNumber_t& getAtomElement() const;
105
106 /** Getter to atom name contained in \a ObservedValues.
107 *
108 * \return atom's name
109 */
110 const std::string& getAtomName() const;
111
112 /** Getter to atom position contained in \a ObservedValues.
113 *
114 * \return atom's position
115 */
116 const Vector& getAtomPosition() const;
117
118 /** Getter to atom's molecule index contained in \a ObservedValues.
119 *
120 * \return atom's molecule index
121 */
122 const moleculeId_t& getAtomMoleculeIndex() const;
123
124signals:
125 void indexChanged();
126 void bondsChanged();
127 void elementChanged();
128 void moleculeindexChanged();
129 void nameChanged();
130 void positionChanged();
131 void atomRemoved();
132
133//private slots:
134
135private:
136 void activateObserver();
137 void deactivateObserver();
138
139 static const atom * const getAtomConst(const atomId_t _id);
140 static atom * const getAtom(const atomId_t _id);
141
142private:
143 static atomId_t updateIndex();
144 static ListOfBonds_t updateBonds(
145 const boost::function<const atomId_t ()> &_getAtomIndex);
146 static atomicNumber_t updateElement(
147 const boost::function<const atomId_t ()> &_getAtomIndex);
148 static moleculeId_t updateMoleculeIndex(
149 const boost::function<const atomId_t ()> &_getAtomIndex);
150 static std::string updateName(
151 const boost::function<const atomId_t ()> &_getAtomIndex);
152 static Vector updatePosition(
153 const boost::function<const atomId_t ()> &_getAtomIndex);
154
155 //!> enumeration of observed values to match with entries in ObservedValues
156 enum ObservedTypes {
157 //!> contains the current atom index
158 AtomIndex,
159 //!> contains the current set of bonds atoms for the atom
160 AtomBonds,
161 //!> contains the current atom element
162 AtomElement,
163 //!> contains the current atom's molecule index
164 AtomMoleculeIndex,
165 //!> contains the current atom position
166 AtomName,
167 //!> contains the current atom position
168 AtomPosition,
169 //!> gives the size of the enumeration
170 MAX_ObservedTypes
171 };
172
173 /** Initializes all \a ObservedValues entries.
174 *
175 * \param _ObservedValues vector of ObservedValue to be filled
176 * \param _id atom id
177 * \param _atomref reference to atom
178 * \param _subjectKilled ref to function to call on subjectKilled()
179 */
180 static void initObservedValues(
181 ObservedValues_t &_ObservedValues,
182 const atomId_t _id,
183 const atom * const _atomref,
184 const boost::function<void(const atomId_t)> &_subjectKilled);
185
186 /** Destroys all \a ObservedValues entries.
187 *
188 * \param _ObservedValues vector of ObservedValue to be destroyed
189 */
190 static void destroyObservedValues(
191 std::vector<boost::any> &_ObservedValues);
192
193 /** Function is called by InstanceBoard to inform about its destruction.
194 *
195 * \note callbacks must not be used after this
196 */
197 void noteBoardIsGone()
198 { BoardIsGone = true; }
199
200 //!> counts how many ObservedValues have already been subjectKilled()
201 mutable size_t subjectKilledCount;
202
203private:
204
205 //!> list of channels when index needs to update
206 static const Observable::channels_t AtomIndexChannels;
207 //!> list of channels when bonds needs to update
208 static const Observable::channels_t AtomBondsChannels;
209 //!> list of channels when element needs to update
210 static const Observable::channels_t AtomElementChannels;
211 //!> list of channels when molecule index needs to update
212 static const Observable::channels_t AtomMoleculeIndexChannels;
213 //!> list of channels when name needs to update
214 static const Observable::channels_t AtomNameChannels;
215 //!> list of channels when position needs to update
216 static const Observable::channels_t AtomPositionChannels;
217
218 //!> we get multiple subjectKilled(), count and call callback() only on last
219 const unsigned int AllsignedOnChannels;
220 unsigned int signedOffChannels;
221
222 //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
223 const Observable *owner;
224
225private:
226
227 //!> reference to InstanceBoard for callbacks on subjectKilled()
228 QtObservedInstanceBoard & board;
229
230 //!> is board still alive or not, impacts callbacks
231 bool BoardIsGone;
232
233 //!> internal reference to ObservedValues held by QtObservedInstanceBoard
234 ObservedValues_t ObservedValues;
235};
236
237
238#endif /* QTOBSERVEDATOM_HPP_ */
Note: See TracBrowser for help on using the repository browser.