source: src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp@ 1b07b1

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

QtObservedInstanceBoard now sends QtObserved..::ptr around in signals.

  • this should get rid of the problem that we need to keep the QtObservedAtom until it was requested at least once. And we don't know for how long. Now, we simply place the shared_ptr into the signal (to which it seems to be copied) and hence a representation of the atoms remains valid.
  • cstor of GLMoleculeObject_.. take Observed.. as ref.
  • Property mode set to 100644
File size: 8.4 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 _ObservedValues ref to set of observed values for this instance
63 * \param _board ref to InstanceBoard for callbacks on occasion of subjectKilled()
64 * \param _parent Qt parent to automatically destroy when parent is destroyed
65 */
66 QtObservedMolecule(
67 const ObservedValues_t &_ObservedValues,
68 QtObservedInstanceBoard &_board,
69 QWidget * _parent=0);
70
71public:
72
73 /** Dstor of QtObservedMolecule.
74 *
75 */
76 ~QtObservedMolecule();
77
78 // Observer functions
79 void update(Observable *publisher);
80 void subjectKilled(Observable *publisher);
81 void recieveNotification(Observable *publisher, Notification_ptr notification);
82
83 /** Getter to molecule atom count contained in \a ObservedValues.
84 *
85 * \return molecule's atom count
86 */
87 const int& getAtomCount() const;
88
89 /** Getter to molecule bond count contained in \a ObservedValues.
90 *
91 * \return molecule's bond count
92 */
93 const int& getBondCount() const;
94
95 /** Getter to molecule center contained in \a ObservedValues.
96 *
97 * \return molecule's center
98 */
99 const Vector& getMolCenter() const;
100
101 /** Getter to molecule index contained in \a ObservedValues.
102 *
103 * \return molecule's index
104 */
105 const moleculeId_t& getMolIndex() const;
106
107 /** Getter to molecule name contained in \a ObservedValues.
108 *
109 * \return molecule's name
110 */
111 const std::string& getMolName() const;
112
113 /** Getter to molecule formula contained in \a ObservedValues.
114 *
115 * \return molecule's formula
116 */
117 const std::string& getMolFormula() const;
118
119 /** Getter to molecule non-hydrogen atom count contained in \a ObservedValues.
120 *
121 * \return molecule's non-hydrogen atom count
122 */
123 const int& getNonHydrogenCount() const;
124
125 /** Getter to molecule's bounding box contained in \a ObservedValues.
126 *
127 * \return molecule's bounding box
128 */
129 const molecule::BoundingBoxInfo& getBoundingBox() const;
130
131 /** Getter to molecule's selected status.
132 *
133 * \return true - molecule selected, false - else
134 */
135 const bool& getMolSelected() const;
136
137 static const molecule * const getMolecule(const moleculeId_t _id);
138
139signals:
140 void atomcountChanged();
141 void bondcountChanged();
142 void formulaChanged();
143 void indexChanged();
144 void nameChanged();
145 void nononhydrogenChanged();
146 void centerChanged();
147 void tesselationhullChanged();
148 void boundingboxChanged();
149 void atomInserted(QtObservedAtom::ptr);
150 void atomRemoved(const atomId_t);
151 void moleculeRemoved();
152 void selectedChanged();
153
154private:
155
156 void activateObserver();
157 void deactivateObserver();
158
159private:
160 static int updateAtomCount(
161 const boost::function<const moleculeId_t ()> &_getMolIndex);
162 static int updateBondCount(
163 const boost::function<const moleculeId_t ()> &_getMolIndex);
164 static molecule::BoundingBoxInfo updateBoundingBox(
165 const boost::function<const moleculeId_t ()> &_getMolIndex);
166 static std::string updateFormulaString(
167 const boost::function<const moleculeId_t ()> &_getMolIndex);
168 static Vector updateCenter(
169 const boost::function<const moleculeId_t ()> &_getMolIndex);
170 static moleculeId_t updateIndex();
171 static std::string updateName(
172 const boost::function<const moleculeId_t ()> &_getMolIndex);
173 static int updateNonHydrogenCount(
174 const boost::function<const moleculeId_t ()> &_getMolIndex);
175 static bool updateSelected(
176 const boost::function<const moleculeId_t ()> &_getMolIndex);
177
178 //!> list of channels when atom count needs to update
179 static const Observable::channels_t AtomCountChannels;
180 //!> list of channels when bond count needs to update
181 static const Observable::channels_t BondCountChannels;
182 //!> list of channels when bounding box needs to update
183 static const Observable::channels_t BoundingBoxChannels;
184 //!> list of channels when formula needs to update
185 static const Observable::channels_t FormulaStringChannels;
186 //!> list of channels when the center needs to update
187 static const Observable::channels_t CenterChannels;
188 //!> list of channels when the index needs to update
189 static const Observable::channels_t IndexChannels;
190 //!> list of channels when the name needs to update
191 static const Observable::channels_t NameChannels;
192 //!> list of channels when the name needs to update
193 static const Observable::channels_t NonHydrogenCountChannels;
194 //!> list of channels when the name needs to update
195 static const Observable::channels_t SelectedChannels;
196
197private:
198 /** Observed Values **/
199
200 //!> enumeration of observed values to match with entries in ObservedValues
201 enum ObservedTypes {
202 //!> contains the current molecule index
203 MolIndex,
204 //!> contains the current molecule's atom count
205 AtomCount,
206 //!> contains the current molecule's number of bonds
207 BondCount,
208 //!> contains newest version of the bounding box on request
209 BoundingBox,
210 //!> contains the current molecule's formula
211 FormulaString,
212 //!> contains the current molecule's center
213 MolCenter,
214 //!> contains the current molecule name
215 MolName,
216 //!> contains the current molecule's non-hydrogen atom count
217 NonHydrogenCount,
218 //!> contains the current molecule's selection status
219 MolSelected,
220 //!> gives the size of the enumeration
221 MAX_ObservedTypes
222 };
223
224 /** Initializes all \a _ObservedValues entries.
225 *
226 * \param _ObservedValues vector of ObservedValue to be filled
227 * \param _moid molecule id
228 * \param _molref reference to molecule
229 * \param _subjectKilled ref to function to call on subjectKilled()
230 */
231 static void initObservedValues(
232 ObservedValues_t &_ObservedValues,
233 const moleculeId_t _molid,
234 const molecule * const _molref,
235 const boost::function<void(const moleculeId_t)> &_subjectKilled);
236
237 /** Destroys all \a ObservedValues entries.
238 *
239 * \param _ObservedValues vector of ObservedValue to be destroyed
240 */
241 static void destroyObservedValues(
242 std::vector<boost::any> &_ObservedValues);
243
244 /** Function is called by InstanceBoard to inform about its destruction.
245 *
246 * \note callbacks must not be used after this
247 */
248 void noteBoardIsGone()
249 { BoardIsGone = true; }
250
251 //!> counts how many ObservedValues have already been subjectKilled()
252 mutable size_t subjectKilledCount;
253
254private:
255
256 //!> we get multiple subjectKilled(), count and call callback() only on last
257 const unsigned int AllsignedOnChannels;
258 unsigned int signedOffChannels;
259
260 //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
261 const Observable *owner;
262
263private:
264
265 //!> reference to InstanceBoard for callbacks on subjectKilled()
266 QtObservedInstanceBoard & board;
267
268 //!> is board still alive or not, impacts callbacks
269 bool BoardIsGone;
270
271 //!> internal reference to ObservedValues held by QtObservedInstanceBoard
272 ObservedValues_t ObservedValues;
273};
274
275
276#endif /* QTOBSERVEDMOLECULE_HPP_ */
Note: See TracBrowser for help on using the repository browser.