source: src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp@ 6a7353

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

QtObservedAtom and ..Molecule now have internal selfref.

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