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