source: src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp@ 14de9a4

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 14de9a4 was 96e145, checked in by Frederik Heber <heber@…>, 9 years ago

AtomInserted/Removed of QtObservedMolecule sends ptr as unique key.

  • this is used to associate the atom with the right molecule. This is needed in case when the molecule is deleted and a new one with the same id is created. If signals are delayed, we need to know which atomInserted/Removed signal to associated with which GLMoleculeObject_molecule.
  • Property mode set to 100644
File size: 9.0 KB
RevLine 
[0070aa]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
[494478]19#include <boost/function.hpp>
[98c35c]20#include <boost/shared_ptr.hpp>
[0070aa]21
[494478]22#include "CodePatterns/Observer/Observable.hpp"
[0070aa]23#include "CodePatterns/Observer/Observer.hpp"
24
[5a9e34]25#include "LinearAlgebra/Vector.hpp"
26
[494478]27#include "molecule.hpp"
[98c35c]28#include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
[41e287]29#include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp"
[1b07b1]30#include "UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp"
[0070aa]31#include "types.hpp"
32
[98c35c]33class QtObservedInstanceBoard;
34
[0070aa]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
[494478]49public:
50
51 //!> typedef for instance wrapped in shared ptr
52 typedef boost::shared_ptr<QtObservedMolecule> ptr;
53
54private:
[41e287]55 //!> ObservedValuesContainer needs to access private cstor and dstor
56 friend class ObservedValuesContainer<QtObservedMolecule, moleculeId_t>;
[98c35c]57 //!> QtObservedInstanceBoard needs to access private cstor and dstor
58 friend class QtObservedInstanceBoard;
59
[0070aa]60 /** Cstor of QtObservedMolecule.
61 *
[62a0ee]62 * \param _id id of observed molecule
63 * \param _mol ref to observed molecule
[494478]64 * \param _board ref to InstanceBoard for callbacks on occasion of subjectKilled()
[0070aa]65 * \param _parent Qt parent to automatically destroy when parent is destroyed
66 */
[98c35c]67 QtObservedMolecule(
[62a0ee]68 const moleculeId_t _id,
69 const molecule * const _mol,
[494478]70 QtObservedInstanceBoard &_board,
[98c35c]71 QWidget * _parent=0);
72
73public:
[0070aa]74
75 /** Dstor of QtObservedMolecule.
76 *
77 */
78 ~QtObservedMolecule();
79
[98c35c]80 // Observer functions
81 void update(Observable *publisher);
82 void subjectKilled(Observable *publisher);
83 void recieveNotification(Observable *publisher, Notification_ptr notification);
84
[1b6415a]85 /** Getter to molecule atom count contained in \a ObservedValues.
86 *
87 * \return molecule's atom count
88 */
[3b9aa1]89 const int& getAtomCount() const;
[1b6415a]90
[5a9e34]91 /** Getter to molecule bond count contained in \a ObservedValues.
92 *
93 * \return molecule's bond count
94 */
[3b9aa1]95 const int& getBondCount() const;
[5a9e34]96
97 /** Getter to molecule center contained in \a ObservedValues.
98 *
99 * \return molecule's center
100 */
[3b9aa1]101 const Vector& getMolCenter() const;
[5a9e34]102
[494478]103 /** Getter to molecule index contained in \a ObservedValues.
104 *
105 * \return molecule's index
106 */
[3b9aa1]107 const moleculeId_t& getMolIndex() const;
[494478]108
109 /** Getter to molecule name contained in \a ObservedValues.
110 *
111 * \return molecule's name
112 */
[3b9aa1]113 const std::string& getMolName() const;
[494478]114
[1b6415a]115 /** Getter to molecule formula contained in \a ObservedValues.
116 *
117 * \return molecule's formula
118 */
[3b9aa1]119 const std::string& getMolFormula() const;
[1b6415a]120
[5a9e34]121 /** Getter to molecule non-hydrogen atom count contained in \a ObservedValues.
122 *
123 * \return molecule's non-hydrogen atom count
124 */
[3b9aa1]125 const int& getNonHydrogenCount() const;
[5a9e34]126
[494478]127 /** Getter to molecule's bounding box contained in \a ObservedValues.
128 *
129 * \return molecule's bounding box
130 */
[3b9aa1]131 const molecule::BoundingBoxInfo& getBoundingBox() const;
[494478]132
[9e9100]133 /** Getter to molecule's selected status.
134 *
135 * \return true - molecule selected, false - else
136 */
137 const bool& getMolSelected() const;
138
[494478]139 static const molecule * const getMolecule(const moleculeId_t _id);
140
[0070aa]141signals:
[1b6415a]142 void atomcountChanged();
[5a9e34]143 void bondcountChanged();
[1b6415a]144 void formulaChanged();
[1c0961]145 void indexChanged(const moleculeId_t, const moleculeId_t);
[494478]146 void nameChanged();
[5a9e34]147 void nononhydrogenChanged();
148 void centerChanged();
[494478]149 void tesselationhullChanged();
150 void boundingboxChanged();
[96e145]151 void atomInserted(QtObservedAtom::ptr, QtObservedMolecule *);
152 void atomRemoved(const atomId_t, QtObservedMolecule *);
[5a9e34]153 void moleculeRemoved();
[9e9100]154 void selectedChanged();
[494478]155
156private:
157
158 void activateObserver();
159 void deactivateObserver();
160
161private:
[1b6415a]162 static int updateAtomCount(
163 const boost::function<const moleculeId_t ()> &_getMolIndex);
[5a9e34]164 static int updateBondCount(
165 const boost::function<const moleculeId_t ()> &_getMolIndex);
[494478]166 static molecule::BoundingBoxInfo updateBoundingBox(
167 const boost::function<const moleculeId_t ()> &_getMolIndex);
[1b6415a]168 static std::string updateFormulaString(
169 const boost::function<const moleculeId_t ()> &_getMolIndex);
[5a9e34]170 static Vector updateCenter(
171 const boost::function<const moleculeId_t ()> &_getMolIndex);
[494478]172 static moleculeId_t updateIndex();
173 static std::string updateName(
174 const boost::function<const moleculeId_t ()> &_getMolIndex);
[5a9e34]175 static int updateNonHydrogenCount(
176 const boost::function<const moleculeId_t ()> &_getMolIndex);
[9e9100]177 static bool updateSelected(
178 const boost::function<const moleculeId_t ()> &_getMolIndex);
[494478]179
[1b6415a]180 //!> list of channels when atom count needs to update
181 static const Observable::channels_t AtomCountChannels;
[5a9e34]182 //!> list of channels when bond count needs to update
183 static const Observable::channels_t BondCountChannels;
[494478]184 //!> list of channels when bounding box needs to update
185 static const Observable::channels_t BoundingBoxChannels;
[1b6415a]186 //!> list of channels when formula needs to update
187 static const Observable::channels_t FormulaStringChannels;
[5a9e34]188 //!> list of channels when the center needs to update
189 static const Observable::channels_t CenterChannels;
[494478]190 //!> list of channels when the index needs to update
191 static const Observable::channels_t IndexChannels;
192 //!> list of channels when the name needs to update
193 static const Observable::channels_t NameChannels;
[5a9e34]194 //!> list of channels when the name needs to update
195 static const Observable::channels_t NonHydrogenCountChannels;
[9e9100]196 //!> list of channels when the name needs to update
197 static const Observable::channels_t SelectedChannels;
[494478]198
199private:
200 /** Observed Values **/
201
202 //!> enumeration of observed values to match with entries in ObservedValues
203 enum ObservedTypes {
[04c3a3]204 //!> contains the current molecule index
205 MolIndex,
[1b6415a]206 //!> contains the current molecule's atom count
207 AtomCount,
[5a9e34]208 //!> contains the current molecule's number of bonds
209 BondCount,
210 //!> contains newest version of the bounding box on request
211 BoundingBox,
[1b6415a]212 //!> contains the current molecule's formula
213 FormulaString,
[5a9e34]214 //!> contains the current molecule's center
215 MolCenter,
[494478]216 //!> contains the current molecule name
217 MolName,
[5a9e34]218 //!> contains the current molecule's non-hydrogen atom count
219 NonHydrogenCount,
[9e9100]220 //!> contains the current molecule's selection status
221 MolSelected,
[494478]222 //!> gives the size of the enumeration
223 MAX_ObservedTypes
224 };
225
226 /** Initializes all \a _ObservedValues entries.
227 *
228 * \param _ObservedValues vector of ObservedValue to be filled
229 * \param _moid molecule id
230 * \param _molref reference to molecule
231 * \param _subjectKilled ref to function to call on subjectKilled()
232 */
233 static void initObservedValues(
234 ObservedValues_t &_ObservedValues,
235 const moleculeId_t _molid,
236 const molecule * const _molref,
237 const boost::function<void(const moleculeId_t)> &_subjectKilled);
[0070aa]238
[494478]239 /** Destroys all \a ObservedValues entries.
240 *
241 * \param _ObservedValues vector of ObservedValue to be destroyed
242 */
243 static void destroyObservedValues(
244 std::vector<boost::any> &_ObservedValues);
[0070aa]245
[04c3a3]246 /** Function is called by InstanceBoard to inform about its destruction.
247 *
248 * \note callbacks must not be used after this
249 */
250 void noteBoardIsGone()
251 { BoardIsGone = true; }
252
[62a0ee]253
254 /** Counts the number of subject killed received from the observed values.
255 *
256 * \param _id id to check against ours
257 */
258 void countValuesSubjectKilled(const atomId_t _id);
259
[494478]260 //!> counts how many ObservedValues have already been subjectKilled()
261 mutable size_t subjectKilledCount;
[0070aa]262
[62a0ee]263 /** Helper function to check that all subjectKilled have been received for both
264 * this instance and all its internal observed values.
265 *
266 */
267 void checkForRemoval();
268
[0070aa]269private:
[494478]270
271 //!> we get multiple subjectKilled(), count and call callback() only on last
272 const unsigned int AllsignedOnChannels;
273 unsigned int signedOffChannels;
274
275 //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
276 const Observable *owner;
277
278private:
[1c0961]279 //!> contains still the old index after the index changed
280 moleculeId_t oldId;
[494478]281
282 //!> reference to InstanceBoard for callbacks on subjectKilled()
283 QtObservedInstanceBoard & board;
284
[04c3a3]285 //!> is board still alive or not, impacts callbacks
286 bool BoardIsGone;
287
[98c35c]288 //!> internal reference to ObservedValues held by QtObservedInstanceBoard
[494478]289 ObservedValues_t ObservedValues;
[0070aa]290};
291
292
293#endif /* QTOBSERVEDMOLECULE_HPP_ */
Note: See TracBrowser for help on using the repository browser.