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