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

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 d53902 was 343a4b, checked in by Frederik Heber <heber@…>, 13 years ago

GL: bond tracks its atoms' position changes

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