source: src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.cpp@ 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 Candidate_v1.7.0 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@…>, 10 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: 13.0 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2015 Frederik Heber. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * QtObservedInstanceBoard.cpp
25 *
26 * Created on: Oct 17, 2015
27 * Author: heber
28 */
29
30
31// include config.h
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36#include "QtObservedInstanceBoard.hpp"
37
38#include <QtCore/QMetaType>
39
40#include "UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp"
41#include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp"
42
43#include "CodePatterns/MemDebug.hpp"
44
45#include <boost/bind.hpp>
46
47#include "CodePatterns/Log.hpp"
48
49#include "Atom/atom.hpp"
50#include "Descriptors/AtomIdDescriptor.hpp"
51#include "Descriptors/MoleculeIdDescriptor.hpp"
52#include "molecule.hpp"
53#include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer_impl.hpp"
54#include "World.hpp"
55
56QtObservedInstanceBoard::QtObservedInstanceBoard(QWidget * _parent) :
57 QWidget(_parent),
58 Observer("QtObservedInstanceBoard"),
59 WorldSignedOn(false),
60 atomObservedValues(
61 "atom",
62 *this,
63 boost::bind(&QtObservedInstanceBoard::atomcountsubjectKilled, this, _1)),
64 moleculeObservedValues(
65 "molecule",
66 *this,
67 boost::bind(&QtObservedInstanceBoard::moleculecountsubjectKilled, this, _1)),
68 atomSubjectKilled(
69 boost::bind(&ObservedValuesContainer<QtObservedAtom, atomId_t>::countsubjectKilled,
70 boost::ref(atomObservedValues),
71 _1)),
72 moleculeSubjectKilled(
73 boost::bind(&ObservedValuesContainer<QtObservedMolecule, moleculeId_t>::countsubjectKilled,
74 boost::ref(moleculeObservedValues),
75 _1)),
76 lastremovedatom((atomId_t)-1),
77 lastremovedmolecule((moleculeId_t)-1)
78{
79 qRegisterMetaType<QtObservedAtom::ptr>("QtObservedAtom::ptr");
80 qRegisterMetaType<QtObservedMolecule::ptr>("QtObservedMolecule::ptr");
81
82 // be first (besides ObservedValues to know about new insertions)
83 World::getInstance().signOn(this, World::AtomInserted, GlobalObservableInfo::PriorityLevel(int(-10)));
84 World::getInstance().signOn(this, World::AtomRemoved, GlobalObservableInfo::PriorityLevel(int(-10)));
85 World::getInstance().signOn(this, World::MoleculeInserted, GlobalObservableInfo::PriorityLevel(int(-10)));
86 World::getInstance().signOn(this, World::MoleculeRemoved, GlobalObservableInfo::PriorityLevel(int(-10)));
87 WorldSignedOn = true;
88}
89
90QtObservedInstanceBoard::~QtObservedInstanceBoard()
91{
92 if (WorldSignedOn) {
93 World::getInstance().signOff(this, World::AtomInserted);
94 World::getInstance().signOff(this, World::AtomRemoved);
95 World::getInstance().signOff(this, World::MoleculeInserted);
96 World::getInstance().signOff(this, World::MoleculeRemoved);
97 }
98 // sign off from all remaining molecules and atoms
99 for (SignedOn_t::iterator iter = AtomSignedOn.begin(); !AtomSignedOn.empty();
100 iter = AtomSignedOn.begin()) {
101 (*iter)->signOff(this, atom::IndexChanged);
102 AtomSignedOn.erase(iter);
103 }
104
105 for (SignedOn_t::iterator iter = MoleculeSignedOn.begin(); !MoleculeSignedOn.empty();
106 iter = MoleculeSignedOn.begin()) {
107 (*iter)->signOff(this, molecule::IndexChanged);
108 (*iter)->signOff(this, molecule::AtomInserted);
109 (*iter)->signOff(this, molecule::AtomRemoved);
110 MoleculeSignedOn.erase(*iter); //erase all instances
111 }
112}
113
114void QtObservedInstanceBoard::update(Observable *publisher)
115{
116 ASSERT(0,
117 "QtObservedInstanceBoard::update() - we are not signed on to general updates.");
118}
119
120void QtObservedInstanceBoard::subjectKilled(Observable *publisher)
121{
122 SignedOn_t::iterator iter = AtomSignedOn.find(publisher);
123 if ( iter != AtomSignedOn.end()) {
124 LOG(3, "DEBUG: InstanceBoard got subjectKilled() from atom " << publisher);
125 AtomSignedOn.erase(iter);
126 } else {
127 iter = MoleculeSignedOn.find(publisher);
128 if ( iter != MoleculeSignedOn.end()) {
129 LOG(3, "DEBUG: InstanceBoard got subjectKilled() from molecule " << publisher);
130 MoleculeSignedOn.erase(iter);
131 } else {
132 ASSERT(0,
133 "QtObservedInstanceBoard::subjectKilled() - could not find signedOn for atom/molecule "+toString(publisher));
134 }
135 }
136}
137
138void QtObservedInstanceBoard::recieveNotification(Observable *publisher, Notification_ptr notification)
139{
140 if (static_cast<World *>(publisher) == World::getPointer()) {
141 switch (notification->getChannelNo()) {
142 case World::MoleculeInserted:
143 {
144 const moleculeId_t _id = const_cast<const World &>(World::getInstance()).lastChangedMolId();
145 #ifdef LOG_OBSERVER
146 observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that molecule "+toString(_id)+" has been inserted.";
147 #endif
148 LOG(3, "DEBUG: InformationBoard got moleculeInserted signal for molecule " << _id);
149 const molecule * const _molecule = const_cast<const World &>(World::getInstance()).
150 getMolecule(MoleculeById(_id));
151 if (_molecule != NULL) {
152 ObservedValues_t ObservedValues(QtObservedMolecule::MAX_ObservedTypes);
153 LOG(3, "DEBUG: InformationBoard initializes ObservedValues for molecule " << _id);
154 QtObservedMolecule::initObservedValues(
155 ObservedValues,
156 _id,
157 _molecule,
158 moleculeSubjectKilled);
159 QtObservedMolecule::ptr observedmolecule(new QtObservedMolecule(ObservedValues, *this));
160 moleculeObservedValues.insert(_id, observedmolecule);
161 // we need to check for index changes
162 LOG(3, "DEBUG: InformationBoard signOn()s to molecule " << _id);
163 _molecule->signOn(this, molecule::IndexChanged);
164 MoleculeSignedOn.insert( static_cast<Observable *>(const_cast<molecule *>(_molecule)) );
165 _molecule->signOn(this, molecule::AtomInserted);
166 MoleculeSignedOn.insert( static_cast<Observable *>(const_cast<molecule *>(_molecule)) );
167 _molecule->signOn(this, molecule::AtomRemoved);
168 MoleculeSignedOn.insert( static_cast<Observable *>(const_cast<molecule *>(_molecule)) );
169
170 emit moleculeInserted(observedmolecule);
171 } else {
172 ELOG(1, "QtObservedInstanceBoard got MoleculeInserted for unknown molecule id " << _id);
173 }
174 break;
175 }
176 case World::MoleculeRemoved:
177 {
178 const moleculeId_t _id = const_cast<const World &>(World::getInstance()).lastChangedMolId();
179 LOG(3, "DEBUG: InformationBoard got MoleculeRemoved signal for molecule " << _id);
180 // note down such that ObservedValues are simply dropped
181 lastremovedmolecule = _id;
182 break;
183 }
184 case World::AtomInserted:
185 {
186 const atomId_t _id = const_cast<const World &>(World::getInstance()).lastChangedAtomId();
187 #ifdef LOG_OBSERVER
188 observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+" has been inserted.";
189 #endif
190 LOG(3, "DEBUG: InformationBoard got atomInserted signal for atom " << _id);
191 const atom * const _atom = const_cast<const World &>(World::getInstance()).
192 getAtom(AtomById(_id));
193 if (_atom!= NULL) {
194 ObservedValues_t ObservedValues(QtObservedAtom::MAX_ObservedTypes);
195 LOG(3, "DEBUG: InformationBoard initializes ObservedValues for atom " << _id);
196 QtObservedAtom::initObservedValues(
197 ObservedValues,
198 _id,
199 _atom,
200 atomSubjectKilled);
201 QtObservedAtom::ptr observedatom(new QtObservedAtom(ObservedValues, *this));
202 atomObservedValues.insert(_id, observedatom);
203 // we need to check for index changes
204 LOG(3, "DEBUG: InformationBoard signOn()s to atom " << _id);
205 _atom->signOn(this, atom::IndexChanged);
206 AtomSignedOn.insert( static_cast<Observable *>(const_cast<atom *>(_atom)) );
207 emit atomInserted(observedatom);
208 } else {
209 ELOG(1, "QtObservedInstanceBoard got AtomInserted for unknown atom id " << _id);
210 }
211 break;
212 }
213 case World::AtomRemoved:
214 {
215 const atomId_t _id = const_cast<const World &>(World::getInstance()).lastChangedAtomId();
216 LOG(3, "DEBUG: InformationBoard got AtomRemoved signal for atom " << _id);
217 // note down such that ObservedValues are simply dropped
218 lastremovedatom = _id;
219 break;
220 }
221 default:
222 ASSERT(0, "QtObservedInstanceBoard::recieveNotification() - we cannot get here for World.");
223 break;
224 }
225 } else if (dynamic_cast<molecule *>(publisher) != NULL) {
226 const moleculeId_t molid = const_cast<const World &>(World::getInstance()).lastChangedMolId();
227 switch (notification->getChannelNo()) {
228 case molecule::IndexChanged:
229 {
230 // molecule has changed its index
231 const moleculeId_t newmoleculeId = dynamic_cast<molecule *>(publisher)->getId();
232 LOG(3, "DEBUG: InformationBoard got IndexChanged from molecule " << molid << " to " << newmoleculeId);
233#ifndef NDEBUG
234 bool status =
235#endif
236 moleculeObservedValues.changeIdentifier(molid, newmoleculeId);
237 ASSERT( status,
238 "QtObservedInstanceBoard::recieveNotification() - cannot change molecule's id "
239 +toString(molid)+" "+toString(newmoleculeId)+" in moleculeObservedValues.");
240 // no need update SignedOn, ref does not change
241 emit moleculeIndexChanged(molid, newmoleculeId);
242 break;
243 }
244 default:
245 ASSERT(0, "QtObservedInstanceBoard::recieveNotification() - we cannot get here.");
246 break;
247 }
248 } else if (dynamic_cast<atom *>(publisher) != NULL) {
249 const atomId_t oldatomId = const_cast<const World &>(World::getInstance()).lastChangedAtomId();
250 switch (notification->getChannelNo()) {
251 case AtomObservable::IndexChanged:
252 {
253 const atomId_t newatomId = dynamic_cast<atom *>(publisher)->getId();
254 LOG(3, "DEBUG: InformationBoard got IndexChanged from atom " << oldatomId << " to " << newatomId);
255#ifndef NDEBUG
256 bool status =
257#endif
258 atomObservedValues.changeIdentifier(oldatomId, newatomId);
259 ASSERT( status,
260 "QtObservedInstanceBoard::recieveNotification() - cannot change atom's id "
261 +toString(oldatomId)+" "+toString(newatomId)+" in atomObservedValues.");
262 // no need update SignedOn, ref does not change
263 emit atomIndexChanged(oldatomId, newatomId);
264 break;
265 }
266 default:
267 ASSERT(0, "QtObservedInstanceBoard::recieveNotification() - we cannot get here.");
268 break;
269 }
270 } else {
271 ASSERT(0, "QtObservedInstanceBoard::recieveNotification() - notification from unknown source.");
272 }
273}
274
275void QtObservedInstanceBoard::atomcountsubjectKilled(const atomId_t _atomid)
276{
277 if ((_atomid == lastremovedatom)) {
278 LOG(3, "DEBUG: InstanceBoard emits atomRemoved for " << _atomid);
279 emit atomRemoved(lastremovedatom);
280 } else
281 ELOG(2, "QtObservedInstanceBoard::atomcountsubjectKilled() - id " << _atomid
282 << " not fitting with " << lastremovedatom);
283}
284
285void QtObservedInstanceBoard::moleculecountsubjectKilled(const moleculeId_t _molid)
286{
287 if (lastremovedmolecule == _molid) {
288 LOG(3, "DEBUG: InstanceBoard emits moleculeRemoved for " << _molid);
289 emit moleculeRemoved(_molid);
290 } else
291 ELOG(2, "QtObservedInstanceBoard::moleculecountsubjectKilled() - id " << _molid
292 << " not fitting with " << lastremovedmolecule);
293}
294
295QtObservedAtom::ptr QtObservedInstanceBoard::getObservedAtom(const atomId_t _id)
296{
297 return atomObservedValues.get(_id);
298}
299
300QtObservedMolecule::ptr QtObservedInstanceBoard::getObservedMolecule(const moleculeId_t _id)
301{
302 return moleculeObservedValues.get(_id);
303}
304
305void QtObservedInstanceBoard::markObservedAtomAsConnected(const atomId_t _id)
306{
307 atomObservedValues.markObservedValuesAsConnected(_id);
308}
309
310void QtObservedInstanceBoard::markObservedAtomAsDisconnected(const atomId_t _id)
311{
312 atomObservedValues.markObservedValuesAsDisconnected(_id);
313}
314
315void QtObservedInstanceBoard::markObservedAtomForErase(const atomId_t _id)
316{
317 atomObservedValues.eraseObservedValues(_id);
318}
319
320void QtObservedInstanceBoard::markObservedMoleculeAsConnected(const moleculeId_t _id)
321{
322 moleculeObservedValues.markObservedValuesAsConnected(_id);
323}
324
325void QtObservedInstanceBoard::markObservedMoleculeAsDisconnected(const moleculeId_t _id)
326{
327 moleculeObservedValues.markObservedValuesAsDisconnected(_id);
328}
329
330void QtObservedInstanceBoard::markObservedMoleculeForErase(const moleculeId_t _id)
331{
332 moleculeObservedValues.eraseObservedValues(_id);
333}
Note: See TracBrowser for help on using the repository browser.