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