| [907636] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
| [0aa122] | 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| [94d5ac6] | 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/>.
 | 
|---|
| [907636] | 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"
 | 
|---|
| [d1196d] | 38 | #include <Qt3D/qglview.h>
 | 
|---|
| [bca99d] | 39 | #include <Qt3D/qglbuilder.h>
 | 
|---|
 | 40 | #include <Qt3D/qglscenenode.h>
 | 
|---|
 | 41 | #include <Qt3D/qglsphere.h>
 | 
|---|
 | 42 | #include <Qt3D/qglcylinder.h>
 | 
|---|
| [907636] | 43 | 
 | 
|---|
 | 44 | #include "GLMoleculeObject.hpp"
 | 
|---|
| [7188b1] | 45 | #include "GLMoleculeObject_atom.hpp"
 | 
|---|
 | 46 | #include "GLMoleculeObject_bond.hpp"
 | 
|---|
| [c67518] | 47 | #include "GLMoleculeObject_molecule.hpp"
 | 
|---|
| [907636] | 48 | 
 | 
|---|
 | 49 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
 | 50 | 
 | 
|---|
| [7188b1] | 51 | #include "CodePatterns/Log.hpp"
 | 
|---|
 | 52 | 
 | 
|---|
| [0e9ffe] | 53 | #include "Actions/SelectionAction/Atoms/AtomByIdAction.hpp"
 | 
|---|
| [89643d] | 54 | #include "Actions/SelectionAction/Atoms/NotAtomByIdAction.hpp"
 | 
|---|
| [6966b7] | 55 | #include "Actions/SelectionAction/Molecules/MoleculeByIdAction.hpp"
 | 
|---|
 | 56 | #include "Actions/SelectionAction/Molecules/NotMoleculeByIdAction.hpp"
 | 
|---|
| [6f0841] | 57 | #include "Atom/atom.hpp"
 | 
|---|
| [7188b1] | 58 | #include "Bond/bond.hpp"
 | 
|---|
| [89643d] | 59 | #include "Descriptors/AtomIdDescriptor.hpp"
 | 
|---|
| [37b2575] | 60 | #include "Helpers/helpers.hpp"
 | 
|---|
| [907636] | 61 | #include "molecule.hpp"
 | 
|---|
 | 62 | #include "World.hpp"
 | 
|---|
 | 63 | 
 | 
|---|
| [2ad1ec] | 64 | #include <iostream>
 | 
|---|
 | 65 | 
 | 
|---|
| [ce7fdc] | 66 | using namespace MoleCuilder;
 | 
|---|
| [907636] | 67 | 
 | 
|---|
| [2ad1ec] | 68 | std::ostream &operator<<(std::ostream &ost, const GLWorldScene::BondIds &t)
 | 
|---|
 | 69 | {
 | 
|---|
 | 70 |   ost << t.first << "," << t.second;
 | 
|---|
 | 71 |   return ost;
 | 
|---|
 | 72 | }
 | 
|---|
 | 73 | 
 | 
|---|
| [907636] | 74 | GLWorldScene::GLWorldScene(QObject *parent)
 | 
|---|
| [407638e] | 75 |    : QObject(parent),
 | 
|---|
 | 76 |      hoverAtom(NULL)
 | 
|---|
| [907636] | 77 | {
 | 
|---|
| [72a4c1] | 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 |   }
 | 
|---|
| [0a6ff9] | 92 | 
 | 
|---|
| [6966b7] | 93 |   setSelectionMode(SelectAtom);
 | 
|---|
 | 94 | 
 | 
|---|
| [907636] | 95 |   init();
 | 
|---|
 | 96 | }
 | 
|---|
 | 97 | 
 | 
|---|
 | 98 | GLWorldScene::~GLWorldScene()
 | 
|---|
| [7188b1] | 99 | {
 | 
|---|
 | 100 |   // remove all elements
 | 
|---|
 | 101 |   GLMoleculeObject::cleanMaterialMap();
 | 
|---|
 | 102 | }
 | 
|---|
| [907636] | 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++) {
 | 
|---|
| [c67518] | 115 | 
 | 
|---|
| [7188b1] | 116 |       for (molecule::const_iterator atomiter = (*Runner)->begin();
 | 
|---|
 | 117 |           atomiter != (*Runner)->end();
 | 
|---|
 | 118 |           ++atomiter) {
 | 
|---|
 | 119 |         // create atom objects in scene
 | 
|---|
 | 120 |         atomInserted(*atomiter);
 | 
|---|
 | 121 | 
 | 
|---|
| [9c18e4] | 122 |         // create bond objects in scene
 | 
|---|
| [2ad1ec] | 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 |         }
 | 
|---|
| [7188b1] | 132 |       }
 | 
|---|
| [907636] | 133 |     }
 | 
|---|
 | 134 |   }
 | 
|---|
 | 135 | }
 | 
|---|
 | 136 | 
 | 
|---|
| [7188b1] | 137 | /** Adds an atom to the scene.
 | 
|---|
 | 138 |  *
 | 
|---|
 | 139 |  * @param _atom atom to add
 | 
|---|
 | 140 |  */
 | 
|---|
 | 141 | void GLWorldScene::atomInserted(const atom *_atom)
 | 
|---|
| [907636] | 142 | {
 | 
|---|
| [57a770] | 143 |   LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "+toString(_atom->getId())+".");
 | 
|---|
| [72a4c1] | 144 |   GLMoleculeObject_atom *atomObject = new GLMoleculeObject_atom(meshSphere, this, _atom);
 | 
|---|
| [37b2575] | 145 |   AtomNodeMap::iterator iter = AtomsinSceneMap.find(_atom->getId());
 | 
|---|
 | 146 |   ASSERT(iter == AtomsinSceneMap.end(),
 | 
|---|
| [7188b1] | 147 |       "GLWorldScene::atomAdded() - same atom "+_atom->getName()+" added again.");
 | 
|---|
| [37b2575] | 148 |   AtomsinSceneMap.insert( make_pair(_atom->getId(), atomObject) );
 | 
|---|
| [7188b1] | 149 |   connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
 | 
|---|
| [5a2a06] | 150 |   connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed()));
 | 
|---|
| [407638e] | 151 |   connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
 | 
|---|
 | 152 |   connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
 | 
|---|
| [5a2a06] | 153 |   connect (atomObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
 | 
|---|
| [2ad1ec] | 154 |   connect (atomObject, SIGNAL(BondsInserted(const bond *, const GLMoleculeObject_bond::SideOfBond)), this, SLOT(bondInserted(const bond *, const GLMoleculeObject_bond::SideOfBond)));
 | 
|---|
| [30cd0d] | 155 |   connect (atomObject, SIGNAL(indexChanged(GLMoleculeObject_atom*, int, int)), this, SLOT(changeAtomId(GLMoleculeObject_atom*, int, int)));
 | 
|---|
| [2ad1ec] | 156 |   //bondsChanged(_atom);
 | 
|---|
| [65487f] | 157 |   emit changeOccured();
 | 
|---|
| [7188b1] | 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 | {
 | 
|---|
| [57a770] | 166 |   LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atom->getId())+".");
 | 
|---|
| [2ad1ec] | 167 |   // bonds are removed by signal coming from ~bond
 | 
|---|
| [7188b1] | 168 |   // remove atoms
 | 
|---|
| [37b2575] | 169 |   AtomNodeMap::iterator iter = AtomsinSceneMap.find(_atom->getId());
 | 
|---|
 | 170 |   ASSERT(iter != AtomsinSceneMap.end(),
 | 
|---|
| [7188b1] | 171 |       "GLWorldScene::atomRemoved() - atom "+_atom->getName()+" not on display.");
 | 
|---|
 | 172 |   GLMoleculeObject_atom *atomObject = iter->second;
 | 
|---|
 | 173 |   atomObject->disconnect();
 | 
|---|
| [37b2575] | 174 |   AtomsinSceneMap.erase(iter);
 | 
|---|
| [7188b1] | 175 |   delete atomObject;
 | 
|---|
| [65487f] | 176 |   emit changeOccured();
 | 
|---|
| [907636] | 177 | }
 | 
|---|
 | 178 | 
 | 
|---|
| [3927ef] | 179 | /** ....
 | 
|---|
| [c67518] | 180 |  *
 | 
|---|
 | 181 |  */
 | 
|---|
| [3927ef] | 182 | void GLWorldScene::worldSelectionChanged()
 | 
|---|
| [c67518] | 183 | {
 | 
|---|
| [3927ef] | 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
 | 
|---|
| [bca99d] | 199 |         GLMoleculeObject_molecule *molObject = new GLMoleculeObject_molecule(meshEmpty, this, *Runner);
 | 
|---|
| [3927ef] | 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 |   }
 | 
|---|
| [c67518] | 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 | {
 | 
|---|
| [3927ef] | 224 |   LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_molecule->getId())+".");
 | 
|---|
| [c67518] | 225 |   MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molecule->getId());
 | 
|---|
| [3927ef] | 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 |   }
 | 
|---|
| [c67518] | 237 | }
 | 
|---|
 | 238 | 
 | 
|---|
| [37b2575] | 239 | /** Adds a bond to the scene.
 | 
|---|
| [7188b1] | 240 |  *
 | 
|---|
 | 241 |  * @param _bond bond to add
 | 
|---|
| [2ad1ec] | 242 |  * @param side which side of the bond (left or right)
 | 
|---|
| [7188b1] | 243 |  */
 | 
|---|
| [2ad1ec] | 244 | void GLWorldScene::bondInserted(const bond *_bond, const enum GLMoleculeObject_bond::SideOfBond side)
 | 
|---|
| [7188b1] | 245 | {
 | 
|---|
| [57a770] | 246 |   LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bond "+toString(*_bond)+".");
 | 
|---|
| [2ad1ec] | 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;
 | 
|---|
| [7188b1] | 257 |   }
 | 
|---|
| [2ad1ec] | 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 =
 | 
|---|
| [72a4c1] | 264 |       new GLMoleculeObject_bond(meshCylinder, this, _bond, side);
 | 
|---|
| [2ad1ec] | 265 |   connect (
 | 
|---|
 | 266 |       bondObject, SIGNAL(BondRemoved(const atomId_t, const atomId_t)),
 | 
|---|
 | 267 |       this, SLOT(bondRemoved(const atomId_t, const atomId_t)));
 | 
|---|
| [5a2a06] | 268 |   connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));
 | 
|---|
| [2ad1ec] | 269 |   BondsinSceneMap.insert( make_pair(ids, bondObject) );
 | 
|---|
 | 270 | //    BondIdsinSceneMap.insert( Leftids );
 | 
|---|
| [65487f] | 271 |   emit changeOccured();
 | 
|---|
| [7188b1] | 272 | }
 | 
|---|
| [907636] | 273 | 
 | 
|---|
| [37b2575] | 274 | /** Removes a bond from the scene.
 | 
|---|
| [7188b1] | 275 |  *
 | 
|---|
 | 276 |  * @param _bond bond to remove
 | 
|---|
 | 277 |  */
 | 
|---|
| [37b2575] | 278 | void GLWorldScene::bondRemoved(const atomId_t leftnr, const atomId_t rightnr)
 | 
|---|
| [907636] | 279 | {
 | 
|---|
| [2ad1ec] | 280 |   LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond between "+toString(leftnr)+" and "+toString(rightnr)+".");
 | 
|---|
| [7188b1] | 281 |   {
 | 
|---|
 | 282 |     // left bond
 | 
|---|
| [37b2575] | 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.");
 | 
|---|
| [2ad1ec] | 288 |     //GLMoleculeObject_bond *bondObject = leftiter->second;
 | 
|---|
| [37b2575] | 289 |     BondsinSceneMap.erase(leftiter);
 | 
|---|
| [2ad1ec] | 290 |     //delete bondObject; // is done by signal from bond itself
 | 
|---|
 | 291 |     //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");
 | 
|---|
| [7188b1] | 292 |   }
 | 
|---|
| [2ad1ec] | 293 | 
 | 
|---|
| [65487f] | 294 |   emit changeOccured();
 | 
|---|
| [7188b1] | 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 | 
 | 
|---|
| [72a4c1] | 307 | void GLWorldScene::draw(QGLPainter *painter, const QVector4D &cameraPlane) const
 | 
|---|
| [7188b1] | 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)
 | 
|---|
| [72a4c1] | 313 |          meshobj->draw(painter, cameraPlane);
 | 
|---|
| [7188b1] | 314 |    }
 | 
|---|
| [907636] | 315 | }
 | 
|---|
| [06ebf5] | 316 | 
 | 
|---|
| [7188b1] | 317 | void GLWorldScene::atomClicked(atomId_t no)
 | 
|---|
| [907636] | 318 | {
 | 
|---|
| [57a770] | 319 |    LOG(3, "INFO: GLWorldScene - atom " << no << " has been clicked.");
 | 
|---|
| [89643d] | 320 |    const atom *Walker = World::getInstance().getAtom(AtomById(no));
 | 
|---|
| [6966b7] | 321 |    if (selectionMode == SelectAtom){
 | 
|---|
 | 322 |      if (!World::getInstance().isSelected(Walker))
 | 
|---|
| [f7c7cf] | 323 |        SelectionAtomById(std::vector<atomId_t>(1,no));
 | 
|---|
| [6966b7] | 324 |      else
 | 
|---|
| [f7c7cf] | 325 |        SelectionNotAtomById(std::vector<atomId_t>(1,no));
 | 
|---|
| [6966b7] | 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 |    }
 | 
|---|
| [7188b1] | 334 |    emit clicked(no);
 | 
|---|
| [907636] | 335 | }
 | 
|---|
| [029bb4] | 336 | 
 | 
|---|
| [6966b7] | 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 | 
 | 
|---|
| [407638e] | 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 | 
 | 
|---|
| [30cd0d] | 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 | 
 | 
|---|