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

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

Replaced World::getAtom() wherever possible by const version.

  • some AtomSet member functions now have const atom ptr instead of atom ptr.
  • molecule can return const and non-const AtomSet.
  • added FromIdToConstAtom to allow iterate through atoms in molecule (which are stored by id, not by ptr) in const fashion.
  • in molecule::isInMolecule() is now const, ::CopyMolecule..() is non-const (because copying involves father atom who is stored non-const).
  • Property mode set to 100644
File size: 8.2 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 uptodatePosition(false),
60 uptodateElement(false)
61{
62 // sign on as observer (obtain non-const instance before)
63 const atom * const _atom = const_cast<const World &>(World::getInstance()).
64 getAtom(AtomById(atomicid));
65 if (_atom != NULL) {
66 _atom->signOn(this, AtomObservable::IndexChanged);
67 _atom->signOn(this, AtomObservable::PositionChanged);
68 _atom->signOn(this, AtomObservable::ElementChanged);
69 _atom->signOn(this, AtomObservable::BondsAdded);
70 } else {
71 ELOG(2, "Atom with id "+toString(atomicid)+" is already gone.");
72 }
73 World::getInstance().signOn(this, World::SelectionChanged);
74
75 // set the object's id
76 resetProperties();
77
78 LOG(2, "INFO: Created sphere for atom " << atomicid << ".");
79
80 connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));
81}
82
83GLMoleculeObject_atom::~GLMoleculeObject_atom()
84{
85 const atom * const _atom = const_cast<const World &>(World::getInstance()).
86 getAtom(AtomById(atomicid));
87 if (_atom != NULL){
88 _atom->signOff(this, AtomObservable::IndexChanged);
89 _atom->signOff(this, AtomObservable::PositionChanged);
90 _atom->signOff(this, AtomObservable::ElementChanged);
91 _atom->signOff(this, AtomObservable::BondsAdded);
92 }
93 World::getInstance().signOff(this, World::SelectionChanged);
94}
95
96void GLMoleculeObject_atom::update(Observable *publisher)
97{
98#ifdef LOG_OBSERVER
99 observerLog().addMessage() << "++ Update of Observer " << observerLog().getName(static_cast<Observer *>(this)) << " from atom "+toString(atomicid)+".";
100#endif
101 resetProperties();
102}
103
104void GLMoleculeObject_atom::resetPosition()
105{
106 const atom * const _atom = const_cast<const World &>(World::getInstance()).
107 getAtom(AtomById(atomicid));
108 if (_atom != NULL) {
109 const Vector Position = _atom->getPosition();
110 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new position is "+toString(Position)+".");
111 setPosition(QVector3D(Position[0], Position[1], Position[2]));
112 } else {
113 ELOG(2, "Atom with id "+toString(atomicid)+" is already gone.");
114 }
115 uptodatePosition = true;
116}
117
118void GLMoleculeObject_atom::resetElement()
119{
120 size_t elementno = 0;
121 const atom * const _atom = const_cast<const World &>(World::getInstance()).
122 getAtom(AtomById(atomicid));
123 const element *_type = NULL;
124 if (_atom != NULL) {
125 _type = _atom->getType();
126 } else {
127 ELOG(2, "Atom with id "+toString(atomicid)+" is already gone.");
128 }
129 if (_type != NULL) {
130 elementno = _type->getAtomicNumber();
131 } else { // if no element yet, set to hydrogen
132 elementno = 1;
133 }
134 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new element number is "+toString(elementno)+".");
135
136 // set materials
137 QGLMaterial *elementmaterial = getMaterial(elementno);
138 ASSERT(elementmaterial != NULL,
139 "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function is NULL.");
140 setMaterial(elementmaterial);
141
142 // set scale
143 double radius = 0.;
144 if (_type != NULL) {
145 radius = _type->getVanDerWaalsRadius();
146 } else {
147 radius = 0.5;
148 }
149 setScale( radius / 4. );
150
151 uptodateElement = true;
152}
153
154void GLMoleculeObject_atom::resetIndex()
155{
156 int oldId = objectId();
157 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new index is "+toString(atomicid)+".");
158 setObjectId(atomicid);
159
160 emit indexChanged(this, oldId, atomicid);
161}
162
163void GLMoleculeObject_atom::resetProperties()
164{
165 // set position
166 resetPosition();
167
168 // set element
169 resetElement();
170
171 // set the object's id
172 resetIndex();
173
174 // selected?
175 setSelected(World::getInstance().isAtomSelected(atomicid));
176}
177
178void GLMoleculeObject_atom::draw(QGLPainter *painter, const QVector4D &cameraPlane)
179{
180 // hook to update prior to painting
181 if (!uptodatePosition)
182 resetPosition();
183 if (!uptodateElement)
184 resetElement();
185
186 // call old hook to do the actual paining
187 GLMoleculeObject::draw(painter, cameraPlane);
188}
189
190void GLMoleculeObject_atom::subjectKilled(Observable *publisher)
191{
192 // remove id such that we don't sign off accidentally from a different atom
193 const_cast<atomId_t &>(atomicid) = -1;
194}
195
196void GLMoleculeObject_atom::recieveNotification(Observable *publisher, Notification_ptr notification)
197{
198 const atom * const _atom = const_cast<const World &>(World::getInstance()).
199 getAtom(AtomById(atomicid));
200 if (publisher == dynamic_cast<const Observable*>(_atom)){
201 // notofication from atom
202#ifdef LOG_OBSERVER
203 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this))
204 << " received notification from atom " << _atom->getId() << " for channel "
205 << notification->getChannelNo() << ".";
206#endif
207 switch (notification->getChannelNo()) {
208 case AtomObservable::ElementChanged:
209 uptodateElement = false;
210 break;
211 case AtomObservable::IndexChanged:
212 resetIndex();
213 break;
214 case AtomObservable::PositionChanged:
215 uptodatePosition = false;
216 break;
217 case AtomObservable::BondsAdded:
218 {
219 const atom * const _atom = const_cast<const World &>(World::getInstance()).
220 getAtom(AtomById(atomicid));
221 if (_atom != NULL) {
222 // make sure position is up-to-date
223 if (!uptodatePosition)
224 resetPosition();
225 ASSERT(!_atom->getListOfBonds().empty(),
226 "GLMoleculeObject_atom::recieveNotification() - received BondsAdded but ListOfBonds is empty.");
227 const bond::ptr _bond = *(_atom->getListOfBonds().rbegin());
228 const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == _atom) ?
229 GLMoleculeObject_bond::left : GLMoleculeObject_bond::right;
230 emit BondsInserted(_bond, side);
231 } else {
232 ELOG(2, "Atom with id "+toString(atomicid)+" is already gone.");
233 }
234 break;
235 }
236 default:
237 //setProperties();
238 break;
239 }
240 }else if (static_cast<World *>(publisher) == World::getPointer()) {
241 // notification from world
242#ifdef LOG_OBSERVER
243 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this))
244 << " received notification from world for channel "
245 << notification->getChannelNo() << ".";
246#endif
247 switch (notification->getChannelNo()) {
248 case World::SelectionChanged:
249 if (_atom != NULL)
250 setSelected(World::getInstance().isSelected(_atom));
251 break;
252 default:
253 break;
254 }
255 }
256}
257
258void GLMoleculeObject_atom::wasClicked()
259{
260 LOG(4, "INFO: GLMoleculeObject_atom: atom " << atomicid << " has been clicked");
261 emit clicked(atomicid);
262}
Note: See TracBrowser for help on using the repository browser.