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

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 3f7587 was 57a770, checked in by Frederik Heber <heber@…>, 13 years ago

Corrected verbosity levels of GLMoleculeObject..., GLWorldScene, and ..View.

  • placede messages from Observer's to observerLog.
  • Property mode set to 100644
File size: 4.7 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/qglbuilder.h>
23#include <Qt3D/qglscenenode.h>
24#include <Qt3D/qglsphere.h>
25
26#include "CodePatterns/MemDebug.hpp"
27
28#include "CodePatterns/Assert.hpp"
29#include "CodePatterns/Log.hpp"
30#include "CodePatterns/Observer/Notification.hpp"
31
32#include "Descriptors/AtomIdDescriptor.hpp"
33#include "Element/element.hpp"
34#include "LinearAlgebra/Vector.hpp"
35#include "World.hpp"
36
37static QGLSceneNode * createAtom(QObject *parent)
38{
39 QGLBuilder builder;
40 builder << QGLSphere(0.5);
41 QGLSceneNode *n = builder.finalizedSceneNode();
42 n->setParent(parent);
43 return n;
44}
45
46GLMoleculeObject_atom::GLMoleculeObject_atom(QObject *parent, const atom *atomref) :
47 GLMoleculeObject(createAtom(parent), parent), Observer("GLMoleculeObject_atom"), _atom(atomref)
48{
49 // sign on as observer (obtain non-const instance before)
50 atomref->signOn(this, AtomObservable::IndexChanged);
51 atomref->signOn(this, AtomObservable::PositionChanged);
52 atomref->signOn(this, AtomObservable::ElementChanged);
53 atomref->signOn(this, AtomObservable::BondsChanged);
54
55 // set the object's id
56 resetProperties();
57
58 LOG(2, "INFO: Created sphere for atom " << _atom->getId() << ".");
59
60 connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));
61}
62
63GLMoleculeObject_atom::~GLMoleculeObject_atom()
64{
65 _atom->signOff(this, AtomObservable::IndexChanged);
66 _atom->signOff(this, AtomObservable::PositionChanged);
67 _atom->signOff(this, AtomObservable::ElementChanged);
68 _atom->signOff(this, AtomObservable::BondsChanged);
69}
70
71void GLMoleculeObject_atom::update(Observable *publisher)
72{
73#ifdef LOG_OBSERVER
74 observerLog().addMessage() << "++ Update of Observer " << observerLog().getName(this) << " from atom "+toString(_atom->getId())+".";
75#endif
76 resetProperties();
77}
78
79void GLMoleculeObject_atom::resetPosition()
80{
81 const Vector Position = _atom->getPosition();
82 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new position is "+toString(Position)+".");
83 setPosition(QVector3D(Position[0], Position[1], Position[2]));
84}
85
86void GLMoleculeObject_atom::resetElement()
87{
88 size_t elementno = 0;
89 if (_atom->getType() != NULL) {
90 elementno = _atom->getType()->getNumber();
91 } else { // if no element yet, set to hydrogen
92 elementno = 1;
93 }
94 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new element number is "+toString(elementno)+".");
95
96 // set materials
97 QGLMaterial *elementmaterial = getMaterial(elementno);
98 ASSERT(elementmaterial != NULL,
99 "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function is NULL.");
100 setMaterial(elementmaterial);
101 QGLMaterial *hovermaterial = getMaterial(0); // 0 is the hover material
102 ASSERT(hovermaterial != NULL,
103 "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function for hover is NULL.");
104 setHoverMaterial(hovermaterial);
105
106 // set scale
107 double radius = 0.;
108 if (_atom->getType() != NULL) {
109 radius = _atom->getType()->getVanDerWaalsRadius();
110 } else {
111 radius = 0.5;
112 }
113 setScale( radius );
114}
115
116void GLMoleculeObject_atom::resetIndex()
117{
118 const size_t atomno = _atom->getId();
119 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new index is "+toString(atomno)+".");
120 setObjectId(atomno);
121}
122
123void GLMoleculeObject_atom::resetProperties()
124{
125 // set position
126 resetPosition();
127
128 // set element
129 resetElement();
130
131 // set the object's id
132 resetIndex();
133}
134
135void GLMoleculeObject_atom::subjectKilled(Observable *publisher)
136{}
137
138void GLMoleculeObject_atom::recieveNotification(Observable *publisher, Notification_ptr notification)
139{
140#ifdef LOG_OBSERVER
141 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(this)
142 << " received notification from atom " << _atom->getId() << " for channel "
143 << notification->getChannelNo() << ".";
144#endif
145 switch (notification->getChannelNo()) {
146 case AtomObservable::ElementChanged:
147 resetElement();
148 break;
149 case AtomObservable::IndexChanged:
150 resetIndex();
151 break;
152 case AtomObservable::PositionChanged:
153 resetPosition();
154 break;
155 case AtomObservable::BondsChanged:
156 emit BondsChanged(_atom);
157 break;
158 default:
159 //setProperties();
160 break;
161 }
162}
163
164void GLMoleculeObject_atom::wasClicked()
165{
166 LOG(4, "INFO: GLMoleculeObject_atom: atom " << _atom->getId() << " has been clicked");
167 emit clicked(_atom->getId());
168}
Note: See TracBrowser for help on using the repository browser.