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