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

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

FIX: Observers (GLMoleculeObject_atom, GLWorldScene) sign off on destruction.

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