source: src/UIElements/Qt4/InstanceBoard/QtObservedBond.hpp@ 7f185f9

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

QtObservedBond also offers direct access to stored QtObservedAtoms as const refs.

  • leftatom and rightatom are const throughout the lifetime of the bond. Hence, there is no need to update them and we simply store the refs directly. This will be different for the atom, where the molecule ref may change over the lifetime!
  • Property mode set to 100644
File size: 9.7 KB
RevLine 
[b4bd0e]1/*
2 * QtObservedBond.hpp
3 *
4 * Created on: Mar 03, 2016
5 * Author: heber
6 */
7
8
9#ifndef QTOBSERVEDBOND_HPP_
10#define QTOBSERVEDBOND_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 "Bond/bond.hpp"
28#include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
29#include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp"
[4112691]30#include "UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp"
[b4bd0e]31#include "types.hpp"
32
33class atom;
34class molecule;
35class QtObservedInstanceBoard;
36class QtObservedMolecule;
37
38/** This instance is the ObservedValue representation of a World's bond.
39 *
40 * Due to the signal/slot mechanism and its delays, lifetime of objects in the
41 * World and their QtGui representation cannot directly be related (without
42 * slowing down Actions just for having the representation up to speed).
43 * Hence, the required information for displaying and representing these
44 * objects must be contained in an extra instance.
45 *
46 * This is the instance for information about a particular bond.
47 *
48 * Essentially, this is the interface between molecuilder's World (and a
49 * particular bond) and the QtGui part of the code.
50 */
51class QtObservedBond : public QWidget, public Observer
52{
53 Q_OBJECT
54
55public:
56 typedef std::pair<atomId_t, atomId_t> bondId_t;
57
58 //!> typedef for instance wrapped in shared ptr
59 typedef boost::shared_ptr<QtObservedBond> ptr;
60
61 //!> typedef for instance wrapped in weak shared ptr
62 typedef boost::weak_ptr<QtObservedBond> weak_ptr;
63
64private:
65 //!> ObservedValuesContainer needs to access private cstor and dstor
66 friend class ObservedValuesContainer<QtObservedBond, ObservedValue_Index_t>;
67 //!> QtObservedInstanceBoard needs to access private cstor and dstor
68 friend class QtObservedInstanceBoard;
69
70 /** Cstor of QtObservedBond.
71 *
72 * \param _id id of observed bond
73 * \param _bond ref to observed bond
[4112691]74 * \param _leftatom bond's observed left atom for position, element, ...
75 * \param _rightatom bond's observed right atom for position, element, ...
[b4bd0e]76 * \param _board ref to InstanceBoard for callbacks on occasion of subjectKilled()
77 * \param _parent Qt parent to automatically destroy when parent is destroyed
78 */
79 QtObservedBond(
80 const bondId_t _id,
81 const bond::ptr _bond,
[4112691]82 const QtObservedAtom::ptr &_leftatom,
83 const QtObservedAtom::ptr &_rightatom,
[b4bd0e]84 QtObservedInstanceBoard &_board,
85 QWidget * _parent=0);
86
87public:
88
89 /** Dstor of QtObservedBond.
90 *
91 */
92 ~QtObservedBond();
93
94 // Observer functions
95 void update(Observable *publisher);
96 void subjectKilled(Observable *publisher);
97 void recieveNotification(Observable *publisher, Notification_ptr notification);
98
99 /** Getter for a permanent and unique index of this instance.
100 *
101 * \note ALWAYS use this index if you need to store and identifier to this
102 * instance which you might need to retrieve at some later date.
103 *
104 * \warning DO NOT STORE the QtObserved...:ptr directly. This will possibly
105 * prevent their eventual destruction. Only store the ObservedValue_Index_t
106 * as means to obtain the ptr from the QtObservedInstanceBoard.
107 *
108 * \return returns a unique and permanent index that can be used to retrieve this
109 * instance from the QtObservedInstanceBoard as it must not be stored.
110 */
111 ObservedValue_Index_t getIndex() const;
112
113 /** Getter to bond's index pair contained in \a ObservedValues.
114 *
115 * \return bond's index pair
116 */
117 const bondId_t getBondIndex() const;
118
119 /** Getter to bond's degree contained in \a ObservedValues.
120 *
121 * \return bond's degree
122 */
123 const int& getBondDegree() const;
124
[7f185f9]125 /** Getter to the observed state of the left atom of this bond.
126 *
127 * \return const ref to left atom's observed state.
128 */
129 const QtObservedAtom* const getLeftAtom() const
130 { return leftatom.get(); }
131
132 /** Getter to the observed state of the right atom of this bond.
133 *
134 * \return const ref to right atom's observed state.
135 */
136 const QtObservedAtom* const getRightAtom() const
137 { return rightatom.get(); }
138
[b4bd0e]139 /** Getter to bond's left atom index contained in \a ObservedValues.
140 *
141 * \return bond's left atom index
142 */
143 const atomId_t& getLeftAtomIndex() const;
144
145 /** Getter to bond's left atom element contained in \a ObservedValues.
146 *
147 * \return bond's left atom element
148 */
149 const atomicNumber_t& getLeftAtomElement() const;
150
[7f185f9]151 /** Getter to left atoms's molecule index contained in \a ObservedValues.
152 *
153 * \return left atom's molecule index
154 */
155 const moleculeId_t getLeftMoleculeIndex() const;
156
[b4bd0e]157 /** Getter to bond's right atom position contained in \a ObservedValues.
158 *
159 * \return bond's left atom position
160 */
161 const Vector& getLeftAtomPosition() const;
162
163 /** Getter to bond's right atom index contained in \a ObservedValues.
164 *
165 * \return bond's right atom index
166 */
167 const atomId_t& getRightAtomIndex() const;
168
169 /** Getter to bond's right atom element contained in \a ObservedValues.
170 *
171 * \return bond's right atom element
172 */
173 const atomicNumber_t& getRightAtomElement() const;
174
175 /** Getter to bond's right atom position contained in \a ObservedValues.
176 *
177 * \return bond's right atom position
178 */
179 const Vector& getRightAtomPosition() const;
180
[7f185f9]181 /** Getter to right atom's molecule index contained in \a ObservedValues.
[b4bd0e]182 *
[7f185f9]183 * \return right atom's molecule index
[b4bd0e]184 */
[7f185f9]185 const moleculeId_t getRightMoleculeIndex() const;
[b4bd0e]186
187 //!> typedef for internal observable counter maps
188 typedef std::map<Observable * const, unsigned int> ObservableCount_t;
189
190signals:
191
192 void indexChanged(bondId_t, bondId_t);
193 void degreeChanged();
194 void leftAtomIndexChanged(atomId_t, atomId_t);
195 void leftAtomElementChanged();
196 void leftAtomPositionChanged();
[7f185f9]197 void leftmoleculeChanged();
[b4bd0e]198 void rightAtomIndexChanged(atomId_t, atomId_t);
199 void rightAtomElementChanged();
200 void rightAtomPositionChanged();
[7f185f9]201 void rightmoleculeChanged();
[b4bd0e]202 void bondRemoved();
203
[7f185f9]204//private slots:
[b4bd0e]205
206private:
207 void activateObserver();
208 void deactivateObserver();
209
210 static const atom * const getAtomConst(const atomId_t _id);
211 static atom * const getAtom(const atomId_t _id);
212
213private:
214 static int updateDegree(const bond &_bond);
215
216 //!> enumeration of observed values to match with entries in ObservedValues
217 enum ObservedTypes {
218 //!> contains the current bond degree
219 BondDegree,
220 //!> gives the size of the enumeration
221 MAX_ObservedTypes
222 };
223
224 /** Initializes all \a ObservedValues entries.
225 *
226 * \param _ObservedValues vector of ObservedValue to be filled
227 * \param _id bond id
228 * \param _bondref reference to bond
229 * \param _bondsubjectKilled ref to function to call on subjectKilled() from bond
230 */
231 void initObservedValues(
232 ObservedValues_t &_ObservedValues,
233 const bondId_t _id,
234 const bond::ptr _bondref,
[4112691]235 const boost::function<void()> &_bondsubjectKilled);
[b4bd0e]236
237 /** Destroys all \a ObservedValues entries.
238 *
239 * \param _ObservedValues vector of ObservedValue to be destroyed
240 */
241 static void destroyObservedValues(
242 std::vector<boost::any> &_ObservedValues);
243
244 /** Function is called by InstanceBoard to inform about its destruction.
245 *
246 * \note callbacks must not be used after this
247 */
248 void noteBoardIsGone()
249 { BoardIsGone = true; }
250
251 /** Counts the number of subject killed received from the observed values.
252 *
253 * \param _id id to check against ours
254 * \param _counter counter to decrease
255 */
256 void countValuesSubjectKilled(ObservedValue_Index_t _id, unsigned int &_counter);
257
258 //!> counts how many ObservedValues have already been subjectKilled() for a given observable
259 mutable ObservableCount_t subjectKilledCount;
260
261 /** Helper function to check that all subjectKilled have been received for both
262 * this instance and all its internal observed values.
263 *
264 * \param _id id to check against ours
265 */
266 void checkForRemoval(ObservedValue_Index_t _id);
267
268private:
269
270 //!> list of channels when index needs to update
271 static const Observable::channels_t BondDegreeChannels;
272
273 //!> we get multiple subjectKilled(), count and call callback() only on last
274 const ObservableCount_t AllsignedOnChannels;
275 ObservableCount_t signedOffChannels;
276
277 //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
278 const Observable *bondowner;
279
280private:
281
282 /** Internal setter for the weak shared_ptr instance that we sometimes
283 * need to convert the ref to this instance into an shared ptr instance that
284 * is safe to hand around.
285 *
286 * \param _selfref ref to shared ptr instance that is internally stored
287 */
288 void setSelfRef(const weak_ptr &_selfref)
289 { const_cast<weak_ptr &>(selfref) = _selfref; }
290
291 //!> reference to this instance wrapped in a shared ptr for handing around
292 const weak_ptr selfref;
293
294public:
295
296 /** Getter for this instance safely wrapped in a shared ptr instance for
297 * handing arount.
298 *
299 * \return shared ptr of this instance
300 */
301 ptr getRef() const
302 { return ptr(selfref); }
303
304private:
305 //!> contains still the old id after the index of the bond changed
306 bondId_t oldbondId;
307
[4112691]308 //!> observed left atom of bond for position, element, ...
309 const QtObservedAtom::ptr leftatom;
310
311 //!> observed right atom of bond for position, element, ...
312 const QtObservedAtom::ptr rightatom;
313
[b4bd0e]314 //!> reference to InstanceBoard for callbacks on subjectKilled()
315 QtObservedInstanceBoard & board;
316
317 //!> is board still alive or not, impacts callbacks
318 bool BoardIsGone;
319
320 //!> internal reference to ObservedValues held by QtObservedInstanceBoard
321 ObservedValues_t ObservedValues;
322};
323
324
325#endif /* QTOBSERVEDBOND_HPP_ */
Note: See TracBrowser for help on using the repository browser.