[907636] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[5aaa43] | 5 | * Copyright (C) 2013 Frederik Heber. All rights reserved.
|
---|
[94d5ac6] | 6 | *
|
---|
| 7 | *
|
---|
| 8 | * This file is part of MoleCuilder.
|
---|
| 9 | *
|
---|
| 10 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
| 11 | * it under the terms of the GNU General Public License as published by
|
---|
| 12 | * the Free Software Foundation, either version 2 of the License, or
|
---|
| 13 | * (at your option) any later version.
|
---|
| 14 | *
|
---|
| 15 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | * GNU General Public License for more details.
|
---|
| 19 | *
|
---|
| 20 | * You should have received a copy of the GNU General Public License
|
---|
| 21 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
[907636] | 22 | */
|
---|
| 23 |
|
---|
| 24 | /*
|
---|
| 25 | * GLWorldScene.cpp
|
---|
| 26 | *
|
---|
| 27 | * This is based on the Qt3D example "teaservice", specifically parts of teaservice.cpp.
|
---|
| 28 | *
|
---|
| 29 | * Created on: Aug 17, 2011
|
---|
| 30 | * Author: heber
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | // include config.h
|
---|
| 34 | #ifdef HAVE_CONFIG_H
|
---|
| 35 | #include <config.h>
|
---|
| 36 | #endif
|
---|
| 37 |
|
---|
| 38 | #include "GLWorldScene.hpp"
|
---|
[d1196d] | 39 | #include <Qt3D/qglview.h>
|
---|
[bca99d] | 40 | #include <Qt3D/qglbuilder.h>
|
---|
| 41 | #include <Qt3D/qglscenenode.h>
|
---|
| 42 | #include <Qt3D/qglsphere.h>
|
---|
| 43 | #include <Qt3D/qglcylinder.h>
|
---|
[907636] | 44 |
|
---|
[015f8c] | 45 | #include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject.hpp"
|
---|
| 46 | #include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp"
|
---|
| 47 | #include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp"
|
---|
| 48 | #include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp"
|
---|
| 49 | #include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_shape.hpp"
|
---|
| 50 |
|
---|
[2f7988] | 51 | #include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
|
---|
[907636] | 52 |
|
---|
| 53 | #include "CodePatterns/MemDebug.hpp"
|
---|
| 54 |
|
---|
[7188b1] | 55 | #include "CodePatterns/Log.hpp"
|
---|
| 56 |
|
---|
[f1b5ca] | 57 | #include <boost/assign.hpp>
|
---|
| 58 |
|
---|
[0e9ffe] | 59 | #include "Actions/SelectionAction/Atoms/AtomByIdAction.hpp"
|
---|
[89643d] | 60 | #include "Actions/SelectionAction/Atoms/NotAtomByIdAction.hpp"
|
---|
[6966b7] | 61 | #include "Actions/SelectionAction/Molecules/MoleculeByIdAction.hpp"
|
---|
| 62 | #include "Actions/SelectionAction/Molecules/NotMoleculeByIdAction.hpp"
|
---|
[6f0841] | 63 | #include "Atom/atom.hpp"
|
---|
[7188b1] | 64 | #include "Bond/bond.hpp"
|
---|
[89643d] | 65 | #include "Descriptors/AtomIdDescriptor.hpp"
|
---|
[8c001a] | 66 | #include "Descriptors/MoleculeIdDescriptor.hpp"
|
---|
[37b2575] | 67 | #include "Helpers/helpers.hpp"
|
---|
[85c36d] | 68 | #include "Shapes/ShapeRegistry.hpp"
|
---|
[907636] | 69 | #include "molecule.hpp"
|
---|
| 70 | #include "World.hpp"
|
---|
| 71 |
|
---|
[2ad1ec] | 72 | #include <iostream>
|
---|
| 73 |
|
---|
[ce7fdc] | 74 | using namespace MoleCuilder;
|
---|
[907636] | 75 |
|
---|
[15c8a9] | 76 | GLWorldScene::GLWorldScene(
|
---|
[2f7988] | 77 | QtObservedInstanceBoard * _board,
|
---|
[15c8a9] | 78 | QObject *parent) :
|
---|
| 79 | QObject(parent),
|
---|
| 80 | selectionMode(SelectAtom),
|
---|
| 81 | board(_board)
|
---|
[907636] | 82 | {
|
---|
[f1b5ca] | 83 | qRegisterMetaType<atomId_t>("atomId_t");
|
---|
| 84 | qRegisterMetaType<GLMoleculeObject_bond::SideOfBond>("GLMoleculeObject_bond::SideOfBond");
|
---|
| 85 |
|
---|
[72a4c1] | 86 | int sphereDetails[] = {5, 3, 2, 0};
|
---|
| 87 | int cylinderDetails[] = {16, 8, 6, 3};
|
---|
| 88 | for (int i=0;i<GLMoleculeObject::DETAILTYPES_MAX;i++){
|
---|
| 89 | QGLBuilder emptyBuilder;
|
---|
[8c001a] | 90 | GLMoleculeObject::meshEmpty[i] = emptyBuilder.finalizedSceneNode();
|
---|
[72a4c1] | 91 | QGLBuilder sphereBuilder;
|
---|
| 92 | sphereBuilder << QGLSphere(2.0, sphereDetails[i]);
|
---|
[8c001a] | 93 | GLMoleculeObject::meshSphere[i] = sphereBuilder.finalizedSceneNode();
|
---|
| 94 | GLMoleculeObject::meshSphere[i]->setOption(QGLSceneNode::CullBoundingBox, true);
|
---|
[72a4c1] | 95 | QGLBuilder cylinderBuilder;
|
---|
| 96 | cylinderBuilder << QGLCylinder(.25,.25,1.0,cylinderDetails[i]);
|
---|
[8c001a] | 97 | GLMoleculeObject::meshCylinder[i] = cylinderBuilder.finalizedSceneNode();
|
---|
| 98 | GLMoleculeObject::meshCylinder[i]->setOption(QGLSceneNode::CullBoundingBox, true);
|
---|
[72a4c1] | 99 | }
|
---|
[1b07b1] | 100 | connect(board, SIGNAL(moleculeInserted(QtObservedMolecule::ptr)),
|
---|
[f1b5ca] | 101 | this, SLOT(moleculeInserted(QtObservedMolecule::ptr)));
|
---|
[f91ef6] | 102 | connect(board, SIGNAL(moleculeRemoved(ObservedValue_Index_t)),
|
---|
[f1b5ca] | 103 | this, SLOT(moleculeRemoved(ObservedValue_Index_t)));
|
---|
[59f1bc] | 104 | connect(board, SIGNAL(atomInserted(QtObservedAtom::ptr)),
|
---|
| 105 | this, SLOT(atomInserted(QtObservedAtom::ptr)));
|
---|
[f91ef6] | 106 | connect(board, SIGNAL(atomRemoved(ObservedValue_Index_t)),
|
---|
| 107 | this, SLOT(atomRemoved(ObservedValue_Index_t)));
|
---|
[96f14a] | 108 | connect(board, SIGNAL(bondInserted(QtObservedBond::ptr)),
|
---|
| 109 | this, SLOT(bondInserted(QtObservedBond::ptr)));
|
---|
| 110 | connect(board, SIGNAL(bondRemoved(ObservedValue_Index_t)),
|
---|
| 111 | this, SLOT(bondRemoved(ObservedValue_Index_t)));
|
---|
[0a6ff9] | 112 |
|
---|
[f714763] | 113 | // connect(this, SIGNAL(updated()), this, SLOT(update()));
|
---|
[907636] | 114 | }
|
---|
| 115 |
|
---|
| 116 | GLWorldScene::~GLWorldScene()
|
---|
[7188b1] | 117 | {
|
---|
| 118 | // remove all elements
|
---|
| 119 | GLMoleculeObject::cleanMaterialMap();
|
---|
| 120 | }
|
---|
[907636] | 121 |
|
---|
[8c001a] | 122 | void GLWorldScene::atomClicked(atomId_t no)
|
---|
| 123 | {
|
---|
| 124 | LOG(3, "INFO: GLMoleculeObject_molecule - atom " << no << " has been clicked.");
|
---|
[f01769] | 125 | const atom * const Walker = const_cast<const World &>(World::getInstance()).
|
---|
| 126 | getAtom(AtomById(no));
|
---|
[369cb1] | 127 | ASSERT( Walker != NULL,
|
---|
| 128 | "GLWorldScene::atomClicked() - clicked atom has disappeared.");
|
---|
[8c001a] | 129 | if (selectionMode == SelectAtom){
|
---|
| 130 | if (!World::getInstance().isSelected(Walker))
|
---|
| 131 | SelectionAtomById(std::vector<atomId_t>(1,no));
|
---|
| 132 | else
|
---|
| 133 | SelectionNotAtomById(std::vector<atomId_t>(1,no));
|
---|
| 134 | }else if (selectionMode == SelectMolecule){
|
---|
| 135 | const molecule *mol = Walker->getMolecule();
|
---|
| 136 | ASSERT(mol, "Atom without molecule has been clicked.");
|
---|
[d7cad1] | 137 | molids_t ids(1, mol->getId());
|
---|
[8c001a] | 138 | if (!World::getInstance().isSelected(mol))
|
---|
[d7cad1] | 139 | SelectionMoleculeById(ids);
|
---|
[8c001a] | 140 | else
|
---|
[d7cad1] | 141 | SelectionNotMoleculeById(ids);
|
---|
[8c001a] | 142 | }
|
---|
| 143 | emit clicked(no);
|
---|
| 144 | }
|
---|
| 145 |
|
---|
[f1b5ca] | 146 | /** Adds an atom to the scene.
|
---|
[59f1bc] | 147 | *
|
---|
[f1b5ca] | 148 | * @param _atom atom to add
|
---|
[9c259e] | 149 | */
|
---|
[1b07b1] | 150 | void GLWorldScene::atomInserted(QtObservedAtom::ptr _atom)
|
---|
[9c259e] | 151 | {
|
---|
[f1b5ca] | 152 | LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "
|
---|
| 153 | << _atom->getAtomIndex());
|
---|
| 154 |
|
---|
| 155 | GLMoleculeObject_atom *atomObject =
|
---|
| 156 | new GLMoleculeObject_atom(
|
---|
| 157 | GLMoleculeObject::meshSphere,
|
---|
| 158 | this, /* parent is GLWorldScene */
|
---|
| 159 | _atom);
|
---|
| 160 | ASSERT( atomObject != NULL,
|
---|
| 161 | "GLWorldScene::atomInserted - could not create atom object for "
|
---|
| 162 | +toString(_atom->getAtomIndex()));
|
---|
[f91ef6] | 163 | const ObservedValue_Index_t atomid = _atom->getIndex();
|
---|
[f1b5ca] | 164 | AtomNodeMap::iterator iter = AtomsinSceneMap.find(atomid);
|
---|
| 165 | ASSERT(iter == AtomsinSceneMap.end(),
|
---|
| 166 | "GLWorldScene::atomInserted - same atom with id "
|
---|
| 167 | +toString(_atom->getAtomIndex())+" added again.");
|
---|
| 168 | AtomsinSceneMap.insert( make_pair(atomid, atomObject) );
|
---|
| 169 |
|
---|
| 170 | connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
|
---|
| 171 | connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed()));
|
---|
| 172 | connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
|
---|
| 173 | connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
|
---|
| 174 |
|
---|
| 175 | emit changed();
|
---|
| 176 | emit changeOccured();
|
---|
[59f1bc] | 177 | }
|
---|
| 178 |
|
---|
[f1b5ca] | 179 | /** Removes an atom.
|
---|
[59f1bc] | 180 | *
|
---|
[f1b5ca] | 181 | * @param _atomid index of the atom that is removed
|
---|
[59f1bc] | 182 | */
|
---|
[f91ef6] | 183 | void GLWorldScene::atomRemoved(ObservedValue_Index_t _atomid)
|
---|
[59f1bc] | 184 | {
|
---|
[f1b5ca] | 185 | LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atomid)+".");
|
---|
| 186 | // bonds are removed by signal coming from ~bond
|
---|
| 187 |
|
---|
| 188 | // remove atoms
|
---|
| 189 | AtomNodeMap::iterator iter = AtomsinSceneMap.find(_atomid);
|
---|
| 190 | ASSERT(iter != AtomsinSceneMap.end(),
|
---|
| 191 | "GLWorldScene::atomRemoved() - atom "+toString(_atomid)+" not on display.");
|
---|
| 192 | GLMoleculeObject_atom *atomObject = iter->second;
|
---|
| 193 | AtomsinSceneMap.erase(iter);
|
---|
| 194 | delete atomObject;
|
---|
| 195 |
|
---|
| 196 | emit changed();
|
---|
| 197 | emit changeOccured();
|
---|
[59f1bc] | 198 | }
|
---|
| 199 |
|
---|
[f1b5ca] | 200 | /** Adds a bond to the scene.
|
---|
[96f14a] | 201 | *
|
---|
[f1b5ca] | 202 | * @param _bond bond to add
|
---|
[96f14a] | 203 | */
|
---|
| 204 | void GLWorldScene::bondInserted(QtObservedBond::ptr _bond)
|
---|
| 205 | {
|
---|
[f1b5ca] | 206 | static const std::vector< GLMoleculeObject_bond::SideOfBond > bondsides =
|
---|
| 207 | boost::assign::list_of<GLMoleculeObject_bond::SideOfBond>
|
---|
| 208 | (GLMoleculeObject_bond::left)
|
---|
| 209 | (GLMoleculeObject_bond::right);
|
---|
| 210 | LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bonds " << _bond->getBondIndex());
|
---|
| 211 | //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << ".");
|
---|
| 212 |
|
---|
[96f14a] | 213 | const ObservedValue_Index_t bondid = _bond->getIndex();
|
---|
[f1b5ca] | 214 | BondNodeMap::iterator iter = BondsinSceneMap.find(bondid);
|
---|
| 215 | ASSERT( iter == BondsinSceneMap.end(),
|
---|
| 216 | "GLWorldScene::bondInserted() - bond "+toString(bondid)+" is already known.");
|
---|
| 217 | for (size_t i=0;i<2;++i) {
|
---|
| 218 | GLMoleculeObject_bond * bondObject =
|
---|
| 219 | new GLMoleculeObject_bond(GLMoleculeObject::meshCylinder, this, _bond, bondsides[i]);
|
---|
| 220 | connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));
|
---|
| 221 | BondsinSceneMap.insert( std::make_pair(bondid, bondObject) );
|
---|
[96f14a] | 222 | }
|
---|
| 223 |
|
---|
[f1b5ca] | 224 | emit changed();
|
---|
| 225 | emit changeOccured();
|
---|
[96f14a] | 226 | }
|
---|
| 227 |
|
---|
[f1b5ca] | 228 | /** Removes a bond.
|
---|
[96f14a] | 229 | *
|
---|
[f1b5ca] | 230 | * @param _bondid id of bond to remove
|
---|
[96f14a] | 231 | */
|
---|
| 232 | void GLWorldScene::bondRemoved(ObservedValue_Index_t _bondid)
|
---|
| 233 | {
|
---|
[f1b5ca] | 234 | LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond to id " << _bondid);
|
---|
[9c259e] | 235 |
|
---|
[f1b5ca] | 236 | // left bond
|
---|
| 237 | BondNodeMap::iterator iter = BondsinSceneMap.find(_bondid);
|
---|
| 238 | ASSERT( iter != BondsinSceneMap.end(),
|
---|
| 239 | "GLWorldScene::bondRemoved() - could not find bond to id "+toString(_bondid));
|
---|
| 240 | GLMoleculeObject_bond *bondObject = iter->second;
|
---|
| 241 | delete bondObject; // is done by signal from bond itself
|
---|
| 242 | //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");
|
---|
| 243 | BondsinSceneMap.erase(iter);
|
---|
[8281cc] | 244 |
|
---|
[f1b5ca] | 245 | emit changed();
|
---|
| 246 | emit changeOccured();
|
---|
[9c259e] | 247 | }
|
---|
| 248 |
|
---|
[f1b5ca] | 249 | void GLWorldScene::hoverChangedSignalled(GLMoleculeObject *ob)
|
---|
[96f14a] | 250 | {
|
---|
[f1b5ca] | 251 | // Find the atom, ob corresponds to.
|
---|
| 252 | hoverAtomId = -1;
|
---|
| 253 | GLMoleculeObject_atom *atomObject = dynamic_cast<GLMoleculeObject_atom *>(ob);
|
---|
| 254 | if (atomObject){
|
---|
| 255 | for (AtomNodeMap::iterator iter = AtomsinSceneMap.begin();iter != AtomsinSceneMap.end(); ++ iter){
|
---|
| 256 | if (iter->second == atomObject)
|
---|
| 257 | hoverAtomId = iter->second->objectId();
|
---|
[96f14a] | 258 | }
|
---|
| 259 |
|
---|
[f1b5ca] | 260 | // Propagate signal.
|
---|
| 261 | emit hoverChanged(hoverAtomId);
|
---|
[96f14a] | 262 | } else {
|
---|
[f1b5ca] | 263 | // Find the atom, ob corresponds to.
|
---|
| 264 | GLMoleculeObject_molecule *moleculeObject = dynamic_cast<GLMoleculeObject_molecule *>(ob);
|
---|
| 265 | if (moleculeObject){
|
---|
| 266 | // Propagate signal.
|
---|
| 267 | emit hoverChanged(moleculeObject->objectId(), 0);
|
---|
[96f14a] | 268 | }
|
---|
| 269 | }
|
---|
| 270 | }
|
---|
| 271 |
|
---|
[f1b5ca] | 272 | void GLWorldScene::moleculeClicked(moleculeId_t no)
|
---|
[8281cc] | 273 | {
|
---|
[f1b5ca] | 274 | LOG(3, "INFO: GLMoleculeObject_molecule - mol " << no << " has been clicked.");
|
---|
| 275 | const molecule * const mol= const_cast<const World &>(World::getInstance()).
|
---|
| 276 | getMolecule(MoleculeById(no));
|
---|
| 277 | ASSERT(mol, "Atom without molecule has been clicked.");
|
---|
| 278 | molids_t ids(1, mol->getId());
|
---|
| 279 | if (!World::getInstance().isSelected(mol))
|
---|
| 280 | SelectionMoleculeById(ids);
|
---|
| 281 | else
|
---|
| 282 | SelectionNotMoleculeById(ids);
|
---|
| 283 | emit clicked(no);
|
---|
[8281cc] | 284 | }
|
---|
| 285 |
|
---|
[026bef] | 286 | /** Inserts a molecule into the scene.
|
---|
[c67518] | 287 | *
|
---|
[8c001a] | 288 | * @param _mol molecule to insert
|
---|
[c67518] | 289 | */
|
---|
[1b07b1] | 290 | void GLWorldScene::moleculeInserted(QtObservedMolecule::ptr _mol)
|
---|
[c67518] | 291 | {
|
---|
[f91ef6] | 292 | const ObservedValue_Index_t molid = _mol->getIndex();
|
---|
| 293 | LOG(3, "INFO: GLWorldScene: Received signal moleculeInserted for molecule "
|
---|
| 294 | << _mol->getMolIndex());
|
---|
[7cf0eb] | 295 |
|
---|
[1b07b1] | 296 | MoleculeNodeMap::const_iterator iter = MoleculesinSceneMap.find(molid);
|
---|
[8c001a] | 297 | ASSERT( iter == MoleculesinSceneMap.end(),
|
---|
[f91ef6] | 298 | "GLWorldScene::moleculeInserted() - molecule's id "+toString(_mol->getMolIndex())
|
---|
| 299 | +" already present.");
|
---|
[8c001a] | 300 |
|
---|
| 301 | // add new object
|
---|
[f91ef6] | 302 | LOG(1, "DEBUG: Adding GLMoleculeObject_molecule to id " << _mol->getMolIndex());
|
---|
[1b07b1] | 303 | GLMoleculeObject_molecule *molObject =
|
---|
| 304 | new GLMoleculeObject_molecule(
|
---|
| 305 | GLMoleculeObject::meshEmpty,
|
---|
| 306 | this,
|
---|
| 307 | _mol);
|
---|
| 308 | ASSERT( molObject != NULL,
|
---|
[f91ef6] | 309 | "GLWorldScene::moleculeInserted - could not create molecule object for "
|
---|
| 310 | +toString(_mol->getMolIndex()));
|
---|
[1b07b1] | 311 | #ifndef NDEBUG
|
---|
| 312 | std::pair<MoleculeNodeMap::iterator, bool> inserter =
|
---|
| 313 | #endif
|
---|
| 314 | MoleculesinSceneMap.insert( make_pair(molid, molObject) );
|
---|
| 315 | ASSERT(inserter.second,
|
---|
[f91ef6] | 316 | "GLWorldScene::moleculeInserted() - molecule "+toString(_mol->getMolIndex())
|
---|
| 317 | +" already present in scene.");
|
---|
[1b07b1] | 318 |
|
---|
| 319 | connect (molObject, SIGNAL(changed()), this, SIGNAL(changed()));
|
---|
| 320 | connect (molObject, SIGNAL(changeOccured()), this, SIGNAL(changeOccured()));
|
---|
| 321 |
|
---|
| 322 | emit changed();
|
---|
| 323 | emit changeOccured();
|
---|
[c67518] | 324 | }
|
---|
| 325 |
|
---|
[7cf0eb] | 326 | /** Removes a molecule from the scene.
|
---|
| 327 | *
|
---|
[f1b5ca] | 328 | * @param _molid index of the molecule to remove
|
---|
[7cf0eb] | 329 | */
|
---|
[f1b5ca] | 330 | void GLWorldScene::moleculeRemoved(ObservedValue_Index_t _molid)
|
---|
[7cf0eb] | 331 | {
|
---|
[f1b5ca] | 332 | LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_molid)+".");
|
---|
[7c7c4a] | 333 |
|
---|
[f1b5ca] | 334 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molid);
|
---|
[4a187d] | 335 | ASSERT ( iter != MoleculesinSceneMap.end(),
|
---|
[f1b5ca] | 336 | "GLWorldScene::moleculeRemoved() - to be removed molecule "+toString(_molid)
|
---|
[4a187d] | 337 | +" is already gone.");
|
---|
| 338 | // check if it's already empty
|
---|
[f1b5ca] | 339 | GLMoleculeObject_molecule *molObject = iter->second;
|
---|
| 340 | delete molObject;
|
---|
[4a187d] | 341 | MoleculesinSceneMap.erase(iter);
|
---|
[bcf9cd] | 342 |
|
---|
[f1b5ca] | 343 | emit changed();
|
---|
| 344 | emit changeOccured();
|
---|
[ce4126] | 345 | }
|
---|
| 346 |
|
---|
[f91ef6] | 347 | void GLWorldScene::moleculesVisibilityChanged(ObservedValue_Index_t _id, bool _visible)
|
---|
[739ee9] | 348 | {
|
---|
| 349 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_id);
|
---|
| 350 | ASSERT( iter != MoleculesinSceneMap.end(),
|
---|
[f91ef6] | 351 | "GLWorldScene::moleculeInserted() - molecule's id "
|
---|
| 352 | +toString(board->getMoleculeIdToIndex(_id))+" is unknown.");
|
---|
[739ee9] | 353 |
|
---|
| 354 | GLMoleculeObject_molecule *molObject = iter->second;
|
---|
| 355 | molObject->setVisible(_visible);
|
---|
| 356 |
|
---|
| 357 | emit changed();
|
---|
| 358 | emit changeOccured();
|
---|
| 359 | }
|
---|
| 360 |
|
---|
[f75491] | 361 | /** Adds a shape to the scene.
|
---|
[4d6662] | 362 | *
|
---|
[f75491] | 363 | */
|
---|
[07136a] | 364 | void GLWorldScene::addShape(const std::string &_name)
|
---|
[f75491] | 365 | {
|
---|
[07136a] | 366 | Shape * const shape = ShapeRegistry::getInstance().getByName(_name);
|
---|
| 367 | if (shape != NULL) {
|
---|
| 368 | GLMoleculeObject_shape *shapeObject = new GLMoleculeObject_shape(*shape, this);
|
---|
| 369 | ShapeNodeMap::iterator iter = ShapesinSceneMap.find(_name);
|
---|
| 370 | ASSERT(iter == ShapesinSceneMap.end(),
|
---|
| 371 | "GLWorldScene::addShape() - same shape "+_name+" added again.");
|
---|
| 372 | ShapesinSceneMap.insert( make_pair(_name, shapeObject) );
|
---|
| 373 | } else
|
---|
| 374 | ELOG(2, "GLWorldScene::addShape() - shape disappeared before we could draw it.");
|
---|
| 375 |
|
---|
| 376 | emit changed();
|
---|
[284551] | 377 | }
|
---|
| 378 |
|
---|
[07136a] | 379 | void GLWorldScene::removeShape(const std::string &_name)
|
---|
[85c36d] | 380 | {
|
---|
[07136a] | 381 | ShapeNodeMap::iterator iter = ShapesinSceneMap.find(_name);
|
---|
[ba6b5c] | 382 | ASSERT(iter != ShapesinSceneMap.end(),
|
---|
[07136a] | 383 | "GLWorldScene::removeShape() - shape "+_name+" not in scene.");
|
---|
[148dde0] | 384 | ShapesinSceneMap.erase(iter);
|
---|
[85c36d] | 385 | delete(iter->second);
|
---|
[07136a] | 386 |
|
---|
| 387 | emit changed();
|
---|
[85c36d] | 388 | }
|
---|
| 389 |
|
---|
| 390 | void GLWorldScene::updateSelectedShapes()
|
---|
[284551] | 391 | {
|
---|
| 392 | foreach (QObject *obj, children()) {
|
---|
| 393 | GLMoleculeObject_shape *shapeobj = qobject_cast<GLMoleculeObject_shape *>(obj);
|
---|
[85c36d] | 394 | if (shapeobj){
|
---|
| 395 | shapeobj->enable(ShapeRegistry::getInstance().isSelected(shapeobj->getShape()));
|
---|
| 396 | }
|
---|
[284551] | 397 | }
|
---|
[07136a] | 398 |
|
---|
| 399 | emit changed();
|
---|
[f75491] | 400 | }
|
---|
| 401 |
|
---|
[7188b1] | 402 | void GLWorldScene::initialize(QGLView *view, QGLPainter *painter) const
|
---|
| 403 | {
|
---|
| 404 | // Initialize all of the mesh objects that we have as children.
|
---|
| 405 | foreach (QObject *obj, children()) {
|
---|
| 406 | GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
|
---|
| 407 | if (meshobj)
|
---|
| 408 | meshobj->initialize(view, painter);
|
---|
| 409 | }
|
---|
| 410 | }
|
---|
| 411 |
|
---|
[72a4c1] | 412 | void GLWorldScene::draw(QGLPainter *painter, const QVector4D &cameraPlane) const
|
---|
[7188b1] | 413 | {
|
---|
| 414 | // Draw all of the mesh objects that we have as children.
|
---|
| 415 | foreach (QObject *obj, children()) {
|
---|
| 416 | GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
|
---|
| 417 | if (meshobj)
|
---|
[72a4c1] | 418 | meshobj->draw(painter, cameraPlane);
|
---|
[7188b1] | 419 | }
|
---|
[907636] | 420 | }
|
---|
[06ebf5] | 421 |
|
---|
[6966b7] | 422 | void GLWorldScene::setSelectionMode(SelectionModeType mode)
|
---|
| 423 | {
|
---|
| 424 | selectionMode = mode;
|
---|
| 425 | // TODO send update to toolbar
|
---|
| 426 | }
|
---|
| 427 |
|
---|
| 428 | void GLWorldScene::setSelectionModeAtom()
|
---|
| 429 | {
|
---|
| 430 | setSelectionMode(SelectAtom);
|
---|
| 431 | }
|
---|
| 432 |
|
---|
| 433 | void GLWorldScene::setSelectionModeMolecule()
|
---|
| 434 | {
|
---|
| 435 | setSelectionMode(SelectMolecule);
|
---|
| 436 | }
|
---|
[20f9b5] | 437 |
|
---|