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

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 Candidate_v1.7.0 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 c736fe was c736fe, checked in by Michael Ankele <ankele@…>, 13 years ago

Fix: GLMoleculeObject_atom must not signOff after subjectKilled

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