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

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 3927ef was 3927ef, checked in by Frederik Heber <heber@…>, 13 years ago

GL: molecule selection boxes

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