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

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 3f7587 was 57a770, checked in by Frederik Heber <heber@…>, 13 years ago

Corrected verbosity levels of GLMoleculeObject..., GLWorldScene, and ..View.

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