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

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 5aec20 was 4cac6c, checked in by Frederik Heber <heber@…>, 9 years ago

CHECK: Don't admonish empty missed states in GLWorldScene?

  • skipped in subsequent loop anyway.
  • Property mode set to 100644
File size: 18.6 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 * Copyright (C) 2013 Frederik Heber. All rights reserved.
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/>.
22 */
23
24/*
25 * GLWorldScene.cpp
26 *
27 * This is based on the Qt3D example "teaservice", specifically parts of teaservice.cpp.
28 *
29 * Created on: Aug 17, 2011
30 * Author: heber
31 */
32
33// include config.h
34#ifdef HAVE_CONFIG_H
35#include <config.h>
36#endif
37
38#include "GLWorldScene.hpp"
39#include <Qt3D/qglview.h>
40#include <Qt3D/qglbuilder.h>
41#include <Qt3D/qglscenenode.h>
42#include <Qt3D/qglsphere.h>
43#include <Qt3D/qglcylinder.h>
44
45#include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject.hpp"
46#include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp"
47#include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp"
48#include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp"
49#include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_shape.hpp"
50
51#include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
52
53#include "CodePatterns/MemDebug.hpp"
54
55#include "CodePatterns/Log.hpp"
56
57#include "Actions/SelectionAction/Atoms/AtomByIdAction.hpp"
58#include "Actions/SelectionAction/Atoms/NotAtomByIdAction.hpp"
59#include "Actions/SelectionAction/Molecules/MoleculeByIdAction.hpp"
60#include "Actions/SelectionAction/Molecules/NotMoleculeByIdAction.hpp"
61#include "Atom/atom.hpp"
62#include "Bond/bond.hpp"
63#include "Descriptors/AtomIdDescriptor.hpp"
64#include "Descriptors/MoleculeIdDescriptor.hpp"
65#include "Helpers/helpers.hpp"
66#include "Shapes/ShapeRegistry.hpp"
67#include "molecule.hpp"
68#include "World.hpp"
69
70#include <iostream>
71
72using namespace MoleCuilder;
73
74GLWorldScene::GLWorldScene(
75 QtObservedInstanceBoard * _board,
76 QObject *parent) :
77 QObject(parent),
78 selectionMode(SelectAtom),
79 board(_board)
80{
81 int sphereDetails[] = {5, 3, 2, 0};
82 int cylinderDetails[] = {16, 8, 6, 3};
83 for (int i=0;i<GLMoleculeObject::DETAILTYPES_MAX;i++){
84 QGLBuilder emptyBuilder;
85 GLMoleculeObject::meshEmpty[i] = emptyBuilder.finalizedSceneNode();
86 QGLBuilder sphereBuilder;
87 sphereBuilder << QGLSphere(2.0, sphereDetails[i]);
88 GLMoleculeObject::meshSphere[i] = sphereBuilder.finalizedSceneNode();
89 GLMoleculeObject::meshSphere[i]->setOption(QGLSceneNode::CullBoundingBox, true);
90 QGLBuilder cylinderBuilder;
91 cylinderBuilder << QGLCylinder(.25,.25,1.0,cylinderDetails[i]);
92 GLMoleculeObject::meshCylinder[i] = cylinderBuilder.finalizedSceneNode();
93 GLMoleculeObject::meshCylinder[i]->setOption(QGLSceneNode::CullBoundingBox, true);
94 }
95 connect(board, SIGNAL(moleculeInserted(const moleculeId_t)),
96 this, SLOT(moleculeInserted(const moleculeId_t)));
97 connect(board, SIGNAL(moleculeRemoved(const moleculeId_t)),
98 this, SLOT(moleculeRemoved(const moleculeId_t)));
99 connect(board, SIGNAL(moleculeIndexChanged(const moleculeId_t, const moleculeId_t)),
100 this, SLOT(moleculeIndexChanged(const moleculeId_t, const moleculeId_t)));
101 connect(board, SIGNAL(atomInserted(const moleculeId_t, const atomId_t)),
102 this, SLOT(atomInserted(const moleculeId_t, const atomId_t)), Qt::DirectConnection);
103 connect(board, SIGNAL(atomRemoved(const moleculeId_t, const atomId_t)),
104 this, SLOT(atomRemoved(const moleculeId_t, const atomId_t)), Qt::DirectConnection);
105
106// connect(this, SIGNAL(updated()), this, SLOT(update()));
107}
108
109GLWorldScene::~GLWorldScene()
110{
111 // remove all elements
112 GLMoleculeObject::cleanMaterialMap();
113}
114
115void GLWorldScene::atomClicked(atomId_t no)
116{
117 LOG(3, "INFO: GLMoleculeObject_molecule - atom " << no << " has been clicked.");
118 const atom * const Walker = const_cast<const World &>(World::getInstance()).
119 getAtom(AtomById(no));
120 ASSERT( Walker != NULL,
121 "GLWorldScene::atomClicked() - clicked atom has disappeared.");
122 if (selectionMode == SelectAtom){
123 if (!World::getInstance().isSelected(Walker))
124 SelectionAtomById(std::vector<atomId_t>(1,no));
125 else
126 SelectionNotAtomById(std::vector<atomId_t>(1,no));
127 }else if (selectionMode == SelectMolecule){
128 const molecule *mol = Walker->getMolecule();
129 ASSERT(mol, "Atom without molecule has been clicked.");
130 molids_t ids(1, mol->getId());
131 if (!World::getInstance().isSelected(mol))
132 SelectionMoleculeById(ids);
133 else
134 SelectionNotMoleculeById(ids);
135 }
136 emit clicked(no);
137}
138
139void GLWorldScene::moleculeClicked(moleculeId_t no)
140{
141 LOG(3, "INFO: GLMoleculeObject_molecule - mol " << no << " has been clicked.");
142 const molecule * const mol= const_cast<const World &>(World::getInstance()).
143 getMolecule(MoleculeById(no));
144 ASSERT(mol, "Atom without molecule has been clicked.");
145 molids_t ids(1, mol->getId());
146 if (!World::getInstance().isSelected(mol))
147 SelectionMoleculeById(ids);
148 else
149 SelectionNotMoleculeById(ids);
150 emit clicked(no);
151}
152
153/** Inserts an atom into the scene before molecule is present.
154 *
155 * @param _molid molecule to insert atom for
156 * @param _atomid atom to insert
157 */
158void GLWorldScene::atomInserted(const moleculeId_t _molid, const atomId_t _atomid)
159{
160 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
161
162 LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "+toString(_atomid)+".");
163
164 // check of molecule is already present
165 MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(_molid);
166 if (moliter != MoleculesinSceneMap.end()) {
167 // no action, is also caught via QtObservedMolecule by GLMoleculeObject_molecule
168 } else {
169 // store signal for when it is instantiated
170 if (MoleculeMissedStateMap.count(_molid) == 0)
171 MoleculeMissedStateMap.insert( std::make_pair(_molid ,StateChangeMap_t()) );
172 MoleculeMissedStateMap[_molid].insert( std::make_pair(_atomid, atomInsertedState) );
173 }
174}
175
176/** Removes an atom into the scene before molecule is present.
177 *
178 * @param _molid molecule to insert atom for
179 * @param _atomid atom to insert
180 */
181void GLWorldScene::atomRemoved(const moleculeId_t _molid, const atomId_t _atomid)
182{
183 LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atomid)+".");
184
185 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
186
187 // check of molecule is already present
188 MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(_molid);
189 if (moliter != MoleculesinSceneMap.end()) {
190 // no action, is also caught via QtObservedMolecule by GLMoleculeObject_molecule
191 } else {
192 // store signal for when it is instantiated
193 if (MoleculeMissedStateMap.count(_molid) == 0)
194 MoleculeMissedStateMap.insert( std::make_pair(_molid ,StateChangeMap_t()) );
195 MoleculeMissedStateMap[_molid].insert( std::make_pair(_atomid, atomRemovedState) );
196 }
197}
198
199/** Inserts a molecule into the scene.
200 *
201 * @param _mol molecule to insert
202 */
203void GLWorldScene::moleculeInserted(const moleculeId_t _id)
204{
205 LOG(3, "INFO: GLWorldScene: Received signal moleculeInserted for molecule "+toString(_id)+".");
206
207 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
208
209 MoleculeNodeMap::const_iterator iter = MoleculesinSceneMap.find(_id);
210 ASSERT( iter == MoleculesinSceneMap.end(),
211 "GLWorldScene::moleculeInserted() - molecule's id "+toString(_id)+" already present.");
212
213 // check whether molecule is still present
214 if (RemovalMolecules.count(_id) != 0) {
215 RemovalMolecules.erase(_id);
216 return;
217 }
218 if (const_cast<const World &>(World::getInstance()).getMolecule(MoleculeById(_id)) == NULL) {
219 ELOG(2, "Molecule with id " << _id << " has disappeared.");
220 return;
221 }
222
223 // add new object
224 LOG(1, "DEBUG: Adding GLMoleculeObject_molecule to id " << _id);
225 const QtObservedMolecule::ptr mol = board->getObservedMolecule(_id);
226 if (mol) {
227 GLMoleculeObject_molecule *molObject =
228 new GLMoleculeObject_molecule(
229 GLMoleculeObject::meshEmpty,
230 this,
231 *board,
232 mol);
233 ASSERT( molObject != NULL,
234 "GLWorldScene::moleculeInserted - could not create molecule object for "+toString(_id));
235 MoleculesinSceneMap.insert( make_pair(_id, molObject) );
236
237 // now handle all state changes that came up before the instantiation
238 while (MoleculeMissedStateMap.count(_id) != 0) {
239// ASSERT( !MoleculeMissedStateMap[_id].empty(),
240// "GLWorldScene::moleculeInserted() - we have an empty state change map for molecule with id "
241// +toString(_id));
242 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
243 for (StateChangeMap_t::iterator iter = MoleculeMissedStateMap[_id].begin();
244 !MoleculeMissedStateMap[_id].empty();
245 iter = MoleculeMissedStateMap[_id].begin()) {
246 std::pair<StateChangeMap_t::iterator, StateChangeMap_t::iterator> rangeiter =
247 MoleculeMissedStateMap[_id].equal_range(iter->first);
248 const size_t StateCounts = std::distance(rangeiter.first, rangeiter.second);
249 if (StateCounts > 1) {
250 // more than one state change, have to combine
251 typedef std::map<StateChangeType, size_t> StateChangeAmounts_t;
252 StateChangeAmounts_t StateChangeAmounts;
253 for (StateChangeMap_t::const_iterator stateiter = rangeiter.first;
254 stateiter != rangeiter.second; ++stateiter)
255 ++StateChangeAmounts[stateiter->second];
256 ASSERT( StateChangeAmounts[atomInsertedState] >= StateChangeAmounts[atomRemovedState],
257 "GLWorldScene::moleculeInserted() - more atomRemoved states than atomInserted for atom "
258 +toString(iter->first));
259 if (StateChangeAmounts[atomInsertedState] > StateChangeAmounts[atomRemovedState]) {
260 LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
261 QMetaObject::invokeMethod(molObject, // pointer to a QObject
262 "atomInserted", // member name (no parameters here)
263 Qt::QueuedConnection, // connection type
264 Q_ARG(const atomId_t, iter->first)); // parameters
265 } else {
266 LOG(1, "INFO: Atom " << iter->first << " has been inserted and removed already.");
267 }
268 } else {
269 // can only be an insertion
270 switch (rangeiter.first->second) {
271 case atomRemovedState:
272 ASSERT( 0,
273 "GLWorldScene::moleculeInserted() - atomRemoved state without atomInserted for atom "
274 +toString(iter->first));
275 break;
276 case atomInsertedState:
277 LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
278 QMetaObject::invokeMethod(molObject, // pointer to a QObject
279 "atomInserted", // member name (no parameters here)
280 Qt::QueuedConnection, // connection type
281 Q_ARG(const atomId_t, iter->first)); // parameters
282 break;
283 default:
284 ASSERT( 0,
285 "GLWorldScene::moleculeInserted() - there are unknown change states.");
286 break;
287 }
288 }
289 // removed state changes for this atom
290 MoleculeMissedStateMap[_id].erase(iter);
291 }
292 }
293
294 connect (molObject, SIGNAL(changed()), this, SIGNAL(changed()));
295 connect (molObject, SIGNAL(changeOccured()), this, SIGNAL(changeOccured()));
296 connect (molObject, SIGNAL(atomClicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
297 connect (molObject, SIGNAL(moleculeClicked(moleculeId_t)), this, SLOT(moleculeClicked(moleculeId_t)));
298 connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
299 connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
300 connect (molObject, SIGNAL(hoverChanged(const atomId_t)), this, SIGNAL(hoverChanged(const atomId_t)));
301 connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
302 connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
303
304 emit changed();
305 emit changeOccured();
306 }
307
308 // remove state change map for the molecule
309 {
310 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
311 MoleculeMissedStateMap.erase(_id);
312 }
313}
314
315/** Removes a molecule from the scene.
316 *
317 * @param _id id of molecule to remove
318 */
319void GLWorldScene::moleculeRemoved(const moleculeId_t _id)
320{
321 LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_id)+".");
322
323 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
324
325 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_id);
326 if ( iter == MoleculesinSceneMap.end()) {
327 RemovalMolecules.insert(_id);
328 } else {
329 LOG(1, "DEBUG: Removing GLMoleculeObject_molecule to id " << _id);
330 GLMoleculeObject_molecule *molObject = iter->second;
331 molObject->disconnect();
332 MoleculesinSceneMap.erase(iter);
333 delete molObject;
334 }
335
336 // remove any possible state changes left
337 {
338 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
339 MoleculeMissedStateMap.erase(_id);
340 }
341
342 emit changed();
343 emit changeOccured();
344}
345
346void GLWorldScene::moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid)
347{
348 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_oldid);
349 if ( iter == MoleculesinSceneMap.end()) {
350 RemovalMolecule_t::iterator removeiter =
351 RemovalMolecules.find(_oldid);
352 ASSERT( removeiter != RemovalMolecules.end(),
353 "GLWorldScene::moleculeIndexChanged() - cannot find id "+toString(_oldid)+" in any map.");
354 RemovalMolecules.erase(removeiter);
355 RemovalMolecules.insert(_newid);
356 } else {
357 LOG(1, "DEBUG: Changing GLMoleculeObject_molecule from " << _oldid << " to id " << _newid);
358 GLMoleculeObject_molecule* molObject = iter->second;
359 MoleculesinSceneMap.erase(iter);
360 MoleculesinSceneMap.insert(
361 std::make_pair( _newid, molObject) );
362 }
363}
364
365void GLWorldScene::moleculesVisibilityChanged(const moleculeId_t _id, bool _visible)
366{
367 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
368 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_id);
369 ASSERT( iter != MoleculesinSceneMap.end(),
370 "GLWorldScene::moleculeInserted() - molecule's id "+toString(_id)+" is unknown.");
371
372 GLMoleculeObject_molecule *molObject = iter->second;
373 molObject->setVisible(_visible);
374
375 emit changed();
376 emit changeOccured();
377}
378
379/** Adds a shape to the scene.
380 *
381 */
382void GLWorldScene::addShape(const std::string &_name)
383{
384 Shape * const shape = ShapeRegistry::getInstance().getByName(_name);
385 if (shape != NULL) {
386 GLMoleculeObject_shape *shapeObject = new GLMoleculeObject_shape(*shape, this);
387 ShapeNodeMap::iterator iter = ShapesinSceneMap.find(_name);
388 ASSERT(iter == ShapesinSceneMap.end(),
389 "GLWorldScene::addShape() - same shape "+_name+" added again.");
390 ShapesinSceneMap.insert( make_pair(_name, shapeObject) );
391 } else
392 ELOG(2, "GLWorldScene::addShape() - shape disappeared before we could draw it.");
393
394 emit changed();
395}
396
397void GLWorldScene::removeShape(const std::string &_name)
398{
399 ShapeNodeMap::iterator iter = ShapesinSceneMap.find(_name);
400 ASSERT(iter != ShapesinSceneMap.end(),
401 "GLWorldScene::removeShape() - shape "+_name+" not in scene.");
402 ShapesinSceneMap.erase(iter);
403 delete(iter->second);
404
405 emit changed();
406}
407
408void GLWorldScene::updateSelectedShapes()
409{
410 foreach (QObject *obj, children()) {
411 GLMoleculeObject_shape *shapeobj = qobject_cast<GLMoleculeObject_shape *>(obj);
412 if (shapeobj){
413 shapeobj->enable(ShapeRegistry::getInstance().isSelected(shapeobj->getShape()));
414 }
415 }
416
417 emit changed();
418}
419
420void GLWorldScene::initialize(QGLView *view, QGLPainter *painter) const
421{
422 // Initialize all of the mesh objects that we have as children.
423 foreach (QObject *obj, children()) {
424 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
425 if (meshobj)
426 meshobj->initialize(view, painter);
427 }
428}
429
430void GLWorldScene::draw(QGLPainter *painter, const QVector4D &cameraPlane) const
431{
432 // Draw all of the mesh objects that we have as children.
433 foreach (QObject *obj, children()) {
434 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
435 if (meshobj)
436 meshobj->draw(painter, cameraPlane);
437 }
438}
439
440void GLWorldScene::setSelectionMode(SelectionModeType mode)
441{
442 selectionMode = mode;
443 // TODO send update to toolbar
444}
445
446void GLWorldScene::setSelectionModeAtom()
447{
448 setSelectionMode(SelectAtom);
449}
450
451void GLWorldScene::setSelectionModeMolecule()
452{
453 setSelectionMode(SelectMolecule);
454}
455
456void GLWorldScene::changeMoleculeId(
457 GLMoleculeObject_molecule *ob,
458 const moleculeId_t oldId,
459 const moleculeId_t newId)
460{
461 LOG(3, "INFO: GLWorldScene - change molecule id " << oldId << " to " << newId << ".");
462
463 {
464 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
465 // Remove from map.
466 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(oldId);
467 ASSERT(iter != MoleculesinSceneMap.end(),
468 "GLWorldScene::changeMoleculeId() - molecule with old id "+toString(oldId)+" not on display.");
469 ASSERT(iter->second == ob,
470 "GLWorldScene::changeMoleculeId() - molecule with id "
471 +toString(oldId)+" does not match with object in MoleculesinSceneMap.");
472 MoleculesinSceneMap.erase(iter);
473
474 // Reinsert with new id.
475 {
476 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(newId);
477 ASSERT(iter == MoleculesinSceneMap.end(),
478 "GLWorldScene::changeMoleculeId() - moleculewith new id "+toString(newId)+" already known.");
479 }
480 MoleculesinSceneMap.insert( make_pair(newId, ob) );
481 }
482
483 {
484 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
485 // Remove and re-insert from map if present.
486 MoleculeMissedStateMap_t::iterator iter = MoleculeMissedStateMap.find(oldId);
487 if (iter != MoleculeMissedStateMap.end()) {
488 StateChangeMap_t changemap = iter->second;
489 MoleculeMissedStateMap.erase(iter);
490 MoleculeMissedStateMap.insert( std::make_pair(newId, changemap) );
491 }
492 }
493}
494
Note: See TracBrowser for help on using the repository browser.