[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 |
|
---|
[0e9ffe] | 57 | #include "Actions/SelectionAction/Atoms/AtomByIdAction.hpp"
|
---|
[89643d] | 58 | #include "Actions/SelectionAction/Atoms/NotAtomByIdAction.hpp"
|
---|
[6966b7] | 59 | #include "Actions/SelectionAction/Molecules/MoleculeByIdAction.hpp"
|
---|
| 60 | #include "Actions/SelectionAction/Molecules/NotMoleculeByIdAction.hpp"
|
---|
[6f0841] | 61 | #include "Atom/atom.hpp"
|
---|
[7188b1] | 62 | #include "Bond/bond.hpp"
|
---|
[89643d] | 63 | #include "Descriptors/AtomIdDescriptor.hpp"
|
---|
[8c001a] | 64 | #include "Descriptors/MoleculeIdDescriptor.hpp"
|
---|
[37b2575] | 65 | #include "Helpers/helpers.hpp"
|
---|
[85c36d] | 66 | #include "Shapes/ShapeRegistry.hpp"
|
---|
[907636] | 67 | #include "molecule.hpp"
|
---|
| 68 | #include "World.hpp"
|
---|
| 69 |
|
---|
[2ad1ec] | 70 | #include <iostream>
|
---|
| 71 |
|
---|
[ce7fdc] | 72 | using namespace MoleCuilder;
|
---|
[907636] | 73 |
|
---|
[15c8a9] | 74 | GLWorldScene::GLWorldScene(
|
---|
[2f7988] | 75 | QtObservedInstanceBoard * _board,
|
---|
[15c8a9] | 76 | QObject *parent) :
|
---|
| 77 | QObject(parent),
|
---|
| 78 | selectionMode(SelectAtom),
|
---|
| 79 | board(_board)
|
---|
[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;
|
---|
[8c001a] | 85 | GLMoleculeObject::meshEmpty[i] = emptyBuilder.finalizedSceneNode();
|
---|
[72a4c1] | 86 | QGLBuilder sphereBuilder;
|
---|
| 87 | sphereBuilder << QGLSphere(2.0, sphereDetails[i]);
|
---|
[8c001a] | 88 | GLMoleculeObject::meshSphere[i] = sphereBuilder.finalizedSceneNode();
|
---|
| 89 | GLMoleculeObject::meshSphere[i]->setOption(QGLSceneNode::CullBoundingBox, true);
|
---|
[72a4c1] | 90 | QGLBuilder cylinderBuilder;
|
---|
| 91 | cylinderBuilder << QGLCylinder(.25,.25,1.0,cylinderDetails[i]);
|
---|
[8c001a] | 92 | GLMoleculeObject::meshCylinder[i] = cylinderBuilder.finalizedSceneNode();
|
---|
| 93 | GLMoleculeObject::meshCylinder[i]->setOption(QGLSceneNode::CullBoundingBox, true);
|
---|
[72a4c1] | 94 | }
|
---|
[15c8a9] | 95 | connect(board, SIGNAL(moleculeInserted(const moleculeId_t)),
|
---|
| 96 | this, SLOT(moleculeInserted(const moleculeId_t)));
|
---|
| 97 | connect(board, SIGNAL(moleculeRemoved(const moleculeId_t)),
|
---|
| 98 | this, SLOT(moleculeRemoved(const moleculeId_t)));
|
---|
| 99 | connect(board, SIGNAL(moleculeIndexChanged(const moleculeId_t, const moleculeId_t)),
|
---|
| 100 | this, SLOT(moleculeIndexChanged(const moleculeId_t, const moleculeId_t)));
|
---|
[8d5fbf1] | 101 | connect(board, SIGNAL(atomInserted(const moleculeId_t, const atomId_t)),
|
---|
| 102 | this, SLOT(atomInserted(const moleculeId_t, const atomId_t)), Qt::DirectConnection);
|
---|
| 103 | connect(board, SIGNAL(atomRemoved(const moleculeId_t, const atomId_t)),
|
---|
| 104 | this, SLOT(atomRemoved(const moleculeId_t, const atomId_t)), Qt::DirectConnection);
|
---|
[0a6ff9] | 105 |
|
---|
[f714763] | 106 | // connect(this, SIGNAL(updated()), this, SLOT(update()));
|
---|
[907636] | 107 | }
|
---|
| 108 |
|
---|
| 109 | GLWorldScene::~GLWorldScene()
|
---|
[7188b1] | 110 | {
|
---|
| 111 | // remove all elements
|
---|
| 112 | GLMoleculeObject::cleanMaterialMap();
|
---|
| 113 | }
|
---|
[907636] | 114 |
|
---|
[8c001a] | 115 | void GLWorldScene::atomClicked(atomId_t no)
|
---|
| 116 | {
|
---|
| 117 | LOG(3, "INFO: GLMoleculeObject_molecule - atom " << no << " has been clicked.");
|
---|
[f01769] | 118 | const atom * const Walker = const_cast<const World &>(World::getInstance()).
|
---|
| 119 | getAtom(AtomById(no));
|
---|
[369cb1] | 120 | ASSERT( Walker != NULL,
|
---|
| 121 | "GLWorldScene::atomClicked() - clicked atom has disappeared.");
|
---|
[8c001a] | 122 | if (selectionMode == SelectAtom){
|
---|
| 123 | if (!World::getInstance().isSelected(Walker))
|
---|
| 124 | SelectionAtomById(std::vector<atomId_t>(1,no));
|
---|
| 125 | else
|
---|
| 126 | SelectionNotAtomById(std::vector<atomId_t>(1,no));
|
---|
| 127 | }else if (selectionMode == SelectMolecule){
|
---|
| 128 | const molecule *mol = Walker->getMolecule();
|
---|
| 129 | ASSERT(mol, "Atom without molecule has been clicked.");
|
---|
[d7cad1] | 130 | molids_t ids(1, mol->getId());
|
---|
[8c001a] | 131 | if (!World::getInstance().isSelected(mol))
|
---|
[d7cad1] | 132 | SelectionMoleculeById(ids);
|
---|
[8c001a] | 133 | else
|
---|
[d7cad1] | 134 | SelectionNotMoleculeById(ids);
|
---|
[8c001a] | 135 | }
|
---|
| 136 | emit clicked(no);
|
---|
| 137 | }
|
---|
| 138 |
|
---|
[9a7ef9] | 139 | void GLWorldScene::moleculeClicked(moleculeId_t no)
|
---|
| 140 | {
|
---|
| 141 | LOG(3, "INFO: GLMoleculeObject_molecule - mol " << no << " has been clicked.");
|
---|
[63fb7a] | 142 | const molecule * const mol= const_cast<const World &>(World::getInstance()).
|
---|
| 143 | getMolecule(MoleculeById(no));
|
---|
[9a7ef9] | 144 | ASSERT(mol, "Atom without molecule has been clicked.");
|
---|
[d7cad1] | 145 | molids_t ids(1, mol->getId());
|
---|
[9a7ef9] | 146 | if (!World::getInstance().isSelected(mol))
|
---|
[d7cad1] | 147 | SelectionMoleculeById(ids);
|
---|
[9a7ef9] | 148 | else
|
---|
[d7cad1] | 149 | SelectionNotMoleculeById(ids);
|
---|
[9a7ef9] | 150 | emit clicked(no);
|
---|
| 151 | }
|
---|
| 152 |
|
---|
[9c259e] | 153 | /** Inserts an atom into the scene before molecule is present.
|
---|
| 154 | *
|
---|
| 155 | * @param _molid molecule to insert atom for
|
---|
| 156 | * @param _atomid atom to insert
|
---|
| 157 | */
|
---|
| 158 | void GLWorldScene::atomInserted(const moleculeId_t _molid, const atomId_t _atomid)
|
---|
| 159 | {
|
---|
[73b13c] | 160 | boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
|
---|
| 161 |
|
---|
[7c7c4a] | 162 | LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "+toString(_atomid)+".");
|
---|
| 163 |
|
---|
[9c259e] | 164 | // check of molecule is already present
|
---|
[8d5fbf1] | 165 | MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(_molid);
|
---|
| 166 | if (moliter != MoleculesinSceneMap.end()) {
|
---|
[494478] | 167 | // no action, is also caught via QtObservedMolecule by GLMoleculeObject_molecule
|
---|
[9c259e] | 168 | } else {
|
---|
| 169 | // store signal for when it is instantiated
|
---|
| 170 | if (MoleculeMissedStateMap.count(_molid) == 0)
|
---|
| 171 | MoleculeMissedStateMap.insert( std::make_pair(_molid ,StateChangeMap_t()) );
|
---|
| 172 | MoleculeMissedStateMap[_molid].insert( std::make_pair(_atomid, atomInsertedState) );
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | /** Removes an atom into the scene before molecule is present.
|
---|
| 177 | *
|
---|
| 178 | * @param _molid molecule to insert atom for
|
---|
| 179 | * @param _atomid atom to insert
|
---|
| 180 | */
|
---|
| 181 | void GLWorldScene::atomRemoved(const moleculeId_t _molid, const atomId_t _atomid)
|
---|
| 182 | {
|
---|
| 183 | LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atomid)+".");
|
---|
| 184 |
|
---|
[73b13c] | 185 | boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
|
---|
| 186 |
|
---|
[9c259e] | 187 | // check of molecule is already present
|
---|
[8d5fbf1] | 188 | MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(_molid);
|
---|
| 189 | if (moliter != MoleculesinSceneMap.end()) {
|
---|
[494478] | 190 | // no action, is also caught via QtObservedMolecule by GLMoleculeObject_molecule
|
---|
[9c259e] | 191 | } else {
|
---|
| 192 | // store signal for when it is instantiated
|
---|
| 193 | if (MoleculeMissedStateMap.count(_molid) == 0)
|
---|
| 194 | MoleculeMissedStateMap.insert( std::make_pair(_molid ,StateChangeMap_t()) );
|
---|
| 195 | MoleculeMissedStateMap[_molid].insert( std::make_pair(_atomid, atomRemovedState) );
|
---|
| 196 | }
|
---|
| 197 | }
|
---|
| 198 |
|
---|
[026bef] | 199 | /** Inserts a molecule into the scene.
|
---|
[c67518] | 200 | *
|
---|
[8c001a] | 201 | * @param _mol molecule to insert
|
---|
[c67518] | 202 | */
|
---|
[026bef] | 203 | void GLWorldScene::moleculeInserted(const moleculeId_t _id)
|
---|
[c67518] | 204 | {
|
---|
[026bef] | 205 | LOG(3, "INFO: GLWorldScene: Received signal moleculeInserted for molecule "+toString(_id)+".");
|
---|
[7cf0eb] | 206 |
|
---|
| 207 | boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
|
---|
| 208 |
|
---|
[ef3013] | 209 | MoleculeNodeMap::const_iterator iter = MoleculesinSceneMap.find(_id);
|
---|
[8c001a] | 210 | ASSERT( iter == MoleculesinSceneMap.end(),
|
---|
[ef3013] | 211 | "GLWorldScene::moleculeInserted() - molecule's id "+toString(_id)+" already present.");
|
---|
[8c001a] | 212 |
|
---|
[20f9b5] | 213 | // check whether molecule is still present
|
---|
| 214 | if (RemovalMolecules.count(_id) != 0) {
|
---|
| 215 | RemovalMolecules.erase(_id);
|
---|
| 216 | return;
|
---|
| 217 | }
|
---|
[7cf0eb] | 218 | if (const_cast<const World &>(World::getInstance()).getMolecule(MoleculeById(_id)) == NULL) {
|
---|
| 219 | ELOG(2, "Molecule with id " << _id << " has disappeared.");
|
---|
[20f9b5] | 220 | return;
|
---|
[7cf0eb] | 221 | }
|
---|
[20f9b5] | 222 |
|
---|
[8c001a] | 223 | // add new object
|
---|
[7c7c4a] | 224 | LOG(1, "DEBUG: Adding GLMoleculeObject_molecule to id " << _id);
|
---|
[b3a33d] | 225 | GLMoleculeObject_molecule *molObject =
|
---|
[026bef] | 226 | new GLMoleculeObject_molecule(
|
---|
[8d5fbf1] | 227 | GLMoleculeObject::meshEmpty,
|
---|
| 228 | this,
|
---|
[494478] | 229 | *board,
|
---|
| 230 | board->getObservedMolecule(_id));
|
---|
[704d59] | 231 | ASSERT( molObject != NULL,
|
---|
| 232 | "GLWorldScene::moleculeInserted - could not create molecule object for "+toString(_id));
|
---|
| 233 | MoleculesinSceneMap.insert( make_pair(_id, molObject) );
|
---|
[9c259e] | 234 |
|
---|
[b3a33d] | 235 | // now handle all state changes that came up before the instantiation
|
---|
[73b13c] | 236 | while (MoleculeMissedStateMap.count(_id) != 0) {
|
---|
[9c259e] | 237 | ASSERT( !MoleculeMissedStateMap[_id].empty(),
|
---|
| 238 | "GLWorldScene::moleculeInserted() - we have an empty state change map for molecule with id "
|
---|
| 239 | +toString(_id));
|
---|
[73b13c] | 240 | boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
|
---|
[9c259e] | 241 | for (StateChangeMap_t::iterator iter = MoleculeMissedStateMap[_id].begin();
|
---|
| 242 | !MoleculeMissedStateMap[_id].empty();
|
---|
| 243 | iter = MoleculeMissedStateMap[_id].begin()) {
|
---|
| 244 | std::pair<StateChangeMap_t::iterator, StateChangeMap_t::iterator> rangeiter =
|
---|
| 245 | MoleculeMissedStateMap[_id].equal_range(iter->first);
|
---|
| 246 | const size_t StateCounts = std::distance(rangeiter.first, rangeiter.second);
|
---|
| 247 | if (StateCounts > 1) {
|
---|
| 248 | // more than one state change, have to combine
|
---|
| 249 | typedef std::map<StateChangeType, size_t> StateChangeAmounts_t;
|
---|
| 250 | StateChangeAmounts_t StateChangeAmounts;
|
---|
| 251 | for (StateChangeMap_t::const_iterator stateiter = rangeiter.first;
|
---|
| 252 | stateiter != rangeiter.second; ++stateiter)
|
---|
| 253 | ++StateChangeAmounts[stateiter->second];
|
---|
| 254 | ASSERT( StateChangeAmounts[atomInsertedState] >= StateChangeAmounts[atomRemovedState],
|
---|
| 255 | "GLWorldScene::moleculeInserted() - more atomRemoved states than atomInserted for atom "
|
---|
| 256 | +toString(iter->first));
|
---|
[73b13c] | 257 | if (StateChangeAmounts[atomInsertedState] > StateChangeAmounts[atomRemovedState]) {
|
---|
| 258 | LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
|
---|
[9c259e] | 259 | QMetaObject::invokeMethod(molObject, // pointer to a QObject
|
---|
| 260 | "atomInserted", // member name (no parameters here)
|
---|
[8d5fbf1] | 261 | Qt::QueuedConnection, // connection type
|
---|
[9c259e] | 262 | Q_ARG(const atomId_t, iter->first)); // parameters
|
---|
[73b13c] | 263 | } else {
|
---|
| 264 | LOG(1, "INFO: Atom " << iter->first << " has been inserted and removed already.");
|
---|
| 265 | }
|
---|
[9c259e] | 266 | } else {
|
---|
| 267 | // can only be an insertion
|
---|
| 268 | switch (rangeiter.first->second) {
|
---|
| 269 | case atomRemovedState:
|
---|
| 270 | ASSERT( 0,
|
---|
| 271 | "GLWorldScene::moleculeInserted() - atomRemoved state without atomInserted for atom "
|
---|
| 272 | +toString(iter->first));
|
---|
| 273 | break;
|
---|
| 274 | case atomInsertedState:
|
---|
[73b13c] | 275 | LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
|
---|
[9c259e] | 276 | QMetaObject::invokeMethod(molObject, // pointer to a QObject
|
---|
| 277 | "atomInserted", // member name (no parameters here)
|
---|
[8d5fbf1] | 278 | Qt::QueuedConnection, // connection type
|
---|
[9c259e] | 279 | Q_ARG(const atomId_t, iter->first)); // parameters
|
---|
| 280 | break;
|
---|
| 281 | default:
|
---|
| 282 | ASSERT( 0,
|
---|
| 283 | "GLWorldScene::moleculeInserted() - there are unknown change states.");
|
---|
| 284 | break;
|
---|
| 285 | }
|
---|
| 286 | }
|
---|
| 287 | // removed state changes for this atom
|
---|
| 288 | MoleculeMissedStateMap[_id].erase(iter);
|
---|
| 289 | }
|
---|
| 290 | // remove state change map for the molecule
|
---|
| 291 | MoleculeMissedStateMap.erase(_id);
|
---|
| 292 | }
|
---|
| 293 |
|
---|
[704d59] | 294 | connect (molObject, SIGNAL(changed()), this, SIGNAL(changed()));
|
---|
| 295 | connect (molObject, SIGNAL(changeOccured()), this, SIGNAL(changeOccured()));
|
---|
| 296 | connect (molObject, SIGNAL(atomClicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
|
---|
| 297 | connect (molObject, SIGNAL(moleculeClicked(moleculeId_t)), this, SLOT(moleculeClicked(moleculeId_t)));
|
---|
| 298 | connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
|
---|
| 299 | connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
|
---|
| 300 | connect (molObject, SIGNAL(hoverChanged(const atomId_t)), this, SIGNAL(hoverChanged(const atomId_t)));
|
---|
| 301 | connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
|
---|
[7c7c4a] | 302 | connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
|
---|
[9c259e] | 303 |
|
---|
[704d59] | 304 | emit changed();
|
---|
| 305 | emit changeOccured();
|
---|
[c67518] | 306 | }
|
---|
| 307 |
|
---|
[7cf0eb] | 308 | /** Removes a molecule from the scene.
|
---|
| 309 | *
|
---|
| 310 | * @param _id id of molecule to remove
|
---|
| 311 | */
|
---|
| 312 | void GLWorldScene::moleculeRemoved(const moleculeId_t _id)
|
---|
| 313 | {
|
---|
[026bef] | 314 | LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_id)+".");
|
---|
[7c7c4a] | 315 |
|
---|
[7cf0eb] | 316 | boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
|
---|
| 317 |
|
---|
| 318 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_id);
|
---|
[7c7c4a] | 319 | if ( iter == MoleculesinSceneMap.end()) {
|
---|
| 320 | RemovalMolecules.insert(_id);
|
---|
| 321 | } else {
|
---|
| 322 | LOG(1, "DEBUG: Removing GLMoleculeObject_molecule to id " << _id);
|
---|
| 323 | GLMoleculeObject_molecule *molObject = iter->second;
|
---|
| 324 | molObject->disconnect();
|
---|
| 325 | MoleculesinSceneMap.erase(iter);
|
---|
| 326 | delete molObject;
|
---|
| 327 | }
|
---|
[9c259e] | 328 |
|
---|
| 329 | // remove any possible state changes left
|
---|
[73b13c] | 330 | {
|
---|
| 331 | boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
|
---|
| 332 | MoleculeMissedStateMap.erase(_id);
|
---|
| 333 | }
|
---|
[9c259e] | 334 |
|
---|
[7cf0eb] | 335 | emit changed();
|
---|
| 336 | emit changeOccured();
|
---|
[ce4126] | 337 | }
|
---|
| 338 |
|
---|
[15c8a9] | 339 | void GLWorldScene::moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid)
|
---|
| 340 | {
|
---|
| 341 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_oldid);
|
---|
| 342 | if ( iter == MoleculesinSceneMap.end()) {
|
---|
| 343 | RemovalMolecule_t::iterator removeiter =
|
---|
| 344 | RemovalMolecules.find(_oldid);
|
---|
| 345 | ASSERT( removeiter != RemovalMolecules.end(),
|
---|
| 346 | "GLWorldScene::moleculeIndexChanged() - cannot find id "+toString(_oldid)+" in any map.");
|
---|
| 347 | RemovalMolecules.erase(removeiter);
|
---|
| 348 | RemovalMolecules.insert(_newid);
|
---|
| 349 | } else {
|
---|
| 350 | LOG(1, "DEBUG: Changing GLMoleculeObject_molecule from " << _oldid << " to id " << _newid);
|
---|
| 351 | GLMoleculeObject_molecule* molObject = iter->second;
|
---|
| 352 | MoleculesinSceneMap.erase(iter);
|
---|
| 353 | MoleculesinSceneMap.insert(
|
---|
| 354 | std::make_pair( _newid, molObject) );
|
---|
| 355 | }
|
---|
| 356 | }
|
---|
| 357 |
|
---|
[739ee9] | 358 | void GLWorldScene::moleculesVisibilityChanged(const moleculeId_t _id, bool _visible)
|
---|
| 359 | {
|
---|
[7c7c4a] | 360 | boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
|
---|
[739ee9] | 361 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_id);
|
---|
| 362 | ASSERT( iter != MoleculesinSceneMap.end(),
|
---|
| 363 | "GLWorldScene::moleculeInserted() - molecule's id "+toString(_id)+" is unknown.");
|
---|
| 364 |
|
---|
| 365 | GLMoleculeObject_molecule *molObject = iter->second;
|
---|
| 366 | molObject->setVisible(_visible);
|
---|
| 367 |
|
---|
| 368 | emit changed();
|
---|
| 369 | emit changeOccured();
|
---|
| 370 | }
|
---|
| 371 |
|
---|
[f75491] | 372 | /** Adds a shape to the scene.
|
---|
[4d6662] | 373 | *
|
---|
[f75491] | 374 | */
|
---|
[07136a] | 375 | void GLWorldScene::addShape(const std::string &_name)
|
---|
[f75491] | 376 | {
|
---|
[07136a] | 377 | Shape * const shape = ShapeRegistry::getInstance().getByName(_name);
|
---|
| 378 | if (shape != NULL) {
|
---|
| 379 | GLMoleculeObject_shape *shapeObject = new GLMoleculeObject_shape(*shape, this);
|
---|
| 380 | ShapeNodeMap::iterator iter = ShapesinSceneMap.find(_name);
|
---|
| 381 | ASSERT(iter == ShapesinSceneMap.end(),
|
---|
| 382 | "GLWorldScene::addShape() - same shape "+_name+" added again.");
|
---|
| 383 | ShapesinSceneMap.insert( make_pair(_name, shapeObject) );
|
---|
| 384 | } else
|
---|
| 385 | ELOG(2, "GLWorldScene::addShape() - shape disappeared before we could draw it.");
|
---|
| 386 |
|
---|
| 387 | emit changed();
|
---|
[284551] | 388 | }
|
---|
| 389 |
|
---|
[07136a] | 390 | void GLWorldScene::removeShape(const std::string &_name)
|
---|
[85c36d] | 391 | {
|
---|
[07136a] | 392 | ShapeNodeMap::iterator iter = ShapesinSceneMap.find(_name);
|
---|
[ba6b5c] | 393 | ASSERT(iter != ShapesinSceneMap.end(),
|
---|
[07136a] | 394 | "GLWorldScene::removeShape() - shape "+_name+" not in scene.");
|
---|
[148dde0] | 395 | ShapesinSceneMap.erase(iter);
|
---|
[85c36d] | 396 | delete(iter->second);
|
---|
[07136a] | 397 |
|
---|
| 398 | emit changed();
|
---|
[85c36d] | 399 | }
|
---|
| 400 |
|
---|
| 401 | void GLWorldScene::updateSelectedShapes()
|
---|
[284551] | 402 | {
|
---|
| 403 | foreach (QObject *obj, children()) {
|
---|
| 404 | GLMoleculeObject_shape *shapeobj = qobject_cast<GLMoleculeObject_shape *>(obj);
|
---|
[85c36d] | 405 | if (shapeobj){
|
---|
| 406 | shapeobj->enable(ShapeRegistry::getInstance().isSelected(shapeobj->getShape()));
|
---|
| 407 | }
|
---|
[284551] | 408 | }
|
---|
[07136a] | 409 |
|
---|
| 410 | emit changed();
|
---|
[f75491] | 411 | }
|
---|
| 412 |
|
---|
[7188b1] | 413 | void GLWorldScene::initialize(QGLView *view, QGLPainter *painter) const
|
---|
| 414 | {
|
---|
| 415 | // Initialize all of the mesh objects that we have as children.
|
---|
| 416 | foreach (QObject *obj, children()) {
|
---|
| 417 | GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
|
---|
| 418 | if (meshobj)
|
---|
| 419 | meshobj->initialize(view, painter);
|
---|
| 420 | }
|
---|
| 421 | }
|
---|
| 422 |
|
---|
[72a4c1] | 423 | void GLWorldScene::draw(QGLPainter *painter, const QVector4D &cameraPlane) const
|
---|
[7188b1] | 424 | {
|
---|
| 425 | // Draw all of the mesh objects that we have as children.
|
---|
| 426 | foreach (QObject *obj, children()) {
|
---|
| 427 | GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
|
---|
| 428 | if (meshobj)
|
---|
[72a4c1] | 429 | meshobj->draw(painter, cameraPlane);
|
---|
[7188b1] | 430 | }
|
---|
[907636] | 431 | }
|
---|
[06ebf5] | 432 |
|
---|
[6966b7] | 433 | void GLWorldScene::setSelectionMode(SelectionModeType mode)
|
---|
| 434 | {
|
---|
| 435 | selectionMode = mode;
|
---|
| 436 | // TODO send update to toolbar
|
---|
| 437 | }
|
---|
| 438 |
|
---|
| 439 | void GLWorldScene::setSelectionModeAtom()
|
---|
| 440 | {
|
---|
| 441 | setSelectionMode(SelectAtom);
|
---|
| 442 | }
|
---|
| 443 |
|
---|
| 444 | void GLWorldScene::setSelectionModeMolecule()
|
---|
| 445 | {
|
---|
| 446 | setSelectionMode(SelectMolecule);
|
---|
| 447 | }
|
---|
[20f9b5] | 448 |
|
---|
| 449 | void GLWorldScene::changeMoleculeId(
|
---|
| 450 | GLMoleculeObject_molecule *ob,
|
---|
| 451 | const moleculeId_t oldId,
|
---|
| 452 | const moleculeId_t newId)
|
---|
| 453 | {
|
---|
| 454 | LOG(3, "INFO: GLWorldScene - change molecule id " << oldId << " to " << newId << ".");
|
---|
| 455 |
|
---|
| 456 | {
|
---|
[7c7c4a] | 457 | boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
|
---|
[20f9b5] | 458 | // Remove from map.
|
---|
| 459 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(oldId);
|
---|
| 460 | ASSERT(iter != MoleculesinSceneMap.end(),
|
---|
| 461 | "GLWorldScene::changeMoleculeId() - molecule with old id "+toString(oldId)+" not on display.");
|
---|
| 462 | ASSERT(iter->second == ob,
|
---|
| 463 | "GLWorldScene::changeMoleculeId() - molecule with id "
|
---|
| 464 | +toString(oldId)+" does not match with object in MoleculesinSceneMap.");
|
---|
| 465 | MoleculesinSceneMap.erase(iter);
|
---|
| 466 |
|
---|
| 467 | // Reinsert with new id.
|
---|
| 468 | {
|
---|
| 469 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(newId);
|
---|
| 470 | ASSERT(iter == MoleculesinSceneMap.end(),
|
---|
| 471 | "GLWorldScene::changeMoleculeId() - moleculewith new id "+toString(newId)+" already known.");
|
---|
| 472 | }
|
---|
| 473 | MoleculesinSceneMap.insert( make_pair(newId, ob) );
|
---|
| 474 | }
|
---|
| 475 |
|
---|
| 476 | {
|
---|
[7c7c4a] | 477 | boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
|
---|
[20f9b5] | 478 | // Remove and re-insert from map if present.
|
---|
| 479 | MoleculeMissedStateMap_t::iterator iter = MoleculeMissedStateMap.find(oldId);
|
---|
| 480 | if (iter != MoleculeMissedStateMap.end()) {
|
---|
| 481 | StateChangeMap_t changemap = iter->second;
|
---|
| 482 | MoleculeMissedStateMap.erase(iter);
|
---|
| 483 | MoleculeMissedStateMap.insert( std::make_pair(newId, changemap) );
|
---|
| 484 | }
|
---|
| 485 | }
|
---|
| 486 | }
|
---|
[015f8c] | 487 |
|
---|