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

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 b1b413 was 856d05, checked in by Frederik Heber <heber@…>, 13 years ago

MEMFIX: Added WorldTime and ObserverLog ::purgeInstance() calls.

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