source: trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc@ 721

Last change on this file since 721 was 721, checked in by garnier, 18 years ago

mise a jour des shortcuts qui ne se displaient pas comme il faut. Ajout d un shortcut pour accelerer/relantir les mvt automatiques

  • Property svn:mime-type set to text/cpp
File size: 60.1 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id: G4OpenGLQtViewer.cc,v 1.10 2008/01/30 10:54:13 lgarnier Exp $
28// GEANT4 tag $Name: $
29//
30//
31// G4OpenGLQtViewer : Class to provide Qt specific
32// functionality for OpenGL in GEANT4
33//
34// 27/06/2003 : G.Barrand : implementation (at last !).
35
36#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
37
38#define GEANT4_QT_DEBUG
39
40#include "G4OpenGLQtViewer.hh"
41
42#include "G4ios.hh"
43#include "G4VisExtent.hh"
44#include "G4LogicalVolume.hh"
45#include "G4VSolid.hh"
46#include "G4Point3D.hh"
47#include "G4Normal3D.hh"
48#include "G4Scene.hh"
49#include "G4OpenGLQtExportDialog.hh"
50#include "G4UnitsTable.hh"
51#include "G4Qt.hh"
52#include "G4UImanager.hh"
53#include "G4UIcommandTree.hh"
54#include <qapplication.h>
55#include <qlayout.h>
56#include <qdialog.h>
57
58#if QT_VERSION >= 0x040000
59#include <qmenu.h>
60#include <qimagewriter.h>
61#else
62#include <qaction.h>
63#include <qwidgetlist.h>
64#include <qpopupmenu.h>
65#include <qimage.h>
66#endif
67
68#include <qapplication.h>
69#include <qmessagebox.h>
70#include <qfiledialog.h>
71#include <qprinter.h>
72#include <qpainter.h>
73#include <qgl.h> // include <qglwidget.h>
74#include <qdialog.h>
75#include <qevent.h> //include <qcontextmenuevent.h>
76
77
78//////////////////////////////////////////////////////////////////////////////
79/**
80 Implementation of virtual method of G4VViewer
81*/
82void G4OpenGLQtViewer::SetView (
83)
84//////////////////////////////////////////////////////////////////////////////
85//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
86{
87#ifdef GEANT4_QT_DEBUG
88 printf("G4OpenGLQtViewer::SetView ++++++++++++++++++++\n");
89#endif
90 // if(!fHDC) return;
91 // if(!fHGLRC) return;
92 // ::wglMakeCurrent(fHDC,fHGLRC);
93 // fWindow->makeCurrent();
94 G4OpenGLViewer::SetView ();
95#ifdef GEANT4_QT_DEBUG
96 printf("G4OpenGLQtViewer::SetView --------------------\n");
97#endif
98}
99
100/**
101 * Set the viewport of the scene
102 */
103void G4OpenGLQtViewer::setupViewport(int aWidth, int aHeight)
104{
105 int side = aWidth;
106 if (aHeight < aWidth) side = aHeight;
107 glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side);
108
109 glMatrixMode(GL_PROJECTION);
110 glLoadIdentity();
111 glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
112 glMatrixMode(GL_MODELVIEW);
113}
114
115
116//////////////////////////////////////////////////////////////////////////////
117/**
118 Implementation of virtual method of G4VViewer
119*/
120void G4OpenGLQtViewer::ShowView (
121)
122//////////////////////////////////////////////////////////////////////////////
123//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
124{
125#ifdef GEANT4_QT_DEBUG
126 printf("G4OpenGLQtViewer::ShowView +++++++++++++++++++++\n");
127#endif
128 if (!GLWindow) {
129 G4cerr << "Visualization window not defined, please choose one before\n" << G4endl;
130 } else {
131#if QT_VERSION < 0x040000
132 GLWindow->setActiveWindow();
133#else
134 GLWindow->activateWindow();
135#endif
136#ifdef GEANT4_QT_DEBUG
137 printf("G4OpenGLQtViewer::ShowView -----------------------\n");
138#endif
139 }
140 glFlush ();
141 // // Empty the Windows message queue :
142 // MSG event;
143 // while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
144 // ::TranslateMessage(&event);
145 // ::DispatchMessage (&event);
146 // }
147}
148
149
150
151//////////////////////////////////////////////////////////////////////////////
152void G4OpenGLQtViewer::CreateGLQtContext (
153)
154//////////////////////////////////////////////////////////////////////////////
155//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
156{
157#ifdef GEANT4_QT_DEBUG
158 printf("G4OpenGLQtViewer::CreateGLQtContext \n");
159#endif
160}
161
162
163//////////////////////////////////////////////////////////////////////////////
164void G4OpenGLQtViewer::CreateMainWindow (
165 QGLWidget* glWidget
166)
167//////////////////////////////////////////////////////////////////////////////
168//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
169{
170
171 if(fWindow) return; //Done.
172#ifdef GEANT4_QT_DEBUG
173 printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n");
174#endif
175
176 // launch Qt if not
177 G4Qt* interactorManager = G4Qt::getInstance ();
178 // G4UImanager* UI = G4UImanager::GetUIpointer();
179
180 fWindow = glWidget ;
181 // fWindow->makeCurrent();
182
183 // create window
184 if (((QApplication*)interactorManager->GetMainInteractor())) {
185 // look for the main window
186 bool found = false;
187#if QT_VERSION < 0x040000
188 // theses lines does nothing exept this one "GLWindow = new QDialog(0..."
189 // but if I comment them, it doesn't work...
190 QWidgetList *list = QApplication::allWidgets();
191 QWidgetListIt it( *list ); // iterate over the widgets
192 QWidget * widget;
193 while ( (widget=it.current()) != 0 ) { // for each widget...
194 ++it;
195 if ((found== false) && (widget->inherits("QMainWindow"))) {
196 GLWindow = new QDialog(0,0,FALSE,Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_MinMax );
197 found = true;
198 }
199 }
200 delete list; // delete the list, not the widgets
201#else
202 foreach (QWidget *widget, QApplication::allWidgets()) {
203 if ((found== false) && (widget->inherits("QMainWindow"))) {
204 GLWindow = new QDialog(0,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
205 found = true;
206 }
207 }
208#endif
209
210#if QT_VERSION < 0x040000
211 glWidget->reparent(GLWindow,0,QPoint(0,0));
212#else
213 glWidget->setParent(GLWindow);
214#endif
215
216 if (found==false) {
217#ifdef GEANT4_QT_DEBUG
218 printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n");
219#endif
220 GLWindow = new QDialog();
221 }
222 } else {
223#ifdef GEANT4_QT_DEBUG
224 printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
225#endif
226 GLWindow = new QDialog();
227 }
228
229 QHBoxLayout *mainLayout = new QHBoxLayout(GLWindow);
230
231 mainLayout->addWidget(fWindow);
232
233#if QT_VERSION < 0x040000
234 GLWindow->setCaption( tr( "QGl Viewer" ));
235#else
236 GLWindow->setLayout(mainLayout);
237 GLWindow->setWindowTitle(tr("QGl Viewer"));
238#endif
239 GLWindow->resize(300, 300);
240 GLWindow->move(900,300);
241 GLWindow->show();
242
243 // delete the pointer if close this
244 // GLWindow->setAttribute(Qt::WA_DeleteOnClose);
245
246#if QT_VERSION >= 0x040000
247// QObject ::connect(GLWindow,
248// SIGNAL(rejected()),
249// this,
250// SLOT(dialogClosed()));
251#endif
252
253 WinSize_x = 400;
254 WinSize_y = 400;
255 if (WinSize_x < fVP.GetWindowSizeHintX ())
256 WinSize_x = fVP.GetWindowSizeHintX ();
257 if (WinSize_y < fVP.GetWindowSizeHintY ())
258 WinSize_y = fVP.GetWindowSizeHintY ();
259
260 if(!fWindow) return;
261#ifdef GEANT4_QT_DEBUG
262 printf("G4OpenGLQtViewer::CreateMainWindow glWidget END\n");
263#endif
264
265 if (!fContextMenu)
266 createPopupMenu();
267
268}
269
270#if QT_VERSION >= 0x040000
271/** Close the dialog and set the pointer to NULL
272 */
273// void G4OpenGLQtViewer::dialogClosed() {
274// #ifdef GEANT4_QT_DEBUG
275// printf("G4OpenGLQtViewer::dialogClosed END\n");
276// #endif
277// // GLWindow = NULL;
278// }
279#endif
280
281//////////////////////////////////////////////////////////////////////////////
282G4OpenGLQtViewer::G4OpenGLQtViewer (
283 G4OpenGLSceneHandler& scene
284 )
285 :G4VViewer (scene, -1)
286 ,G4OpenGLViewer (scene)
287 ,fWindow(0)
288 ,fContextMenu(0)
289 ,fMouseAction(STYLE1)
290 ,fDeltaRotation(1)
291 ,fDeltaSceneTranslation(0.01)
292 ,fDeltaDepth(0.01)
293 ,fDeltaZoom(0.1)
294 ,fDeltaMove(0.2)
295 ,fHoldKeyEvent(false)
296 ,fAutoMove(false)
297{
298#ifdef GEANT4_QT_DEBUG
299 printf("G4OpenGLQtViewer::G4OpenGLQtViewer \n");
300#endif
301}
302
303//////////////////////////////////////////////////////////////////////////////
304G4OpenGLQtViewer::~G4OpenGLQtViewer (
305)
306//////////////////////////////////////////////////////////////////////////////
307//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
308{
309#ifdef GEANT4_QT_DEBUG
310 printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n");
311#endif
312}
313
314
315/**
316 Create a popup menu for the widget. This menu is activated by right-mouse click
317*/
318void G4OpenGLQtViewer::createPopupMenu() {
319
320#if QT_VERSION < 0x040000
321 fContextMenu = new QPopupMenu( GLWindow,"All" );
322#else
323 fContextMenu = new QMenu("All");
324#endif
325
326#if QT_VERSION < 0x040000
327 QPopupMenu *mMouseAction = new QPopupMenu( fContextMenu );
328 fContextMenu->insertItem("&Mouse actions",mMouseAction);
329#if QT_VERSION < 0x030200
330 fRotateAction = new QAction("&Rotate","&Rotate",CTRL+Key_R,mMouseAction,0,true);
331 fMoveAction = new QAction("&Move","&Move",CTRL+Key_M,mMouseAction,0,true);
332 fPickAction = new QAction("&Pick","&Pick",CTRL+Key_P,mMouseAction,0,true);
333 QAction * shortcutsAction = new QAction("&Show shortcuts","&Show shortcuts",CTRL+Key_S,mMouseAction,0,true);
334#else
335 fRotateAction = new QAction("&Rotate",CTRL+Key_R,mMouseAction);
336 fMoveAction = new QAction("&Move",CTRL+Key_M,mMouseAction);
337 fPickAction = new QAction("&Pick",CTRL+Key_P,mMouseAction);
338 QAction *shortcutsAction = new QAction("&Show shortcuts",CTRL+Key_S,mMouseAction);
339#endif
340 fRotateAction->addTo(mMouseAction);
341 fMoveAction->addTo(mMouseAction);
342 fPickAction->addTo(mMouseAction);
343 shortcutsAction->addTo(mMouseAction);
344
345 fRotateAction->setToggleAction(true);
346 fMoveAction->setToggleAction(true);
347 fPickAction->setToggleAction(true);
348 shortcutsAction->setToggleAction(true);
349
350 fRotateAction->setOn(true);
351 fMoveAction->setOn(false);
352 fPickAction->setOn(false);
353 shortcutsAction->setOn(false);
354
355
356 QObject ::connect(fRotateAction,
357 SIGNAL(activated()),
358 this,
359 SLOT(actionMouseRotate()));
360
361 QObject ::connect(fMoveAction,
362 SIGNAL(activated()),
363 this,
364 SLOT(actionMouseMove()));
365
366 QObject ::connect(fPickAction,
367 SIGNAL(activated()),
368 this,
369 SLOT(actionMousePick()));
370
371 QObject ::connect(shortcutsAction,
372 SIGNAL(activated()),
373 this,
374 SLOT(showShortcuts()));
375
376#else
377 QMenu *mMouseAction = fContextMenu->addMenu("&Mouse actions");
378
379 fRotateAction = mMouseAction->addAction("Rotate");
380 fMoveAction = mMouseAction->addAction("Move");
381 fPickAction = mMouseAction->addAction("Pick");
382 QAction *shortcutsAction = mMouseAction->addAction("Show shortcuts");
383
384 fRotateAction->setCheckable(true);
385 fMoveAction->setCheckable(false);
386 fPickAction->setCheckable(false);
387 shortcutsAction->setCheckable(false);
388
389 fRotateAction->setChecked(true);
390 fMoveAction->setChecked(false);
391 fPickAction->setChecked(false);
392 shortcutsAction->setChecked(false);
393
394 QObject ::connect(fRotateAction,
395 SIGNAL(triggered(bool)),
396 this,
397 SLOT(actionMouseRotate()));
398
399 QObject ::connect(fMoveAction,
400 SIGNAL(triggered(bool)),
401 this,
402 SLOT(actionMouseMove()));
403
404 QObject ::connect(fPickAction,
405 SIGNAL(triggered(bool)),
406 this,
407 SLOT(actionMousePick()));
408
409 QObject ::connect(shortcutsAction,
410 SIGNAL(triggered(bool)),
411 this,
412 SLOT(showShortcuts()));
413#endif
414
415#if QT_VERSION < 0x040000
416 // === Style Menu ===
417 QPopupMenu *mStyle = new QPopupMenu(fContextMenu);
418
419 QPopupMenu *mRepresentation = new QPopupMenu(fContextMenu);
420
421 QPopupMenu *mProjection = new QPopupMenu(fContextMenu);
422
423#if QT_VERSION < 0x030200
424 QAction *polyhedron = new QAction("&Polyhedron","&Polyhedron",CTRL+Key_P,mRepresentation,0,true);
425 QAction *nurbs = new QAction("&NURBS","&NURBS",CTRL+Key_N,mRepresentation,0,true);
426
427 QAction *ortho = new QAction("&Orthographic","&Orthographic",CTRL+Key_O,mProjection,0,true);
428 QAction *perspective = new QAction("&Perspective","&Perspective",CTRL+Key_P,mProjection,0,true);
429#else
430 QAction *polyhedron = new QAction("&Polyhedron",CTRL+Key_P,mRepresentation);
431 QAction *nurbs = new QAction("&NURBS",CTRL+Key_N,mRepresentation);
432
433 QAction *ortho = new QAction("&Orthographic",CTRL+Key_O,mProjection);
434 QAction *perspective = new QAction("&Perspective",CTRL+Key_P,mProjection);
435 polyhedron->setToggleAction(true);
436 nurbs->setToggleAction(true);
437 ortho->setToggleAction(true);
438 perspective->setToggleAction(true);
439#endif
440 polyhedron->addTo(mRepresentation);
441 nurbs->addTo(mRepresentation);
442
443 ortho->addTo(mProjection);
444 perspective->addTo(mProjection);
445
446 mStyle->insertItem("&Representation",mRepresentation);
447 mStyle->insertItem("&Projection",mProjection);
448 fContextMenu->insertItem("&Style",mStyle);
449
450
451#else
452 // === Style Menu ===
453 QMenu *mStyle = fContextMenu->addMenu("&Style");
454
455 QMenu *mRepresentation = mStyle->addMenu("&Representation");
456 QMenu *mProjection = mStyle->addMenu("&Projection");
457 QAction *polyhedron = mRepresentation->addAction("Polyhedron");
458 QAction *nurbs = mRepresentation->addAction("NURBS");
459
460 QAction *ortho = mProjection->addAction("Orthographic");
461 QAction *perspective = mProjection->addAction("Persepective");
462#endif
463
464 // INIT mRepresentation
465 G4ViewParameters::RepStyle style;
466 style = fVP.GetRepStyle();
467 if (style == G4ViewParameters::polyhedron) {
468 createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),1);
469 } else if (style == G4ViewParameters::nurbs) {
470 createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),2);
471 } else {
472 mRepresentation->clear();
473 }
474
475 // INIT mProjection
476 if (fVP.GetFieldHalfAngle() == 0) {
477 createRadioAction(ortho, perspective,SLOT(toggleProjection(bool)),1);
478 } else {
479 createRadioAction(ortho, perspective,SLOT(toggleProjection(bool)),2);
480 }
481
482#if QT_VERSION < 0x040000
483 // === Drawing Menu ===
484 QPopupMenu *mDrawing = new QPopupMenu(fContextMenu);
485 fContextMenu->insertItem("&Drawing",mDrawing);
486
487#if QT_VERSION < 0x030200
488 fDrawingWireframe = new QAction("&Wireframe","&Wireframe",CTRL+Key_W,mDrawing,0,true);
489 fDrawingLineRemoval = new QAction("&Hidden line removal","&Hidden line removal",CTRL+Key_L,mDrawing,0,true);
490 fDrawingSurfaceRemoval = new QAction("&Hidden surface removal","&Hidden surface removal",CTRL+Key_S,mDrawing,0,true);
491 fDrawingLineSurfaceRemoval = new QAction("&Hidden line and surface removal","&Hidden line and surface removal",CTRL+Key_R,mDrawing,0,true);
492#else
493 fDrawingWireframe = new QAction("&Wireframe",CTRL+Key_W,mDrawing);
494 fDrawingLineRemoval = new QAction("&Hidden line removal",CTRL+Key_L,mDrawing);
495 fDrawingSurfaceRemoval = new QAction("&Hidden surface removal",CTRL+Key_S,mDrawing);
496 fDrawingLineSurfaceRemoval = new QAction("&Hidden line and surface removal",CTRL+Key_R,mDrawing);
497#endif
498 fDrawingWireframe->setToggleAction(true);
499 fDrawingLineRemoval->setToggleAction(true);
500 fDrawingSurfaceRemoval->setToggleAction(true);
501 fDrawingLineSurfaceRemoval->setToggleAction(true);
502
503 fDrawingWireframe->addTo(mDrawing);
504 fDrawingLineRemoval->addTo(mDrawing);
505 fDrawingSurfaceRemoval->addTo(mDrawing);
506 fDrawingLineSurfaceRemoval->addTo(mDrawing);
507
508
509#else
510 // === Drawing Menu ===
511 QMenu *mDrawing = mStyle->addMenu("&Drawing");
512
513 fDrawingWireframe = mDrawing->addAction("Wireframe");
514 fDrawingWireframe->setCheckable(true);
515
516 fDrawingLineRemoval = mDrawing->addAction("Hidden line removal");
517 fDrawingLineRemoval->setCheckable(true);
518
519 fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal");
520 fDrawingSurfaceRemoval->setCheckable(true);
521
522 fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal");
523 fDrawingLineSurfaceRemoval->setCheckable(true);
524#endif
525 // INIT Drawing
526 G4ViewParameters::DrawingStyle d_style;
527 d_style = fVP.GetDrawingStyle();
528
529#if QT_VERSION < 0x040000
530 if (d_style == G4ViewParameters::wireframe) {
531 fDrawingWireframe->setOn(true);
532 } else if (d_style == G4ViewParameters::hlr) {
533 fDrawingLineRemoval->setOn(true);
534 } else if (d_style == G4ViewParameters::hsr) {
535 fDrawingSurfaceRemoval->setOn(true);
536 } else if (d_style == G4ViewParameters::hlhsr) {
537 fDrawingLineSurfaceRemoval->setOn(true);
538 } else {
539 mDrawing->clear();
540 }
541#ifdef GEANT4_QT_DEBUG
542 printf("G4OpenGLQtViewer:: fDrawingWireframe 1\n");
543#endif
544 QObject ::connect(fDrawingWireframe,
545 SIGNAL(activated()),
546 this,
547 SLOT(actionDrawingWireframe()));
548#ifdef GEANT4_QT_DEBUG
549 printf("G4OpenGLQtViewer:: fDrawingWireframe 2\n");
550#endif
551 QObject ::connect(fDrawingLineRemoval,
552 SIGNAL(activated()),
553 this,
554 SLOT(actionDrawingLineRemoval()));
555 QObject ::connect(fDrawingSurfaceRemoval,
556 SIGNAL(activated()),
557 this,
558 SLOT(actionDrawingSurfaceRemoval()));
559 QObject ::connect(fDrawingLineSurfaceRemoval,
560 SIGNAL(activated()),
561 this,
562 SLOT(actionDrawingLineSurfaceRemoval()));
563#else
564 if (d_style == G4ViewParameters::wireframe) {
565 fDrawingWireframe->setChecked(true);
566 } else if (d_style == G4ViewParameters::hlr) {
567 fDrawingLineRemoval->setChecked(true);
568 } else if (d_style == G4ViewParameters::hsr) {
569 fDrawingSurfaceRemoval->setChecked(true);
570 } else if (d_style == G4ViewParameters::hlhsr) {
571 fDrawingLineSurfaceRemoval->setChecked(true);
572 } else {
573 mDrawing->clear();
574 }
575 QObject ::connect(fDrawingWireframe,
576 SIGNAL(triggered(bool)),
577 this,
578 SLOT(actionDrawingWireframe()));
579 QObject ::connect(fDrawingLineRemoval,
580 SIGNAL(triggered(bool)),
581 this,
582 SLOT(actionDrawingLineRemoval()));
583 QObject ::connect(fDrawingSurfaceRemoval,
584 SIGNAL(triggered(bool)),
585 this,
586 SLOT(actionDrawingSurfaceRemoval()));
587 QObject ::connect(fDrawingLineSurfaceRemoval,
588 SIGNAL(triggered(bool)),
589 this,
590 SLOT(actionDrawingLineSurfaceRemoval()));
591#endif
592
593
594
595#if QT_VERSION < 0x040000
596 QPopupMenu *mBackground = new QPopupMenu(mStyle);
597 mStyle->insertItem("&Background color",mBackground);
598
599#if QT_VERSION < 0x030200
600 QAction *white = new QAction("&White","&White",CTRL+Key_W,mBackground,0,true);
601 QAction *black = new QAction("&Black","&Black",CTRL+Key_B,mBackground,0,true);
602#else
603 QAction *white = new QAction("&White",CTRL+Key_W,mBackground);
604 QAction *black = new QAction("&Black",CTRL+Key_B,mBackground);
605 white->setToggleAction(true);
606 black->setToggleAction(true);
607#endif
608 white->addTo(mBackground);
609 black->addTo(mBackground);
610
611#else
612 QMenu *mBackground = mStyle->addMenu("&Background color");
613 QAction *white = mBackground->addAction("White");
614 QAction *black = mBackground->addAction("Black");
615
616#endif
617 if (background.GetRed() == 1. &&
618 background.GetGreen() == 1. &&
619 background.GetBlue() == 1.) {
620 createRadioAction(white,black,SLOT(toggleBackground(bool)),1);
621 } else {
622 createRadioAction(white,black,SLOT(toggleBackground(bool)),2);
623 }
624
625
626#if QT_VERSION < 0x040000
627 // === Action Menu ===
628 QPopupMenu *mActions = new QPopupMenu(fContextMenu);
629 fContextMenu->insertItem("&Actions",mActions);
630
631#if QT_VERSION < 0x030200
632 QAction *createEPS = new QAction("&Save as ...","&Save as ...",CTRL+Key_S,mActions,0,true);
633#else
634 QAction *createEPS = new QAction("&Save as ...",CTRL+Key_S,mActions);
635#endif
636 createEPS->addTo(mActions);
637 QObject ::connect(createEPS,
638 SIGNAL(activated()),
639 this,
640 SLOT(actionCreateEPS()));
641
642#else
643 // === Action Menu ===
644 QMenu *mActions = fContextMenu->addMenu("&Actions");
645 QAction *createEPS = mActions->addAction("Save as ...");
646 QObject ::connect(createEPS,
647 SIGNAL(triggered()),
648 this,
649 SLOT(actionCreateEPS()));
650#endif
651
652
653
654#if QT_VERSION < 0x040000
655 // === Special Menu ===
656 QPopupMenu *mSpecial = new QPopupMenu(fContextMenu);
657 fContextMenu->insertItem("S&pecial",mSpecial);
658
659 QPopupMenu *mTransparency = new QPopupMenu(mSpecial);
660 mSpecial->insertItem("Transparency",mTransparency);
661
662#if QT_VERSION < 0x030200
663 QAction *transparencyOn = new QAction("&On","&On",CTRL+Key_O,mTransparency,0,true);
664 QAction *transparencyOff = new QAction("&Off","&Off",CTRL+Key_F,mTransparency,0,true);
665#else
666 QAction *transparencyOn = new QAction("&On",CTRL+Key_O,mTransparency);
667 QAction *transparencyOff = new QAction("&Off",CTRL+Key_F,mTransparency);
668 transparencyOn->setToggleAction(true);
669 transparencyOff->setToggleAction(true);
670#endif
671 transparencyOn->addTo(mTransparency);
672 transparencyOff->addTo(mTransparency);
673
674#else
675 // === Special Menu ===
676 QMenu *mSpecial = fContextMenu->addMenu("S&pecial");
677 QMenu *mTransparency = mSpecial->addMenu("Transparency");
678 QAction *transparencyOn = mTransparency->addAction("On");
679 QAction *transparencyOff = mTransparency->addAction("Off");
680#endif
681
682 if (transparency_enabled == false) {
683 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2);
684 } else if (transparency_enabled == true) {
685 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),1);
686 } else {
687 mSpecial->clear();
688 }
689
690
691#if QT_VERSION < 0x040000
692 QPopupMenu *mAntialiasing = new QPopupMenu(mSpecial);
693 mSpecial->insertItem("Antialiasing",mAntialiasing);
694
695#if QT_VERSION < 0x030200
696 QAction *antialiasingOn = new QAction("&On","&On",CTRL+Key_O,mAntialiasing,0,true);
697 QAction *antialiasingOff = new QAction("&Off","&Off",CTRL+Key_F,mAntialiasing,0,true);
698#else
699 QAction *antialiasingOn = new QAction("&On",CTRL+Key_O,mAntialiasing);
700 QAction *antialiasingOff = new QAction("&Off",CTRL+Key_F,mAntialiasing);
701 antialiasingOn->setToggleAction(true);
702 antialiasingOff->setToggleAction(true);
703#endif
704 antialiasingOn->addTo(mAntialiasing);
705 antialiasingOff->addTo(mAntialiasing);
706
707#else
708 QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing");
709 QAction *antialiasingOn = mAntialiasing->addAction("On");
710 QAction *antialiasingOff = mAntialiasing->addAction("Off");
711#endif
712
713 if (antialiasing_enabled == false) {
714 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2);
715 } else if (antialiasing_enabled == true) {
716 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),1);
717 } else {
718 mAntialiasing->clear();
719 }
720
721#if QT_VERSION < 0x040000
722 QPopupMenu *mHaloing = new QPopupMenu(mSpecial);
723 mSpecial->insertItem("Haloing",mHaloing);
724
725#if QT_VERSION < 0x030200
726 QAction *haloingOn = new QAction("&On","&On",CTRL+Key_O,mHaloing,0,true);
727 QAction *haloingOff = new QAction("&Off","&Off",CTRL+Key_F,mHaloing,0,true);
728#else
729 QAction *haloingOn = new QAction("&On",CTRL+Key_O,mHaloing);
730 QAction *haloingOff = new QAction("&Off",CTRL+Key_F,mHaloing);
731 haloingOn->setToggleAction(true);
732 haloingOff->setToggleAction(true);
733#endif
734 haloingOn->addTo(mHaloing);
735 haloingOff->addTo(mHaloing);
736#else
737 QMenu *mHaloing = mSpecial->addMenu("Haloing");
738 QAction *haloingOn = mHaloing->addAction("On");
739 QAction *haloingOff = mHaloing->addAction("Off");
740#endif
741 if (haloing_enabled == false) {
742 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2);
743 } else if (haloing_enabled == true) {
744 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),1);
745 } else {
746 mHaloing->clear();
747 }
748
749#if QT_VERSION < 0x040000
750 QPopupMenu *mAux = new QPopupMenu(mSpecial);
751 mSpecial->insertItem("Auxiliairy edges",mAux);
752
753#if QT_VERSION < 0x030200
754 QAction *auxOn = new QAction("&On","&On",CTRL+Key_O,mAux,0,true);
755 QAction *auxOff = new QAction("&Off","&Off",CTRL+Key_F,mAux,0,true);
756#else
757 QAction *auxOn = new QAction("&On",CTRL+Key_O,mAux);
758 QAction *auxOff = new QAction("&Off",CTRL+Key_F,mAux);
759 auxOn->setToggleAction(true);
760 auxOff->setToggleAction(true);
761#endif
762 auxOn->addTo(mAux);
763 auxOff->addTo(mAux);
764
765#else
766 QMenu *mAux = mSpecial->addMenu("Auxiliary edges");
767 QAction *auxOn = mAux->addAction("On");
768 QAction *auxOff = mAux->addAction("Off");
769#endif
770 if (!fVP.IsAuxEdgeVisible()) {
771 createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1);
772 } else {
773 createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),2);
774 }
775
776
777
778#if QT_VERSION < 0x040000
779 QPopupMenu *mFullScreen = new QPopupMenu(mSpecial);
780 mSpecial->insertItem("Full screen",mFullScreen);
781
782#if QT_VERSION < 0x030200
783 fFullScreenOn = new QAction("&On","&On",CTRL+Key_O,mFullScreen,0,true);
784 fFullScreenOff = new QAction("&Off","&Off",CTRL+Key_F,mFullScreen,0,true);
785#else
786 fFullScreenOn = new QAction("&On",CTRL+Key_O,mFullScreen);
787 fFullScreenOff = new QAction("&Off",CTRL+Key_F,mFullScreen);
788 fFullScreenOn->setToggleAction(true);
789 fFullScreenOff->setToggleAction(true);
790#endif
791 fFullScreenOn->addTo(mFullScreen);
792 fFullScreenOff->addTo(mFullScreen);
793#else
794 QMenu *mFullScreen = mSpecial->addMenu("&Full screen");
795 fFullScreenOn = mFullScreen->addAction("On");
796 fFullScreenOff = mFullScreen->addAction("Off");
797#endif
798 createRadioAction(fFullScreenOn,fFullScreenOff,SLOT(toggleFullScreen(bool)),2);
799
800}
801
802void G4OpenGLQtViewer::manageContextMenuEvent(QContextMenuEvent *e)
803{
804 if (!GLWindow) {
805 G4cerr << "Visualization window not defined, please choose one before\n" << G4endl;
806 } else {
807
808 if (!fContextMenu)
809 createPopupMenu();
810
811 // launch menu
812 if ( fContextMenu ) {
813 fContextMenu->exec( e->globalPos() );
814 // delete fContextMenu;
815 }
816 }
817 e->accept();
818}
819
820
821/**
822 Create a radio button menu. The two menu will be connected. When click on one,
823 eatch state will be invert and callback method will be called.
824 @param action1 first action to connect
825 @param action2 second action to connect
826 @param method callback method
827 @param nCheck: 1 : first action will be set true. 2 : second action will be set true
828*/
829#if QT_VERSION < 0x040000
830void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
831
832 if (action1->parent()->inherits("QPopupMenu")){
833 ((QPopupMenu*)action1->parent())->setCheckable(true);
834 ((QPopupMenu*)action2->parent())->setCheckable(true);
835 }
836 action1->setOn(false);
837 action2->setOn(false);
838
839 if (nCheck ==1)
840 action1->setOn(true);
841 else
842 action2->setOn(true);
843
844 //FIXME : Should not work on Qt3
845 QObject ::connect(action1, SIGNAL(activated()),action2, SLOT(toggle()));
846 QObject ::connect(action2, SIGNAL(activated()),action1, SLOT(toggle()));
847
848 QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str());
849}
850
851#else
852void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
853
854 action1->setCheckable(true);
855 action2->setCheckable(true);
856
857 if (nCheck ==1)
858 action1->setChecked (true);
859 else
860 action2->setChecked (true);
861
862 QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle()));
863 QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle()));
864
865 QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str());
866
867}
868#endif
869
870/**
871 Slot activate when mouseAction->rotate menu is set
872 */
873void G4OpenGLQtViewer::actionMouseRotate() {
874 emit toggleMouseAction(STYLE1);
875}
876
877
878/**
879 Slot activate when mouseAction->rotate menu is set
880 */
881void G4OpenGLQtViewer::actionMouseMove() {
882 emit toggleMouseAction(STYLE2);
883}
884
885
886/**
887 Slot activate when mouseAction->zoom menu is set
888 */
889void G4OpenGLQtViewer::actionMousePick() {
890#ifdef GEANT4_QT_DEBUG
891 printf("G4OpenGLQtViewer::actionMousePick \n");
892#endif
893 emit toggleMouseAction(STYLE3);
894}
895
896
897/**
898 Slot activate when drawing->wireframe menu is set
899 */
900void G4OpenGLQtViewer::actionDrawingWireframe() {
901 emit toggleDrawingAction(1);
902}
903
904/**
905 Slot activate when drawing->line removal menu is set
906 */
907void G4OpenGLQtViewer::actionDrawingLineRemoval() {
908 emit toggleDrawingAction(2);
909}
910
911/**
912 Slot activate when drawing->surface removal menu is set
913 */
914void G4OpenGLQtViewer::actionDrawingSurfaceRemoval() {
915 emit toggleDrawingAction(3);
916}
917
918/**
919 Slot activate when drawing->wireframe menu is set
920 */
921void G4OpenGLQtViewer::actionDrawingLineSurfaceRemoval() {
922 emit toggleDrawingAction(4);
923}
924
925
926/**
927 Slot activated when mouse action is toggle
928 @param aAction : STYLE1, STYLE2, STYLE3
929 */
930void G4OpenGLQtViewer::toggleMouseAction(mouseActions aAction) {
931
932 if ((aAction == STYLE1) || //initialize all
933 (aAction == STYLE2) ||
934 (aAction == STYLE3)) {
935#if QT_VERSION < 0x040000
936 fRotateAction->setOn (false);
937 fMoveAction->setOn (false);
938 fPickAction->setOn (false);
939#else
940 fRotateAction->setChecked (false);
941 fMoveAction->setChecked (false);
942 fPickAction->setChecked (false);
943#endif
944 fVP.SetPicking(false);
945 fMouseAction = aAction;
946 }
947 // rotate
948 if (aAction == STYLE1) { // rotate
949 showShortcuts();
950#if QT_VERSION < 0x040000
951 fRotateAction->setOn (true);
952#else
953 fRotateAction->setChecked (true);
954#endif
955 } else if (aAction == STYLE2) { //move
956#if QT_VERSION < 0x040000
957 fMoveAction->setOn (true);
958#else
959 fMoveAction->setChecked (true);
960#endif
961 } else if (aAction == STYLE3) { //pick
962#if QT_VERSION < 0x040000
963 fPickAction->setOn (true);
964#else
965 fPickAction->setChecked (true);
966#endif
967 fVP.SetPicking(true);
968 }
969}
970
971/**
972 Show shortcuts for this mouse action
973 */
974void G4OpenGLQtViewer::showShortcuts() {
975 if (fMouseAction == STYLE1) { // rotate
976 G4cout << "Click and move mouse to rotate volume \n" << G4endl;
977 G4cout << "Press left/right arrows to move volume left/right\n" << G4endl;
978 G4cout << "Press up/down arrows to move volume up/down\n" << G4endl;
979 G4cout << "Press ALT+up/down arrows to move volume toward/forward\n" << G4endl;
980 G4cout << "Press SHIFT+left/right arrows to rotate volume left/right\n" << G4endl;
981 G4cout << "Press SHIFT+up/down arrows to rotate volume up/down\n" << G4endl;
982 G4cout << "Press ALT+/- to slow/speed auto rotation/move\n" << G4endl;
983 } else if (fMouseAction == STYLE2) { //move
984 G4cout << "Move camera point of view with mouse\n" << G4endl;
985 G4cout << "Press left/right arrows to move volume left/right\n" << G4endl;
986 G4cout << "Press up/down arrows to move volume up/down\n" << G4endl;
987 G4cout << "Press ALT+up/down arrows to move volume toward/forward\n" << G4endl;
988 G4cout << "Press SHIFT+left/right arrows to rotate volume left/right\n" << G4endl;
989 G4cout << "Press SHIFT+up/down arrows to rotate volume up/down\n" << G4endl;
990 G4cout << "Press +/- to zoom into volume\n" << G4endl;
991 G4cout << "Press ALT+/- to slow/speed auto rotation/move\n" << G4endl;
992 } else if (fMouseAction == STYLE3) { //pick
993 G4cout << "Click and pick \n" << G4endl;
994 }
995
996}
997
998
999
1000/**
1001 Slot activated when drawing menu is toggle
1002 Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
1003 KernelVisitDecision () will be call and will set the fNeedKernelVisit
1004 to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
1005 It will cause a redraw of the view
1006 @param aAction : 1 wireframe, 2 line removal, 3 surface removal, 4 line & surface removal
1007 @see G4OpenGLStoredQtViewer::DrawView
1008 @see G4XXXStoredViewer::CompareForKernelVisit
1009 */
1010void G4OpenGLQtViewer::toggleDrawingAction(int aAction) {
1011
1012 G4ViewParameters::DrawingStyle d_style;
1013
1014
1015 // initialize
1016 if ((aAction >0) && (aAction <5)) {
1017#if QT_VERSION < 0x040000
1018 fDrawingWireframe->setOn(false);
1019 fDrawingLineRemoval->setOn(false);
1020 fDrawingSurfaceRemoval->setOn(false);
1021 fDrawingLineSurfaceRemoval->setOn(false);
1022#else
1023 fDrawingWireframe->setChecked (false);
1024 fDrawingLineRemoval->setChecked (false);
1025 fDrawingSurfaceRemoval->setChecked (false);
1026 fDrawingLineSurfaceRemoval->setChecked (false);
1027#endif
1028 }
1029 if (aAction ==1) {
1030#if QT_VERSION < 0x040000
1031 fDrawingWireframe->setOn(true);
1032#else
1033 fDrawingWireframe->setChecked (true);
1034#endif
1035
1036 d_style = G4ViewParameters::wireframe;
1037
1038 } else if (aAction ==2) {
1039#if QT_VERSION < 0x040000
1040 fDrawingLineRemoval->setOn(true);
1041#else
1042 fDrawingLineRemoval->setChecked (true);
1043#endif
1044
1045 d_style = G4ViewParameters::hlr;
1046
1047 } else if (aAction ==3) {
1048#if QT_VERSION < 0x040000
1049 fDrawingSurfaceRemoval->setOn(true);
1050#else
1051 fDrawingSurfaceRemoval->setChecked (true);
1052#endif
1053
1054 d_style = G4ViewParameters::hsr;
1055
1056 } else if (aAction ==4) {
1057#if QT_VERSION < 0x040000
1058 fDrawingLineSurfaceRemoval->setOn(true);
1059#else
1060 fDrawingLineSurfaceRemoval->setChecked (true);
1061#endif
1062 d_style = G4ViewParameters::hlhsr;
1063 }
1064 fVP.SetDrawingStyle(d_style);
1065
1066 updateQWidget();
1067}
1068
1069
1070/**
1071 SLOT Activate by a click on the representation menu
1072 Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
1073 KernelVisitDecision () will be call and will set the fNeedKernelVisit
1074 to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
1075 It will cause a redraw of the view
1076 @param check : 1 polyhedron, 0 nurbs
1077 @see G4OpenGLStoredQtViewer::DrawView
1078 @see G4XXXStoredViewer::CompareForKernelVisit
1079*/
1080void G4OpenGLQtViewer::toggleRepresentation(bool check) {
1081
1082 G4ViewParameters::RepStyle style;
1083 if (check == 1) {
1084 style = G4ViewParameters::polyhedron;
1085 } else {
1086 style = G4ViewParameters::nurbs;
1087 }
1088 fVP.SetRepStyle (style);
1089
1090 updateQWidget();
1091}
1092
1093/**
1094 SLOT Activate by a click on the projection menu
1095 Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
1096 KernelVisitDecision () will be call and will set the fNeedKernelVisit
1097 to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
1098 It will cause a redraw of the view
1099 @param check : 1 orthographic, 2 perspective
1100 @see G4OpenGLStoredQtViewer::DrawView
1101 @see G4XXXStoredViewer::CompareForKernelVisit
1102*/
1103void G4OpenGLQtViewer::toggleProjection(bool check) {
1104
1105 if (check == 1) {
1106 fVP.SetFieldHalfAngle (0);
1107 } else {
1108
1109 // look for the default parameter hidden in G4UIcommand parameters
1110 G4UImanager* UI = G4UImanager::GetUIpointer();
1111 if(UI==NULL)
1112 return;
1113 G4UIcommandTree * treeTop = UI->GetTree();
1114
1115 // find command
1116 G4UIcommand* command = treeTop->FindPath("/vis/viewer/set/projection");
1117 if (!command)
1118 return;
1119
1120 // find param
1121 G4UIparameter * angleParam = NULL;
1122 for(G4int i=0; i<command->GetParameterEntries(); i++)
1123 {
1124 if( command->GetParameter(i)->GetParameterName() == "field-half-angle" ) {
1125 angleParam = command->GetParameter(i);
1126 }
1127 }
1128 if (!angleParam)
1129 return;
1130
1131 // find unit
1132 G4UIparameter * unitParam = NULL;
1133 for(G4int i=0; i<command->GetParameterEntries(); i++)
1134 {
1135 if( command->GetParameter(i)->GetParameterName() == "unit" ) {
1136 unitParam = command->GetParameter(i);
1137 }
1138 }
1139 if (!unitParam)
1140 return;
1141
1142 G4double defaultValue = command->ConvertToDouble(angleParam->GetDefaultValue())
1143 * G4UnitDefinition::GetValueOf(unitParam->GetDefaultValue());
1144 if (defaultValue > 89.5 || defaultValue <= 0.0) {
1145 G4cerr << "Field half angle should be 0 < angle <= 89.5 degrees. Check your default Field half angle parameter\n";
1146 } else {
1147 G4cout << "Perspective view has been set to default value. Field half angle="<<angleParam->GetDefaultValue() <<" \n" << G4endl;
1148 fVP.SetFieldHalfAngle (defaultValue);
1149 SetView ();
1150 }
1151 }
1152 updateQWidget();
1153}
1154
1155
1156/**
1157 SLOT Activate by a click on the background menu
1158@param check : 1 white, 0 black
1159*/
1160void G4OpenGLQtViewer::toggleBackground(bool check) {
1161
1162 // //I need to revisit the kernel if the background colour changes and
1163 // //hidden line removal is enabled, because hlr drawing utilises the
1164 // //background colour in its drawing...
1165 // // (Note added by JA 13/9/2005) Background now handled in view
1166 // // parameters. A kernel visit is triggered on change of background.
1167 if (check == 1) {
1168 ((G4ViewParameters&)this->GetViewParameters()).
1169 SetBackgroundColour(G4Colour(1.,1.,1.)); // White
1170 } else {
1171 ((G4ViewParameters&)this->GetViewParameters()).
1172 SetBackgroundColour(G4Colour(0.,0.,0.)); // Black
1173 }
1174 updateQWidget();
1175}
1176
1177/**
1178 SLOT Activate by a click on the transparency menu
1179@param check : 1 , 0
1180*/
1181void G4OpenGLQtViewer::toggleTransparency(bool check) {
1182
1183 if (check) {
1184 transparency_enabled = false;
1185 } else {
1186 transparency_enabled = true;
1187 }
1188 SetNeedKernelVisit (true);
1189 updateQWidget();
1190}
1191
1192/**
1193 SLOT Activate by a click on the antialiasing menu
1194@param check : 1 , 0
1195*/
1196void G4OpenGLQtViewer::toggleAntialiasing(bool check) {
1197
1198 if (!check) {
1199 antialiasing_enabled = false;
1200 glDisable (GL_LINE_SMOOTH);
1201 glDisable (GL_POLYGON_SMOOTH);
1202 } else {
1203 antialiasing_enabled = true;
1204 glEnable (GL_LINE_SMOOTH);
1205 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
1206 glEnable (GL_POLYGON_SMOOTH);
1207 glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
1208 }
1209
1210 updateQWidget();
1211}
1212
1213/**
1214 SLOT Activate by a click on the haloing menu
1215@param check : 1 , 0
1216*/
1217//FIXME : I SEE NOTHING...
1218void G4OpenGLQtViewer::toggleHaloing(bool check) {
1219 if (check) {
1220 haloing_enabled = false;
1221 } else {
1222 haloing_enabled = true;
1223 }
1224
1225 updateQWidget();
1226
1227}
1228
1229/**
1230 SLOT Activate by a click on the auxiliaire edges menu
1231@param check : 1 , 0
1232*/
1233void G4OpenGLQtViewer::toggleAux(bool check) {
1234 if (check) {
1235 fVP.SetAuxEdgeVisible(false);
1236 } else {
1237 fVP.SetAuxEdgeVisible(true);
1238 }
1239 SetNeedKernelVisit (true);
1240 updateQWidget();
1241
1242}
1243
1244/**
1245 SLOT Activate by a click on the full screen menu
1246*/
1247void G4OpenGLQtViewer::toggleFullScreen(bool check) {
1248#ifdef GEANT4_QT_DEBUG
1249 printf("G4OpenGLQtViewer::toggleFullScreen checked:%d() \n",check);
1250#endif
1251 if (check != GLWindow->isFullScreen()) { //toggle
1252#if QT_VERSION >= 0x030200
1253#if QT_VERSION < 0x040000
1254 GLWindow->setWindowState(GLWindow->windowState() ^ Qt::WindowFullScreen);
1255// fFullScreenOn->setOn(check);
1256// fFullScreenOff->setOn(!check);
1257#else
1258 GLWindow->setWindowState(GLWindow->windowState() ^ Qt::WindowFullScreen);
1259// fFullScreenOn->setChecked(check);
1260// fFullScreenOff->setChecked(!check);
1261#endif
1262#else
1263 G4cerr << "This version of Qt could not do fullScreen. Resizing the widget is the only solution available.\n" << G4endl;
1264#endif
1265 }
1266}
1267
1268void G4OpenGLQtViewer::actionCreateEPS() {
1269 QString filters;
1270#if QT_VERSION < 0x040000
1271 QStrList listFormat=QImageIO::outputFormats();
1272 char *tmp=listFormat.first();
1273 while (tmp!=0) {
1274 filters += QString(tmp) + ";;";
1275 tmp=listFormat.next();
1276 }
1277#else
1278 QList<QByteArray> formats = QImageWriter::supportedImageFormats ();
1279 for (int i = 0; i < formats.size(); ++i) {
1280 filters +=formats.at(i) + ";;";
1281 }
1282#endif
1283 filters += "eps;;";
1284 filters += "ps;;";
1285 filters += "pdf";
1286 QString* selectedFormat = new QString();
1287#if QT_VERSION < 0x040000
1288 QString nomFich = QFileDialog::getSaveFileName ( ".",
1289 filters,
1290 GLWindow,
1291 "Save file dialog",
1292 tr("Save as ..."),
1293 selectedFormat );
1294#else
1295 QString nomFich = QFileDialog::getSaveFileName ( GLWindow,
1296 tr("Save as ..."),
1297 ".",
1298 filters,
1299 selectedFormat );
1300#endif
1301 // bmp jpg jpeg png ppm xbm xpm
1302 if (nomFich == "") {
1303 return;
1304 }
1305#if QT_VERSION < 0x040000
1306 nomFich += "."+QString(selectedFormat->ascii());
1307 QString format = selectedFormat->lower();
1308#else
1309 nomFich += "."+QString(selectedFormat->toStdString().c_str());
1310 QString format = selectedFormat->toLower();
1311#endif
1312 G4OpenGLQtExportDialog* exportDialog= new G4OpenGLQtExportDialog(GLWindow,format,fWindow->height(),fWindow->width());
1313 if( exportDialog->exec()) {
1314
1315 QImage image;
1316 bool res = false;
1317 if ((exportDialog->getWidth() !=fWindow->width()) ||
1318 (exportDialog->getHeight() !=fWindow->height())) {
1319 if (format != QString("eps")) {
1320 G4cerr << "Export->Change Size : This function is not implemented, to export in another size, please resize your frame to what you need\n" << G4endl;
1321
1322 // rescaleImage(exportDialog->getWidth(),exportDialog->getHeight());// re-scale image
1323 // QGLWidget* glResized = fWindow;
1324
1325 // FIXME :
1326 // L.Garnier : I've try to implement change size function, but the problem is
1327 // the renderPixmap function call the QGLWidget to resize and it doesn't draw
1328 // the content of this widget... It only draw the background.
1329
1330 // fWindow->renderPixmap (exportDialog->getWidth()*2,exportDialog->getHeight()*2,true );
1331
1332 // QPixmap pixmap = fWindow->renderPixmap ();
1333
1334 // image = pixmap->toImage();
1335 // glResized->resize(exportDialog->getWidth()*2,exportDialog->getHeight()*2);
1336 // image = glResized->grabFrameBuffer();
1337 }
1338 } else {
1339 image = fWindow->grabFrameBuffer();
1340 }
1341 if (format == QString("eps")) {
1342 if (exportDialog->getVectorEPS()) {
1343 res = generateVectorEPS(nomFich,exportDialog->getWidth(),exportDialog->getHeight(),image);
1344 } else {
1345 res = generateEPS(nomFich,exportDialog->getNbColor(),image);
1346 }
1347 } else if ((format == "ps") || (format == "pdf")) {
1348 res = generatePS_PDF(nomFich,exportDialog->getNbColor(),image);
1349 } else if ((format == "tif") ||
1350 (format == "tiff") ||
1351 (format == "jpg") ||
1352 (format == "jpeg") ||
1353 (format == "png") ||
1354 (format == "pbm") ||
1355 (format == "pgm") ||
1356 (format == "ppm") ||
1357 (format == "bmp") ||
1358 (format == "xbm") ||
1359 (format == "xpm")) {
1360#if QT_VERSION < 0x040000
1361 res = image.save(nomFich,selectedFormat->ascii(),exportDialog->getSliderValue());
1362#else
1363 res = image.save(nomFich,0,exportDialog->getSliderValue());
1364#endif
1365 } else {
1366 G4cerr << "This version of G4UI Could not generate the selected format\n" << G4endl;
1367 }
1368 if (res == false) {
1369#if QT_VERSION < 0x040000
1370 G4cerr << "Error while saving file... "<<nomFich.ascii()<<"\n" << G4endl;
1371#else
1372 G4cerr << "Error while saving file... "<<nomFich.toStdString().c_str()<<"\n" << G4endl;
1373#endif
1374 } else {
1375#if QT_VERSION < 0x040000
1376 G4cout << "File "<<nomFich.ascii()<<" has been saved \n" << G4endl;
1377#else
1378 G4cout << "File "<<nomFich.toStdString().c_str()<<" has been saved \n" << G4endl;
1379#endif
1380 }
1381
1382 } else { // cancel selected
1383 return;
1384 }
1385
1386#ifdef GEANT4_QT_DEBUG
1387 printf("G4OpenGLQtViewer::actionCreateEPS() \n");
1388#endif
1389}
1390
1391/*
1392// http://www.google.com/codesearch?hl=en&q=+jpg+Qt+quality+QDialog+show:FZkUoth8oiw:TONpW2mR-_c:tyTfrKMO-xI&sa=N&cd=2&ct=rc&cs_p=http://soft.proindependent.com/src/qtiplot-0.8.9.zip&cs_f=qtiplot-0.8.9/qtiplot/src/application.cpp#a0
1393
1394void Graph::exportToSVG(const QString& fname)
1395{
1396 // enable workaround for Qt3 misalignments
1397 QwtPainter::setSVGMode(true);
1398 QPicture picture;
1399 QPainter p(&picture);
1400 d_plot->print(&p, d_plot->rect());
1401 p.end();
1402
1403 picture.save(fname, "svg");
1404}
1405*/
1406
1407
1408
1409
1410/**
1411 Save the current mouse press point
1412 @param p mouse click point
1413*/
1414#if QT_VERSION < 0x040000
1415void G4OpenGLQtViewer::G4MousePressEvent(QPoint p,Qt::ButtonState mButtons)
1416#else
1417void G4OpenGLQtViewer::G4MousePressEvent(QPoint p,Qt::MouseButtons mButtons)
1418#endif
1419{
1420 fAutoMove = false; // stop automove
1421 fLastPos = p;
1422 if (fMouseAction == STYLE2){ // pick
1423 Pick(p.x(),p.y());
1424 }
1425}
1426
1427
1428/**
1429 @param pos_x mouse x position
1430 @param pos_y mouse y position
1431 @param mButtons mouse button active
1432 @param mAutoMove true: apply this move till another evnt came, false :one time move
1433*/
1434
1435#if QT_VERSION < 0x040000
1436void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::ButtonState mButtons,bool mAutoMove)
1437#else
1438 void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons,bool mAutoMove)
1439#endif
1440{
1441 fAutoMove = mAutoMove;
1442#ifdef GEANT4_QT_DEBUG
1443 printf(" mouse move event %d %d\n",pos_x,pos_y);
1444#endif
1445
1446 if (!fAutoMove) { // keep old delta if automove
1447 fDeltaPosX = fLastPos.x() - pos_x;
1448 fDeltaPosY = fLastPos.y() - pos_y;
1449 }
1450
1451 if ((fDeltaPosX == 0) && (fDeltaPosY == 0)) {
1452 fAutoMove = false;
1453 }
1454
1455 if (fMouseAction == STYLE1) { // rotate
1456 if (mButtons & Qt::LeftButton) {
1457 if (fAutoMove) {
1458 while (fAutoMove) {
1459 rotateScene(fDeltaPosX,fDeltaPosY);
1460#ifdef GEANT4_QT_DEBUG
1461 printf(" Processiongevent %d %d\n",fDeltaPosX,fDeltaPosY);
1462#endif
1463 ((QApplication*)G4Qt::getInstance ())->processEvents();
1464 }
1465 } else {
1466 rotateScene(fDeltaPosX,fDeltaPosY);
1467 }
1468 }
1469 } else if (fMouseAction == STYLE2) { // move
1470 if (mButtons & Qt::LeftButton) {
1471 if (fAutoMove) {
1472 while (fAutoMove) {
1473 moveScene(-fDeltaPosX,-fDeltaPosY,0,true);
1474 }
1475 } else {
1476 moveScene(-fDeltaPosX,-fDeltaPosY,0,true);
1477 }
1478 }
1479 }
1480 fLastPos = QPoint(pos_x, pos_y);
1481#ifdef GEANT4_QT_DEBUG
1482 if (mButtons & Qt::LeftButton) {
1483 printf(" end of mouse move event %d %d delta:%d %d\n",pos_x,pos_y,fDeltaPosX,fDeltaPosY);
1484 } else {
1485 printf(" end of mouse move event %d %d delta:%d %d --------------NO BUTTON\n",pos_x,pos_y,fDeltaPosX,fDeltaPosY);
1486 }
1487#endif
1488}
1489
1490
1491/**
1492 Move the scene of dx, dy, dz values.
1493 @param dx delta mouse x position
1494 @param dy delta mouse y position
1495 @param mouseMove : true if even comes froma mouse move, false if even comes from key action
1496*/
1497
1498void G4OpenGLQtViewer::moveScene(G4double dx,G4double dy, G4double dz,bool mouseMove)
1499{
1500 G4double coefTrans = 0;
1501 GLdouble coefDepth = 0;
1502 if(mouseMove) {
1503 coefTrans = ((G4double)getSceneNearWidth())/((G4double)WinSize_x);
1504 if (WinSize_y <WinSize_x) {
1505 coefTrans = ((G4double)getSceneNearWidth())/((G4double)WinSize_y);
1506 }
1507 } else {
1508 coefTrans = getSceneNearWidth()*fDeltaSceneTranslation;
1509 coefDepth = getSceneDepth()*fDeltaDepth;
1510 }
1511 fVP.IncrementPan(-dx*coefTrans,dy*coefTrans,dz*coefDepth);
1512
1513 updateQWidget();
1514}
1515
1516
1517/**
1518 @param dx delta mouse x position
1519 @param dy delta mouse y position
1520*/
1521
1522void G4OpenGLQtViewer::rotateScene(G4double dx, G4double dy)
1523{
1524 dx = dx * fDeltaRotation;
1525 dy = dy * fDeltaRotation;
1526
1527 //phi spin stuff here
1528
1529 G4Vector3D vp = fVP.GetViewpointDirection ().unit ();
1530 G4Vector3D up = fVP.GetUpVector ().unit ();
1531
1532 G4Vector3D yprime = (up.cross(vp)).unit();
1533 G4Vector3D zprime = (vp.cross(yprime)).unit();
1534
1535 G4double delta_alpha;
1536 G4double delta_theta;
1537
1538 if (fVP.GetLightsMoveWithCamera()) {
1539 delta_alpha = dy;
1540 delta_theta = -dx;
1541 } else {
1542 delta_alpha = -dy;
1543 delta_theta = dx;
1544 }
1545
1546 delta_alpha *= deg;
1547 delta_theta *= deg;
1548
1549 G4Vector3D new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime;
1550
1551 G4Vector3D new_up;
1552 if (fVP.GetLightsMoveWithCamera()) {
1553 new_up = (new_vp.cross(yprime)).unit();
1554 fVP.SetUpVector(new_up);
1555 } else {
1556 new_up = up;
1557 }
1558 ////////////////
1559 // Rotates by fixed azimuthal angle delta_theta.
1560
1561 G4double cosalpha = new_up.dot (new_vp.unit());
1562 G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));
1563 yprime = (new_up.cross (new_vp.unit())).unit ();
1564 G4Vector3D xprime = yprime.cross (new_up);
1565 // Projection of vp on plane perpendicular to up...
1566 G4Vector3D a1 = sinalpha * xprime;
1567 // Required new projection...
1568 G4Vector3D a2 =
1569 sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);
1570 // Required Increment vector...
1571 G4Vector3D delta = a2 - a1;
1572 // So new viewpoint is...
1573 G4Vector3D viewPoint = new_vp.unit() + delta;
1574
1575 fVP.SetViewAndLights (viewPoint);
1576 updateQWidget();
1577
1578}
1579
1580/** This is the benning of a rescale function. It does nothing for the moment
1581 @param aWidth : new width
1582 @param aHeight : new height
1583*/
1584void G4OpenGLQtViewer::rescaleImage(
1585 int aWidth
1586,int aHeight
1587){
1588#ifdef GEANT4_QT_DEBUG
1589 printf("should rescale \n");
1590#endif
1591 GLfloat* feedback_buffer;
1592 GLint returned;
1593 FILE* file;
1594
1595// feedback_buffer = new GLfloat[size];
1596// glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer);
1597// glRenderMode (GL_FEEDBACK);
1598
1599// glViewport (0, 0, aWidth, aHeight);
1600// DrawView();
1601// returned = glRenderMode (GL_RENDER);
1602
1603}
1604
1605/**
1606 Generate Vectorial Encapsulated Postscript form image
1607 @param aFilename : name of file
1608 @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha
1609 @param aImage : Image to print
1610*/
1611bool G4OpenGLQtViewer::generateVectorEPS (
1612 QString aFilename
1613,int aWidth
1614,int aHeight
1615,QImage aImage
1616)
1617{
1618 // Print vectored PostScript
1619
1620 G4int size = 5000000;
1621
1622 GLfloat* feedback_buffer;
1623 GLint returned;
1624 FILE* file;
1625
1626 feedback_buffer = new GLfloat[size];
1627 glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer);
1628 glRenderMode (GL_FEEDBACK);
1629
1630 int side = aWidth;
1631 if (aHeight < aWidth) side = aHeight;
1632 glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side);
1633 DrawView();
1634
1635 returned = glRenderMode (GL_RENDER);
1636
1637
1638#if QT_VERSION < 0x040000
1639 file = fopen (aFilename.ascii(), "w");
1640#else
1641 file = fopen (aFilename.toStdString().c_str(), "w");
1642#endif
1643 if (file) {
1644 spewWireframeEPS (file, returned, feedback_buffer, "rendereps");
1645 } else {
1646#if QT_VERSION < 0x040000
1647 G4cerr << "Could not open "<< aFilename.ascii()<<"\n" << G4endl;
1648#else
1649 G4cerr << "Could not open "<< aFilename.toStdString().c_str()<<"\n" << G4endl;
1650#endif
1651 }
1652
1653 delete[] feedback_buffer;
1654
1655 return true;
1656}
1657
1658/**
1659 Generate Encapsulated Postscript form image
1660 @param aFilename : name of file
1661 @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha
1662 @param aImage : Image to print
1663*/
1664bool G4OpenGLQtViewer::generateEPS (
1665 QString aFilename
1666,int aInColor
1667,QImage aImage
1668)
1669{
1670 // FIXME
1671#ifdef GEANT4_QT_DEBUG
1672 printf("saving EPS\n");
1673#endif
1674
1675 FILE* fp;
1676
1677 if (aImage.bits () == NULL)
1678 return false;
1679
1680#if QT_VERSION < 0x040000
1681 fp = fopen (aFilename.ascii(), "w");
1682#else
1683 fp = fopen (aFilename.toStdString().c_str(), "w");
1684#endif
1685 if (fp == NULL) {
1686 return false;
1687 }
1688
1689 fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n");
1690#if QT_VERSION < 0x040000
1691 fprintf (fp, "%%%%Title: %s\n", aFilename.ascii());
1692#else
1693 fprintf (fp, "%%%%Title: %s\n", aFilename.toStdString().c_str());
1694#endif
1695 fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n");
1696 fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", aImage.width(), aImage.height());
1697 fprintf (fp, "%%%%EndComments\n");
1698 fprintf (fp, "gsave\n");
1699 fprintf (fp, "/bwproc {\n");
1700 fprintf (fp, " rgbproc\n");
1701 fprintf (fp, " dup length 3 idiv string 0 3 0 \n");
1702 fprintf (fp, " 5 -1 roll {\n");
1703 fprintf (fp, " add 2 1 roll 1 sub dup 0 eq\n");
1704 fprintf (fp, " { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n");
1705 fprintf (fp, " 3 1 roll 5 -1 roll } put 1 add 3 0 \n");
1706 fprintf (fp, " { 2 1 roll } ifelse\n");
1707 fprintf (fp, " }forall\n");
1708 fprintf (fp, " pop pop pop\n");
1709 fprintf (fp, "} def\n");
1710 fprintf (fp, "systemdict /colorimage known not {\n");
1711 fprintf (fp, " /colorimage {\n");
1712 fprintf (fp, " pop\n");
1713 fprintf (fp, " pop\n");
1714 fprintf (fp, " /rgbproc exch def\n");
1715 fprintf (fp, " { bwproc } image\n");
1716 fprintf (fp, " } def\n");
1717 fprintf (fp, "} if\n");
1718 fprintf (fp, "/picstr %d string def\n", aImage.width() * aInColor);
1719 fprintf (fp, "%d %d scale\n", aImage.width(), aImage.height());
1720 fprintf (fp, "%d %d %d\n", aImage.width(), aImage.height(), 8);
1721 fprintf (fp, "[%d 0 0 %d 0 0]\n", aImage.width(), aImage.height());
1722 fprintf (fp, "{currentfile picstr readhexstring pop}\n");
1723 fprintf (fp, "false %d\n", aInColor);
1724 fprintf (fp, "colorimage\n");
1725
1726
1727 int width = aImage.width();
1728 int height = aImage.height();
1729 int depth = aImage.depth();
1730 int size = width*height;
1731
1732 if (depth == 1)
1733 size = (width+7)/8*height;
1734 else if (aInColor == 1)
1735 size = size*3;
1736
1737 int i = 0;
1738 // if ( aInColor ==1 ) {
1739 // FIXME : L. Garnier. For the moment 10 dec 2007, I could not find a way
1740 // to save correctly grayscale Image. I mean that color or grayscale image
1741 // have the same file save size !
1742
1743 /* } else*/ if (depth == 8) {
1744 for(int y=height-1; y >=0 ; y--) {
1745 const uchar * s = aImage.scanLine(y);
1746 for(int x=0; x <width; x++) {
1747 QRgb rgb = aImage.color(s[x]);
1748 if (aInColor == 1) {
1749 fprintf (fp, " %02hx ",(unsigned char)qGray(rgb));
1750 i++;
1751 } else {
1752 fprintf (fp, " %02hx %02hx %02hx",
1753 (unsigned char) qRed(rgb),
1754 (unsigned char) qGreen(rgb),
1755 (unsigned char) qBlue(rgb));
1756 i += 3;
1757 }
1758 }
1759 fprintf (fp, "\n");
1760 }
1761 } else {
1762#if QT_VERSION < 0x040000
1763 bool alpha = aImage.hasAlphaBuffer();
1764#else
1765 bool alpha = aImage.hasAlphaChannel();
1766 for(int y=height-1; y >=0 ; y--) {
1767 QRgb * s = (QRgb*)(aImage.scanLine(y));
1768 for(int x=0; x <width; x++) {
1769 QRgb rgb = (*s++);
1770 if (alpha && qAlpha(rgb) < 0x40) // 25% alpha, convert to white -
1771 rgb = qRgb(0xff, 0xff, 0xff);
1772 if (aInColor == 1) {
1773 fprintf (fp, " %02hx ",(unsigned char)qGray(rgb));
1774 i++;
1775 } else {
1776 fprintf (fp, " %02hx %02hx %02hx",
1777 (unsigned char) qRed(rgb),
1778 (unsigned char) qGreen(rgb),
1779 (unsigned char) qBlue(rgb));
1780 i += 3;
1781 }
1782 }
1783 fprintf (fp, "\n");
1784 }
1785#endif
1786
1787 }
1788
1789 fprintf (fp, "grestore\n");
1790 fprintf (fp, "showpage\n");
1791 fclose (fp);
1792
1793 return true;
1794}
1795/**
1796 Generate Postscript or PDF form image
1797 @param aFilename : name of file
1798 @param aInColor : numbers of colors : 1->BW 2->RGB
1799 @param aImage : Image to print
1800*/
1801bool G4OpenGLQtViewer::generatePS_PDF (
1802 QString aFilename
1803,int aInColor
1804,QImage aImage
1805)
1806{
1807
1808#if QT_VERSION < 0x040000
1809#ifdef Q_WS_MAC || Q_WS_X11
1810 QPrinter printer;
1811 // printer.setPageSize(pageSize);
1812 if (aInColor == 1) {
1813 printer.setColorMode(QPrinter::GrayScale);
1814 } else {
1815 printer.setColorMode(QPrinter::Color);
1816 }
1817
1818 /* FIXME : I don't know which format it will save...
1819 if (aFilename.endsWith(".ps")) {
1820 printer.setOutputFormat(QPrinter::PostScriptFormat);
1821 } else {
1822 printer.setOutputFormat(QPrinter::PdfFormat);
1823 }
1824 */
1825 printer.setOutputFileName(aFilename);
1826 // printer.setFullPage ( true);
1827 QPainter paint(&printer);
1828 paint.drawImage (0,0,aImage );
1829 paint.end();
1830#else
1831 G4cerr << "This fonction is only supported on Mac OsX or X11 with Qt3. Full platform supported with Qt4\n" << G4endl;
1832#endif
1833#else
1834 QPrinter printer;
1835 // printer.setPageSize(pageSize);
1836
1837 // FIXME : L. Garnier 4/12/07
1838 // This is not working, it does nothing. Image is staying in color mode
1839 // So I have desactivate the B/W button in GUI
1840 if ((!aImage.isGrayscale ()) &&(aInColor ==1 )) {
1841#if QT_VERSION < 0x040000
1842 aImage = aImage.convertDepth(1,Qt::MonoOnly);
1843#else
1844 aImage = aImage.convertToFormat ( aImage.format(), Qt::MonoOnly);
1845#endif
1846 }
1847
1848
1849 if (aFilename.endsWith(".ps")) {
1850#if QT_VERSION > 0x040200
1851 printer.setOutputFormat(QPrinter::PostScriptFormat);
1852#endif
1853 } else {
1854#if QT_VERSION > 0x040100
1855 printer.setOutputFormat(QPrinter::PdfFormat);
1856#endif
1857 }
1858#if QT_VERSION > 0x040100
1859 printer.setOutputFileName(aFilename);
1860#endif
1861 // printer.setFullPage ( true);
1862 QPainter paint(&printer);
1863 paint.drawImage (0,0,aImage);
1864 paint.end();
1865#endif
1866 return true;
1867}
1868
1869
1870
1871void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * event)
1872{
1873 if (fHoldKeyEvent)
1874 return;
1875
1876 fHoldKeyEvent = true;
1877
1878#if QT_VERSION < 0x040000
1879 if ((event->key() == Qt::Key_Down) && (event->state() & Qt::AltButton )) { // go backward
1880#else
1881 if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::AltModifier )) { // go backward
1882#endif
1883
1884 moveScene(0,0,1,false);
1885 }
1886#if QT_VERSION < 0x040000
1887 else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::AltButton)) { // go forward
1888#else
1889 else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::AltModifier)) { // go forward
1890#endif
1891 moveScene(0,0,-1,false);
1892 }
1893#if QT_VERSION < 0x040000
1894 if ((event->key() == Qt::Key_Down) && (event->state() & Qt::ShiftButton)) { // rotate phi
1895#else
1896 if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi
1897#endif
1898 rotateScene(0,-1);
1899 }
1900#if QT_VERSION < 0x040000
1901 else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::ShiftButton)) { // rotate phi
1902#else
1903 else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi
1904#endif
1905 rotateScene(0,1);
1906 }
1907#if QT_VERSION < 0x040000
1908 if ((event->key() == Qt::Key_Left) && (event->state() & Qt::ShiftButton)) { // rotate theta
1909#else
1910 if ((event->key() == Qt::Key_Left) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta
1911#endif
1912 rotateScene(1,0);
1913 }
1914#if QT_VERSION < 0x040000
1915 else if ((event->key() == Qt::Key_Right) && (event->state() & Qt::ShiftButton)) { // rotate theta
1916#else
1917 else if ((event->key() == Qt::Key_Right) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta
1918#endif
1919 rotateScene(-1,0);
1920 }
1921
1922#if QT_VERSION < 0x040000
1923 if ((event->key() == Qt::Key_Plus) && (event->state() & Qt::AltButton)) { // rotate theta
1924#else
1925 if ((event->key() == Qt::Key_Plus) && (event->modifiers() & Qt::AltModifier)) { // rotate theta
1926#endif
1927 fDeltaPosX =fDeltaPosX*(1+fDeltaMove);
1928 fDeltaPosY =fDeltaPosY*(1+fDeltaMove);
1929 }
1930#if QT_VERSION < 0x040000
1931 else if ((event->key() == Qt::Key_Minus) && (event->state() & Qt::AltButton)) { // rotate theta
1932#else
1933 else if ((event->key() == Qt::Key_Minus) && (event->modifiers() & Qt::AltModifier)) { // rotate theta
1934#endif
1935 fDeltaPosX =fDeltaPosX*(1-fDeltaMove);
1936 fDeltaPosY =fDeltaPosY*(1-fDeltaMove);
1937 }
1938
1939
1940 if (event->key() == Qt::Key_Escape) { // escaped from full screen
1941#if QT_VERSION >= 0x030200
1942 if (GLWindow->isFullScreen()) {
1943#if QT_VERSION < 0x040000
1944 fFullScreenOn->activated();
1945#else
1946 fFullScreenOn->trigger();
1947#endif
1948 }
1949#endif
1950 }
1951 if (event->key() == Qt::Key_Plus) { // zoom in
1952 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+fDeltaZoom));
1953 updateQWidget();
1954 }
1955 else if (event->key() == Qt::Key_Minus) { // zoom out
1956 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1-fDeltaZoom));
1957 updateQWidget();
1958 }
1959 // with no modifiers
1960#if QT_VERSION < 0x040000
1961 if (event->state() == Qt::NoButton) {
1962#else
1963 if (event->modifiers() == Qt::NoModifier) {
1964#endif
1965 if (event->key() == Qt::Key_Down) { // go down
1966 moveScene(0,-1,0,false);
1967 }
1968 else if (event->key() == Qt::Key_Up) { // go up
1969 moveScene(0,1,0,false);
1970 }
1971 if (event->key() == Qt::Key_Left) { // go left
1972 moveScene(-1,0,0,false);
1973 }
1974 else if (event->key() == Qt::Key_Right) { // go right
1975 moveScene(1,0,0,false);
1976 }
1977 }
1978 fHoldKeyEvent = false;
1979}
1980
1981
1982bool G4OpenGLQtViewer::hasPendingEvents () {
1983 return ((QApplication*)G4Qt::getInstance ())->hasPendingEvents ();
1984}
1985
1986
1987/*
1988
1989void MultiLayer::exportToSVG(const QString& fname)
1990{
1991 QPicture picture;
1992 QPainter p(&picture);
1993 for (int i=0;i<(int)graphsList->count();i++)
1994 {
1995 Graph *gr=(Graph *)graphsList->at(i);
1996 Plot *myPlot= (Plot *)gr->plotWidget();
1997
1998 QPoint pos=gr->pos();
1999
2000 int width=int(myPlot->frameGeometry().width());
2001 int height=int(myPlot->frameGeometry().height());
2002
2003 myPlot->print(&p, QRect(pos,QSize(width,height)));
2004 }
2005
2006 p.end();
2007 picture.save(fname, "svg");
2008}
2009*/
2010#endif
Note: See TracBrowser for help on using the repository browser.