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

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 8d5fbf1 was 8d5fbf1, checked in by Frederik Heber <heber@…>, 9 years ago

GLMoleculeObject_atom, _bond, _molecule all use QtInstanceInformationBoard passed via GLWorldScene.

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