source: src/UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp@ 96e145

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

FIX: indexChanged from QtObserved... transmit both old and new id.

  • Property mode set to 100644
File size: 7.9 KB
RevLine 
[0070aa]1/*
2 * QtObservedAtom.hpp
3 *
4 * Created on: Oct 28, 2015
5 * Author: heber
6 */
7
8
9#ifndef QTOBSERVEDATOM_HPP_
10#define QTOBSERVEDATOM_HPP_
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include <QtGui/QWidget>
18
[65c323]19#include <boost/function.hpp>
[98c35c]20#include <boost/shared_ptr.hpp>
[0070aa]21
[65c323]22#include "CodePatterns/Observer/Observable.hpp"
[0070aa]23#include "CodePatterns/Observer/Observer.hpp"
24
[65c323]25#include "LinearAlgebra/Vector.hpp"
26
[98c35c]27#include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
[41e287]28#include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp"
[0070aa]29#include "types.hpp"
30
[65c323]31class atom;
[98c35c]32class QtObservedInstanceBoard;
33
[0070aa]34/** This instance is the ObservedValue representation of a World's atom.
35 *
36 * Due to the signal/slot mechanism and its delays, lifetime of objects in the
37 * World and their QtGui representation cannot directly be related (without
38 * slowing down Actions just for having the representation up to speed).
39 * Hence, the required information for displaying and representing these
40 * objects must be contained in an extra instance.
41 *
42 * This is the instance for information about a particular atom.
[65c323]43 *
44 * Essentially, this is the interface between molecuilder's World (and a
45 * particular atom) and the QtGui part of the code.
[0070aa]46 */
47class QtObservedAtom : public QWidget, public Observer
48{
49 Q_OBJECT
50
[65c323]51public:
52
53 //!> typedef for instance wrapped in shared ptr
54 typedef boost::shared_ptr<QtObservedAtom> ptr;
55
56private:
[41e287]57 //!> ObservedValuesContainer needs to access private cstor and dstor
58 friend class ObservedValuesContainer<QtObservedAtom, atomId_t>;
[98c35c]59 //!> QtObservedInstanceBoard needs to access private cstor and dstor
60 friend class QtObservedInstanceBoard;
61
[0070aa]62 /** Cstor of QtObservedAtom.
63 *
[62a0ee]64 * \param _id id of observed atom
65 * \param _atom ref to observed atom
[65c323]66 * \param _board ref to InstanceBoard for callbacks on occasion of subjectKilled()
[0070aa]67 * \param _parent Qt parent to automatically destroy when parent is destroyed
68 */
[98c35c]69 QtObservedAtom(
[62a0ee]70 const atomId_t _id,
71 const atom * const _atom,
[65c323]72 QtObservedInstanceBoard &_board,
[98c35c]73 QWidget * _parent=0);
74
75public:
[0070aa]76
77 /** Dstor of QtObservedAtom.
78 *
79 */
80 ~QtObservedAtom();
81
[98c35c]82 // Observer functions
83 void update(Observable *publisher);
84 void subjectKilled(Observable *publisher);
85 void recieveNotification(Observable *publisher, Notification_ptr notification);
86
[65c323]87 /** Getter to atom index contained in \a ObservedValues.
88 *
89 * \return atom's index
90 */
[3b9aa1]91 const atomId_t& getAtomIndex() const;
[65c323]92
[fe493f]93 //!> typedef for list of bonds, defined by pairs of atom ids
94 typedef std::vector< std::pair<atomId_t, atomId_t> > ListOfBonds_t;
95
96 /** Getter to atom bonds contained in \a ObservedValues.
[65c323]97 *
[fe493f]98 * \return atom's bonds
[65c323]99 */
[3b9aa1]100 const ListOfBonds_t& getAtomBonds() const;
[65c323]101
102 /** Getter to atom element contained in \a ObservedValues.
103 *
[fe493f]104 * \return atom's element
[65c323]105 */
[3b9aa1]106 const atomicNumber_t& getAtomElement() const;
[65c323]107
[fe493f]108 /** Getter to atom name contained in \a ObservedValues.
109 *
110 * \return atom's name
111 */
[3b9aa1]112 const std::string& getAtomName() const;
[65c323]113
[fe493f]114 /** Getter to atom position contained in \a ObservedValues.
[65c323]115 *
[fe493f]116 * \return atom's position
[65c323]117 */
[3b9aa1]118 const Vector& getAtomPosition() const;
[fe493f]119
120 /** Getter to atom's molecule index contained in \a ObservedValues.
121 *
122 * \return atom's molecule index
123 */
[3b9aa1]124 const moleculeId_t& getAtomMoleculeIndex() const;
[65c323]125
[9e9100]126 /** Getter to atom's selected status.
127 *
128 * \return true - atom selected, false - else
129 */
130 const bool getAtomSelected() const;
131
[0070aa]132signals:
[1c0961]133 void indexChanged(const atomId_t, const atomId_t);
[65c323]134 void bondsChanged();
[fe493f]135 void elementChanged();
136 void moleculeindexChanged();
137 void nameChanged();
138 void positionChanged();
139 void atomRemoved();
[9e9100]140 void selectedChanged();
[65c323]141
142//private slots:
[0070aa]143
[65c323]144private:
145 void activateObserver();
146 void deactivateObserver();
[0070aa]147
[65c323]148 static const atom * const getAtomConst(const atomId_t _id);
149 static atom * const getAtom(const atomId_t _id);
[0070aa]150
151private:
[65c323]152 static atomId_t updateIndex();
[fe493f]153 static ListOfBonds_t updateBonds(
[65c323]154 const boost::function<const atomId_t ()> &_getAtomIndex);
155 static atomicNumber_t updateElement(
156 const boost::function<const atomId_t ()> &_getAtomIndex);
[fe493f]157 static moleculeId_t updateMoleculeIndex(
158 const boost::function<const atomId_t ()> &_getAtomIndex);
159 static std::string updateName(
160 const boost::function<const atomId_t ()> &_getAtomIndex);
161 static Vector updatePosition(
[65c323]162 const boost::function<const atomId_t ()> &_getAtomIndex);
[9e9100]163 static bool updateSelected(
164 const boost::function<const atomId_t ()> &_getAtomIndex);
[65c323]165
166 //!> enumeration of observed values to match with entries in ObservedValues
167 enum ObservedTypes {
168 //!> contains the current atom index
169 AtomIndex,
[fe493f]170 //!> contains the current set of bonds atoms for the atom
171 AtomBonds,
[65c323]172 //!> contains the current atom element
173 AtomElement,
[fe493f]174 //!> contains the current atom's molecule index
175 AtomMoleculeIndex,
176 //!> contains the current atom position
177 AtomName,
178 //!> contains the current atom position
179 AtomPosition,
[9e9100]180 //!> contains the current atom's selection status
181 AtomSelected,
[65c323]182 //!> gives the size of the enumeration
183 MAX_ObservedTypes
184 };
185
186 /** Initializes all \a ObservedValues entries.
187 *
188 * \param _ObservedValues vector of ObservedValue to be filled
189 * \param _id atom id
190 * \param _atomref reference to atom
191 * \param _subjectKilled ref to function to call on subjectKilled()
192 */
[62a0ee]193 void initObservedValues(
[65c323]194 ObservedValues_t &_ObservedValues,
195 const atomId_t _id,
196 const atom * const _atomref,
197 const boost::function<void(const atomId_t)> &_subjectKilled);
198
199 /** Destroys all \a ObservedValues entries.
200 *
201 * \param _ObservedValues vector of ObservedValue to be destroyed
202 */
203 static void destroyObservedValues(
204 std::vector<boost::any> &_ObservedValues);
205
[04c3a3]206 /** Function is called by InstanceBoard to inform about its destruction.
207 *
208 * \note callbacks must not be used after this
209 */
210 void noteBoardIsGone()
211 { BoardIsGone = true; }
212
[62a0ee]213 /** Counts the number of subject killed received from the observed values.
214 *
215 * \param _id id to check against ours
216 */
217 void countValuesSubjectKilled(const atomId_t _id);
218
[65c323]219 //!> counts how many ObservedValues have already been subjectKilled()
220 mutable size_t subjectKilledCount;
221
[62a0ee]222 /** Helper function to check that all subjectKilled have been received for both
223 * this instance and all its internal observed values.
224 *
225 */
226 void checkForRemoval();
227
[65c323]228private:
229
230 //!> list of channels when index needs to update
231 static const Observable::channels_t AtomIndexChannels;
232 //!> list of channels when bonds needs to update
233 static const Observable::channels_t AtomBondsChannels;
[fe493f]234 //!> list of channels when element needs to update
235 static const Observable::channels_t AtomElementChannels;
236 //!> list of channels when molecule index needs to update
237 static const Observable::channels_t AtomMoleculeIndexChannels;
238 //!> list of channels when name needs to update
239 static const Observable::channels_t AtomNameChannels;
240 //!> list of channels when position needs to update
241 static const Observable::channels_t AtomPositionChannels;
[9e9100]242 //!> list of channels when selection needs to update
243 static const Observable::channels_t AtomSelectedChannels;
[65c323]244
245 //!> we get multiple subjectKilled(), count and call callback() only on last
246 const unsigned int AllsignedOnChannels;
247 unsigned int signedOffChannels;
248
249 //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
250 const Observable *owner;
251
252private:
[1c0961]253 //!> contains still the old id after the index of the atom changed
254 atomId_t oldId;
[65c323]255
256 //!> reference to InstanceBoard for callbacks on subjectKilled()
257 QtObservedInstanceBoard & board;
258
[04c3a3]259 //!> is board still alive or not, impacts callbacks
260 bool BoardIsGone;
261
[98c35c]262 //!> internal reference to ObservedValues held by QtObservedInstanceBoard
[65c323]263 ObservedValues_t ObservedValues;
[0070aa]264};
265
266
267#endif /* QTOBSERVEDATOM_HPP_ */
Note: See TracBrowser for help on using the repository browser.