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

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 v1.3.9
Last change on this file since d6b6ce was 1d02c2d, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: GLWorldView lacked molecule include.

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