source: src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp@ db7e6d

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 db7e6d was 7188b1, checked in by Frederik Heber <heber@…>, 14 years ago

Introduced atom_observables and GLWorldView observes World, GLMoleculeObject_atom observes its atom.

Observer changes:

  • new Channels pattern required from CodePatterns 1.1.5 and that Observable signing on and off is now with const instance possible.
  • class atom is now observable, encapsulated in class AtomObservable:
    • enums have notification types
    • we use NotificationChannels of Observable to emit these distinct types.
  • atominfo, particleinfo, bondedparticleinfo all have OBSERVE and NOTIFY(..) in their setter functions (thx encapsulation).
  • class GLMoleculeObject_atom signs on to atom to changes to position, element, and index.
  • World equally has notifications for atom (new,remove) and molecules (new, remove).
  • GLWorldView now observes World for these changes.

Other changes:

  • removed additional hierarchy level for GLWidget of molecules (i.e. GLMoleculeScene removed and incorporated into GLWorldScene).
  • Property mode set to 100644
File size: 6.4 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * GLWorldScene.cpp
10 *
11 * This is based on the Qt3D example "teaservice", specifically parts of teaservice.cpp.
12 *
13 * Created on: Aug 17, 2011
14 * Author: heber
15 */
16
17// include config.h
18#ifdef HAVE_CONFIG_H
19#include <config.h>
20#endif
21
22#include "GLWorldScene.hpp"
23
24#include "GLMoleculeObject.hpp"
25#include "GLMoleculeObject_atom.hpp"
26#include "GLMoleculeObject_bond.hpp"
27
28#include "CodePatterns/MemDebug.hpp"
29
30#include "CodePatterns/Log.hpp"
31
32#include "atom.hpp"
33#include "Bond/bond.hpp"
34#include "molecule.hpp"
35#include "World.hpp"
36
37
38GLWorldScene::GLWorldScene(QObject *parent)
39 : QObject(parent)
40{
41 init();
42
43 //changeMaterials(false);
44}
45
46GLWorldScene::~GLWorldScene()
47{
48 // remove all elements
49 GLMoleculeObject::cleanMaterialMap();
50}
51
52/** Initialise the WorldScene with molecules and atoms from World.
53 *
54 */
55void GLWorldScene::init()
56{
57 const std::vector<molecule*> &molecules = World::getInstance().getAllMolecules();
58
59 if (molecules.size() > 0) {
60 for (std::vector<molecule*>::const_iterator Runner = molecules.begin();
61 Runner != molecules.end();
62 Runner++) {
63 // create molecule
64 for (molecule::const_iterator atomiter = (*Runner)->begin();
65 atomiter != (*Runner)->end();
66 ++atomiter) {
67 // create atom objects in scene
68 atomInserted(*atomiter);
69
70 // create its bonds
71 const BondList &bonds = (*atomiter)->getListOfBonds();
72 for (BondList::const_iterator bonditer = bonds.begin();
73 bonditer != bonds.end();
74 ++bonditer) {
75 if ((*bonditer)->leftatom->getId() == (*atomiter)->getId()) {
76 // create bond objects in scene
77 bondInserted(*bonditer);
78 }
79 }
80 }
81 }
82 }
83}
84
85/** Adds an atom to the scene.
86 *
87 * @param _atom atom to add
88 */
89void GLWorldScene::atomInserted(const atom *_atom)
90{
91 LOG(0, "GLWorldScene: Received signal atomInserted for atom "+toString(_atom->getId())+".");
92 GLMoleculeObject_atom *atomObject = new GLMoleculeObject_atom(this, _atom);
93 AtomNodeMap::iterator iter = AtomsinMoleculeMap.find(_atom->getId());
94 ASSERT(iter == AtomsinMoleculeMap.end(),
95 "GLWorldScene::atomAdded() - same atom "+_atom->getName()+" added again.");
96 AtomsinMoleculeMap.insert( make_pair(_atom->getId(), atomObject) );
97 connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
98 connect (atomObject, SIGNAL(hoverChanged()), this, SIGNAL(hoverChanged()));
99 emit changed();
100}
101
102/** Removes an atom from the scene.
103 *
104 * @param _atom atom to remove
105 */
106void GLWorldScene::atomRemoved(const atom *_atom)
107{
108 LOG(0, "GLWorldScene: Received signal atomRemoved for atom "+toString(_atom->getId())+".");
109 // remove all its bonds
110 const BondList& bondlist = _atom->getListOfBonds();
111 for (BondList::const_iterator iter = bondlist.begin(); iter != bondlist.end(); ++iter) {
112 bondRemoved(*iter);
113 }
114 // remove atoms
115 AtomNodeMap::iterator iter = AtomsinMoleculeMap.find(_atom->getId());
116 ASSERT(iter != AtomsinMoleculeMap.end(),
117 "GLWorldScene::atomRemoved() - atom "+_atom->getName()+" not on display.");
118 GLMoleculeObject_atom *atomObject = iter->second;
119 atomObject->disconnect();
120 AtomsinMoleculeMap.erase(iter);
121 delete atomObject;
122 emit changed();
123}
124
125/** Adds an bond to the scene.
126 *
127 * @param _bond bond to add
128 */
129void GLWorldScene::bondInserted(const bond *_bond)
130{
131 const double distance =
132 _bond->leftatom->getPosition().distance(_bond->rightatom->getPosition())/2.;
133 {
134 // left bond
135 const BondIds Leftids( make_pair(_bond->leftatom->getId(), _bond->rightatom->getId()) );
136 BondNodeMap::iterator iter = BondsinMoleculeMap.find(Leftids);
137 ASSERT(iter == BondsinMoleculeMap.end(),
138 "GLWorldScene::bondAdded() - same left-sided bond "+toString(*_bond)+" added again.");
139 GLMoleculeObject_bond *bondObject =
140 new GLMoleculeObject_bond(this, _bond, distance, GLMoleculeObject_bond::left);
141 BondsinMoleculeMap.insert( make_pair(Leftids, bondObject) );
142 }
143 {
144 // right bond
145 const BondIds Rightids( make_pair(_bond->rightatom->getId(), _bond->leftatom->getId()) );
146 BondNodeMap::iterator iter = BondsinMoleculeMap.find(Rightids);
147 ASSERT(iter == BondsinMoleculeMap.end(),
148 "GLWorldScene::bondAdded() - same right-sided bond "+toString(*_bond)+" added again.");
149 GLMoleculeObject_bond *bondObject =
150 new GLMoleculeObject_bond(this, _bond, distance, GLMoleculeObject_bond::right);
151 BondsinMoleculeMap.insert( make_pair(Rightids, bondObject) );
152 }
153 emit changed();
154}
155
156/** Removes an bond from the scene.
157 *
158 * @param _bond bond to remove
159 */
160void GLWorldScene::bondRemoved(const bond *_bond)
161{
162 {
163 // left bond
164 const BondIds Leftids( make_pair(_bond->leftatom->getId(), _bond->rightatom->getId()) );
165 BondNodeMap::iterator leftiter = BondsinMoleculeMap.find( Leftids );
166 ASSERT(leftiter != BondsinMoleculeMap.end(),
167 "GLWorldScene::bondRemoved() - bond "+toString(*_bond)+" not on display.");
168 GLMoleculeObject_bond *bondObject = leftiter->second;
169 BondsinMoleculeMap.erase(leftiter);
170 delete bondObject;
171 }
172 {
173 // right bond
174 const BondIds Rightids( make_pair(_bond->rightatom->getId(), _bond->leftatom->getId()) );
175 BondNodeMap::iterator rightiter = BondsinMoleculeMap.find( Rightids );
176 ASSERT(rightiter != BondsinMoleculeMap.end(),
177 "GLWorldScene::bondRemoved() - bond "+toString(*_bond)+" not on display.");
178 GLMoleculeObject_bond *bondObject = rightiter->second;
179 BondsinMoleculeMap.erase(rightiter);
180 delete bondObject;
181 }
182 emit changed();
183}
184
185void GLWorldScene::initialize(QGLView *view, QGLPainter *painter) const
186{
187 // Initialize all of the mesh objects that we have as children.
188 foreach (QObject *obj, children()) {
189 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
190 if (meshobj)
191 meshobj->initialize(view, painter);
192 }
193}
194
195void GLWorldScene::draw(QGLPainter *painter) const
196{
197 // Draw all of the mesh objects that we have as children.
198 foreach (QObject *obj, children()) {
199 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
200 if (meshobj)
201 meshobj->draw(painter);
202 }
203}
204
205void GLWorldScene::atomClicked(atomId_t no)
206{
207 qDebug("GLWorldScene: atom %d has been clicked.", no);
208 emit clicked(no);
209}
210
Note: See TracBrowser for help on using the repository browser.