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