Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Views/Qt4/Qt3D/GLWorldView.cpp

    r5a9f4c r592d42  
    752752  emit hoverChanged(_atom);
    753753}
     754
     755
     756//#include <GL/glu.h>
     757//#include <QtGui/qslider.h>
     758//#include <QtGui/qevent.h>
     759//
     760//#include "ui_dialoglight.h"
     761//
     762//#include "CodePatterns/MemDebug.hpp"
     763//
     764//#include <iostream>
     765//#include <boost/shared_ptr.hpp>
     766//
     767//#include "LinearAlgebra/Line.hpp"
     768//#include "Atom/atom.hpp"
     769//#include "Bond/bond.hpp"
     770//#include "Element/element.hpp"
     771//#include "molecule.hpp"
     772//#include "Element/periodentafel.hpp"
     773//#include "World.hpp"
     774//
     775//#if defined(Q_CC_MSVC)
     776//#pragma warning(disable:4305) // init: truncation from const double to float
     777//#endif
     778//
     779//
     780//GLMoleculeView::GLMoleculeView(QWidget *parent) :
     781//  QGLWidget(parent), Observer("GLMoleculeView"), X(Vector(1,0,0)), Y(Vector(0,1,0)), Z(Vector(0,0,1))
     782//{
     783//    xRot = yRot = zRot = 0.0;    // default object rotation
     784//    scale = 5.;      // default object scale
     785//    object = 0;
     786//    LightPosition[0] = 0.0f;
     787//    LightPosition[1] = 2.0f;
     788//    LightPosition[2] = 2.0f;
     789//    LightPosition[3] = 0.0f;
     790//    LightDiffuse[0] = 0.5f;
     791//    LightDiffuse[1] = 0.5f;
     792//    LightDiffuse[2] = 0.5f;
     793//    LightDiffuse[3] = 0.0f;
     794//    LightAmbient[0] = 0.0f;
     795//    LightAmbient[1] = 0.0f;
     796//    LightAmbient[2] = 0.0f;
     797//    LightAmbient[3] = 0.0f;
     798//
     799//    SelectionColor[0] = 0;
     800//    SelectionColor[1] = 128;
     801//    SelectionColor[2] = 128;
     802//
     803//    MultiViewEnabled = true;
     804//
     805//    isSignaller = false;
     806//
     807//    World::getInstance().signOn(this);
     808//}
     809//
     810///** Destructor of GLMoleculeView.
     811// * Free's the CallList.
     812// */
     813//GLMoleculeView::~GLMoleculeView()
     814//{
     815//    makeCurrent();
     816//    glDeleteLists( object, 1 );
     817//
     818//    World::getInstance().signOff(this);
     819//}
     820//
     821///** Paints the conents of the OpenGL window.
     822// * Clears the GL buffers, enables lighting and depth.
     823// * Window is either quartered (if GLMoleculeView::MultiViewEnabled) and xy, xz, yz planar views
     824// * are added. Uses the CallList, constructed during InitializeGL().
     825// */
     826//void GLMoleculeView::paintGL()
     827//{
     828//  Vector spot;
     829//
     830//  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     831//  glShadeModel(GL_SMOOTH);            // Enable Smooth Shading
     832//  glEnable(GL_LIGHTING);              // Enable Light One
     833//  glEnable(GL_DEPTH_TEST);            // Enables Depth Testing
     834//  glDepthFunc(GL_LEQUAL);              // The Type Of Depth Testing To Do
     835//  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);      // Really Nice Perspective Calculations
     836//
     837//  // 3d viewport
     838//  if (MultiViewEnabled)
     839//    glViewport( 0, 0, (GLint)width/2, (GLint)height/2 );
     840//  else
     841//    glViewport( 0, 0, (GLint)width, (GLint)height );
     842//  glMatrixMode( GL_PROJECTION );
     843//  glLoadIdentity();
     844//  glFrustum( -1.0, 1.0, -1.0, 1.0, 1.0, 50.0 );
     845//  glMatrixMode( GL_MODELVIEW );
     846//  glLoadIdentity();
     847//
     848//  // calculate point of view and direction
     849//  glTranslated(position[0],position[1],position[2]);
     850//  glTranslated(0.0, 0.0, -scale);
     851//  glRotated(xRot, 1.0, 0.0, 0.0);
     852//  glRotated(yRot, 0.0, 1.0, 0.0);
     853//  glRotated(zRot, 0.0, 0.0, 1.0);
     854//
     855//  // render scene
     856//  glCallList(object);
     857//
     858//  // enable light
     859//  glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);       // Setup The Ambient Light
     860//  glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);       // Setup The Diffuse Light
     861//  glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);      // Position The Light
     862//  glEnable(GL_LIGHT1);              // Enable Light One
     863//
     864//  if (MultiViewEnabled) {
     865//    // xy view port
     866//    glViewport( (GLint)width/2, 0, (GLint)width/2, (GLint)height/2 );
     867//    glMatrixMode( GL_PROJECTION );
     868//    glLoadIdentity();
     869//    glScalef(1./scale, 1./scale,1./scale);
     870//    glOrtho(0, width/2, 0, height/2, 0,0);
     871//    glMatrixMode( GL_MODELVIEW );
     872//    glLoadIdentity();
     873//
     874//    // calculate point of view and direction
     875//    view = position;
     876//    spot = Vector(0.,0.,scale);
     877//    top = Vector(0.,1.,0.);
     878//    gluLookAt(
     879//        spot[0], spot[1], spot[2],
     880//        view[0], view[1], view[2],
     881//        top[0], top[1], top[2]);
     882//
     883//    // enable light
     884//    glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);       // Setup The Ambient Light
     885//    glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);       // Setup The Diffuse Light
     886//    glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);      // Position The Light
     887//    glEnable(GL_LIGHT1);              // Enable Light One
     888//
     889//    // render scene
     890//    glCallList(object);
     891//
     892//    // xz viewport
     893//    glViewport( 0, (GLint)height/2, (GLint)width/2, (GLint)height/2 );
     894//    glMatrixMode( GL_PROJECTION );
     895//    glLoadIdentity();
     896//    glScalef(1./scale, 1./scale,1./scale);
     897//    glOrtho(0, width/2, 0, height/2, 0,0);
     898//    glMatrixMode( GL_MODELVIEW );
     899//    glLoadIdentity();
     900//
     901//    // calculate point of view and direction
     902//    view = position;
     903//    spot = Vector(0.,scale,0.);
     904//    top = Vector(1.,0.,0.);
     905//    gluLookAt(
     906//        spot[0], spot[1], spot[2],
     907//        view[0], view[1], view[2],
     908//        top[0], top[1], top[2]);
     909//
     910//    // enable light
     911//    glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);       // Setup The Ambient Light
     912//    glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);       // Setup The Diffuse Light
     913//    glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);      // Position The Light
     914//    glEnable(GL_LIGHT1);              // Enable Light One
     915//
     916//    // render scene
     917//    glCallList(object);
     918//
     919//    //yz viewport
     920//    glViewport( (GLint)width/2, (GLint)height/2, (GLint)width/2, (GLint)height/2 );
     921//    glMatrixMode( GL_PROJECTION );
     922//    glLoadIdentity();
     923//    glScalef(1./scale, 1./scale,1./scale);
     924//    glOrtho(0, width/2, 0, height/2, 0,0);
     925//    glMatrixMode( GL_MODELVIEW );
     926//    glLoadIdentity();
     927//
     928//    // calculate point of view and direction
     929//    view= position;
     930//    spot = Vector(scale,0.,0.);
     931//    top = Vector(0.,1.,0.);
     932//    gluLookAt(
     933//        spot[0], spot[1], spot[2],
     934//        view[0], view[1], view[2],
     935//        top[0], top[1], top[2]);
     936//
     937//    // enable light
     938//    glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);       // Setup The Ambient Light
     939//    glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);       // Setup The Diffuse Light
     940//    glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);      // Position The Light
     941//    glEnable(GL_LIGHT1);              // Enable Light One
     942//
     943//    // render scene
     944//    glCallList(object);
     945//  }
     946//  //CoordinatesBar->setText( QString ("X: %1, Y: %2, Z: %3").arg(position[0]).arg(position[1]).arg(position[2]) );
     947//}
     948//
     949////void polarView{GLdouble distance, GLdouble twist,
     950////   GLdouble elevation, GLdouble azimuth)
     951////{
     952////      glTranslated(0.0, 0.0, -distance);
     953////      glRotated(-twist, 0.0, 0.0, 1.0);
     954////      glRotated(-elevation, 1.0, 0.0, 0.0);
     955////      glRotated(azimuth, 0.0, 0.0, 1.0);
     956////}
     957//
     958///** Make a sphere.
     959// * \param x position
     960// * \param radius radius
     961// * \param color[3] color rgb values
     962// */
     963//void GLMoleculeView::makeSphere(const Vector &x, double radius, const unsigned char color[3])
     964//{
     965//  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
     966//  GLUquadricObj* q = gluNewQuadric ();
     967//  gluQuadricOrientation(q, GLU_OUTSIDE);
     968//
     969//  std::cout << "Setting sphere at " << x << " with color r"
     970//      << (int)color[0] << ",g" << (int)color[1] << ",b" << (int)color[2] << "." << endl;
     971//
     972//  glPushMatrix();
     973//  glTranslatef( x[0], x[1], x[2]);
     974////  glRotatef( xRot, 1.0, 0.0, 0.0);
     975////  glRotatef( yRot, 0.0, 1.0, 0.0);
     976////  glRotatef( zRot, 0.0, 0.0, 1.0);
     977//  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blueMaterial);
     978//  gluSphere (q, (GLdouble)radius, 10, 10);
     979//  glPopMatrix();
     980//}
     981//
     982///** Make a cylinder.
     983// * \param x origin
     984// * \param y direction
     985// * \param radius thickness
     986// * \param height length
     987// * \color[3] color rgb values
     988// */
     989//void GLMoleculeView::makeCylinder(const Vector &x, const Vector &y, double radius, double height, const unsigned char color[3])
     990//{
     991//  float blueMaterial[] = { 255./(float)color[0], 255./(float)color[1], 255./(float)color[2], 1 };
     992//  GLUquadricObj* q = gluNewQuadric ();
     993//  gluQuadricOrientation(q, GLU_OUTSIDE);
     994//  Vector a,b;
     995//  Vector OtherAxis;
     996//  double alpha;
     997//  a = x - y;
     998//  // construct rotation axis
     999//  b = a;
     1000//  b.VectorProduct(Z);
     1001//  Line axis(zeroVec, b);
     1002//  // calculate rotation angle
     1003//  alpha = a.Angle(Z);
     1004//  // construct other axis to check right-hand rule
     1005//  OtherAxis = b;
     1006//  OtherAxis.VectorProduct(Z);
     1007//  // assure right-hand rule for the rotation
     1008//  if (a.ScalarProduct(OtherAxis) < MYEPSILON)
     1009//    alpha = M_PI-alpha;
     1010//  // check
     1011//  Vector a_rotated = axis.rotateVector(a, alpha);
     1012//  std::cout << "Setting cylinder from "// << x << " to " << y
     1013//      << a << " to " << a_rotated << " around " << b << " by " << alpha/M_PI*180. << ", respectively, "
     1014//      << " with color r"
     1015//      << (int)color[0] << ",g" << (int)color[1] << ",b" << (int)color[2] << "." << endl;
     1016//
     1017//  glPushMatrix();
     1018//  glTranslatef( x[0], x[1], x[2]);
     1019//  glRotatef( alpha/M_PI*180., b[0], b[1], b[2]);
     1020//  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blueMaterial);
     1021//  gluCylinder (q, (GLdouble)radius, (GLdouble)radius, (GLdouble)height, 10, 10);
     1022//  glPopMatrix();
     1023//}
     1024//
     1025///** Defines the display CallList.
     1026// * Goes through all molecules and their atoms and adds spheres for atoms and cylinders
     1027// * for bonds. Heeds GLMoleculeView::SelectedAtom and GLMoleculeView::SelectedMolecule.
     1028// */
     1029//void GLMoleculeView::initializeGL()
     1030//{
     1031//  double x[3] = {-1, 0, -10};
     1032//  unsigned char white[3] = {255,255,255};
     1033//  Vector Position, OtherPosition;
     1034//  QSize window = size();
     1035//  width = window.width();
     1036//  height = window.height();
     1037//  std::cout << "Setting width to " << width << " and height to " << height << std::endl;
     1038//  GLfloat shininess[] = { 0.0 };
     1039//  GLfloat specular[] = { 0, 0, 0, 1 };
     1040//  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);     // Let OpenGL clear to black
     1041//  object = glGenLists(1);
     1042//  glNewList( object, GL_COMPILE );
     1043//  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
     1044//  glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
     1045//
     1046//  const std::vector<molecule*> &molecules = World::getInstance().getAllMolecules();
     1047//
     1048//  if (molecules.size() > 0) {
     1049//    for (std::vector<molecule*>::const_iterator Runner = molecules.begin();
     1050//        Runner != molecules.end();
     1051//        Runner++) {
     1052//      for (molecule::const_iterator atomiter = (*Runner)->begin();
     1053//          atomiter != (*Runner)->end();
     1054//          ++atomiter) {
     1055//        // create atom
     1056//        const element *ptr = (*atomiter)->getType();
     1057//        boost::shared_ptr<Vector> MolCenter((*Runner)->DetermineCenterOfGravity());
     1058//        Position = (*atomiter)->getPosition() - *MolCenter;
     1059//        const unsigned char* color = NULL;
     1060//        if ((World::getInstance().isSelected(*atomiter)) || (World::getInstance().isSelected((*Runner))))
     1061//          color = SelectionColor;
     1062//        else
     1063//          color = ptr->getColor();
     1064//        makeSphere(Position, ptr->getVanDerWaalsRadius()*0.25, color);
     1065//
     1066//        // create bonds
     1067//        const BondList &bonds = (*atomiter)->getListOfBonds();
     1068//        for (BondList::const_iterator bonditer = bonds.begin();
     1069//            bonditer != bonds.end();
     1070//            ++bonditer) {
     1071//          if ((*bonditer)->leftatom->getId() == (*atomiter)->getId()) {
     1072//            Position = (*bonditer)->leftatom->getPosition() - *MolCenter;
     1073//            OtherPosition = (*bonditer)->rightatom->getPosition() - *MolCenter;
     1074//            const double distance = sqrt(Position.DistanceSquared(OtherPosition))/2.;
     1075//            const unsigned char *color1 = (*bonditer)->leftatom->getType()->getColor();
     1076//            const unsigned char *color2 = (*bonditer)->rightatom->getType()->getColor();
     1077//            makeCylinder(Position, OtherPosition, 0.1, distance, color1);
     1078//            makeCylinder(OtherPosition, Position, 0.1, distance, color2);
     1079//          }
     1080//        }
     1081//      }
     1082//    }
     1083//  } else {
     1084//    makeSphere( x,1, white);
     1085//  }
     1086//  glEndList();
     1087//}
     1088//
     1089//
     1090///* ================================== SLOTS ============================== */
     1091//
     1092///** Initializes some public variables.
     1093// * \param *ptr pointer to QLabel statusbar
     1094// */
     1095//void GLMoleculeView::init(QLabel *ptr)
     1096//{
     1097//  StatusBar = ptr;
     1098//}
     1099//
     1100///** Initializes the viewport statusbar.
     1101// * \param *ptr pointer to QLabel for showing view pointcoordinates.
     1102// */
     1103//void GLMoleculeView::initCoordinates(QLabel *ptr)
     1104//{
     1105//  CoordinatesBar = ptr;
     1106//}
     1107//
     1108///** Slot to be called when to initialize GLMoleculeView::MolData.
     1109// */
     1110//void GLMoleculeView::createView( )
     1111//{
     1112//  initializeGL();
     1113//  updateGL();
     1114//}
     1115//
     1116///** Slot of window is resized.
     1117// * Copies new width and height to GLMoleculeView::width and GLMoleculeView::height and calls updateGL().
     1118// * \param w new width of window
     1119// * \param h new height of window
     1120// */
     1121//void GLMoleculeView::resizeGL( int w, int h )
     1122//{
     1123//  width = w;
     1124//  height = h;
     1125//  updateGL();
     1126//}
     1127//
     1128///** Sets x rotation angle.
     1129// * sets GLMoleculeView::xRot and calls updateGL().
     1130// * \param degrees new rotation angle in degrees
     1131// */
     1132//void GLMoleculeView::setXRotation( int degrees )
     1133//{
     1134//  xRot = (GLfloat)(degrees % 360);
     1135//  updateGL();
     1136//}
     1137//
     1138//
     1139///** Sets y rotation angle.
     1140// * sets GLMoleculeView::yRot and calls updateGL().
     1141// * \param degrees new rotation angle in degrees
     1142// */
     1143//void GLMoleculeView::setYRotation( int degrees )
     1144//{
     1145//  yRot = (GLfloat)(degrees % 360);
     1146//  updateGL();
     1147//}
     1148//
     1149//
     1150///** Sets z rotation angle.
     1151// * sets GLMoleculeView::zRot and calls updateGL().
     1152// * \param degrees new rotation angle in degrees
     1153// */
     1154//void GLMoleculeView::setZRotation( int degrees )
     1155//{
     1156//  zRot = (GLfloat)(degrees % 360);
     1157//  updateGL();
     1158//}
     1159//
     1160///** Sets the scale of the scene.
     1161// * sets GLMoleculeView::scale and calls updateGL().
     1162// * \param distance distance divided by 100 is the new scale
     1163// */
     1164//void GLMoleculeView::setScale( int distance )
     1165//{
     1166//  scale = (GLfloat)(distance / 100.);
     1167//  updateGL();
     1168//}
     1169//
     1170///** Update the ambient light.
     1171// * \param light[4] light strength per axis and position (w)
     1172// */
     1173//void GLMoleculeView::setLightAmbient( int *light )
     1174//{
     1175//  for(int i=0;i<4;i++)
     1176//    LightAmbient[i] = light[i];
     1177//  updateGL();
     1178//}
     1179//
     1180///** Update the diffuse light.
     1181// * \param light[4] light strength per axis and position (w)
     1182// */
     1183//void GLMoleculeView::setLightDiffuse( int *light )
     1184//{
     1185//  for(int i=0;i<4;i++)
     1186//    LightDiffuse[i] = light[i];
     1187//  updateGL();
     1188//}
     1189//
     1190///** Update the position of light.
     1191// * \param light[4] light strength per axis and position (w)
     1192// */
     1193//void GLMoleculeView::setLightPosition( int *light )
     1194//{
     1195//  for(int i=0;i<4;i++)
     1196//    LightPosition[i] = light[i];
     1197//  updateGL();
     1198//}
     1199//
     1200///** Toggles the boolean GLMoleculeView::MultiViewEnabled.
     1201// * Flips the boolean and calls updateGL().
     1202// */
     1203//void GLMoleculeView::toggleMultiViewEnabled ( )
     1204//{
     1205//  MultiViewEnabled = !MultiViewEnabled;
     1206//  cout << "Setting MultiView to " << MultiViewEnabled << "." << endl;
     1207//  updateGL();
     1208//}
     1209//
     1210///** Launch a dialog to configure the lights.
     1211// */
     1212//void GLMoleculeView::createDialogLight()
     1213//{
     1214////  Ui_DialogLight *Lights = new Ui_DialogLight();
     1215////  if (Lights == NULL)
     1216////    return;
     1217////  // Set up the dynamic dialog here
     1218////  QLineEdit *Field = NULL;
     1219////  Field = Lights->findChild<QLineEdit *>("LightPositionX");
     1220////  if (Field) Field->setText( QString("%1").arg(LightPosition[0]) );
     1221////  Field = Lights->findChild<QLineEdit *>("LightPositionY");
     1222////  if (Field) Field->setText( QString("%1").arg(LightPosition[1]) );
     1223////  Field = Lights->findChild<QLineEdit *>("LightPositionZ");
     1224////  if (Field) Field->setText( QString("%1").arg(LightPosition[2]) );
     1225////  Field = Lights->findChild<QLineEdit *>("LightPositionW");
     1226////  if (Field) Field->setText( QString("%1").arg(LightPosition[3]) );
     1227////
     1228////  Field = Lights->findChild<QLineEdit *>("LightDiffuseX");
     1229////  if (Field) Field->setText( QString("%1").arg(LightDiffuse[0]) );
     1230////  Field = Lights->findChild<QLineEdit *>("LightDiffuseY");
     1231////  if (Field) Field->setText( QString("%1").arg(LightDiffuse[1]) );
     1232////  Field = Lights->findChild<QLineEdit *>("LightDiffuseZ");
     1233////  if (Field) Field->setText( QString("%1").arg(LightDiffuse[2]) );
     1234////  Field = Lights->findChild<QLineEdit *>("LightDiffuseW");
     1235////  if (Field) Field->setText( QString("%1").arg(LightDiffuse[3]) );
     1236////
     1237////  Field = Lights->findChild<QLineEdit *>("LightAmbientX");
     1238////  if (Field) Field->setText( QString("%1").arg(LightAmbient[0]) );
     1239////  Field = Lights->findChild<QLineEdit *>("LightAmbientY");
     1240////  if (Field) Field->setText( QString("%1").arg(LightAmbient[1]) );
     1241////  Field = Lights->findChild<QLineEdit *>("LightAmbientZ");
     1242////  if (Field) Field->setText( QString("%1").arg(LightAmbient[2]) );
     1243////  Field = Lights->findChild<QLineEdit *>("LightAmbientW");
     1244////  if (Field) Field->setText( QString("%1").arg(LightAmbient[3]) );
     1245////
     1246////  if ( Lights->exec() ) {
     1247////    //cout << "User accepted.\n";
     1248////    // The user accepted, act accordingly
     1249////    Field = Lights->findChild<QLineEdit *>("LightPositionX");
     1250////    if (Field) LightPosition[0] = Field->text().toDouble();
     1251////    Field = Lights->findChild<QLineEdit *>("LightPositionY");
     1252////    if (Field) LightPosition[1] = Field->text().toDouble();
     1253////    Field = Lights->findChild<QLineEdit *>("LightPositionZ");
     1254////    if (Field) LightPosition[2] = Field->text().toDouble();
     1255////    Field = Lights->findChild<QLineEdit *>("LightPositionW");
     1256////    if (Field) LightPosition[3] = Field->text().toDouble();
     1257////
     1258////    Field = Lights->findChild<QLineEdit *>("LightDiffuseX");
     1259////    if (Field) LightDiffuse[0] = Field->text().toDouble();
     1260////    Field = Lights->findChild<QLineEdit *>("LightDiffuseY");
     1261////    if (Field) LightDiffuse[1] = Field->text().toDouble();
     1262////    Field = Lights->findChild<QLineEdit *>("LightDiffuseZ");
     1263////    if (Field) LightDiffuse[2] = Field->text().toDouble();
     1264////    Field = Lights->findChild<QLineEdit *>("LightDiffuseW");
     1265////    if (Field) LightDiffuse[3] = Field->text().toDouble();
     1266////
     1267////    Field = Lights->findChild<QLineEdit *>("LightAmbientX");
     1268////    if (Field) LightAmbient[0] = Field->text().toDouble();
     1269////    Field = Lights->findChild<QLineEdit *>("LightAmbientY");
     1270////    if (Field) LightAmbient[1] = Field->text().toDouble();
     1271////    Field = Lights->findChild<QLineEdit *>("LightAmbientZ");
     1272////    if (Field) LightAmbient[2] = Field->text().toDouble();
     1273////    Field = Lights->findChild<QLineEdit *>("LightAmbientW");
     1274////    if (Field) LightAmbient[3] = Field->text().toDouble();
     1275////    updateGL();
     1276////  } else {
     1277////    //cout << "User reclined.\n";
     1278////  }
     1279////  delete(Lights);
     1280//}
     1281//
     1282///** Slot for event of pressed mouse button.
     1283// * Switch discerns between buttons and stores position of event in GLMoleculeView::LeftButtonPos,
     1284// * GLMoleculeView::MiddleButtonPos or GLMoleculeView::RightButtonPos.
     1285// * \param *event structure containing information of the event
     1286// */
     1287//void GLMoleculeView::mousePressEvent(QMouseEvent *event)
     1288//{
     1289//  std::cout << "MousePressEvent." << endl;
     1290//  QPoint *pos = NULL;
     1291//  switch (event->button()) {  // get the right array
     1292//    case Qt::LeftButton:
     1293//      pos = &LeftButtonPos;
     1294//      std::cout << "Left Button" << endl;
     1295//      break;
     1296//    case Qt::MidButton:
     1297//      pos = &MiddleButtonPos;
     1298//      std::cout << "Middle Button" << endl;
     1299//      break;
     1300//    case Qt::RightButton:
     1301//      pos = &RightButtonPos;
     1302//      std::cout << "Right Button" << endl;
     1303//      break;
     1304//    default:
     1305//      break;
     1306//  }
     1307//  if (pos) {    // store the position
     1308//    pos->setX(event->pos().x());
     1309//    pos->setY(event->pos().y());
     1310//    std::cout << "Stored src position is (" << pos->x() << "," << pos->y() << ")." << endl;
     1311//  } else {
     1312//    std::cout << "pos is NULL." << endl;
     1313//  }
     1314//}
     1315//
     1316///** Slot for event of pressed mouse button.
     1317// * Switch discerns between buttons:
     1318// * -# Left Button: Rotates the view of the GLMoleculeView, relative to GLMoleculeView::LeftButtonPos.
     1319// * -# Middle Button: nothing
     1320// * -# Right Button: Shifts the selected molecule or atom, relative to GLMoleculeView::RightButtonPos.
     1321// * \param *event structure containing information of the event
     1322// */
     1323//void GLMoleculeView::mouseReleaseEvent(QMouseEvent *event)
     1324//{
     1325//  std::cout << "MouseReleaseEvent." << endl;
     1326//  QPoint *srcpos = NULL;
     1327//  QPoint destpos = event->pos();
     1328//  int Width = (MultiViewEnabled) ? width/2 : width;
     1329//  int Height = (MultiViewEnabled) ? height/2 : height;
     1330//  std::cout << "Received dest position is (" << destpos.x() << "," << destpos.y() << ")." << endl;
     1331//  switch (event->button()) {  // get the right array
     1332//    case Qt::LeftButton:  // LeftButton rotates the view
     1333//      srcpos = &LeftButtonPos;
     1334//      std::cout << "Left Button" << endl;
     1335//      if (srcpos) {    // subtract the position and act
     1336//        std::cout << "Stored src position is (" << srcpos->x() << "," << srcpos->y() << ")." << endl;
     1337//        destpos -= *srcpos;
     1338//        std::cout << "Resulting diff position is (" << destpos.x() << "," << destpos.y() << ")." << endl;
     1339//        std::cout << "Width and Height are " << Width << "," << Height << "." << endl;
     1340//
     1341//        int pos = (int)floor((double)srcpos->x()/(double)Width) + ((int)floor((double)srcpos->y()/(double)Height))*2;
     1342//        if ((MultiViewEnabled) && (pos != 2)) { // means four regions, and we are in a shifting one
     1343//          // switch between three regions
     1344//          // decide into which of the four screens the initial click has been made
     1345//          std::cout << "Position is " << pos << "." << endl;
     1346//          switch(pos) {
     1347//            case 0:  // lower left = xz
     1348//              position[0] += -destpos.y()/100.;
     1349//              position[2] += destpos.x()/100.;
     1350//              break;
     1351//            case 1: // lower right = yz
     1352//              position[1] += -destpos.y()/100.;
     1353//              position[2] += -destpos.x()/100.;
     1354//              break;
     1355//            case 2:  // upper left = projected
     1356//              std::cout << "This is impossible: Shifting in the projected region, we should rotate!." << endl;
     1357//              break;
     1358//            case 3:  // upper right = xy
     1359//              position[0] += destpos.x()/100.;
     1360//              position[1] += -destpos.y()/100.;
     1361//              break;
     1362//            default:
     1363//              std::cout << "click was not in any of the four regions." << endl;
     1364//              break;
     1365//          }
     1366//          updateGL();
     1367//        } else { // we are in rotation region
     1368//          QWidget *Parent = parentWidget();
     1369//          QSlider *sliderX = Parent->findChild<QSlider *>("sliderX");
     1370//          QSlider *sliderY = Parent->findChild<QSlider *>("sliderY");
     1371//          std::cout << sliderX << " and " << sliderY << endl;
     1372//          if (sliderX) {
     1373//            int xrange = sliderX->maximum() - sliderX->minimum();
     1374//            double xValue = ((destpos.x() + Width) % Width);
     1375//            xValue *= (double)xrange/(double)Width;
     1376//            xValue += sliderX->value();
     1377//            int xvalue = (int) xValue % xrange;
     1378//            std::cout << "Setting x to " << xvalue << " within range " << xrange << "." << endl;
     1379//            setXRotation(xvalue);
     1380//            sliderX->setValue(xvalue);
     1381//          } else {
     1382//            std::cout << "sliderX is NULL." << endl;
     1383//          }
     1384//          if (sliderY) {
     1385//            int yrange = sliderY->maximum() - sliderY->minimum();
     1386//            double yValue = ((destpos.y() + Height) % Height);
     1387//            yValue *= (double)yrange/(double)Height;
     1388//            yValue += sliderY->value();
     1389//            int yvalue = (int) yValue % yrange;
     1390//            std::cout << "Setting y to " << yvalue << " within range " << yrange << "." << endl;
     1391//            setYRotation(yvalue);
     1392//            sliderY->setValue(yvalue);
     1393//          } else {
     1394//            std::cout << "sliderY is NULL." << endl;
     1395//          }
     1396//        }
     1397//      } else {
     1398//        std::cout << "srcpos is NULL." << endl;
     1399//      }
     1400//      break;
     1401//
     1402//    case Qt::MidButton: // MiddleButton has no function so far
     1403//      srcpos = &MiddleButtonPos;
     1404//      std::cout << "Middle Button" << endl;
     1405//      if (srcpos) {    // subtract the position and act
     1406//        QWidget *Parent = parentWidget();
     1407//        QSlider *sliderZ = Parent->findChild<QSlider *>("sliderZ");
     1408//        QSlider *sliderScale = Parent->findChild<QSlider *>("sliderScale");
     1409//        std::cout << sliderZ << " and " << sliderScale << endl;
     1410//        std::cout << "Stored src position is (" << srcpos->x() << "," << srcpos->y() << ")." << endl;
     1411//        destpos -= *srcpos;
     1412//        std::cout << "Resulting diff position is (" << destpos.x() << "," << destpos.y() << ")." << endl;
     1413//        std::cout << "Width and Height are " << Width << "," << Height << "." << endl;
     1414//        if (sliderZ) {
     1415//          int xrange = sliderZ->maximum() - sliderZ->minimum();
     1416//          double xValue = ((destpos.x() + Width) % Width);
     1417//          xValue *= (double)xrange/(double)Width;
     1418//          xValue += sliderZ->value();
     1419//          int xvalue = (int) xValue % xrange;
     1420//          std::cout << "Setting x to " << xvalue << " within range " << xrange << "." << endl;
     1421//          setZRotation(xvalue);
     1422//          sliderZ->setValue(xvalue);
     1423//        } else {
     1424//          std::cout << "sliderZ is NULL." << endl;
     1425//        }
     1426//        if (sliderScale) {
     1427//          int yrange = sliderScale->maximum() - sliderScale->minimum();
     1428//          double yValue = ((destpos.y() + Height) % Height);
     1429//          yValue *= (double)yrange/(double)Height;
     1430//          yValue += sliderScale->value();
     1431//          int yvalue = (int) yValue % yrange;
     1432//          std::cout << "Setting y to " << yvalue << " within range " << yrange << "." << endl;
     1433//          setScale(yvalue);
     1434//          sliderScale->setValue(yvalue);
     1435//        } else {
     1436//          std::cout << "sliderScale is NULL." << endl;
     1437//        }
     1438//      } else {
     1439//        std::cout << "srcpos is NULL." << endl;
     1440//      }
     1441//      break;
     1442//      break;
     1443//
     1444//    case Qt::RightButton:  // RightButton moves eitstdher the selected molecule or atom
     1445//      srcpos = &RightButtonPos;
     1446//      std::cout << "Right Button" << endl;
     1447//      if (srcpos) {    // subtract the position and act
     1448//        std::cout << "Stored src position is (" << srcpos->x() << "," << srcpos->y() << ")." << endl;
     1449//        destpos -= *srcpos;
     1450//        std::cout << "Resulting diff position is (" << destpos.x() << "," << destpos.y() << ")." << endl;
     1451//        std::cout << "Width and Height are " << Width << "," << Height << "." << endl;
     1452//        if (MultiViewEnabled) {
     1453//          // which vector to change
     1454//          Vector SelectedPosition;
     1455//          const std::vector<atom*> &SelectedAtoms = World::getInstance().getSelectedAtoms();
     1456//          const std::vector<molecule*> &SelectedMolecules = World::getInstance().getSelectedMolecules();
     1457//          if (SelectedMolecules.size()) {
     1458//            if (SelectedAtoms.size())
     1459//              SelectedPosition = (*SelectedAtoms.begin())->getPosition();
     1460//            else
     1461//              SelectedPosition = (*(*SelectedMolecules.begin())->begin())->getPosition();
     1462//          }
     1463//          // decide into which of the four screens the initial click has been made
     1464//          int pos = (int)floor((double)srcpos->x()/(double)Width) + ((int)floor((double)srcpos->y()/(double)Height))*2;
     1465//          if (!SelectedPosition.IsZero()) {
     1466//            std::cout << "Position is " << pos << "." << endl;
     1467//            switch(pos) {
     1468//              case 0:  // lower left = xz
     1469//                SelectedPosition[0] += -destpos.y()/100.;
     1470//                SelectedPosition[2] += destpos.x()/100.;
     1471//                break;
     1472//              case 1: // lower right = yz
     1473//                SelectedPosition[1] += -destpos.y()/100.;
     1474//                SelectedPosition[2] += -destpos.x()/100.;
     1475//                break;
     1476//              case 2:  // upper left = projected
     1477//                SelectedPosition[0] += destpos.x()/100.;
     1478//                SelectedPosition[1] += destpos.y()/100.;
     1479//                SelectedPosition[2] += destpos.y()/100.;
     1480//                break;
     1481//              case 3:  // upper right = xy
     1482//                SelectedPosition[0] += destpos.x()/100.;
     1483//                SelectedPosition[1] += -destpos.y()/100.;
     1484//                break;
     1485//              default:
     1486//                std::cout << "click was not in any of the four regions." << endl;
     1487//                break;
     1488//            }
     1489//          } else {
     1490//            std::cout << "Nothing selected." << endl;
     1491//          }
     1492//          // update Tables
     1493//          if (SelectedMolecules.size()) {
     1494//            isSignaller = true;
     1495//            if (SelectedAtoms.size())
     1496//              emit notifyAtomChanged( (*SelectedMolecules.begin()), (*SelectedAtoms.begin()), AtomPosition);
     1497//            else
     1498//              emit notifyMoleculeChanged( (*SelectedMolecules.begin()), MoleculePosition );
     1499//          }
     1500//          // update graphic
     1501//          initializeGL();
     1502//          updateGL();
     1503//        } else {
     1504//          cout << "MultiView is not enabled." << endl;
     1505//        }
     1506//      } else {
     1507//        cout << "srcpos is NULL." << endl;
     1508//      }
     1509//  break;
     1510//
     1511//    default:
     1512//      break;
     1513//  }
     1514//}
     1515//
     1516///* ======================================== SLOTS ================================ */
     1517//
     1518///** Hear announcement of selected molecule.
     1519// * \param *mol pointer to selected molecule
     1520// */
     1521//void GLMoleculeView::hearMoleculeSelected(molecule *mol)
     1522//{
     1523//  if (isSignaller) { // if we emitted the signal, return
     1524//    isSignaller = false;
     1525//    return;
     1526//  }
     1527//  initializeGL();
     1528//  updateGL();
     1529//};
     1530//
     1531///** Hear announcement of selected atom.
     1532// * \param *mol pointer to molecule containing atom
     1533// * \param *Walker pointer to selected atom
     1534// */
     1535//void GLMoleculeView::hearAtomSelected(molecule *mol, atom *Walker)
     1536//{
     1537//  if (isSignaller) { // if we emitted the signal, return
     1538//    isSignaller = false;
     1539//    return;
     1540//  }
     1541//  initializeGL();
     1542//  updateGL();
     1543//};
     1544//
     1545///** Hear announcement of changed molecule.
     1546// * \param *mol pointer to changed molecule
     1547// * \param type of change
     1548// */
     1549//void GLMoleculeView::hearMoleculeChanged(molecule *mol, enum ChangesinMolecule type)
     1550//{
     1551//  if (isSignaller) { // if we emitted the signal, return
     1552//    isSignaller = false;
     1553//    return;
     1554//  }
     1555//  initializeGL();
     1556//  updateGL();
     1557//};
     1558//
     1559///** Hear announcement of changed atom.
     1560// * \param *mol pointer to molecule containing atom
     1561// * \param *Walker pointer to changed atom
     1562// * \param type type of change
     1563// */
     1564//void GLMoleculeView::hearAtomChanged(molecule *mol, atom *Walker, enum ChangesinAtom type)
     1565//{
     1566//  if (isSignaller) { // if we emitted the signal, return
     1567//    isSignaller = false;
     1568//    return;
     1569//  }
     1570//  initializeGL();
     1571//  updateGL();
     1572//};
     1573//
     1574///** Hear announcement of changed element.
     1575// * \param *Runner pointer to changed element
     1576// * \param type of change
     1577// */
     1578//void GLMoleculeView::hearElementChanged(element *Runner, enum ChangesinElement type)
     1579//{
     1580//  if (isSignaller) { // if we emitted the signal, return
     1581//    isSignaller = false;
     1582//    return;
     1583//  }
     1584//  switch(type) {
     1585//    default:
     1586//    case ElementName:
     1587//    case ElementSymbol:
     1588//    case ElementMass:
     1589//    case ElementValence:
     1590//    case ElementZ:
     1591//      break;
     1592//    case ElementCovalent:
     1593//    case ElementVanderWaals:
     1594//      initializeGL();
     1595//      updateGL();
     1596//      break;
     1597//  }
     1598//};
     1599//
     1600///** Hear announcement of added molecule.
     1601// * \param *mol pointer to added molecule
     1602// */
     1603//void GLMoleculeView::hearMoleculeAdded(molecule *mol)
     1604//{
     1605//  if (isSignaller) { // if we emitted the signal, return
     1606//    isSignaller = false;
     1607//    return;
     1608//  }
     1609//  initializeGL();
     1610//  updateGL();
     1611//};
     1612//
     1613///** Hear announcement of added atom.
     1614// * \param *mol pointer to molecule containing atom
     1615// * \param *Walker pointer to added atom
     1616// */
     1617//void GLMoleculeView::hearAtomAdded(molecule *mol, atom *Walker)
     1618//{
     1619//  if (isSignaller) { // if we emitted the signal, return
     1620//    isSignaller = false;
     1621//    return;
     1622//  }
     1623//  initializeGL();
     1624//  updateGL();
     1625//};
     1626//
     1627///** Hear announcement of removed molecule.
     1628// * \param *mol pointer to removed molecule
     1629// */
     1630//void GLMoleculeView::hearMoleculeRemoved(molecule *mol)
     1631//{
     1632//  if (isSignaller) { // if we emitted the signal, return
     1633//    isSignaller = false;
     1634//    return;
     1635//  }
     1636//  initializeGL();
     1637//  updateGL();
     1638//};
     1639//
     1640///** Hear announcement of removed atom.
     1641// * \param *mol pointer to molecule containing atom
     1642// * \param *Walker pointer to removed atom
     1643// */
     1644//void GLMoleculeView::hearAtomRemoved(molecule *mol, atom *Walker)
     1645//{
     1646//  if (isSignaller) { // if we emitted the signal, return
     1647//    isSignaller = false;
     1648//    return;
     1649//  }
     1650//  initializeGL();
     1651//  updateGL();
     1652//};
     1653//
     1654//void GLMoleculeView::update(Observable *publisher)
     1655//{
     1656//  initializeGL();
     1657//  updateGL();
     1658//}
     1659//
     1660///**
     1661// * This method is called when a special named change
     1662// * of the Observable occured
     1663// */
     1664//void GLMoleculeView::recieveNotification(Observable *publisher, Notification_ptr notification)
     1665//{
     1666//  initializeGL();
     1667//  updateGL();
     1668//}
     1669//
     1670///**
     1671// * This method is called when the observed object is destroyed.
     1672// */
     1673//void GLMoleculeView::subjectKilled(Observable *publisher)
     1674//{
     1675//
     1676//}
     1677//
     1678//
     1679//// new stuff
     1680//
     1681///** Returns the ref to the Material for element No \a from the map.
     1682// *
     1683// * \note We create a new one if the element is missing.
     1684// *
     1685// * @param no element no
     1686// * @return ref to QGLMaterial
     1687// */
     1688//QGLMaterial* GLMoleculeView::getMaterial(size_t no)
     1689//{
     1690//  if (ElementNoMaterialMap.find(no) != ElementNoMaterialMap.end()){
     1691//    // get present one
     1692//
     1693//  } else {
     1694//    ASSERT( (no >= 0) && (no < MAX_ELEMENTS),
     1695//        "GLMoleculeView::getMaterial() - Element no "+toString(no)+" is invalid.");
     1696//    // create new one
     1697//    LOG(1, "Creating new material for element "+toString(no)+".");
     1698//    QGLMaterial *newmaterial = new QGLMaterial(this);
     1699//    periodentafel *periode = World::getInstance().getPeriode();
     1700//    element *desiredelement = periode->FindElement(no);
     1701//    ASSERT(desiredelement != NULL,
     1702//        "GLMoleculeView::getMaterial() - desired element "+toString(no)+" not present in periodentafel.");
     1703//    const unsigned char* color = desiredelement->getColor();
     1704//    newmaterial->setAmbientColor( QColor(color[0], color[1], color[2]) );
     1705//    newmaterial->setSpecularColor( QColor(60, 60, 60) );
     1706//    newmaterial->setShininess( QColor(128) );
     1707//    ElementNoMaterialMap.insert( no, newmaterial);
     1708//  }
     1709//}
     1710//
     1711//QGLSceneNode* GLMoleculeView::getAtom(size_t no)
     1712//{
     1713//  // first some sensibility checks
     1714//  ASSERT(World::getInstance().getAtom(AtomById(no)) != NULL,
     1715//      "GLMoleculeView::getAtom() - desired atom "
     1716//      +toString(no)+" not present in the World.");
     1717//  ASSERT(AtomsinSceneMap.find(no) != AtomsinSceneMap.end(),
     1718//      "GLMoleculeView::getAtom() - desired atom "
     1719//      +toString(no)+" not present in the AtomsinSceneMap.");
     1720//
     1721//  return AtomsinSceneMap[no];
     1722//}
     1723//
     1724//QGLSceneNode* GLMoleculeView::getBond(size_t leftno, size_t rightno)
     1725//{
     1726//  // first some sensibility checks
     1727//  ASSERT(World::getInstance().getAtom(AtomById(leftno)) != NULL,
     1728//      "GLMoleculeView::getAtom() - desired atom "
     1729//      +toString(leftno)+" of bond not present in the World.");
     1730//  ASSERT(World::getInstance().getAtom(AtomById(rightno)) != NULL,
     1731//      "GLMoleculeView::getAtom() - desired atom "
     1732//      +toString(rightno)+" of bond not present in the World.");
     1733//  ASSERT(AtomsinSceneMap.find(leftno) != AtomsinSceneMap.end(),
     1734//      "GLMoleculeView::getAtom() - desired atom "
     1735//      +toString(leftno)+" of bond not present in the AtomsinSceneMap.");
     1736//  ASSERT(AtomsinSceneMap.find(rightno) != AtomsinSceneMap.end(),
     1737//      "GLMoleculeView::getAtom() - desired atom "
     1738//      +toString(rightno)+" of bond not present in the AtomsinSceneMap.");
     1739//  ASSERT(leftno == rightno,
     1740//      "GLMoleculeView::getAtom() - bond must not be between the same atom: "
     1741//      +toString(leftno)+" == "+toString(rightno)+".");
     1742//
     1743//  // then return with smaller index first
     1744//  if (leftno > rightno)
     1745//    return AtomsinSceneMap[ make_pair(rightno, leftno) ];
     1746//  else
     1747//    return AtomsinSceneMap[ make_pair(leftno, rightno) ];
     1748//}
     1749//
Note: See TracChangeset for help on using the changeset viewer.