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

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 d7e931 was 89b992, checked in by Frederik Heber <heber@…>, 12 years ago

GLWorldView now listens to World::TimeChanged() and updates view.

  • GLMoleculeObject_atom also listen to World::TimeChanged, required such that positions are updated, too. (Bonds are re-created, hence automatically updated).
  • Property mode set to 100644
File size: 7.1 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 atom *atomref) :
56 GLMoleculeObject(mesh, parent),
57 Observer(std::string("GLMoleculeObject_atom")+toString(atomref->getId())),
58 _atom(atomref)
59{
60 // sign on as observer (obtain non-const instance before)
61 atomref->signOn(this, AtomObservable::IndexChanged);
62 atomref->signOn(this, AtomObservable::PositionChanged);
63 atomref->signOn(this, AtomObservable::ElementChanged);
64 atomref->signOn(this, AtomObservable::BondsAdded);
65 World::getInstance().signOn(this, World::SelectionChanged);
66 WorldTime::getInstance().signOn(this, WorldTime::TimeChanged);
67
68 // set the object's id
69 resetProperties();
70
71 LOG(2, "INFO: Created sphere for atom " << _atom->getId() << ".");
72
73 connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));
74}
75
76GLMoleculeObject_atom::~GLMoleculeObject_atom()
77{
78 if (_atom){
79 _atom->signOff(this, AtomObservable::IndexChanged);
80 _atom->signOff(this, AtomObservable::PositionChanged);
81 _atom->signOff(this, AtomObservable::ElementChanged);
82 _atom->signOff(this, AtomObservable::BondsAdded);
83 }
84 World::getInstance().signOff(this, World::SelectionChanged);
85 WorldTime::getInstance().signOff(this, WorldTime::TimeChanged);
86}
87
88void GLMoleculeObject_atom::update(Observable *publisher)
89{
90#ifdef LOG_OBSERVER
91 observerLog().addMessage() << "++ Update of Observer " << observerLog().getName(static_cast<Observer *>(this)) << " from atom "+toString(_atom->getId())+".";
92#endif
93 resetProperties();
94}
95
96void GLMoleculeObject_atom::resetPosition()
97{
98 const Vector Position = _atom->getPosition();
99 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new position is "+toString(Position)+".");
100 setPosition(QVector3D(Position[0], Position[1], Position[2]));
101}
102
103void GLMoleculeObject_atom::resetElement()
104{
105 size_t elementno = 0;
106 if (_atom->getType() != NULL) {
107 elementno = _atom->getType()->getAtomicNumber();
108 } else { // if no element yet, set to hydrogen
109 elementno = 1;
110 }
111 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new element number is "+toString(elementno)+".");
112
113 // set materials
114 QGLMaterial *elementmaterial = getMaterial(elementno);
115 ASSERT(elementmaterial != NULL,
116 "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function is NULL.");
117 setMaterial(elementmaterial);
118
119 // set scale
120 double radius = 0.;
121 if (_atom->getType() != NULL) {
122 radius = _atom->getType()->getVanDerWaalsRadius();
123 } else {
124 radius = 0.5;
125 }
126 setScale( radius / 4. );
127}
128
129void GLMoleculeObject_atom::resetIndex()
130{
131 int oldId = objectId();
132 const size_t atomno = _atom->getId();
133 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new index is "+toString(atomno)+".");
134 setObjectId(atomno);
135
136 emit indexChanged(this, oldId, atomno);
137}
138
139void GLMoleculeObject_atom::resetProperties()
140{
141 // set position
142 resetPosition();
143
144 // set element
145 resetElement();
146
147 // set the object's id
148 resetIndex();
149
150 // selected?
151 setSelected(World::getInstance().isSelected(_atom));
152}
153
154void GLMoleculeObject_atom::subjectKilled(Observable *publisher)
155{
156 _atom = NULL;
157}
158
159void GLMoleculeObject_atom::recieveNotification(Observable *publisher, Notification_ptr notification)
160{
161 if (publisher == dynamic_cast<const Observable*>(_atom)){
162 // notofication from atom
163#ifdef LOG_OBSERVER
164 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this))
165 << " received notification from atom " << _atom->getId() << " for channel "
166 << notification->getChannelNo() << ".";
167#endif
168 switch (notification->getChannelNo()) {
169 case AtomObservable::ElementChanged:
170 resetElement();
171 emit changed();
172 break;
173 case AtomObservable::IndexChanged:
174 resetIndex();
175 break;
176 case AtomObservable::PositionChanged:
177 resetPosition();
178 emit changed();
179 break;
180 case AtomObservable::BondsAdded:
181 {
182 ASSERT(!_atom->getListOfBonds().empty(),
183 "GLMoleculeObject_atom::recieveNotification() - received BondsAdded but ListOfBonds is empty.");
184 const bond::ptr _bond = *(_atom->getListOfBonds().rbegin());
185 const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == _atom) ?
186 GLMoleculeObject_bond::left : GLMoleculeObject_bond::right;
187 emit BondsInserted(_bond, side);
188 break;
189 }
190 default:
191 //setProperties();
192 break;
193 }
194 }else if (static_cast<World *>(publisher) == World::getPointer()) {
195 // notification from world
196#ifdef LOG_OBSERVER
197 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this))
198 << " received notification from world for channel "
199 << notification->getChannelNo() << ".";
200#endif
201 switch (notification->getChannelNo()) {
202 case World::SelectionChanged:
203 setSelected(World::getInstance().isSelected(_atom));
204 break;
205 default:
206 break;
207 }
208 } else {
209 // notification from world
210#ifdef LOG_OBSERVER
211 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this))
212 << " received notification from Worldtime for channel "
213 << notification->getChannelNo() << ".";
214#endif
215 switch (notification->getChannelNo()) {
216 case WorldTime::TimeChanged:
217 resetPosition();
218 emit changed();
219 break;
220 default:
221 break;
222 }
223 }
224}
225
226void GLMoleculeObject_atom::wasClicked()
227{
228 LOG(4, "INFO: GLMoleculeObject_atom: atom " << _atom->getId() << " has been clicked");
229 emit clicked(_atom->getId());
230}
Note: See TracBrowser for help on using the repository browser.