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

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 0aa122 was 0aa122, checked in by Frederik Heber <heber@…>, 14 years ago

Updated all source files's copyright note to current year 2012.

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