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