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

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

added toolbar actions for camera modes

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