source: src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp@ ee3fb8

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

QtObserved...Observed now get index on ...Removed() signal.

  • Property mode set to 100644
File size: 5.8 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/bimap.hpp>
24#include <boost/function.hpp>
25
26#include "CodePatterns/Observer/Observer.hpp"
27
28#include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
29#include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp"
30#include "types.hpp"
31
32class GLWorldScene;
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 const atomId_t getAtomIdToIndex(ObservedValue_Index_t _id) const;
83 const moleculeId_t getMoleculeIdToIndex(ObservedValue_Index_t _id) const;
84
85 QtObservedAtom::ptr getObservedAtom(const atomId_t _id);
86 QtObservedAtom::ptr getObservedAtom(ObservedValue_Index_t _id);
87 QtObservedMolecule::ptr getObservedMolecule(const moleculeId_t _id);
88 QtObservedMolecule::ptr getObservedMolecule(ObservedValue_Index_t _id);
89 void markObservedAtomAsConnected(ObservedValue_Index_t _id);
90 void markObservedAtomAsDisconnected(ObservedValue_Index_t _id);
91 void markObservedAtomForErase(ObservedValue_Index_t _id);
92 void markObservedMoleculeAsConnected(ObservedValue_Index_t _id);
93 void markObservedMoleculeAsDisconnected(ObservedValue_Index_t _id);
94 void markObservedMoleculeForErase(ObservedValue_Index_t _id);
95
96signals:
97 void atomInserted(QtObservedAtom::ptr _atom);
98 void atomRemoved(ObservedValue_Index_t _atomid);
99 void atomIndexChanged(const atomId_t _oldid, const atomId_t _newid);
100 void moleculeInserted(QtObservedMolecule::ptr _mol);
101 void moleculeRemoved(ObservedValue_Index_t _molid);
102 void moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid);
103
104private:
105 friend class GLWorldScene;
106 friend class GLMoleculeObject_bond;
107 friend class QtObservedAtom;
108 friend class QtObservedMolecule;
109
110 //!> indicating whether we are still signedOn to World or not
111 bool WorldSignedOn;
112
113 typedef std::set<Observable *> SignedOn_t;
114 //!> map indicating to which atom we are currently signed on
115 SignedOn_t AtomSignedOn;
116 //!> map indicating to which molecule we are currently signed on
117 SignedOn_t MoleculeSignedOn;
118
119 //!> "templated typedef" for an id to index map.
120 template <class id>
121 struct IdtoIndex_t : boost::bimap<id, ObservedValue_Index_t> {};
122 IdtoIndex_t<atomId_t> atomids_lookup;
123 IdtoIndex_t<moleculeId_t> moleculeids_lookup;
124
125 /** Counts how many atom's ObservedValues got subjectKilled.
126 *
127 * This is used to give removal signal only when each and every
128 * ObservedValue (and the instance itself) has been subjectKilled by the
129 * monitored Observable. Only then can we safely remove the instance.
130 *
131 * \param _id observable that received the subjectKilled()
132 */
133 void atomcountsubjectKilled(ObservedValue_Index_t _id);
134
135 /** Counts how many molecule's ObservedValues got subjectKilled.
136 *
137 * This is used to give removal signal only when each and every
138 * ObservedValue (and the instance itself) has been subjectKilled by the
139 * monitored Observable. Only then can we safely remove the instance.
140 *
141 * \param _id observable that received the subjectKilled()
142 */
143 void moleculecountsubjectKilled(ObservedValue_Index_t _id);
144
145 //!> container with all ObservedValues for each atom, associated by id
146 ObservedValuesContainer<QtObservedAtom, ObservedValue_Index_t> atomObservedValues;
147 //!> container with all ObservedValues for each molecule, associated by id
148 ObservedValuesContainer<QtObservedMolecule, ObservedValue_Index_t> moleculeObservedValues;
149};
150
151#endif /* QTOBSERVEDINSTANCEBOARD_HPP_ */
Note: See TracBrowser for help on using the repository browser.