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