source: src/UIElements/Views/Qt4/Qt3D/GLWorldView.cpp@ 8a77ac

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 8a77ac was 8a77ac, checked in by Frederik Heber <heber@…>, 13 years ago

GL: track atoms changing position

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