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

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 26ed25 was bca99d, checked in by Michael Ankele <ankele@…>, 13 years ago

GL: shared meshes

  • Property mode set to 100644
File size: 5.6 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 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * GLMoleculeObject_atom.cpp
10 *
11 * Created on: Aug 17, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "GLMoleculeObject_atom.hpp"
21
22#include <Qt3D/qglscenenode.h>
23
24#include "CodePatterns/MemDebug.hpp"
25
26#include "CodePatterns/Assert.hpp"
27#include "CodePatterns/Log.hpp"
28#include "CodePatterns/Observer/Notification.hpp"
29
30#include "Atom/atom.hpp"
31#include "Bond/bond.hpp"
32#include "Descriptors/AtomIdDescriptor.hpp"
33#include "Element/element.hpp"
34#include "LinearAlgebra/Vector.hpp"
35#include "GLMoleculeObject_bond.hpp"
36#include "World.hpp"
37
38GLMoleculeObject_atom::GLMoleculeObject_atom(QGLSceneNode *mesh, QObject *parent, const atom *atomref) :
39 GLMoleculeObject(mesh, parent),
40 Observer(std::string("GLMoleculeObject_atom")+toString(atomref->getId())),
41 _atom(atomref)
42{
43 // sign on as observer (obtain non-const instance before)
44 atomref->signOn(this, AtomObservable::IndexChanged);
45 atomref->signOn(this, AtomObservable::PositionChanged);
46 atomref->signOn(this, AtomObservable::ElementChanged);
47 atomref->signOn(this, AtomObservable::BondsAdded);
48 World::getInstance().signOn(this, World::SelectionChanged);
49
50 // set the object's id
51 resetProperties();
52
53 LOG(2, "INFO: Created sphere for atom " << _atom->getId() << ".");
54
55 connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));
56}
57
58GLMoleculeObject_atom::~GLMoleculeObject_atom()
59{
60 _atom->signOff(this, AtomObservable::IndexChanged);
61 _atom->signOff(this, AtomObservable::PositionChanged);
62 _atom->signOff(this, AtomObservable::ElementChanged);
63 _atom->signOff(this, AtomObservable::BondsAdded);
64 World::getInstance().signOff(this, World::SelectionChanged);
65}
66
67void GLMoleculeObject_atom::update(Observable *publisher)
68{
69#ifdef LOG_OBSERVER
70 observerLog().addMessage() << "++ Update of Observer " << observerLog().getName(this) << " from atom "+toString(_atom->getId())+".";
71#endif
72 resetProperties();
73}
74
75void GLMoleculeObject_atom::resetPosition()
76{
77 const Vector Position = _atom->getPosition();
78 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new position is "+toString(Position)+".");
79 setPosition(QVector3D(Position[0], Position[1], Position[2]));
80}
81
82void GLMoleculeObject_atom::resetElement()
83{
84 size_t elementno = 0;
85 if (_atom->getType() != NULL) {
86 elementno = _atom->getType()->getAtomicNumber();
87 } else { // if no element yet, set to hydrogen
88 elementno = 1;
89 }
90 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new element number is "+toString(elementno)+".");
91
92 // set materials
93 QGLMaterial *elementmaterial = getMaterial(elementno);
94 ASSERT(elementmaterial != NULL,
95 "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function is NULL.");
96 setMaterial(elementmaterial);
97
98 // set scale
99 double radius = 0.;
100 if (_atom->getType() != NULL) {
101 radius = _atom->getType()->getVanDerWaalsRadius();
102 } else {
103 radius = 0.5;
104 }
105 setScale( radius / 4. );
106}
107
108void GLMoleculeObject_atom::resetIndex()
109{
110 const size_t atomno = _atom->getId();
111 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new index is "+toString(atomno)+".");
112 setObjectId(atomno);
113}
114
115void GLMoleculeObject_atom::resetProperties()
116{
117 // set position
118 resetPosition();
119
120 // set element
121 resetElement();
122
123 // set the object's id
124 resetIndex();
125
126 // selected?
127 setSelected(World::getInstance().isSelected(_atom));
128}
129
130void GLMoleculeObject_atom::subjectKilled(Observable *publisher)
131{}
132
133void GLMoleculeObject_atom::recieveNotification(Observable *publisher, Notification_ptr notification)
134{
135 if (publisher == dynamic_cast<const Observable*>(_atom)){
136 // notofication from atom
137#ifdef LOG_OBSERVER
138 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(this)
139 << " received notification from atom " << _atom->getId() << " for channel "
140 << notification->getChannelNo() << ".";
141#endif
142 switch (notification->getChannelNo()) {
143 case AtomObservable::ElementChanged:
144 resetElement();
145 emit changed();
146 break;
147 case AtomObservable::IndexChanged:
148 resetIndex();
149 break;
150 case AtomObservable::PositionChanged:
151 resetPosition();
152 emit changed();
153 break;
154 case AtomObservable::BondsAdded:
155 {
156 ASSERT(!_atom->getListOfBonds().empty(),
157 "GLMoleculeObject_atom::recieveNotification() - received BondsAdded but ListOfBonds is empty.");
158 const bond * _bond = *(_atom->getListOfBonds().rbegin());
159 const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == _atom) ?
160 GLMoleculeObject_bond::left : GLMoleculeObject_bond::right;
161 emit BondsInserted(_bond, side);
162 break;
163 }
164 default:
165 //setProperties();
166 break;
167 }
168 }else{
169 // notification from world
170#ifdef LOG_OBSERVER
171 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(this)
172 << " received notification from world for channel "
173 << notification->getChannelNo() << ".";
174#endif
175 switch (notification->getChannelNo()) {
176 case World::SelectionChanged:
177 setSelected(World::getInstance().isSelected(_atom));
178 break;
179 default:
180 break;
181 }
182 }
183}
184
185void GLMoleculeObject_atom::wasClicked()
186{
187 LOG(4, "INFO: GLMoleculeObject_atom: atom " << _atom->getId() << " has been clicked");
188 emit clicked(_atom->getId());
189}
Note: See TracBrowser for help on using the repository browser.