| 1 | /*
 | 
|---|
| 2 |  * Project: MoleCuilder
 | 
|---|
| 3 |  * Description: creates and alters molecular systems
 | 
|---|
| 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| 5 |  * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | /*
 | 
|---|
| 9 |  * GLWorldView.cpp
 | 
|---|
| 10 |  *
 | 
|---|
| 11 |  *  Created on: Aug 1, 2010
 | 
|---|
| 12 |  *      Author: heber
 | 
|---|
| 13 |  */
 | 
|---|
| 14 | 
 | 
|---|
| 15 | // include config.h
 | 
|---|
| 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 17 | #include <config.h>
 | 
|---|
| 18 | #endif
 | 
|---|
| 19 | 
 | 
|---|
| 20 | #include "GLWorldView.hpp"
 | 
|---|
| 21 | 
 | 
|---|
| 22 | #include <Qt/qevent.h>
 | 
|---|
| 23 | 
 | 
|---|
| 24 | #include "GLWorldScene.hpp"
 | 
|---|
| 25 | 
 | 
|---|
| 26 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| 27 | 
 | 
|---|
| 28 | #include "Atom/AtomObserver.hpp"
 | 
|---|
| 29 | #include "Atom/atom_observable.hpp"
 | 
|---|
| 30 | #include "CodePatterns/Log.hpp"
 | 
|---|
| 31 | #include "CodePatterns/Observer/Notification.hpp"
 | 
|---|
| 32 | #include "World.hpp"
 | 
|---|
| 33 | 
 | 
|---|
| 34 | GLWorldView::GLWorldView(QWidget *parent)
 | 
|---|
| 35 |   : QGLView(parent), Observer("GLWorldView"), worldscene(NULL), changesPresent(false)
 | 
|---|
| 36 | {
 | 
|---|
| 37 |   worldscene = new GLWorldScene(this);
 | 
|---|
| 38 | 
 | 
|---|
| 39 |   setOption(QGLView::ObjectPicking, true);
 | 
|---|
| 40 | 
 | 
|---|
| 41 |   connect(worldscene, SIGNAL(changeOccured()), this, SLOT(changeSignalled()));
 | 
|---|
| 42 |   connect(worldscene, SIGNAL(changed()), this, SIGNAL(changed()));
 | 
|---|
| 43 |   connect(this, SIGNAL(atomInserted(const atom *)), worldscene, SLOT(atomInserted(const atom *)));
 | 
|---|
| 44 |   connect(this, SIGNAL(atomRemoved(const atom *)), worldscene, SLOT(atomRemoved(const atom *)));
 | 
|---|
| 45 |   connect(this, SIGNAL(worldSelectionChanged()), worldscene, SLOT(worldSelectionChanged()));
 | 
|---|
| 46 |   connect(this, SIGNAL(moleculeRemoved(const molecule *)), worldscene, SLOT(moleculeRemoved(const molecule *)));
 | 
|---|
| 47 |   connect(this, SIGNAL(changed()), this, SLOT(updateGL()));
 | 
|---|
| 48 | 
 | 
|---|
| 49 |   // sign on to changes in the world
 | 
|---|
| 50 |   World::getInstance().signOn(this);
 | 
|---|
| 51 |   World::getInstance().signOn(this, World::AtomInserted);
 | 
|---|
| 52 |   World::getInstance().signOn(this, World::AtomRemoved);
 | 
|---|
| 53 |   World::getInstance().signOn(this, World::MoleculeInserted);
 | 
|---|
| 54 |   World::getInstance().signOn(this, World::MoleculeRemoved);
 | 
|---|
| 55 |   World::getInstance().signOn(this, World::SelectionChanged);
 | 
|---|
| 56 |   AtomObserver::getInstance().signOn(this, AtomObservable::PositionChanged);
 | 
|---|
| 57 | }
 | 
|---|
| 58 | 
 | 
|---|
| 59 | GLWorldView::~GLWorldView()
 | 
|---|
| 60 | {
 | 
|---|
| 61 |   World::getInstance().signOff(this);
 | 
|---|
| 62 |   World::getInstance().signOff(this, World::AtomInserted);
 | 
|---|
| 63 |   World::getInstance().signOff(this, World::AtomRemoved);
 | 
|---|
| 64 |   World::getInstance().signOff(this, World::MoleculeInserted);
 | 
|---|
| 65 |   World::getInstance().signOff(this, World::MoleculeRemoved);
 | 
|---|
| 66 |   World::getInstance().signOff(this, World::SelectionChanged);
 | 
|---|
| 67 |   AtomObserver::getInstance().signOff(this, AtomObservable::PositionChanged);
 | 
|---|
| 68 |   delete worldscene;
 | 
|---|
| 69 | }
 | 
|---|
| 70 | 
 | 
|---|
| 71 | /**
 | 
|---|
| 72 |  * Update operation which can be invoked by the observable (which should be the
 | 
|---|
| 73 |  * change tracker here).
 | 
|---|
| 74 |  */
 | 
|---|
| 75 | void GLWorldView::update(Observable *publisher)
 | 
|---|
| 76 | {
 | 
|---|
| 77 |   emit changed();
 | 
|---|
| 78 | }
 | 
|---|
| 79 | 
 | 
|---|
| 80 | /**
 | 
|---|
| 81 |  * The observable can tell when it dies.
 | 
|---|
| 82 |  */
 | 
|---|
| 83 | void GLWorldView::subjectKilled(Observable *publisher) {}
 | 
|---|
| 84 | 
 | 
|---|
| 85 | /** Listen to specific changes to the world.
 | 
|---|
| 86 |  *
 | 
|---|
| 87 |  * @param publisher ref to observable.
 | 
|---|
| 88 |  * @param notification type of notification
 | 
|---|
| 89 |  */
 | 
|---|
| 90 | void GLWorldView::recieveNotification(Observable *publisher, Notification_ptr notification)
 | 
|---|
| 91 | {
 | 
|---|
| 92 |   if (static_cast<World *>(publisher) == World::getPointer()) {
 | 
|---|
| 93 |     switch (notification->getChannelNo()) {
 | 
|---|
| 94 |       case World::AtomInserted:
 | 
|---|
| 95 |       {
 | 
|---|
| 96 |         const atom *_atom = World::getInstance().lastChanged<atom>();
 | 
|---|
| 97 |   #ifdef LOG_OBSERVER
 | 
|---|
| 98 |         observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that atom "+toString(_atom->getId())+" has been inserted.";
 | 
|---|
| 99 |   #endif
 | 
|---|
| 100 |         emit atomInserted(_atom);
 | 
|---|
| 101 |         break;
 | 
|---|
| 102 |       }
 | 
|---|
| 103 |       case World::AtomRemoved:
 | 
|---|
| 104 |       {
 | 
|---|
| 105 |         const atom *_atom = World::getInstance().lastChanged<atom>();
 | 
|---|
| 106 |   #ifdef LOG_OBSERVER
 | 
|---|
| 107 |         observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that atom "+toString(_atom->getId())+" has been removed.";
 | 
|---|
| 108 |   #endif
 | 
|---|
| 109 |         emit atomRemoved(_atom);
 | 
|---|
| 110 |         break;
 | 
|---|
| 111 |       }
 | 
|---|
| 112 |       case World::SelectionChanged:
 | 
|---|
| 113 |       {
 | 
|---|
| 114 |   #ifdef LOG_OBSERVER
 | 
|---|
| 115 |         observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that selection has changed.";
 | 
|---|
| 116 |   #endif
 | 
|---|
| 117 |         emit worldSelectionChanged();
 | 
|---|
| 118 |         break;
 | 
|---|
| 119 |       }
 | 
|---|
| 120 |       case World::MoleculeInserted:
 | 
|---|
| 121 |       {
 | 
|---|
| 122 |         const molecule *_molecule = World::getInstance().lastChanged<molecule>();
 | 
|---|
| 123 |   #ifdef LOG_OBSERVER
 | 
|---|
| 124 |         observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that molecule "+toString(_molecule->getId())+" has been removed.";
 | 
|---|
| 125 |   #endif
 | 
|---|
| 126 |         emit moleculeInserted(_molecule);
 | 
|---|
| 127 |         break;
 | 
|---|
| 128 |       }
 | 
|---|
| 129 |       case World::MoleculeRemoved:
 | 
|---|
| 130 |       {
 | 
|---|
| 131 |         const molecule *_molecule = World::getInstance().lastChanged<molecule>();
 | 
|---|
| 132 |   #ifdef LOG_OBSERVER
 | 
|---|
| 133 |         observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that molecule "+toString(_molecule->getId())+" has been removed.";
 | 
|---|
| 134 |   #endif
 | 
|---|
| 135 |         emit moleculeRemoved(_molecule);
 | 
|---|
| 136 |         break;
 | 
|---|
| 137 |       }
 | 
|---|
| 138 |       default:
 | 
|---|
| 139 |         ASSERT(0, "GLWorldView::recieveNotification() - we cannot get here.");
 | 
|---|
| 140 |         break;
 | 
|---|
| 141 |     }
 | 
|---|
| 142 |   } else if (dynamic_cast<AtomObservable *>(publisher) != NULL) {
 | 
|---|
| 143 |     switch (notification->getChannelNo()) {
 | 
|---|
| 144 |       case AtomObservable::PositionChanged:
 | 
|---|
| 145 |       {
 | 
|---|
| 146 |         const atom *_atom = dynamic_cast<const atom *>(publisher);
 | 
|---|
| 147 |     #ifdef LOG_OBSERVER
 | 
|---|
| 148 |         observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that atom "+toString(_atom->getId())+" has changed its position.";
 | 
|---|
| 149 |     #endif
 | 
|---|
| 150 |         emit changed();
 | 
|---|
| 151 |         break;
 | 
|---|
| 152 |       }
 | 
|---|
| 153 |       default:
 | 
|---|
| 154 |         ASSERT(0, "GLWorldView::recieveNotification() - we cannot get here.");
 | 
|---|
| 155 |         break;
 | 
|---|
| 156 |     }
 | 
|---|
| 157 |   } else
 | 
|---|
| 158 |     ASSERT(0, "GLWorldView::recieveNotification() - received notification from unknown source.");
 | 
|---|
| 159 | }
 | 
|---|
| 160 | 
 | 
|---|
| 161 | void GLWorldView::initializeGL(QGLPainter *painter)
 | 
|---|
| 162 | {
 | 
|---|
| 163 |   worldscene->initialize(this, painter);
 | 
|---|
| 164 |   changesPresent = false;
 | 
|---|
| 165 | }
 | 
|---|
| 166 | 
 | 
|---|
| 167 | void GLWorldView::paintGL(QGLPainter *painter)
 | 
|---|
| 168 | {
 | 
|---|
| 169 |   if (changesPresent) {
 | 
|---|
| 170 |     initializeGL(painter);
 | 
|---|
| 171 |     changesPresent = false;
 | 
|---|
| 172 |   }
 | 
|---|
| 173 |   worldscene->draw(painter);
 | 
|---|
| 174 | }
 | 
|---|
| 175 | 
 | 
|---|
| 176 | void GLWorldView::keyPressEvent(QKeyEvent *e)
 | 
|---|
| 177 | {
 | 
|---|
| 178 |   if (e->key() == Qt::Key_Tab) {
 | 
|---|
| 179 |     // The Tab key turns the ShowPicking option on and off,
 | 
|---|
| 180 |     // which helps show what the pick buffer looks like.
 | 
|---|
| 181 |     setOption(QGLView::ShowPicking, ((options() & QGLView::ShowPicking) == 0));
 | 
|---|
| 182 |     updateGL();
 | 
|---|
| 183 |   }
 | 
|---|
| 184 |   QGLView::keyPressEvent(e);
 | 
|---|
| 185 | }
 | 
|---|
| 186 | 
 | 
|---|
| 187 | void GLWorldView::changeSignalled()
 | 
|---|
| 188 | {
 | 
|---|
| 189 |   changesPresent = true;
 | 
|---|
| 190 | }
 | 
|---|
| 191 | 
 | 
|---|
| 192 | 
 | 
|---|
| 193 | //#include <GL/glu.h>
 | 
|---|
| 194 | //#include <QtGui/qslider.h>
 | 
|---|
| 195 | //#include <QtGui/qevent.h>
 | 
|---|
| 196 | //
 | 
|---|
| 197 | //#include "ui_dialoglight.h"
 | 
|---|
| 198 | //
 | 
|---|
| 199 | //#include "CodePatterns/MemDebug.hpp"
 | 
|---|
| 200 | //
 | 
|---|
| 201 | //#include <iostream>
 | 
|---|
| 202 | //#include <boost/shared_ptr.hpp>
 | 
|---|
| 203 | //
 | 
|---|
| 204 | //#include "LinearAlgebra/Line.hpp"
 | 
|---|
| 205 | //#include "Atom/atom.hpp"
 | 
|---|
| 206 | //#include "Bond/bond.hpp"
 | 
|---|
| 207 | //#include "Element/element.hpp"
 | 
|---|
| 208 | //#include "molecule.hpp"
 | 
|---|
| 209 | //#include "Element/periodentafel.hpp"
 | 
|---|
| 210 | //#include "World.hpp"
 | 
|---|
| 211 | //
 | 
|---|
| 212 | //#if defined(Q_CC_MSVC)
 | 
|---|
| 213 | //#pragma warning(disable:4305) // init: truncation from const double to float
 | 
|---|
| 214 | //#endif
 | 
|---|
| 215 | //
 | 
|---|
| 216 | //
 | 
|---|
| 217 | //GLMoleculeView::GLMoleculeView(QWidget *parent) :
 | 
|---|
| 218 | //  QGLWidget(parent), Observer("GLMoleculeView"), X(Vector(1,0,0)), Y(Vector(0,1,0)), Z(Vector(0,0,1))
 | 
|---|
| 219 | //{
 | 
|---|
| 220 | //    xRot = yRot = zRot = 0.0;    // default object rotation
 | 
|---|
| 221 | //    scale = 5.;      // default object scale
 | 
|---|
| 222 | //    object = 0;
 | 
|---|
| 223 | //    LightPosition[0] = 0.0f;
 | 
|---|
| 224 | //    LightPosition[1] = 2.0f;
 | 
|---|
| 225 | //    LightPosition[2] = 2.0f;
 | 
|---|
| 226 | //    LightPosition[3] = 0.0f;
 | 
|---|
| 227 | //    LightDiffuse[0] = 0.5f;
 | 
|---|
| 228 | //    LightDiffuse[1] = 0.5f;
 | 
|---|
| 229 | //    LightDiffuse[2] = 0.5f;
 | 
|---|
| 230 | //    LightDiffuse[3] = 0.0f;
 | 
|---|
| 231 | //    LightAmbient[0] = 0.0f;
 | 
|---|
| 232 | //    LightAmbient[1] = 0.0f;
 | 
|---|
| 233 | //    LightAmbient[2] = 0.0f;
 | 
|---|
| 234 | //    LightAmbient[3] = 0.0f;
 | 
|---|
| 235 | //
 | 
|---|
| 236 | //    SelectionColor[0] = 0;
 | 
|---|
| 237 | //    SelectionColor[1] = 128;
 | 
|---|
| 238 | //    SelectionColor[2] = 128;
 | 
|---|
| 239 | //
 | 
|---|
| 240 | //    MultiViewEnabled = true;
 | 
|---|
| 241 | //
 | 
|---|
| 242 | //    isSignaller = false;
 | 
|---|
| 243 | //
 | 
|---|
| 244 | //    World::getInstance().signOn(this);
 | 
|---|
| 245 | //}
 | 
|---|
| 246 | //
 | 
|---|
| 247 | ///** Destructor of GLMoleculeView.
 | 
|---|
| 248 | // * Free's the CallList.
 | 
|---|
| 249 | // */
 | 
|---|
| 250 | //GLMoleculeView::~GLMoleculeView()
 | 
|---|
| 251 | //{
 | 
|---|
| 252 | //    makeCurrent();
 | 
|---|
| 253 | //    glDeleteLists( object, 1 );
 | 
|---|
| 254 | //
 | 
|---|
| 255 | //    World::getInstance().signOff(this);
 | 
|---|
| 256 | //}
 | 
|---|
| 257 | //
 | 
|---|
| 258 | ///** Paints the conents of the OpenGL window.
 | 
|---|
| 259 | // * Clears the GL buffers, enables lighting and depth.
 | 
|---|
| 260 | // * Window is either quartered (if GLMoleculeView::MultiViewEnabled) and xy, xz, yz planar views
 | 
|---|
| 261 | // * are added. Uses the CallList, constructed during InitializeGL().
 | 
|---|
| 262 | // */
 | 
|---|
| 263 | //void GLMoleculeView::paintGL()
 | 
|---|
| 264 | //{
 | 
|---|
| 265 | //  Vector spot;
 | 
|---|
| 266 | //
 | 
|---|
| 267 | //  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 | 
|---|
| 268 | //  glShadeModel(GL_SMOOTH);            // Enable Smooth Shading
 | 
|---|
| 269 | //  glEnable(GL_LIGHTING);              // Enable Light One
 | 
|---|
| 270 | //  glEnable(GL_DEPTH_TEST);            // Enables Depth Testing
 | 
|---|
| 271 | //  glDepthFunc(GL_LEQUAL);              // The Type Of Depth Testing To Do
 | 
|---|
| 272 | //  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);      // Really Nice Perspective Calculations
 | 
|---|
| 273 | //
 | 
|---|
| 274 | //  // 3d viewport
 | 
|---|
| 275 | //  if (MultiViewEnabled)
 | 
|---|
| 276 | //    glViewport( 0, 0, (GLint)width/2, (GLint)height/2 );
 | 
|---|
| 277 | //  else
 | 
|---|
| 278 | //    glViewport( 0, 0, (GLint)width, (GLint)height );
 | 
|---|
| 279 | //  glMatrixMode( GL_PROJECTION );
 | 
|---|
| 280 | //  glLoadIdentity();
 | 
|---|
| 281 | //  glFrustum( -1.0, 1.0, -1.0, 1.0, 1.0, 50.0 );
 | 
|---|
| 282 | //  glMatrixMode( GL_MODELVIEW );
 | 
|---|
| 283 | //  glLoadIdentity();
 | 
|---|
| 284 | //
 | 
|---|
| 285 | //  // calculate point of view and direction
 | 
|---|
| 286 | //  glTranslated(position[0],position[1],position[2]);
 | 
|---|
| 287 | //  glTranslated(0.0, 0.0, -scale);
 | 
|---|
| 288 | //  glRotated(xRot, 1.0, 0.0, 0.0);
 | 
|---|
| 289 | //  glRotated(yRot, 0.0, 1.0, 0.0);
 | 
|---|
| 290 | //  glRotated(zRot, 0.0, 0.0, 1.0);
 | 
|---|
| 291 | //
 | 
|---|
| 292 | //  // render scene
 | 
|---|
| 293 | //  glCallList(object);
 | 
|---|
| 294 | //
 | 
|---|
| 295 | //  // enable light
 | 
|---|
| 296 | //  glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);       // Setup The Ambient Light
 | 
|---|
| 297 | //  glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);       // Setup The Diffuse Light
 | 
|---|
| 298 | //  glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);      // Position The Light
 | 
|---|
| 299 | //  glEnable(GL_LIGHT1);              // Enable Light One
 | 
|---|
| 300 | //
 | 
|---|
| 301 | //  if (MultiViewEnabled) {
 | 
|---|
| 302 | //    // xy view port
 | 
|---|
| 303 | //    glViewport( (GLint)width/2, 0, (GLint)width/2, (GLint)height/2 );
 | 
|---|
| 304 | //    glMatrixMode( GL_PROJECTION );
 | 
|---|
| 305 | //    glLoadIdentity();
 | 
|---|
| 306 | //    glScalef(1./scale, 1./scale,1./scale);
 | 
|---|
| 307 | //    glOrtho(0, width/2, 0, height/2, 0,0);
 | 
|---|
| 308 | //    glMatrixMode( GL_MODELVIEW );
 | 
|---|
| 309 | //    glLoadIdentity();
 | 
|---|
| 310 | //
 | 
|---|
| 311 | //    // calculate point of view and direction
 | 
|---|
| 312 | //    view = position;
 | 
|---|
| 313 | //    spot = Vector(0.,0.,scale);
 | 
|---|
| 314 | //    top = Vector(0.,1.,0.);
 | 
|---|
| 315 | //    gluLookAt(
 | 
|---|
| 316 | //        spot[0], spot[1], spot[2],
 | 
|---|
| 317 | //        view[0], view[1], view[2],
 | 
|---|
| 318 | //        top[0], top[1], top[2]);
 | 
|---|
| 319 | //
 | 
|---|
| 320 | //    // enable light
 | 
|---|
| 321 | //    glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);       // Setup The Ambient Light
 | 
|---|
| 322 | //    glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);       // Setup The Diffuse Light
 | 
|---|
| 323 | //    glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);      // Position The Light
 | 
|---|
| 324 | //    glEnable(GL_LIGHT1);              // Enable Light One
 | 
|---|
| 325 | //
 | 
|---|
| 326 | //    // render scene
 | 
|---|
| 327 | //    glCallList(object);
 | 
|---|
| 328 | //
 | 
|---|
| 329 | //    // xz viewport
 | 
|---|
| 330 | //    glViewport( 0, (GLint)height/2, (GLint)width/2, (GLint)height/2 );
 | 
|---|
| 331 | //    glMatrixMode( GL_PROJECTION );
 | 
|---|
| 332 | //    glLoadIdentity();
 | 
|---|
| 333 | //    glScalef(1./scale, 1./scale,1./scale);
 | 
|---|
| 334 | //    glOrtho(0, width/2, 0, height/2, 0,0);
 | 
|---|
| 335 | //    glMatrixMode( GL_MODELVIEW );
 | 
|---|
| 336 | //    glLoadIdentity();
 | 
|---|
| 337 | //
 | 
|---|
| 338 | //    // calculate point of view and direction
 | 
|---|
| 339 | //    view = position;
 | 
|---|
| 340 | //    spot = Vector(0.,scale,0.);
 | 
|---|
| 341 | //    top = Vector(1.,0.,0.);
 | 
|---|
| 342 | //    gluLookAt(
 | 
|---|
| 343 | //        spot[0], spot[1], spot[2],
 | 
|---|
| 344 | //        view[0], view[1], view[2],
 | 
|---|
| 345 | //        top[0], top[1], top[2]);
 | 
|---|
| 346 | //
 | 
|---|
| 347 | //    // enable light
 | 
|---|
| 348 | //    glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);       // Setup The Ambient Light
 | 
|---|
| 349 | //    glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);       // Setup The Diffuse Light
 | 
|---|
| 350 | //    glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);      // Position The Light
 | 
|---|
| 351 | //    glEnable(GL_LIGHT1);              // Enable Light One
 | 
|---|
| 352 | //
 | 
|---|
| 353 | //    // render scene
 | 
|---|
| 354 | //    glCallList(object);
 | 
|---|
| 355 | //
 | 
|---|
| 356 | //    //yz viewport
 | 
|---|
| 357 | //    glViewport( (GLint)width/2, (GLint)height/2, (GLint)width/2, (GLint)height/2 );
 | 
|---|
| 358 | //    glMatrixMode( GL_PROJECTION );
 | 
|---|
| 359 | //    glLoadIdentity();
 | 
|---|
| 360 | //    glScalef(1./scale, 1./scale,1./scale);
 | 
|---|
| 361 | //    glOrtho(0, width/2, 0, height/2, 0,0);
 | 
|---|
| 362 | //    glMatrixMode( GL_MODELVIEW );
 | 
|---|
| 363 | //    glLoadIdentity();
 | 
|---|
| 364 | //
 | 
|---|
| 365 | //    // calculate point of view and direction
 | 
|---|
| 366 | //    view= position;
 | 
|---|
| 367 | //    spot = Vector(scale,0.,0.);
 | 
|---|
| 368 | //    top = Vector(0.,1.,0.);
 | 
|---|
| 369 | //    gluLookAt(
 | 
|---|
| 370 | //        spot[0], spot[1], spot[2],
 | 
|---|
| 371 | //        view[0], view[1], view[2],
 | 
|---|
| 372 | //        top[0], top[1], top[2]);
 | 
|---|
| 373 | //
 | 
|---|
| 374 | //    // enable light
 | 
|---|
| 375 | //    glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);       // Setup The Ambient Light
 | 
|---|
| 376 | //    glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);       // Setup The Diffuse Light
 | 
|---|
| 377 | //    glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);      // Position The Light
 | 
|---|
| 378 | //    glEnable(GL_LIGHT1);              // Enable Light One
 | 
|---|
| 379 | //
 | 
|---|
| 380 | //    // render scene
 | 
|---|
| 381 | //    glCallList(object);
 | 
|---|
| 382 | //  }
 | 
|---|
| 383 | //  //CoordinatesBar->setText( QString ("X: %1, Y: %2, Z: %3").arg(position[0]).arg(position[1]).arg(position[2]) );
 | 
|---|
| 384 | //}
 | 
|---|
| 385 | //
 | 
|---|
| 386 | ////void polarView{GLdouble distance, GLdouble twist,
 | 
|---|
| 387 | ////   GLdouble elevation, GLdouble azimuth)
 | 
|---|
| 388 | ////{
 | 
|---|
| 389 | ////      glTranslated(0.0, 0.0, -distance);
 | 
|---|
| 390 | ////      glRotated(-twist, 0.0, 0.0, 1.0);
 | 
|---|
| 391 | ////      glRotated(-elevation, 1.0, 0.0, 0.0);
 | 
|---|
| 392 | ////      glRotated(azimuth, 0.0, 0.0, 1.0);
 | 
|---|
| 393 | ////}
 | 
|---|
| 394 | //
 | 
|---|
| 395 | ///** Make a sphere.
 | 
|---|
| 396 | // * \param x position
 | 
|---|
| 397 | // * \param radius radius
 | 
|---|
| 398 | // * \param color[3] color rgb values
 | 
|---|
| 399 | // */
 | 
|---|
| 400 | //void GLMoleculeView::makeSphere(const Vector &x, double radius, const unsigned char color[3])
 | 
|---|
| 401 | //{
 | 
|---|
| 402 | //  float blueMaterial[] = { 255./(float)color[0], 255./(float)color[1], 255./(float)color[2], 1 };  // need to recast from [0,255] with integers into [0,1] with floats
 | 
|---|
| 403 | //  GLUquadricObj* q = gluNewQuadric ();
 | 
|---|
| 404 | //  gluQuadricOrientation(q, GLU_OUTSIDE);
 | 
|---|
| 405 | //
 | 
|---|
| 406 | //  std::cout << "Setting sphere at " << x << " with color r"
 | 
|---|
| 407 | //      << (int)color[0] << ",g" << (int)color[1] << ",b" << (int)color[2] << "." << endl;
 | 
|---|
| 408 | //
 | 
|---|
| 409 | //  glPushMatrix();
 | 
|---|
| 410 | //  glTranslatef( x[0], x[1], x[2]);
 | 
|---|
| 411 | ////  glRotatef( xRot, 1.0, 0.0, 0.0);
 | 
|---|
| 412 | ////  glRotatef( yRot, 0.0, 1.0, 0.0);
 | 
|---|
| 413 | ////  glRotatef( zRot, 0.0, 0.0, 1.0);
 | 
|---|
| 414 | //  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blueMaterial);
 | 
|---|
| 415 | //  gluSphere (q, (GLdouble)radius, 10, 10);
 | 
|---|
| 416 | //  glPopMatrix();
 | 
|---|
| 417 | //}
 | 
|---|
| 418 | //
 | 
|---|
| 419 | ///** Make a cylinder.
 | 
|---|
| 420 | // * \param x origin
 | 
|---|
| 421 | // * \param y direction
 | 
|---|
| 422 | // * \param radius thickness
 | 
|---|
| 423 | // * \param height length
 | 
|---|
| 424 | // * \color[3] color rgb values
 | 
|---|
| 425 | // */
 | 
|---|
| 426 | //void GLMoleculeView::makeCylinder(const Vector &x, const Vector &y, double radius, double height, const unsigned char color[3])
 | 
|---|
| 427 | //{
 | 
|---|
| 428 | //  float blueMaterial[] = { 255./(float)color[0], 255./(float)color[1], 255./(float)color[2], 1 };
 | 
|---|
| 429 | //  GLUquadricObj* q = gluNewQuadric ();
 | 
|---|
| 430 | //  gluQuadricOrientation(q, GLU_OUTSIDE);
 | 
|---|
| 431 | //  Vector a,b;
 | 
|---|
| 432 | //  Vector OtherAxis;
 | 
|---|
| 433 | //  double alpha;
 | 
|---|
| 434 | //  a = x - y;
 | 
|---|
| 435 | //  // construct rotation axis
 | 
|---|
| 436 | //  b = a;
 | 
|---|
| 437 | //  b.VectorProduct(Z);
 | 
|---|
| 438 | //  Line axis(zeroVec, b);
 | 
|---|
| 439 | //  // calculate rotation angle
 | 
|---|
| 440 | //  alpha = a.Angle(Z);
 | 
|---|
| 441 | //  // construct other axis to check right-hand rule
 | 
|---|
| 442 | //  OtherAxis = b;
 | 
|---|
| 443 | //  OtherAxis.VectorProduct(Z);
 | 
|---|
| 444 | //  // assure right-hand rule for the rotation
 | 
|---|
| 445 | //  if (a.ScalarProduct(OtherAxis) < MYEPSILON)
 | 
|---|
| 446 | //    alpha = M_PI-alpha;
 | 
|---|
| 447 | //  // check
 | 
|---|
| 448 | //  Vector a_rotated = axis.rotateVector(a, alpha);
 | 
|---|
| 449 | //  std::cout << "Setting cylinder from "// << x << " to " << y
 | 
|---|
| 450 | //      << a << " to " << a_rotated << " around " << b << " by " << alpha/M_PI*180. << ", respectively, "
 | 
|---|
| 451 | //      << " with color r"
 | 
|---|
| 452 | //      << (int)color[0] << ",g" << (int)color[1] << ",b" << (int)color[2] << "." << endl;
 | 
|---|
| 453 | //
 | 
|---|
| 454 | //  glPushMatrix();
 | 
|---|
| 455 | //  glTranslatef( x[0], x[1], x[2]);
 | 
|---|
| 456 | //  glRotatef( alpha/M_PI*180., b[0], b[1], b[2]);
 | 
|---|
| 457 | //  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blueMaterial);
 | 
|---|
| 458 | //  gluCylinder (q, (GLdouble)radius, (GLdouble)radius, (GLdouble)height, 10, 10);
 | 
|---|
| 459 | //  glPopMatrix();
 | 
|---|
| 460 | //}
 | 
|---|
| 461 | //
 | 
|---|
| 462 | ///** Defines the display CallList.
 | 
|---|
| 463 | // * Goes through all molecules and their atoms and adds spheres for atoms and cylinders
 | 
|---|
| 464 | // * for bonds. Heeds GLMoleculeView::SelectedAtom and GLMoleculeView::SelectedMolecule.
 | 
|---|
| 465 | // */
 | 
|---|
| 466 | //void GLMoleculeView::initializeGL()
 | 
|---|
| 467 | //{
 | 
|---|
| 468 | //  double x[3] = {-1, 0, -10};
 | 
|---|
| 469 | //  unsigned char white[3] = {255,255,255};
 | 
|---|
| 470 | //  Vector Position, OtherPosition;
 | 
|---|
| 471 | //  QSize window = size();
 | 
|---|
| 472 | //  width = window.width();
 | 
|---|
| 473 | //  height = window.height();
 | 
|---|
| 474 | //  std::cout << "Setting width to " << width << " and height to " << height << std::endl;
 | 
|---|
| 475 | //  GLfloat shininess[] = { 0.0 };
 | 
|---|
| 476 | //  GLfloat specular[] = { 0, 0, 0, 1 };
 | 
|---|
| 477 | //  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);     // Let OpenGL clear to black
 | 
|---|
| 478 | //  object = glGenLists(1);
 | 
|---|
| 479 | //  glNewList( object, GL_COMPILE );
 | 
|---|
| 480 | //  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
 | 
|---|
| 481 | //  glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
 | 
|---|
| 482 | //
 | 
|---|
| 483 | //  const std::vector<molecule*> &molecules = World::getInstance().getAllMolecules();
 | 
|---|
| 484 | //
 | 
|---|
| 485 | //  if (molecules.size() > 0) {
 | 
|---|
| 486 | //    for (std::vector<molecule*>::const_iterator Runner = molecules.begin();
 | 
|---|
| 487 | //        Runner != molecules.end();
 | 
|---|
| 488 | //        Runner++) {
 | 
|---|
| 489 | //      for (molecule::const_iterator atomiter = (*Runner)->begin();
 | 
|---|
| 490 | //          atomiter != (*Runner)->end();
 | 
|---|
| 491 | //          ++atomiter) {
 | 
|---|
| 492 | //        // create atom
 | 
|---|
| 493 | //        const element *ptr = (*atomiter)->getType();
 | 
|---|
| 494 | //        boost::shared_ptr<Vector> MolCenter((*Runner)->DetermineCenterOfGravity());
 | 
|---|
| 495 | //        Position = (*atomiter)->getPosition() - *MolCenter;
 | 
|---|
| 496 | //        const unsigned char* color = NULL;
 | 
|---|
| 497 | //        if ((World::getInstance().isSelected(*atomiter)) || (World::getInstance().isSelected((*Runner))))
 | 
|---|
| 498 | //          color = SelectionColor;
 | 
|---|
| 499 | //        else
 | 
|---|
| 500 | //          color = ptr->getColor();
 | 
|---|
| 501 | //        makeSphere(Position, ptr->getVanDerWaalsRadius()*0.25, color);
 | 
|---|
| 502 | //
 | 
|---|
| 503 | //        // create bonds
 | 
|---|
| 504 | //        const BondList &bonds = (*atomiter)->getListOfBonds();
 | 
|---|
| 505 | //        for (BondList::const_iterator bonditer = bonds.begin();
 | 
|---|
| 506 | //            bonditer != bonds.end();
 | 
|---|
| 507 | //            ++bonditer) {
 | 
|---|
| 508 | //          if ((*bonditer)->leftatom->getId() == (*atomiter)->getId()) {
 | 
|---|
| 509 | //            Position = (*bonditer)->leftatom->getPosition() - *MolCenter;
 | 
|---|
| 510 | //            OtherPosition = (*bonditer)->rightatom->getPosition() - *MolCenter;
 | 
|---|
| 511 | //            const double distance = sqrt(Position.DistanceSquared(OtherPosition))/2.;
 | 
|---|
| 512 | //            const unsigned char *color1 = (*bonditer)->leftatom->getType()->getColor();
 | 
|---|
| 513 | //            const unsigned char *color2 = (*bonditer)->rightatom->getType()->getColor();
 | 
|---|
| 514 | //            makeCylinder(Position, OtherPosition, 0.1, distance, color1);
 | 
|---|
| 515 | //            makeCylinder(OtherPosition, Position, 0.1, distance, color2);
 | 
|---|
| 516 | //          }
 | 
|---|
| 517 | //        }
 | 
|---|
| 518 | //      }
 | 
|---|
| 519 | //    }
 | 
|---|
| 520 | //  } else {
 | 
|---|
| 521 | //    makeSphere( x,1, white);
 | 
|---|
| 522 | //  }
 | 
|---|
| 523 | //  glEndList();
 | 
|---|
| 524 | //}
 | 
|---|
| 525 | //
 | 
|---|
| 526 | //
 | 
|---|
| 527 | ///* ================================== SLOTS ============================== */
 | 
|---|
| 528 | //
 | 
|---|
| 529 | ///** Initializes some public variables.
 | 
|---|
| 530 | // * \param *ptr pointer to QLabel statusbar
 | 
|---|
| 531 | // */
 | 
|---|
| 532 | //void GLMoleculeView::init(QLabel *ptr)
 | 
|---|
| 533 | //{
 | 
|---|
| 534 | //  StatusBar = ptr;
 | 
|---|
| 535 | //}
 | 
|---|
| 536 | //
 | 
|---|
| 537 | ///** Initializes the viewport statusbar.
 | 
|---|
| 538 | // * \param *ptr pointer to QLabel for showing view pointcoordinates.
 | 
|---|
| 539 | // */
 | 
|---|
| 540 | //void GLMoleculeView::initCoordinates(QLabel *ptr)
 | 
|---|
| 541 | //{
 | 
|---|
| 542 | //  CoordinatesBar = ptr;
 | 
|---|
| 543 | //}
 | 
|---|
| 544 | //
 | 
|---|
| 545 | ///** Slot to be called when to initialize GLMoleculeView::MolData.
 | 
|---|
| 546 | // */
 | 
|---|
| 547 | //void GLMoleculeView::createView( )
 | 
|---|
| 548 | //{
 | 
|---|
| 549 | //  initializeGL();
 | 
|---|
| 550 | //  updateGL();
 | 
|---|
| 551 | //}
 | 
|---|
| 552 | //
 | 
|---|
| 553 | ///** Slot of window is resized.
 | 
|---|
| 554 | // * Copies new width and height to GLMoleculeView::width and GLMoleculeView::height and calls updateGL().
 | 
|---|
| 555 | // * \param w new width of window
 | 
|---|
| 556 | // * \param h new height of window
 | 
|---|
| 557 | // */
 | 
|---|
| 558 | //void GLMoleculeView::resizeGL( int w, int h )
 | 
|---|
| 559 | //{
 | 
|---|
| 560 | //  width = w;
 | 
|---|
| 561 | //  height = h;
 | 
|---|
| 562 | //  updateGL();
 | 
|---|
| 563 | //}
 | 
|---|
| 564 | //
 | 
|---|
| 565 | ///** Sets x rotation angle.
 | 
|---|
| 566 | // * sets GLMoleculeView::xRot and calls updateGL().
 | 
|---|
| 567 | // * \param degrees new rotation angle in degrees
 | 
|---|
| 568 | // */
 | 
|---|
| 569 | //void GLMoleculeView::setXRotation( int degrees )
 | 
|---|
| 570 | //{
 | 
|---|
| 571 | //  xRot = (GLfloat)(degrees % 360);
 | 
|---|
| 572 | //  updateGL();
 | 
|---|
| 573 | //}
 | 
|---|
| 574 | //
 | 
|---|
| 575 | //
 | 
|---|
| 576 | ///** Sets y rotation angle.
 | 
|---|
| 577 | // * sets GLMoleculeView::yRot and calls updateGL().
 | 
|---|
| 578 | // * \param degrees new rotation angle in degrees
 | 
|---|
| 579 | // */
 | 
|---|
| 580 | //void GLMoleculeView::setYRotation( int degrees )
 | 
|---|
| 581 | //{
 | 
|---|
| 582 | //  yRot = (GLfloat)(degrees % 360);
 | 
|---|
| 583 | //  updateGL();
 | 
|---|
| 584 | //}
 | 
|---|
| 585 | //
 | 
|---|
| 586 | //
 | 
|---|
| 587 | ///** Sets z rotation angle.
 | 
|---|
| 588 | // * sets GLMoleculeView::zRot and calls updateGL().
 | 
|---|
| 589 | // * \param degrees new rotation angle in degrees
 | 
|---|
| 590 | // */
 | 
|---|
| 591 | //void GLMoleculeView::setZRotation( int degrees )
 | 
|---|
| 592 | //{
 | 
|---|
| 593 | //  zRot = (GLfloat)(degrees % 360);
 | 
|---|
| 594 | //  updateGL();
 | 
|---|
| 595 | //}
 | 
|---|
| 596 | //
 | 
|---|
| 597 | ///** Sets the scale of the scene.
 | 
|---|
| 598 | // * sets GLMoleculeView::scale and calls updateGL().
 | 
|---|
| 599 | // * \param distance distance divided by 100 is the new scale
 | 
|---|
| 600 | // */
 | 
|---|
| 601 | //void GLMoleculeView::setScale( int distance )
 | 
|---|
| 602 | //{
 | 
|---|
| 603 | //  scale = (GLfloat)(distance / 100.);
 | 
|---|
| 604 | //  updateGL();
 | 
|---|
| 605 | //}
 | 
|---|
| 606 | //
 | 
|---|
| 607 | ///** Update the ambient light.
 | 
|---|
| 608 | // * \param light[4] light strength per axis and position (w)
 | 
|---|
| 609 | // */
 | 
|---|
| 610 | //void GLMoleculeView::setLightAmbient( int *light )
 | 
|---|
| 611 | //{
 | 
|---|
| 612 | //  for(int i=0;i<4;i++)
 | 
|---|
| 613 | //    LightAmbient[i] = light[i];
 | 
|---|
| 614 | //  updateGL();
 | 
|---|
| 615 | //}
 | 
|---|
| 616 | //
 | 
|---|
| 617 | ///** Update the diffuse light.
 | 
|---|
| 618 | // * \param light[4] light strength per axis and position (w)
 | 
|---|
| 619 | // */
 | 
|---|
| 620 | //void GLMoleculeView::setLightDiffuse( int *light )
 | 
|---|
| 621 | //{
 | 
|---|
| 622 | //  for(int i=0;i<4;i++)
 | 
|---|
| 623 | //    LightDiffuse[i] = light[i];
 | 
|---|
| 624 | //  updateGL();
 | 
|---|
| 625 | //}
 | 
|---|
| 626 | //
 | 
|---|
| 627 | ///** Update the position of light.
 | 
|---|
| 628 | // * \param light[4] light strength per axis and position (w)
 | 
|---|
| 629 | // */
 | 
|---|
| 630 | //void GLMoleculeView::setLightPosition( int *light )
 | 
|---|
| 631 | //{
 | 
|---|
| 632 | //  for(int i=0;i<4;i++)
 | 
|---|
| 633 | //    LightPosition[i] = light[i];
 | 
|---|
| 634 | //  updateGL();
 | 
|---|
| 635 | //}
 | 
|---|
| 636 | //
 | 
|---|
| 637 | ///** Toggles the boolean GLMoleculeView::MultiViewEnabled.
 | 
|---|
| 638 | // * Flips the boolean and calls updateGL().
 | 
|---|
| 639 | // */
 | 
|---|
| 640 | //void GLMoleculeView::toggleMultiViewEnabled ( )
 | 
|---|
| 641 | //{
 | 
|---|
| 642 | //  MultiViewEnabled = !MultiViewEnabled;
 | 
|---|
| 643 | //  cout << "Setting MultiView to " << MultiViewEnabled << "." << endl;
 | 
|---|
| 644 | //  updateGL();
 | 
|---|
| 645 | //}
 | 
|---|
| 646 | //
 | 
|---|
| 647 | ///** Launch a dialog to configure the lights.
 | 
|---|
| 648 | // */
 | 
|---|
| 649 | //void GLMoleculeView::createDialogLight()
 | 
|---|
| 650 | //{
 | 
|---|
| 651 | ////  Ui_DialogLight *Lights = new Ui_DialogLight();
 | 
|---|
| 652 | ////  if (Lights == NULL)
 | 
|---|
| 653 | ////    return;
 | 
|---|
| 654 | ////  // Set up the dynamic dialog here
 | 
|---|
| 655 | ////  QLineEdit *Field = NULL;
 | 
|---|
| 656 | ////  Field = Lights->findChild<QLineEdit *>("LightPositionX");
 | 
|---|
| 657 | ////  if (Field) Field->setText( QString("%1").arg(LightPosition[0]) );
 | 
|---|
| 658 | ////  Field = Lights->findChild<QLineEdit *>("LightPositionY");
 | 
|---|
| 659 | ////  if (Field) Field->setText( QString("%1").arg(LightPosition[1]) );
 | 
|---|
| 660 | ////  Field = Lights->findChild<QLineEdit *>("LightPositionZ");
 | 
|---|
| 661 | ////  if (Field) Field->setText( QString("%1").arg(LightPosition[2]) );
 | 
|---|
| 662 | ////  Field = Lights->findChild<QLineEdit *>("LightPositionW");
 | 
|---|
| 663 | ////  if (Field) Field->setText( QString("%1").arg(LightPosition[3]) );
 | 
|---|
| 664 | ////
 | 
|---|
| 665 | ////  Field = Lights->findChild<QLineEdit *>("LightDiffuseX");
 | 
|---|
| 666 | ////  if (Field) Field->setText( QString("%1").arg(LightDiffuse[0]) );
 | 
|---|
| 667 | ////  Field = Lights->findChild<QLineEdit *>("LightDiffuseY");
 | 
|---|
| 668 | ////  if (Field) Field->setText( QString("%1").arg(LightDiffuse[1]) );
 | 
|---|
| 669 | ////  Field = Lights->findChild<QLineEdit *>("LightDiffuseZ");
 | 
|---|
| 670 | ////  if (Field) Field->setText( QString("%1").arg(LightDiffuse[2]) );
 | 
|---|
| 671 | ////  Field = Lights->findChild<QLineEdit *>("LightDiffuseW");
 | 
|---|
| 672 | ////  if (Field) Field->setText( QString("%1").arg(LightDiffuse[3]) );
 | 
|---|
| 673 | ////
 | 
|---|
| 674 | ////  Field = Lights->findChild<QLineEdit *>("LightAmbientX");
 | 
|---|
| 675 | ////  if (Field) Field->setText( QString("%1").arg(LightAmbient[0]) );
 | 
|---|
| 676 | ////  Field = Lights->findChild<QLineEdit *>("LightAmbientY");
 | 
|---|
| 677 | ////  if (Field) Field->setText( QString("%1").arg(LightAmbient[1]) );
 | 
|---|
| 678 | ////  Field = Lights->findChild<QLineEdit *>("LightAmbientZ");
 | 
|---|
| 679 | ////  if (Field) Field->setText( QString("%1").arg(LightAmbient[2]) );
 | 
|---|
| 680 | ////  Field = Lights->findChild<QLineEdit *>("LightAmbientW");
 | 
|---|
| 681 | ////  if (Field) Field->setText( QString("%1").arg(LightAmbient[3]) );
 | 
|---|
| 682 | ////
 | 
|---|
| 683 | ////  if ( Lights->exec() ) {
 | 
|---|
| 684 | ////    //cout << "User accepted.\n";
 | 
|---|
| 685 | ////    // The user accepted, act accordingly
 | 
|---|
| 686 | ////    Field = Lights->findChild<QLineEdit *>("LightPositionX");
 | 
|---|
| 687 | ////    if (Field) LightPosition[0] = Field->text().toDouble();
 | 
|---|
| 688 | ////    Field = Lights->findChild<QLineEdit *>("LightPositionY");
 | 
|---|
| 689 | ////    if (Field) LightPosition[1] = Field->text().toDouble();
 | 
|---|
| 690 | ////    Field = Lights->findChild<QLineEdit *>("LightPositionZ");
 | 
|---|
| 691 | ////    if (Field) LightPosition[2] = Field->text().toDouble();
 | 
|---|
| 692 | ////    Field = Lights->findChild<QLineEdit *>("LightPositionW");
 | 
|---|
| 693 | ////    if (Field) LightPosition[3] = Field->text().toDouble();
 | 
|---|
| 694 | ////
 | 
|---|
| 695 | ////    Field = Lights->findChild<QLineEdit *>("LightDiffuseX");
 | 
|---|
| 696 | ////    if (Field) LightDiffuse[0] = Field->text().toDouble();
 | 
|---|
| 697 | ////    Field = Lights->findChild<QLineEdit *>("LightDiffuseY");
 | 
|---|
| 698 | ////    if (Field) LightDiffuse[1] = Field->text().toDouble();
 | 
|---|
| 699 | ////    Field = Lights->findChild<QLineEdit *>("LightDiffuseZ");
 | 
|---|
| 700 | ////    if (Field) LightDiffuse[2] = Field->text().toDouble();
 | 
|---|
| 701 | ////    Field = Lights->findChild<QLineEdit *>("LightDiffuseW");
 | 
|---|
| 702 | ////    if (Field) LightDiffuse[3] = Field->text().toDouble();
 | 
|---|
| 703 | ////
 | 
|---|
| 704 | ////    Field = Lights->findChild<QLineEdit *>("LightAmbientX");
 | 
|---|
| 705 | ////    if (Field) LightAmbient[0] = Field->text().toDouble();
 | 
|---|
| 706 | ////    Field = Lights->findChild<QLineEdit *>("LightAmbientY");
 | 
|---|
| 707 | ////    if (Field) LightAmbient[1] = Field->text().toDouble();
 | 
|---|
| 708 | ////    Field = Lights->findChild<QLineEdit *>("LightAmbientZ");
 | 
|---|
| 709 | ////    if (Field) LightAmbient[2] = Field->text().toDouble();
 | 
|---|
| 710 | ////    Field = Lights->findChild<QLineEdit *>("LightAmbientW");
 | 
|---|
| 711 | ////    if (Field) LightAmbient[3] = Field->text().toDouble();
 | 
|---|
| 712 | ////    updateGL();
 | 
|---|
| 713 | ////  } else {
 | 
|---|
| 714 | ////    //cout << "User reclined.\n";
 | 
|---|
| 715 | ////  }
 | 
|---|
| 716 | ////  delete(Lights);
 | 
|---|
| 717 | //}
 | 
|---|
| 718 | //
 | 
|---|
| 719 | ///** Slot for event of pressed mouse button.
 | 
|---|
| 720 | // * Switch discerns between buttons and stores position of event in GLMoleculeView::LeftButtonPos,
 | 
|---|
| 721 | // * GLMoleculeView::MiddleButtonPos or GLMoleculeView::RightButtonPos.
 | 
|---|
| 722 | // * \param *event structure containing information of the event
 | 
|---|
| 723 | // */
 | 
|---|
| 724 | //void GLMoleculeView::mousePressEvent(QMouseEvent *event)
 | 
|---|
| 725 | //{
 | 
|---|
| 726 | //  std::cout << "MousePressEvent." << endl;
 | 
|---|
| 727 | //  QPoint *pos = NULL;
 | 
|---|
| 728 | //  switch (event->button()) {  // get the right array
 | 
|---|
| 729 | //    case Qt::LeftButton:
 | 
|---|
| 730 | //      pos = &LeftButtonPos;
 | 
|---|
| 731 | //      std::cout << "Left Button" << endl;
 | 
|---|
| 732 | //      break;
 | 
|---|
| 733 | //    case Qt::MidButton:
 | 
|---|
| 734 | //      pos = &MiddleButtonPos;
 | 
|---|
| 735 | //      std::cout << "Middle Button" << endl;
 | 
|---|
| 736 | //      break;
 | 
|---|
| 737 | //    case Qt::RightButton:
 | 
|---|
| 738 | //      pos = &RightButtonPos;
 | 
|---|
| 739 | //      std::cout << "Right Button" << endl;
 | 
|---|
| 740 | //      break;
 | 
|---|
| 741 | //    default:
 | 
|---|
| 742 | //      break;
 | 
|---|
| 743 | //  }
 | 
|---|
| 744 | //  if (pos) {    // store the position
 | 
|---|
| 745 | //    pos->setX(event->pos().x());
 | 
|---|
| 746 | //    pos->setY(event->pos().y());
 | 
|---|
| 747 | //    std::cout << "Stored src position is (" << pos->x() << "," << pos->y() << ")." << endl;
 | 
|---|
| 748 | //  } else {
 | 
|---|
| 749 | //    std::cout << "pos is NULL." << endl;
 | 
|---|
| 750 | //  }
 | 
|---|
| 751 | //}
 | 
|---|
| 752 | //
 | 
|---|
| 753 | ///** Slot for event of pressed mouse button.
 | 
|---|
| 754 | // * Switch discerns between buttons:
 | 
|---|
| 755 | // * -# Left Button: Rotates the view of the GLMoleculeView, relative to GLMoleculeView::LeftButtonPos.
 | 
|---|
| 756 | // * -# Middle Button: nothing
 | 
|---|
| 757 | // * -# Right Button: Shifts the selected molecule or atom, relative to GLMoleculeView::RightButtonPos.
 | 
|---|
| 758 | // * \param *event structure containing information of the event
 | 
|---|
| 759 | // */
 | 
|---|
| 760 | //void GLMoleculeView::mouseReleaseEvent(QMouseEvent *event)
 | 
|---|
| 761 | //{
 | 
|---|
| 762 | //  std::cout << "MouseReleaseEvent." << endl;
 | 
|---|
| 763 | //  QPoint *srcpos = NULL;
 | 
|---|
| 764 | //  QPoint destpos = event->pos();
 | 
|---|
| 765 | //  int Width = (MultiViewEnabled) ? width/2 : width;
 | 
|---|
| 766 | //  int Height = (MultiViewEnabled) ? height/2 : height;
 | 
|---|
| 767 | //  std::cout << "Received dest position is (" << destpos.x() << "," << destpos.y() << ")." << endl;
 | 
|---|
| 768 | //  switch (event->button()) {  // get the right array
 | 
|---|
| 769 | //    case Qt::LeftButton:  // LeftButton rotates the view
 | 
|---|
| 770 | //      srcpos = &LeftButtonPos;
 | 
|---|
| 771 | //      std::cout << "Left Button" << endl;
 | 
|---|
| 772 | //      if (srcpos) {    // subtract the position and act
 | 
|---|
| 773 | //        std::cout << "Stored src position is (" << srcpos->x() << "," << srcpos->y() << ")." << endl;
 | 
|---|
| 774 | //        destpos -= *srcpos;
 | 
|---|
| 775 | //        std::cout << "Resulting diff position is (" << destpos.x() << "," << destpos.y() << ")." << endl;
 | 
|---|
| 776 | //        std::cout << "Width and Height are " << Width << "," << Height << "." << endl;
 | 
|---|
| 777 | //
 | 
|---|
| 778 | //        int pos = (int)floor((double)srcpos->x()/(double)Width) + ((int)floor((double)srcpos->y()/(double)Height))*2;
 | 
|---|
| 779 | //        if ((MultiViewEnabled) && (pos != 2)) { // means four regions, and we are in a shifting one
 | 
|---|
| 780 | //          // switch between three regions
 | 
|---|
| 781 | //          // decide into which of the four screens the initial click has been made
 | 
|---|
| 782 | //          std::cout << "Position is " << pos << "." << endl;
 | 
|---|
| 783 | //          switch(pos) {
 | 
|---|
| 784 | //            case 0:  // lower left = xz
 | 
|---|
| 785 | //              position[0] += -destpos.y()/100.;
 | 
|---|
| 786 | //              position[2] += destpos.x()/100.;
 | 
|---|
| 787 | //              break;
 | 
|---|
| 788 | //            case 1: // lower right = yz
 | 
|---|
| 789 | //              position[1] += -destpos.y()/100.;
 | 
|---|
| 790 | //              position[2] += -destpos.x()/100.;
 | 
|---|
| 791 | //              break;
 | 
|---|
| 792 | //            case 2:  // upper left = projected
 | 
|---|
| 793 | //              std::cout << "This is impossible: Shifting in the projected region, we should rotate!." << endl;
 | 
|---|
| 794 | //              break;
 | 
|---|
| 795 | //            case 3:  // upper right = xy
 | 
|---|
| 796 | //              position[0] += destpos.x()/100.;
 | 
|---|
| 797 | //              position[1] += -destpos.y()/100.;
 | 
|---|
| 798 | //              break;
 | 
|---|
| 799 | //            default:
 | 
|---|
| 800 | //              std::cout << "click was not in any of the four regions." << endl;
 | 
|---|
| 801 | //              break;
 | 
|---|
| 802 | //          }
 | 
|---|
| 803 | //          updateGL();
 | 
|---|
| 804 | //        } else { // we are in rotation region
 | 
|---|
| 805 | //          QWidget *Parent = parentWidget();
 | 
|---|
| 806 | //          QSlider *sliderX = Parent->findChild<QSlider *>("sliderX");
 | 
|---|
| 807 | //          QSlider *sliderY = Parent->findChild<QSlider *>("sliderY");
 | 
|---|
| 808 | //          std::cout << sliderX << " and " << sliderY << endl;
 | 
|---|
| 809 | //          if (sliderX) {
 | 
|---|
| 810 | //            int xrange = sliderX->maximum() - sliderX->minimum();
 | 
|---|
| 811 | //            double xValue = ((destpos.x() + Width) % Width);
 | 
|---|
| 812 | //            xValue *= (double)xrange/(double)Width;
 | 
|---|
| 813 | //            xValue += sliderX->value();
 | 
|---|
| 814 | //            int xvalue = (int) xValue % xrange;
 | 
|---|
| 815 | //            std::cout << "Setting x to " << xvalue << " within range " << xrange << "." << endl;
 | 
|---|
| 816 | //            setXRotation(xvalue);
 | 
|---|
| 817 | //            sliderX->setValue(xvalue);
 | 
|---|
| 818 | //          } else {
 | 
|---|
| 819 | //            std::cout << "sliderX is NULL." << endl;
 | 
|---|
| 820 | //          }
 | 
|---|
| 821 | //          if (sliderY) {
 | 
|---|
| 822 | //            int yrange = sliderY->maximum() - sliderY->minimum();
 | 
|---|
| 823 | //            double yValue = ((destpos.y() + Height) % Height);
 | 
|---|
| 824 | //            yValue *= (double)yrange/(double)Height;
 | 
|---|
| 825 | //            yValue += sliderY->value();
 | 
|---|
| 826 | //            int yvalue = (int) yValue % yrange;
 | 
|---|
| 827 | //            std::cout << "Setting y to " << yvalue << " within range " << yrange << "." << endl;
 | 
|---|
| 828 | //            setYRotation(yvalue);
 | 
|---|
| 829 | //            sliderY->setValue(yvalue);
 | 
|---|
| 830 | //          } else {
 | 
|---|
| 831 | //            std::cout << "sliderY is NULL." << endl;
 | 
|---|
| 832 | //          }
 | 
|---|
| 833 | //        }
 | 
|---|
| 834 | //      } else {
 | 
|---|
| 835 | //        std::cout << "srcpos is NULL." << endl;
 | 
|---|
| 836 | //      }
 | 
|---|
| 837 | //      break;
 | 
|---|
| 838 | //
 | 
|---|
| 839 | //    case Qt::MidButton: // MiddleButton has no function so far
 | 
|---|
| 840 | //      srcpos = &MiddleButtonPos;
 | 
|---|
| 841 | //      std::cout << "Middle Button" << endl;
 | 
|---|
| 842 | //      if (srcpos) {    // subtract the position and act
 | 
|---|
| 843 | //        QWidget *Parent = parentWidget();
 | 
|---|
| 844 | //        QSlider *sliderZ = Parent->findChild<QSlider *>("sliderZ");
 | 
|---|
| 845 | //        QSlider *sliderScale = Parent->findChild<QSlider *>("sliderScale");
 | 
|---|
| 846 | //        std::cout << sliderZ << " and " << sliderScale << endl;
 | 
|---|
| 847 | //        std::cout << "Stored src position is (" << srcpos->x() << "," << srcpos->y() << ")." << endl;
 | 
|---|
| 848 | //        destpos -= *srcpos;
 | 
|---|
| 849 | //        std::cout << "Resulting diff position is (" << destpos.x() << "," << destpos.y() << ")." << endl;
 | 
|---|
| 850 | //        std::cout << "Width and Height are " << Width << "," << Height << "." << endl;
 | 
|---|
| 851 | //        if (sliderZ) {
 | 
|---|
| 852 | //          int xrange = sliderZ->maximum() - sliderZ->minimum();
 | 
|---|
| 853 | //          double xValue = ((destpos.x() + Width) % Width);
 | 
|---|
| 854 | //          xValue *= (double)xrange/(double)Width;
 | 
|---|
| 855 | //          xValue += sliderZ->value();
 | 
|---|
| 856 | //          int xvalue = (int) xValue % xrange;
 | 
|---|
| 857 | //          std::cout << "Setting x to " << xvalue << " within range " << xrange << "." << endl;
 | 
|---|
| 858 | //          setZRotation(xvalue);
 | 
|---|
| 859 | //          sliderZ->setValue(xvalue);
 | 
|---|
| 860 | //        } else {
 | 
|---|
| 861 | //          std::cout << "sliderZ is NULL." << endl;
 | 
|---|
| 862 | //        }
 | 
|---|
| 863 | //        if (sliderScale) {
 | 
|---|
| 864 | //          int yrange = sliderScale->maximum() - sliderScale->minimum();
 | 
|---|
| 865 | //          double yValue = ((destpos.y() + Height) % Height);
 | 
|---|
| 866 | //          yValue *= (double)yrange/(double)Height;
 | 
|---|
| 867 | //          yValue += sliderScale->value();
 | 
|---|
| 868 | //          int yvalue = (int) yValue % yrange;
 | 
|---|
| 869 | //          std::cout << "Setting y to " << yvalue << " within range " << yrange << "." << endl;
 | 
|---|
| 870 | //          setScale(yvalue);
 | 
|---|
| 871 | //          sliderScale->setValue(yvalue);
 | 
|---|
| 872 | //        } else {
 | 
|---|
| 873 | //          std::cout << "sliderScale is NULL." << endl;
 | 
|---|
| 874 | //        }
 | 
|---|
| 875 | //      } else {
 | 
|---|
| 876 | //        std::cout << "srcpos is NULL." << endl;
 | 
|---|
| 877 | //      }
 | 
|---|
| 878 | //      break;
 | 
|---|
| 879 | //      break;
 | 
|---|
| 880 | //
 | 
|---|
| 881 | //    case Qt::RightButton:  // RightButton moves eitstdher the selected molecule or atom
 | 
|---|
| 882 | //      srcpos = &RightButtonPos;
 | 
|---|
| 883 | //      std::cout << "Right Button" << endl;
 | 
|---|
| 884 | //      if (srcpos) {    // subtract the position and act
 | 
|---|
| 885 | //        std::cout << "Stored src position is (" << srcpos->x() << "," << srcpos->y() << ")." << endl;
 | 
|---|
| 886 | //        destpos -= *srcpos;
 | 
|---|
| 887 | //        std::cout << "Resulting diff position is (" << destpos.x() << "," << destpos.y() << ")." << endl;
 | 
|---|
| 888 | //        std::cout << "Width and Height are " << Width << "," << Height << "." << endl;
 | 
|---|
| 889 | //        if (MultiViewEnabled) {
 | 
|---|
| 890 | //          // which vector to change
 | 
|---|
| 891 | //          Vector SelectedPosition;
 | 
|---|
| 892 | //          const std::vector<atom*> &SelectedAtoms = World::getInstance().getSelectedAtoms();
 | 
|---|
| 893 | //          const std::vector<molecule*> &SelectedMolecules = World::getInstance().getSelectedMolecules();
 | 
|---|
| 894 | //          if (SelectedMolecules.size()) {
 | 
|---|
| 895 | //            if (SelectedAtoms.size())
 | 
|---|
| 896 | //              SelectedPosition = (*SelectedAtoms.begin())->getPosition();
 | 
|---|
| 897 | //            else
 | 
|---|
| 898 | //              SelectedPosition = (*(*SelectedMolecules.begin())->begin())->getPosition();
 | 
|---|
| 899 | //          }
 | 
|---|
| 900 | //          // decide into which of the four screens the initial click has been made
 | 
|---|
| 901 | //          int pos = (int)floor((double)srcpos->x()/(double)Width) + ((int)floor((double)srcpos->y()/(double)Height))*2;
 | 
|---|
| 902 | //          if (!SelectedPosition.IsZero()) {
 | 
|---|
| 903 | //            std::cout << "Position is " << pos << "." << endl;
 | 
|---|
| 904 | //            switch(pos) {
 | 
|---|
| 905 | //              case 0:  // lower left = xz
 | 
|---|
| 906 | //                SelectedPosition[0] += -destpos.y()/100.;
 | 
|---|
| 907 | //                SelectedPosition[2] += destpos.x()/100.;
 | 
|---|
| 908 | //                break;
 | 
|---|
| 909 | //              case 1: // lower right = yz
 | 
|---|
| 910 | //                SelectedPosition[1] += -destpos.y()/100.;
 | 
|---|
| 911 | //                SelectedPosition[2] += -destpos.x()/100.;
 | 
|---|
| 912 | //                break;
 | 
|---|
| 913 | //              case 2:  // upper left = projected
 | 
|---|
| 914 | //                SelectedPosition[0] += destpos.x()/100.;
 | 
|---|
| 915 | //                SelectedPosition[1] += destpos.y()/100.;
 | 
|---|
| 916 | //                SelectedPosition[2] += destpos.y()/100.;
 | 
|---|
| 917 | //                break;
 | 
|---|
| 918 | //              case 3:  // upper right = xy
 | 
|---|
| 919 | //                SelectedPosition[0] += destpos.x()/100.;
 | 
|---|
| 920 | //                SelectedPosition[1] += -destpos.y()/100.;
 | 
|---|
| 921 | //                break;
 | 
|---|
| 922 | //              default:
 | 
|---|
| 923 | //                std::cout << "click was not in any of the four regions." << endl;
 | 
|---|
| 924 | //                break;
 | 
|---|
| 925 | //            }
 | 
|---|
| 926 | //          } else {
 | 
|---|
| 927 | //            std::cout << "Nothing selected." << endl;
 | 
|---|
| 928 | //          }
 | 
|---|
| 929 | //          // update Tables
 | 
|---|
| 930 | //          if (SelectedMolecules.size()) {
 | 
|---|
| 931 | //            isSignaller = true;
 | 
|---|
| 932 | //            if (SelectedAtoms.size())
 | 
|---|
| 933 | //              emit notifyAtomChanged( (*SelectedMolecules.begin()), (*SelectedAtoms.begin()), AtomPosition);
 | 
|---|
| 934 | //            else
 | 
|---|
| 935 | //              emit notifyMoleculeChanged( (*SelectedMolecules.begin()), MoleculePosition );
 | 
|---|
| 936 | //          }
 | 
|---|
| 937 | //          // update graphic
 | 
|---|
| 938 | //          initializeGL();
 | 
|---|
| 939 | //          updateGL();
 | 
|---|
| 940 | //        } else {
 | 
|---|
| 941 | //          cout << "MultiView is not enabled." << endl;
 | 
|---|
| 942 | //        }
 | 
|---|
| 943 | //      } else {
 | 
|---|
| 944 | //        cout << "srcpos is NULL." << endl;
 | 
|---|
| 945 | //      }
 | 
|---|
| 946 | //  break;
 | 
|---|
| 947 | //
 | 
|---|
| 948 | //    default:
 | 
|---|
| 949 | //      break;
 | 
|---|
| 950 | //  }
 | 
|---|
| 951 | //}
 | 
|---|
| 952 | //
 | 
|---|
| 953 | ///* ======================================== SLOTS ================================ */
 | 
|---|
| 954 | //
 | 
|---|
| 955 | ///** Hear announcement of selected molecule.
 | 
|---|
| 956 | // * \param *mol pointer to selected molecule
 | 
|---|
| 957 | // */
 | 
|---|
| 958 | //void GLMoleculeView::hearMoleculeSelected(molecule *mol)
 | 
|---|
| 959 | //{
 | 
|---|
| 960 | //  if (isSignaller) { // if we emitted the signal, return
 | 
|---|
| 961 | //    isSignaller = false;
 | 
|---|
| 962 | //    return;
 | 
|---|
| 963 | //  }
 | 
|---|
| 964 | //  initializeGL();
 | 
|---|
| 965 | //  updateGL();
 | 
|---|
| 966 | //};
 | 
|---|
| 967 | //
 | 
|---|
| 968 | ///** Hear announcement of selected atom.
 | 
|---|
| 969 | // * \param *mol pointer to molecule containing atom
 | 
|---|
| 970 | // * \param *Walker pointer to selected atom
 | 
|---|
| 971 | // */
 | 
|---|
| 972 | //void GLMoleculeView::hearAtomSelected(molecule *mol, atom *Walker)
 | 
|---|
| 973 | //{
 | 
|---|
| 974 | //  if (isSignaller) { // if we emitted the signal, return
 | 
|---|
| 975 | //    isSignaller = false;
 | 
|---|
| 976 | //    return;
 | 
|---|
| 977 | //  }
 | 
|---|
| 978 | //  initializeGL();
 | 
|---|
| 979 | //  updateGL();
 | 
|---|
| 980 | //};
 | 
|---|
| 981 | //
 | 
|---|
| 982 | ///** Hear announcement of changed molecule.
 | 
|---|
| 983 | // * \param *mol pointer to changed molecule
 | 
|---|
| 984 | // * \param type of change
 | 
|---|
| 985 | // */
 | 
|---|
| 986 | //void GLMoleculeView::hearMoleculeChanged(molecule *mol, enum ChangesinMolecule type)
 | 
|---|
| 987 | //{
 | 
|---|
| 988 | //  if (isSignaller) { // if we emitted the signal, return
 | 
|---|
| 989 | //    isSignaller = false;
 | 
|---|
| 990 | //    return;
 | 
|---|
| 991 | //  }
 | 
|---|
| 992 | //  initializeGL();
 | 
|---|
| 993 | //  updateGL();
 | 
|---|
| 994 | //};
 | 
|---|
| 995 | //
 | 
|---|
| 996 | ///** Hear announcement of changed atom.
 | 
|---|
| 997 | // * \param *mol pointer to molecule containing atom
 | 
|---|
| 998 | // * \param *Walker pointer to changed atom
 | 
|---|
| 999 | // * \param type type of change
 | 
|---|
| 1000 | // */
 | 
|---|
| 1001 | //void GLMoleculeView::hearAtomChanged(molecule *mol, atom *Walker, enum ChangesinAtom type)
 | 
|---|
| 1002 | //{
 | 
|---|
| 1003 | //  if (isSignaller) { // if we emitted the signal, return
 | 
|---|
| 1004 | //    isSignaller = false;
 | 
|---|
| 1005 | //    return;
 | 
|---|
| 1006 | //  }
 | 
|---|
| 1007 | //  initializeGL();
 | 
|---|
| 1008 | //  updateGL();
 | 
|---|
| 1009 | //};
 | 
|---|
| 1010 | //
 | 
|---|
| 1011 | ///** Hear announcement of changed element.
 | 
|---|
| 1012 | // * \param *Runner pointer to changed element
 | 
|---|
| 1013 | // * \param type of change
 | 
|---|
| 1014 | // */
 | 
|---|
| 1015 | //void GLMoleculeView::hearElementChanged(element *Runner, enum ChangesinElement type)
 | 
|---|
| 1016 | //{
 | 
|---|
| 1017 | //  if (isSignaller) { // if we emitted the signal, return
 | 
|---|
| 1018 | //    isSignaller = false;
 | 
|---|
| 1019 | //    return;
 | 
|---|
| 1020 | //  }
 | 
|---|
| 1021 | //  switch(type) {
 | 
|---|
| 1022 | //    default:
 | 
|---|
| 1023 | //    case ElementName:
 | 
|---|
| 1024 | //    case ElementSymbol:
 | 
|---|
| 1025 | //    case ElementMass:
 | 
|---|
| 1026 | //    case ElementValence:
 | 
|---|
| 1027 | //    case ElementZ:
 | 
|---|
| 1028 | //      break;
 | 
|---|
| 1029 | //    case ElementCovalent:
 | 
|---|
| 1030 | //    case ElementVanderWaals:
 | 
|---|
| 1031 | //      initializeGL();
 | 
|---|
| 1032 | //      updateGL();
 | 
|---|
| 1033 | //      break;
 | 
|---|
| 1034 | //  }
 | 
|---|
| 1035 | //};
 | 
|---|
| 1036 | //
 | 
|---|
| 1037 | ///** Hear announcement of added molecule.
 | 
|---|
| 1038 | // * \param *mol pointer to added molecule
 | 
|---|
| 1039 | // */
 | 
|---|
| 1040 | //void GLMoleculeView::hearMoleculeAdded(molecule *mol)
 | 
|---|
| 1041 | //{
 | 
|---|
| 1042 | //  if (isSignaller) { // if we emitted the signal, return
 | 
|---|
| 1043 | //    isSignaller = false;
 | 
|---|
| 1044 | //    return;
 | 
|---|
| 1045 | //  }
 | 
|---|
| 1046 | //  initializeGL();
 | 
|---|
| 1047 | //  updateGL();
 | 
|---|
| 1048 | //};
 | 
|---|
| 1049 | //
 | 
|---|
| 1050 | ///** Hear announcement of added atom.
 | 
|---|
| 1051 | // * \param *mol pointer to molecule containing atom
 | 
|---|
| 1052 | // * \param *Walker pointer to added atom
 | 
|---|
| 1053 | // */
 | 
|---|
| 1054 | //void GLMoleculeView::hearAtomAdded(molecule *mol, atom *Walker)
 | 
|---|
| 1055 | //{
 | 
|---|
| 1056 | //  if (isSignaller) { // if we emitted the signal, return
 | 
|---|
| 1057 | //    isSignaller = false;
 | 
|---|
| 1058 | //    return;
 | 
|---|
| 1059 | //  }
 | 
|---|
| 1060 | //  initializeGL();
 | 
|---|
| 1061 | //  updateGL();
 | 
|---|
| 1062 | //};
 | 
|---|
| 1063 | //
 | 
|---|
| 1064 | ///** Hear announcement of removed molecule.
 | 
|---|
| 1065 | // * \param *mol pointer to removed molecule
 | 
|---|
| 1066 | // */
 | 
|---|
| 1067 | //void GLMoleculeView::hearMoleculeRemoved(molecule *mol)
 | 
|---|
| 1068 | //{
 | 
|---|
| 1069 | //  if (isSignaller) { // if we emitted the signal, return
 | 
|---|
| 1070 | //    isSignaller = false;
 | 
|---|
| 1071 | //    return;
 | 
|---|
| 1072 | //  }
 | 
|---|
| 1073 | //  initializeGL();
 | 
|---|
| 1074 | //  updateGL();
 | 
|---|
| 1075 | //};
 | 
|---|
| 1076 | //
 | 
|---|
| 1077 | ///** Hear announcement of removed atom.
 | 
|---|
| 1078 | // * \param *mol pointer to molecule containing atom
 | 
|---|
| 1079 | // * \param *Walker pointer to removed atom
 | 
|---|
| 1080 | // */
 | 
|---|
| 1081 | //void GLMoleculeView::hearAtomRemoved(molecule *mol, atom *Walker)
 | 
|---|
| 1082 | //{
 | 
|---|
| 1083 | //  if (isSignaller) { // if we emitted the signal, return
 | 
|---|
| 1084 | //    isSignaller = false;
 | 
|---|
| 1085 | //    return;
 | 
|---|
| 1086 | //  }
 | 
|---|
| 1087 | //  initializeGL();
 | 
|---|
| 1088 | //  updateGL();
 | 
|---|
| 1089 | //};
 | 
|---|
| 1090 | //
 | 
|---|
| 1091 | //void GLMoleculeView::update(Observable *publisher)
 | 
|---|
| 1092 | //{
 | 
|---|
| 1093 | //  initializeGL();
 | 
|---|
| 1094 | //  updateGL();
 | 
|---|
| 1095 | //}
 | 
|---|
| 1096 | //
 | 
|---|
| 1097 | ///**
 | 
|---|
| 1098 | // * This method is called when a special named change
 | 
|---|
| 1099 | // * of the Observable occured
 | 
|---|
| 1100 | // */
 | 
|---|
| 1101 | //void GLMoleculeView::recieveNotification(Observable *publisher, Notification_ptr notification)
 | 
|---|
| 1102 | //{
 | 
|---|
| 1103 | //  initializeGL();
 | 
|---|
| 1104 | //  updateGL();
 | 
|---|
| 1105 | //}
 | 
|---|
| 1106 | //
 | 
|---|
| 1107 | ///**
 | 
|---|
| 1108 | // * This method is called when the observed object is destroyed.
 | 
|---|
| 1109 | // */
 | 
|---|
| 1110 | //void GLMoleculeView::subjectKilled(Observable *publisher)
 | 
|---|
| 1111 | //{
 | 
|---|
| 1112 | //
 | 
|---|
| 1113 | //}
 | 
|---|
| 1114 | //
 | 
|---|
| 1115 | //
 | 
|---|
| 1116 | //// new stuff
 | 
|---|
| 1117 | //
 | 
|---|
| 1118 | ///** Returns the ref to the Material for element No \a from the map.
 | 
|---|
| 1119 | // *
 | 
|---|
| 1120 | // * \note We create a new one if the element is missing.
 | 
|---|
| 1121 | // *
 | 
|---|
| 1122 | // * @param no element no
 | 
|---|
| 1123 | // * @return ref to QGLMaterial
 | 
|---|
| 1124 | // */
 | 
|---|
| 1125 | //QGLMaterial* GLMoleculeView::getMaterial(size_t no)
 | 
|---|
| 1126 | //{
 | 
|---|
| 1127 | //  if (ElementNoMaterialMap.find(no) != ElementNoMaterialMap.end()){
 | 
|---|
| 1128 | //    // get present one
 | 
|---|
| 1129 | //
 | 
|---|
| 1130 | //  } else {
 | 
|---|
| 1131 | //    ASSERT( (no >= 0) && (no < MAX_ELEMENTS),
 | 
|---|
| 1132 | //        "GLMoleculeView::getMaterial() - Element no "+toString(no)+" is invalid.");
 | 
|---|
| 1133 | //    // create new one
 | 
|---|
| 1134 | //    LOG(1, "Creating new material for element "+toString(no)+".");
 | 
|---|
| 1135 | //    QGLMaterial *newmaterial = new QGLMaterial(this);
 | 
|---|
| 1136 | //    periodentafel *periode = World::getInstance().getPeriode();
 | 
|---|
| 1137 | //    element *desiredelement = periode->FindElement(no);
 | 
|---|
| 1138 | //    ASSERT(desiredelement != NULL,
 | 
|---|
| 1139 | //        "GLMoleculeView::getMaterial() - desired element "+toString(no)+" not present in periodentafel.");
 | 
|---|
| 1140 | //    const unsigned char* color = desiredelement->getColor();
 | 
|---|
| 1141 | //    newmaterial->setAmbientColor( QColor(color[0], color[1], color[2]) );
 | 
|---|
| 1142 | //    newmaterial->setSpecularColor( QColor(60, 60, 60) );
 | 
|---|
| 1143 | //    newmaterial->setShininess( QColor(128) );
 | 
|---|
| 1144 | //    ElementNoMaterialMap.insert( no, newmaterial);
 | 
|---|
| 1145 | //  }
 | 
|---|
| 1146 | //}
 | 
|---|
| 1147 | //
 | 
|---|
| 1148 | //QGLSceneNode* GLMoleculeView::getAtom(size_t no)
 | 
|---|
| 1149 | //{
 | 
|---|
| 1150 | //  // first some sensibility checks
 | 
|---|
| 1151 | //  ASSERT(World::getInstance().getAtom(AtomById(no)) != NULL,
 | 
|---|
| 1152 | //      "GLMoleculeView::getAtom() - desired atom "
 | 
|---|
| 1153 | //      +toString(no)+" not present in the World.");
 | 
|---|
| 1154 | //  ASSERT(AtomsinSceneMap.find(no) != AtomsinSceneMap.end(),
 | 
|---|
| 1155 | //      "GLMoleculeView::getAtom() - desired atom "
 | 
|---|
| 1156 | //      +toString(no)+" not present in the AtomsinSceneMap.");
 | 
|---|
| 1157 | //
 | 
|---|
| 1158 | //  return AtomsinSceneMap[no];
 | 
|---|
| 1159 | //}
 | 
|---|
| 1160 | //
 | 
|---|
| 1161 | //QGLSceneNode* GLMoleculeView::getBond(size_t leftno, size_t rightno)
 | 
|---|
| 1162 | //{
 | 
|---|
| 1163 | //  // first some sensibility checks
 | 
|---|
| 1164 | //  ASSERT(World::getInstance().getAtom(AtomById(leftno)) != NULL,
 | 
|---|
| 1165 | //      "GLMoleculeView::getAtom() - desired atom "
 | 
|---|
| 1166 | //      +toString(leftno)+" of bond not present in the World.");
 | 
|---|
| 1167 | //  ASSERT(World::getInstance().getAtom(AtomById(rightno)) != NULL,
 | 
|---|
| 1168 | //      "GLMoleculeView::getAtom() - desired atom "
 | 
|---|
| 1169 | //      +toString(rightno)+" of bond not present in the World.");
 | 
|---|
| 1170 | //  ASSERT(AtomsinSceneMap.find(leftno) != AtomsinSceneMap.end(),
 | 
|---|
| 1171 | //      "GLMoleculeView::getAtom() - desired atom "
 | 
|---|
| 1172 | //      +toString(leftno)+" of bond not present in the AtomsinSceneMap.");
 | 
|---|
| 1173 | //  ASSERT(AtomsinSceneMap.find(rightno) != AtomsinSceneMap.end(),
 | 
|---|
| 1174 | //      "GLMoleculeView::getAtom() - desired atom "
 | 
|---|
| 1175 | //      +toString(rightno)+" of bond not present in the AtomsinSceneMap.");
 | 
|---|
| 1176 | //  ASSERT(leftno == rightno,
 | 
|---|
| 1177 | //      "GLMoleculeView::getAtom() - bond must not be between the same atom: "
 | 
|---|
| 1178 | //      +toString(leftno)+" == "+toString(rightno)+".");
 | 
|---|
| 1179 | //
 | 
|---|
| 1180 | //  // then return with smaller index first
 | 
|---|
| 1181 | //  if (leftno > rightno)
 | 
|---|
| 1182 | //    return AtomsinSceneMap[ make_pair(rightno, leftno) ];
 | 
|---|
| 1183 | //  else
 | 
|---|
| 1184 | //    return AtomsinSceneMap[ make_pair(leftno, rightno) ];
 | 
|---|
| 1185 | //}
 | 
|---|
| 1186 | //
 | 
|---|