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

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 Candidate_v1.7.0 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 e4b13a was 96f14a, checked in by Frederik Heber <heber@…>, 10 years ago

Modified all GLMoleculeObjects and GLWorldScene to the new QtObservedBond.

  • GLWorldScene transmits bondInserted/bondRemoved similarly to those for the atoms to the molecule if aLready present and otherwise into the MissedStateMap.
  • Property mode set to 100644
File size: 39.7 KB
RevLine 
[907636]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[5aaa43]5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
[94d5ac6]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/>.
[907636]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"
[d1196d]39#include <Qt3D/qglview.h>
[bca99d]40#include <Qt3D/qglbuilder.h>
41#include <Qt3D/qglscenenode.h>
42#include <Qt3D/qglsphere.h>
43#include <Qt3D/qglcylinder.h>
[907636]44
[015f8c]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
[2f7988]51#include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
[907636]52
53#include "CodePatterns/MemDebug.hpp"
54
[7188b1]55#include "CodePatterns/Log.hpp"
56
[0e9ffe]57#include "Actions/SelectionAction/Atoms/AtomByIdAction.hpp"
[89643d]58#include "Actions/SelectionAction/Atoms/NotAtomByIdAction.hpp"
[6966b7]59#include "Actions/SelectionAction/Molecules/MoleculeByIdAction.hpp"
60#include "Actions/SelectionAction/Molecules/NotMoleculeByIdAction.hpp"
[6f0841]61#include "Atom/atom.hpp"
[7188b1]62#include "Bond/bond.hpp"
[89643d]63#include "Descriptors/AtomIdDescriptor.hpp"
[8c001a]64#include "Descriptors/MoleculeIdDescriptor.hpp"
[37b2575]65#include "Helpers/helpers.hpp"
[85c36d]66#include "Shapes/ShapeRegistry.hpp"
[907636]67#include "molecule.hpp"
68#include "World.hpp"
69
[2ad1ec]70#include <iostream>
71
[ce7fdc]72using namespace MoleCuilder;
[907636]73
[15c8a9]74GLWorldScene::GLWorldScene(
[2f7988]75 QtObservedInstanceBoard * _board,
[15c8a9]76 QObject *parent) :
77 QObject(parent),
78 selectionMode(SelectAtom),
79 board(_board)
[907636]80{
[72a4c1]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;
[8c001a]85 GLMoleculeObject::meshEmpty[i] = emptyBuilder.finalizedSceneNode();
[72a4c1]86 QGLBuilder sphereBuilder;
87 sphereBuilder << QGLSphere(2.0, sphereDetails[i]);
[8c001a]88 GLMoleculeObject::meshSphere[i] = sphereBuilder.finalizedSceneNode();
89 GLMoleculeObject::meshSphere[i]->setOption(QGLSceneNode::CullBoundingBox, true);
[72a4c1]90 QGLBuilder cylinderBuilder;
91 cylinderBuilder << QGLCylinder(.25,.25,1.0,cylinderDetails[i]);
[8c001a]92 GLMoleculeObject::meshCylinder[i] = cylinderBuilder.finalizedSceneNode();
93 GLMoleculeObject::meshCylinder[i]->setOption(QGLSceneNode::CullBoundingBox, true);
[72a4c1]94 }
[1b07b1]95 connect(board, SIGNAL(moleculeInserted(QtObservedMolecule::ptr)),
[59f1bc]96 this, SLOT(moleculeSignOn(QtObservedMolecule::ptr)), Qt::DirectConnection);
[f91ef6]97 connect(board, SIGNAL(moleculeRemoved(ObservedValue_Index_t)),
98 this, SLOT(moleculeSignOff(ObservedValue_Index_t)), Qt::DirectConnection);
[59f1bc]99 connect(board, SIGNAL(atomInserted(QtObservedAtom::ptr)),
100 this, SLOT(atomInserted(QtObservedAtom::ptr)));
[f91ef6]101 connect(board, SIGNAL(atomRemoved(ObservedValue_Index_t)),
102 this, SLOT(atomRemoved(ObservedValue_Index_t)));
[96f14a]103 connect(board, SIGNAL(bondInserted(QtObservedBond::ptr)),
104 this, SLOT(bondInserted(QtObservedBond::ptr)));
105 connect(board, SIGNAL(bondRemoved(ObservedValue_Index_t)),
106 this, SLOT(bondRemoved(ObservedValue_Index_t)));
[8281cc]107 connect(this, SIGNAL(insertMolecule(QtObservedMolecule::ptr)),
108 this, SLOT(moleculeInserted(QtObservedMolecule::ptr)) );
[e29427]109 connect(this, SIGNAL(removeMolecule(QtObservedMolecule*)),
110 this, SLOT(moleculeRemoved(QtObservedMolecule*)) );
[0a6ff9]111
[f714763]112// connect(this, SIGNAL(updated()), this, SLOT(update()));
[907636]113}
114
115GLWorldScene::~GLWorldScene()
[7188b1]116{
117 // remove all elements
118 GLMoleculeObject::cleanMaterialMap();
119}
[907636]120
[8c001a]121void GLWorldScene::atomClicked(atomId_t no)
122{
123 LOG(3, "INFO: GLMoleculeObject_molecule - atom " << no << " has been clicked.");
[f01769]124 const atom * const Walker = const_cast<const World &>(World::getInstance()).
125 getAtom(AtomById(no));
[369cb1]126 ASSERT( Walker != NULL,
127 "GLWorldScene::atomClicked() - clicked atom has disappeared.");
[8c001a]128 if (selectionMode == SelectAtom){
129 if (!World::getInstance().isSelected(Walker))
130 SelectionAtomById(std::vector<atomId_t>(1,no));
131 else
132 SelectionNotAtomById(std::vector<atomId_t>(1,no));
133 }else if (selectionMode == SelectMolecule){
134 const molecule *mol = Walker->getMolecule();
135 ASSERT(mol, "Atom without molecule has been clicked.");
[d7cad1]136 molids_t ids(1, mol->getId());
[8c001a]137 if (!World::getInstance().isSelected(mol))
[d7cad1]138 SelectionMoleculeById(ids);
[8c001a]139 else
[d7cad1]140 SelectionNotMoleculeById(ids);
[8c001a]141 }
142 emit clicked(no);
143}
144
[9a7ef9]145void GLWorldScene::moleculeClicked(moleculeId_t no)
146{
147 LOG(3, "INFO: GLMoleculeObject_molecule - mol " << no << " has been clicked.");
[63fb7a]148 const molecule * const mol= const_cast<const World &>(World::getInstance()).
149 getMolecule(MoleculeById(no));
[9a7ef9]150 ASSERT(mol, "Atom without molecule has been clicked.");
[d7cad1]151 molids_t ids(1, mol->getId());
[9a7ef9]152 if (!World::getInstance().isSelected(mol))
[d7cad1]153 SelectionMoleculeById(ids);
[9a7ef9]154 else
[d7cad1]155 SelectionNotMoleculeById(ids);
[9a7ef9]156 emit clicked(no);
157}
158
[59f1bc]159/** Prepares insertion of a general atom.
[9c259e]160 *
[59f1bc]161 * This is called before the insertion into a molecule and thus before the
162 * insertion into the scene.
163 *
164 * @param _atom atom to insert
[9c259e]165 */
[1b07b1]166void GLWorldScene::atomInserted(QtObservedAtom::ptr _atom)
[9c259e]167{
[f91ef6]168 const ObservedValue_Index_t atomid = _atom->getIndex();
[59f1bc]169 ASSERT( QtObservedAtomMap.find(atomid) == QtObservedAtomMap.end(),
[f91ef6]170 "GLWorldScene::AtomInserted() - atom with id "+toString(_atom->getAtomIndex())
[59f1bc]171 +" is already present in QtObservedAtomMap.");
172 QtObservedAtomMap[atomid] = _atom;
173}
174
175/** Removes an general atom.
176 *
177 * This is called when the atom has been removed from the molecule.
178 *
179 * @param _atom atom to remove
180 */
[f91ef6]181void GLWorldScene::atomRemoved(ObservedValue_Index_t _atomid)
[59f1bc]182{
183 const QtObservedAtomMap_t::iterator eraseiter = QtObservedAtomMap.find(_atomid);
184 ASSERT( eraseiter != QtObservedAtomMap.end(),
185 "GLWorldScene::AtomRemoved() - atom with id "+toString(_atomid)
186 +" is not present in QtObservedAtomMap.");
187 QtObservedAtomMap.erase(eraseiter);
188}
189
[96f14a]190/** Prepares insertion of a bond.
191 *
192 * This is called before the insertion into a molecule and thus before the
193 * insertion into the scene.
194 *
195 * @param _bond bond to insert
196 */
197void GLWorldScene::bondInserted(QtObservedBond::ptr _bond)
198{
199 const ObservedValue_Index_t bondid = _bond->getIndex();
200 ASSERT( QtObservedBondMap.find(bondid) == QtObservedBondMap.end(),
201 "GLWorldScene::BondInserted() - bond with id "+toString(_bond->getBondIndex())
202 +" is already present in QtObservedBondMap.");
203 QtObservedBondMap[bondid] = _bond;
204
205 // assign to its molecule if present
206 const moleculeId_t molid = _bond->getMoleculeIndex();
207 if (molid != (moleculeId_t)-1) {
208 QtObservedMolecule::ptr mol = board->getObservedMolecule(molid);
209 emit moleculesBondInserted(_bond, mol.get());
210 } else {
211 // watch bond till it has a molecule
212 connect( _bond.get(), SIGNAL(moleculeIndexChanged(moleculeId_t,moleculeId_t)),
213 this, SLOT(bondsMoleculeChanged(moleculeId_t, moleculeId_t)));
214 }
215}
216
217/** Handle change of molecule from initial none.
218 *
219 */
220void GLWorldScene::bondsMoleculeChanged(moleculeId_t _oldid, moleculeId_t _newid)
221{
222 ASSERT( _oldid == (moleculeId_t)-1,
223 "GLWorldScene::bondsMoleculeChanged() - got true index change from "
224 +toString(_oldid)+" to "+toString(_newid)+" and not just added to mol.");
225 QtObservedBond* bondref = static_cast<QtObservedBond*>(sender());
226
227 // disconnect from further molecule changes
228 disconnect( bondref, SIGNAL(moleculeIndexChanged(moleculeId_t,moleculeId_t)),
229 this, SLOT(bondsMoleculeChanged(moleculeId_t, moleculeId_t)));
230
231 // add it to its molecule
232 QtObservedMolecule::ptr mol = board->getObservedMolecule(_newid);
233 emit moleculesBondInserted(bondref->getRef(), mol.get());
234}
235
236
237/** Removes an general bond.
238 *
239 * This is called when the bond has been removed from the molecule.
240 *
241 * @param _bond bond to remove
242 */
243void GLWorldScene::bondRemoved(ObservedValue_Index_t _bondid)
244{
245 const QtObservedBondMap_t::iterator eraseiter = QtObservedBondMap.find(_bondid);
246 ASSERT( eraseiter != QtObservedBondMap.end(),
247 "GLWorldScene::BondRemoved() - bond with id "+toString(_bondid)
248 +" is not present in QtObservedBondMap.");
249 QtObservedBond::ptr bondref = eraseiter->second;
250
251 // tell its assigned molecule if present
252 const moleculeId_t molid = bondref->getMoleculeIndex();
253 if (molid != (moleculeId_t)-1) {
254 QtObservedMolecule::ptr mol = board->getObservedMolecule(molid);
255 emit moleculesBondRemoved(_bondid, mol.get());
256 } else {
257 // it might have still been waiting for a molecule assignment
258 disconnect( bondref.get(), SIGNAL(moleculeIndexChanged(moleculeId_t,moleculeId_t)),
259 this, SLOT(bondsMoleculeChanged(moleculeId_t, moleculeId_t)));
260 }
261 QtObservedBondMap.erase(eraseiter);
262}
263
[59f1bc]264/** Inserts an atom into the scene when molecule is present.
265 *
266 * @param _atom atom to insert
267 */
[96e145]268void GLWorldScene::moleculesAtomInserted(QtObservedAtom::ptr _atom, QtObservedMolecule * _mol)
[59f1bc]269{
[f91ef6]270 const ObservedValue_Index_t atomid = _atom->getIndex();
[1187c5]271 // this ASSERT cannot work: The same molecule may get reassigned to a different
272 // molecule, when e.g. the time step changes (which triggers an update-molecules).
273 // The GUI is slow and may lack behind and thus get to execute the event
274 // moleculeAtomInserted when the change has been already been done.
275// ASSERT( (atommol == NULL) || (_mol == atommol),
276// "GLWorldScene::moleculesAtomInserted() - atom "+toString(atomid)
277// +" claims to belong to QtObservedMolecule "+toString(atommol)
278// +" but signal came from QtObservedMolecule "+toString(_mol)+".");
[f91ef6]279 LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom " << _atom->getAtomIndex());
280 const ObservedValue_Index_t molid = _mol->getIndex();
[7c7c4a]281
[9c259e]282 // check of molecule is already present
[59f1bc]283 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
[96e145]284 const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
[8d5fbf1]285 if (moliter != MoleculesinSceneMap.end()) {
[4a187d]286 const RemovedMoleculesMap_t::iterator emptyiter = EmptyMolecules.find(_mol);
287 if (emptyiter != EmptyMolecules.end())
288 EmptyMolecules.erase(emptyiter);
[96e145]289 // check that it is the right molecule
290 QtObservedMolecule::ptr &checkmol = moliter->second->ObservedMolecule;
291 if (checkmol.get() == _mol) {
[f91ef6]292 LOG(3, "INFO: GLWorldScene: Sending signal moleculesAtomInserted for atom "
293 << _atom->getAtomIndex());
[96e145]294 QMetaObject::invokeMethod(moliter->second, // pointer to a QObject
295 "atomInserted", // member name (no parameters here)
296 Qt::QueuedConnection, // connection type
297 Q_ARG(QtObservedAtom::ptr, _atom)); // parameters
298 } else {
299 // relay atomRemoved to GLMoleculeObject_molecule in RemovedMolecules
300// LOG(3, "INFO: GLWorldScene: Sending signal moleculesAtomInserted for atom "+toString(_atomid)
301// +" to molecule in RemovedMolecules.");
[e29427]302// const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(molid);
[96e145]303// ASSERT( removedmoliter != RemovedMolecules.end(),
304// "GLWorldScene::moleculesAtomInserted() - signal from old mol "
305// +toString(molid)+", but not present in RemovedMolecules");
306// QMetaObject::invokeMethod(removedmoliter->second, // pointer to a QObject
307// "atomInserted ", // member name (no parameters here)
308// Qt::QueuedConnection, // connection type
309// Q_ARG(QtObservedAtom::ptr, _atom)); // parameters
310 ASSERT( 0,
311 "GLWorldScene::moleculesAtomInserted() - would need to send atomInserted to already removed molecule.");
312 }
[9c259e]313 } else {
[e29427]314 const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);
315 if (removedmoliter != RemovedMolecules.end()) {
316 ASSERT( 0,
317 "GLWorldScene::moleculesAtomInserted() - would need to send atomInserted to already removed molecule.");
318 } else {
319 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
320 // only record missed state for molecule if (still) present but not instantiated
321 if (QtObservedMoleculeMap.count(molid)) {
322 // store signal for when it is instantiated
323 if (MoleculeMissedStateMap.count(molid) == 0)
324 MoleculeMissedStateMap.insert( std::make_pair(molid ,StateChangeMap_t()) );
325 MoleculeMissedStateMap[molid].insert( std::make_pair(atomid, atomInsertedState) );
326 ASSERT( QtObservedAtomMap[atomid] == _atom,
327 "GLWorldScene::moleculesAtomInserted() - atom "+toString(atomid)
[f91ef6]328 +" inserted in molecule "+toString(_mol->getMolIndex())
[e29427]329 +" which does not match atom in QtObservedAtomMap.");
[f91ef6]330 LOG(3, "INFO: GLWorldScene: Placing atomInserted for atom " << _atom->getAtomIndex()
331 << " and molecule " << _mol->getMolIndex() << " into missed state map.");
[e29427]332 }
[59f1bc]333 }
[9c259e]334 }
335}
336
337/** Removes an atom into the scene before molecule is present.
338 *
[59f1bc]339 * @param _atomid atom to remove
[9c259e]340 */
[f91ef6]341void GLWorldScene::moleculesAtomRemoved(ObservedValue_Index_t _atomid, QtObservedMolecule * _mol)
[9c259e]342{
[8281cc]343 LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atomid)+".");
344
[f91ef6]345 const ObservedValue_Index_t molid = _mol->getIndex();
[805fdc]346 // check of molecule is already present
347 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
348 const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
349 if (moliter != MoleculesinSceneMap.end()) {
350 const QtObservedMolecule::ptr &checkmol = moliter->second->ObservedMolecule;
351 if (checkmol.get() == _mol) {
352 LOG(3, "INFO: GLWorldScene: Sending signal moleculesAtomRemoved for atom "+toString(_atomid)+".");
353 QMetaObject::invokeMethod(moliter->second, // pointer to a QObject
354 "atomRemoved", // member name (no parameters here)
355 Qt::QueuedConnection, // connection type
[f91ef6]356 Q_ARG(ObservedValue_Index_t, _atomid)); // parameters
[805fdc]357 } else {
358 // relay atomRemoved to GLMoleculeObject_molecule in RemovedMolecules
359 LOG(3, "INFO: GLWorldScene: Sending signal moleculesAtomRemoved for atom "+toString(_atomid)
360 +" to molecule in RemovedMolecules.");
[e29427]361 const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);
[805fdc]362 ASSERT( removedmoliter != RemovedMolecules.end(),
363 "GLWorldScene::moleculesAtomRemoved() - signal from old molecule "
364 +toString(molid)+", but not present in RemovedMolecules");
365#ifndef NDEBUG
366 const QtObservedMolecule::ptr &othercheckmol = removedmoliter->second->ObservedMolecule;
367#endif
368 ASSERT( othercheckmol.get() == _mol,
369 "GLWorldScene::moleculesAtomRemoved() - signal from old molecule "
370 +toString(molid)+", but different one "+toString(othercheckmol)
371 +" present in RemovedMolecules.");
372 QMetaObject::invokeMethod(removedmoliter->second, // pointer to a QObject
373 "atomRemoved", // member name (no parameters here)
374 Qt::QueuedConnection, // connection type
[f91ef6]375 Q_ARG(ObservedValue_Index_t, _atomid)); // parameters
[805fdc]376 }
377 } else {
[e29427]378 const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);
[805fdc]379 if (removedmoliter != RemovedMolecules.end()) {
380 ASSERT( removedmoliter != RemovedMolecules.end(),
381 "GLWorldScene::moleculesAtomRemoved() - signal from old molecule "
382 +toString(molid)+", but not present in RemovedMolecules");
383#ifndef NDEBUG
384 const QtObservedMolecule::ptr &othercheckmol = removedmoliter->second->ObservedMolecule;
385#endif
386 ASSERT( othercheckmol.get() == _mol,
387 "GLWorldScene::moleculesAtomRemoved() - signal from old molecule "
388 +toString(molid)+", but different one "+toString(othercheckmol)
389 +" present in RemovedMolecules.");
390 QMetaObject::invokeMethod(removedmoliter->second, // pointer to a QObject
391 "atomRemoved", // member name (no parameters here)
392 Qt::QueuedConnection, // connection type
[f91ef6]393 Q_ARG(ObservedValue_Index_t, _atomid)); // parameters
[8281cc]394 } else {
[59f1bc]395 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
396 // only record missed state for molecule if (still) present but not instantiated
397 if (QtObservedMoleculeMap.count(molid)) {
398 // store signal for when it is instantiated
399 if (MoleculeMissedStateMap.count(molid) == 0)
400 MoleculeMissedStateMap.insert( std::make_pair(molid, StateChangeMap_t()) );
401 MoleculeMissedStateMap[molid].insert( std::make_pair(_atomid, atomRemovedState) );
402 LOG(3, "INFO: GLWorldScene: Placing atomRemoved for atom " << _atomid
403 << " and molecule " << molid << " into missed state map.");
404 }
[8281cc]405 }
[9c259e]406 }
407}
408
[96f14a]409/** Inserts an bond into the scene when molecule is present.
410 *
411 * @param _bond bond to insert
412 */
413void GLWorldScene::moleculesBondInserted(QtObservedBond::ptr _bond, QtObservedMolecule * _mol)
414{
415 const ObservedValue_Index_t bondid = _bond->getIndex();
416 LOG(3, "INFO: GLWorldScene: Received signal bondInserted for bond " << _bond->getBondIndex());
417 const ObservedValue_Index_t molid = _mol->getIndex();
418
419 // check of molecule is already present
420 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
421 const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
422 if (moliter != MoleculesinSceneMap.end()) {
423 // check that it is the right molecule
424 QtObservedMolecule::ptr &checkmol = moliter->second->ObservedMolecule;
425 ASSERT( checkmol.get() == _mol,
426 "GLWorldScene::moleculesBondInserted() - claimed and present molecule differ.");
427 LOG(3, "INFO: GLWorldScene: Sending signal moleculesBondInserted for bond "
428 << _bond->getBondIndex());
429 QMetaObject::invokeMethod(moliter->second, // pointer to a QObject
430 "bondInserted", // member name (no parameters here)
431 Qt::QueuedConnection, // connection type
432 Q_ARG(QtObservedBond::ptr, _bond)); // parameters
433 } else {
434#ifndef NDEBUG
435 const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);
436 ASSERT( removedmoliter != RemovedMolecules.end(),
437 "GLWorldScene::moleculesBondInserted() - would need to send bondInserted to already removed molecule.");
438#endif
439 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
440 // only record missed state for molecule if (still) present but not instantiated
441 if (QtObservedMoleculeMap.count(molid)) {
442 // store signal for when it is instantiated
443 if (MoleculeMissedStateMap.count(molid) == 0)
444 MoleculeMissedStateMap.insert( std::make_pair(molid ,StateChangeMap_t()) );
445 MoleculeMissedStateMap[molid].insert( std::make_pair(bondid, bondInsertedState) );
446 ASSERT( QtObservedBondMap[bondid] == _bond,
447 "GLWorldScene::moleculesBondInserted() - bond "+toString(bondid)
448 +" inserted in molecule "+toString(_mol->getMolIndex())
449 +" which does not match bond in QtObservedBondMap.");
450 LOG(3, "INFO: GLWorldScene: Placing bondInserted for bond " << _bond->getBondIndex()
451 << " and molecule " << _mol->getMolIndex() << " into missed state map.");
452 }
453 }
454}
455
456/** Removes an bond into the scene before molecule is present.
457 *
458 * @param _bondid bond to remove
459 */
460void GLWorldScene::moleculesBondRemoved(ObservedValue_Index_t _bondid, QtObservedMolecule * _mol)
461{
462 LOG(3, "INFO: GLWorldScene: Received signal bondRemoved for bond "+toString(_bondid)+".");
463
464 const ObservedValue_Index_t molid = _mol->getIndex();
465 // check of molecule is already present
466 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
467 const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
468 if (moliter != MoleculesinSceneMap.end()) {
469 const QtObservedMolecule::ptr &checkmol = moliter->second->ObservedMolecule;
470 if (checkmol.get() == _mol) {
471 LOG(3, "INFO: GLWorldScene: Sending signal moleculesBondRemoved for bond "+toString(_bondid)+".");
472 QMetaObject::invokeMethod(moliter->second, // pointer to a QObject
473 "bondRemoved", // member name (no parameters here)
474 Qt::QueuedConnection, // connection type
475 Q_ARG(ObservedValue_Index_t, _bondid)); // parameters
476 } else {
477 // relay bondRemoved to GLMoleculeObject_molecule in RemovedMolecules
478 LOG(3, "INFO: GLWorldScene: Sending signal moleculesBondRemoved for bond "+toString(_bondid)
479 +" to molecule in RemovedMolecules.");
480 const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);
481 ASSERT( removedmoliter != RemovedMolecules.end(),
482 "GLWorldScene::moleculesBondRemoved() - signal from old molecule "
483 +toString(molid)+", but not present in RemovedMolecules");
484#ifndef NDEBUG
485 const QtObservedMolecule::ptr &othercheckmol = removedmoliter->second->ObservedMolecule;
486 ASSERT( othercheckmol.get() == _mol,
487 "GLWorldScene::moleculesBondRemoved() - signal from old molecule "
488 +toString(molid)+", but different one "+toString(othercheckmol)
489 +" present in RemovedMolecules.");
490#endif
491 QMetaObject::invokeMethod(removedmoliter->second, // pointer to a QObject
492 "bondRemoved", // member name (no parameters here)
493 Qt::QueuedConnection, // connection type
494 Q_ARG(ObservedValue_Index_t, _bondid)); // parameters
495 }
496 } else {
497 const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);
498 if (removedmoliter != RemovedMolecules.end()) {
499 ASSERT( removedmoliter != RemovedMolecules.end(),
500 "GLWorldScene::moleculesBondRemoved() - signal from old molecule "
501 +toString(molid)+", but not present in RemovedMolecules");
502#ifndef NDEBUG
503 const QtObservedMolecule::ptr &othercheckmol = removedmoliter->second->ObservedMolecule;
504 ASSERT( othercheckmol.get() == _mol,
505 "GLWorldScene::moleculesBondRemoved() - signal from old molecule "
506 +toString(molid)+", but different one "+toString(othercheckmol)
507 +" present in RemovedMolecules.");
508#endif
509 QMetaObject::invokeMethod(removedmoliter->second, // pointer to a QObject
510 "bondRemoved", // member name (no parameters here)
511 Qt::QueuedConnection, // connection type
512 Q_ARG(ObservedValue_Index_t, _bondid)); // parameters
513 } else {
514 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
515 // only record missed state for molecule if (still) present but not instantiated
516 if (QtObservedMoleculeMap.count(molid)) {
517 // store signal for when it is instantiated
518 if (MoleculeMissedStateMap.count(molid) == 0)
519 MoleculeMissedStateMap.insert( std::make_pair(molid, StateChangeMap_t()) );
520 MoleculeMissedStateMap[molid].insert( std::make_pair(_bondid, bondRemovedState) );
521 LOG(3, "INFO: GLWorldScene: Placing bondRemoved for bond " << _bondid
522 << " and molecule " << molid << " into missed state map.");
523 }
524 }
525 }
526}
527
[8281cc]528void GLWorldScene::moleculeSignOn(QtObservedMolecule::ptr _mol)
529{
530 // sign on to QtObservedMolecule to get atomInserted/..Removed signals from same
531 // source as GLMoleculeObject_molecule would
[96e145]532 connect(_mol.get(), SIGNAL(atomInserted(QtObservedAtom::ptr, QtObservedMolecule *)),
533 this, SLOT(moleculesAtomInserted(QtObservedAtom::ptr, QtObservedMolecule *)) );
[f91ef6]534 connect(_mol.get(), SIGNAL(atomRemoved(ObservedValue_Index_t, QtObservedMolecule *)),
535 this, SLOT(moleculesAtomRemoved(ObservedValue_Index_t, QtObservedMolecule *)) );
536 const ObservedValue_Index_t molid = _mol->getIndex();
[59f1bc]537 ASSERT( QtObservedMoleculeMap.find(molid) == QtObservedMoleculeMap.end(),
[f91ef6]538 "GLWorldScene::moleculeSignOn() - molecule with id "+toString(_mol->getMolIndex())
[59f1bc]539 +" is already present in QtObservedMoleculeMap.");
540 QtObservedMoleculeMap[molid] = _mol;
[8281cc]541
[f91ef6]542 LOG(3, "INFO: GLWorldScene: Received signal moleculeSignOn for molecule " << _mol->getMolIndex());
[8281cc]543
544 emit insertMolecule(_mol);
545}
546
[f91ef6]547void GLWorldScene::moleculeSignOff(ObservedValue_Index_t _id)
[8281cc]548{
[59f1bc]549 const QtObservedMoleculeMap_t::iterator eraseiter = QtObservedMoleculeMap.find(_id);
550 ASSERT( eraseiter != QtObservedMoleculeMap.end(),
[8281cc]551 "GLWorldScene::moleculeSignOff() - cannot find id "+toString(_id)+" in map.");
[e29427]552 QtObservedMolecule * mol = eraseiter->second.get();
[59f1bc]553 QtObservedMoleculeMap.erase(eraseiter);
[8281cc]554
[f91ef6]555 LOG(3, "INFO: GLWorldScene: Received signal moleculeSignOff for molecule " << mol->getMolIndex());
[8281cc]556
[e29427]557 emit removeMolecule(mol);
[8281cc]558}
559
[026bef]560/** Inserts a molecule into the scene.
[c67518]561 *
[8c001a]562 * @param _mol molecule to insert
[c67518]563 */
[1b07b1]564void GLWorldScene::moleculeInserted(QtObservedMolecule::ptr _mol)
[c67518]565{
[1b07b1]566 ASSERT (_mol,
567 "GLWorldScene::moleculeInserted() - received shared_ptr for molecule is empty?");
[f91ef6]568 const ObservedValue_Index_t molid = _mol->getIndex();
569 LOG(3, "INFO: GLWorldScene: Received signal moleculeInserted for molecule "
570 << _mol->getMolIndex());
[7cf0eb]571
572 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
573
[1b07b1]574 MoleculeNodeMap::const_iterator iter = MoleculesinSceneMap.find(molid);
[8c001a]575 ASSERT( iter == MoleculesinSceneMap.end(),
[f91ef6]576 "GLWorldScene::moleculeInserted() - molecule's id "+toString(_mol->getMolIndex())
577 +" already present.");
[8c001a]578
579 // add new object
[f91ef6]580 LOG(1, "DEBUG: Adding GLMoleculeObject_molecule to id " << _mol->getMolIndex());
[1b07b1]581 GLMoleculeObject_molecule *molObject =
582 new GLMoleculeObject_molecule(
583 GLMoleculeObject::meshEmpty,
584 this,
585 *board,
586 _mol);
587 ASSERT( molObject != NULL,
[f91ef6]588 "GLWorldScene::moleculeInserted - could not create molecule object for "
589 +toString(_mol->getMolIndex()));
[1b07b1]590#ifndef NDEBUG
591 std::pair<MoleculeNodeMap::iterator, bool> inserter =
592#endif
593 MoleculesinSceneMap.insert( make_pair(molid, molObject) );
594 ASSERT(inserter.second,
[f91ef6]595 "GLWorldScene::moleculeInserted() - molecule "+toString(_mol->getMolIndex())
596 +" already present in scene.");
[1b07b1]597
598 // now handle all state changes that came up before the instantiation
599 if (MoleculeMissedStateMap.count(molid) != 0) {
600// ASSERT( !MoleculeMissedStateMap[molid].empty(),
[4cac6c]601// "GLWorldScene::moleculeInserted() - we have an empty state change map for molecule with id "
[1b07b1]602// +toString(molid));
603 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
604 for (StateChangeMap_t::iterator iter = MoleculeMissedStateMap[molid].begin();
605 !MoleculeMissedStateMap[molid].empty();
606 iter = MoleculeMissedStateMap[molid].begin()) {
607 std::pair<StateChangeMap_t::iterator, StateChangeMap_t::iterator> rangeiter =
608 MoleculeMissedStateMap[molid].equal_range(iter->first);
609 const size_t StateCounts = std::distance(rangeiter.first, rangeiter.second);
610 if (StateCounts > 1) {
611 // more than one state change, have to combine
612 typedef std::map<StateChangeType, size_t> StateChangeAmounts_t;
613 StateChangeAmounts_t StateChangeAmounts;
614 for (StateChangeMap_t::const_iterator stateiter = rangeiter.first;
615 stateiter != rangeiter.second; ++stateiter)
616 ++StateChangeAmounts[stateiter->second];
[96f14a]617 // is it an atom?
618 if ((StateChangeAmounts[atomInsertedState] + StateChangeAmounts[atomRemovedState]) != 0) {
619 ASSERT( StateChangeAmounts[atomInsertedState] >= StateChangeAmounts[atomRemovedState],
620 "GLWorldScene::moleculeInserted() - more atomRemoved states "
621 +toString(StateChangeAmounts[atomRemovedState])+" than atomInserted "
622 +toString(StateChangeAmounts[atomInsertedState])+" for atom "+toString(iter->first));
623 if (StateChangeAmounts[atomInsertedState] > StateChangeAmounts[atomRemovedState]) {
624 LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
625 QMetaObject::invokeMethod(molObject, // pointer to a QObject
626 "atomInserted", // member name (no parameters here)
627 Qt::QueuedConnection, // connection type
628 Q_ARG(QtObservedAtom::ptr, QtObservedAtomMap[iter->first])); // parameters
629 } else {
630 LOG(1, "INFO: Atom " << iter->first << " has been inserted and removed already.");
631 }
[1b07b1]632 }
[96f14a]633 // or is it a bond?
634 if ((StateChangeAmounts[bondInsertedState] + StateChangeAmounts[bondInsertedState]) != 0) {
635 ASSERT( StateChangeAmounts[bondInsertedState] >= StateChangeAmounts[bondRemovedState],
636 "GLWorldScene::moleculeInserted() - more bondRemoved states "
637 +toString(StateChangeAmounts[bondRemovedState])+" than bondInserted "
638 +toString(StateChangeAmounts[bondInsertedState])+" for bond "+toString(iter->first));
639 if (StateChangeAmounts[bondInsertedState] > StateChangeAmounts[bondRemovedState]) {
640 LOG(1, "INFO: invoking bondInserted for bond " << iter->first);
641 QMetaObject::invokeMethod(molObject, // pointer to a QObject
642 "bondInserted", // member name (no parameters here)
643 Qt::QueuedConnection, // connection type
644 Q_ARG(QtObservedBond::ptr, QtObservedBondMap[iter->first])); // parameters
645 } else {
646 LOG(1, "INFO: Bond " << iter->first << " has been inserted and removed already.");
647 }
648 }
649 ASSERT( (StateChangeAmounts[bondInsertedState] + StateChangeAmounts[bondInsertedState]
650 + StateChangeAmounts[atomInsertedState] + StateChangeAmounts[atomRemovedState]) != 0,
651 "GLWorldScene::moleculeInserted() - state with no changes for "+toString(iter->first));
652 // removed all state changes for this atom/bond
[1b07b1]653 MoleculeMissedStateMap[molid].erase(rangeiter.first, rangeiter.second);
654 } else {
655 // can only be an insertion
656 switch (rangeiter.first->second) {
657 case atomRemovedState:
658 ASSERT( 0,
659 "GLWorldScene::moleculeInserted() - atomRemoved state without atomInserted for atom "
660 +toString(iter->first));
661 break;
662 case atomInsertedState:
663 {
[73b13c]664 LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
[9c259e]665 QMetaObject::invokeMethod(molObject, // pointer to a QObject
666 "atomInserted", // member name (no parameters here)
[8d5fbf1]667 Qt::QueuedConnection, // connection type
[1b07b1]668 Q_ARG(QtObservedAtom::ptr, QtObservedAtomMap[iter->first])); // parameters
669 break;
[7ded1c]670 }
[96f14a]671 case bondRemovedState:
672 ASSERT( 0,
673 "GLWorldScene::moleculeInserted() - bondRemoved state without bondInserted for bond "
674 +toString(iter->first));
675 break;
676 case bondInsertedState:
677 {
678 LOG(1, "INFO: invoking bondInserted for bond " << iter->first);
679 QMetaObject::invokeMethod(molObject, // pointer to a QObject
680 "bondInserted", // member name (no parameters here)
681 Qt::QueuedConnection, // connection type
682 Q_ARG(QtObservedBond::ptr, QtObservedBondMap[iter->first])); // parameters
683 break;
684 }
[1b07b1]685 default:
686 ASSERT( 0,
687 "GLWorldScene::moleculeInserted() - there are unknown change states.");
688 break;
[9c259e]689 }
[96f14a]690 // removed state changes for this atom/bond
[1b07b1]691 MoleculeMissedStateMap[molid].erase(iter);
[9c259e]692 }
693 }
694 }
695
[1b07b1]696 connect (molObject, SIGNAL(changed()), this, SIGNAL(changed()));
697 connect (molObject, SIGNAL(changeOccured()), this, SIGNAL(changeOccured()));
698 connect (molObject, SIGNAL(atomClicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
699 connect (molObject, SIGNAL(moleculeClicked(moleculeId_t)), this, SLOT(moleculeClicked(moleculeId_t)));
[e29427]700 connect (molObject, SIGNAL(moleculeEmptied(QtObservedMolecule::ptr)), this, SLOT(moleculeEmpty(QtObservedMolecule::ptr)));
[1b07b1]701 connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
702 connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
703 connect (molObject, SIGNAL(hoverChanged(const atomId_t)), this, SIGNAL(hoverChanged(const atomId_t)));
704 connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
705 connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
706
707 emit changed();
708 emit changeOccured();
709
[7ded1c]710 // remove state change map for the molecule
711 {
712 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
[1b07b1]713 MoleculeMissedStateMap.erase(molid);
[7ded1c]714 }
[c67518]715}
716
[7cf0eb]717/** Removes a molecule from the scene.
718 *
[e29427]719 * @param _mol QtObservedMolecule instance of molecule to remove
[7cf0eb]720 */
[e29427]721void GLWorldScene::moleculeRemoved(QtObservedMolecule* _mol)
[7cf0eb]722{
[f91ef6]723 const ObservedValue_Index_t molid = _mol->getIndex();
[e29427]724 LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(molid)+".");
[7c7c4a]725
[7cf0eb]726 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
727
[e29427]728 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(molid);
[4a187d]729 ASSERT ( iter != MoleculesinSceneMap.end(),
[f91ef6]730 "GLWorldScene::moleculeRemoved() - to be removed molecule "+toString(_mol->getMolIndex())
[4a187d]731 +" is already gone.");
732 // check if it's already empty
733 const RemovedMoleculesMap_t::iterator emptyiter = EmptyMolecules.find(_mol);
734 if (emptyiter != EmptyMolecules.end()) {
[f91ef6]735 LOG(1, "DEBUG: Removing empty GLMoleculeObject_molecule to id " << _mol->getMolIndex()
736 << " from scene.");
[4a187d]737 // it's already empty, remove it
738 ASSERT( emptyiter->second == iter->second,
739 "GLWorldScene::moleculeRemoved() - empty molecule "
740 +toString(emptyiter->second)+" and removed molecule "
741 +toString(iter->second)+" don't match.");
[f91ef6]742 LOG(1, "DEBUG: Deleting already empty GLMoleculeObject_molecule to id " << _mol->getMolIndex());
[4a187d]743 GLMoleculeObject_molecule *molObject = emptyiter->second;
744 EmptyMolecules.erase(emptyiter);
745 molObject->disconnect();
746 delete molObject;
747
748 emit changed();
749 emit changeOccured();
750 } else {
751 // otherwise note it as removal candidate
[e29427]752 RemovedMolecules.insert( std::make_pair(_mol, iter->second) );
[bcf9cd]753 }
[4a187d]754 MoleculesinSceneMap.erase(iter);
[bcf9cd]755
756 // remove any possible state changes left
757 {
758 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
[e29427]759 MoleculeMissedStateMap.erase(molid);
[bcf9cd]760 }
761}
762
[e29427]763void GLWorldScene::moleculeEmpty(QtObservedMolecule::ptr _mol)
[bcf9cd]764{
[f91ef6]765 LOG(3, "INFO: GLWorldScene: Received signal moleculeEmpty for molecule "
766 +toString(_mol->getMolIndex())+".");
[bcf9cd]767
768 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
769
[f91ef6]770 const ObservedValue_Index_t molid = _mol->getIndex();
[4a187d]771 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(molid);
772 if ( iter == MoleculesinSceneMap.end()) {
773 RemovedMoleculesMap_t::iterator removeiter = RemovedMolecules.find(_mol.get());
774 ASSERT ( removeiter != RemovedMolecules.end(),
[f91ef6]775 "GLWorldScene::moleculeEmpty() - to be removed molecule "+toString(_mol->getMolIndex())
[4a187d]776 +" is neither in MoleculesinSceneMap, nor in RemovedMolecules.");
777 // it's noted for removal already, remove it
[f91ef6]778 LOG(1, "DEBUG: Deleting empty GLMoleculeObject_molecule to id " << _mol->getMolIndex());
[4a187d]779 GLMoleculeObject_molecule *molObject = removeiter->second;
780 RemovedMolecules.erase(removeiter);
[7c7c4a]781 molObject->disconnect();
782 delete molObject;
[9c259e]783
[4a187d]784 emit changed();
785 emit changeOccured();
786 } else {
787 // otherwise just note it as empty
788 EmptyMolecules.insert( std::make_pair(_mol.get(), iter->second) );
[73b13c]789 }
[9c259e]790
[4a187d]791// // remove any possible state changes left
792// {
793// boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
794// MoleculeMissedStateMap.erase(molid);
795// }
[ce4126]796}
797
[f91ef6]798void GLWorldScene::moleculesVisibilityChanged(ObservedValue_Index_t _id, bool _visible)
[739ee9]799{
[7c7c4a]800 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
[739ee9]801 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_id);
802 ASSERT( iter != MoleculesinSceneMap.end(),
[f91ef6]803 "GLWorldScene::moleculeInserted() - molecule's id "
804 +toString(board->getMoleculeIdToIndex(_id))+" is unknown.");
[739ee9]805
806 GLMoleculeObject_molecule *molObject = iter->second;
807 molObject->setVisible(_visible);
808
809 emit changed();
810 emit changeOccured();
811}
812
[f75491]813/** Adds a shape to the scene.
[4d6662]814 *
[f75491]815 */
[07136a]816void GLWorldScene::addShape(const std::string &_name)
[f75491]817{
[07136a]818 Shape * const shape = ShapeRegistry::getInstance().getByName(_name);
819 if (shape != NULL) {
820 GLMoleculeObject_shape *shapeObject = new GLMoleculeObject_shape(*shape, this);
821 ShapeNodeMap::iterator iter = ShapesinSceneMap.find(_name);
822 ASSERT(iter == ShapesinSceneMap.end(),
823 "GLWorldScene::addShape() - same shape "+_name+" added again.");
824 ShapesinSceneMap.insert( make_pair(_name, shapeObject) );
825 } else
826 ELOG(2, "GLWorldScene::addShape() - shape disappeared before we could draw it.");
827
828 emit changed();
[284551]829}
830
[07136a]831void GLWorldScene::removeShape(const std::string &_name)
[85c36d]832{
[07136a]833 ShapeNodeMap::iterator iter = ShapesinSceneMap.find(_name);
[ba6b5c]834 ASSERT(iter != ShapesinSceneMap.end(),
[07136a]835 "GLWorldScene::removeShape() - shape "+_name+" not in scene.");
[148dde0]836 ShapesinSceneMap.erase(iter);
[85c36d]837 delete(iter->second);
[07136a]838
839 emit changed();
[85c36d]840}
841
842void GLWorldScene::updateSelectedShapes()
[284551]843{
844 foreach (QObject *obj, children()) {
845 GLMoleculeObject_shape *shapeobj = qobject_cast<GLMoleculeObject_shape *>(obj);
[85c36d]846 if (shapeobj){
847 shapeobj->enable(ShapeRegistry::getInstance().isSelected(shapeobj->getShape()));
848 }
[284551]849 }
[07136a]850
851 emit changed();
[f75491]852}
853
[7188b1]854void GLWorldScene::initialize(QGLView *view, QGLPainter *painter) const
855{
856 // Initialize all of the mesh objects that we have as children.
857 foreach (QObject *obj, children()) {
858 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
859 if (meshobj)
860 meshobj->initialize(view, painter);
861 }
862}
863
[72a4c1]864void GLWorldScene::draw(QGLPainter *painter, const QVector4D &cameraPlane) const
[7188b1]865{
866 // Draw all of the mesh objects that we have as children.
867 foreach (QObject *obj, children()) {
868 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
869 if (meshobj)
[72a4c1]870 meshobj->draw(painter, cameraPlane);
[7188b1]871 }
[907636]872}
[06ebf5]873
[6966b7]874void GLWorldScene::setSelectionMode(SelectionModeType mode)
875{
876 selectionMode = mode;
877 // TODO send update to toolbar
878}
879
880void GLWorldScene::setSelectionModeAtom()
881{
882 setSelectionMode(SelectAtom);
883}
884
885void GLWorldScene::setSelectionModeMolecule()
886{
887 setSelectionMode(SelectMolecule);
888}
[20f9b5]889
Note: See TracBrowser for help on using the repository browser.