source: src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp@ 59eabc

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 Candidate_v1.7.0 Candidate_v1.7.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 59eabc was 59eabc, checked in by Frederik Heber <heber@…>, 10 years ago

Introduced unique and permanent ObservedValue_Index_t.

  • this is currently the address of the observable which is not perfectly secure but might work for the moment.
  • QtObservedInstanceBoard uses the index internally and only has an additional map to serve instances on request for the their atomId_t, moleculeId_t, .... However, this id should nowhere else be used because it may change during the lifetime of the object.
  • this should prevent the hazzle with the possibly changing atomId_t, moleculeId_t, ... in all classes that work with QtObserved... instances.
  • Property mode set to 100644
File size: 5.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_bond;
33class GLMoleculeObject_molecule;
34
35/** The QtObservedInstanceBoard is the central class for communicating instance
36 * creation and destruction from MoleCuilder into the QtGui realm. It should be
37 * thought of as an interface to allow for safe multi-threaded computing.
38 *
39 * The idea is as follows: As soon as a molecule is instantiated, all the QtGui
40 * needs to access the instance (for displaying it) is wrapped up in a
41 * ObservedValue. This ObservedValue separates the lifetime of the molecule object
42 * from the information contained therein and thus makes the visual representation
43 * independent of the life time. The Observer/Observable signal from the World,
44 * i.e. World::MoleculeInserted, is caught (directly within the same thread) by
45 * the QtObservedInstanceBoard. Here, we instantiate all ObservedValue's needed
46 * for this specific molecule and store them in an internal map. Next, we emit
47 * a Qt signal informing the QtGui part about the new molecule.
48 * At some later stage, the QtGui will (probably in a different thread)
49 * instantiate a GLMoleculeObject_molecule as a visual representation of the
50 * molecule. It requests the ObservedValues from the QtObservedInstanceBoard
51 * and uses these directly.
52 * The QtObservedInstanceBoard also records all subjectKilled() signals from
53 * each ObservedValue. Additionally, each class using the ObservedValues
54 * additionally informs the QtObservedInstanceBoard when subjectKilled() was
55 * called. If subjectKilled() for each ObservedValue of a molecule and from the
56 * visual representation have been received, a removal Qt signal is emitted.
57 *
58 * The same holds for the atom
59 */
60class QtObservedInstanceBoard : public QWidget, public Observer
61{
62 Q_OBJECT
63
64public:
65 /** Cstor of QtObservedInstanceBoard.
66 *
67 * \param _parent Qt parent to automatically destroy when parent is destroyed
68 */
69 QtObservedInstanceBoard(QWidget * _parent=0);
70
71 /** Dstor of QtObservedInstanceBoard.
72 *
73 */
74 ~QtObservedInstanceBoard();
75
76 // Observer functions
77 void update(Observable *publisher);
78 void subjectKilled(Observable *publisher);
79 void recieveNotification(Observable *publisher, Notification_ptr notification);
80
81 QtObservedAtom::ptr getObservedAtom(const atomId_t _id);
82 QtObservedMolecule::ptr getObservedMolecule(const moleculeId_t _id);
83 void markObservedAtomAsConnected(ObservedValue_Index_t _id);
84 void markObservedAtomAsDisconnected(ObservedValue_Index_t _id);
85 void markObservedAtomForErase(ObservedValue_Index_t _id);
86 void markObservedMoleculeAsConnected(ObservedValue_Index_t _id);
87 void markObservedMoleculeAsDisconnected(ObservedValue_Index_t _id);
88 void markObservedMoleculeForErase(ObservedValue_Index_t _id);
89
90signals:
91 void atomInserted(QtObservedAtom::ptr _atom);
92 void atomRemoved(ObservedValue_Index_t _atomid);
93 void atomIndexChanged(const atomId_t _oldid, const atomId_t _newid);
94 void moleculeInserted(QtObservedMolecule::ptr _mol);
95 void moleculeRemoved(ObservedValue_Index_t _molid);
96 void moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid);
97
98private:
99 friend class GLWorldScene;
100 friend class GLMoleculeObject_bond;
101 friend class QtObservedAtom;
102 friend class QtObservedMolecule;
103
104 //!> indicating whether we are still signedOn to World or not
105 bool WorldSignedOn;
106
107 typedef std::set<Observable *> SignedOn_t;
108 //!> map indicating to which atom we are currently signed on
109 SignedOn_t AtomSignedOn;
110 //!> map indicating to which molecule we are currently signed on
111 SignedOn_t MoleculeSignedOn;
112
113 //!> "templated typedef" for an id to index map.
114 template <class id>
115 struct IdtoIndex_t : std::map<id, ObservedValue_Index_t> {};
116 IdtoIndex_t<atomId_t> atomids_lookup;
117 IdtoIndex_t<moleculeId_t> moleculeids_lookup;
118
119 /** Counts how many atom's ObservedValues got subjectKilled.
120 *
121 * This is used to give removal signal only when each and every
122 * ObservedValue (and the instance itself) has been subjectKilled by the
123 * monitored Observable. Only then can we safely remove the instance.
124 *
125 * \param _id observable that received the subjectKilled()
126 */
127 void atomcountsubjectKilled(ObservedValue_Index_t _id);
128
129 /** Counts how many molecule's ObservedValues got subjectKilled.
130 *
131 * This is used to give removal signal only when each and every
132 * ObservedValue (and the instance itself) has been subjectKilled by the
133 * monitored Observable. Only then can we safely remove the instance.
134 *
135 * \param _id observable that received the subjectKilled()
136 */
137 void moleculecountsubjectKilled(ObservedValue_Index_t _id);
138
139 //!> container with all ObservedValues for each atom, associated by id
140 ObservedValuesContainer<QtObservedAtom, ObservedValue_Index_t> atomObservedValues;
141 //!> container with all ObservedValues for each molecule, associated by id
142 ObservedValuesContainer<QtObservedMolecule, ObservedValue_Index_t> moleculeObservedValues;
143};
144
145#endif /* QTOBSERVEDINSTANCEBOARD_HPP_ */
Note: See TracBrowser for help on using the repository browser.