| 1 | /*
 | 
|---|
| 2 |  * Project: MoleCuilder
 | 
|---|
| 3 |  * Description: creates and alters molecular systems
 | 
|---|
| 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| 5 |  * 
 | 
|---|
| 6 |  *
 | 
|---|
| 7 |  *   This file is part of MoleCuilder.
 | 
|---|
| 8 |  *
 | 
|---|
| 9 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
| 10 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
| 11 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
| 12 |  *    (at your option) any later version.
 | 
|---|
| 13 |  *
 | 
|---|
| 14 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
| 15 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
| 16 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
| 17 |  *    GNU General Public License for more details.
 | 
|---|
| 18 |  *
 | 
|---|
| 19 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
| 20 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
 | 
|---|
| 21 |  */
 | 
|---|
| 22 | 
 | 
|---|
| 23 | /*
 | 
|---|
| 24 |  * GLWorldScene.cpp
 | 
|---|
| 25 |  *
 | 
|---|
| 26 |  *  This is based on the Qt3D example "teaservice", specifically parts of teaservice.cpp.
 | 
|---|
| 27 |  *
 | 
|---|
| 28 |  *  Created on: Aug 17, 2011
 | 
|---|
| 29 |  *      Author: heber
 | 
|---|
| 30 |  */
 | 
|---|
| 31 | 
 | 
|---|
| 32 | // include config.h
 | 
|---|
| 33 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 34 | #include <config.h>
 | 
|---|
| 35 | #endif
 | 
|---|
| 36 | 
 | 
|---|
| 37 | #include "GLWorldScene.hpp"
 | 
|---|
| 38 | #include <Qt3D/qglview.h>
 | 
|---|
| 39 | #include <Qt3D/qglbuilder.h>
 | 
|---|
| 40 | #include <Qt3D/qglscenenode.h>
 | 
|---|
| 41 | #include <Qt3D/qglsphere.h>
 | 
|---|
| 42 | #include <Qt3D/qglcylinder.h>
 | 
|---|
| 43 | 
 | 
|---|
| 44 | #include "GLMoleculeObject.hpp"
 | 
|---|
| 45 | #include "GLMoleculeObject_atom.hpp"
 | 
|---|
| 46 | #include "GLMoleculeObject_bond.hpp"
 | 
|---|
| 47 | #include "GLMoleculeObject_molecule.hpp"
 | 
|---|
| 48 | 
 | 
|---|
| 49 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| 50 | 
 | 
|---|
| 51 | #include "CodePatterns/Log.hpp"
 | 
|---|
| 52 | 
 | 
|---|
| 53 | #include "Actions/SelectionAction/Atoms/AtomByIdAction.hpp"
 | 
|---|
| 54 | #include "Actions/SelectionAction/Atoms/NotAtomByIdAction.hpp"
 | 
|---|
| 55 | #include "Actions/SelectionAction/Molecules/MoleculeByIdAction.hpp"
 | 
|---|
| 56 | #include "Actions/SelectionAction/Molecules/NotMoleculeByIdAction.hpp"
 | 
|---|
| 57 | #include "Atom/atom.hpp"
 | 
|---|
| 58 | #include "Bond/bond.hpp"
 | 
|---|
| 59 | #include "Descriptors/AtomIdDescriptor.hpp"
 | 
|---|
| 60 | #include "Helpers/helpers.hpp"
 | 
|---|
| 61 | #include "molecule.hpp"
 | 
|---|
| 62 | #include "World.hpp"
 | 
|---|
| 63 | 
 | 
|---|
| 64 | #include <iostream>
 | 
|---|
| 65 | 
 | 
|---|
| 66 | using namespace MoleCuilder;
 | 
|---|
| 67 | 
 | 
|---|
| 68 | std::ostream &operator<<(std::ostream &ost, const GLWorldScene::BondIds &t)
 | 
|---|
| 69 | {
 | 
|---|
| 70 |   ost << t.first << "," << t.second;
 | 
|---|
| 71 |   return ost;
 | 
|---|
| 72 | }
 | 
|---|
| 73 | 
 | 
|---|
| 74 | GLWorldScene::GLWorldScene(QObject *parent)
 | 
|---|
| 75 |    : QObject(parent),
 | 
|---|
| 76 |      hoverAtom(NULL)
 | 
|---|
| 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 |     meshEmpty[i] = emptyBuilder.finalizedSceneNode();
 | 
|---|
| 83 |     QGLBuilder sphereBuilder;
 | 
|---|
| 84 |     sphereBuilder << QGLSphere(2.0, sphereDetails[i]);
 | 
|---|
| 85 |     meshSphere[i] = sphereBuilder.finalizedSceneNode();
 | 
|---|
| 86 |     meshSphere[i]->setOption(QGLSceneNode::CullBoundingBox, true);
 | 
|---|
| 87 |     QGLBuilder cylinderBuilder;
 | 
|---|
| 88 |     cylinderBuilder << QGLCylinder(.25,.25,1.0,cylinderDetails[i]);
 | 
|---|
| 89 |     meshCylinder[i] = cylinderBuilder.finalizedSceneNode();
 | 
|---|
| 90 |     meshCylinder[i]->setOption(QGLSceneNode::CullBoundingBox, true);
 | 
|---|
| 91 |   }
 | 
|---|
| 92 | 
 | 
|---|
| 93 |   setSelectionMode(SelectAtom);
 | 
|---|
| 94 | 
 | 
|---|
| 95 |   init();
 | 
|---|
| 96 | }
 | 
|---|
| 97 | 
 | 
|---|
| 98 | GLWorldScene::~GLWorldScene()
 | 
|---|
| 99 | {
 | 
|---|
| 100 |   // remove all elements
 | 
|---|
| 101 |   GLMoleculeObject::cleanMaterialMap();
 | 
|---|
| 102 | }
 | 
|---|
| 103 | 
 | 
|---|
| 104 | /** Initialise the WorldScene with molecules and atoms from World.
 | 
|---|
| 105 |  *
 | 
|---|
| 106 |  */
 | 
|---|
| 107 | void GLWorldScene::init()
 | 
|---|
| 108 | {
 | 
|---|
| 109 |   const std::vector<molecule*> &molecules = World::getInstance().getAllMolecules();
 | 
|---|
| 110 | 
 | 
|---|
| 111 |   if (molecules.size() > 0) {
 | 
|---|
| 112 |     for (std::vector<molecule*>::const_iterator Runner = molecules.begin();
 | 
|---|
| 113 |         Runner != molecules.end();
 | 
|---|
| 114 |         Runner++) {
 | 
|---|
| 115 | 
 | 
|---|
| 116 |       for (molecule::const_iterator atomiter = (*Runner)->begin();
 | 
|---|
| 117 |           atomiter != (*Runner)->end();
 | 
|---|
| 118 |           ++atomiter) {
 | 
|---|
| 119 |         // create atom objects in scene
 | 
|---|
| 120 |         atomInserted(*atomiter);
 | 
|---|
| 121 | 
 | 
|---|
| 122 |         // create bond objects in scene
 | 
|---|
| 123 |         const BondList &bondlist = (*atomiter)->getListOfBonds();
 | 
|---|
| 124 |         for (BondList::const_iterator bonditer = bondlist.begin();
 | 
|---|
| 125 |             bonditer != bondlist.end();
 | 
|---|
| 126 |             ++bonditer) {
 | 
|---|
| 127 |           const bond *_bond = *bonditer;
 | 
|---|
| 128 |           const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == *atomiter) ?
 | 
|---|
| 129 |               GLMoleculeObject_bond::left : GLMoleculeObject_bond::right;
 | 
|---|
| 130 |           bondInserted(_bond, side);
 | 
|---|
| 131 |         }
 | 
|---|
| 132 |       }
 | 
|---|
| 133 |     }
 | 
|---|
| 134 |   }
 | 
|---|
| 135 | }
 | 
|---|
| 136 | 
 | 
|---|
| 137 | /** Adds an atom to the scene.
 | 
|---|
| 138 |  *
 | 
|---|
| 139 |  * @param _atom atom to add
 | 
|---|
| 140 |  */
 | 
|---|
| 141 | void GLWorldScene::atomInserted(const atom *_atom)
 | 
|---|
| 142 | {
 | 
|---|
| 143 |   LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "+toString(_atom->getId())+".");
 | 
|---|
| 144 |   GLMoleculeObject_atom *atomObject = new GLMoleculeObject_atom(meshSphere, this, _atom);
 | 
|---|
| 145 |   AtomNodeMap::iterator iter = AtomsinSceneMap.find(_atom->getId());
 | 
|---|
| 146 |   ASSERT(iter == AtomsinSceneMap.end(),
 | 
|---|
| 147 |       "GLWorldScene::atomAdded() - same atom "+_atom->getName()+" added again.");
 | 
|---|
| 148 |   AtomsinSceneMap.insert( make_pair(_atom->getId(), atomObject) );
 | 
|---|
| 149 |   connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
 | 
|---|
| 150 |   connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed()));
 | 
|---|
| 151 |   connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
 | 
|---|
| 152 |   connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
 | 
|---|
| 153 |   connect (atomObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
 | 
|---|
| 154 |   connect (atomObject, SIGNAL(BondsInserted(const bond *, const GLMoleculeObject_bond::SideOfBond)), this, SLOT(bondInserted(const bond *, const GLMoleculeObject_bond::SideOfBond)));
 | 
|---|
| 155 |   connect (atomObject, SIGNAL(indexChanged(GLMoleculeObject_atom*, int, int)), this, SLOT(changeAtomId(GLMoleculeObject_atom*, int, int)));
 | 
|---|
| 156 |   //bondsChanged(_atom);
 | 
|---|
| 157 |   emit changeOccured();
 | 
|---|
| 158 | }
 | 
|---|
| 159 | 
 | 
|---|
| 160 | /** Removes an atom from the scene.
 | 
|---|
| 161 |  *
 | 
|---|
| 162 |  * @param _atom atom to remove
 | 
|---|
| 163 |  */
 | 
|---|
| 164 | void GLWorldScene::atomRemoved(const atom *_atom)
 | 
|---|
| 165 | {
 | 
|---|
| 166 |   LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atom->getId())+".");
 | 
|---|
| 167 |   // bonds are removed by signal coming from ~bond
 | 
|---|
| 168 |   // remove atoms
 | 
|---|
| 169 |   AtomNodeMap::iterator iter = AtomsinSceneMap.find(_atom->getId());
 | 
|---|
| 170 |   ASSERT(iter != AtomsinSceneMap.end(),
 | 
|---|
| 171 |       "GLWorldScene::atomRemoved() - atom "+_atom->getName()+" not on display.");
 | 
|---|
| 172 |   GLMoleculeObject_atom *atomObject = iter->second;
 | 
|---|
| 173 |   atomObject->disconnect();
 | 
|---|
| 174 |   AtomsinSceneMap.erase(iter);
 | 
|---|
| 175 |   delete atomObject;
 | 
|---|
| 176 |   emit changeOccured();
 | 
|---|
| 177 | }
 | 
|---|
| 178 | 
 | 
|---|
| 179 | /** ....
 | 
|---|
| 180 |  *
 | 
|---|
| 181 |  */
 | 
|---|
| 182 | void GLWorldScene::worldSelectionChanged()
 | 
|---|
| 183 | {
 | 
|---|
| 184 |   LOG(3, "INFO: GLWorldScene: Received signal selectionChanged.");
 | 
|---|
| 185 | 
 | 
|---|
| 186 |   const std::vector<molecule*> &molecules = World::getInstance().getAllMolecules();
 | 
|---|
| 187 | 
 | 
|---|
| 188 |   if (molecules.size() > 0) {
 | 
|---|
| 189 |     for (std::vector<molecule*>::const_iterator Runner = molecules.begin();
 | 
|---|
| 190 |         Runner != molecules.end();
 | 
|---|
| 191 |         Runner++) {
 | 
|---|
| 192 | 
 | 
|---|
| 193 |       MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find((*Runner)->getId());
 | 
|---|
| 194 |       bool isSelected = World::getInstance().isSelected(*Runner);
 | 
|---|
| 195 | 
 | 
|---|
| 196 |       // molecule selected but not in scene?
 | 
|---|
| 197 |       if (isSelected && (iter == MoleculesinSceneMap.end())){
 | 
|---|
| 198 |         // -> create new mesh
 | 
|---|
| 199 |         GLMoleculeObject_molecule *molObject = new GLMoleculeObject_molecule(meshEmpty, this, *Runner);
 | 
|---|
| 200 |         MoleculesinSceneMap.insert( make_pair((*Runner)->getId(), molObject) );
 | 
|---|
| 201 |         connect (molObject, SIGNAL(changed()), this, SIGNAL(changed()));
 | 
|---|
| 202 |         connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
 | 
|---|
| 203 |         connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
 | 
|---|
| 204 |         emit changed();
 | 
|---|
| 205 |         emit changeOccured();
 | 
|---|
| 206 |       }
 | 
|---|
| 207 | 
 | 
|---|
| 208 |       // molecule not selected but in scene?
 | 
|---|
| 209 |       if (!isSelected && (iter != MoleculesinSceneMap.end())){
 | 
|---|
| 210 |         // -> remove from scene
 | 
|---|
| 211 |         moleculeRemoved(*Runner);
 | 
|---|
| 212 |       }
 | 
|---|
| 213 | 
 | 
|---|
| 214 |     }
 | 
|---|
| 215 |   }
 | 
|---|
| 216 | }
 | 
|---|
| 217 | 
 | 
|---|
| 218 | /** Removes a molecule from the scene.
 | 
|---|
| 219 |  *
 | 
|---|
| 220 |  * @param _molecule molecule to remove
 | 
|---|
| 221 |  */
 | 
|---|
| 222 | void GLWorldScene::moleculeRemoved(const molecule *_molecule)
 | 
|---|
| 223 | {
 | 
|---|
| 224 |   LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_molecule->getId())+".");
 | 
|---|
| 225 |   MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molecule->getId());
 | 
|---|
| 226 | 
 | 
|---|
| 227 |   // only remove if the molecule is in the scene
 | 
|---|
| 228 |   //  (= is selected)
 | 
|---|
| 229 |   if (iter != MoleculesinSceneMap.end()){
 | 
|---|
| 230 |     GLMoleculeObject_molecule *molObject = iter->second;
 | 
|---|
| 231 |     molObject->disconnect();
 | 
|---|
| 232 |     MoleculesinSceneMap.erase(iter);
 | 
|---|
| 233 |     delete molObject;
 | 
|---|
| 234 |     emit changed();
 | 
|---|
| 235 |     emit changeOccured();
 | 
|---|
| 236 |   }
 | 
|---|
| 237 | }
 | 
|---|
| 238 | 
 | 
|---|
| 239 | /** Adds a bond to the scene.
 | 
|---|
| 240 |  *
 | 
|---|
| 241 |  * @param _bond bond to add
 | 
|---|
| 242 |  * @param side which side of the bond (left or right)
 | 
|---|
| 243 |  */
 | 
|---|
| 244 | void GLWorldScene::bondInserted(const bond *_bond, const enum GLMoleculeObject_bond::SideOfBond side)
 | 
|---|
| 245 | {
 | 
|---|
| 246 |   LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bond "+toString(*_bond)+".");
 | 
|---|
| 247 |   //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << ".");
 | 
|---|
| 248 | 
 | 
|---|
| 249 |   BondIds ids;
 | 
|---|
| 250 |   switch (side) {
 | 
|---|
| 251 |     case GLMoleculeObject_bond::left:
 | 
|---|
| 252 |       ids = std::make_pair(_bond->leftatom->getId(), _bond->rightatom->getId());
 | 
|---|
| 253 |       break;
 | 
|---|
| 254 |     case GLMoleculeObject_bond::right:
 | 
|---|
| 255 |       ids = std::make_pair(_bond->rightatom->getId(), _bond->leftatom->getId());
 | 
|---|
| 256 |       break;
 | 
|---|
| 257 |   }
 | 
|---|
| 258 | #ifndef NDEBUG
 | 
|---|
| 259 |   BondNodeMap::iterator iter = BondsinSceneMap.find(ids);
 | 
|---|
| 260 |   ASSERT(iter == BondsinSceneMap.end(),
 | 
|---|
| 261 |       "GLWorldScene::bondAdded() - same left-sided bond "+toString(*_bond)+" added again.");
 | 
|---|
| 262 | #endif
 | 
|---|
| 263 |   GLMoleculeObject_bond *bondObject =
 | 
|---|
| 264 |       new GLMoleculeObject_bond(meshCylinder, this, _bond, side);
 | 
|---|
| 265 |   connect (
 | 
|---|
| 266 |       bondObject, SIGNAL(BondRemoved(const atomId_t, const atomId_t)),
 | 
|---|
| 267 |       this, SLOT(bondRemoved(const atomId_t, const atomId_t)));
 | 
|---|
| 268 |   connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));
 | 
|---|
| 269 |   BondsinSceneMap.insert( make_pair(ids, bondObject) );
 | 
|---|
| 270 | //    BondIdsinSceneMap.insert( Leftids );
 | 
|---|
| 271 |   emit changeOccured();
 | 
|---|
| 272 | }
 | 
|---|
| 273 | 
 | 
|---|
| 274 | /** Removes a bond from the scene.
 | 
|---|
| 275 |  *
 | 
|---|
| 276 |  * @param _bond bond to remove
 | 
|---|
| 277 |  */
 | 
|---|
| 278 | void GLWorldScene::bondRemoved(const atomId_t leftnr, const atomId_t rightnr)
 | 
|---|
| 279 | {
 | 
|---|
| 280 |   LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond between "+toString(leftnr)+" and "+toString(rightnr)+".");
 | 
|---|
| 281 |   {
 | 
|---|
| 282 |     // left bond
 | 
|---|
| 283 |     const BondIds Leftids( make_pair(leftnr, rightnr) );
 | 
|---|
| 284 |     BondNodeMap::iterator leftiter = BondsinSceneMap.find( Leftids );
 | 
|---|
| 285 |     ASSERT(leftiter != BondsinSceneMap.end(),
 | 
|---|
| 286 |         "GLWorldScene::bondRemoved() - bond "+toString(leftnr)+"-"
 | 
|---|
| 287 |         +toString(rightnr)+" not on display.");
 | 
|---|
| 288 |     //GLMoleculeObject_bond *bondObject = leftiter->second;
 | 
|---|
| 289 |     BondsinSceneMap.erase(leftiter);
 | 
|---|
| 290 |     //delete bondObject; // is done by signal from bond itself
 | 
|---|
| 291 |     //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");
 | 
|---|
| 292 |   }
 | 
|---|
| 293 | 
 | 
|---|
| 294 |   emit changeOccured();
 | 
|---|
| 295 | }
 | 
|---|
| 296 | 
 | 
|---|
| 297 | void GLWorldScene::initialize(QGLView *view, QGLPainter *painter) const
 | 
|---|
| 298 | {
 | 
|---|
| 299 |   // Initialize all of the mesh objects that we have as children.
 | 
|---|
| 300 |    foreach (QObject *obj, children()) {
 | 
|---|
| 301 |      GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
 | 
|---|
| 302 |        if (meshobj)
 | 
|---|
| 303 |          meshobj->initialize(view, painter);
 | 
|---|
| 304 |    }
 | 
|---|
| 305 | }
 | 
|---|
| 306 | 
 | 
|---|
| 307 | void GLWorldScene::draw(QGLPainter *painter, const QVector4D &cameraPlane) const
 | 
|---|
| 308 | {
 | 
|---|
| 309 |    // Draw all of the mesh objects that we have as children.
 | 
|---|
| 310 |    foreach (QObject *obj, children()) {
 | 
|---|
| 311 |      GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
 | 
|---|
| 312 |        if (meshobj)
 | 
|---|
| 313 |          meshobj->draw(painter, cameraPlane);
 | 
|---|
| 314 |    }
 | 
|---|
| 315 | }
 | 
|---|
| 316 | 
 | 
|---|
| 317 | void GLWorldScene::atomClicked(atomId_t no)
 | 
|---|
| 318 | {
 | 
|---|
| 319 |    LOG(3, "INFO: GLWorldScene - atom " << no << " has been clicked.");
 | 
|---|
| 320 |    const atom *Walker = World::getInstance().getAtom(AtomById(no));
 | 
|---|
| 321 |    if (selectionMode == SelectAtom){
 | 
|---|
| 322 |      if (!World::getInstance().isSelected(Walker))
 | 
|---|
| 323 |        SelectionAtomById(std::vector<atomId_t>(1,no));
 | 
|---|
| 324 |      else
 | 
|---|
| 325 |        SelectionNotAtomById(std::vector<atomId_t>(1,no));
 | 
|---|
| 326 |    }else if (selectionMode == SelectMolecule){
 | 
|---|
| 327 |      const molecule *mol = Walker->getMolecule();
 | 
|---|
| 328 |      ASSERT(mol, "Atom without molecule has been clicked.");
 | 
|---|
| 329 |      if (!World::getInstance().isSelected(mol))
 | 
|---|
| 330 |        SelectionMoleculeById(mol->getId());
 | 
|---|
| 331 |      else
 | 
|---|
| 332 |        SelectionNotMoleculeById(mol->getId());
 | 
|---|
| 333 |    }
 | 
|---|
| 334 |    emit clicked(no);
 | 
|---|
| 335 | }
 | 
|---|
| 336 | 
 | 
|---|
| 337 | void GLWorldScene::setSelectionMode(SelectionModeType mode)
 | 
|---|
| 338 | {
 | 
|---|
| 339 |   selectionMode = mode;
 | 
|---|
| 340 |   // TODO send update to toolbar
 | 
|---|
| 341 | }
 | 
|---|
| 342 | 
 | 
|---|
| 343 | void GLWorldScene::setSelectionModeAtom()
 | 
|---|
| 344 | {
 | 
|---|
| 345 |   setSelectionMode(SelectAtom);
 | 
|---|
| 346 | }
 | 
|---|
| 347 | 
 | 
|---|
| 348 | void GLWorldScene::setSelectionModeMolecule()
 | 
|---|
| 349 | {
 | 
|---|
| 350 |   setSelectionMode(SelectMolecule);
 | 
|---|
| 351 | }
 | 
|---|
| 352 | 
 | 
|---|
| 353 | void GLWorldScene::hoverChangedSignalled(GLMoleculeObject *ob)
 | 
|---|
| 354 | {
 | 
|---|
| 355 |   // Find the atom, ob corresponds to.
 | 
|---|
| 356 |   hoverAtom = NULL;
 | 
|---|
| 357 |   GLMoleculeObject_atom *atomObject = dynamic_cast<GLMoleculeObject_atom *>(ob);
 | 
|---|
| 358 |   if (atomObject){
 | 
|---|
| 359 |     for (AtomNodeMap::iterator iter = AtomsinSceneMap.begin();iter != AtomsinSceneMap.end(); ++ iter){
 | 
|---|
| 360 |       if (iter->second == atomObject)
 | 
|---|
| 361 |         hoverAtom = World::getInstance().getAtom(AtomById(iter->first));
 | 
|---|
| 362 |     }
 | 
|---|
| 363 |   }
 | 
|---|
| 364 | 
 | 
|---|
| 365 |   // Propagate signal.
 | 
|---|
| 366 |   emit hoverChanged(hoverAtom);
 | 
|---|
| 367 | }
 | 
|---|
| 368 | 
 | 
|---|
| 369 | void GLWorldScene::changeAtomId(GLMoleculeObject_atom *ob, int oldId, int newId)
 | 
|---|
| 370 | {
 | 
|---|
| 371 |   LOG(3, "INFO: GLWorldScene - change atom id " << oldId << " to " << newId << ".");
 | 
|---|
| 372 |   // Remove from map.
 | 
|---|
| 373 |   AtomNodeMap::iterator iter = AtomsinSceneMap.find(oldId);
 | 
|---|
| 374 |   ASSERT(iter != AtomsinSceneMap.end(),
 | 
|---|
| 375 |         "GLWorldScene::objectIdChangedSignalled() - atom with id "+toString(oldId)+" not on display.");
 | 
|---|
| 376 |   GLMoleculeObject_atom *atomObject = iter->second;
 | 
|---|
| 377 |   AtomsinSceneMap.erase(iter);
 | 
|---|
| 378 | 
 | 
|---|
| 379 |   // Reinsert with new id.
 | 
|---|
| 380 |   AtomsinSceneMap.insert( make_pair(newId, atomObject) );
 | 
|---|
| 381 | }
 | 
|---|
| 382 | 
 | 
|---|