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

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 1e1098 was 5aaa43, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: Fixed new copyright line since start of 2013 in CodeChecks test.

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