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