source: src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp@ 14de9a4

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

AtomInserted/Removed of QtObservedMolecule sends ptr as unique key.

  • this is used to associate the atom with the right molecule. This is needed in case when the molecule is deleted and a new one with the same id is created. If signals are delayed, we need to know which atomInserted/Removed signal to associated with which GLMoleculeObject_molecule.
  • Property mode set to 100644
File size: 9.0 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(
163 const boost::function<const moleculeId_t ()> &_getMolIndex);
164 static int updateBondCount(
165 const boost::function<const moleculeId_t ()> &_getMolIndex);
166 static molecule::BoundingBoxInfo updateBoundingBox(
167 const boost::function<const moleculeId_t ()> &_getMolIndex);
168 static std::string updateFormulaString(
169 const boost::function<const moleculeId_t ()> &_getMolIndex);
170 static Vector updateCenter(
171 const boost::function<const moleculeId_t ()> &_getMolIndex);
172 static moleculeId_t updateIndex();
173 static std::string updateName(
174 const boost::function<const moleculeId_t ()> &_getMolIndex);
175 static int updateNonHydrogenCount(
176 const boost::function<const moleculeId_t ()> &_getMolIndex);
177 static bool updateSelected(
178 const boost::function<const moleculeId_t ()> &_getMolIndex);
179
180 //!> list of channels when atom count needs to update
181 static const Observable::channels_t AtomCountChannels;
182 //!> list of channels when bond count needs to update
183 static const Observable::channels_t BondCountChannels;
184 //!> list of channels when bounding box needs to update
185 static const Observable::channels_t BoundingBoxChannels;
186 //!> list of channels when formula needs to update
187 static const Observable::channels_t FormulaStringChannels;
188 //!> list of channels when the center needs to update
189 static const Observable::channels_t CenterChannels;
190 //!> list of channels when the index needs to update
191 static const Observable::channels_t IndexChannels;
192 //!> list of channels when the name needs to update
193 static const Observable::channels_t NameChannels;
194 //!> list of channels when the name needs to update
195 static const Observable::channels_t NonHydrogenCountChannels;
196 //!> list of channels when the name needs to update
197 static const Observable::channels_t SelectedChannels;
198
199private:
200 /** Observed Values **/
201
202 //!> enumeration of observed values to match with entries in ObservedValues
203 enum ObservedTypes {
204 //!> contains the current molecule index
205 MolIndex,
206 //!> contains the current molecule's atom count
207 AtomCount,
208 //!> contains the current molecule's number of bonds
209 BondCount,
210 //!> contains newest version of the bounding box on request
211 BoundingBox,
212 //!> contains the current molecule's formula
213 FormulaString,
214 //!> contains the current molecule's center
215 MolCenter,
216 //!> contains the current molecule name
217 MolName,
218 //!> contains the current molecule's non-hydrogen atom count
219 NonHydrogenCount,
220 //!> contains the current molecule's selection status
221 MolSelected,
222 //!> gives the size of the enumeration
223 MAX_ObservedTypes
224 };
225
226 /** Initializes all \a _ObservedValues entries.
227 *
228 * \param _ObservedValues vector of ObservedValue to be filled
229 * \param _moid molecule id
230 * \param _molref reference to molecule
231 * \param _subjectKilled ref to function to call on subjectKilled()
232 */
233 static void initObservedValues(
234 ObservedValues_t &_ObservedValues,
235 const moleculeId_t _molid,
236 const molecule * const _molref,
237 const boost::function<void(const moleculeId_t)> &_subjectKilled);
238
239 /** Destroys all \a ObservedValues entries.
240 *
241 * \param _ObservedValues vector of ObservedValue to be destroyed
242 */
243 static void destroyObservedValues(
244 std::vector<boost::any> &_ObservedValues);
245
246 /** Function is called by InstanceBoard to inform about its destruction.
247 *
248 * \note callbacks must not be used after this
249 */
250 void noteBoardIsGone()
251 { BoardIsGone = true; }
252
253
254 /** Counts the number of subject killed received from the observed values.
255 *
256 * \param _id id to check against ours
257 */
258 void countValuesSubjectKilled(const atomId_t _id);
259
260 //!> counts how many ObservedValues have already been subjectKilled()
261 mutable size_t subjectKilledCount;
262
263 /** Helper function to check that all subjectKilled have been received for both
264 * this instance and all its internal observed values.
265 *
266 */
267 void checkForRemoval();
268
269private:
270
271 //!> we get multiple subjectKilled(), count and call callback() only on last
272 const unsigned int AllsignedOnChannels;
273 unsigned int signedOffChannels;
274
275 //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
276 const Observable *owner;
277
278private:
279 //!> contains still the old index after the index changed
280 moleculeId_t oldId;
281
282 //!> reference to InstanceBoard for callbacks on subjectKilled()
283 QtObservedInstanceBoard & board;
284
285 //!> is board still alive or not, impacts callbacks
286 bool BoardIsGone;
287
288 //!> internal reference to ObservedValues held by QtObservedInstanceBoard
289 ObservedValues_t ObservedValues;
290};
291
292
293#endif /* QTOBSERVEDMOLECULE_HPP_ */
Note: See TracBrowser for help on using the repository browser.