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

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 284551 was 284551, checked in by Frederik Heber <heber@…>, 12 years ago

GLWorldView shows the selected shapes from ShapeRegistry

  • Property mode set to 100644
File size: 57.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 *
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 "CodePatterns/Log.hpp"
57#include "CodePatterns/Observer/Notification.hpp"
58#include "CodePatterns/Observer/ObserverLog.hpp"
59#include "Shapes/ShapeRegistry.hpp"
60#include "World.hpp"
61#include "Box.hpp"
62
63GLWorldView::GLWorldView(QWidget *parent)
64 : QGLView(parent), Observer("GLWorldView"), worldscene(NULL), changesPresent(false), needsRedraw(false)
65{
66 worldscene = new GLWorldScene(this);
67
68 setOption(QGLView::ObjectPicking, true);
69 setOption(QGLView::CameraNavigation, false);
70 setCameraControlMode(Rotate);
71 defaultEyeSeparation = 4.0;
72
73 createDomainBox();
74 createDreiBein();
75 //changeMaterials(false);
76
77 connect(worldscene, SIGNAL(changeOccured()), this, SLOT(changeSignalled()));
78 connect(worldscene, SIGNAL(changed()), this, SIGNAL(changed()));
79 connect(worldscene, SIGNAL(hoverChanged(const atom *)), this, SLOT(sceneHoverSignalled(const atom *)));
80 connect(this, SIGNAL(atomInserted(const atom *)), worldscene, SLOT(atomInserted(const atom *)));
81 connect(this, SIGNAL(atomRemoved(const atom *)), worldscene, SLOT(atomRemoved(const atom *)));
82 connect(this, SIGNAL(worldSelectionChanged()), worldscene, SLOT(worldSelectionChanged()));
83 connect(this, SIGNAL(moleculeRemoved(const molecule *)), worldscene, SLOT(moleculeRemoved(const molecule *)));
84 //connect(this, SIGNAL(moleculeInserted(const molecule *)), worldscene, SLOT(moleculeInserted(const molecule *)));
85 //connect(this, SIGNAL(changed()), this, SLOT(updateGL()));
86 connect(this, SIGNAL(changed()), this, SLOT(sceneChangeSignalled()));
87
88 // sign on to changes in the world
89 World::getInstance().signOn(this);
90 World::getInstance().signOn(this, World::AtomInserted);
91 World::getInstance().signOn(this, World::AtomRemoved);
92 World::getInstance().signOn(this, World::MoleculeInserted);
93 World::getInstance().signOn(this, World::MoleculeRemoved);
94 World::getInstance().signOn(this, World::SelectionChanged);
95 AtomObserver::getInstance().signOn(this, AtomObservable::PositionChanged);
96
97 ShapeRegistry::getInstance().signOn(this);
98 ShapeRegistry::getInstance().signOn(this, ShapeRegistry::ShapeRemoved);
99 ShapeRegistry::getInstance().signOn(this, ShapeRegistry::SelectionChanged);
100
101 redrawTimer = new QTimer(this);
102}
103
104GLWorldView::~GLWorldView()
105{
106 World::getInstance().signOff(this);
107 World::getInstance().signOff(this, World::AtomInserted);
108 World::getInstance().signOff(this, World::AtomRemoved);
109 World::getInstance().signOff(this, World::MoleculeInserted);
110 World::getInstance().signOff(this, World::MoleculeRemoved);
111 World::getInstance().signOff(this, World::SelectionChanged);
112 AtomObserver::getInstance().signOff(this, AtomObservable::PositionChanged);
113 ShapeRegistry::getInstance().signOff(this);
114 ShapeRegistry::getInstance().signOff(this, ShapeRegistry::ShapeRemoved);
115 ShapeRegistry::getInstance().signOff(this, ShapeRegistry::SelectionChanged);
116 delete worldscene;
117
118 delete(domainBoxMaterial);
119 for (int i=0;i<3;i++)
120 delete(dreiBeinMaterial[i]);
121}
122
123
124/**
125 * Add some widget specific actions to the toolbar:
126 * - camera rotation/translation mode
127 * - camera fit to domain
128 */
129void GLWorldView::addToolBarActions(QToolBar *toolbar)
130{
131 // camera control mode
132 toolbar->addSeparator();
133 QAction *transAction = new QAction(QIcon::fromTheme("forward"), tr("camera translation mode"), this);
134 connect(transAction, SIGNAL(triggered()), this, SLOT(setCameraControlModeTranslation()));
135 toolbar->addAction(transAction);
136 QAction *rotAction = new QAction(QIcon::fromTheme("object-rotate-left"), tr("camera rotation mode"), this);
137 connect(rotAction, SIGNAL(triggered()), this, SLOT(setCameraControlModeRotation()));
138 toolbar->addAction(rotAction);
139 QAction *fitAction = new QAction(QIcon::fromTheme("zoom-best-fit"), tr("camera fit to domain"), this);
140 connect(fitAction, SIGNAL(triggered()), this, SLOT(fitCameraToDomain()));
141 toolbar->addAction(fitAction);
142
143 // stereo mode
144 QToolButton *stereoButton = new QToolButton(toolbar);
145 QMenu *stereoMenu = new QMenu();
146 QAction *stereoDisableAction = new QAction(QIcon::fromTheme("zoom-best-fit"), tr("disable"), this);
147 connect(stereoDisableAction, SIGNAL(triggered()), this, SLOT(setCameraStereoModeDisable()));
148 stereoMenu->addAction(stereoDisableAction);
149 QAction *stereoHardwareAction = new QAction(QIcon::fromTheme("zoom-best-fit"), tr("hardware"), this);
150 connect(stereoHardwareAction, SIGNAL(triggered()), this, SLOT(setCameraStereoModeHardware()));
151 stereoMenu->addAction(stereoHardwareAction);
152 QAction *stereoLeftRightAction = new QAction(QIcon::fromTheme("zoom-best-fit"), tr("left right"), this);
153 connect(stereoLeftRightAction, SIGNAL(triggered()), this, SLOT(setCameraStereoModeLeftRight()));
154 stereoMenu->addAction(stereoLeftRightAction);
155 QAction *stereoRightLeftAction = new QAction(QIcon::fromTheme("zoom-best-fit"), tr("right left"), this);
156 connect(stereoRightLeftAction, SIGNAL(triggered()), this, SLOT(setCameraStereoModeRightLeft()));
157 stereoMenu->addAction(stereoRightLeftAction);
158 QAction *stereoTopBottomAction = new QAction(QIcon::fromTheme("zoom-best-fit"), tr("top bottom"), this);
159 connect(stereoTopBottomAction, SIGNAL(triggered()), this, SLOT(setCameraStereoModeTopBottom()));
160 stereoMenu->addAction(stereoTopBottomAction);
161 QAction *stereoBottomTopAction = new QAction(QIcon::fromTheme("zoom-best-fit"), tr("bottom top"), this);
162 connect(stereoBottomTopAction, SIGNAL(triggered()), this, SLOT(setCameraStereoModeBottomTop()));
163 stereoMenu->addAction(stereoBottomTopAction);
164 QAction *stereoAnaglyphAction = new QAction(QIcon::fromTheme("zoom-best-fit"), tr("anaglyph"), this);
165 connect(stereoAnaglyphAction, SIGNAL(triggered()), this, SLOT(setCameraStereoModeAnaglyph()));
166 stereoMenu->addAction(stereoAnaglyphAction);
167 stereoButton->setMenu(stereoMenu);
168 stereoButton->setIcon(QIcon::fromTheme("find"));
169 stereoButton->setPopupMode(QToolButton::InstantPopup);
170 toolbar->addWidget(stereoButton);
171
172 // selection mode
173 toolbar->addSeparator();
174 QAction *selAtomAction = new QAction(QIcon::fromTheme("edit-select-all"), tr("select atom by clicking"), this);
175 connect(selAtomAction, SIGNAL(triggered()), worldscene, SLOT(setSelectionModeAtom()));
176 toolbar->addAction(selAtomAction);
177 QAction *selMolAction = new QAction(QIcon::fromTheme("edit-select-all"), tr("select molecule by clicking"), this);
178 connect(selMolAction, SIGNAL(triggered()), worldscene, SLOT(setSelectionModeMolecule()));
179 toolbar->addAction(selMolAction);
180}
181
182void GLWorldView::createDomainBox()
183{
184 QSettings settings;
185 settings.beginGroup("WorldView");
186 QColor colorFrame = settings.value("domainBoxColorFrame", QColor(150,160,200,255)).value<QColor>();
187 QColor colorAmbient = settings.value("domainBoxColorAmbient", QColor(50,60,100,255)).value<QColor>();
188 QColor colorDiffuse = settings.value("domainBoxColorDiffuse", QColor(150,160,200,180)).value<QColor>();
189 settings.setValue("domainBoxColorFrame", colorFrame);
190 settings.setValue("domainBoxColorAmbient", colorAmbient);
191 settings.setValue("domainBoxColorDiffuse", colorDiffuse);
192 settings.endGroup();
193
194 domainBoxMaterial = new QGLMaterial;
195 domainBoxMaterial->setAmbientColor(QColor(0,0,0,255));
196 domainBoxMaterial->setDiffuseColor(QColor(0,0,0,255));
197 domainBoxMaterial->setEmittedLight(colorFrame);
198
199
200 QGLMaterial *material = new QGLMaterial;
201 material->setAmbientColor(colorAmbient);
202 material->setDiffuseColor(colorDiffuse);
203
204 QGLBuilder builder;
205 builder << QGL::Faceted;
206 builder << QGLCube(-1.0); // "inverted" => inside faces are used as front.
207 meshDomainBox = builder.finalizedSceneNode();
208 QMatrix4x4 mat;
209 mat.translate(0.5f, 0.5f, 0.5f);
210 meshDomainBox->setLocalTransform(mat);
211 meshDomainBox->setMaterial(material);
212}
213
214void GLWorldView::createDreiBein()
215{
216 QSettings settings;
217 settings.beginGroup("WorldView");
218 QColor colorX = settings.value("dreiBeinColorX", QColor(255,50,50,255)).value<QColor>();
219 QColor colorY = settings.value("dreiBeinColorY", QColor(50,255,50,255)).value<QColor>();
220 QColor colorZ = settings.value("dreiBeinColorZ", QColor(50,50,255,255)).value<QColor>();
221 settings.setValue("dreiBeinColorX", colorX);
222 settings.setValue("dreiBeinColorY", colorY);
223 settings.setValue("dreiBeinColorZ", colorZ);
224 settings.setValue("dreiBeinEnabled", true);
225 settings.endGroup();
226
227 // Create 3 color for the 3 axes.
228 dreiBeinMaterial[0] = new QGLMaterial;
229 dreiBeinMaterial[0]->setColor(colorX);
230 dreiBeinMaterial[1] = new QGLMaterial;
231 dreiBeinMaterial[1]->setColor(colorY);
232 dreiBeinMaterial[2] = new QGLMaterial;
233 dreiBeinMaterial[2]->setColor(colorZ);
234
235 // Create the basic meshes (cylinder and cone).
236 QGLBuilder builderCyl;
237 builderCyl << QGLCylinder(.15,.15,1.0,16);
238 QGLSceneNode *cyl = builderCyl.finalizedSceneNode();
239
240 QGLBuilder builderCone;
241 builderCone << QGLCylinder(0,.4,0.4,16);
242 QGLSceneNode *cone = builderCone.finalizedSceneNode();
243 {
244 QMatrix4x4 mat;
245 mat.translate(0.0f, 0.0f, 1.0f);
246 cone->setLocalTransform(mat);
247 }
248
249 // Create a scene node from the 3 axes.
250 meshDreiBein = new QGLSceneNode(this);
251
252 // X-direction
253 QGLSceneNode *node = new QGLSceneNode(meshDreiBein);
254 node->setMaterial(dreiBeinMaterial[0]);
255 node->addNode(cyl);
256 node->addNode(cone);
257 {
258 QMatrix4x4 mat;
259 mat.rotate(90, 0.0f, 1.0f, 0.0f);
260 node->setLocalTransform(mat);
261 }
262
263 // Y-direction
264 node = new QGLSceneNode(meshDreiBein);
265 node->setMaterial(dreiBeinMaterial[1]);
266 node->addNode(cyl);
267 node->addNode(cone);
268 {
269 QMatrix4x4 mat;
270 mat.rotate(-90, 1.0f, 0.0f, 0.0f);
271 node->setLocalTransform(mat);
272 }
273
274 // Z-direction
275 node = new QGLSceneNode(meshDreiBein);
276 node->setMaterial(dreiBeinMaterial[2]);
277 node->addNode(cyl);
278 node->addNode(cone);
279}
280
281/**
282 * Update operation which can be invoked by the observable (which should be the
283 * change tracker here).
284 */
285void GLWorldView::update(Observable *publisher)
286{
287 emit changed();
288}
289
290/**
291 * The observable can tell when it dies.
292 */
293void GLWorldView::subjectKilled(Observable *publisher) {}
294
295/** Listen to specific changes to the world.
296 *
297 * @param publisher ref to observable.
298 * @param notification type of notification
299 */
300void GLWorldView::recieveNotification(Observable *publisher, Notification_ptr notification)
301{
302 if (static_cast<World *>(publisher) == World::getPointer()) {
303 switch (notification->getChannelNo()) {
304 case World::AtomInserted:
305 {
306 const atom *_atom = World::getInstance().lastChanged<atom>();
307 #ifdef LOG_OBSERVER
308 observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that atom "+toString(_atom->getId())+" has been inserted.";
309 #endif
310 emit atomInserted(_atom);
311 break;
312 }
313 case World::AtomRemoved:
314 {
315 const atom *_atom = World::getInstance().lastChanged<atom>();
316 #ifdef LOG_OBSERVER
317 observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that atom "+toString(_atom->getId())+" has been removed.";
318 #endif
319 emit atomRemoved(_atom);
320 break;
321 }
322 case World::SelectionChanged:
323 {
324 #ifdef LOG_OBSERVER
325 observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that selection has changed.";
326 #endif
327 emit worldSelectionChanged();
328 break;
329 }
330 case World::MoleculeInserted:
331 {
332 const molecule *_molecule = World::getInstance().lastChanged<molecule>();
333 #ifdef LOG_OBSERVER
334 observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that molecule "+toString(_molecule->getId())+" has been removed.";
335 #endif
336 emit moleculeInserted(_molecule);
337 break;
338 }
339 case World::MoleculeRemoved:
340 {
341 const molecule *_molecule = World::getInstance().lastChanged<molecule>();
342 #ifdef LOG_OBSERVER
343 observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that molecule "+toString(_molecule->getId())+" has been removed.";
344 #endif
345 emit moleculeRemoved(_molecule);
346 break;
347 }
348 default:
349 ASSERT(0, "GLWorldView::recieveNotification() - we cannot get here.");
350 break;
351 }
352 } else if (dynamic_cast<AtomObservable *>(publisher) != NULL) {
353 switch (notification->getChannelNo()) {
354 case AtomObservable::PositionChanged:
355 {
356 const atom *_atom = dynamic_cast<const atom *>(publisher);
357 #ifdef LOG_OBSERVER
358 observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that atom "+toString(_atom->getId())+" has changed its position.";
359 #endif
360 emit changed();
361 break;
362 }
363 default:
364 ASSERT(0, "GLWorldView::recieveNotification() - we cannot get here.");
365 break;
366 }
367 } else if (static_cast<ShapeRegistry*>(publisher) == ShapeRegistry::getPointer()) {
368 switch (notification->getChannelNo()) {
369 case ShapeRegistry::ShapeRemoved:
370 {
371 updateSelectedShapes();
372 break;
373 }
374 case ShapeRegistry::SelectionChanged:
375 {
376 updateSelectedShapes();
377 break;
378 }
379 default:
380 ASSERT(0, "GLWorldView::recieveNotification() - we cannot get here.");
381 break;
382 }
383 } else
384 ASSERT(0, "GLWorldView::recieveNotification() - received notification from unknown source.");
385}
386
387void GLWorldView::checkChanges()
388{
389 updateGL();
390 needsRedraw = false;
391}
392
393void GLWorldView::sceneChangeSignalled()
394{
395 if (!needsRedraw){
396 redrawTimer->singleShot(0, this, SLOT(checkChanges()));
397 needsRedraw = true;
398 redrawTimer->start();
399 }
400}
401
402void GLWorldView::initializeGL(QGLPainter *painter)
403{
404 worldscene->initialize(this, painter);
405 changesPresent = false;
406}
407
408void GLWorldView::paintGL(QGLPainter *painter)
409{
410 if (changesPresent) {
411 initializeGL(painter);
412 changesPresent = false;
413 }
414
415 QVector3D cameraDir = camera()->center() - camera()->eye();
416 cameraDir.normalize();
417 QVector4D cameraPlane(cameraDir, QVector3D::dotProduct(cameraDir, camera()->eye()));
418 worldscene->draw(painter, cameraPlane);
419
420 drawDreiBein(painter);
421
422 // Domain box has to be last because of its transparency.
423 drawDomainBox(painter);
424}
425
426void GLWorldView::keyPressEvent(QKeyEvent *e)
427{
428 if (e->key() == Qt::Key_Tab) {
429 // The Tab key turns the ShowPicking option on and off,
430 // which helps show what the pick buffer looks like.
431 setOption(QGLView::ShowPicking, ((options() & QGLView::ShowPicking) == 0));
432 updateGL();
433 }
434 QGLView::keyPressEvent(e);
435}
436
437void GLWorldView::changeSignalled()
438{
439 changesPresent = true;
440}
441
442
443/**
444 * Set the current camera control mode.
445 */
446void GLWorldView::setCameraControlMode(GLWorldView::CameraControlModeType mode)
447{
448 cameraControlMode = mode;
449}
450
451void GLWorldView::setCameraControlModeRotation()
452{
453 setCameraControlMode(Rotate);
454}
455
456void GLWorldView::setCameraControlModeTranslation()
457{
458 setCameraControlMode(Translate);
459}
460
461/**
462 * Returns the current camera control mode.
463 * This needs to be invertable (rotation - translation), if the shift key is pressed.
464 */
465GLWorldView::CameraControlModeType GLWorldView::getCameraControlMode(bool inverted)
466{
467 if (inverted){
468 if (cameraControlMode == Rotate)
469 return Translate;
470 if (cameraControlMode == Translate)
471 return Rotate;
472 return Rotate;
473 }else
474 return cameraControlMode;
475}
476
477/**
478 * Set the camera so it can oversee the whole domain.
479 */
480void GLWorldView::fitCameraToDomain()
481{
482 // Move the camera focus point to the center of the domain box.
483 Vector v = World::getInstance().getDomain().translateIn(Vector(0.5, 0.5, 0.5));
484 camera()->setCenter(QVector3D(v[0], v[1], v[2]));
485
486 // Guess some eye distance.
487 double dist = v.Norm() * 3;
488 camera()->setEye(QVector3D(v[0], v[1], v[2] + dist));
489 camera()->setUpVector(QVector3D(0, 1, 0));
490}
491
492void GLWorldView::setCameraStereoModeDisable()
493{
494 setStereoType(QGLView::Hardware);
495 camera()->setEyeSeparation(0.0);
496 updateGL();
497}
498
499void GLWorldView::setCameraStereoModeHardware()
500{
501 setStereoType(QGLView::Hardware);
502 camera()->setEyeSeparation(defaultEyeSeparation);
503 updateGL();
504}
505
506void GLWorldView::setCameraStereoModeLeftRight()
507{
508 setStereoType(QGLView::LeftRight);
509 camera()->setEyeSeparation(defaultEyeSeparation);
510 updateGL();
511}
512
513void GLWorldView::setCameraStereoModeRightLeft()
514{
515 setStereoType(QGLView::RightLeft);
516 camera()->setEyeSeparation(defaultEyeSeparation);
517 updateGL();
518}
519
520void GLWorldView::setCameraStereoModeTopBottom()
521{
522 setStereoType(QGLView::TopBottom);
523 camera()->setEyeSeparation(defaultEyeSeparation);
524 updateGL();
525}
526
527void GLWorldView::setCameraStereoModeBottomTop()
528{
529 setStereoType(QGLView::BottomTop);
530 camera()->setEyeSeparation(defaultEyeSeparation);
531 updateGL();
532}
533
534void GLWorldView::setCameraStereoModeAnaglyph()
535{
536 setStereoType(QGLView::RedCyanAnaglyph);
537 camera()->setEyeSeparation(defaultEyeSeparation);
538 updateGL();
539}
540
541void GLWorldView::mousePressEvent(QMouseEvent *event)
542{
543 QGLView::mousePressEvent(event);
544
545 // Reset the saved mouse position.
546 lastMousePos = event->posF();
547}
548
549/**
550 * Handle a mouse move event.
551 * This is used to control the camera (rotation and translation) when the left button is being pressed.
552 */
553void GLWorldView::mouseMoveEvent(QMouseEvent *event)
554{
555 if (event->buttons() & Qt::LeftButton){
556 // Find the mouse distance since the last event.
557 QPointF d = event->posF() - lastMousePos;
558 lastMousePos = event->posF();
559
560 // Rotate or translate? (inverted by shift key)
561 CameraControlModeType mode = getCameraControlMode(event->modifiers() & Qt::ShiftModifier);
562
563 if (mode == Rotate){
564 // Rotate the camera.
565 d *= 0.3;
566 camera()->tiltPanRollCenter(- d.y(), - d.x(), 0);
567 }else if (mode == Translate){
568 // Translate the camera.
569 d *= 0.02;
570 camera()->translateCenter(- d.x(), d.y(), 0);
571 camera()->translateEye(- d.x(), d.y(), 0);
572 }
573 }else{
574 // Without this Qt would not test for hover events (i.e. mouse over an atom).
575 QGLView::mouseMoveEvent(event);
576 }
577}
578
579/**
580 * When the mouse wheel is used, zoom in or out.
581 */
582void GLWorldView::wheelEvent(QWheelEvent *event)
583{
584 // Find the distance between the eye and focus point.
585 QVector3D d = camera()->eye() - camera()->center();
586
587 // Scale the distance.
588 if (event->delta() < 0)
589 d *= 1.2;
590 else if (event->delta() > 0)
591 d /= 1.2;
592
593 // Set new eye position.
594 camera()->setEye(camera()->center() + d);
595}
596
597/**
598 * Draw a transparent cube representing the domain.
599 */
600void GLWorldView::drawDomainBox(QGLPainter *painter) const
601{
602 // Apply the domain matrix.
603 RealSpaceMatrix m = World::getInstance().getDomain().getM();
604 painter->modelViewMatrix().push();
605 painter->modelViewMatrix() *= QMatrix4x4(m.at(0,0), m.at(0,1), m.at(0,2), 0.0,
606 m.at(1,0), m.at(1,1), m.at(1,2), 0.0,
607 m.at(2,0), m.at(2,1), m.at(2,2), 0.0,
608 0.0, 0.0, 0.0, 1.0);
609
610 // Draw the transparent cube.
611 painter->setStandardEffect(QGL::LitMaterial);
612 glCullFace(GL_BACK);
613 glEnable(GL_CULL_FACE);
614 glEnable(GL_BLEND);
615 glDepthMask(0);
616 //glDisable(GL_DEPTH_TEST);
617 meshDomainBox->draw(painter);
618 //glEnable(GL_DEPTH_TEST);
619 glDepthMask(1);
620 glDisable(GL_BLEND);
621 glDisable(GL_CULL_FACE);
622
623 // Draw the outlines.
624 painter->setFaceMaterial(QGL::AllFaces, domainBoxMaterial);
625 //glEnable(GL_LINE_SMOOTH);
626 QVector3DArray array;
627 array.append(0, 0, 0); array.append(1, 0, 0);
628 array.append(1, 0, 0); array.append(1, 1, 0);
629 array.append(1, 1, 0); array.append(0, 1, 0);
630 array.append(0, 1, 0); array.append(0, 0, 0);
631
632 array.append(0, 0, 1); array.append(1, 0, 1);
633 array.append(1, 0, 1); array.append(1, 1, 1);
634 array.append(1, 1, 1); array.append(0, 1, 1);
635 array.append(0, 1, 1); array.append(0, 0, 1);
636
637 array.append(0, 0, 0); array.append(0, 0, 1);
638 array.append(1, 0, 0); array.append(1, 0, 1);
639 array.append(0, 1, 0); array.append(0, 1, 1);
640 array.append(1, 1, 0); array.append(1, 1, 1);
641 painter->clearAttributes();
642 painter->setVertexAttribute(QGL::Position, array);
643 painter->draw(QGL::Lines, 24);
644
645 painter->modelViewMatrix().pop();
646}
647
648void GLWorldView::drawDreiBein(QGLPainter *painter)
649{
650 painter->modelViewMatrix().push();
651 painter->modelViewMatrix().translate(camera()->center());
652 painter->setStandardEffect(QGL::LitMaterial);
653 painter->setFaceMaterial(QGL::FrontFaces, NULL);
654 meshDreiBein->draw(painter);
655 painter->modelViewMatrix().pop();
656}
657
658void GLWorldView::sceneHoverSignalled(const atom *_atom)
659{
660 emit hoverChanged(_atom);
661}
662
663void GLWorldView::updateSelectedShapes()
664{
665 worldscene->clearShapes();
666 std::vector<Shape*> selectedShapes = ShapeRegistry::getInstance().getSelectedShapes();
667 for (unsigned int i=0; i<selectedShapes.size(); i++)
668 worldscene->addShape(*selectedShapes[i]);
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.