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

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 8880c9 was 8880c9, checked in by Michael Ankele <ankele@…>, 13 years ago

GLWorldView: implemented own camera

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