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

Last change on this file since 711 was 711, checked in by garnier, 16 years ago

debut de recherche du decalage de deplacement

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