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

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

GL: redraw only once during loading

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