| [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 |  | 
|---|
| [9eb71b3] | 53 | //#include "CodePatterns/MemDebug.hpp" | 
|---|
| [907636] | 54 |  | 
|---|
| [7188b1] | 55 | #include "CodePatterns/Log.hpp" | 
|---|
|  | 56 |  | 
|---|
| [f1b5ca] | 57 | #include <boost/assign.hpp> | 
|---|
|  | 58 |  | 
|---|
| [0e9ffe] | 59 | #include "Actions/SelectionAction/Atoms/AtomByIdAction.hpp" | 
|---|
| [89643d] | 60 | #include "Actions/SelectionAction/Atoms/NotAtomByIdAction.hpp" | 
|---|
| [6966b7] | 61 | #include "Actions/SelectionAction/Molecules/MoleculeByIdAction.hpp" | 
|---|
|  | 62 | #include "Actions/SelectionAction/Molecules/NotMoleculeByIdAction.hpp" | 
|---|
| [6f0841] | 63 | #include "Atom/atom.hpp" | 
|---|
| [7188b1] | 64 | #include "Bond/bond.hpp" | 
|---|
| [89643d] | 65 | #include "Descriptors/AtomIdDescriptor.hpp" | 
|---|
| [8c001a] | 66 | #include "Descriptors/MoleculeIdDescriptor.hpp" | 
|---|
| [37b2575] | 67 | #include "Helpers/helpers.hpp" | 
|---|
| [85c36d] | 68 | #include "Shapes/ShapeRegistry.hpp" | 
|---|
| [907636] | 69 | #include "molecule.hpp" | 
|---|
|  | 70 | #include "World.hpp" | 
|---|
|  | 71 |  | 
|---|
| [2ad1ec] | 72 | #include <iostream> | 
|---|
|  | 73 |  | 
|---|
| [ce7fdc] | 74 | using namespace MoleCuilder; | 
|---|
| [907636] | 75 |  | 
|---|
| [efeeb7] | 76 | // static functions | 
|---|
|  | 77 |  | 
|---|
|  | 78 | static void eraseBondNodeParents( | 
|---|
|  | 79 | std::vector<GLWorldScene::BondNodeParentMap_t> &_BondNodeParentMaps, | 
|---|
|  | 80 | const ObservedValue_Index_t &_bondid) | 
|---|
|  | 81 | { | 
|---|
|  | 82 | const size_t left_erased = _BondNodeParentMaps[0].left.erase(_bondid); | 
|---|
|  | 83 | const size_t right_erased = _BondNodeParentMaps[1].left.erase(_bondid); | 
|---|
|  | 84 | ASSERT( (left_erased == 1) && (right_erased == 1), | 
|---|
|  | 85 | "eraseBondNodeParents() - could not erase both parents of "+toString(_bondid)+"?"); | 
|---|
|  | 86 | } | 
|---|
|  | 87 |  | 
|---|
|  | 88 | /** Checks whether both parents of the bond are set to GLWorldScene and the | 
|---|
|  | 89 | * bondRemoved() signals was received for this bond. | 
|---|
|  | 90 | * | 
|---|
|  | 91 | * \param _BondNodeParent_Maps - map containing parents | 
|---|
|  | 92 | * \param _ToBeRemovedNodes - set with all bonds that are to be removed | 
|---|
|  | 93 | * \param _bondid id of bond | 
|---|
|  | 94 | * \return true - both parents are assigned to GLWorldScene, false - else | 
|---|
|  | 95 | */ | 
|---|
|  | 96 | static bool checkBondRemoval( | 
|---|
|  | 97 | const std::vector<GLWorldScene::BondNodeParentMap_t> &_BondNodeParentMaps, | 
|---|
|  | 98 | const GLWorldScene::ToBeRemovedNodes_t &_ToBeRemovedNodes, | 
|---|
|  | 99 | const ObservedValue_Index_t &_bondid) | 
|---|
|  | 100 | { | 
|---|
|  | 101 | GLWorldScene::BondNodeParentMap_t::left_const_iterator leftiter = | 
|---|
|  | 102 | _BondNodeParentMaps[0].left.find(_bondid); | 
|---|
|  | 103 | GLWorldScene::BondNodeParentMap_t::left_const_iterator rightiter = | 
|---|
|  | 104 | _BondNodeParentMaps[1].left.find(_bondid); | 
|---|
|  | 105 | ASSERT( leftiter != _BondNodeParentMaps[0].left.end(), | 
|---|
|  | 106 | "checkBondRemoval() - left parent to index "+toString(_bondid)+" missing?"); | 
|---|
|  | 107 | ASSERT( rightiter != _BondNodeParentMaps[1].left.end(), | 
|---|
|  | 108 | "checkBondRemoval() - right parent to index "+toString(_bondid)+" missing?"); | 
|---|
|  | 109 | return ((leftiter->second == (ObservedValue_Index_t)NULL) | 
|---|
|  | 110 | && (rightiter->second == (ObservedValue_Index_t)NULL) | 
|---|
|  | 111 | && (_ToBeRemovedNodes.count(_bondid))); | 
|---|
|  | 112 | } | 
|---|
|  | 113 |  | 
|---|
|  | 114 | void removeBondFromScene( | 
|---|
|  | 115 | GLWorldScene::BondNodeMap &_BondsinSceneMap, | 
|---|
|  | 116 | const ObservedValue_Index_t &_bondid) | 
|---|
|  | 117 | { | 
|---|
|  | 118 | std::pair<GLWorldScene::BondNodeMap::iterator, GLWorldScene::BondNodeMap::iterator> iters = | 
|---|
|  | 119 | _BondsinSceneMap.equal_range(_bondid); | 
|---|
|  | 120 | ASSERT( iters.first != iters.second, | 
|---|
|  | 121 | "removeBondFromScene() - could not find bond to id "+toString(_bondid)); | 
|---|
|  | 122 | for (GLWorldScene::BondNodeMap::iterator iter = iters.first; iter != iters.second; ++iter) { | 
|---|
|  | 123 | GLMoleculeObject_bond *bondObject = iter->second; | 
|---|
|  | 124 | delete bondObject; // is done by signal from bond itself | 
|---|
|  | 125 | //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << "."); | 
|---|
|  | 126 | } | 
|---|
|  | 127 | _BondsinSceneMap.erase(_bondid); | 
|---|
|  | 128 | } | 
|---|
|  | 129 |  | 
|---|
|  | 130 | static bool checkAtomRemoval( | 
|---|
|  | 131 | const GLWorldScene::AtomNodeParentMap_t &_AtomNodeParentMap, | 
|---|
|  | 132 | const GLWorldScene::ToBeRemovedNodes_t &_ToBeRemovedNodes, | 
|---|
|  | 133 | const ObservedValue_Index_t &_atomid) | 
|---|
|  | 134 | { | 
|---|
|  | 135 | GLWorldScene::AtomNodeParentMap_t::left_const_iterator iter = _AtomNodeParentMap.left.find(_atomid); | 
|---|
|  | 136 | ASSERT( iter != _AtomNodeParentMap.left.end(), | 
|---|
|  | 137 | "checkAtomRemoval() - missing parent entry for "+toString(_atomid)); | 
|---|
|  | 138 | return ((iter->second == (ObservedValue_Index_t)NULL) && (_ToBeRemovedNodes.count(_atomid))); | 
|---|
|  | 139 | } | 
|---|
|  | 140 |  | 
|---|
|  | 141 | // class definitions | 
|---|
|  | 142 |  | 
|---|
| [15c8a9] | 143 | GLWorldScene::GLWorldScene( | 
|---|
| [2f7988] | 144 | QtObservedInstanceBoard * _board, | 
|---|
| [15c8a9] | 145 | QObject *parent) : | 
|---|
|  | 146 | QObject(parent), | 
|---|
| [a13f2b] | 147 | BondNodeParentMaps(std::vector<BondNodeParentMap_t>(2)), | 
|---|
| [15c8a9] | 148 | selectionMode(SelectAtom), | 
|---|
|  | 149 | board(_board) | 
|---|
| [907636] | 150 | { | 
|---|
| [f1b5ca] | 151 | qRegisterMetaType<atomId_t>("atomId_t"); | 
|---|
|  | 152 | qRegisterMetaType<GLMoleculeObject_bond::SideOfBond>("GLMoleculeObject_bond::SideOfBond"); | 
|---|
|  | 153 |  | 
|---|
| [72a4c1] | 154 | int sphereDetails[] = {5, 3, 2, 0}; | 
|---|
|  | 155 | int cylinderDetails[] = {16, 8, 6, 3}; | 
|---|
| [897a01] | 156 | int arrowDetails[] = {8, 5, 3, 0}; | 
|---|
| [72a4c1] | 157 | for (int i=0;i<GLMoleculeObject::DETAILTYPES_MAX;i++){ | 
|---|
|  | 158 | QGLBuilder emptyBuilder; | 
|---|
| [8c001a] | 159 | GLMoleculeObject::meshEmpty[i] = emptyBuilder.finalizedSceneNode(); | 
|---|
| [72a4c1] | 160 | QGLBuilder sphereBuilder; | 
|---|
|  | 161 | sphereBuilder << QGLSphere(2.0, sphereDetails[i]); | 
|---|
| [8c001a] | 162 | GLMoleculeObject::meshSphere[i] = sphereBuilder.finalizedSceneNode(); | 
|---|
|  | 163 | GLMoleculeObject::meshSphere[i]->setOption(QGLSceneNode::CullBoundingBox, true); | 
|---|
| [72a4c1] | 164 | QGLBuilder cylinderBuilder; | 
|---|
|  | 165 | cylinderBuilder << QGLCylinder(.25,.25,1.0,cylinderDetails[i]); | 
|---|
| [8c001a] | 166 | GLMoleculeObject::meshCylinder[i] = cylinderBuilder.finalizedSceneNode(); | 
|---|
|  | 167 | GLMoleculeObject::meshCylinder[i]->setOption(QGLSceneNode::CullBoundingBox, true); | 
|---|
| [897a01] | 168 | { | 
|---|
|  | 169 | QGLBuilder builderCyl; | 
|---|
|  | 170 | builderCyl << QGLCylinder(.15,.15,1.6,arrowDetails[i]); | 
|---|
|  | 171 | QGLSceneNode *cyl = builderCyl.finalizedSceneNode(); | 
|---|
|  | 172 | QGLBuilder builderCone; | 
|---|
|  | 173 | builderCone << QGLCylinder(0,.4,0.4,arrowDetails[i]); | 
|---|
|  | 174 | QGLSceneNode *cone = builderCone.finalizedSceneNode(); | 
|---|
|  | 175 | { | 
|---|
|  | 176 | QMatrix4x4 mat; | 
|---|
|  | 177 | mat.translate(0.0f, 0.0f, 1.0f); | 
|---|
|  | 178 | cone->setLocalTransform(mat); | 
|---|
|  | 179 | } | 
|---|
|  | 180 | GLMoleculeObject::meshArrow[i] = new QGLSceneNode(this); | 
|---|
|  | 181 | GLMoleculeObject::meshArrow[i]->addNode(cyl); | 
|---|
|  | 182 | GLMoleculeObject::meshArrow[i]->addNode(cone); | 
|---|
|  | 183 | } | 
|---|
|  | 184 | GLMoleculeObject::meshArrow[i]->setOption(QGLSceneNode::CullBoundingBox, true); | 
|---|
| [72a4c1] | 185 | } | 
|---|
| [1b07b1] | 186 | connect(board, SIGNAL(moleculeInserted(QtObservedMolecule::ptr)), | 
|---|
| [bd6768] | 187 | this, SLOT(insertMolecule(QtObservedMolecule::ptr))); | 
|---|
| [f91ef6] | 188 | connect(board, SIGNAL(moleculeRemoved(ObservedValue_Index_t)), | 
|---|
| [bd6768] | 189 | this, SLOT(removeMolecule(ObservedValue_Index_t))); | 
|---|
|  | 190 |  | 
|---|
| [59f1bc] | 191 | connect(board, SIGNAL(atomInserted(QtObservedAtom::ptr)), | 
|---|
| [bd6768] | 192 | this, SLOT(connectAtom(QtObservedAtom::ptr)), Qt::DirectConnection); | 
|---|
|  | 193 | connect(this, SIGNAL(atomConnected(QtObservedAtom::ptr)), | 
|---|
|  | 194 | this, SLOT(insertAtom(QtObservedAtom::ptr))); | 
|---|
| [f91ef6] | 195 | connect(board, SIGNAL(atomRemoved(ObservedValue_Index_t)), | 
|---|
| [bd6768] | 196 | this, SLOT(removeAtom(ObservedValue_Index_t))); | 
|---|
|  | 197 |  | 
|---|
| [96f14a] | 198 | connect(board, SIGNAL(bondInserted(QtObservedBond::ptr)), | 
|---|
| [bd6768] | 199 | this, SLOT(connectBond(QtObservedBond::ptr)), Qt::DirectConnection); | 
|---|
|  | 200 | connect(this, SIGNAL(bondConnected(QtObservedBond::ptr)), | 
|---|
|  | 201 | this, SLOT(insertBond(QtObservedBond::ptr))); | 
|---|
| [96f14a] | 202 | connect(board, SIGNAL(bondRemoved(ObservedValue_Index_t)), | 
|---|
| [bd6768] | 203 | this, SLOT(removeBond(ObservedValue_Index_t))); | 
|---|
| [0a6ff9] | 204 |  | 
|---|
| [f714763] | 205 | //  connect(this, SIGNAL(updated()), this, SLOT(update())); | 
|---|
| [907636] | 206 | } | 
|---|
|  | 207 |  | 
|---|
|  | 208 | GLWorldScene::~GLWorldScene() | 
|---|
| [7188b1] | 209 | { | 
|---|
|  | 210 | // remove all elements | 
|---|
|  | 211 | GLMoleculeObject::cleanMaterialMap(); | 
|---|
|  | 212 | } | 
|---|
| [907636] | 213 |  | 
|---|
| [bd6768] | 214 | void GLWorldScene::clickAtom(atomId_t no) | 
|---|
| [8c001a] | 215 | { | 
|---|
| [bd6768] | 216 | LOG(3, "INFO: GLWorldScene - atom " << no << " has been clicked."); | 
|---|
| [f01769] | 217 | const atom * const Walker = const_cast<const World &>(World::getInstance()). | 
|---|
|  | 218 | getAtom(AtomById(no)); | 
|---|
| [369cb1] | 219 | ASSERT( Walker != NULL, | 
|---|
| [bd6768] | 220 | "GLWorldScene::clickAtom() - clicked atom has disappeared."); | 
|---|
| [8c001a] | 221 | if (selectionMode == SelectAtom){ | 
|---|
|  | 222 | if (!World::getInstance().isSelected(Walker)) | 
|---|
|  | 223 | SelectionAtomById(std::vector<atomId_t>(1,no)); | 
|---|
|  | 224 | else | 
|---|
|  | 225 | SelectionNotAtomById(std::vector<atomId_t>(1,no)); | 
|---|
|  | 226 | }else if (selectionMode == SelectMolecule){ | 
|---|
|  | 227 | const molecule *mol = Walker->getMolecule(); | 
|---|
|  | 228 | ASSERT(mol, "Atom without molecule has been clicked."); | 
|---|
| [d7cad1] | 229 | molids_t ids(1, mol->getId()); | 
|---|
| [8c001a] | 230 | if (!World::getInstance().isSelected(mol)) | 
|---|
| [d7cad1] | 231 | SelectionMoleculeById(ids); | 
|---|
| [8c001a] | 232 | else | 
|---|
| [d7cad1] | 233 | SelectionNotMoleculeById(ids); | 
|---|
| [8c001a] | 234 | } | 
|---|
|  | 235 | emit clicked(no); | 
|---|
|  | 236 | } | 
|---|
|  | 237 |  | 
|---|
| [bd6768] | 238 | /** Prepares adding an atom to the scene | 
|---|
|  | 239 | * | 
|---|
|  | 240 | * We need to listen to moleculeChanged() in order to properly re-parent() | 
|---|
|  | 241 | * this QObject | 
|---|
|  | 242 | * | 
|---|
|  | 243 | * @param _atom atom to connect | 
|---|
|  | 244 | */ | 
|---|
|  | 245 | void GLWorldScene::connectAtom(QtObservedAtom::ptr _atom) | 
|---|
|  | 246 | { | 
|---|
| [1eba7c] | 247 | boost::recursive_mutex::scoped_lock lock(Atom_mutex); | 
|---|
|  | 248 |  | 
|---|
| [9d1a78] | 249 | connect(_atom.get(), SIGNAL(moleculeChanged()), this, SLOT(reparentAtom())); | 
|---|
|  | 250 |  | 
|---|
| [136842] | 251 | // store the object, as we need it on reparenting | 
|---|
| [1eba7c] | 252 | const ObservedValue_Index_t atomid = _atom->getIndex(); | 
|---|
| [136842] | 253 | #ifndef NDEBUG | 
|---|
| [1eba7c] | 254 | std::pair< ObservedAtoms_t::iterator, bool > inserter = | 
|---|
| [136842] | 255 | #endif | 
|---|
| [1eba7c] | 256 | ObservedAtoms.insert( std::make_pair(_atom.get(), _atom) ); | 
|---|
|  | 257 | ASSERT( inserter.second, | 
|---|
|  | 258 | "GLWorldScene::connectAtom() - observed atom "+toString(_atom)+" already stored?"); | 
|---|
| [649f59] | 259 | #ifndef NDEBUG | 
|---|
| [1eba7c] | 260 | std::pair< ObservedValueIndexLookup_t::iterator, bool > indexinserter = | 
|---|
| [649f59] | 261 | #endif | 
|---|
| [ea7926] | 262 | ObservedAtomIndexLookup.insert( std::make_pair(atomid, _atom.get()) ); | 
|---|
| [1eba7c] | 263 | ASSERT( indexinserter.second, | 
|---|
|  | 264 | "GLWorldScene::connectAtom() - observed atom's index " | 
|---|
|  | 265 | +toString(atomid)+" already stored?"); | 
|---|
|  | 266 |  | 
|---|
|  | 267 | // and create entry in the parent map | 
|---|
|  | 268 | AtomNodeParentMap.left.insert( std::make_pair(atomid, (ObservedValue_Index_t)NULL) ); | 
|---|
| [bd6768] | 269 |  | 
|---|
|  | 270 | emit atomConnected(_atom); | 
|---|
|  | 271 | } | 
|---|
|  | 272 |  | 
|---|
| [f1b5ca] | 273 | /** Adds an atom to the scene. | 
|---|
| [59f1bc] | 274 | * | 
|---|
| [f1b5ca] | 275 | * @param _atom atom to add | 
|---|
| [9c259e] | 276 | */ | 
|---|
| [bd6768] | 277 | void GLWorldScene::insertAtom(QtObservedAtom::ptr _atom) | 
|---|
| [9c259e] | 278 | { | 
|---|
| [f1b5ca] | 279 | LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom " | 
|---|
|  | 280 | << _atom->getAtomIndex()); | 
|---|
| [1eba7c] | 281 | boost::recursive_mutex::scoped_lock lock(Atom_mutex); | 
|---|
| [f1b5ca] | 282 |  | 
|---|
| [f91ef6] | 283 | const ObservedValue_Index_t atomid = _atom->getIndex(); | 
|---|
| [bd6768] | 284 | QObject *parent = static_cast<QObject *>(this); | 
|---|
|  | 285 | GLMoleculeObject_atom *atomObject = NULL; | 
|---|
|  | 286 | { | 
|---|
| [a13f2b] | 287 | AtomNodeParentMap_t::left_iterator parentiter = AtomNodeParentMap.left.find(atomid); | 
|---|
|  | 288 | ASSERT (parentiter != AtomNodeParentMap.left.end(), | 
|---|
| [502614] | 289 | "GLWorldScene::insertAtom() - parent to atom id "+toString(atomid)+" unknown?"); | 
|---|
|  | 290 | const ObservedValue_Index_t parentindex = parentiter->second; | 
|---|
|  | 291 | if (parentindex != (ObservedValue_Index_t)NULL) { | 
|---|
|  | 292 | const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(parentindex); | 
|---|
|  | 293 | if (moliter != MoleculesinSceneMap.end()) | 
|---|
|  | 294 | parent = moliter->second; | 
|---|
|  | 295 | } | 
|---|
| [bd6768] | 296 |  | 
|---|
|  | 297 | atomObject = new GLMoleculeObject_atom( | 
|---|
|  | 298 | GLMoleculeObject::meshSphere, | 
|---|
| [897a01] | 299 | GLMoleculeObject::meshArrow, | 
|---|
| [bd6768] | 300 | parent, | 
|---|
|  | 301 | _atom); | 
|---|
|  | 302 | ASSERT( atomObject != NULL, | 
|---|
|  | 303 | "GLWorldScene::atomInserted - could not create atom object for " | 
|---|
|  | 304 | +toString(_atom->getAtomIndex())); | 
|---|
|  | 305 | } | 
|---|
| [9d1a78] | 306 | #ifndef NDEBUG | 
|---|
|  | 307 | const AtomNodeMap::iterator iter = AtomsinSceneMap.find(atomid); | 
|---|
|  | 308 | #endif | 
|---|
| [f1b5ca] | 309 | ASSERT(iter == AtomsinSceneMap.end(), | 
|---|
| [bd6768] | 310 | "GLWorldScene::insertAtom - same atom with id " | 
|---|
| [f1b5ca] | 311 | +toString(_atom->getAtomIndex())+" added again."); | 
|---|
|  | 312 | AtomsinSceneMap.insert( make_pair(atomid, atomObject) ); | 
|---|
|  | 313 |  | 
|---|
| [bd6768] | 314 | connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(clickAtom(atomId_t))); | 
|---|
| [f1b5ca] | 315 | connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed())); | 
|---|
|  | 316 | connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed())); | 
|---|
|  | 317 | connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *))); | 
|---|
|  | 318 |  | 
|---|
|  | 319 | emit changed(); | 
|---|
|  | 320 | emit changeOccured(); | 
|---|
| [59f1bc] | 321 | } | 
|---|
|  | 322 |  | 
|---|
| [649f59] | 323 | template <class T> | 
|---|
|  | 324 | void removeStoredObservedValue( | 
|---|
|  | 325 | GLWorldScene::ObservedValueIndexLookup_t &_ObservedValueIndexLookup, | 
|---|
|  | 326 | T &_ObservedValues, | 
|---|
| [efeeb7] | 327 | const ObservedValue_Index_t &_id) | 
|---|
| [649f59] | 328 | { | 
|---|
|  | 329 | // get QObject* from lookup | 
|---|
|  | 330 | const GLWorldScene::ObservedValueIndexLookup_t::iterator iter = | 
|---|
|  | 331 | _ObservedValueIndexLookup.find(_id); | 
|---|
|  | 332 | ASSERT( iter != _ObservedValueIndexLookup.end(), | 
|---|
| [efeeb7] | 333 | "removeStoredObservedValue() - could not find index "+toString(_id) | 
|---|
| [649f59] | 334 | +" to stored observed value."); | 
|---|
|  | 335 | QObject * sender = iter->second; | 
|---|
|  | 336 | const size_t erased = _ObservedValues.erase(sender); | 
|---|
|  | 337 | ASSERT( erased == 1, | 
|---|
| [efeeb7] | 338 | "removeStoredObservedValue() - could not erase stored observed value " | 
|---|
| [649f59] | 339 | +toString(_id)); | 
|---|
|  | 340 | _ObservedValueIndexLookup.erase(iter); | 
|---|
|  | 341 | } | 
|---|
|  | 342 |  | 
|---|
| [efeeb7] | 343 | void removeAtomFromScene( | 
|---|
|  | 344 | GLWorldScene::AtomNodeMap &_AtomsinSceneMap, | 
|---|
|  | 345 | const ObservedValue_Index_t &_atomid) | 
|---|
|  | 346 | { | 
|---|
|  | 347 | GLWorldScene::AtomNodeMap::iterator iter = _AtomsinSceneMap.find(_atomid); | 
|---|
|  | 348 | ASSERT(iter != _AtomsinSceneMap.end(), | 
|---|
|  | 349 | "removeAtomFromScene() - atom "+toString(_atomid)+" not on display."); | 
|---|
|  | 350 | GLMoleculeObject_atom *atomObject = iter->second; | 
|---|
|  | 351 | _AtomsinSceneMap.erase(iter); | 
|---|
|  | 352 | delete atomObject; | 
|---|
|  | 353 | } | 
|---|
|  | 354 |  | 
|---|
|  | 355 | void GLWorldScene::checkAndRemoveAtom(const ObservedValue_Index_t &_atomid) | 
|---|
|  | 356 | { | 
|---|
| [1eba7c] | 357 | boost::recursive_mutex::scoped_lock lock(Atom_mutex); | 
|---|
| [efeeb7] | 358 |  | 
|---|
|  | 359 | if (checkAtomRemoval(AtomNodeParentMap, ToBeRemovedNodes, _atomid)) { | 
|---|
|  | 360 | LOG(4, "DEBUG: Found parent of to be removed atom as GLWorldScene, removing."); | 
|---|
|  | 361 | removeAtomFromScene(AtomsinSceneMap, _atomid); | 
|---|
|  | 362 | AtomNodeParentMap.left.erase(_atomid); | 
|---|
|  | 363 | ToBeRemovedNodes.erase(_atomid); | 
|---|
| [ea7926] | 364 | removeStoredObservedValue(ObservedAtomIndexLookup, ObservedAtoms, _atomid); | 
|---|
| [efeeb7] | 365 | } | 
|---|
|  | 366 | } | 
|---|
|  | 367 |  | 
|---|
| [f1b5ca] | 368 | /** Removes an atom. | 
|---|
| [59f1bc] | 369 | * | 
|---|
| [f1b5ca] | 370 | * @param _atomid index of the atom that is removed | 
|---|
| [59f1bc] | 371 | */ | 
|---|
| [bd6768] | 372 | void GLWorldScene::removeAtom(ObservedValue_Index_t _atomid) | 
|---|
| [59f1bc] | 373 | { | 
|---|
| [f1b5ca] | 374 | LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atomid)+"."); | 
|---|
|  | 375 | // bonds are removed by signal coming from ~bond | 
|---|
| [1eba7c] | 376 | boost::recursive_mutex::scoped_lock lock(Atom_mutex); | 
|---|
| [f1b5ca] | 377 |  | 
|---|
| [efeeb7] | 378 | ASSERT( ToBeRemovedNodes.count(_atomid) == 0, | 
|---|
|  | 379 | "GLWorldScene::removeAtom() - removedAtom signal for id "+toString(_atomid) | 
|---|
|  | 380 | +" came in twice?"); | 
|---|
|  | 381 | ToBeRemovedNodes.insert( _atomid ); | 
|---|
|  | 382 |  | 
|---|
| [f1b5ca] | 383 | // remove atoms | 
|---|
| [efeeb7] | 384 | checkAndRemoveAtom( _atomid ); | 
|---|
| [649f59] | 385 |  | 
|---|
| [f1b5ca] | 386 | emit changed(); | 
|---|
|  | 387 | emit changeOccured(); | 
|---|
| [59f1bc] | 388 | } | 
|---|
|  | 389 |  | 
|---|
| [bd6768] | 390 | /** Prepares adding a bond to the scene | 
|---|
|  | 391 | * | 
|---|
|  | 392 | * We need to listen to moleculeChanged() in order to properly re-parent() | 
|---|
|  | 393 | * this QObject | 
|---|
|  | 394 | * | 
|---|
|  | 395 | * @param _bond bond to connect | 
|---|
|  | 396 | */ | 
|---|
|  | 397 | void GLWorldScene::connectBond(QtObservedBond::ptr _bond) | 
|---|
|  | 398 | { | 
|---|
| [efeeb7] | 399 | LOG(3, "INFO: GLWorldScene::connectBond() - connecting to bonds " << _bond->getBondIndex()); | 
|---|
|  | 400 |  | 
|---|
|  | 401 | connect(_bond.get(), SIGNAL(leftmoleculeChanged()), this, SLOT(reparentBondLeft()), Qt::QueuedConnection); | 
|---|
|  | 402 | connect(_bond.get(), SIGNAL(rightmoleculeChanged()), this, SLOT(reparentBondRight()), Qt::QueuedConnection); | 
|---|
| [bd6768] | 403 |  | 
|---|
| [1eba7c] | 404 | boost::recursive_mutex::scoped_lock lock(Bond_mutex); | 
|---|
|  | 405 |  | 
|---|
| [136842] | 406 | // store the object, as we need it on reparenting | 
|---|
| [1eba7c] | 407 | const ObservedValue_Index_t bondid = _bond->getIndex(); | 
|---|
| [649f59] | 408 | { | 
|---|
| [136842] | 409 | #ifndef NDEBUG | 
|---|
| [649f59] | 410 | std::pair< ObservedBonds_t::iterator, bool > inserter = | 
|---|
| [136842] | 411 | #endif | 
|---|
| [649f59] | 412 | ObservedBonds.insert( std::make_pair(_bond.get(), _bond) ); | 
|---|
|  | 413 | ASSERT( inserter.second, | 
|---|
|  | 414 | "GLWorldScene::connectBond() - observed bond "+toString(_bond)+" already stored?"); | 
|---|
|  | 415 | #ifndef NDEBUG | 
|---|
|  | 416 | std::pair< ObservedValueIndexLookup_t::iterator, bool > indexinserter = | 
|---|
|  | 417 | #endif | 
|---|
| [ea7926] | 418 | ObservedBondIndexLookup.insert( std::make_pair(bondid, _bond.get()) ); | 
|---|
| [649f59] | 419 | ASSERT( indexinserter.second, | 
|---|
|  | 420 | "GLWorldScene::connectBond() - observed bond's index " | 
|---|
| [1eba7c] | 421 | +toString(bondid)+" already stored?"); | 
|---|
| [649f59] | 422 | } | 
|---|
| [bd6768] | 423 | { | 
|---|
| [502614] | 424 | if ((_bond->getLeftAtom() != NULL) && (_bond->getLeftAtom()->getMoleculeRef() != NULL)) | 
|---|
| [a13f2b] | 425 | BondNodeParentMaps[0].left.insert( | 
|---|
|  | 426 | std::make_pair(bondid, _bond->getLeftAtom()->getMoleculeRef()->getIndex()) ); | 
|---|
|  | 427 | else | 
|---|
|  | 428 | BondNodeParentMaps[0].left.insert( | 
|---|
|  | 429 | std::make_pair(bondid, (ObservedValue_Index_t)NULL) ); | 
|---|
| [502614] | 430 | if ((_bond->getRightAtom() != NULL) && (_bond->getRightAtom()->getMoleculeRef() != NULL)) | 
|---|
| [a13f2b] | 431 | BondNodeParentMaps[1].left.insert( | 
|---|
|  | 432 | std::make_pair(bondid, _bond->getRightAtom()->getMoleculeRef()->getIndex()) ); | 
|---|
|  | 433 | else | 
|---|
|  | 434 | BondNodeParentMaps[1].left.insert( | 
|---|
|  | 435 | std::make_pair(bondid, (ObservedValue_Index_t)NULL) ); | 
|---|
| [bd6768] | 436 | } | 
|---|
|  | 437 |  | 
|---|
|  | 438 | emit bondConnected(_bond); | 
|---|
|  | 439 | } | 
|---|
|  | 440 |  | 
|---|
| [f1b5ca] | 441 | /** Adds a bond to the scene. | 
|---|
| [96f14a] | 442 | * | 
|---|
| [f1b5ca] | 443 | * @param _bond bond to add | 
|---|
| [96f14a] | 444 | */ | 
|---|
| [bd6768] | 445 | void GLWorldScene::insertBond(QtObservedBond::ptr _bond) | 
|---|
| [96f14a] | 446 | { | 
|---|
| [1eba7c] | 447 | boost::recursive_mutex::scoped_lock lock(Bond_mutex); | 
|---|
|  | 448 |  | 
|---|
|  | 449 | const std::vector< GLMoleculeObject_bond::SideOfBond > bondsides = | 
|---|
| [f1b5ca] | 450 | boost::assign::list_of<GLMoleculeObject_bond::SideOfBond> | 
|---|
|  | 451 | (GLMoleculeObject_bond::left) | 
|---|
|  | 452 | (GLMoleculeObject_bond::right); | 
|---|
| [bd6768] | 453 | LOG(3, "INFO: GLWorldScene::insertBond() - Adding bonds " << _bond->getBondIndex()); | 
|---|
| [f1b5ca] | 454 |  | 
|---|
| [96f14a] | 455 | const ObservedValue_Index_t bondid = _bond->getIndex(); | 
|---|
| [a13f2b] | 456 | #ifdef NDEBUG | 
|---|
|  | 457 | BondNodeMap::iterator iter = BondsinSceneMap.find(bondid); | 
|---|
|  | 458 | ASSERT( iter == BondsinSceneMap.end(), | 
|---|
|  | 459 | "GLWorldScene::insertBond() - bond "+toString(bondid)+" is already known."); | 
|---|
|  | 460 | #endif | 
|---|
| [bd6768] | 461 | { | 
|---|
| [a13f2b] | 462 | for (size_t i=0;i<2;++i) { | 
|---|
|  | 463 | BondNodeParentMap_t::left_iterator parentiter = BondNodeParentMaps[i].left.find(bondid); | 
|---|
|  | 464 | ASSERT (parentiter != BondNodeParentMaps[i].left.end(), | 
|---|
|  | 465 | "GLWorldScene::insertBond() - parent to bond id "+toString(bondid)+" unknown?"); | 
|---|
|  | 466 | QObject *parent = this; | 
|---|
|  | 467 | if (parentiter->second != (ObservedValue_Index_t)NULL) { | 
|---|
|  | 468 | const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(parentiter->second); | 
|---|
| [502614] | 469 | if (moliter != MoleculesinSceneMap.end()) | 
|---|
| [a13f2b] | 470 | parent = moliter->second; | 
|---|
| [502614] | 471 | } | 
|---|
| [bd6768] | 472 |  | 
|---|
|  | 473 | GLMoleculeObject_bond *bondObject = new GLMoleculeObject_bond( | 
|---|
|  | 474 | GLMoleculeObject::meshCylinder, | 
|---|
| [a13f2b] | 475 | parent, | 
|---|
| [bd6768] | 476 | _bond, | 
|---|
|  | 477 | bondsides[i]); | 
|---|
|  | 478 | connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed())); | 
|---|
|  | 479 | BondsinSceneMap.insert( std::make_pair(bondid, bondObject) ); | 
|---|
|  | 480 | } | 
|---|
| [96f14a] | 481 | } | 
|---|
|  | 482 |  | 
|---|
| [f1b5ca] | 483 | emit changed(); | 
|---|
|  | 484 | emit changeOccured(); | 
|---|
| [96f14a] | 485 | } | 
|---|
|  | 486 |  | 
|---|
| [efeeb7] | 487 | void GLWorldScene::checkAndRemoveBond(const ObservedValue_Index_t &_bondid) | 
|---|
|  | 488 | { | 
|---|
| [1eba7c] | 489 | boost::recursive_mutex::scoped_lock lock(Bond_mutex); | 
|---|
|  | 490 |  | 
|---|
| [efeeb7] | 491 | if (checkBondRemoval(BondNodeParentMaps, ToBeRemovedNodes, _bondid)) { | 
|---|
|  | 492 | LOG(3, "DEBUG: Found both parents of to be removed bond " << _bondid << " as GLWorldScene, removing."); | 
|---|
|  | 493 | removeBondFromScene(BondsinSceneMap, _bondid); | 
|---|
| [ea7926] | 494 | removeStoredObservedValue(ObservedBondIndexLookup, ObservedBonds, _bondid); | 
|---|
| [efeeb7] | 495 | eraseBondNodeParents(BondNodeParentMaps, _bondid); | 
|---|
|  | 496 | ToBeRemovedNodes.erase(_bondid); | 
|---|
|  | 497 | } | 
|---|
|  | 498 | } | 
|---|
|  | 499 |  | 
|---|
| [f1b5ca] | 500 | /** Removes a bond. | 
|---|
| [96f14a] | 501 | * | 
|---|
| [f1b5ca] | 502 | * @param _bondid id of bond to remove | 
|---|
| [96f14a] | 503 | */ | 
|---|
| [bd6768] | 504 | void GLWorldScene::removeBond(ObservedValue_Index_t _bondid) | 
|---|
| [96f14a] | 505 | { | 
|---|
| [1eba7c] | 506 | boost::recursive_mutex::scoped_lock lock(Bond_mutex); | 
|---|
| [efeeb7] | 507 | LOG(3, "INFO: GLWorldScene::removedBond() - got bondRemoved signal from board for id " << _bondid); | 
|---|
| [9c259e] | 508 |  | 
|---|
| [30b134] | 509 | // check current state of associated molecules: We won't receive any | 
|---|
|  | 510 | // moleculeChanged() here anymore, as this QtObservedBond is already | 
|---|
|  | 511 | // disconnected from its bond object | 
|---|
|  | 512 | { | 
|---|
|  | 513 | const ObservedValueIndexLookup_t::const_iterator objiter = ObservedBondIndexLookup.find(_bondid); | 
|---|
|  | 514 | ASSERT( objiter != ObservedBondIndexLookup.end(), | 
|---|
|  | 515 | "GLWorldScene::removeBond() - bond's index "+toString(_bondid) | 
|---|
|  | 516 | +" to be removed not stored yet?"); | 
|---|
|  | 517 | QObject *obj = objiter->second; | 
|---|
|  | 518 | const ObservedBonds_t::const_iterator observediter = ObservedBonds.find(obj); | 
|---|
|  | 519 | ASSERT( observediter != ObservedBonds.end(), | 
|---|
|  | 520 | "GLWorldScene::removeBond() - bond "+toString(_bondid) | 
|---|
|  | 521 | +" to be removed not stored yet??"); | 
|---|
|  | 522 | const QtObservedBond::ptr &_bond = observediter->second; | 
|---|
|  | 523 | if (_bond->getLeftMoleculeIndex() != (moleculeId_t)-1) { | 
|---|
|  | 524 | BondNodeParentMaps[0].left.erase(_bondid); | 
|---|
|  | 525 | BondNodeParentMaps[0].left.insert( std::make_pair( _bondid, (ObservedValue_Index_t)NULL) ); | 
|---|
|  | 526 | resetParent(getBondInScene(_bondid, GLMoleculeObject_bond::left), NULL); | 
|---|
|  | 527 | } | 
|---|
|  | 528 | if (_bond->getRightMoleculeIndex() != (moleculeId_t)-1) { | 
|---|
|  | 529 | BondNodeParentMaps[1].left.erase(_bondid); | 
|---|
|  | 530 | BondNodeParentMaps[1].left.insert( std::make_pair( _bondid, (ObservedValue_Index_t)NULL) ); | 
|---|
|  | 531 | resetParent(getBondInScene(_bondid, GLMoleculeObject_bond::right), NULL); | 
|---|
|  | 532 | } | 
|---|
|  | 533 | } | 
|---|
|  | 534 |  | 
|---|
| [efeeb7] | 535 | ASSERT( ToBeRemovedNodes.find(_bondid) == ToBeRemovedNodes.end(), | 
|---|
|  | 536 | "GLWorldScene::removeBond() - bondRemoved for "+toString(_bondid)+" obtained twice?"); | 
|---|
|  | 537 | ToBeRemovedNodes.insert( _bondid ); | 
|---|
|  | 538 |  | 
|---|
|  | 539 | // check whether node has still non-NULL parents, otherwise remove completely | 
|---|
|  | 540 | checkAndRemoveBond( _bondid ); | 
|---|
| [8281cc] | 541 |  | 
|---|
| [f1b5ca] | 542 | emit changed(); | 
|---|
|  | 543 | emit changeOccured(); | 
|---|
| [9c259e] | 544 | } | 
|---|
|  | 545 |  | 
|---|
| [f1b5ca] | 546 | void GLWorldScene::hoverChangedSignalled(GLMoleculeObject *ob) | 
|---|
| [96f14a] | 547 | { | 
|---|
| [1eba7c] | 548 | boost::recursive_mutex::scoped_lock lock(Atom_mutex); | 
|---|
| [f1b5ca] | 549 | // Find the atom, ob corresponds to. | 
|---|
|  | 550 | hoverAtomId = -1; | 
|---|
|  | 551 | GLMoleculeObject_atom *atomObject = dynamic_cast<GLMoleculeObject_atom *>(ob); | 
|---|
|  | 552 | if (atomObject){ | 
|---|
|  | 553 | for (AtomNodeMap::iterator iter = AtomsinSceneMap.begin();iter != AtomsinSceneMap.end(); ++ iter){ | 
|---|
|  | 554 | if (iter->second == atomObject) | 
|---|
|  | 555 | hoverAtomId = iter->second->objectId(); | 
|---|
| [96f14a] | 556 | } | 
|---|
|  | 557 |  | 
|---|
| [f1b5ca] | 558 | // Propagate signal. | 
|---|
|  | 559 | emit hoverChanged(hoverAtomId); | 
|---|
| [96f14a] | 560 | } else { | 
|---|
| [f1b5ca] | 561 | // Find the atom, ob corresponds to. | 
|---|
|  | 562 | GLMoleculeObject_molecule *moleculeObject = dynamic_cast<GLMoleculeObject_molecule *>(ob); | 
|---|
|  | 563 | if (moleculeObject){ | 
|---|
|  | 564 | // Propagate signal. | 
|---|
|  | 565 | emit hoverChanged(moleculeObject->objectId(), 0); | 
|---|
| [96f14a] | 566 | } | 
|---|
|  | 567 | } | 
|---|
|  | 568 | } | 
|---|
|  | 569 |  | 
|---|
| [bd6768] | 570 | void GLWorldScene::clickMolecule(moleculeId_t no) | 
|---|
| [8281cc] | 571 | { | 
|---|
| [f1b5ca] | 572 | LOG(3, "INFO: GLMoleculeObject_molecule - mol " << no << " has been clicked."); | 
|---|
|  | 573 | const molecule * const mol= const_cast<const World &>(World::getInstance()). | 
|---|
|  | 574 | getMolecule(MoleculeById(no)); | 
|---|
|  | 575 | ASSERT(mol, "Atom without molecule has been clicked."); | 
|---|
|  | 576 | molids_t ids(1, mol->getId()); | 
|---|
|  | 577 | if (!World::getInstance().isSelected(mol)) | 
|---|
|  | 578 | SelectionMoleculeById(ids); | 
|---|
|  | 579 | else | 
|---|
|  | 580 | SelectionNotMoleculeById(ids); | 
|---|
|  | 581 | emit clicked(no); | 
|---|
| [8281cc] | 582 | } | 
|---|
|  | 583 |  | 
|---|
| [026bef] | 584 | /** Inserts a molecule into the scene. | 
|---|
| [c67518] | 585 | * | 
|---|
| [8c001a] | 586 | * @param _mol molecule to insert | 
|---|
| [c67518] | 587 | */ | 
|---|
| [bd6768] | 588 | void GLWorldScene::insertMolecule(QtObservedMolecule::ptr _mol) | 
|---|
| [c67518] | 589 | { | 
|---|
| [f91ef6] | 590 | const ObservedValue_Index_t molid = _mol->getIndex(); | 
|---|
|  | 591 | LOG(3, "INFO: GLWorldScene: Received signal moleculeInserted for molecule " | 
|---|
|  | 592 | << _mol->getMolIndex()); | 
|---|
| [7cf0eb] | 593 |  | 
|---|
| [1b07b1] | 594 | MoleculeNodeMap::const_iterator iter = MoleculesinSceneMap.find(molid); | 
|---|
| [8c001a] | 595 | ASSERT( iter == MoleculesinSceneMap.end(), | 
|---|
| [a13f2b] | 596 | "GLWorldScene::insertMolecule() - molecule's id "+toString(molid) | 
|---|
| [f91ef6] | 597 | +" already present."); | 
|---|
| [8c001a] | 598 |  | 
|---|
|  | 599 | // add new object | 
|---|
| [a13f2b] | 600 | LOG(1, "DEBUG: Adding GLMoleculeObject_molecule to id " << molid); | 
|---|
| [1b07b1] | 601 | GLMoleculeObject_molecule *molObject = | 
|---|
|  | 602 | new GLMoleculeObject_molecule( | 
|---|
|  | 603 | GLMoleculeObject::meshEmpty, | 
|---|
|  | 604 | this, | 
|---|
|  | 605 | _mol); | 
|---|
|  | 606 | ASSERT( molObject != NULL, | 
|---|
| [bd6768] | 607 | "GLWorldScene::insertMolecule - could not create molecule object for " | 
|---|
| [a13f2b] | 608 | +toString(molid)); | 
|---|
| [6c4b69] | 609 | #ifndef NDEBUG | 
|---|
|  | 610 | foreach (QObject *obj, molObject->children()) { | 
|---|
|  | 611 | GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj); | 
|---|
|  | 612 | ASSERT( meshobj == NULL, | 
|---|
|  | 613 | "GLWorldScene::insertMolecule() - there are already atoms or bonds attached to a to molecule."); | 
|---|
|  | 614 | } | 
|---|
|  | 615 | #endif | 
|---|
| [a13f2b] | 616 |  | 
|---|
|  | 617 | // check all atoms for not yet assigned parents | 
|---|
|  | 618 | { | 
|---|
| [1eba7c] | 619 | boost::recursive_mutex::scoped_lock lock(Atom_mutex); | 
|---|
| [a13f2b] | 620 | std::pair<AtomNodeParentMap_t::right_const_iterator, AtomNodeParentMap_t::right_const_iterator> iters = | 
|---|
|  | 621 | AtomNodeParentMap.right.equal_range(molid); | 
|---|
|  | 622 | for (AtomNodeParentMap_t::right_const_iterator iter = iters.first; | 
|---|
|  | 623 | iter != iters.second; ++iter) { | 
|---|
|  | 624 | AtomNodeMap::const_iterator atomiter = AtomsinSceneMap.find(iter->second); | 
|---|
|  | 625 | if (atomiter != AtomsinSceneMap.end()) | 
|---|
|  | 626 | resetParent(atomiter->second, molObject); | 
|---|
|  | 627 | } | 
|---|
|  | 628 | } | 
|---|
|  | 629 | // check all bonds for not yet assigned parents | 
|---|
|  | 630 | { | 
|---|
| [1eba7c] | 631 | boost::recursive_mutex::scoped_lock lock(Bond_mutex); | 
|---|
| [a13f2b] | 632 | for (size_t i=0;i<2;++i) { | 
|---|
|  | 633 | std::pair<BondNodeParentMap_t::right_const_iterator, BondNodeParentMap_t::right_const_iterator> iters = | 
|---|
|  | 634 | BondNodeParentMaps[i].right.equal_range(molid); | 
|---|
|  | 635 | for (BondNodeParentMap_t::right_const_iterator iter = iters.first; | 
|---|
|  | 636 | iter != iters.second; ++iter) { | 
|---|
|  | 637 | BondNodeMap::const_iterator bonditer = BondsinSceneMap.find(iter->second); | 
|---|
|  | 638 | if (bonditer != BondsinSceneMap.end()) | 
|---|
|  | 639 | resetParent(bonditer->second, molObject); | 
|---|
|  | 640 | } | 
|---|
|  | 641 | } | 
|---|
|  | 642 | } | 
|---|
|  | 643 |  | 
|---|
| [1b07b1] | 644 | #ifndef NDEBUG | 
|---|
|  | 645 | std::pair<MoleculeNodeMap::iterator, bool> inserter = | 
|---|
|  | 646 | #endif | 
|---|
|  | 647 | MoleculesinSceneMap.insert( make_pair(molid, molObject) ); | 
|---|
|  | 648 | ASSERT(inserter.second, | 
|---|
| [bd6768] | 649 | "GLWorldScene::insertMolecule() - molecule "+toString(_mol->getMolIndex()) | 
|---|
| [f91ef6] | 650 | +" already present in scene."); | 
|---|
| [1b07b1] | 651 |  | 
|---|
|  | 652 | connect (molObject, SIGNAL(changed()), this, SIGNAL(changed())); | 
|---|
|  | 653 | connect (molObject, SIGNAL(changeOccured()), this, SIGNAL(changeOccured())); | 
|---|
|  | 654 |  | 
|---|
|  | 655 | emit changed(); | 
|---|
|  | 656 | emit changeOccured(); | 
|---|
| [c67518] | 657 | } | 
|---|
|  | 658 |  | 
|---|
| [7cf0eb] | 659 | /** Removes a molecule from the scene. | 
|---|
|  | 660 | * | 
|---|
| [f1b5ca] | 661 | * @param _molid index of the molecule to remove | 
|---|
| [7cf0eb] | 662 | */ | 
|---|
| [bd6768] | 663 | void GLWorldScene::removeMolecule(ObservedValue_Index_t _molid) | 
|---|
| [7cf0eb] | 664 | { | 
|---|
| [f1b5ca] | 665 | LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_molid)+"."); | 
|---|
| [7c7c4a] | 666 |  | 
|---|
| [f1b5ca] | 667 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molid); | 
|---|
| [4a187d] | 668 | ASSERT ( iter != MoleculesinSceneMap.end(), | 
|---|
| [bd6768] | 669 | "GLWorldScene::removeMolecule() - to be removed molecule "+toString(_molid) | 
|---|
| [4a187d] | 670 | +" is already gone."); | 
|---|
| [f1b5ca] | 671 | GLMoleculeObject_molecule *molObject = iter->second; | 
|---|
| [6c4b69] | 672 | // check for any atoms and bonds still attached to it | 
|---|
|  | 673 | #ifndef NDEBUG | 
|---|
|  | 674 | foreach (QObject *obj, molObject->children()) { | 
|---|
|  | 675 | GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj); | 
|---|
|  | 676 | ASSERT( meshobj == NULL, | 
|---|
|  | 677 | "GLWorldScene::removeMolecule() - there are still atoms or bonds attached to a to molecule."); | 
|---|
|  | 678 | } | 
|---|
|  | 679 | #endif | 
|---|
|  | 680 | // finally, remove molecule | 
|---|
| [f1b5ca] | 681 | delete molObject; | 
|---|
| [4a187d] | 682 | MoleculesinSceneMap.erase(iter); | 
|---|
| [bcf9cd] | 683 |  | 
|---|
| [f1b5ca] | 684 | emit changed(); | 
|---|
|  | 685 | emit changeOccured(); | 
|---|
| [ce4126] | 686 | } | 
|---|
|  | 687 |  | 
|---|
| [f91ef6] | 688 | void GLWorldScene::moleculesVisibilityChanged(ObservedValue_Index_t _id, bool _visible) | 
|---|
| [739ee9] | 689 | { | 
|---|
|  | 690 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_id); | 
|---|
|  | 691 | ASSERT( iter != MoleculesinSceneMap.end(), | 
|---|
| [f91ef6] | 692 | "GLWorldScene::moleculeInserted() - molecule's id " | 
|---|
|  | 693 | +toString(board->getMoleculeIdToIndex(_id))+" is unknown."); | 
|---|
| [739ee9] | 694 |  | 
|---|
|  | 695 | GLMoleculeObject_molecule *molObject = iter->second; | 
|---|
|  | 696 | molObject->setVisible(_visible); | 
|---|
|  | 697 |  | 
|---|
|  | 698 | emit changed(); | 
|---|
|  | 699 | emit changeOccured(); | 
|---|
|  | 700 | } | 
|---|
|  | 701 |  | 
|---|
| [a13f2b] | 702 | /** This converts safely index into a GLMoleculeObject_molecule. | 
|---|
|  | 703 | * | 
|---|
|  | 704 | * \param _MoleculesinSceneMap all present molecules | 
|---|
|  | 705 | * \param _molid index to look for | 
|---|
|  | 706 | * \return MolObject or NULL when not found | 
|---|
|  | 707 | */ | 
|---|
|  | 708 | GLMoleculeObject_molecule *GLWorldScene::getMoleculeObject( | 
|---|
|  | 709 | const ObservedValue_Index_t _molid) const | 
|---|
|  | 710 | { | 
|---|
|  | 711 | const MoleculeNodeMap::const_iterator moliter = MoleculesinSceneMap.find(_molid); | 
|---|
|  | 712 | if (moliter != MoleculesinSceneMap.end()) | 
|---|
|  | 713 | return moliter->second; | 
|---|
|  | 714 | else | 
|---|
|  | 715 | return NULL; | 
|---|
|  | 716 | } | 
|---|
|  | 717 |  | 
|---|
| [bd6768] | 718 | /** Changes the parent of an object in the scene. | 
|---|
|  | 719 | * | 
|---|
|  | 720 | * \param _id index of the object whose parent to change | 
|---|
|  | 721 | * \param _ob new parent | 
|---|
|  | 722 | */ | 
|---|
|  | 723 | void GLWorldScene::reparentAtom() | 
|---|
|  | 724 | { | 
|---|
| [1eba7c] | 725 | boost::recursive_mutex::scoped_lock lock(Atom_mutex); | 
|---|
| [649f59] | 726 | QObject * origin = sender(); | 
|---|
| [efeeb7] | 727 | if (origin == NULL) { | 
|---|
|  | 728 | ELOG(1, "Got reparentAtom() with sender being NULL."); | 
|---|
|  | 729 | return; | 
|---|
|  | 730 | } | 
|---|
| [649f59] | 731 | ObservedAtoms_t::const_iterator iter = ObservedAtoms.find(origin); | 
|---|
|  | 732 | ASSERT( iter != ObservedAtoms.end(), | 
|---|
|  | 733 | "GLWorldScene::reparentAtom() - atom's "+toString(origin)+" is no longer stored?"); | 
|---|
|  | 734 | QtObservedAtom::ptr walker = iter->second; | 
|---|
| [bd6768] | 735 | const ObservedValue_Index_t walkerid = walker->getIndex(); | 
|---|
| [6c4b69] | 736 | LOG(4, "DEBUG: GLWorldScene: Received signal moleculeChanged for atom "+toString(walkerid)+"."); | 
|---|
| [a13f2b] | 737 | AtomNodeParentMap_t::left_iterator parentiter = AtomNodeParentMap.left.find(walkerid); | 
|---|
|  | 738 | ASSERT( parentiter != AtomNodeParentMap.left.end(), | 
|---|
| [bd6768] | 739 | "GLWorldScene::reparentAtom() - could not find object to id "+toString(walkerid)); | 
|---|
| [502614] | 740 |  | 
|---|
|  | 741 | // change parent entry | 
|---|
| [a13f2b] | 742 | AtomNodeParentMap.left.erase(parentiter); | 
|---|
| [502614] | 743 | if (walker->getMoleculeRef() != NULL) | 
|---|
| [a13f2b] | 744 | AtomNodeParentMap.left.insert( std::make_pair(walkerid, walker->getMoleculeRef()->getIndex()) ); | 
|---|
| [502614] | 745 | else | 
|---|
| [a13f2b] | 746 | AtomNodeParentMap.left.insert( std::make_pair(walkerid, (ObservedValue_Index_t)NULL) ); | 
|---|
|  | 747 | parentiter = AtomNodeParentMap.left.find(walkerid); | 
|---|
| [502614] | 748 |  | 
|---|
| [a13f2b] | 749 | const AtomNodeMap::iterator atomiter = AtomsinSceneMap.find(walkerid); | 
|---|
|  | 750 | if (atomiter != AtomsinSceneMap.end()) | 
|---|
|  | 751 | resetParent(atomiter->second, getMoleculeObject(parentiter->second)); | 
|---|
|  | 752 | // else atom does not yet exist | 
|---|
| [649f59] | 753 |  | 
|---|
| [efeeb7] | 754 | // check whether node is still shown, otherwise remove completely | 
|---|
|  | 755 | checkAndRemoveAtom( walkerid ); | 
|---|
| [bd6768] | 756 | } | 
|---|
|  | 757 |  | 
|---|
| [502614] | 758 | /** Changes the parent of an left-side bond in the scene. | 
|---|
| [bd6768] | 759 | * | 
|---|
|  | 760 | */ | 
|---|
|  | 761 | void GLWorldScene::reparentBondLeft() | 
|---|
|  | 762 | { | 
|---|
| [1eba7c] | 763 | boost::recursive_mutex::scoped_lock lock(Bond_mutex); | 
|---|
| [649f59] | 764 | QObject * origin = sender(); | 
|---|
| [efeeb7] | 765 | if (origin == NULL) { | 
|---|
|  | 766 | ELOG(1, "Got reparentBondLeft() with sender being NULL."); | 
|---|
|  | 767 | return; | 
|---|
|  | 768 | } | 
|---|
| [649f59] | 769 | ObservedBonds_t::const_iterator iter = ObservedBonds.find(origin); | 
|---|
|  | 770 | ASSERT( iter != ObservedBonds.end(), | 
|---|
|  | 771 | "GLWorldScene::reparentBondLeft() - bond "+toString(origin)+" is no longer stored?"); | 
|---|
|  | 772 | QtObservedBond::ptr bond = iter->second; | 
|---|
| [efeeb7] | 773 | LOG(3, "INFO: GLWorldScene::reparentBondLeft() - Reparenting left side of bond " | 
|---|
|  | 774 | << bond->getBondIndex() << "."); | 
|---|
| [502614] | 775 | reparentBond(bond, bond->getLeftAtom(), GLMoleculeObject_bond::left); | 
|---|
| [649f59] | 776 |  | 
|---|
| [efeeb7] | 777 | // check whether node is still shown, otherwise remove completely | 
|---|
|  | 778 | checkAndRemoveBond( bond->getIndex() ); | 
|---|
| [502614] | 779 | } | 
|---|
|  | 780 |  | 
|---|
|  | 781 | /** Changes the parent of an right-side bond in the scene. | 
|---|
|  | 782 | * | 
|---|
|  | 783 | */ | 
|---|
|  | 784 | void GLWorldScene::reparentBondRight() | 
|---|
|  | 785 | { | 
|---|
| [1eba7c] | 786 | boost::recursive_mutex::scoped_lock lock(Bond_mutex); | 
|---|
| [649f59] | 787 | QObject * origin = sender(); | 
|---|
| [efeeb7] | 788 | if (origin == NULL) { | 
|---|
|  | 789 | ELOG(1, "Got reparentBondRight() with sender being NULL."); | 
|---|
|  | 790 | return; | 
|---|
|  | 791 | } | 
|---|
| [649f59] | 792 | ObservedBonds_t::const_iterator iter = ObservedBonds.find(origin); | 
|---|
|  | 793 | ASSERT( iter != ObservedBonds.end(), | 
|---|
|  | 794 | "GLWorldScene::reparentBondRight() - bond "+toString(origin)+" is no longer stored?"); | 
|---|
|  | 795 | QtObservedBond::ptr bond = iter->second; | 
|---|
| [efeeb7] | 796 | LOG(3, "INFO: GLWorldScene::reparentBondRight() - Reparenting right side of bond " | 
|---|
|  | 797 | << bond->getBondIndex() << "."); | 
|---|
| [502614] | 798 | reparentBond(bond, bond->getRightAtom(), GLMoleculeObject_bond::right); | 
|---|
| [649f59] | 799 |  | 
|---|
| [efeeb7] | 800 | // check whether node is still shown, otherwise remove completely | 
|---|
|  | 801 | checkAndRemoveBond( bond->getIndex() ); | 
|---|
| [502614] | 802 | } | 
|---|
|  | 803 |  | 
|---|
|  | 804 | GLMoleculeObject_bond *GLWorldScene::getBondInScene( | 
|---|
|  | 805 | const ObservedValue_Index_t _bondid, | 
|---|
|  | 806 | GLMoleculeObject_bond::SideOfBond _side) const | 
|---|
|  | 807 | { | 
|---|
|  | 808 | std::pair<GLWorldScene::BondNodeMap::const_iterator, GLWorldScene::BondNodeMap::const_iterator> iters = | 
|---|
|  | 809 | BondsinSceneMap.equal_range(_bondid); | 
|---|
| [efeeb7] | 810 | ASSERT( std::distance(iters.first, iters.second) >= 1, | 
|---|
|  | 811 | "GLWorldScene::getBondInScene() - not at least one bond of id " | 
|---|
| [502614] | 812 | +toString(_bondid)+" present in scene."); | 
|---|
|  | 813 | for (GLWorldScene::BondNodeMap::const_iterator bonditer = iters.first; | 
|---|
|  | 814 | bonditer != iters.second; ++bonditer) { | 
|---|
|  | 815 | if (bonditer->second->BondSide == _side) | 
|---|
|  | 816 | return bonditer->second; | 
|---|
| [bd6768] | 817 | } | 
|---|
| [502614] | 818 | return NULL; | 
|---|
| [bd6768] | 819 | } | 
|---|
|  | 820 |  | 
|---|
|  | 821 | /** Changes the parent of an object in the scene. | 
|---|
|  | 822 | * | 
|---|
| [502614] | 823 | * \param _atom atom of bond whose molecule we are associated to | 
|---|
|  | 824 | * \param _side side of bond | 
|---|
| [bd6768] | 825 | */ | 
|---|
| [502614] | 826 | void GLWorldScene::reparentBond( | 
|---|
| [649f59] | 827 | const QtObservedBond::ptr _bond, | 
|---|
| [507f3c] | 828 | const QtObservedAtom::ptr _atom, | 
|---|
| [502614] | 829 | const GLMoleculeObject_bond::SideOfBond _side) | 
|---|
| [bd6768] | 830 | { | 
|---|
| [1eba7c] | 831 | boost::recursive_mutex::scoped_lock lock(Bond_mutex); | 
|---|
| [a13f2b] | 832 | const size_t dim = (_side == GLMoleculeObject_bond::left) ? 0 : 1; | 
|---|
| [502614] | 833 | const ObservedValue_Index_t bondid = _bond->getIndex(); | 
|---|
| [a13f2b] | 834 | BondNodeParentMap_t::left_iterator parentiter = BondNodeParentMaps[dim].left.find(bondid); | 
|---|
|  | 835 | ASSERT( parentiter != BondNodeParentMaps[dim].left.end(), | 
|---|
| [502614] | 836 | "GLWorldScene::reparentBond() - could not find object to id "+toString(bondid)); | 
|---|
|  | 837 |  | 
|---|
|  | 838 | // change parent entry | 
|---|
| [a13f2b] | 839 | BondNodeParentMaps[dim].left.erase(bondid); | 
|---|
| [502614] | 840 | if ((_atom != NULL) && (_atom->getMoleculeRef() != NULL)) | 
|---|
| [a13f2b] | 841 | BondNodeParentMaps[dim].left.insert( std::make_pair( bondid, _atom->getMoleculeRef()->getIndex())); | 
|---|
| [502614] | 842 | else | 
|---|
| [a13f2b] | 843 | BondNodeParentMaps[dim].left.insert( std::make_pair( bondid, (ObservedValue_Index_t)NULL) ); | 
|---|
|  | 844 | parentiter = BondNodeParentMaps[dim].left.find(bondid); | 
|---|
| [efeeb7] | 845 | LOG(3, "INFO: GLWorldScene::reparentBond() - Reparented bond " | 
|---|
|  | 846 | << _bond->getBondIndex() << " to " << parentiter->second); | 
|---|
| [502614] | 847 |  | 
|---|
|  | 848 | // reset parent | 
|---|
| [a13f2b] | 849 | resetParent(getBondInScene(bondid, _side), getMoleculeObject(parentiter->second)); | 
|---|
|  | 850 | } | 
|---|
|  | 851 |  | 
|---|
|  | 852 | /** Resets the parent of an GLMoleculeObject. | 
|---|
|  | 853 | * | 
|---|
|  | 854 | * \param _obj object to reparent | 
|---|
|  | 855 | * \param _molid index of parent molecule | 
|---|
|  | 856 | */ | 
|---|
|  | 857 | void GLWorldScene::resetParent( | 
|---|
|  | 858 | GLMoleculeObject *_obj, | 
|---|
|  | 859 | GLMoleculeObject_molecule *_molobj) | 
|---|
|  | 860 | { | 
|---|
|  | 861 | if (_obj != NULL) { | 
|---|
| [0bddd1e] | 862 | if (_molobj != NULL) { | 
|---|
|  | 863 | LOG(5, "DEBUG: Resetting parent of " << _obj << " to " << _molobj); | 
|---|
|  | 864 | _obj->setParent(_molobj); | 
|---|
|  | 865 | ASSERT( _obj->parent() == _molobj, | 
|---|
|  | 866 | "GLWorldScene::resetParent() - new parent "+toString(_molobj)+" was not set."); | 
|---|
|  | 867 | } else { | 
|---|
|  | 868 | LOG(5, "DEBUG: Resetting parent of " << _obj << " to " << this); | 
|---|
|  | 869 | _obj->setParent(this); | 
|---|
|  | 870 | ASSERT( _obj->parent() == this, | 
|---|
|  | 871 | "GLWorldScene::resetParent() - new parent "+toString(this)+" was not set."); | 
|---|
|  | 872 | } | 
|---|
| [6c4b69] | 873 | } else | 
|---|
|  | 874 | ELOG(1, "Object to reparent was NULL."); | 
|---|
| [a13f2b] | 875 | // else object does not yet exist | 
|---|
| [bd6768] | 876 | } | 
|---|
|  | 877 |  | 
|---|
| [f75491] | 878 | /** Adds a shape to the scene. | 
|---|
| [4d6662] | 879 | * | 
|---|
| [f75491] | 880 | */ | 
|---|
| [07136a] | 881 | void GLWorldScene::addShape(const std::string &_name) | 
|---|
| [f75491] | 882 | { | 
|---|
| [07136a] | 883 | Shape * const shape = ShapeRegistry::getInstance().getByName(_name); | 
|---|
|  | 884 | if (shape != NULL) { | 
|---|
|  | 885 | GLMoleculeObject_shape *shapeObject = new GLMoleculeObject_shape(*shape, this); | 
|---|
|  | 886 | ShapeNodeMap::iterator iter = ShapesinSceneMap.find(_name); | 
|---|
|  | 887 | ASSERT(iter == ShapesinSceneMap.end(), | 
|---|
|  | 888 | "GLWorldScene::addShape() - same shape "+_name+" added again."); | 
|---|
|  | 889 | ShapesinSceneMap.insert( make_pair(_name, shapeObject) ); | 
|---|
|  | 890 | } else | 
|---|
|  | 891 | ELOG(2, "GLWorldScene::addShape() - shape disappeared before we could draw it."); | 
|---|
|  | 892 |  | 
|---|
|  | 893 | emit changed(); | 
|---|
| [284551] | 894 | } | 
|---|
|  | 895 |  | 
|---|
| [07136a] | 896 | void GLWorldScene::removeShape(const std::string &_name) | 
|---|
| [85c36d] | 897 | { | 
|---|
| [07136a] | 898 | ShapeNodeMap::iterator iter = ShapesinSceneMap.find(_name); | 
|---|
| [ba6b5c] | 899 | ASSERT(iter != ShapesinSceneMap.end(), | 
|---|
| [07136a] | 900 | "GLWorldScene::removeShape() - shape "+_name+" not in scene."); | 
|---|
| [85c36d] | 901 | delete(iter->second); | 
|---|
| [8f2f4e] | 902 | ShapesinSceneMap.erase(iter); | 
|---|
| [07136a] | 903 |  | 
|---|
|  | 904 | emit changed(); | 
|---|
| [85c36d] | 905 | } | 
|---|
|  | 906 |  | 
|---|
|  | 907 | void GLWorldScene::updateSelectedShapes() | 
|---|
| [284551] | 908 | { | 
|---|
|  | 909 | foreach (QObject *obj, children()) { | 
|---|
|  | 910 | GLMoleculeObject_shape *shapeobj = qobject_cast<GLMoleculeObject_shape *>(obj); | 
|---|
| [85c36d] | 911 | if (shapeobj){ | 
|---|
|  | 912 | shapeobj->enable(ShapeRegistry::getInstance().isSelected(shapeobj->getShape())); | 
|---|
|  | 913 | } | 
|---|
| [284551] | 914 | } | 
|---|
| [07136a] | 915 |  | 
|---|
|  | 916 | emit changed(); | 
|---|
| [f75491] | 917 | } | 
|---|
|  | 918 |  | 
|---|
| [7188b1] | 919 | void GLWorldScene::initialize(QGLView *view, QGLPainter *painter) const | 
|---|
|  | 920 | { | 
|---|
|  | 921 | // Initialize all of the mesh objects that we have as children. | 
|---|
|  | 922 | foreach (QObject *obj, children()) { | 
|---|
|  | 923 | GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj); | 
|---|
|  | 924 | if (meshobj) | 
|---|
|  | 925 | meshobj->initialize(view, painter); | 
|---|
|  | 926 | } | 
|---|
|  | 927 | } | 
|---|
|  | 928 |  | 
|---|
| [72a4c1] | 929 | void GLWorldScene::draw(QGLPainter *painter, const QVector4D &cameraPlane) const | 
|---|
| [7188b1] | 930 | { | 
|---|
|  | 931 | // Draw all of the mesh objects that we have as children. | 
|---|
|  | 932 | foreach (QObject *obj, children()) { | 
|---|
|  | 933 | GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj); | 
|---|
|  | 934 | if (meshobj) | 
|---|
| [72a4c1] | 935 | meshobj->draw(painter, cameraPlane); | 
|---|
| [7188b1] | 936 | } | 
|---|
| [907636] | 937 | } | 
|---|
| [06ebf5] | 938 |  | 
|---|
| [6966b7] | 939 | void GLWorldScene::setSelectionMode(SelectionModeType mode) | 
|---|
|  | 940 | { | 
|---|
|  | 941 | selectionMode = mode; | 
|---|
|  | 942 | // TODO send update to toolbar | 
|---|
|  | 943 | } | 
|---|
|  | 944 |  | 
|---|
|  | 945 | void GLWorldScene::setSelectionModeAtom() | 
|---|
|  | 946 | { | 
|---|
|  | 947 | setSelectionMode(SelectAtom); | 
|---|
|  | 948 | } | 
|---|
|  | 949 |  | 
|---|
|  | 950 | void GLWorldScene::setSelectionModeMolecule() | 
|---|
|  | 951 | { | 
|---|
|  | 952 | setSelectionMode(SelectMolecule); | 
|---|
|  | 953 | } | 
|---|
| [20f9b5] | 954 |  | 
|---|