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

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

GL: dreibein as a real mesh

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