[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()) {
|
---|
[9c259e] | 168 | // pass signal through
|
---|
[8d5fbf1] | 169 | GLMoleculeObject_molecule *molObject = moliter->second;
|
---|
| 170 | QMetaObject::invokeMethod(molObject, // pointer to a QObject
|
---|
| 171 | "atomInserted", // member name (no parameters here)
|
---|
| 172 | Qt::QueuedConnection, // connection type
|
---|
| 173 | Q_ARG(const atomId_t, _atomid)); // parameters
|
---|
[9c259e] | 174 | } else {
|
---|
| 175 | // store signal for when it is instantiated
|
---|
| 176 | if (MoleculeMissedStateMap.count(_molid) == 0)
|
---|
| 177 | MoleculeMissedStateMap.insert( std::make_pair(_molid ,StateChangeMap_t()) );
|
---|
| 178 | MoleculeMissedStateMap[_molid].insert( std::make_pair(_atomid, atomInsertedState) );
|
---|
| 179 | }
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | /** Removes an atom into the scene before molecule is present.
|
---|
| 183 | *
|
---|
| 184 | * @param _molid molecule to insert atom for
|
---|
| 185 | * @param _atomid atom to insert
|
---|
| 186 | */
|
---|
| 187 | void GLWorldScene::atomRemoved(const moleculeId_t _molid, const atomId_t _atomid)
|
---|
| 188 | {
|
---|
| 189 | LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atomid)+".");
|
---|
| 190 |
|
---|
[73b13c] | 191 | boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
|
---|
| 192 |
|
---|
[9c259e] | 193 | // check of molecule is already present
|
---|
[8d5fbf1] | 194 | MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(_molid);
|
---|
| 195 | if (moliter != MoleculesinSceneMap.end()) {
|
---|
[9c259e] | 196 | // pass signal through
|
---|
[8d5fbf1] | 197 | GLMoleculeObject_molecule *molObject = moliter->second;
|
---|
| 198 | QMetaObject::invokeMethod(molObject, // pointer to a QObject
|
---|
| 199 | "atomRemoved", // member name (no parameters here)
|
---|
| 200 | Qt::QueuedConnection, // connection type
|
---|
| 201 | Q_ARG(const atomId_t, _atomid)); // parameters
|
---|
[9c259e] | 202 | } else {
|
---|
| 203 | // store signal for when it is instantiated
|
---|
| 204 | if (MoleculeMissedStateMap.count(_molid) == 0)
|
---|
| 205 | MoleculeMissedStateMap.insert( std::make_pair(_molid ,StateChangeMap_t()) );
|
---|
| 206 | MoleculeMissedStateMap[_molid].insert( std::make_pair(_atomid, atomRemovedState) );
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
| 209 |
|
---|
[026bef] | 210 | /** Inserts a molecule into the scene.
|
---|
[c67518] | 211 | *
|
---|
[8c001a] | 212 | * @param _mol molecule to insert
|
---|
[c67518] | 213 | */
|
---|
[026bef] | 214 | void GLWorldScene::moleculeInserted(const moleculeId_t _id)
|
---|
[c67518] | 215 | {
|
---|
[026bef] | 216 | LOG(3, "INFO: GLWorldScene: Received signal moleculeInserted for molecule "+toString(_id)+".");
|
---|
[7cf0eb] | 217 |
|
---|
| 218 | boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
|
---|
| 219 |
|
---|
[ef3013] | 220 | MoleculeNodeMap::const_iterator iter = MoleculesinSceneMap.find(_id);
|
---|
[8c001a] | 221 | ASSERT( iter == MoleculesinSceneMap.end(),
|
---|
[ef3013] | 222 | "GLWorldScene::moleculeInserted() - molecule's id "+toString(_id)+" already present.");
|
---|
[8c001a] | 223 |
|
---|
[20f9b5] | 224 | // check whether molecule is still present
|
---|
| 225 | if (RemovalMolecules.count(_id) != 0) {
|
---|
| 226 | RemovalMolecules.erase(_id);
|
---|
| 227 | return;
|
---|
| 228 | }
|
---|
[7cf0eb] | 229 | if (const_cast<const World &>(World::getInstance()).getMolecule(MoleculeById(_id)) == NULL) {
|
---|
| 230 | ELOG(2, "Molecule with id " << _id << " has disappeared.");
|
---|
[20f9b5] | 231 | return;
|
---|
[7cf0eb] | 232 | }
|
---|
[20f9b5] | 233 |
|
---|
[8c001a] | 234 | // add new object
|
---|
[7c7c4a] | 235 | LOG(1, "DEBUG: Adding GLMoleculeObject_molecule to id " << _id);
|
---|
[b3a33d] | 236 | GLMoleculeObject_molecule *molObject =
|
---|
[026bef] | 237 | new GLMoleculeObject_molecule(
|
---|
[8d5fbf1] | 238 | GLMoleculeObject::meshEmpty,
|
---|
| 239 | this,
|
---|
| 240 | _id,
|
---|
| 241 | board,
|
---|
| 242 | board->getMoleculeObservedValues(_id));
|
---|
[704d59] | 243 | ASSERT( molObject != NULL,
|
---|
| 244 | "GLWorldScene::moleculeInserted - could not create molecule object for "+toString(_id));
|
---|
| 245 | MoleculesinSceneMap.insert( make_pair(_id, molObject) );
|
---|
[9c259e] | 246 |
|
---|
[b3a33d] | 247 | // now handle all state changes that came up before the instantiation
|
---|
[73b13c] | 248 | while (MoleculeMissedStateMap.count(_id) != 0) {
|
---|
[9c259e] | 249 | ASSERT( !MoleculeMissedStateMap[_id].empty(),
|
---|
| 250 | "GLWorldScene::moleculeInserted() - we have an empty state change map for molecule with id "
|
---|
| 251 | +toString(_id));
|
---|
[73b13c] | 252 | boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
|
---|
[9c259e] | 253 | for (StateChangeMap_t::iterator iter = MoleculeMissedStateMap[_id].begin();
|
---|
| 254 | !MoleculeMissedStateMap[_id].empty();
|
---|
| 255 | iter = MoleculeMissedStateMap[_id].begin()) {
|
---|
| 256 | std::pair<StateChangeMap_t::iterator, StateChangeMap_t::iterator> rangeiter =
|
---|
| 257 | MoleculeMissedStateMap[_id].equal_range(iter->first);
|
---|
| 258 | const size_t StateCounts = std::distance(rangeiter.first, rangeiter.second);
|
---|
| 259 | if (StateCounts > 1) {
|
---|
| 260 | // more than one state change, have to combine
|
---|
| 261 | typedef std::map<StateChangeType, size_t> StateChangeAmounts_t;
|
---|
| 262 | StateChangeAmounts_t StateChangeAmounts;
|
---|
| 263 | for (StateChangeMap_t::const_iterator stateiter = rangeiter.first;
|
---|
| 264 | stateiter != rangeiter.second; ++stateiter)
|
---|
| 265 | ++StateChangeAmounts[stateiter->second];
|
---|
| 266 | ASSERT( StateChangeAmounts[atomInsertedState] >= StateChangeAmounts[atomRemovedState],
|
---|
| 267 | "GLWorldScene::moleculeInserted() - more atomRemoved states than atomInserted for atom "
|
---|
| 268 | +toString(iter->first));
|
---|
[73b13c] | 269 | if (StateChangeAmounts[atomInsertedState] > StateChangeAmounts[atomRemovedState]) {
|
---|
| 270 | LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
|
---|
[9c259e] | 271 | QMetaObject::invokeMethod(molObject, // pointer to a QObject
|
---|
| 272 | "atomInserted", // member name (no parameters here)
|
---|
[8d5fbf1] | 273 | Qt::QueuedConnection, // connection type
|
---|
[9c259e] | 274 | Q_ARG(const atomId_t, iter->first)); // parameters
|
---|
[73b13c] | 275 | } else {
|
---|
| 276 | LOG(1, "INFO: Atom " << iter->first << " has been inserted and removed already.");
|
---|
| 277 | }
|
---|
[9c259e] | 278 | } else {
|
---|
| 279 | // can only be an insertion
|
---|
| 280 | switch (rangeiter.first->second) {
|
---|
| 281 | case atomRemovedState:
|
---|
| 282 | ASSERT( 0,
|
---|
| 283 | "GLWorldScene::moleculeInserted() - atomRemoved state without atomInserted for atom "
|
---|
| 284 | +toString(iter->first));
|
---|
| 285 | break;
|
---|
| 286 | case atomInsertedState:
|
---|
[73b13c] | 287 | LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
|
---|
[9c259e] | 288 | QMetaObject::invokeMethod(molObject, // pointer to a QObject
|
---|
| 289 | "atomInserted", // member name (no parameters here)
|
---|
[8d5fbf1] | 290 | Qt::QueuedConnection, // connection type
|
---|
[9c259e] | 291 | Q_ARG(const atomId_t, iter->first)); // parameters
|
---|
| 292 | break;
|
---|
| 293 | default:
|
---|
| 294 | ASSERT( 0,
|
---|
| 295 | "GLWorldScene::moleculeInserted() - there are unknown change states.");
|
---|
| 296 | break;
|
---|
| 297 | }
|
---|
| 298 | }
|
---|
| 299 | // removed state changes for this atom
|
---|
| 300 | MoleculeMissedStateMap[_id].erase(iter);
|
---|
| 301 | }
|
---|
| 302 | // remove state change map for the molecule
|
---|
| 303 | MoleculeMissedStateMap.erase(_id);
|
---|
| 304 | }
|
---|
| 305 |
|
---|
[704d59] | 306 | connect (molObject, SIGNAL(changed()), this, SIGNAL(changed()));
|
---|
| 307 | connect (molObject, SIGNAL(changeOccured()), this, SIGNAL(changeOccured()));
|
---|
| 308 | connect (molObject, SIGNAL(atomClicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
|
---|
| 309 | connect (molObject, SIGNAL(moleculeClicked(moleculeId_t)), this, SLOT(moleculeClicked(moleculeId_t)));
|
---|
| 310 | connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
|
---|
| 311 | connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
|
---|
| 312 | connect (molObject, SIGNAL(hoverChanged(const atomId_t)), this, SIGNAL(hoverChanged(const atomId_t)));
|
---|
| 313 | connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
|
---|
[7c7c4a] | 314 | connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
|
---|
[9c259e] | 315 |
|
---|
[704d59] | 316 | emit changed();
|
---|
| 317 | emit changeOccured();
|
---|
[c67518] | 318 | }
|
---|
| 319 |
|
---|
[7cf0eb] | 320 | /** Removes a molecule from the scene.
|
---|
| 321 | *
|
---|
| 322 | * @param _id id of molecule to remove
|
---|
| 323 | */
|
---|
| 324 | void GLWorldScene::moleculeRemoved(const moleculeId_t _id)
|
---|
| 325 | {
|
---|
[026bef] | 326 | LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_id)+".");
|
---|
[7c7c4a] | 327 |
|
---|
[7cf0eb] | 328 | boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
|
---|
| 329 |
|
---|
| 330 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_id);
|
---|
[7c7c4a] | 331 | if ( iter == MoleculesinSceneMap.end()) {
|
---|
| 332 | RemovalMolecules.insert(_id);
|
---|
| 333 | } else {
|
---|
| 334 | LOG(1, "DEBUG: Removing GLMoleculeObject_molecule to id " << _id);
|
---|
| 335 | GLMoleculeObject_molecule *molObject = iter->second;
|
---|
| 336 | molObject->disconnect();
|
---|
| 337 | MoleculesinSceneMap.erase(iter);
|
---|
| 338 | delete molObject;
|
---|
| 339 | }
|
---|
[9c259e] | 340 |
|
---|
| 341 | // remove any possible state changes left
|
---|
[73b13c] | 342 | {
|
---|
| 343 | boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
|
---|
| 344 | MoleculeMissedStateMap.erase(_id);
|
---|
| 345 | }
|
---|
[9c259e] | 346 |
|
---|
[7cf0eb] | 347 | emit changed();
|
---|
| 348 | emit changeOccured();
|
---|
[ce4126] | 349 | }
|
---|
| 350 |
|
---|
[15c8a9] | 351 | void GLWorldScene::moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid)
|
---|
| 352 | {
|
---|
| 353 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_oldid);
|
---|
| 354 | if ( iter == MoleculesinSceneMap.end()) {
|
---|
| 355 | RemovalMolecule_t::iterator removeiter =
|
---|
| 356 | RemovalMolecules.find(_oldid);
|
---|
| 357 | ASSERT( removeiter != RemovalMolecules.end(),
|
---|
| 358 | "GLWorldScene::moleculeIndexChanged() - cannot find id "+toString(_oldid)+" in any map.");
|
---|
| 359 | RemovalMolecules.erase(removeiter);
|
---|
| 360 | RemovalMolecules.insert(_newid);
|
---|
| 361 | } else {
|
---|
| 362 | LOG(1, "DEBUG: Changing GLMoleculeObject_molecule from " << _oldid << " to id " << _newid);
|
---|
| 363 | GLMoleculeObject_molecule* molObject = iter->second;
|
---|
| 364 | MoleculesinSceneMap.erase(iter);
|
---|
| 365 | MoleculesinSceneMap.insert(
|
---|
| 366 | std::make_pair( _newid, molObject) );
|
---|
| 367 | }
|
---|
| 368 | }
|
---|
| 369 |
|
---|
[739ee9] | 370 | void GLWorldScene::moleculesVisibilityChanged(const moleculeId_t _id, bool _visible)
|
---|
| 371 | {
|
---|
[7c7c4a] | 372 | boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
|
---|
[739ee9] | 373 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_id);
|
---|
| 374 | ASSERT( iter != MoleculesinSceneMap.end(),
|
---|
| 375 | "GLWorldScene::moleculeInserted() - molecule's id "+toString(_id)+" is unknown.");
|
---|
| 376 |
|
---|
| 377 | GLMoleculeObject_molecule *molObject = iter->second;
|
---|
| 378 | molObject->setVisible(_visible);
|
---|
| 379 |
|
---|
| 380 | emit changed();
|
---|
| 381 | emit changeOccured();
|
---|
| 382 | }
|
---|
| 383 |
|
---|
[f75491] | 384 | /** Adds a shape to the scene.
|
---|
[4d6662] | 385 | *
|
---|
[f75491] | 386 | */
|
---|
[07136a] | 387 | void GLWorldScene::addShape(const std::string &_name)
|
---|
[f75491] | 388 | {
|
---|
[07136a] | 389 | Shape * const shape = ShapeRegistry::getInstance().getByName(_name);
|
---|
| 390 | if (shape != NULL) {
|
---|
| 391 | GLMoleculeObject_shape *shapeObject = new GLMoleculeObject_shape(*shape, this);
|
---|
| 392 | ShapeNodeMap::iterator iter = ShapesinSceneMap.find(_name);
|
---|
| 393 | ASSERT(iter == ShapesinSceneMap.end(),
|
---|
| 394 | "GLWorldScene::addShape() - same shape "+_name+" added again.");
|
---|
| 395 | ShapesinSceneMap.insert( make_pair(_name, shapeObject) );
|
---|
| 396 | } else
|
---|
| 397 | ELOG(2, "GLWorldScene::addShape() - shape disappeared before we could draw it.");
|
---|
| 398 |
|
---|
| 399 | emit changed();
|
---|
[284551] | 400 | }
|
---|
| 401 |
|
---|
[07136a] | 402 | void GLWorldScene::removeShape(const std::string &_name)
|
---|
[85c36d] | 403 | {
|
---|
[07136a] | 404 | ShapeNodeMap::iterator iter = ShapesinSceneMap.find(_name);
|
---|
[ba6b5c] | 405 | ASSERT(iter != ShapesinSceneMap.end(),
|
---|
[07136a] | 406 | "GLWorldScene::removeShape() - shape "+_name+" not in scene.");
|
---|
[148dde0] | 407 | ShapesinSceneMap.erase(iter);
|
---|
[85c36d] | 408 | delete(iter->second);
|
---|
[07136a] | 409 |
|
---|
| 410 | emit changed();
|
---|
[85c36d] | 411 | }
|
---|
| 412 |
|
---|
| 413 | void GLWorldScene::updateSelectedShapes()
|
---|
[284551] | 414 | {
|
---|
| 415 | foreach (QObject *obj, children()) {
|
---|
| 416 | GLMoleculeObject_shape *shapeobj = qobject_cast<GLMoleculeObject_shape *>(obj);
|
---|
[85c36d] | 417 | if (shapeobj){
|
---|
| 418 | shapeobj->enable(ShapeRegistry::getInstance().isSelected(shapeobj->getShape()));
|
---|
| 419 | }
|
---|
[284551] | 420 | }
|
---|
[07136a] | 421 |
|
---|
| 422 | emit changed();
|
---|
[f75491] | 423 | }
|
---|
| 424 |
|
---|
[7188b1] | 425 | void GLWorldScene::initialize(QGLView *view, QGLPainter *painter) const
|
---|
| 426 | {
|
---|
| 427 | // Initialize all of the mesh objects that we have as children.
|
---|
| 428 | foreach (QObject *obj, children()) {
|
---|
| 429 | GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
|
---|
| 430 | if (meshobj)
|
---|
| 431 | meshobj->initialize(view, painter);
|
---|
| 432 | }
|
---|
| 433 | }
|
---|
| 434 |
|
---|
[72a4c1] | 435 | void GLWorldScene::draw(QGLPainter *painter, const QVector4D &cameraPlane) const
|
---|
[7188b1] | 436 | {
|
---|
| 437 | // Draw all of the mesh objects that we have as children.
|
---|
| 438 | foreach (QObject *obj, children()) {
|
---|
| 439 | GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
|
---|
| 440 | if (meshobj)
|
---|
[72a4c1] | 441 | meshobj->draw(painter, cameraPlane);
|
---|
[7188b1] | 442 | }
|
---|
[907636] | 443 | }
|
---|
[06ebf5] | 444 |
|
---|
[6966b7] | 445 | void GLWorldScene::setSelectionMode(SelectionModeType mode)
|
---|
| 446 | {
|
---|
| 447 | selectionMode = mode;
|
---|
| 448 | // TODO send update to toolbar
|
---|
| 449 | }
|
---|
| 450 |
|
---|
[015f8c] | 451 | void GLWorldScene::setSelectionChangedAgent(QtSelectionChangedAgent *agent)
|
---|
| 452 | {
|
---|
| 453 | connect(agent, SIGNAL(atomSelected(const moleculeId_t, const atomId_t)),
|
---|
| 454 | this, SLOT(AtomSelected(const moleculeId_t, const atomId_t)));
|
---|
| 455 | connect(agent, SIGNAL(atomUnselected(const moleculeId_t, const atomId_t)),
|
---|
| 456 | this, SLOT(AtomUnselected(const moleculeId_t, const atomId_t)));
|
---|
| 457 |
|
---|
| 458 | connect(agent, SIGNAL(moleculeSelected(const moleculeId_t)),
|
---|
| 459 | this, SLOT(MoleculeSelected(const moleculeId_t)));
|
---|
| 460 | connect(agent, SIGNAL(moleculeUnselected(const moleculeId_t)),
|
---|
| 461 | this, SLOT(MoleculeUnselected(const moleculeId_t)));
|
---|
| 462 | }
|
---|
| 463 |
|
---|
[6966b7] | 464 | void GLWorldScene::setSelectionModeAtom()
|
---|
| 465 | {
|
---|
| 466 | setSelectionMode(SelectAtom);
|
---|
| 467 | }
|
---|
| 468 |
|
---|
| 469 | void GLWorldScene::setSelectionModeMolecule()
|
---|
| 470 | {
|
---|
| 471 | setSelectionMode(SelectMolecule);
|
---|
| 472 | }
|
---|
[20f9b5] | 473 |
|
---|
| 474 | void GLWorldScene::changeMoleculeId(
|
---|
| 475 | GLMoleculeObject_molecule *ob,
|
---|
| 476 | const moleculeId_t oldId,
|
---|
| 477 | const moleculeId_t newId)
|
---|
| 478 | {
|
---|
| 479 | LOG(3, "INFO: GLWorldScene - change molecule id " << oldId << " to " << newId << ".");
|
---|
| 480 |
|
---|
| 481 | {
|
---|
[7c7c4a] | 482 | boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
|
---|
[20f9b5] | 483 | // Remove from map.
|
---|
| 484 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(oldId);
|
---|
| 485 | ASSERT(iter != MoleculesinSceneMap.end(),
|
---|
| 486 | "GLWorldScene::changeMoleculeId() - molecule with old id "+toString(oldId)+" not on display.");
|
---|
| 487 | ASSERT(iter->second == ob,
|
---|
| 488 | "GLWorldScene::changeMoleculeId() - molecule with id "
|
---|
| 489 | +toString(oldId)+" does not match with object in MoleculesinSceneMap.");
|
---|
| 490 | MoleculesinSceneMap.erase(iter);
|
---|
| 491 |
|
---|
| 492 | // Reinsert with new id.
|
---|
| 493 | {
|
---|
| 494 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(newId);
|
---|
| 495 | ASSERT(iter == MoleculesinSceneMap.end(),
|
---|
| 496 | "GLWorldScene::changeMoleculeId() - moleculewith new id "+toString(newId)+" already known.");
|
---|
| 497 | }
|
---|
| 498 | MoleculesinSceneMap.insert( make_pair(newId, ob) );
|
---|
| 499 | }
|
---|
| 500 |
|
---|
| 501 | {
|
---|
[7c7c4a] | 502 | boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
|
---|
[20f9b5] | 503 | // Remove and re-insert from map if present.
|
---|
| 504 | MoleculeMissedStateMap_t::iterator iter = MoleculeMissedStateMap.find(oldId);
|
---|
| 505 | if (iter != MoleculeMissedStateMap.end()) {
|
---|
| 506 | StateChangeMap_t changemap = iter->second;
|
---|
| 507 | MoleculeMissedStateMap.erase(iter);
|
---|
| 508 | MoleculeMissedStateMap.insert( std::make_pair(newId, changemap) );
|
---|
| 509 | }
|
---|
| 510 | }
|
---|
| 511 | }
|
---|
[015f8c] | 512 |
|
---|
| 513 | void GLWorldScene::AtomSelected(const moleculeId_t _molid, const atomId_t _id)
|
---|
| 514 | {
|
---|
[7c7c4a] | 515 | boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
|
---|
[015f8c] | 516 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molid);
|
---|
[15c8a9] | 517 | // use direct connection as it's lightweight and we avoid index change troubles
|
---|
[a39d72] | 518 | if (iter != MoleculesinSceneMap.end())
|
---|
| 519 | QMetaObject::invokeMethod(iter->second, // pointer to a QObject
|
---|
[015f8c] | 520 | "AtomSelected", // member name (no parameters here)
|
---|
[15c8a9] | 521 | Qt::DirectConnection, // connection type
|
---|
[015f8c] | 522 | Q_ARG(const atomId_t, _id)); // parameters
|
---|
[a39d72] | 523 | else
|
---|
| 524 | ELOG(2, "DEBUG: GLWorldScene::AtomSelected() - molecule " <<
|
---|
| 525 | _molid << " unknown to GLWorldScene.");
|
---|
[015f8c] | 526 | }
|
---|
| 527 |
|
---|
| 528 | void GLWorldScene::AtomUnselected(const moleculeId_t _molid, const atomId_t _id)
|
---|
| 529 | {
|
---|
[7c7c4a] | 530 | boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
|
---|
[015f8c] | 531 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molid);
|
---|
[15c8a9] | 532 | // use direct connection as it's lightweight and we avoid index change troubles
|
---|
[a39d72] | 533 | if (iter != MoleculesinSceneMap.end())
|
---|
| 534 | QMetaObject::invokeMethod(iter->second, // pointer to a QObject
|
---|
[015f8c] | 535 | "AtomUnselected", // member name (no parameters here)
|
---|
[15c8a9] | 536 | Qt::DirectConnection, // connection type
|
---|
[015f8c] | 537 | Q_ARG(const atomId_t, _id)); // parameters
|
---|
[a39d72] | 538 | else
|
---|
| 539 | ELOG(2, "GLWorldScene::AtomUnselected() - molecule "
|
---|
| 540 | << _molid << " unknown to GLWorldScene.");
|
---|
[015f8c] | 541 | }
|
---|
| 542 |
|
---|
| 543 | void GLWorldScene::MoleculeSelected(const moleculeId_t _molid)
|
---|
| 544 | {
|
---|
[7c7c4a] | 545 | boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
|
---|
| 546 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molid);
|
---|
[a39d72] | 547 | if (iter != MoleculesinSceneMap.end())
|
---|
| 548 | QMetaObject::invokeMethod(iter->second, // pointer to a QObject
|
---|
[015f8c] | 549 | "Selected", // member name (no parameters here)
|
---|
| 550 | Qt::QueuedConnection); // connection type
|
---|
[a39d72] | 551 | else
|
---|
| 552 | ELOG(2, "GLWorldScene::MoleculeSelected() - molecule "
|
---|
| 553 | << _molid << " unknown to GLWorldScene.");
|
---|
[015f8c] | 554 | }
|
---|
| 555 |
|
---|
| 556 | void GLWorldScene::MoleculeUnselected(const moleculeId_t _molid)
|
---|
| 557 | {
|
---|
[7c7c4a] | 558 | boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
|
---|
[015f8c] | 559 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molid);
|
---|
[a39d72] | 560 | if (iter != MoleculesinSceneMap.end())
|
---|
| 561 | QMetaObject::invokeMethod(iter->second, // pointer to a QObject
|
---|
[015f8c] | 562 | "Unselected", // member name (no parameters here)
|
---|
| 563 | Qt::QueuedConnection); // connection type
|
---|
[a39d72] | 564 | else
|
---|
| 565 | ELOG(2, "GLWorldScene::MoleculeUnselected() - molecule "
|
---|
| 566 | << _molid << " unknown to GLWorldScene.");
|
---|
[015f8c] | 567 | }
|
---|