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