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

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

Correction du ticket #121

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