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