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

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 4792ab 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
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.
[5aaa43]5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
[94d5ac6]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/>.
[907636]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"
[7188b1]43#include "CodePatterns/Log.hpp"
[02ce36]44#include "CodePatterns/Observer/Notification.hpp"
[907636]45
[2ad1ec]46#include "Atom/atom.hpp"
47#include "Bond/bond.hpp"
[7188b1]48#include "Descriptors/AtomIdDescriptor.hpp"
[3bdb6d]49#include "Element/element.hpp"
[907636]50#include "LinearAlgebra/Vector.hpp"
[2ad1ec]51#include "GLMoleculeObject_bond.hpp"
[7188b1]52#include "World.hpp"
[907636]53
[72a4c1]54GLMoleculeObject_atom::GLMoleculeObject_atom(QGLSceneNode *mesh[], QObject *parent, const atom *atomref) :
[bca99d]55 GLMoleculeObject(mesh, parent),
[2ad1ec]56 Observer(std::string("GLMoleculeObject_atom")+toString(atomref->getId())),
57 _atom(atomref)
[7188b1]58{
59 // sign on as observer (obtain non-const instance before)
[02ce36]60 atomref->signOn(this, AtomObservable::IndexChanged);
61 atomref->signOn(this, AtomObservable::PositionChanged);
62 atomref->signOn(this, AtomObservable::ElementChanged);
[2ad1ec]63 atomref->signOn(this, AtomObservable::BondsAdded);
[d53902]64 World::getInstance().signOn(this, World::SelectionChanged);
[7188b1]65
66 // set the object's id
67 resetProperties();
68
[57a770]69 LOG(2, "INFO: Created sphere for atom " << _atom->getId() << ".");
[7188b1]70
71 connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));
72}
73
[9c18e4]74GLMoleculeObject_atom::~GLMoleculeObject_atom()
75{
[c736fe]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 }
[d53902]82 World::getInstance().signOff(this, World::SelectionChanged);
[9c18e4]83}
84
[7188b1]85void GLMoleculeObject_atom::update(Observable *publisher)
86{
[57a770]87#ifdef LOG_OBSERVER
[708277]88 observerLog().addMessage() << "++ Update of Observer " << observerLog().getName(static_cast<Observer *>(this)) << " from atom "+toString(_atom->getId())+".";
[57a770]89#endif
[7188b1]90 resetProperties();
91}
92
93void GLMoleculeObject_atom::resetPosition()
[907636]94{
95 const Vector Position = _atom->getPosition();
[57a770]96 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new position is "+toString(Position)+".");
[7188b1]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) {
[ed26ae]104 elementno = _atom->getType()->getAtomicNumber();
[7188b1]105 } else { // if no element yet, set to hydrogen
106 elementno = 1;
107 }
[57a770]108 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new element number is "+toString(elementno)+".");
[907636]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
[7188b1]116 // set scale
117 double radius = 0.;
118 if (_atom->getType() != NULL) {
119 radius = _atom->getType()->getVanDerWaalsRadius();
120 } else {
121 radius = 0.5;
122 }
[3927ef]123 setScale( radius / 4. );
[7188b1]124}
125
126void GLMoleculeObject_atom::resetIndex()
127{
[30cd0d]128 int oldId = objectId();
[7188b1]129 const size_t atomno = _atom->getId();
[57a770]130 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new index is "+toString(atomno)+".");
[7188b1]131 setObjectId(atomno);
[30cd0d]132
133 emit indexChanged(this, oldId, atomno);
[7188b1]134}
135
136void GLMoleculeObject_atom::resetProperties()
137{
[907636]138 // set position
[7188b1]139 resetPosition();
[907636]140
[7188b1]141 // set element
142 resetElement();
[907636]143
144 // set the object's id
[7188b1]145 resetIndex();
[d53902]146
147 // selected?
148 setSelected(World::getInstance().isSelected(_atom));
[7188b1]149}
[907636]150
[7188b1]151void GLMoleculeObject_atom::subjectKilled(Observable *publisher)
[c736fe]152{
153 _atom = NULL;
154}
[06ebf5]155
[7188b1]156void GLMoleculeObject_atom::recieveNotification(Observable *publisher, Notification_ptr notification)
157{
[d53902]158 if (publisher == dynamic_cast<const Observable*>(_atom)){
159 // notofication from atom
[57a770]160#ifdef LOG_OBSERVER
[708277]161 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this))
[d53902]162 << " received notification from atom " << _atom->getId() << " for channel "
163 << notification->getChannelNo() << ".";
[57a770]164#endif
[d53902]165 switch (notification->getChannelNo()) {
166 case AtomObservable::ElementChanged:
167 resetElement();
[5a2a06]168 emit changed();
[d53902]169 break;
170 case AtomObservable::IndexChanged:
171 resetIndex();
172 break;
173 case AtomObservable::PositionChanged:
174 resetPosition();
[5a2a06]175 emit changed();
[d53902]176 break;
177 case AtomObservable::BondsAdded:
[2ad1ec]178 {
[d53902]179 ASSERT(!_atom->getListOfBonds().empty(),
180 "GLMoleculeObject_atom::recieveNotification() - received BondsAdded but ListOfBonds is empty.");
[88c8ec]181 const bond::ptr _bond = *(_atom->getListOfBonds().rbegin());
[d53902]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
[708277]194 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this))
[d53902]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:
[2ad1ec]203 break;
[d53902]204 }
[7188b1]205 }
[06ebf5]206}
207
208void GLMoleculeObject_atom::wasClicked()
209{
[57a770]210 LOG(4, "INFO: GLMoleculeObject_atom: atom " << _atom->getId() << " has been clicked");
[06ebf5]211 emit clicked(_atom->getId());
[907636]212}
Note: See TracBrowser for help on using the repository browser.