| 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
|---|
| 5 | * Copyright (C) 2013 Frederik Heber. All rights reserved.
|
|---|
| 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/>.
|
|---|
| 22 | */
|
|---|
| 23 |
|
|---|
| 24 | /*
|
|---|
| 25 | * GLWorldView.cpp
|
|---|
| 26 | *
|
|---|
| 27 | * Created on: Aug 1, 2010
|
|---|
| 28 | * Author: heber
|
|---|
| 29 | */
|
|---|
| 30 |
|
|---|
| 31 | // include config.h
|
|---|
| 32 | #ifdef HAVE_CONFIG_H
|
|---|
| 33 | #include <config.h>
|
|---|
| 34 | #endif
|
|---|
| 35 |
|
|---|
| 36 | #include "GLWorldView.hpp"
|
|---|
| 37 |
|
|---|
| 38 | #include <Qt/qevent.h>
|
|---|
| 39 | #include <Qt/qaction.h>
|
|---|
| 40 | #include <QtGui/QMenu>
|
|---|
| 41 | #include <QtGui/QToolBar>
|
|---|
| 42 | #include <QtGui/QToolButton>
|
|---|
| 43 | #include <Qt/qtimer.h>
|
|---|
| 44 | #include <Qt/qsettings.h>
|
|---|
| 45 | #include <Qt3D/qglbuilder.h>
|
|---|
| 46 | #include <Qt3D/qglscenenode.h>
|
|---|
| 47 | #include <Qt3D/qglsphere.h>
|
|---|
| 48 | #include <Qt3D/qglcylinder.h>
|
|---|
| 49 | #include <Qt3D/qglcube.h>
|
|---|
| 50 |
|
|---|
| 51 | #include "GLWorldScene.hpp"
|
|---|
| 52 |
|
|---|
| 53 | #include "CodePatterns/MemDebug.hpp"
|
|---|
| 54 |
|
|---|
| 55 | #include "Atom/AtomObserver.hpp"
|
|---|
| 56 | #include "Atom/atom_observable.hpp"
|
|---|
| 57 | #include "Box.hpp"
|
|---|
| 58 | #include "CodePatterns/Log.hpp"
|
|---|
| 59 | #include "CodePatterns/Observer/Notification.hpp"
|
|---|
| 60 | #include "CodePatterns/Observer/ObserverLog.hpp"
|
|---|
| 61 | #include "Descriptors/MoleculeIdDescriptor.hpp"
|
|---|
| 62 | #include "molecule.hpp"
|
|---|
| 63 | #include "Shapes/ShapeRegistry.hpp"
|
|---|
| 64 | #include "World.hpp"
|
|---|
| 65 | #include "WorldTime.hpp"
|
|---|
| 66 |
|
|---|
| 67 | GLWorldView::GLWorldView(QWidget *parent)
|
|---|
| 68 | : QGLView(parent), Observer("GLWorldView"), worldscene(NULL), changesPresent(false), needsRedraw(false)
|
|---|
| 69 | {
|
|---|
| 70 | worldscene = new GLWorldScene(this);
|
|---|
| 71 |
|
|---|
| 72 | setOption(QGLView::ObjectPicking, true);
|
|---|
| 73 | setOption(QGLView::CameraNavigation, false);
|
|---|
| 74 | setFocusPolicy(Qt::StrongFocus);
|
|---|
| 75 | setCameraControlMode(Rotate);
|
|---|
| 76 | defaultEyeSeparation = 4.0;
|
|---|
| 77 |
|
|---|
| 78 | createDomainBox();
|
|---|
| 79 | createDreiBein();
|
|---|
| 80 | //changeMaterials(false);
|
|---|
| 81 |
|
|---|
| 82 | qRegisterMetaType<atomId_t>("atomId_t");
|
|---|
| 83 | qRegisterMetaType<moleculeId_t>("moleculeId_t");
|
|---|
| 84 |
|
|---|
| 85 | connect(this, SIGNAL(ShapeAdded()), worldscene, SLOT(addShape()));
|
|---|
| 86 | connect(this, SIGNAL(ShapeRemoved()), worldscene, SLOT(removeShape()));
|
|---|
| 87 | connect(this, SIGNAL(TimeChanged()), worldscene, SIGNAL(updated()));
|
|---|
| 88 | connect(worldscene, SIGNAL(changeOccured()), this, SLOT(changeSignalled()));
|
|---|
| 89 | connect(worldscene, SIGNAL(changed()), this, SIGNAL(changed()));
|
|---|
| 90 | connect(worldscene, SIGNAL(hoverChanged(const atomId_t)), this, SLOT(sceneHoverSignalled(const atomId_t)));
|
|---|
| 91 | connect(worldscene, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SLOT(sceneHoverSignalled(const moleculeId_t, int)));
|
|---|
| 92 | connect(this, SIGNAL(worldSelectionChanged()), worldscene, SLOT(worldSelectionChanged()));
|
|---|
| 93 | connect(this, SIGNAL(atomRemoved(const moleculeId_t, const atomId_t)), worldscene, SLOT(atomRemoved(const moleculeId_t, const atomId_t)), Qt::DirectConnection);
|
|---|
| 94 | connect(this, SIGNAL(atomInserted(const moleculeId_t, const atomId_t)), worldscene, SLOT(atomInserted(const moleculeId_t, const atomId_t)), Qt::DirectConnection);
|
|---|
| 95 | connect(this, SIGNAL(moleculeRemoved(const moleculeId_t)), worldscene, SLOT(moleculeRemoved(const moleculeId_t)), Qt::DirectConnection);
|
|---|
| 96 | connect(this, SIGNAL(moleculeInserted(const moleculeId_t)), worldscene, SLOT(moleculeInserted(const moleculeId_t)), Qt::DirectConnection);
|
|---|
| 97 | //connect(this, SIGNAL(changed()), this, SLOT(updateGL()));
|
|---|
| 98 | connect(this, SIGNAL(changed()), this, SLOT(sceneChangeSignalled()));
|
|---|
| 99 | connect(this, SIGNAL(moleculesVisibilityChanged(const moleculeId_t,bool)), worldscene, SLOT(moleculesVisibilityChanged(const moleculeId_t,bool)));
|
|---|
| 100 |
|
|---|
| 101 | // sign on to changes in the world
|
|---|
| 102 | World::getInstance().signOn(this);
|
|---|
| 103 | World::getInstance().signOn(this, World::MoleculeInserted);
|
|---|
| 104 | World::getInstance().signOn(this, World::SelectionChanged);
|
|---|
| 105 | WorldTime::getInstance().signOn(this, WorldTime::TimeChanged);
|
|---|
| 106 | AtomObserver::getInstance().signOn(this, AtomObservable::PositionChanged);
|
|---|
| 107 |
|
|---|
| 108 | ShapeRegistry::getInstance().signOn(this);
|
|---|
| 109 | ShapeRegistry::getInstance().signOn(this, ShapeRegistry::ShapeInserted);
|
|---|
| 110 | ShapeRegistry::getInstance().signOn(this, ShapeRegistry::ShapeRemoved);
|
|---|
| 111 | ShapeRegistry::getInstance().signOn(this, ShapeRegistry::SelectionChanged);
|
|---|
| 112 |
|
|---|
| 113 | redrawTimer = new QTimer(this);
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | GLWorldView::~GLWorldView()
|
|---|
| 117 | {
|
|---|
| 118 | // remove me from all observed molecules
|
|---|
| 119 | for (ObservedMolecules_t::iterator iter = ObservedMolecules.begin();
|
|---|
| 120 | !ObservedMolecules.empty();
|
|---|
| 121 | iter = ObservedMolecules.begin())
|
|---|
| 122 | signOffFromMolecule(*iter);
|
|---|
| 123 |
|
|---|
| 124 | QSettings settings;
|
|---|
| 125 | settings.beginGroup("WorldView");
|
|---|
| 126 | settings.setValue("domainBoxEnabled", (meshDomainBox->options() & QGLSceneNode::HideNode) == 0);
|
|---|
| 127 | settings.setValue("dreiBeinEnabled", (meshDreiBein->options() & QGLSceneNode::HideNode) == 0);
|
|---|
| 128 | settings.endGroup();
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 | World::getInstance().signOff(this);
|
|---|
| 132 | World::getInstance().signOff(this, World::AtomInserted);
|
|---|
| 133 | World::getInstance().signOff(this, World::AtomRemoved);
|
|---|
| 134 | World::getInstance().signOff(this, World::MoleculeInserted);
|
|---|
| 135 | World::getInstance().signOff(this, World::SelectionChanged);
|
|---|
| 136 | WorldTime::getInstance().signOff(this, WorldTime::TimeChanged);
|
|---|
| 137 | AtomObserver::getInstance().signOff(this, AtomObservable::PositionChanged);
|
|---|
| 138 | ShapeRegistry::getInstance().signOff(this);
|
|---|
| 139 | ShapeRegistry::getInstance().signOff(this, ShapeRegistry::ShapeInserted);
|
|---|
| 140 | ShapeRegistry::getInstance().signOff(this, ShapeRegistry::ShapeRemoved);
|
|---|
| 141 | ShapeRegistry::getInstance().signOff(this, ShapeRegistry::SelectionChanged);
|
|---|
| 142 | delete worldscene;
|
|---|
| 143 |
|
|---|
| 144 | delete(domainBoxMaterial);
|
|---|
| 145 | for (int i=0;i<3;i++)
|
|---|
| 146 | delete(dreiBeinMaterial[i]);
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 | /**
|
|---|
| 151 | * Add some widget specific actions to the toolbar:
|
|---|
| 152 | * - camera rotation/translation mode
|
|---|
| 153 | * - camera fit to domain
|
|---|
| 154 | */
|
|---|
| 155 | void GLWorldView::addToolBarActions(QToolBar *toolbar)
|
|---|
| 156 | {
|
|---|
| 157 | // camera control mode
|
|---|
| 158 | toolbar->addSeparator();
|
|---|
| 159 | QAction *transAction = new QAction(QIcon::fromTheme("forward"), tr("camera translation mode"), this);
|
|---|
| 160 | connect(transAction, SIGNAL(triggered()), this, SLOT(setCameraControlModeTranslation()));
|
|---|
| 161 | toolbar->addAction(transAction);
|
|---|
| 162 | QAction *rotAction = new QAction(QIcon::fromTheme("object-rotate-left"), tr("camera rotation mode"), this);
|
|---|
| 163 | connect(rotAction, SIGNAL(triggered()), this, SLOT(setCameraControlModeRotation()));
|
|---|
| 164 | toolbar->addAction(rotAction);
|
|---|
| 165 | QAction *fitAction = new QAction(QIcon::fromTheme("zoom-best-fit"), tr("camera fit to domain"), this);
|
|---|
| 166 | connect(fitAction, SIGNAL(triggered()), this, SLOT(fitCameraToDomain()));
|
|---|
| 167 | toolbar->addAction(fitAction);
|
|---|
| 168 |
|
|---|
| 169 | // stereo mode
|
|---|
| 170 | QToolButton *stereoButton = new QToolButton(toolbar);
|
|---|
| 171 | QMenu *stereoMenu = new QMenu();
|
|---|
| 172 | QAction *stereoDisableAction = new QAction(QIcon::fromTheme("zoom-best-fit"), tr("disable"), this);
|
|---|
| 173 | connect(stereoDisableAction, SIGNAL(triggered()), this, SLOT(setCameraStereoModeDisable()));
|
|---|
| 174 | stereoMenu->addAction(stereoDisableAction);
|
|---|
| 175 | QAction *stereoHardwareAction = new QAction(QIcon::fromTheme("zoom-best-fit"), tr("hardware"), this);
|
|---|
| 176 | connect(stereoHardwareAction, SIGNAL(triggered()), this, SLOT(setCameraStereoModeHardware()));
|
|---|
| 177 | stereoMenu->addAction(stereoHardwareAction);
|
|---|
| 178 | QAction *stereoLeftRightAction = new QAction(QIcon::fromTheme("zoom-best-fit"), tr("left right"), this);
|
|---|
| 179 | connect(stereoLeftRightAction, SIGNAL(triggered()), this, SLOT(setCameraStereoModeLeftRight()));
|
|---|
| 180 | stereoMenu->addAction(stereoLeftRightAction);
|
|---|
| 181 | QAction *stereoRightLeftAction = new QAction(QIcon::fromTheme("zoom-best-fit"), tr("right left"), this);
|
|---|
| 182 | connect(stereoRightLeftAction, SIGNAL(triggered()), this, SLOT(setCameraStereoModeRightLeft()));
|
|---|
| 183 | stereoMenu->addAction(stereoRightLeftAction);
|
|---|
| 184 | QAction *stereoTopBottomAction = new QAction(QIcon::fromTheme("zoom-best-fit"), tr("top bottom"), this);
|
|---|
| 185 | connect(stereoTopBottomAction, SIGNAL(triggered()), this, SLOT(setCameraStereoModeTopBottom()));
|
|---|
| 186 | stereoMenu->addAction(stereoTopBottomAction);
|
|---|
| 187 | QAction *stereoBottomTopAction = new QAction(QIcon::fromTheme("zoom-best-fit"), tr("bottom top"), this);
|
|---|
| 188 | connect(stereoBottomTopAction, SIGNAL(triggered()), this, SLOT(setCameraStereoModeBottomTop()));
|
|---|
| 189 | stereoMenu->addAction(stereoBottomTopAction);
|
|---|
| 190 | QAction *stereoAnaglyphAction = new QAction(QIcon::fromTheme("zoom-best-fit"), tr("anaglyph"), this);
|
|---|
| 191 | connect(stereoAnaglyphAction, SIGNAL(triggered()), this, SLOT(setCameraStereoModeAnaglyph()));
|
|---|
| 192 | stereoMenu->addAction(stereoAnaglyphAction);
|
|---|
| 193 | stereoButton->setMenu(stereoMenu);
|
|---|
| 194 | stereoButton->setIcon(QIcon(QPixmap(":/icon_view_stereo.png")));
|
|---|
| 195 | stereoButton->setPopupMode(QToolButton::InstantPopup);
|
|---|
| 196 | toolbar->addWidget(stereoButton);
|
|---|
| 197 |
|
|---|
| 198 | // selection mode
|
|---|
| 199 | toolbar->addSeparator();
|
|---|
| 200 | QAction *selAtomAction = new QAction(QIcon(QPixmap(":/icon_select_atom.png")), tr("select atom by clicking"), this);
|
|---|
| 201 | connect(selAtomAction, SIGNAL(triggered()), worldscene, SLOT(setSelectionModeAtom()));
|
|---|
| 202 | toolbar->addAction(selAtomAction);
|
|---|
| 203 | QAction *selMolAction = new QAction(QIcon(QPixmap(":/icon_select_molecule.png")), tr("select molecule by clicking"), this);
|
|---|
| 204 | connect(selMolAction, SIGNAL(triggered()), worldscene, SLOT(setSelectionModeMolecule()));
|
|---|
| 205 | toolbar->addAction(selMolAction);
|
|---|
| 206 |
|
|---|
| 207 | // dreiBein/domain enabler
|
|---|
| 208 | toolbar->addSeparator();
|
|---|
| 209 | QAction *seldreiBein = new QAction(QIcon(QPixmap(":/icon_dreiBein.png")), tr("enable/disable dreiBein"), this);
|
|---|
| 210 | connect(seldreiBein, SIGNAL(triggered()), this, SLOT(changeDreiBein()));
|
|---|
| 211 | toolbar->addAction(seldreiBein);
|
|---|
| 212 | QAction *seldomain = new QAction(QIcon(QPixmap(":/icon_domain.png")), tr("enable/disable domain box"), this);
|
|---|
| 213 | connect(seldomain, SIGNAL(triggered()), this, SLOT(changeDomain()));
|
|---|
| 214 | toolbar->addAction(seldomain);
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | void GLWorldView::createDomainBox()
|
|---|
| 218 | {
|
|---|
| 219 | QSettings settings;
|
|---|
| 220 | settings.beginGroup("WorldView");
|
|---|
| 221 | QColor colorFrame = settings.value("domainBoxColorFrame", QColor(150,160,200,255)).value<QColor>();
|
|---|
| 222 | QColor colorAmbient = settings.value("domainBoxColorAmbient", QColor(50,60,100,255)).value<QColor>();
|
|---|
| 223 | QColor colorDiffuse = settings.value("domainBoxColorDiffuse", QColor(150,160,200,180)).value<QColor>();
|
|---|
| 224 | settings.setValue("domainBoxColorFrame", colorFrame);
|
|---|
| 225 | settings.setValue("domainBoxColorAmbient", colorAmbient);
|
|---|
| 226 | settings.setValue("domainBoxColorDiffuse", colorDiffuse);
|
|---|
| 227 | const bool status = settings.value("domainBoxEnabled").toBool();
|
|---|
| 228 | settings.endGroup();
|
|---|
| 229 |
|
|---|
| 230 | domainBoxMaterial = new QGLMaterial;
|
|---|
| 231 | domainBoxMaterial->setAmbientColor(QColor(0,0,0,255));
|
|---|
| 232 | domainBoxMaterial->setDiffuseColor(QColor(0,0,0,255));
|
|---|
| 233 | domainBoxMaterial->setEmittedLight(colorFrame);
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 | QGLMaterial *material = new QGLMaterial;
|
|---|
| 237 | material->setAmbientColor(colorAmbient);
|
|---|
| 238 | material->setDiffuseColor(colorDiffuse);
|
|---|
| 239 |
|
|---|
| 240 | QGLBuilder builder;
|
|---|
| 241 | builder << QGL::Faceted;
|
|---|
| 242 | builder << QGLCube(-1.0); // "inverted" => inside faces are used as front.
|
|---|
| 243 | meshDomainBox = builder.finalizedSceneNode();
|
|---|
| 244 | QMatrix4x4 mat;
|
|---|
| 245 | mat.translate(0.5f, 0.5f, 0.5f);
|
|---|
| 246 | meshDomainBox->setLocalTransform(mat);
|
|---|
| 247 | meshDomainBox->setMaterial(material);
|
|---|
| 248 |
|
|---|
| 249 | setDomainStatus( status );
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 | void GLWorldView::createDreiBein()
|
|---|
| 253 | {
|
|---|
| 254 | QSettings settings;
|
|---|
| 255 | settings.beginGroup("WorldView");
|
|---|
| 256 | QColor colorX = settings.value("dreiBeinColorX", QColor(255,50,50,255)).value<QColor>();
|
|---|
| 257 | QColor colorY = settings.value("dreiBeinColorY", QColor(50,255,50,255)).value<QColor>();
|
|---|
| 258 | QColor colorZ = settings.value("dreiBeinColorZ", QColor(50,50,255,255)).value<QColor>();
|
|---|
| 259 | settings.setValue("dreiBeinColorX", colorX);
|
|---|
| 260 | settings.setValue("dreiBeinColorY", colorY);
|
|---|
| 261 | settings.setValue("dreiBeinColorZ", colorZ);
|
|---|
| 262 | const bool status = settings.value("dreiBeinEnabled").toBool();
|
|---|
| 263 | settings.endGroup();
|
|---|
| 264 |
|
|---|
| 265 | // Create 3 color for the 3 axes.
|
|---|
| 266 | dreiBeinMaterial[0] = new QGLMaterial;
|
|---|
| 267 | dreiBeinMaterial[0]->setColor(colorX);
|
|---|
| 268 | dreiBeinMaterial[1] = new QGLMaterial;
|
|---|
| 269 | dreiBeinMaterial[1]->setColor(colorY);
|
|---|
| 270 | dreiBeinMaterial[2] = new QGLMaterial;
|
|---|
| 271 | dreiBeinMaterial[2]->setColor(colorZ);
|
|---|
| 272 |
|
|---|
| 273 | // Create the basic meshes (cylinder and cone).
|
|---|
| 274 | QGLBuilder builderCyl;
|
|---|
| 275 | builderCyl << QGLCylinder(.15,.15,1.6,16);
|
|---|
| 276 | QGLSceneNode *cyl = builderCyl.finalizedSceneNode();
|
|---|
| 277 |
|
|---|
| 278 | QGLBuilder builderCone;
|
|---|
| 279 | builderCone << QGLCylinder(0,.4,0.4,16);
|
|---|
| 280 | QGLSceneNode *cone = builderCone.finalizedSceneNode();
|
|---|
| 281 | {
|
|---|
| 282 | QMatrix4x4 mat;
|
|---|
| 283 | mat.translate(0.0f, 0.0f, 1.0f);
|
|---|
| 284 | cone->setLocalTransform(mat);
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | // Create a scene node from the 3 axes.
|
|---|
| 288 | meshDreiBein = new QGLSceneNode(this);
|
|---|
| 289 |
|
|---|
| 290 | // X-direction
|
|---|
| 291 | QGLSceneNode *node = new QGLSceneNode(meshDreiBein);
|
|---|
| 292 | node->setMaterial(dreiBeinMaterial[0]);
|
|---|
| 293 | node->addNode(cyl);
|
|---|
| 294 | node->setPosition(QVector3D(.8f, 0.f, 0.f));
|
|---|
| 295 | node->addNode(cone);
|
|---|
| 296 | {
|
|---|
| 297 | QMatrix4x4 mat;
|
|---|
| 298 | mat.rotate(90, 0.0f, 1.0f, 0.0f);
|
|---|
| 299 | node->setLocalTransform(mat);
|
|---|
| 300 | }
|
|---|
| 301 |
|
|---|
| 302 | // Y-direction
|
|---|
| 303 | node = new QGLSceneNode(meshDreiBein);
|
|---|
| 304 | node->setMaterial(dreiBeinMaterial[1]);
|
|---|
| 305 | node->addNode(cyl);
|
|---|
| 306 | node->addNode(cone);
|
|---|
| 307 | {
|
|---|
| 308 | QMatrix4x4 mat;
|
|---|
| 309 | mat.rotate(-90, 1.0f, 0.0f, 0.0f);
|
|---|
| 310 | node->setLocalTransform(mat);
|
|---|
| 311 | }
|
|---|
| 312 | node->setPosition(QVector3D(0.f, .8f, 0.f));
|
|---|
| 313 |
|
|---|
| 314 | // Z-direction
|
|---|
| 315 | node = new QGLSceneNode(meshDreiBein);
|
|---|
| 316 | node->setMaterial(dreiBeinMaterial[2]);
|
|---|
| 317 | node->addNode(cyl);
|
|---|
| 318 | node->addNode(cone);
|
|---|
| 319 | node->setPosition(QVector3D(0.f, 0.f, .8f));
|
|---|
| 320 |
|
|---|
| 321 | setdreiBeinStatus( status );
|
|---|
| 322 | }
|
|---|
| 323 |
|
|---|
| 324 | /**
|
|---|
| 325 | * Update operation which can be invoked by the observable (which should be the
|
|---|
| 326 | * change tracker here).
|
|---|
| 327 | */
|
|---|
| 328 | void GLWorldView::update(Observable *publisher)
|
|---|
| 329 | {
|
|---|
| 330 | emit changed();
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 | void GLWorldView::signOnToMolecule(const molecule *_mol)
|
|---|
| 334 | {
|
|---|
| 335 | ASSERT( _mol != NULL,
|
|---|
| 336 | "GLWorldView::signOnToMolecule() - molecule ref is NULL.");
|
|---|
| 337 | _mol->signOn(this, molecule::AtomInserted);
|
|---|
| 338 | _mol->signOn(this, molecule::AtomRemoved);
|
|---|
| 339 |
|
|---|
| 340 | ObservedMolecules.insert(const_cast<molecule *>(_mol));
|
|---|
| 341 | }
|
|---|
| 342 |
|
|---|
| 343 | void GLWorldView::signOffFromMolecule(const molecule *_mol)
|
|---|
| 344 | {
|
|---|
| 345 | ObservedMolecules_t::const_iterator iter = ObservedMolecules.find(
|
|---|
| 346 | const_cast<molecule *>(_mol));
|
|---|
| 347 | ASSERT( iter != ObservedMolecules.end(),
|
|---|
| 348 | "GLWorldView::signOffFromMolecule() - molecule "+toString(_mol)
|
|---|
| 349 | +" gave subjectKilled we are not signed on.");
|
|---|
| 350 | // LOG(1, "INFO: Erasing " << mol << " from ObservedMolecules.");
|
|---|
| 351 | ObservedMolecules.erase(iter);
|
|---|
| 352 |
|
|---|
| 353 | ASSERT( _mol != NULL,
|
|---|
| 354 | "GLWorldView::signOffFromMolecule() - molecule ref is NULL.");
|
|---|
| 355 | _mol->signOff(this, molecule::AtomInserted);
|
|---|
| 356 | _mol->signOff(this, molecule::AtomRemoved);
|
|---|
| 357 | }
|
|---|
| 358 |
|
|---|
| 359 | /**
|
|---|
| 360 | * The observable can tell when it dies.
|
|---|
| 361 | */
|
|---|
| 362 | void GLWorldView::subjectKilled(Observable *publisher)
|
|---|
| 363 | {
|
|---|
| 364 | molecule * mol = static_cast<molecule *>(publisher);
|
|---|
| 365 |
|
|---|
| 366 | // std::copy(ObservedMolecules.begin(), ObservedMolecules.end(),
|
|---|
| 367 | // std::ostream_iterator<molecule *>(std::cout, "\n"));
|
|---|
| 368 |
|
|---|
| 369 | if (mol != NULL) {
|
|---|
| 370 |
|
|---|
| 371 | // sign off
|
|---|
| 372 | signOffFromMolecule(mol);
|
|---|
| 373 |
|
|---|
| 374 | // emit removed signal
|
|---|
| 375 | const moleculeId_t _id = World::getInstance().lastChanged<molecule>()->getId();
|
|---|
| 376 | emit moleculeRemoved(_id);
|
|---|
| 377 | }
|
|---|
| 378 | }
|
|---|
| 379 |
|
|---|
| 380 | /** Listen to specific changes to the world.
|
|---|
| 381 | *
|
|---|
| 382 | * @param publisher ref to observable.
|
|---|
| 383 | * @param notification type of notification
|
|---|
| 384 | */
|
|---|
| 385 | void GLWorldView::recieveNotification(Observable *publisher, Notification_ptr notification)
|
|---|
| 386 | {
|
|---|
| 387 | if (static_cast<World *>(publisher) == World::getPointer()) {
|
|---|
| 388 | switch (notification->getChannelNo()) {
|
|---|
| 389 | case World::SelectionChanged:
|
|---|
| 390 | {
|
|---|
| 391 | #ifdef LOG_OBSERVER
|
|---|
| 392 | observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that selection has changed.";
|
|---|
| 393 | #endif
|
|---|
| 394 | emit worldSelectionChanged();
|
|---|
| 395 | break;
|
|---|
| 396 | }
|
|---|
| 397 | case World::MoleculeInserted:
|
|---|
| 398 | {
|
|---|
| 399 | const moleculeId_t _id = World::getInstance().lastChanged<molecule>()->getId();
|
|---|
| 400 | #ifdef LOG_OBSERVER
|
|---|
| 401 | observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that molecule "+toString(_id)+" has been inserted.";
|
|---|
| 402 | #endif
|
|---|
| 403 | const molecule * const _molecule = const_cast<const World &>(World::getInstance()).
|
|---|
| 404 | getMolecule(MoleculeById(_id));
|
|---|
| 405 | if (_molecule != NULL) {
|
|---|
| 406 | signOnToMolecule(_molecule);
|
|---|
| 407 |
|
|---|
| 408 | emit moleculeInserted(_id);
|
|---|
| 409 | }
|
|---|
| 410 | break;
|
|---|
| 411 | }
|
|---|
| 412 | default:
|
|---|
| 413 | ASSERT(0, "GLWorldView::recieveNotification() - we cannot get here for World.");
|
|---|
| 414 | break;
|
|---|
| 415 | }
|
|---|
| 416 | } else if (static_cast<WorldTime *>(publisher) == WorldTime::getPointer()) {
|
|---|
| 417 | switch (notification->getChannelNo()) {
|
|---|
| 418 | case WorldTime::TimeChanged:
|
|---|
| 419 | {
|
|---|
| 420 | #ifdef LOG_OBSERVER
|
|---|
| 421 | observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that WorldTime's time has changed.";
|
|---|
| 422 | #endif
|
|---|
| 423 | emit changed();
|
|---|
| 424 | emit TimeChanged();
|
|---|
| 425 | break;
|
|---|
| 426 | }
|
|---|
| 427 | default:
|
|---|
| 428 | ASSERT(0, "GLWorldView::recieveNotification() - we cannot get here for WorldTime.");
|
|---|
| 429 | break;
|
|---|
| 430 | }
|
|---|
| 431 | } else if (dynamic_cast<molecule *>(publisher) != NULL) {
|
|---|
| 432 | const molecule * mol = const_cast<const molecule * const>(dynamic_cast<molecule *>(publisher));
|
|---|
| 433 | const atomId_t atomid = mol->lastChanged()->getId();
|
|---|
| 434 | const moleculeId_t molid = mol->getId();
|
|---|
| 435 | switch (notification->getChannelNo()) {
|
|---|
| 436 | case molecule::AtomInserted:
|
|---|
| 437 | {
|
|---|
| 438 | #ifdef LOG_OBSERVER
|
|---|
| 439 | observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this))
|
|---|
| 440 | << " received notification that atom "+toString(atomid)+" has been inserted into molecule "+toString(molid)+".";
|
|---|
| 441 | #endif
|
|---|
| 442 | emit atomInserted(molid, atomid);
|
|---|
| 443 | break;
|
|---|
| 444 | }
|
|---|
| 445 | case World::AtomRemoved:
|
|---|
| 446 | {
|
|---|
| 447 | #ifdef LOG_OBSERVER
|
|---|
| 448 | observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this))
|
|---|
| 449 | << " received notification that atom "+toString(atomid)+" has been removed from molecule "+toString(molid)+".";
|
|---|
| 450 | #endif
|
|---|
| 451 | emit atomRemoved(molid, atomid);
|
|---|
| 452 | break;
|
|---|
| 453 | }
|
|---|
| 454 | default:
|
|---|
| 455 | ASSERT(0, "GLWorldView::recieveNotification() - we cannot get here for molecule.");
|
|---|
| 456 | break;
|
|---|
| 457 | }
|
|---|
| 458 | } else if (dynamic_cast<AtomObservable *>(publisher) != NULL) {
|
|---|
| 459 | switch (notification->getChannelNo()) {
|
|---|
| 460 | case AtomObservable::PositionChanged:
|
|---|
| 461 | {
|
|---|
| 462 | #ifdef LOG_OBSERVER
|
|---|
| 463 | const atom *_atom = dynamic_cast<const atom *>(publisher);
|
|---|
| 464 | observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_atom->getId())+" has changed its position.";
|
|---|
| 465 | #endif
|
|---|
| 466 | emit changed();
|
|---|
| 467 | break;
|
|---|
| 468 | }
|
|---|
| 469 | default:
|
|---|
| 470 | ASSERT(0, "GLWorldView::recieveNotification() - we cannot get here for AtomObservable.");
|
|---|
| 471 | break;
|
|---|
| 472 | }
|
|---|
| 473 | } else if (static_cast<ShapeRegistry*>(publisher) == ShapeRegistry::getPointer()) {
|
|---|
| 474 | switch (notification->getChannelNo()) {
|
|---|
| 475 | case ShapeRegistry::ShapeInserted:
|
|---|
| 476 | {
|
|---|
| 477 | emit ShapeAdded();
|
|---|
| 478 | break;
|
|---|
| 479 | }
|
|---|
| 480 | case ShapeRegistry::ShapeRemoved:
|
|---|
| 481 | {
|
|---|
| 482 | emit ShapeRemoved();
|
|---|
| 483 | break;
|
|---|
| 484 | }
|
|---|
| 485 | case ShapeRegistry::SelectionChanged:
|
|---|
| 486 | {
|
|---|
| 487 | worldscene->updateSelectedShapes();
|
|---|
| 488 | break;
|
|---|
| 489 | }
|
|---|
| 490 | default:
|
|---|
| 491 | ASSERT(0, "GLWorldView::recieveNotification() - we cannot get here for ShapeRegistry.");
|
|---|
| 492 | break;
|
|---|
| 493 | }
|
|---|
| 494 | } else
|
|---|
| 495 | ASSERT(0, "GLWorldView::recieveNotification() - received notification from unknown source.");
|
|---|
| 496 | }
|
|---|
| 497 |
|
|---|
| 498 | void GLWorldView::checkChanges()
|
|---|
| 499 | {
|
|---|
| 500 | updateGL();
|
|---|
| 501 | needsRedraw = false;
|
|---|
| 502 | }
|
|---|
| 503 |
|
|---|
| 504 | void GLWorldView::changeDreiBein()
|
|---|
| 505 | {
|
|---|
| 506 | // invert to new status
|
|---|
| 507 | const bool status = ((meshDreiBein->options() & QGLSceneNode::HideNode) == 0);
|
|---|
| 508 | setdreiBeinStatus(!status);
|
|---|
| 509 | // realize
|
|---|
| 510 | updateGL();
|
|---|
| 511 | needsRedraw = true;
|
|---|
| 512 | }
|
|---|
| 513 |
|
|---|
| 514 | void GLWorldView::setdreiBeinStatus(const bool status)
|
|---|
| 515 | {
|
|---|
| 516 | if (status)
|
|---|
| 517 | meshDreiBein->setOptions( meshDreiBein->options() & (255-QGLSceneNode::HideNode) );
|
|---|
| 518 | else
|
|---|
| 519 | meshDreiBein->setOptions( meshDreiBein->options() | QGLSceneNode::HideNode );
|
|---|
| 520 | }
|
|---|
| 521 |
|
|---|
| 522 | void GLWorldView::changeDomain()
|
|---|
| 523 | {
|
|---|
| 524 | // invert to new status
|
|---|
| 525 | const bool status = ((meshDomainBox->options() & QGLSceneNode::HideNode) == 0);
|
|---|
| 526 | setDomainStatus(!status);
|
|---|
| 527 | // realize
|
|---|
| 528 | updateGL();
|
|---|
| 529 | needsRedraw = true;
|
|---|
| 530 | }
|
|---|
| 531 |
|
|---|
| 532 | void GLWorldView::setDomainStatus(const bool status)
|
|---|
| 533 | {
|
|---|
| 534 | if (status)
|
|---|
| 535 | meshDomainBox->setOptions( meshDomainBox->options() & (255-QGLSceneNode::HideNode) );
|
|---|
| 536 | else
|
|---|
| 537 | meshDomainBox->setOptions( meshDomainBox->options() | QGLSceneNode::HideNode );
|
|---|
| 538 | }
|
|---|
| 539 |
|
|---|
| 540 | void GLWorldView::sceneChangeSignalled()
|
|---|
| 541 | {
|
|---|
| 542 | if (!needsRedraw){
|
|---|
| 543 | redrawTimer->singleShot(0, this, SLOT(checkChanges()));
|
|---|
| 544 | needsRedraw = true;
|
|---|
| 545 | redrawTimer->start();
|
|---|
| 546 | }
|
|---|
| 547 | }
|
|---|
| 548 |
|
|---|
| 549 | void GLWorldView::initializeGL(QGLPainter *painter)
|
|---|
| 550 | {
|
|---|
| 551 | worldscene->initialize(this, painter);
|
|---|
| 552 | changesPresent = false;
|
|---|
| 553 | }
|
|---|
| 554 |
|
|---|
| 555 | void GLWorldView::paintGL(QGLPainter *painter)
|
|---|
| 556 | {
|
|---|
| 557 | if (changesPresent) {
|
|---|
| 558 | initializeGL(painter);
|
|---|
| 559 | changesPresent = false;
|
|---|
| 560 | }
|
|---|
| 561 |
|
|---|
| 562 | QVector3D cameraDir = camera()->center() - camera()->eye();
|
|---|
| 563 | cameraDir.normalize();
|
|---|
| 564 | QVector4D cameraPlane(cameraDir, QVector3D::dotProduct(cameraDir, camera()->eye()));
|
|---|
| 565 | worldscene->draw(painter, cameraPlane);
|
|---|
| 566 |
|
|---|
| 567 | drawDreiBein(painter);
|
|---|
| 568 |
|
|---|
| 569 | // Domain box has to be last because of its transparency.
|
|---|
| 570 | drawDomainBox(painter);
|
|---|
| 571 | }
|
|---|
| 572 |
|
|---|
| 573 | void GLWorldView::keyPressEvent(QKeyEvent *e)
|
|---|
| 574 | {
|
|---|
| 575 | // Find the distance between the eye and focus point.
|
|---|
| 576 | QVector3D d = camera()->eye() - camera()->center();
|
|---|
| 577 | // LOG(1, "Distance vector eye and center is "
|
|---|
| 578 | // << d.x() << "," << d.y() << "," << d.z());
|
|---|
| 579 | // scale the move unit by the eye <-> domain center distance
|
|---|
| 580 | const double key_move_unit = 0.04*(d.length()/50.);
|
|---|
| 581 |
|
|---|
| 582 | if (e->key() == Qt::Key_Tab) {
|
|---|
| 583 | // The Tab key turns the ShowPicking option on and off,
|
|---|
| 584 | // which helps show what the pick buffer looks like.
|
|---|
| 585 | setOption(QGLView::ShowPicking, ((options() & QGLView::ShowPicking) == 0));
|
|---|
| 586 | updateGL();
|
|---|
| 587 | } else if ((e->key() == Qt::Key_Minus) || (e->key() == Qt::Key_Plus)) {
|
|---|
| 588 | // Scale the distance.
|
|---|
| 589 | if (e->key() == Qt::Key_Minus)
|
|---|
| 590 | d *= 1.2;
|
|---|
| 591 | else if (e->key() == Qt::Key_Plus)
|
|---|
| 592 | d /= 1.2;
|
|---|
| 593 | // Set new eye position.
|
|---|
| 594 | camera()->setEye(camera()->center() + d);
|
|---|
| 595 | } else if ((e->key() == Qt::Key_Left) || (e->key() == Qt::Key_Right)) {
|
|---|
| 596 | // Translate the camera.
|
|---|
| 597 | const double d = (e->key() == Qt::Key_Left) ? -key_move_unit : key_move_unit;
|
|---|
| 598 | camera()->translateCenter( d, 0., 0);
|
|---|
| 599 | camera()->translateEye( d, 0., 0);
|
|---|
| 600 | } else if ((e->key() == Qt::Key_Up) || (e->key() == Qt::Key_Down)) {
|
|---|
| 601 | // Translate the camera.
|
|---|
| 602 | const double d = (e->key() == Qt::Key_Up) ? -key_move_unit : key_move_unit;
|
|---|
| 603 | camera()->translateCenter( 0., d, 0);
|
|---|
| 604 | camera()->translateEye( 0., d, 0);
|
|---|
| 605 | } else if ((e->key() == Qt::Key_PageUp) || (e->key() == Qt::Key_PageDown)) {
|
|---|
| 606 | // Translate the camera.
|
|---|
| 607 | const double d = (e->key() == Qt::Key_PageUp) ? -key_move_unit : key_move_unit;
|
|---|
| 608 | camera()->translateCenter( 0., 0., d);
|
|---|
| 609 | camera()->translateEye( 0., 0., d);
|
|---|
| 610 | }
|
|---|
| 611 | QGLView::keyPressEvent(e);
|
|---|
| 612 | }
|
|---|
| 613 |
|
|---|
| 614 | void GLWorldView::changeSignalled()
|
|---|
| 615 | {
|
|---|
| 616 | changesPresent = true;
|
|---|
| 617 | }
|
|---|
| 618 |
|
|---|
| 619 |
|
|---|
| 620 | /**
|
|---|
| 621 | * Set the current camera control mode.
|
|---|
| 622 | */
|
|---|
| 623 | void GLWorldView::setCameraControlMode(GLWorldView::CameraControlModeType mode)
|
|---|
| 624 | {
|
|---|
| 625 | cameraControlMode = mode;
|
|---|
| 626 | }
|
|---|
| 627 |
|
|---|
| 628 | void GLWorldView::setCameraControlModeRotation()
|
|---|
| 629 | {
|
|---|
| 630 | setCameraControlMode(Rotate);
|
|---|
| 631 | }
|
|---|
| 632 |
|
|---|
| 633 | void GLWorldView::setCameraControlModeTranslation()
|
|---|
| 634 | {
|
|---|
| 635 | setCameraControlMode(Translate);
|
|---|
| 636 | }
|
|---|
| 637 |
|
|---|
| 638 | /**
|
|---|
| 639 | * Returns the current camera control mode.
|
|---|
| 640 | * This needs to be invertable (rotation - translation), if the shift key is pressed.
|
|---|
| 641 | */
|
|---|
| 642 | GLWorldView::CameraControlModeType GLWorldView::getCameraControlMode(bool inverted)
|
|---|
| 643 | {
|
|---|
| 644 | if (inverted){
|
|---|
| 645 | if (cameraControlMode == Rotate)
|
|---|
| 646 | return Translate;
|
|---|
| 647 | if (cameraControlMode == Translate)
|
|---|
| 648 | return Rotate;
|
|---|
| 649 | return Rotate;
|
|---|
| 650 | }else
|
|---|
| 651 | return cameraControlMode;
|
|---|
| 652 | }
|
|---|
| 653 |
|
|---|
| 654 | /**
|
|---|
| 655 | * Set the camera so it can oversee the whole domain.
|
|---|
| 656 | */
|
|---|
| 657 | void GLWorldView::fitCameraToDomain()
|
|---|
| 658 | {
|
|---|
| 659 | // Move the camera focus point to the center of the domain box.
|
|---|
| 660 | Vector v = World::getInstance().getDomain().translateIn(Vector(0.5, 0.5, 0.5));
|
|---|
| 661 | camera()->setCenter(QVector3D(v[0], v[1], v[2]));
|
|---|
| 662 |
|
|---|
| 663 | // Guess some eye distance.
|
|---|
| 664 | double dist = v.Norm() * 3;
|
|---|
| 665 | camera()->setEye(QVector3D(v[0], v[1], v[2] + dist));
|
|---|
| 666 | camera()->setUpVector(QVector3D(0, 1, 0));
|
|---|
| 667 | }
|
|---|
| 668 |
|
|---|
| 669 | void GLWorldView::setCameraStereoModeDisable()
|
|---|
| 670 | {
|
|---|
| 671 | setStereoType(QGLView::Hardware);
|
|---|
| 672 | camera()->setEyeSeparation(0.0);
|
|---|
| 673 | updateGL();
|
|---|
| 674 | }
|
|---|
| 675 |
|
|---|
| 676 | void GLWorldView::setCameraStereoModeHardware()
|
|---|
| 677 | {
|
|---|
| 678 | setStereoType(QGLView::Hardware);
|
|---|
| 679 | camera()->setEyeSeparation(defaultEyeSeparation);
|
|---|
| 680 | updateGL();
|
|---|
| 681 | }
|
|---|
| 682 |
|
|---|
| 683 | void GLWorldView::setCameraStereoModeLeftRight()
|
|---|
| 684 | {
|
|---|
| 685 | setStereoType(QGLView::LeftRight);
|
|---|
| 686 | camera()->setEyeSeparation(defaultEyeSeparation);
|
|---|
| 687 | updateGL();
|
|---|
| 688 | }
|
|---|
| 689 |
|
|---|
| 690 | void GLWorldView::setCameraStereoModeRightLeft()
|
|---|
| 691 | {
|
|---|
| 692 | setStereoType(QGLView::RightLeft);
|
|---|
| 693 | camera()->setEyeSeparation(defaultEyeSeparation);
|
|---|
| 694 | updateGL();
|
|---|
| 695 | }
|
|---|
| 696 |
|
|---|
| 697 | void GLWorldView::setCameraStereoModeTopBottom()
|
|---|
| 698 | {
|
|---|
| 699 | setStereoType(QGLView::TopBottom);
|
|---|
| 700 | camera()->setEyeSeparation(defaultEyeSeparation);
|
|---|
| 701 | updateGL();
|
|---|
| 702 | }
|
|---|
| 703 |
|
|---|
| 704 | void GLWorldView::setCameraStereoModeBottomTop()
|
|---|
| 705 | {
|
|---|
| 706 | setStereoType(QGLView::BottomTop);
|
|---|
| 707 | camera()->setEyeSeparation(defaultEyeSeparation);
|
|---|
| 708 | updateGL();
|
|---|
| 709 | }
|
|---|
| 710 |
|
|---|
| 711 | void GLWorldView::setCameraStereoModeAnaglyph()
|
|---|
| 712 | {
|
|---|
| 713 | setStereoType(QGLView::RedCyanAnaglyph);
|
|---|
| 714 | camera()->setEyeSeparation(defaultEyeSeparation);
|
|---|
| 715 | updateGL();
|
|---|
| 716 | }
|
|---|
| 717 |
|
|---|
| 718 | void GLWorldView::mousePressEvent(QMouseEvent *event)
|
|---|
| 719 | {
|
|---|
| 720 | QGLView::mousePressEvent(event);
|
|---|
| 721 |
|
|---|
| 722 | // Reset the saved mouse position.
|
|---|
| 723 | lastMousePos = event->posF();
|
|---|
| 724 | }
|
|---|
| 725 |
|
|---|
| 726 | /**
|
|---|
| 727 | * Handle a mouse move event.
|
|---|
| 728 | * This is used to control the camera (rotation and translation) when the left button is being pressed.
|
|---|
| 729 | */
|
|---|
| 730 | void GLWorldView::mouseMoveEvent(QMouseEvent *event)
|
|---|
| 731 | {
|
|---|
| 732 | if (event->buttons() & Qt::LeftButton){
|
|---|
| 733 | // Find the mouse distance since the last event.
|
|---|
| 734 | QPointF d = event->posF() - lastMousePos;
|
|---|
| 735 | lastMousePos = event->posF();
|
|---|
| 736 |
|
|---|
| 737 | // Rotate or translate? (inverted by shift key)
|
|---|
| 738 | CameraControlModeType mode = getCameraControlMode(event->modifiers() & Qt::ShiftModifier);
|
|---|
| 739 |
|
|---|
| 740 | if (mode == Rotate){
|
|---|
| 741 | // Rotate the camera.
|
|---|
| 742 | d *= 0.3;
|
|---|
| 743 | camera()->tiltPanRollCenter(- d.y(), - d.x(), 0);
|
|---|
| 744 | }else if (mode == Translate){
|
|---|
| 745 | // Translate the camera.
|
|---|
| 746 | d *= 0.02;
|
|---|
| 747 | camera()->translateCenter(- d.x(), d.y(), 0);
|
|---|
| 748 | camera()->translateEye(- d.x(), d.y(), 0);
|
|---|
| 749 | }
|
|---|
| 750 | }else{
|
|---|
| 751 | // Without this Qt would not test for hover events (i.e. mouse over an atom).
|
|---|
| 752 | QGLView::mouseMoveEvent(event);
|
|---|
| 753 | }
|
|---|
| 754 | }
|
|---|
| 755 |
|
|---|
| 756 | /**
|
|---|
| 757 | * When the mouse wheel is used, zoom in or out.
|
|---|
| 758 | */
|
|---|
| 759 | void GLWorldView::wheelEvent(QWheelEvent *event)
|
|---|
| 760 | {
|
|---|
| 761 | // Find the distance between the eye and focus point.
|
|---|
| 762 | QVector3D d = camera()->eye() - camera()->center();
|
|---|
| 763 |
|
|---|
| 764 | // Scale the distance.
|
|---|
| 765 | if (event->delta() < 0)
|
|---|
| 766 | d *= 1.2;
|
|---|
| 767 | else if (event->delta() > 0)
|
|---|
| 768 | d /= 1.2;
|
|---|
| 769 |
|
|---|
| 770 | // Set new eye position.
|
|---|
| 771 | camera()->setEye(camera()->center() + d);
|
|---|
| 772 | }
|
|---|
| 773 |
|
|---|
| 774 | /**
|
|---|
| 775 | * Draw a transparent cube representing the domain.
|
|---|
| 776 | */
|
|---|
| 777 | void GLWorldView::drawDomainBox(QGLPainter *painter) const
|
|---|
| 778 | {
|
|---|
| 779 | // Apply the domain matrix.
|
|---|
| 780 | RealSpaceMatrix m = World::getInstance().getDomain().getM();
|
|---|
| 781 | painter->modelViewMatrix().push();
|
|---|
| 782 | painter->modelViewMatrix() *= QMatrix4x4(m.at(0,0), m.at(0,1), m.at(0,2), 0.0,
|
|---|
| 783 | m.at(1,0), m.at(1,1), m.at(1,2), 0.0,
|
|---|
| 784 | m.at(2,0), m.at(2,1), m.at(2,2), 0.0,
|
|---|
| 785 | 0.0, 0.0, 0.0, 1.0);
|
|---|
| 786 |
|
|---|
| 787 | // Draw the transparent cube.
|
|---|
| 788 | painter->setStandardEffect(QGL::LitMaterial);
|
|---|
| 789 | glCullFace(GL_BACK);
|
|---|
| 790 | glEnable(GL_CULL_FACE);
|
|---|
| 791 | glEnable(GL_BLEND);
|
|---|
| 792 | glDepthMask(0);
|
|---|
| 793 | //glDisable(GL_DEPTH_TEST);
|
|---|
| 794 | meshDomainBox->draw(painter);
|
|---|
| 795 | //glEnable(GL_DEPTH_TEST);
|
|---|
| 796 | glDepthMask(1);
|
|---|
| 797 | glDisable(GL_BLEND);
|
|---|
| 798 | glDisable(GL_CULL_FACE);
|
|---|
| 799 |
|
|---|
| 800 | // Draw the outlines (if we have drawn the box itself)
|
|---|
| 801 | if ((meshDomainBox->options() & QGLSceneNode::HideNode) == 0) {
|
|---|
| 802 | painter->setFaceMaterial(QGL::AllFaces, domainBoxMaterial);
|
|---|
| 803 | //glEnable(GL_LINE_SMOOTH);
|
|---|
| 804 | QVector3DArray array;
|
|---|
| 805 | array.append(0, 0, 0); array.append(1, 0, 0);
|
|---|
| 806 | array.append(1, 0, 0); array.append(1, 1, 0);
|
|---|
| 807 | array.append(1, 1, 0); array.append(0, 1, 0);
|
|---|
| 808 | array.append(0, 1, 0); array.append(0, 0, 0);
|
|---|
| 809 |
|
|---|
| 810 | array.append(0, 0, 1); array.append(1, 0, 1);
|
|---|
| 811 | array.append(1, 0, 1); array.append(1, 1, 1);
|
|---|
| 812 | array.append(1, 1, 1); array.append(0, 1, 1);
|
|---|
| 813 | array.append(0, 1, 1); array.append(0, 0, 1);
|
|---|
| 814 |
|
|---|
| 815 | array.append(0, 0, 0); array.append(0, 0, 1);
|
|---|
| 816 | array.append(1, 0, 0); array.append(1, 0, 1);
|
|---|
| 817 | array.append(0, 1, 0); array.append(0, 1, 1);
|
|---|
| 818 | array.append(1, 1, 0); array.append(1, 1, 1);
|
|---|
| 819 | painter->clearAttributes();
|
|---|
| 820 | painter->setVertexAttribute(QGL::Position, array);
|
|---|
| 821 | painter->draw(QGL::Lines, 24);
|
|---|
| 822 | }
|
|---|
| 823 |
|
|---|
| 824 | painter->modelViewMatrix().pop();
|
|---|
| 825 | }
|
|---|
| 826 |
|
|---|
| 827 | void GLWorldView::drawDreiBein(QGLPainter *painter)
|
|---|
| 828 | {
|
|---|
| 829 | painter->modelViewMatrix().push();
|
|---|
| 830 | painter->modelViewMatrix().translate(camera()->center());
|
|---|
| 831 | painter->setStandardEffect(QGL::LitMaterial);
|
|---|
| 832 | painter->setFaceMaterial(QGL::FrontFaces, NULL);
|
|---|
| 833 | meshDreiBein->draw(painter);
|
|---|
| 834 | painter->modelViewMatrix().pop();
|
|---|
| 835 | }
|
|---|
| 836 |
|
|---|
| 837 | void GLWorldView::sceneHoverSignalled(const atomId_t _id)
|
|---|
| 838 | {
|
|---|
| 839 | emit hoverChanged(_id);
|
|---|
| 840 | }
|
|---|
| 841 |
|
|---|
| 842 | void GLWorldView::sceneHoverSignalled(const moleculeId_t _id, int _i)
|
|---|
| 843 | {
|
|---|
| 844 | emit hoverChanged(_id, _i);
|
|---|
| 845 | }
|
|---|