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

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

FIX: Added update mechanism to GLWorldScene when WorldTime changes.

  • bonds were not updated when WorldTime changed, atoms only change because each was subscribed to WorldTime.
  • Now, just GLWorldView is subscribed to WorldTime::TimeChanged, emitting TimeChanged and activating GLWorldScene::updated() signal.
  • GLWorldScene has access to private reset..() functions of GLMoleculeObject_atom and GLMoleculeObject_bond.
  • added GLWorldScene::update(), enhancing (also modified) ::init() function. It does not use molecules anymore, but directly the World's atoms. These are iterated over, checked whether already present and updated or added. Similarly with bonds. update() is activated on signal updated().
  • Property mode set to 100644
File size: 7.5 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
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/>.
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"
43#include "CodePatterns/Log.hpp"
44#include "CodePatterns/Observer/Notification.hpp"
45
46#include "Atom/atom.hpp"
47#include "Bond/bond.hpp"
48#include "Descriptors/AtomIdDescriptor.hpp"
49#include "Element/element.hpp"
50#include "LinearAlgebra/Vector.hpp"
51#include "GLMoleculeObject_bond.hpp"
52#include "World.hpp"
53#include "WorldTime.hpp"
54
55GLMoleculeObject_atom::GLMoleculeObject_atom(QGLSceneNode *mesh[], QObject *parent, const atomId_t _id) :
56 GLMoleculeObject(mesh, parent),
57 Observer(std::string("GLMoleculeObject_atom")+toString(_id)),
58 atomicid(_id)
59{
60 // sign on as observer (obtain non-const instance before)
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 }
70 World::getInstance().signOn(this, World::SelectionChanged);
71
72 // set the object's id
73 resetProperties();
74
75 LOG(2, "INFO: Created sphere for atom " << atomicid << ".");
76
77 connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));
78}
79
80GLMoleculeObject_atom::~GLMoleculeObject_atom()
81{
82 const atom *_atom = World::getInstance().getAtom(AtomById(atomicid));
83 if (_atom != NULL){
84 _atom->signOff(this, AtomObservable::IndexChanged);
85 _atom->signOff(this, AtomObservable::PositionChanged);
86 _atom->signOff(this, AtomObservable::ElementChanged);
87 _atom->signOff(this, AtomObservable::BondsAdded);
88 }
89 World::getInstance().signOff(this, World::SelectionChanged);
90}
91
92void GLMoleculeObject_atom::update(Observable *publisher)
93{
94#ifdef LOG_OBSERVER
95 observerLog().addMessage() << "++ Update of Observer " << observerLog().getName(static_cast<Observer *>(this)) << " from atom "+toString(atomicid)+".";
96#endif
97 resetProperties();
98}
99
100void GLMoleculeObject_atom::resetPosition()
101{
102 const atom *_atom = World::getInstance().getAtom(AtomById(atomicid));
103 if (_atom != NULL) {
104 const Vector Position = _atom->getPosition();
105 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new position is "+toString(Position)+".");
106 setPosition(QVector3D(Position[0], Position[1], Position[2]));
107 } else {
108 ELOG(2, "Atom with id "+toString(atomicid)+" is already gone.");
109 }
110}
111
112void GLMoleculeObject_atom::resetElement()
113{
114 size_t elementno = 0;
115 const atom *_atom = World::getInstance().getAtom(AtomById(atomicid));
116 const element *_type = NULL;
117 if (_atom != NULL) {
118 _type = _atom->getType();
119 } else {
120 ELOG(2, "Atom with id "+toString(atomicid)+" is already gone.");
121 }
122 if (_type != NULL) {
123 elementno = _type->getAtomicNumber();
124 } else { // if no element yet, set to hydrogen
125 elementno = 1;
126 }
127 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new element number is "+toString(elementno)+".");
128
129 // set materials
130 QGLMaterial *elementmaterial = getMaterial(elementno);
131 ASSERT(elementmaterial != NULL,
132 "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function is NULL.");
133 setMaterial(elementmaterial);
134
135 // set scale
136 double radius = 0.;
137 if (_type != NULL) {
138 radius = _type->getVanDerWaalsRadius();
139 } else {
140 radius = 0.5;
141 }
142 setScale( radius / 4. );
143}
144
145void GLMoleculeObject_atom::resetIndex()
146{
147 int oldId = objectId();
148 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new index is "+toString(atomicid)+".");
149 setObjectId(atomicid);
150
151 emit indexChanged(this, oldId, atomicid);
152}
153
154void GLMoleculeObject_atom::resetProperties()
155{
156 // set position
157 resetPosition();
158
159 // set element
160 resetElement();
161
162 // set the object's id
163 resetIndex();
164
165 // selected?
166 setSelected(World::getInstance().isAtomSelected(atomicid));
167}
168
169void GLMoleculeObject_atom::subjectKilled(Observable *publisher)
170{
171 // remove id such that we don't sign off accidentally from a different atom
172 const_cast<atomId_t &>(atomicid) = -1;
173}
174
175void GLMoleculeObject_atom::recieveNotification(Observable *publisher, Notification_ptr notification)
176{
177 const atom *_atom = World::getInstance().getAtom(AtomById(atomicid));
178 if (publisher == dynamic_cast<const Observable*>(_atom)){
179 // notofication from atom
180#ifdef LOG_OBSERVER
181 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this))
182 << " received notification from atom " << _atom->getId() << " for channel "
183 << notification->getChannelNo() << ".";
184#endif
185 switch (notification->getChannelNo()) {
186 case AtomObservable::ElementChanged:
187 resetElement();
188 emit changed();
189 break;
190 case AtomObservable::IndexChanged:
191 resetIndex();
192 break;
193 case AtomObservable::PositionChanged:
194 resetPosition();
195 emit changed();
196 break;
197 case AtomObservable::BondsAdded:
198 {
199 const atom *_atom = World::getInstance().getAtom(AtomById(atomicid));
200 if (_atom != NULL) {
201 ASSERT(!_atom->getListOfBonds().empty(),
202 "GLMoleculeObject_atom::recieveNotification() - received BondsAdded but ListOfBonds is empty.");
203 const bond::ptr _bond = *(_atom->getListOfBonds().rbegin());
204 const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == _atom) ?
205 GLMoleculeObject_bond::left : GLMoleculeObject_bond::right;
206 emit BondsInserted(_bond, side);
207 } else {
208 ELOG(2, "Atom with id "+toString(atomicid)+" is already gone.");
209 }
210 break;
211 }
212 default:
213 //setProperties();
214 break;
215 }
216 }else if (static_cast<World *>(publisher) == World::getPointer()) {
217 // notification from world
218#ifdef LOG_OBSERVER
219 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this))
220 << " received notification from world for channel "
221 << notification->getChannelNo() << ".";
222#endif
223 switch (notification->getChannelNo()) {
224 case World::SelectionChanged:
225 setSelected(World::getInstance().isSelected(_atom));
226 break;
227 default:
228 break;
229 }
230 }
231}
232
233void GLMoleculeObject_atom::wasClicked()
234{
235 LOG(4, "INFO: GLMoleculeObject_atom: atom " << atomicid << " has been clicked");
236 emit clicked(atomicid);
237}
Note: See TracBrowser for help on using the repository browser.