source: src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp@ ae68b5

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 ae68b5 was c60665, checked in by Frederik Heber <heber@…>, 11 years ago

Rewrote Observer structure of GLMoleculeObject_bond.

  • renamed leftatom/rightatom to ...observable to clarify what they are used for, and we check whether either is still there before signing off.
  • we have three instances to take care of: bond, leftatom, rightatom.
  • we signOn to each Observable as well to get noticed via subjectKilled().
  • we only use subjectKilled() where we signOff() from the other two and then from all Notifications.
  • GLWorldScene is informed via BondRemoved and actually deletes the GLMoleculeObject_bond instance.
  • we use booleans to indicate whether we are still connected and sign off via subjectKilled(), emitting BondRemoved, or in dstor, without emit.
  • we do not use BlockingQueuedConnection yet but as soon as threads are introcued.
  • Property mode set to 100644
File size: 8.1 KB
RevLine 
[907636]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[5aaa43]5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
[94d5ac6]6 *
7 *
8 * This file is part of MoleCuilder.
9 *
10 * MoleCuilder is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * MoleCuilder is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
[907636]22 */
23
24/*
25 * GLMoleculeObject_atom.cpp
26 *
27 * Created on: Aug 17, 2011
28 * Author: heber
29 */
30
31// include config.h
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36#include "GLMoleculeObject_atom.hpp"
37
38#include <Qt3D/qglscenenode.h>
39
40#include "CodePatterns/MemDebug.hpp"
41
42#include "CodePatterns/Assert.hpp"
[7188b1]43#include "CodePatterns/Log.hpp"
[02ce36]44#include "CodePatterns/Observer/Notification.hpp"
[907636]45
[2ad1ec]46#include "Atom/atom.hpp"
47#include "Bond/bond.hpp"
[7188b1]48#include "Descriptors/AtomIdDescriptor.hpp"
[3bdb6d]49#include "Element/element.hpp"
[907636]50#include "LinearAlgebra/Vector.hpp"
[2ad1ec]51#include "GLMoleculeObject_bond.hpp"
[7188b1]52#include "World.hpp"
[89b992]53#include "WorldTime.hpp"
[907636]54
[917659]55GLMoleculeObject_atom::GLMoleculeObject_atom(QGLSceneNode *mesh[], QObject *parent, const atomId_t _id) :
[bca99d]56 GLMoleculeObject(mesh, parent),
[917659]57 Observer(std::string("GLMoleculeObject_atom")+toString(_id)),
58 atomicid(_id)
[7188b1]59{
60 // sign on as observer (obtain non-const instance before)
[917659]61 const atom *_atom = World::getInstance().getAtom(AtomById(atomicid));
62 if (_atom != NULL) {
63 _atom->signOn(this, AtomObservable::IndexChanged);
64 _atom->signOn(this, AtomObservable::PositionChanged);
65 _atom->signOn(this, AtomObservable::ElementChanged);
66 _atom->signOn(this, AtomObservable::BondsAdded);
67 } else {
68 ELOG(2, "Atom with id "+toString(atomicid)+" is already gone.");
69 }
[d53902]70 World::getInstance().signOn(this, World::SelectionChanged);
[89b992]71 WorldTime::getInstance().signOn(this, WorldTime::TimeChanged);
[7188b1]72
73 // set the object's id
74 resetProperties();
75
[917659]76 LOG(2, "INFO: Created sphere for atom " << atomicid << ".");
[7188b1]77
78 connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));
79}
80
[9c18e4]81GLMoleculeObject_atom::~GLMoleculeObject_atom()
82{
[917659]83 const atom *_atom = World::getInstance().getAtom(AtomById(atomicid));
84 if (_atom != NULL){
[c736fe]85 _atom->signOff(this, AtomObservable::IndexChanged);
86 _atom->signOff(this, AtomObservable::PositionChanged);
87 _atom->signOff(this, AtomObservable::ElementChanged);
88 _atom->signOff(this, AtomObservable::BondsAdded);
89 }
[d53902]90 World::getInstance().signOff(this, World::SelectionChanged);
[89b992]91 WorldTime::getInstance().signOff(this, WorldTime::TimeChanged);
[9c18e4]92}
93
[7188b1]94void GLMoleculeObject_atom::update(Observable *publisher)
95{
[57a770]96#ifdef LOG_OBSERVER
[917659]97 observerLog().addMessage() << "++ Update of Observer " << observerLog().getName(static_cast<Observer *>(this)) << " from atom "+toString(atomicid)+".";
[57a770]98#endif
[7188b1]99 resetProperties();
100}
101
102void GLMoleculeObject_atom::resetPosition()
[907636]103{
[917659]104 const atom *_atom = World::getInstance().getAtom(AtomById(atomicid));
105 if (_atom != NULL) {
106 const Vector Position = _atom->getPosition();
107 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new position is "+toString(Position)+".");
108 setPosition(QVector3D(Position[0], Position[1], Position[2]));
109 } else {
110 ELOG(2, "Atom with id "+toString(atomicid)+" is already gone.");
111 }
[7188b1]112}
113
114void GLMoleculeObject_atom::resetElement()
115{
116 size_t elementno = 0;
[917659]117 const atom *_atom = World::getInstance().getAtom(AtomById(atomicid));
[c60665]118 const element *_type = NULL;
[917659]119 if (_atom != NULL) {
[c60665]120 _type = _atom->getType();
[7188b1]121 } else {
[917659]122 ELOG(2, "Atom with id "+toString(atomicid)+" is already gone.");
[7188b1]123 }
[c60665]124 if (_type != NULL) {
125 elementno = _type->getAtomicNumber();
126 } else { // if no element yet, set to hydrogen
127 elementno = 1;
128 }
129 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new element number is "+toString(elementno)+".");
130
131 // set materials
132 QGLMaterial *elementmaterial = getMaterial(elementno);
133 ASSERT(elementmaterial != NULL,
134 "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function is NULL.");
135 setMaterial(elementmaterial);
136
137 // set scale
138 double radius = 0.;
139 if (_type != NULL) {
140 radius = _type->getVanDerWaalsRadius();
141 } else {
142 radius = 0.5;
143 }
144 setScale( radius / 4. );
[7188b1]145}
146
147void GLMoleculeObject_atom::resetIndex()
148{
[30cd0d]149 int oldId = objectId();
[917659]150 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new index is "+toString(atomicid)+".");
151 setObjectId(atomicid);
[30cd0d]152
[917659]153 emit indexChanged(this, oldId, atomicid);
[7188b1]154}
155
156void GLMoleculeObject_atom::resetProperties()
157{
[907636]158 // set position
[7188b1]159 resetPosition();
[907636]160
[7188b1]161 // set element
162 resetElement();
[907636]163
164 // set the object's id
[7188b1]165 resetIndex();
[d53902]166
167 // selected?
[917659]168 setSelected(World::getInstance().isAtomSelected(atomicid));
[7188b1]169}
[907636]170
[7188b1]171void GLMoleculeObject_atom::subjectKilled(Observable *publisher)
[c736fe]172{
[917659]173 // remove id such that we don't sign off accidentally from a different atom
174 const_cast<atomId_t &>(atomicid) = -1;
[c736fe]175}
[06ebf5]176
[7188b1]177void GLMoleculeObject_atom::recieveNotification(Observable *publisher, Notification_ptr notification)
178{
[917659]179 const atom *_atom = World::getInstance().getAtom(AtomById(atomicid));
[d53902]180 if (publisher == dynamic_cast<const Observable*>(_atom)){
181 // notofication from atom
[57a770]182#ifdef LOG_OBSERVER
[708277]183 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this))
[d53902]184 << " received notification from atom " << _atom->getId() << " for channel "
185 << notification->getChannelNo() << ".";
[57a770]186#endif
[d53902]187 switch (notification->getChannelNo()) {
188 case AtomObservable::ElementChanged:
189 resetElement();
[5a2a06]190 emit changed();
[d53902]191 break;
192 case AtomObservable::IndexChanged:
193 resetIndex();
194 break;
195 case AtomObservable::PositionChanged:
196 resetPosition();
[5a2a06]197 emit changed();
[d53902]198 break;
199 case AtomObservable::BondsAdded:
[2ad1ec]200 {
[917659]201 const atom *_atom = World::getInstance().getAtom(AtomById(atomicid));
202 if (_atom != NULL) {
[d53902]203 ASSERT(!_atom->getListOfBonds().empty(),
204 "GLMoleculeObject_atom::recieveNotification() - received BondsAdded but ListOfBonds is empty.");
[88c8ec]205 const bond::ptr _bond = *(_atom->getListOfBonds().rbegin());
[d53902]206 const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == _atom) ?
207 GLMoleculeObject_bond::left : GLMoleculeObject_bond::right;
208 emit BondsInserted(_bond, side);
[917659]209 } else {
210 ELOG(2, "Atom with id "+toString(atomicid)+" is already gone.");
[d53902]211 }
[917659]212 break;
213 }
[d53902]214 default:
215 //setProperties();
216 break;
217 }
[89b992]218 }else if (static_cast<World *>(publisher) == World::getPointer()) {
[d53902]219 // notification from world
220#ifdef LOG_OBSERVER
[708277]221 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this))
[d53902]222 << " received notification from world for channel "
223 << notification->getChannelNo() << ".";
224#endif
225 switch (notification->getChannelNo()) {
226 case World::SelectionChanged:
227 setSelected(World::getInstance().isSelected(_atom));
228 break;
229 default:
[2ad1ec]230 break;
[d53902]231 }
[89b992]232 } else {
233 // notification from world
234#ifdef LOG_OBSERVER
235 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this))
236 << " received notification from Worldtime for channel "
237 << notification->getChannelNo() << ".";
238#endif
239 switch (notification->getChannelNo()) {
240 case WorldTime::TimeChanged:
241 resetPosition();
242 emit changed();
243 break;
244 default:
245 break;
246 }
[7188b1]247 }
[06ebf5]248}
249
250void GLMoleculeObject_atom::wasClicked()
251{
[917659]252 LOG(4, "INFO: GLMoleculeObject_atom: atom " << atomicid << " has been clicked");
253 emit clicked(atomicid);
[907636]254}
Note: See TracBrowser for help on using the repository browser.