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

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

QtObserved... signals indexChanged does not transmit ids anymore.

  • since the change to ObservedValue_Index_t, the id is not used anymore. Only in the GUI for the objectid.
  • Property mode set to 100644
File size: 9.1 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
57 //!> typedef for instance wrapped in weak shared ptr
58 typedef boost::weak_ptr<QtObservedAtom> weak_ptr;
59
60private:
61 //!> ObservedValuesContainer needs to access private cstor and dstor
62 friend class ObservedValuesContainer<QtObservedAtom, ObservedValue_Index_t>;
63 //!> QtObservedInstanceBoard needs to access private cstor and dstor
64 friend class QtObservedInstanceBoard;
65
66 /** Cstor of QtObservedAtom.
67 *
68 * \param _id id of observed atom
69 * \param _atom ref to observed atom
70 * \param _board ref to InstanceBoard for callbacks on occasion of subjectKilled()
71 * \param _parent Qt parent to automatically destroy when parent is destroyed
72 */
73 QtObservedAtom(
74 const atomId_t _id,
75 const atom * const _atom,
76 QtObservedInstanceBoard &_board,
77 QWidget * _parent=0);
78
79public:
80
81 /** Dstor of QtObservedAtom.
82 *
83 */
84 ~QtObservedAtom();
85
86 // Observer functions
87 void update(Observable *publisher);
88 void subjectKilled(Observable *publisher);
89 void recieveNotification(Observable *publisher, Notification_ptr notification);
90
91 /** Getter for a permanent and unique index of this instance.
92 *
93 * \note ALWAYS use this index if you need to store and identifier to this
94 * instance which you might need to retrieve at some later date.
95 *
96 * \warning DO NOT STORE the QtObserved...:ptr directly. This will possibly
97 * prevent their eventual destruction. Only store the ObservedValue_Index_t
98 * as means to obtain the ptr from the QtObservedInstanceBoard.
99 *
100 * \return returns a unique and permanent index that can be used to retrieve this
101 * instance from the QtObservedInstanceBoard as it must not be stored.
102 */
103 ObservedValue_Index_t getIndex() const;
104
105 /** Getter to atom index contained in \a ObservedValues.
106 *
107 * \return atom's index
108 */
109 const atomId_t& getAtomIndex() const;
110
111 //!> typedef for list of bonds, defined by pairs of atom ids
112 typedef std::vector< std::pair<atomId_t, atomId_t> > ListOfBonds_t;
113
114 /** Getter to atom bonds contained in \a ObservedValues.
115 *
116 * \return atom's bonds
117 */
118 const ListOfBonds_t& getAtomBonds() const;
119
120 /** Getter to atom element contained in \a ObservedValues.
121 *
122 * \return atom's element
123 */
124 const atomicNumber_t& getAtomElement() const;
125
126 /** Getter to atom name contained in \a ObservedValues.
127 *
128 * \return atom's name
129 */
130 const std::string& getAtomName() const;
131
132 /** Getter to atom position contained in \a ObservedValues.
133 *
134 * \return atom's position
135 */
136 const Vector& getAtomPosition() const;
137
138 /** Getter to the observed state of the associated molecule.
139 *
140 * \return const ref to observed state of molecule
141 */
142 const QtObservedMolecule* const getMoleculeRef() const;
143
144 /** Getter to atom's selected status.
145 *
146 * \return true - atom selected, false - else
147 */
148 const bool getAtomSelected() const;
149
150signals:
151 void indexChanged();
152 void bondsChanged();
153 void elementChanged();
154 void moleculeChanged();
155 void nameChanged();
156 void positionChanged();
157 void atomRemoved();
158 void selectedChanged();
159
160//private slots:
161
162private:
163 void activateObserver();
164 void deactivateObserver();
165
166 static const atom * const getAtomConst(const atomId_t _id);
167 static atom * const getAtom(const atomId_t _id);
168
169private:
170 static atomId_t updateIndex(const atom &_atomref);
171 static ListOfBonds_t updateBonds(const atom &_atom);
172 static atomicNumber_t updateElement(const atom &_atom);
173 QtObservedMolecule* updateMoleculeRef(const atom &_atom);
174 static std::string updateName(const atom &_atom);
175 static Vector updatePosition(const atom &_atom);
176 static bool updateSelected(const atom &_atom);
177
178 //!> enumeration of observed values to match with entries in ObservedValues
179 enum ObservedTypes {
180 //!> contains the current atom index
181 AtomIndex,
182 //!> contains the current set of bonds atoms for the atom
183 AtomBonds,
184 //!> contains the current atom element
185 AtomElement,
186 //!> contains the current atom position
187 AtomName,
188 //!> contains the current atom position
189 AtomPosition,
190 //!> contains the current atom's selection status
191 AtomSelected,
192 //!> contains the current atom's molecule index
193 MoleculeRef,
194 //!> gives the size of the enumeration
195 MAX_ObservedTypes
196 };
197
198 /** Initializes all \a ObservedValues entries.
199 *
200 * \param _ObservedValues vector of ObservedValue to be filled
201 * \param _id atom id
202 * \param _atomref reference to atom
203 * \param _subjectKilled ref to function to call on subjectKilled()
204 */
205 void initObservedValues(
206 ObservedValues_t &_ObservedValues,
207 const atomId_t _id,
208 const atom * const _atomref,
209 const boost::function<void()> &_subjectKilled);
210
211 /** Destroys all \a ObservedValues entries.
212 *
213 * \param _ObservedValues vector of ObservedValue to be destroyed
214 */
215 void destroyObservedValues(
216 std::vector<boost::any> &_ObservedValues);
217
218 /** Function is called by InstanceBoard to inform about its destruction.
219 *
220 * \note callbacks must not be used after this
221 */
222 void noteBoardIsGone()
223 { BoardIsGone = true; }
224
225 /** Counts the number of subject killed received from the observed values.
226 *
227 * \param _id id to check against ours
228 */
229 void countValuesSubjectKilled(ObservedValue_Index_t _id);
230
231 //!> counts how many ObservedValues have already been subjectKilled()
232 mutable size_t subjectKilledCount;
233
234 /** Helper function to check that all subjectKilled have been received for both
235 * this instance and all its internal observed values.
236 *
237 * \param _id id to check against ours
238 */
239 void checkForRemoval(ObservedValue_Index_t _id);
240
241private:
242
243 //!> list of channels when index needs to update
244 static const Observable::channels_t AtomIndexChannels;
245 //!> list of channels when bonds needs to update
246 static const Observable::channels_t AtomBondsChannels;
247 //!> list of channels when element needs to update
248 static const Observable::channels_t AtomElementChannels;
249 //!> list of channels when molecule index needs to update
250 static const Observable::channels_t MoleculeChangedChannels;
251 //!> list of channels when name needs to update
252 static const Observable::channels_t AtomNameChannels;
253 //!> list of channels when position needs to update
254 static const Observable::channels_t AtomPositionChannels;
255 //!> list of channels when selection needs to update
256 static const Observable::channels_t AtomSelectedChannels;
257
258 //!> we get multiple subjectKilled(), count and call callback() only on last
259 const unsigned int AllsignedOnChannels;
260 unsigned int signedOffChannels;
261
262 //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
263 const Observable *owner;
264
265private:
266
267 /** Internal setter for the weak shared_ptr instance that we sometimes
268 * need to convert the ref to this instance into an shared ptr instance that
269 * is safe to hand around.
270 *
271 * \param _selfref ref to shared ptr instance that is internally stored
272 */
273 void setSelfRef(const weak_ptr &_selfref)
274 { const_cast<weak_ptr &>(selfref) = _selfref; }
275
276 //!> reference to this instance wrapped in a shared ptr for handing around
277 const weak_ptr selfref;
278
279public:
280
281 /** Getter for this instance safely wrapped in a shared ptr instance for
282 * handing arount.
283 *
284 * \return shared ptr of this instance
285 */
286 ptr getRef() const
287 { return ptr(selfref); }
288
289private:
290 //!> unique index among all observed instances
291 const ObservedValue_Index_t index;
292
293 //!> reference to InstanceBoard for callbacks on subjectKilled()
294 QtObservedInstanceBoard & board;
295
296 //!> is board still alive or not, impacts callbacks
297 bool BoardIsGone;
298
299 //!> internal reference to ObservedValues held by QtObservedInstanceBoard
300 ObservedValues_t ObservedValues;
301};
302
303
304#endif /* QTOBSERVEDATOM_HPP_ */
Note: See TracBrowser for help on using the repository browser.