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

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

Added QtObservedBond, managed by QtObservedInstanceBoard.

  • QtObservedBond is special because it observes not only a bond, but also two atoms and a molecule in total.
  • but the general idea is to rather have information duplicate, i.e. the left atom's position is also available via the QtObservedAtom. But in this way QtObservedBond does not depend on the QtObservedAtom being still or already present.
  • Property mode set to 100644
File size: 7.1 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/QtObservedBond.hpp"
21#include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp"
22
23#include <map>
24#include <boost/bimap.hpp>
25#include <boost/function.hpp>
26
27#include "CodePatterns/Observer/Observer.hpp"
28
29#include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
30#include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp"
31#include "types.hpp"
32
33class GLWorldScene;
34class GLMoleculeObject_bond;
35class GLMoleculeObject_molecule;
36
37/** The QtObservedInstanceBoard is the central class for communicating instance
38 * creation and destruction from MoleCuilder into the QtGui realm. It should be
39 * thought of as an interface to allow for safe multi-threaded computing.
40 *
41 * The idea is as follows: As soon as a molecule is instantiated, all the QtGui
42 * needs to access the instance (for displaying it) is wrapped up in a
43 * ObservedValue. This ObservedValue separates the lifetime of the molecule object
44 * from the information contained therein and thus makes the visual representation
45 * independent of the life time. The Observer/Observable signal from the World,
46 * i.e. World::MoleculeInserted, is caught (directly within the same thread) by
47 * the QtObservedInstanceBoard. Here, we instantiate all ObservedValue's needed
48 * for this specific molecule and store them in an internal map. Next, we emit
49 * a Qt signal informing the QtGui part about the new molecule.
50 * At some later stage, the QtGui will (probably in a different thread)
51 * instantiate a GLMoleculeObject_molecule as a visual representation of the
52 * molecule. It requests the ObservedValues from the QtObservedInstanceBoard
53 * and uses these directly.
54 * The QtObservedInstanceBoard also records all subjectKilled() signals from
55 * each ObservedValue. Additionally, each class using the ObservedValues
56 * additionally informs the QtObservedInstanceBoard when subjectKilled() was
57 * called. If subjectKilled() for each ObservedValue of a molecule and from the
58 * visual representation have been received, a removal Qt signal is emitted.
59 *
60 * The same holds for the atom
61 */
62class QtObservedInstanceBoard : public QWidget, public Observer
63{
64 Q_OBJECT
65
66public:
67 //!> copy bond id type from QtObservedBond
68 typedef QtObservedBond::bondId_t bondId_t;
69
70 /** Cstor of QtObservedInstanceBoard.
71 *
72 * \param _parent Qt parent to automatically destroy when parent is destroyed
73 */
74 QtObservedInstanceBoard(QWidget * _parent=0);
75
76 /** Dstor of QtObservedInstanceBoard.
77 *
78 */
79 ~QtObservedInstanceBoard();
80
81 // Observer functions
82 void update(Observable *publisher);
83 void subjectKilled(Observable *publisher);
84 void recieveNotification(Observable *publisher, Notification_ptr notification);
85
86 const atomId_t getAtomIdToIndex(ObservedValue_Index_t _id) const;
87 const bondId_t getBondIdToIndex(ObservedValue_Index_t _id) const;
88 const moleculeId_t getMoleculeIdToIndex(ObservedValue_Index_t _id) const;
89
90 QtObservedAtom::ptr getObservedAtom(const atomId_t _id);
91 QtObservedAtom::ptr getObservedAtom(ObservedValue_Index_t _id);
92 QtObservedBond::ptr getObservedBond(const bondId_t _id);
93 QtObservedBond::ptr getObservedBond(ObservedValue_Index_t _id);
94 QtObservedMolecule::ptr getObservedMolecule(const moleculeId_t _id);
95 QtObservedMolecule::ptr getObservedMolecule(ObservedValue_Index_t _id);
96 void markObservedAtomAsConnected(ObservedValue_Index_t _id);
97 void markObservedAtomAsDisconnected(ObservedValue_Index_t _id);
98 void markObservedAtomForErase(ObservedValue_Index_t _id);
99 void markObservedBondAsConnected(ObservedValue_Index_t _id);
100 void markObservedBondAsDisconnected(ObservedValue_Index_t _id);
101 void markObservedBondForErase(ObservedValue_Index_t _id);
102 void markObservedMoleculeAsConnected(ObservedValue_Index_t _id);
103 void markObservedMoleculeAsDisconnected(ObservedValue_Index_t _id);
104 void markObservedMoleculeForErase(ObservedValue_Index_t _id);
105
106signals:
107 void atomInserted(QtObservedAtom::ptr _atom);
108 void atomRemoved(ObservedValue_Index_t _atomid);
109 void atomIndexChanged(const atomId_t _oldid, const atomId_t _newid);
110 void bondInserted(QtObservedBond::ptr _bond);
111 void bondRemoved(ObservedValue_Index_t _bondid);
112 void bondIndexChanged(const bondId_t _oldid, const bondId_t _newid);
113 void moleculeInserted(QtObservedMolecule::ptr _mol);
114 void moleculeRemoved(ObservedValue_Index_t _molid);
115 void moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid);
116
117private:
118 friend class GLWorldScene;
119 friend class GLMoleculeObject_bond;
120 friend class QtObservedAtom;
121 friend class QtObservedMolecule;
122
123 //!> indicating whether we are still signedOn to World or not
124 bool WorldSignedOn;
125
126 typedef std::multiset<Observable *> SignedOn_t;
127 //!> map indicating to which atom we are currently signed on
128 SignedOn_t AtomSignedOn;
129 //!> map indicating to which molecule we are currently signed on
130 SignedOn_t MoleculeSignedOn;
131
132 //!> "templated typedef" for an id to index map.
133 template <class id>
134 struct IdtoIndex_t : boost::bimap<id, ObservedValue_Index_t> {};
135 IdtoIndex_t<atomId_t> atomids_lookup;
136 IdtoIndex_t<bondId_t> bondids_lookup;
137 IdtoIndex_t<moleculeId_t> moleculeids_lookup;
138
139 /** Counts how many atom's ObservedValues got subjectKilled.
140 *
141 * This is used to give removal signal only when each and every
142 * ObservedValue (and the instance itself) has been subjectKilled by the
143 * monitored Observable. Only then can we safely remove the instance.
144 *
145 * \param _id observable that received the subjectKilled()
146 */
147 void atomcountsubjectKilled(ObservedValue_Index_t _id);
148
149 /** Counts how many bond's ObservedValues got subjectKilled.
150 *
151 * This is used to give removal signal only when each and every
152 * ObservedValue (and the instance itself) has been subjectKilled by the
153 * monitored Observable. Only then can we safely remove the instance.
154 *
155 * \param _bondid id of the bond
156 */
157 void bondcountsubjectKilled(ObservedValue_Index_t _bondid);
158
159 /** Counts how many molecule's ObservedValues got subjectKilled.
160 *
161 * This is used to give removal signal only when each and every
162 * ObservedValue (and the instance itself) has been subjectKilled by the
163 * monitored Observable. Only then can we safely remove the instance.
164 *
165 * \param _id observable that received the subjectKilled()
166 */
167 void moleculecountsubjectKilled(ObservedValue_Index_t _id);
168
169 //!> container with all ObservedValues for each atom, associated by id
170 ObservedValuesContainer<QtObservedAtom, ObservedValue_Index_t> atomObservedValues;
171 //!> container with all ObservedValues for each bond, associated by id pairs
172 ObservedValuesContainer<QtObservedBond, ObservedValue_Index_t> bondObservedValues;
173 //!> container with all ObservedValues for each molecule, associated by id
174 ObservedValuesContainer<QtObservedMolecule, ObservedValue_Index_t> moleculeObservedValues;
175};
176
177#endif /* QTOBSERVEDINSTANCEBOARD_HPP_ */
Note: See TracBrowser for help on using the repository browser.