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