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

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 4ab5dc was 07136a, checked in by Frederik Heber <heber@…>, 9 years ago

FIX: Fixing display of shapes in GLWorldView.

  • we propagate shape name via S/S system such that we may lookup the name in ShapeRegistry and do not have to rely on probably already deallocated lastchanged() shape. This affects ShapeAdded() and ShapeRemoved().
  • GLMoleculeObject_shape now copies the shape, ensuring that its present while its surface is tesselated.
  • Property mode set to 100644
File size: 20.1 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/Views/Qt4/QtSelectionChangedAgent.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(QObject *parent) :
75 QObject(parent),
76 selectionMode(SelectAtom)
77{
78 int sphereDetails[] = {5, 3, 2, 0};
79 int cylinderDetails[] = {16, 8, 6, 3};
80 for (int i=0;i<GLMoleculeObject::DETAILTYPES_MAX;i++){
81 QGLBuilder emptyBuilder;
82 GLMoleculeObject::meshEmpty[i] = emptyBuilder.finalizedSceneNode();
83 QGLBuilder sphereBuilder;
84 sphereBuilder << QGLSphere(2.0, sphereDetails[i]);
85 GLMoleculeObject::meshSphere[i] = sphereBuilder.finalizedSceneNode();
86 GLMoleculeObject::meshSphere[i]->setOption(QGLSceneNode::CullBoundingBox, true);
87 QGLBuilder cylinderBuilder;
88 cylinderBuilder << QGLCylinder(.25,.25,1.0,cylinderDetails[i]);
89 GLMoleculeObject::meshCylinder[i] = cylinderBuilder.finalizedSceneNode();
90 GLMoleculeObject::meshCylinder[i]->setOption(QGLSceneNode::CullBoundingBox, true);
91 }
92
93// connect(this, SIGNAL(updated()), this, SLOT(update()));
94}
95
96GLWorldScene::~GLWorldScene()
97{
98 // remove all elements
99 GLMoleculeObject::cleanMaterialMap();
100}
101
102///** Update the WorldScene with molecules and atomsfrom World.
103// *
104// * This function should be called after e.g. WorldTime::TimeChanged was
105// * received or after another molecule has been loaded.
106// *
107// */
108//void GLWorldScene::update()
109//{
110// const std::vector<const molecule *> &molecules =
111// const_cast<const World &>(World::getInstance()).getAllMolecules();
112//
113// for (std::vector<const molecule*>::const_iterator moliter = molecules.begin();
114// moliter != molecules.end();
115// moliter++) {
116// // check whether molecule already exists
117// const moleculeId_t molid = (*moliter)->getId();
118// const bool mol_present = MoleculesinSceneMap.count(molid);
119// if (!mol_present)
120// moleculeInserted((*moliter)->getId());
121// }
122//
123// MoleculeNodeMap::iterator iter = MoleculesinSceneMap.begin();
124// for (;iter != MoleculesinSceneMap.end();) {
125// const moleculeId_t molid = iter->first;
126// const molecule * const mol = const_cast<const World &>(World::getInstance()).
127// getMolecule(MoleculeById(molid));
128// const bool mol_absent = (mol == NULL);
129// // step on to next molecule before possibly removing entry and invalidating iter
130// ++iter;
131// if (mol_absent)
132// moleculeRemoved(molid);
133// }
134//
135//}
136
137void GLWorldScene::atomClicked(atomId_t no)
138{
139 LOG(3, "INFO: GLMoleculeObject_molecule - atom " << no << " has been clicked.");
140 const atom * const Walker = const_cast<const World &>(World::getInstance()).
141 getAtom(AtomById(no));
142 ASSERT( Walker != NULL,
143 "GLWorldScene::atomClicked() - clicked atom has disappeared.");
144 if (selectionMode == SelectAtom){
145 if (!World::getInstance().isSelected(Walker))
146 SelectionAtomById(std::vector<atomId_t>(1,no));
147 else
148 SelectionNotAtomById(std::vector<atomId_t>(1,no));
149 }else if (selectionMode == SelectMolecule){
150 const molecule *mol = Walker->getMolecule();
151 ASSERT(mol, "Atom without molecule has been clicked.");
152 molids_t ids(1, mol->getId());
153 if (!World::getInstance().isSelected(mol))
154 SelectionMoleculeById(ids);
155 else
156 SelectionNotMoleculeById(ids);
157 }
158 emit clicked(no);
159}
160
161void GLWorldScene::moleculeClicked(moleculeId_t no)
162{
163 LOG(3, "INFO: GLMoleculeObject_molecule - mol " << no << " has been clicked.");
164 const molecule * const mol= const_cast<const World &>(World::getInstance()).
165 getMolecule(MoleculeById(no));
166 ASSERT(mol, "Atom without molecule has been clicked.");
167 molids_t ids(1, mol->getId());
168 if (!World::getInstance().isSelected(mol))
169 SelectionMoleculeById(ids);
170 else
171 SelectionNotMoleculeById(ids);
172 emit clicked(no);
173}
174
175/** Inserts an atom into the scene before molecule is present.
176 *
177 * @param _molid molecule to insert atom for
178 * @param _atomid atom to insert
179 */
180void GLWorldScene::atomInserted(const moleculeId_t _molid, const atomId_t _atomid)
181{
182 LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "+toString(_atomid)+".");
183
184 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
185
186 // check of molecule is already present
187 if (MoleculesinSceneMap.count(_molid) != 0) {
188 // pass signal through
189 } else {
190 // store signal for when it is instantiated
191 if (MoleculeMissedStateMap.count(_molid) == 0)
192 MoleculeMissedStateMap.insert( std::make_pair(_molid ,StateChangeMap_t()) );
193 MoleculeMissedStateMap[_molid].insert( std::make_pair(_atomid, atomInsertedState) );
194 }
195}
196
197/** Removes an atom into the scene before molecule is present.
198 *
199 * @param _molid molecule to insert atom for
200 * @param _atomid atom to insert
201 */
202void GLWorldScene::atomRemoved(const moleculeId_t _molid, const atomId_t _atomid)
203{
204 LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atomid)+".");
205
206 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
207
208 // check of molecule is already present
209 if (MoleculesinSceneMap.count(_molid) != 0) {
210 // pass signal through
211 } else {
212 // store signal for when it is instantiated
213 if (MoleculeMissedStateMap.count(_molid) == 0)
214 MoleculeMissedStateMap.insert( std::make_pair(_molid ,StateChangeMap_t()) );
215 MoleculeMissedStateMap[_molid].insert( std::make_pair(_atomid, atomRemovedState) );
216 }
217}
218
219/** Inserts a molecule into the scene.
220 *
221 * @param _mol molecule to insert
222 */
223void GLWorldScene::moleculeInserted(const moleculeId_t _id)
224{
225 LOG(3, "INFO: GLWorldScene: Received signal moleculeInserted for molecule "+toString(_id)+".");
226 MoleculeNodeMap::const_iterator iter = MoleculesinSceneMap.find(_id);
227 ASSERT( iter == MoleculesinSceneMap.end(),
228 "GLWorldScene::moleculeInserted() - molecule's id "+toString(_id)+" already present.");
229
230 // check whether molecule is still present
231 if (RemovalMolecules.count(_id) != 0) {
232 RemovalMolecules.erase(_id);
233 return;
234 }
235 if (const_cast<const World &>(World::getInstance()).getMolecule(MoleculeById(_id)) == NULL)
236 return;
237
238 // add new object
239 GLMoleculeObject_molecule *molObject =
240 new GLMoleculeObject_molecule(GLMoleculeObject::meshEmpty, this, _id);
241 ASSERT( molObject != NULL,
242 "GLWorldScene::moleculeInserted - could not create molecule object for "+toString(_id));
243 MoleculesinSceneMap.insert( make_pair(_id, molObject) );
244
245 // now handle all state changes that came up before the instantiation
246 while (MoleculeMissedStateMap.count(_id) != 0) {
247 ASSERT( !MoleculeMissedStateMap[_id].empty(),
248 "GLWorldScene::moleculeInserted() - we have an empty state change map for molecule with id "
249 +toString(_id));
250 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
251 for (StateChangeMap_t::iterator iter = MoleculeMissedStateMap[_id].begin();
252 !MoleculeMissedStateMap[_id].empty();
253 iter = MoleculeMissedStateMap[_id].begin()) {
254 std::pair<StateChangeMap_t::iterator, StateChangeMap_t::iterator> rangeiter =
255 MoleculeMissedStateMap[_id].equal_range(iter->first);
256 const size_t StateCounts = std::distance(rangeiter.first, rangeiter.second);
257 if (StateCounts > 1) {
258 // more than one state change, have to combine
259 typedef std::map<StateChangeType, size_t> StateChangeAmounts_t;
260 StateChangeAmounts_t StateChangeAmounts;
261 for (StateChangeMap_t::const_iterator stateiter = rangeiter.first;
262 stateiter != rangeiter.second; ++stateiter)
263 ++StateChangeAmounts[stateiter->second];
264 ASSERT( StateChangeAmounts[atomInsertedState] >= StateChangeAmounts[atomRemovedState],
265 "GLWorldScene::moleculeInserted() - more atomRemoved states than atomInserted for atom "
266 +toString(iter->first));
267 if (StateChangeAmounts[atomInsertedState] > StateChangeAmounts[atomRemovedState]) {
268 LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
269 QMetaObject::invokeMethod(molObject, // pointer to a QObject
270 "atomInserted", // member name (no parameters here)
271 Qt::DirectConnection, // connection type
272 Q_ARG(const atomId_t, iter->first)); // parameters
273 } else {
274 LOG(1, "INFO: Atom " << iter->first << " has been inserted and removed already.");
275 }
276 } else {
277 // can only be an insertion
278 switch (rangeiter.first->second) {
279 case atomRemovedState:
280 ASSERT( 0,
281 "GLWorldScene::moleculeInserted() - atomRemoved state without atomInserted for atom "
282 +toString(iter->first));
283 break;
284 case atomInsertedState:
285 LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
286 QMetaObject::invokeMethod(molObject, // pointer to a QObject
287 "atomInserted", // member name (no parameters here)
288 Qt::DirectConnection, // connection type
289 Q_ARG(const atomId_t, iter->first)); // parameters
290 break;
291 default:
292 ASSERT( 0,
293 "GLWorldScene::moleculeInserted() - there are unknown change states.");
294 break;
295 }
296 }
297 // removed state changes for this atom
298 MoleculeMissedStateMap[_id].erase(iter);
299 }
300 // remove state change map for the molecule
301 MoleculeMissedStateMap.erase(_id);
302 }
303
304 // now let the molObject sign on to molecule
305 molObject->activateObserver();
306
307 connect (molObject, SIGNAL(changed()), this, SIGNAL(changed()));
308 connect (molObject, SIGNAL(changeOccured()), this, SIGNAL(changeOccured()));
309 connect (molObject, SIGNAL(atomClicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
310 connect (molObject, SIGNAL(moleculeClicked(moleculeId_t)), this, SLOT(moleculeClicked(moleculeId_t)));
311 connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
312 connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
313 connect (molObject, SIGNAL(hoverChanged(const atomId_t)), this, SIGNAL(hoverChanged(const atomId_t)));
314 connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
315 connect (molObject, SIGNAL(indexChanged(GLMoleculeObject_molecule *, const moleculeId_t, const moleculeId_t)), this, SLOT(changeMoleculeId(GLMoleculeObject_molecule *, const moleculeId_t, const moleculeId_t)));
316
317 emit changed();
318 emit changeOccured();
319}
320
321/** Removes a molecule from the scene.
322 *
323 * @param _id id of molecule to remove
324 */
325void GLWorldScene::moleculeRemoved(const moleculeId_t _id)
326{
327 LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_id)+".");
328 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_id);
329 if ( iter == MoleculesinSceneMap.end())
330 RemovalMolecules.insert(_id);
331 else {
332
333 GLMoleculeObject_molecule *molObject = iter->second;
334 molObject->disconnect();
335 MoleculesinSceneMap.erase(iter);
336 delete molObject;
337
338 // remove any possible state changes left
339 {
340 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
341 MoleculeMissedStateMap.erase(_id);
342 }
343
344 emit changed();
345 emit changeOccured();
346 }
347}
348
349void GLWorldScene::moleculesVisibilityChanged(const moleculeId_t _id, bool _visible)
350{
351 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_id);
352 ASSERT( iter != MoleculesinSceneMap.end(),
353 "GLWorldScene::moleculeInserted() - molecule's id "+toString(_id)+" is unknown.");
354
355 GLMoleculeObject_molecule *molObject = iter->second;
356 molObject->setVisible(_visible);
357
358 emit changed();
359 emit changeOccured();
360}
361
362/** Adds a shape to the scene.
363 *
364 */
365void GLWorldScene::addShape(const std::string &_name)
366{
367 Shape * const shape = ShapeRegistry::getInstance().getByName(_name);
368 if (shape != NULL) {
369 GLMoleculeObject_shape *shapeObject = new GLMoleculeObject_shape(*shape, this);
370 ShapeNodeMap::iterator iter = ShapesinSceneMap.find(_name);
371 ASSERT(iter == ShapesinSceneMap.end(),
372 "GLWorldScene::addShape() - same shape "+_name+" added again.");
373 ShapesinSceneMap.insert( make_pair(_name, shapeObject) );
374 } else
375 ELOG(2, "GLWorldScene::addShape() - shape disappeared before we could draw it.");
376
377 emit changed();
378}
379
380void GLWorldScene::removeShape(const std::string &_name)
381{
382 ShapeNodeMap::iterator iter = ShapesinSceneMap.find(_name);
383 ASSERT(iter != ShapesinSceneMap.end(),
384 "GLWorldScene::removeShape() - shape "+_name+" not in scene.");
385 ShapesinSceneMap.erase(iter);
386 delete(iter->second);
387
388 emit changed();
389}
390
391void GLWorldScene::updateSelectedShapes()
392{
393 foreach (QObject *obj, children()) {
394 GLMoleculeObject_shape *shapeobj = qobject_cast<GLMoleculeObject_shape *>(obj);
395 if (shapeobj){
396 shapeobj->enable(ShapeRegistry::getInstance().isSelected(shapeobj->getShape()));
397 }
398 }
399
400 emit changed();
401}
402
403void GLWorldScene::initialize(QGLView *view, QGLPainter *painter) const
404{
405 // Initialize all of the mesh objects that we have as children.
406 foreach (QObject *obj, children()) {
407 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
408 if (meshobj)
409 meshobj->initialize(view, painter);
410 }
411}
412
413void GLWorldScene::draw(QGLPainter *painter, const QVector4D &cameraPlane) const
414{
415 // Draw all of the mesh objects that we have as children.
416 foreach (QObject *obj, children()) {
417 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
418 if (meshobj)
419 meshobj->draw(painter, cameraPlane);
420 }
421}
422
423void GLWorldScene::setSelectionMode(SelectionModeType mode)
424{
425 selectionMode = mode;
426 // TODO send update to toolbar
427}
428
429void GLWorldScene::setSelectionChangedAgent(QtSelectionChangedAgent *agent)
430{
431 connect(agent, SIGNAL(atomSelected(const moleculeId_t, const atomId_t)),
432 this, SLOT(AtomSelected(const moleculeId_t, const atomId_t)));
433 connect(agent, SIGNAL(atomUnselected(const moleculeId_t, const atomId_t)),
434 this, SLOT(AtomUnselected(const moleculeId_t, const atomId_t)));
435
436 connect(agent, SIGNAL(moleculeSelected(const moleculeId_t)),
437 this, SLOT(MoleculeSelected(const moleculeId_t)));
438 connect(agent, SIGNAL(moleculeUnselected(const moleculeId_t)),
439 this, SLOT(MoleculeUnselected(const moleculeId_t)));
440}
441
442void GLWorldScene::setSelectionModeAtom()
443{
444 setSelectionMode(SelectAtom);
445}
446
447void GLWorldScene::setSelectionModeMolecule()
448{
449 setSelectionMode(SelectMolecule);
450}
451
452void GLWorldScene::changeMoleculeId(
453 GLMoleculeObject_molecule *ob,
454 const moleculeId_t oldId,
455 const moleculeId_t newId)
456{
457 LOG(3, "INFO: GLWorldScene - change molecule id " << oldId << " to " << newId << ".");
458
459 {
460 // Remove from map.
461 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(oldId);
462 ASSERT(iter != MoleculesinSceneMap.end(),
463 "GLWorldScene::changeMoleculeId() - molecule with old id "+toString(oldId)+" not on display.");
464 ASSERT(iter->second == ob,
465 "GLWorldScene::changeMoleculeId() - molecule with id "
466 +toString(oldId)+" does not match with object in MoleculesinSceneMap.");
467 MoleculesinSceneMap.erase(iter);
468
469 // Reinsert with new id.
470 {
471 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(newId);
472 ASSERT(iter == MoleculesinSceneMap.end(),
473 "GLWorldScene::changeMoleculeId() - moleculewith new id "+toString(newId)+" already known.");
474 }
475 MoleculesinSceneMap.insert( make_pair(newId, ob) );
476 }
477
478 {
479 // Remove and re-insert from map if present.
480 MoleculeMissedStateMap_t::iterator iter = MoleculeMissedStateMap.find(oldId);
481 if (iter != MoleculeMissedStateMap.end()) {
482 StateChangeMap_t changemap = iter->second;
483 MoleculeMissedStateMap.erase(iter);
484 MoleculeMissedStateMap.insert( std::make_pair(newId, changemap) );
485 }
486 }
487}
488
489void GLWorldScene::AtomSelected(const moleculeId_t _molid, const atomId_t _id)
490{
491 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molid);
492 if (iter != MoleculesinSceneMap.end())
493 QMetaObject::invokeMethod(iter->second, // pointer to a QObject
494 "AtomSelected", // member name (no parameters here)
495 Qt::QueuedConnection, // connection type
496 Q_ARG(const atomId_t, _id)); // parameters
497 else
498 ELOG(2, "DEBUG: GLWorldScene::AtomSelected() - molecule " <<
499 _molid << " unknown to GLWorldScene.");
500}
501
502void GLWorldScene::AtomUnselected(const moleculeId_t _molid, const atomId_t _id)
503{
504 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molid);
505 if (iter != MoleculesinSceneMap.end())
506 QMetaObject::invokeMethod(iter->second, // pointer to a QObject
507 "AtomUnselected", // member name (no parameters here)
508 Qt::QueuedConnection, // connection type
509 Q_ARG(const atomId_t, _id)); // parameters
510 else
511 ELOG(2, "GLWorldScene::AtomUnselected() - molecule "
512 << _molid << " unknown to GLWorldScene.");
513}
514
515void GLWorldScene::MoleculeSelected(const moleculeId_t _molid)
516{
517 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molid);
518 if (iter != MoleculesinSceneMap.end())
519 QMetaObject::invokeMethod(iter->second, // pointer to a QObject
520 "Selected", // member name (no parameters here)
521 Qt::QueuedConnection); // connection type
522 else
523 ELOG(2, "GLWorldScene::MoleculeSelected() - molecule "
524 << _molid << " unknown to GLWorldScene.");
525}
526
527void GLWorldScene::MoleculeUnselected(const moleculeId_t _molid)
528{
529 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molid);
530 if (iter != MoleculesinSceneMap.end())
531 QMetaObject::invokeMethod(iter->second, // pointer to a QObject
532 "Unselected", // member name (no parameters here)
533 Qt::QueuedConnection); // connection type
534 else
535 ELOG(2, "GLWorldScene::MoleculeUnselected() - molecule "
536 << _molid << " unknown to GLWorldScene.");
537}
Note: See TracBrowser for help on using the repository browser.