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