source: src/UIElements/Views/Qt4/Qt3D/GLWorldView.cpp@ 6966b7

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

GL: saving color settings (domainBox, dreinBein)

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