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

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 b75386 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: 9.2 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 * 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 "Actions/SelectionAction/Atoms/AtomByIdAction.hpp"
33#include "Actions/SelectionAction/Atoms/NotAtomByIdAction.hpp"
34#include "Atom/atom.hpp"
35#include "Bond/bond.hpp"
36#include "Descriptors/AtomIdDescriptor.hpp"
37#include "Helpers/helpers.hpp"
38#include "molecule.hpp"
39#include "World.hpp"
40
41using namespace MoleCuilder;
42
43GLWorldScene::GLWorldScene(QObject *parent)
44 : QObject(parent)
45{
46 init();
47
48 //changeMaterials(false);
49}
50
51GLWorldScene::~GLWorldScene()
52{
53 // remove all elements
54 GLMoleculeObject::cleanMaterialMap();
55}
56
57/** Initialise the WorldScene with molecules and atoms from World.
58 *
59 */
60void GLWorldScene::init()
61{
62 const std::vector<molecule*> &molecules = World::getInstance().getAllMolecules();
63
64 if (molecules.size() > 0) {
65 for (std::vector<molecule*>::const_iterator Runner = molecules.begin();
66 Runner != molecules.end();
67 Runner++) {
68 // create molecule
69 for (molecule::const_iterator atomiter = (*Runner)->begin();
70 atomiter != (*Runner)->end();
71 ++atomiter) {
72 // create atom objects in scene
73 atomInserted(*atomiter);
74
75 // create bond objects in scene
76 bondsChanged(*atomiter);
77 }
78 }
79 }
80}
81
82/** Adds an atom to the scene.
83 *
84 * @param _atom atom to add
85 */
86void GLWorldScene::atomInserted(const atom *_atom)
87{
88 LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "+toString(_atom->getId())+".");
89 GLMoleculeObject_atom *atomObject = new GLMoleculeObject_atom(this, _atom);
90 AtomNodeMap::iterator iter = AtomsinSceneMap.find(_atom->getId());
91 ASSERT(iter == AtomsinSceneMap.end(),
92 "GLWorldScene::atomAdded() - same atom "+_atom->getName()+" added again.");
93 AtomsinSceneMap.insert( make_pair(_atom->getId(), atomObject) );
94 connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
95 connect (atomObject, SIGNAL(hoverChanged()), this, SIGNAL(changed()));
96 connect (atomObject, SIGNAL(BondsChanged(const atom *)), this, SLOT(bondsChanged(const atom *)));
97 bondsChanged(_atom);
98 emit changeOccured();
99}
100
101/** Removes an atom from the scene.
102 *
103 * @param _atom atom to remove
104 */
105void GLWorldScene::atomRemoved(const atom *_atom)
106{
107 LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atom->getId())+".");
108 // remove all its bonds
109 const BondList& bondlist = _atom->getListOfBonds();
110 for (BondList::const_iterator iter = bondlist.begin(); iter != bondlist.end(); ++iter) {
111 bondRemoved((*iter)->leftatom->getId(), (*iter)->rightatom->getId());
112 bondRemoved((*iter)->rightatom->getId(), (*iter)->leftatom->getId());
113 }
114 // remove atoms
115 AtomNodeMap::iterator iter = AtomsinSceneMap.find(_atom->getId());
116 ASSERT(iter != AtomsinSceneMap.end(),
117 "GLWorldScene::atomRemoved() - atom "+_atom->getName()+" not on display.");
118 GLMoleculeObject_atom *atomObject = iter->second;
119 atomObject->disconnect();
120 AtomsinSceneMap.erase(iter);
121 delete atomObject;
122 emit changeOccured();
123}
124
125/** Updates the bond structure of the signaled \a _atom.
126 *
127 * @param _atom atom whose bonds changed.
128 */
129void GLWorldScene::bondsChanged(const atom *_atom)
130{
131 const atomId_t id = _atom->getId();
132
133 // create list with all present bonds
134 std::set< atomId_t > presentBonds;
135 std::pair< BondIdsMap::const_iterator, BondIdsMap::const_iterator> range =
136 BondIdsinSceneMap.equal_range( id );
137 for (BondIdsMap::const_iterator iter = range.first; iter != range.second; ++iter) {
138 const atomId_t otherid = iter->second;
139#ifndef NDEBUG
140 std::set< atomId_t >::const_iterator iter = presentBonds.find(otherid);
141 ASSERT(iter == presentBonds.end(),
142 "GLWorldScene::BondsChanged() - bond id "+toString(otherid)+" for atom "
143 +toString(id)+" present twice.");
144#endif
145 presentBonds.insert( otherid );
146 }
147 LOG(3, "INFO: We have the following bonds: "+toString(presentBonds)+".");
148
149 // search for added bonds
150 const BondList &bondlist = _atom->getListOfBonds();
151 for (BondList::const_iterator bonditer = bondlist.begin();
152 bonditer != bondlist.end();
153 ++bonditer) {
154 const bond *_bond = *bonditer;
155 const atomId_t otherid = _bond->GetOtherAtom(_atom)->getId();
156 const BondIds ids = std::make_pair( id, otherid );
157 BondNodeMap::const_iterator iter = BondsinSceneMap.find(ids);
158 if (iter != BondsinSceneMap.end()) {
159 // bond is already present
160 std::set< atomId_t >::const_iterator iter = presentBonds.find(otherid);
161 ASSERT(iter != presentBonds.end(),
162 "GLWorldScene::BondsChanged() - other id "+toString(otherid)+" for atom "
163 +toString(_atom->getId())+" not present in BondIdsinSceneMap.");
164 presentBonds.erase(otherid);
165 LOG(0, "Removing "+toString(otherid)+" from presentBonds.");
166 } else {
167 // insert new bond
168 bondInserted(_bond);
169 }
170 }
171 if (!presentBonds.empty())
172 ELOG(2, "The following bonds should not be present: "+toString(presentBonds)+".");
173
174 // remove all still presentBonds
175 for (std::set< atomId_t >::iterator iter = presentBonds.begin();
176 !presentBonds.empty(); iter = presentBonds.begin()) {
177 bondRemoved( id, *iter );
178 }
179}
180
181/** Adds a bond to the scene.
182 *
183 * @param _bond bond to add
184 */
185void GLWorldScene::bondInserted(const bond *_bond)
186{
187 LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bond "+toString(*_bond)+".");
188 const double distance =
189 _bond->leftatom->getPosition().distance(_bond->rightatom->getPosition())/2.;
190 {
191 // left bond
192 const BondIds Leftids( make_pair(_bond->leftatom->getId(), _bond->rightatom->getId()) );
193 BondNodeMap::iterator iter = BondsinSceneMap.find(Leftids);
194 ASSERT(iter == BondsinSceneMap.end(),
195 "GLWorldScene::bondAdded() - same left-sided bond "+toString(*_bond)+" added again.");
196 GLMoleculeObject_bond *bondObject =
197 new GLMoleculeObject_bond(this, _bond, distance, GLMoleculeObject_bond::left);
198 BondsinSceneMap.insert( make_pair(Leftids, bondObject) );
199 BondIdsinSceneMap.insert( Leftids );
200 }
201 {
202 // right bond
203 const BondIds Rightids( make_pair(_bond->rightatom->getId(), _bond->leftatom->getId()) );
204 BondNodeMap::iterator iter = BondsinSceneMap.find(Rightids);
205 ASSERT(iter == BondsinSceneMap.end(),
206 "GLWorldScene::bondAdded() - same right-sided bond "+toString(*_bond)+" added again.");
207 GLMoleculeObject_bond *bondObject =
208 new GLMoleculeObject_bond(this, _bond, distance, GLMoleculeObject_bond::right);
209 BondsinSceneMap.insert( make_pair(Rightids, bondObject) );
210 BondIdsinSceneMap.insert( Rightids );
211 }
212 emit changeOccured();
213}
214
215/** Removes a bond from the scene.
216 *
217 * @param _bond bond to remove
218 */
219void GLWorldScene::bondRemoved(const atomId_t leftnr, const atomId_t rightnr)
220{
221 LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond between "+toString(leftnr)+" and "+toString(leftnr)+".");
222 {
223 // left bond
224 const BondIds Leftids( make_pair(leftnr, rightnr) );
225 BondNodeMap::iterator leftiter = BondsinSceneMap.find( Leftids );
226 ASSERT(leftiter != BondsinSceneMap.end(),
227 "GLWorldScene::bondRemoved() - bond "+toString(leftnr)+"-"
228 +toString(rightnr)+" not on display.");
229 GLMoleculeObject_bond *bondObject = leftiter->second;
230 BondsinSceneMap.erase(leftiter);
231 delete bondObject;
232 }
233 // remove from bond ids
234 std::pair<BondIdsMap::iterator, BondIdsMap::iterator> leftrange =
235 BondIdsinSceneMap.equal_range(leftnr);
236 BondIdsMap::iterator iter;
237 for (iter = leftrange.first; iter != leftrange.second; ++iter) {
238 if (iter->second == rightnr) {
239 BondIdsinSceneMap.erase(iter);
240 break;
241 }
242 }
243 ASSERT(iter != leftrange.second,
244 "GLWorldScene::bondRemoved() - could not find ("
245 +toString(leftnr)+"-"+toString(rightnr)+" in BondIdsinSceneMap.");
246 emit changeOccured();
247}
248
249void GLWorldScene::initialize(QGLView *view, QGLPainter *painter) const
250{
251 // Initialize all of the mesh objects that we have as children.
252 foreach (QObject *obj, children()) {
253 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
254 if (meshobj)
255 meshobj->initialize(view, painter);
256 }
257}
258
259void GLWorldScene::draw(QGLPainter *painter) const
260{
261 // Draw all of the mesh objects that we have as children.
262 foreach (QObject *obj, children()) {
263 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
264 if (meshobj)
265 meshobj->draw(painter);
266 }
267}
268
269void GLWorldScene::atomClicked(atomId_t no)
270{
271 LOG(3, "INFO: GLWorldScene - atom " << no << " has been clicked.");
272 const atom *Walker = World::getInstance().getAtom(AtomById(no));
273 if (!World::getInstance().isSelected(Walker))
274 SelectionAtomById(no);
275 else
276 SelectionNotAtomById(no);
277 emit clicked(no);
278}
279
Note: See TracBrowser for help on using the repository browser.