source: src/UIElements/Views/Qt4/QtInstanceInformationBoard.cpp@ 47f0e4

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 47f0e4 was 15c8a9, checked in by Frederik Heber <heber@…>, 9 years ago

Added QtInstanceInformationBoard that handles ObservedValues through the QtGui interface.

  • this is meant as a instantiator of all ObservedValue's needed by QtGui for representing information from the World. The ObservedValue's are instantiated separately w.r.t. to the instance for the visual representation. This is light-weight and can be performed in the same thread, while the visual representation's instantiation can be done elsewhere and there we just need to access the ready ObservedValue's that exist as long as they are needed by the QtGui.
  • Property mode set to 100644
File size: 16.4 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 * QtInstanceInformationBoard.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 "QtInstanceInformationBoard.hpp"
37
38#include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp"
39#include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp"
40
41#include "CodePatterns/MemDebug.hpp"
42
43#include "CodePatterns/Log.hpp"
44
45#include "Atom/atom.hpp"
46#include "Descriptors/AtomIdDescriptor.hpp"
47#include "Descriptors/MoleculeIdDescriptor.hpp"
48#include "molecule.hpp"
49#include "World.hpp"
50
51QtInstanceInformationBoard::QtInstanceInformationBoard(QWidget * _parent) :
52 QWidget(_parent),
53 Observer("QtInstanceInformationBoard"),
54 WorldSignedOn(false),
55 atomSubjectKilled(
56 boost::bind(&QtInstanceInformationBoard::atomcountsubjectKilled, this, _1)),
57 moleculeSubjectKilled(
58 boost::bind(&QtInstanceInformationBoard::moleculecountsubjectKilled, this, _1)),
59 lastremovedatom((atomId_t)-1),
60 lastremovedmolecule((moleculeId_t)-1)
61{
62 // be first (besides ObservedValues to know about new insertions)
63 World::getInstance().signOn(this, World::AtomInserted, GlobalObservableInfo::PriorityLevel(int(-10)));
64 World::getInstance().signOn(this, World::AtomRemoved, GlobalObservableInfo::PriorityLevel(int(-10)));
65 World::getInstance().signOn(this, World::MoleculeInserted, GlobalObservableInfo::PriorityLevel(int(-10)));
66 World::getInstance().signOn(this, World::MoleculeRemoved, GlobalObservableInfo::PriorityLevel(int(-10)));
67 WorldSignedOn = true;
68}
69
70QtInstanceInformationBoard::~QtInstanceInformationBoard()
71{
72 if (WorldSignedOn) {
73 World::getInstance().signOff(this, World::AtomInserted);
74 World::getInstance().signOff(this, World::AtomRemoved);
75 World::getInstance().signOff(this, World::MoleculeInserted);
76 World::getInstance().signOff(this, World::MoleculeRemoved);
77 }
78 // sign off from all remaining molecules and atoms
79 for (SignedOn_t::iterator iter = AtomSignedOn.begin(); !AtomSignedOn.empty();
80 iter = AtomSignedOn.begin()) {
81 (*iter)->signOff(this, atom::IndexChanged);
82 AtomSignedOn.erase(iter);
83 }
84
85 for (SignedOn_t::iterator iter = MoleculeSignedOn.begin(); !MoleculeSignedOn.empty();
86 iter = MoleculeSignedOn.begin()) {
87 (*iter)->signOff(this, molecule::IndexChanged);
88 MoleculeSignedOn.erase(iter);
89 }
90}
91
92void QtInstanceInformationBoard::update(Observable *publisher)
93{
94 ASSERT(0,
95 "QtInstanceInformationBoard::update() - we are not signed on to general updates.");
96}
97
98void QtInstanceInformationBoard::subjectKilled(Observable *publisher)
99{
100 SignedOn_t::iterator iter = AtomSignedOn.find(publisher);
101 if ( iter != AtomSignedOn.end()) {
102 LOG(3, "DEBUG: InstanceBoard got subjectKilled() from atom " << publisher);
103 AtomSignedOn.erase(iter);
104 } else {
105 iter = MoleculeSignedOn.find(publisher);
106 if ( iter != MoleculeSignedOn.end()) {
107 LOG(3, "DEBUG: InstanceBoard got subjectKilled() from molecule " << publisher);
108 MoleculeSignedOn.erase(iter);
109 } else {
110 ASSERT(0,
111 "QtObservedInstanceBoard::subjectKilled() - could not find signedOn for atom/molecule "+toString(publisher));
112 }
113 }
114}
115
116void QtInstanceInformationBoard::recieveNotification(Observable *publisher, Notification_ptr notification)
117{
118 if (static_cast<World *>(publisher) == World::getPointer()) {
119 switch (notification->getChannelNo()) {
120 case World::MoleculeInserted:
121 {
122 const moleculeId_t _id = const_cast<const World &>(World::getInstance()).lastChangedMolId();
123 #ifdef LOG_OBSERVER
124 observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that molecule "+toString(_id)+" has been inserted.";
125 #endif
126 LOG(3, "DEBUG: InformationBoard got moleculeInserted signal for molecule " << _id);
127 const molecule * const _molecule = const_cast<const World &>(World::getInstance()).
128 getMolecule(MoleculeById(_id));
129 if (_molecule != NULL) {
130 ObservedValues_t ObservedValues(GLMoleculeObject_molecule::MAX_ObservedTypes);
131 LOG(3, "DEBUG: InformationBoard initializes ObservedValues for molecule " << _id);
132 GLMoleculeObject_molecule::initObservedValues(
133 ObservedValues,
134 _id,
135 _molecule,
136 moleculeSubjectKilled);
137#ifndef NDEBUG
138 std::pair<moleculeObservedValues_t::iterator, bool> inserter =
139#endif
140 moleculeObservedValues.insert(
141 std::make_pair( _id, ObservedValues));
142 ASSERT( inserter.second,
143 "QtInstanceInformationBoard::recieveNotification() - could not insert ObservedValues for"
144 +toString(_id)+".");
145 // we need to check for index changes
146 LOG(3, "DEBUG: InformationBoard signOn()s to molecule " << _id);
147 _molecule->signOn(this, molecule::IndexChanged);
148 MoleculeSignedOn.insert( static_cast<Observable *>(const_cast<molecule *>(_molecule)) );
149
150 emit moleculeInserted(_id);
151 } else {
152 ELOG(1, "QtInstanceInformationBoard got MoleculeInserted for unknown molecule id " << _id);
153 }
154 break;
155 }
156 case World::MoleculeRemoved:
157 {
158 const moleculeId_t _id = const_cast<const World &>(World::getInstance()).lastChangedMolId();
159 LOG(3, "DEBUG: InformationBoard got MoleculeRemoved signal for molecule " << _id);
160 // note down such that ObservedValues are simply dropped
161 lastremovedmolecule = _id;
162 break;
163 }
164 case World::AtomInserted:
165 {
166 const atomId_t _id = const_cast<const World &>(World::getInstance()).lastChangedAtomId();
167 #ifdef LOG_OBSERVER
168 observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+" has been inserted.";
169 #endif
170 LOG(3, "DEBUG: InformationBoard got atomInserted signal for atom " << _id);
171 const atom * const _atom = const_cast<const World &>(World::getInstance()).
172 getAtom(AtomById(_id));
173 if (_atom!= NULL) {
174 ObservedValues_t ObservedValues(GLMoleculeObject_atom::MAX_ObservedTypes);
175 LOG(3, "DEBUG: InformationBoard initializes ObservedValues for atom " << _id);
176 GLMoleculeObject_atom::initObservedValues(
177 ObservedValues,
178 _id,
179 _atom,
180 atomSubjectKilled);
181#ifndef NDEBUG
182 std::pair<atomObservedValues_t::iterator, bool> inserter =
183#endif
184 atomObservedValues.insert(
185 std::make_pair( _id, ObservedValues));
186 ASSERT( inserter.second,
187 "QtInstanceInformationBoard::recieveNotification() - could not insert ObservedValues for"
188 +toString(_id)+".");
189 // we need to check for index changes
190 LOG(3, "DEBUG: InformationBoard signOn()s to atom " << _id);
191 _atom->signOn(this, atom::IndexChanged);
192 AtomSignedOn.insert( static_cast<Observable *>(const_cast<atom *>(_atom)) );
193 } else {
194 ELOG(1, "QtInstanceInformationBoard got AtomInserted for unknown atom id " << _id);
195 }
196 break;
197 }
198 case World::AtomRemoved:
199 {
200 const atomId_t _id = const_cast<const World &>(World::getInstance()).lastChangedAtomId();
201 LOG(3, "DEBUG: InformationBoard got AtomRemoved signal for atom " << _id);
202 // note down such that ObservedValues are simply dropped
203 lastremovedatom = _id;
204 break;
205 }
206 default:
207 ASSERT(0, "QtInstanceInformationBoard::recieveNotification() - we cannot get here for World.");
208 break;
209 }
210 } else if (dynamic_cast<molecule *>(publisher) != NULL) {
211 const moleculeId_t molid = const_cast<const World &>(World::getInstance()).lastChangedMolId();
212 switch (notification->getChannelNo()) {
213 case molecule::AtomInserted:
214 {
215 const molecule * const _molecule = const_cast<const World &>(World::getInstance()).
216 getMolecule(MoleculeById(molid));
217 if (_molecule != NULL) {
218 const atomId_t atomid = const_cast<const molecule *>(_molecule)->lastChangedAtomId();
219 LOG(3, "DEBUG: InformationBoard got AtomInserted signal for atom "
220 << atomid << " from molecule " << molid);
221 // check whether atom's observedvalues are present
222 ASSERT( atomObservedValues.find(atomid) != atomObservedValues.end(),
223 "QtInstanceInformationBoard::recieveNotification() - ObservedValues for atom "
224 +toString(atomid)+" are not present yet.");
225 // and emit
226 emit atomInserted(molid, atomid);
227 } else {
228 ELOG(2, "QtInstanceInformationBoard::recieveNotification() - molecule "
229 << molid << " has disappeared.");
230 }
231 break;
232 }
233 case molecule::AtomRemoved:
234 {
235 const molecule * const _molecule = const_cast<const World &>(World::getInstance()).
236 getMolecule(MoleculeById(molid));
237 if (_molecule != NULL) {
238 const atomId_t atomid = const_cast<const molecule *>(_molecule)->lastChangedAtomId();
239 LOG(3, "DEBUG: InformationBoard got AtomRemoved signal for atom "
240 << atomid << " from molecule " << molid);
241 emit atomRemoved(molid, atomid);
242 }
243 break;
244 }
245 case molecule::IndexChanged:
246 {
247 // molecule has changed its index
248 const moleculeId_t newmoleculeId = dynamic_cast<molecule *>(publisher)->getId();
249 LOG(3, "DEBUG: InformationBoard got IndexChanged from molecule " << molid << " to " << newmoleculeId);
250 {
251 moleculeObservedValues_t::iterator iter = moleculeObservedValues.find(molid);
252 // change id here only if still present
253 if (iter != moleculeObservedValues.end()) {
254 ObservedValues_t obsvalues = iter->second;
255 moleculeObservedValues.erase(iter);
256 ASSERT( moleculeObservedValues.find(newmoleculeId) == moleculeObservedValues.end(),
257 "QtInstanceInformationBoard::recieveNotification() - ObservedValues for atom "
258 +toString(newmoleculeId)+" already present.");
259 moleculeObservedValues.insert( std::make_pair(newmoleculeId, obsvalues) );
260 // if (!inserter.second)
261 // ELOG(1, "QtInformationBoard could not insert molecule id change "
262 // << molid << "->" << newmoleculeId);
263 }
264 }
265 // no need update SignedOn, ref does not change
266 emit moleculeIndexChanged(molid, newmoleculeId);
267 break;
268 }
269 default:
270 ASSERT(0, "QtInstanceInformationBoard::recieveNotification() - we cannot get here.");
271 break;
272 }
273 } else if (dynamic_cast<atom *>(publisher) != NULL) {
274 const atomId_t oldatomId = const_cast<const World &>(World::getInstance()).lastChangedAtomId();
275 switch (notification->getChannelNo()) {
276 case AtomObservable::IndexChanged:
277 {
278 const atomId_t newatomId = dynamic_cast<atom *>(publisher)->getId();
279 LOG(3, "DEBUG: InformationBoard got IndexChanged from atom " << oldatomId << " to " << newatomId);
280 // update atomObservedValues
281 {
282 atomObservedValues_t::iterator iter = atomObservedValues.find(oldatomId);
283 // change id here only if still present
284 if (iter != atomObservedValues.end()) {
285 ObservedValues_t obsvalues = iter->second;
286 atomObservedValues.erase(iter);
287 ASSERT( atomObservedValues.find(newatomId) == atomObservedValues.end(),
288 "QtInstanceInformationBoard::recieveNotification() - ObservedValues for atom "
289 +toString(newatomId)+" already present.");
290 atomObservedValues.insert( std::make_pair(newatomId, obsvalues) );
291 // if (!inserter.second)
292 // ELOG(1, "QtInformationBoard could not insert atom id change "
293 // << oldatomId << "->" << newatomId);
294 }
295 }
296 // no need update SignedOn, ref does not change
297 emit atomIndexChanged(oldatomId, newatomId);
298 break;
299 }
300 default:
301 ASSERT(0, "QtInstanceInformationBoard::recieveNotification() - we cannot get here.");
302 break;
303 }
304 } else {
305 ASSERT(0, "QtInstanceInformationBoard::recieveNotification() - notification from unknown source.");
306 }
307}
308
309void QtInstanceInformationBoard::atomcountsubjectKilled(const atomId_t _atomid)
310{
311 LOG(3, "DEBUG: InformationBoard got subjectKilled() for a value of atom " << _atomid);
312 atomsubjectKilledCount_t::iterator iter = atomsubjectKilledCount.find(_atomid);
313 if (iter == atomsubjectKilledCount.end()) {
314 std::pair<atomsubjectKilledCount_t::iterator, bool> inserter =
315 atomsubjectKilledCount.insert( std::make_pair(_atomid, 0) );
316 iter = inserter.first;
317 }
318 ++(iter->second);
319
320 if (iter->second > GLMoleculeObject_atom::MAX_ObservedTypes) {
321 atomsubjectKilledCount.erase(iter);
322 }
323}
324
325void QtInstanceInformationBoard::moleculecountsubjectKilled(const moleculeId_t _molid)
326{
327 LOG(3, "DEBUG: InformationBoard got subjectKilled() for a value of molecule " << _molid);
328 moleculesubjectKilledCount_t::iterator iter = moleculesubjectKilledCount.find(_molid);
329 if (iter == moleculesubjectKilledCount.end()) {
330 std::pair<moleculesubjectKilledCount_t::iterator, bool> inserter =
331 moleculesubjectKilledCount.insert( std::make_pair(_molid, 0) );
332 iter = inserter.first;
333 }
334 ++(iter->second);
335
336 if (iter->second > GLMoleculeObject_molecule::MAX_ObservedTypes) {
337 // then free the instance
338 emit moleculeRemoved(_molid);
339 moleculesubjectKilledCount.erase(iter);
340 }
341}
342
343QtInstanceInformationBoard::ObservedValues_t
344QtInstanceInformationBoard::getAtomObservedValues(const atomId_t _id)
345{
346 ObservedValues_t returnvalues;
347 const atomObservedValues_t::iterator iter = atomObservedValues.find(_id);
348 ASSERT(iter != atomObservedValues.end(),
349 "QtInstanceInformationBoard::getAtomObservedValues() - atom values not present for id"
350 +toString(_id));
351 if (iter->first == _id) {
352 returnvalues = iter->second;
353 atomObservedValues.erase(iter);
354 }
355 return returnvalues;
356}
357
358QtInstanceInformationBoard::ObservedValues_t
359QtInstanceInformationBoard::getMoleculeObservedValues(const moleculeId_t _id)
360{
361 ObservedValues_t returnvalues;
362 const moleculeObservedValues_t::iterator iter = moleculeObservedValues.find(_id);
363 ASSERT(iter != moleculeObservedValues.end(),
364 "getMoleculeObservedValues::getAtomObservedValues() - molecule values not present for id"
365 +toString(_id));
366 if (iter->first == _id) {
367 returnvalues = iter->second;
368 moleculeObservedValues.erase(iter);
369 }
370 return returnvalues;
371}
372
373void QtInstanceInformationBoard::returnAtomObservedValues(
374 const atomId_t _id,
375 ObservedValues_t &_observedvalues)
376{
377 if (lastremovedatom != _id) {
378#ifndef NDEBUG
379 std::pair<atomObservedValues_t::iterator, bool> inserter =
380#endif
381 atomObservedValues.insert(
382 std::make_pair( _id, _observedvalues) );
383 ASSERT( inserter.second,
384 "QtInstanceInformationBoard::returnAtomObservedValues() - could not insert ObservedValues for"
385 +toString(_id)+".");
386 } else
387 lastremovedatom = (atomId_t)-1;
388}
389
390void QtInstanceInformationBoard::returnMoleculeObservedValues(
391 const moleculeId_t _id,
392 ObservedValues_t &_observedvalues)
393{
394 if (lastremovedmolecule != _id) {
395#ifndef NDEBUG
396 std::pair<moleculeObservedValues_t::iterator, bool> inserter =
397#endif
398 moleculeObservedValues.insert(
399 std::make_pair( _id, _observedvalues) );
400 ASSERT( inserter.second,
401 "QtInstanceInformationBoard::returnMoleculeObservedValues() - could not insert ObservedValues for"
402 +toString(_id)+".");
403 } else
404 lastremovedmolecule = (moleculeId_t)-1;
405}
Note: See TracBrowser for help on using the repository browser.