source: src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp@ 41e287

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

Extracted functions handling refcounting of ObservedValues into ObservedValuesContainer.

  • this avoids a lot of code duplication.
  • Property mode set to 100644
File size: 6.5 KB
Line 
1/*
2 * QtObservedInstanceBoard.hpp
3 *
4 * Created on: Oct 17, 2015
5 * Author: heber
6 */
7
8
9#ifndef QTOBSERVEDINSTANCEBOARD_HPP_
10#define QTOBSERVEDINSTANCEBOARD_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 "UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp"
20#include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp"
21
22#include <map>
23#include <boost/function.hpp>
24
25#include "CodePatterns/Observer/Observer.hpp"
26
27#include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
28#include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp"
29#include "types.hpp"
30
31class GLWorldScene;
32class GLMoleculeObject_atom;
33class GLMoleculeObject_bond;
34class GLMoleculeObject_molecule;
35
36/** The QtObservedInstanceBoard is the central class for communicating instance
37 * creation and destruction from MoleCuilder into the QtGui realm. It should be
38 * thought of as an interface to allow for safe multi-threaded computing.
39 *
40 * The idea is as follows: As soon as a molecule is instantiated, all the QtGui
41 * needs to access the instance (for displaying it) is wrapped up in a
42 * ObservedValue. This ObservedValue separates the lifetime of the molecule object
43 * from the information contained therein and thus makes the visual representation
44 * independent of the life time. The Observer/Observable signal from the World,
45 * i.e. World::MoleculeInserted, is caught (directly within the same thread) by
46 * the QtObservedInstanceBoard. Here, we instantiate all ObservedValue's needed
47 * for this specific molecule and store them in an internal map. Next, we emit
48 * a Qt signal informing the QtGui part about the new molecule.
49 * At some later stage, the QtGui will (probably in a different thread)
50 * instantiate a GLMoleculeObject_molecule as a visual representation of the
51 * molecule. It requests the ObservedValues from the QtObservedInstanceBoard
52 * and uses these directly.
53 * The QtObservedInstanceBoard also records all subjectKilled() signals from
54 * each ObservedValue. Additionally, each class using the ObservedValues
55 * additionally informs the QtObservedInstanceBoard when subjectKilled() was
56 * called. If subjectKilled() for each ObservedValue of a molecule and from the
57 * visual representation have been received, a removal Qt signal is emitted.
58 *
59 * The same holds for the atom
60 */
61class QtObservedInstanceBoard : public QWidget, public Observer
62{
63 Q_OBJECT
64
65public:
66 /** Cstor of QtObservedInstanceBoard.
67 *
68 * \param _parent Qt parent to automatically destroy when parent is destroyed
69 */
70 QtObservedInstanceBoard(QWidget * _parent=0);
71
72 /** Dstor of QtObservedInstanceBoard.
73 *
74 */
75 ~QtObservedInstanceBoard();
76
77 // Observer functions
78 void update(Observable *publisher);
79 void subjectKilled(Observable *publisher);
80 void recieveNotification(Observable *publisher, Notification_ptr notification);
81
82 QtObservedAtom::ptr getObservedAtom(const atomId_t _id);
83 QtObservedMolecule::ptr getObservedMolecule(const moleculeId_t _id);
84 void returnObservedAtom(const atomId_t _id);
85 void returnObservedMolecule(const moleculeId_t _id);
86
87 ObservedValues_t getAtomObservedValues(const atomId_t _id);
88 ObservedValues_t getMoleculeObservedValues(const moleculeId_t _id);
89
90 void returnAtomObservedValues(const atomId_t _id, ObservedValues_t &_observedvalues);
91 void returnMoleculeObservedValues(const moleculeId_t _id, ObservedValues_t &_observedvalues);
92
93signals:
94 void atomInserted(const moleculeId_t _molid, const atomId_t _atomid);
95 void atomRemoved(const moleculeId_t _molid, const atomId_t _atomid);
96 void atomIndexChanged(const atomId_t _oldid, const atomId_t _newid);
97 void moleculeInserted(const moleculeId_t _molid);
98 void moleculeRemoved(const moleculeId_t _molid);
99 void moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid);
100
101private:
102 friend class GLWorldScene;
103 friend class GLMoleculeObject_atom;
104 friend class GLMoleculeObject_bond;
105 friend class GLMoleculeObject_molecule;
106
107 //!> indicating whether we are still signedOn to World or not
108 bool WorldSignedOn;
109
110 typedef std::multiset<Observable *> SignedOn_t;
111 //!> map indicating to which atom we are currently signed on
112 SignedOn_t AtomSignedOn;
113 //!> map indicating to which molecule we are currently signed on
114 SignedOn_t MoleculeSignedOn;
115
116 /** Counts how many atom's ObservedValues got subjectKilled.
117 *
118 * This is used to give removal signal only when each and every
119 * ObservedValue (and the instance itself) has been subjectKilled by the
120 * monitored Observable. Only then can we safely remove the instance.
121 *
122 * \param _atomid id of the atom
123 */
124 void atomcountsubjectKilled(const atomId_t _atomid);
125
126 /** Counts how many molecule's ObservedValues got subjectKilled.
127 *
128 * This is used to give removal signal only when each and every
129 * ObservedValue (and the instance itself) has been subjectKilled by the
130 * monitored Observable. Only then can we safely remove the instance.
131 *
132 * \param _molid id of the molecule
133 */
134 void moleculecountsubjectKilled(const moleculeId_t _molid);
135
136 //!> typedef for map with subjectKilledCounts for each atom
137 typedef typename std::map<atomId_t, size_t> atomsubjectKilledCount_t;
138
139 //!> typedef for map with subjectKilledCounts for each molecule
140 typedef typename std::map<moleculeId_t, size_t> moleculesubjectKilledCount_t;
141
142 //!> counts how many ObservedValues have already been subjectKilled()
143 atomsubjectKilledCount_t atomsubjectKilledCount;
144
145 //!> counts how many ObservedValues have already been subjectKilled()
146 moleculesubjectKilledCount_t moleculesubjectKilledCount;
147
148 //!> container with all ObservedValues for each atom, associated by id
149 ObservedValuesContainer<QtObservedAtom, atomId_t> atomObservedValues;
150 //!> container with all ObservedValues for each molecule, associated by id
151 ObservedValuesContainer<QtObservedMolecule, moleculeId_t> moleculeObservedValues;
152
153 //!> stored callback function for notifying QtObservedInstanceBoard about subjectKilled in atom
154 boost::function<void (atomId_t)> atomSubjectKilled;
155 //!> stored callback function for notifying QtObservedInstanceBoard about subjectKilled in molecule
156 boost::function<void (moleculeId_t)> moleculeSubjectKilled;
157
158 //!> note down atom id of last removed atom to drop its ObservedValues
159 atomId_t lastremovedatom;
160
161 //!> note down atom id of last removed atom to drop its ObservedValues
162 std::pair<moleculeId_t, atomId_t> lastremovedatomsmolecule;
163
164 //!> note down molecule id of last removed molecule to drop its ObservedValues
165 moleculeId_t lastremovedmolecule;
166
167};
168
169#endif /* QTOBSERVEDINSTANCEBOARD_HPP_ */
Note: See TracBrowser for help on using the repository browser.