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

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

All QtObserved..::update..() now use the atom or molecule ref instead of index getter.

  • the update() is called instantly by the Observable. Hence, the ref is still fully valid and always more recent than the index that needs updating. Also, it is way faster, as no lookup in the World is required and function may even get inlined.
  • Property mode set to 100644
File size: 8.6 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
54private:
55 //!> ObservedValuesContainer needs to access private cstor and dstor
56 friend class ObservedValuesContainer<QtObservedMolecule, moleculeId_t>;
57 //!> QtObservedInstanceBoard needs to access private cstor and dstor
58 friend class QtObservedInstanceBoard;
59
60 /** Cstor of QtObservedMolecule.
61 *
62 * \param _id id of observed molecule
63 * \param _mol ref to observed molecule
64 * \param _board ref to InstanceBoard for callbacks on occasion of subjectKilled()
65 * \param _parent Qt parent to automatically destroy when parent is destroyed
66 */
67 QtObservedMolecule(
68 const moleculeId_t _id,
69 const molecule * const _mol,
70 QtObservedInstanceBoard &_board,
71 QWidget * _parent=0);
72
73public:
74
75 /** Dstor of QtObservedMolecule.
76 *
77 */
78 ~QtObservedMolecule();
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 molecule atom count contained in \a ObservedValues.
86 *
87 * \return molecule's atom count
88 */
89 const int& getAtomCount() const;
90
91 /** Getter to molecule bond count contained in \a ObservedValues.
92 *
93 * \return molecule's bond count
94 */
95 const int& getBondCount() const;
96
97 /** Getter to molecule center contained in \a ObservedValues.
98 *
99 * \return molecule's center
100 */
101 const Vector& getMolCenter() const;
102
103 /** Getter to molecule index contained in \a ObservedValues.
104 *
105 * \return molecule's index
106 */
107 const moleculeId_t& getMolIndex() const;
108
109 /** Getter to molecule name contained in \a ObservedValues.
110 *
111 * \return molecule's name
112 */
113 const std::string& getMolName() const;
114
115 /** Getter to molecule formula contained in \a ObservedValues.
116 *
117 * \return molecule's formula
118 */
119 const std::string& getMolFormula() const;
120
121 /** Getter to molecule non-hydrogen atom count contained in \a ObservedValues.
122 *
123 * \return molecule's non-hydrogen atom count
124 */
125 const int& getNonHydrogenCount() const;
126
127 /** Getter to molecule's bounding box contained in \a ObservedValues.
128 *
129 * \return molecule's bounding box
130 */
131 const molecule::BoundingBoxInfo& getBoundingBox() const;
132
133 /** Getter to molecule's selected status.
134 *
135 * \return true - molecule selected, false - else
136 */
137 const bool& getMolSelected() const;
138
139 static const molecule * const getMolecule(const moleculeId_t _id);
140
141signals:
142 void atomcountChanged();
143 void bondcountChanged();
144 void formulaChanged();
145 void indexChanged(const moleculeId_t, const moleculeId_t);
146 void nameChanged();
147 void nononhydrogenChanged();
148 void centerChanged();
149 void tesselationhullChanged();
150 void boundingboxChanged();
151 void atomInserted(QtObservedAtom::ptr, QtObservedMolecule *);
152 void atomRemoved(const atomId_t, QtObservedMolecule *);
153 void moleculeRemoved();
154 void selectedChanged();
155
156private:
157
158 void activateObserver();
159 void deactivateObserver();
160
161private:
162 static int updateAtomCount(const molecule &mol);
163 static int updateBondCount(const molecule &mol);
164 static molecule::BoundingBoxInfo updateBoundingBox(const molecule &mol);
165 static std::string updateFormulaString(const molecule &mol);
166 static Vector updateCenter(const molecule &mol);
167 static moleculeId_t updateIndex(const molecule &mol);
168 static std::string updateName(const molecule &mol);
169 static int updateNonHydrogenCount(const molecule &mol);
170 static bool updateSelected(const molecule &mol);
171
172 //!> list of channels when atom count needs to update
173 static const Observable::channels_t AtomCountChannels;
174 //!> list of channels when bond count needs to update
175 static const Observable::channels_t BondCountChannels;
176 //!> list of channels when bounding box needs to update
177 static const Observable::channels_t BoundingBoxChannels;
178 //!> list of channels when formula needs to update
179 static const Observable::channels_t FormulaStringChannels;
180 //!> list of channels when the center needs to update
181 static const Observable::channels_t CenterChannels;
182 //!> list of channels when the index needs to update
183 static const Observable::channels_t IndexChannels;
184 //!> list of channels when the name needs to update
185 static const Observable::channels_t NameChannels;
186 //!> list of channels when the name needs to update
187 static const Observable::channels_t NonHydrogenCountChannels;
188 //!> list of channels when the name needs to update
189 static const Observable::channels_t SelectedChannels;
190
191private:
192 /** Observed Values **/
193
194 //!> enumeration of observed values to match with entries in ObservedValues
195 enum ObservedTypes {
196 //!> contains the current molecule index
197 MolIndex,
198 //!> contains the current molecule's atom count
199 AtomCount,
200 //!> contains the current molecule's number of bonds
201 BondCount,
202 //!> contains newest version of the bounding box on request
203 BoundingBox,
204 //!> contains the current molecule's formula
205 FormulaString,
206 //!> contains the current molecule's center
207 MolCenter,
208 //!> contains the current molecule name
209 MolName,
210 //!> contains the current molecule's non-hydrogen atom count
211 NonHydrogenCount,
212 //!> contains the current molecule's selection status
213 MolSelected,
214 //!> gives the size of the enumeration
215 MAX_ObservedTypes
216 };
217
218 /** Initializes all \a _ObservedValues entries.
219 *
220 * \param _ObservedValues vector of ObservedValue to be filled
221 * \param _moid molecule id
222 * \param _molref reference to molecule
223 * \param _subjectKilled ref to function to call on subjectKilled()
224 */
225 static void initObservedValues(
226 ObservedValues_t &_ObservedValues,
227 const moleculeId_t _molid,
228 const molecule * const _molref,
229 const boost::function<void(const moleculeId_t)> &_subjectKilled);
230
231 /** Destroys all \a ObservedValues entries.
232 *
233 * \param _ObservedValues vector of ObservedValue to be destroyed
234 */
235 void destroyObservedValues(
236 std::vector<boost::any> &_ObservedValues);
237
238 /** Function is called by InstanceBoard to inform about its destruction.
239 *
240 * \note callbacks must not be used after this
241 */
242 void noteBoardIsGone()
243 { BoardIsGone = true; }
244
245
246 /** Counts the number of subject killed received from the observed values.
247 *
248 * \param _id id to check against ours
249 */
250 void countValuesSubjectKilled(const atomId_t _id);
251
252 //!> counts how many ObservedValues have already been subjectKilled()
253 mutable size_t subjectKilledCount;
254
255 /** Helper function to check that all subjectKilled have been received for both
256 * this instance and all its internal observed values.
257 *
258 */
259 void checkForRemoval();
260
261private:
262
263 //!> we get multiple subjectKilled(), count and call callback() only on last
264 const unsigned int AllsignedOnChannels;
265 unsigned int signedOffChannels;
266
267 //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
268 const Observable *owner;
269
270private:
271 //!> contains still the old index after the index changed
272 moleculeId_t oldId;
273
274 //!> reference to InstanceBoard for callbacks on subjectKilled()
275 QtObservedInstanceBoard & board;
276
277 //!> is board still alive or not, impacts callbacks
278 bool BoardIsGone;
279
280 //!> internal reference to ObservedValues held by QtObservedInstanceBoard
281 ObservedValues_t ObservedValues;
282};
283
284
285#endif /* QTOBSERVEDMOLECULE_HPP_ */
Note: See TracBrowser for help on using the repository browser.