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

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

modif dans le movie widget

  • Property svn:mime-type set to text/cpp
File size: 80.9 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"
[730]50#include "G4OpenGLQtMovieDialog.hh"
[703]51#include "G4UnitsTable.hh"
[539]52#include "G4Qt.hh"
[569]53#include "G4UImanager.hh"
[702]54#include "G4UIcommandTree.hh"
[595]55#include <qapplication.h>
[599]56#include <qlayout.h>
[595]57#include <qdialog.h>
[723]58#include <qprocess.h>
[599]59
60#if QT_VERSION >= 0x040000
[595]61#include <qmenu.h>
62#include <qimagewriter.h>
[599]63#else
64#include <qaction.h>
65#include <qwidgetlist.h>
66#include <qpopupmenu.h>
67#include <qimage.h>
68#endif
69
[720]70#include <qapplication.h>
[595]71#include <qmessagebox.h>
72#include <qfiledialog.h>
73#include <qprinter.h>
[739]74#include <qdatetime.h>
[595]75#include <qpainter.h>
76#include <qgl.h> // include <qglwidget.h>
77#include <qdialog.h>
78#include <qevent.h> //include <qcontextmenuevent.h>
[530]79
[593]80
[530]81//////////////////////////////////////////////////////////////////////////////
82/**
[564]83   Implementation of virtual method of G4VViewer
84*/
[530]85void G4OpenGLQtViewer::SetView (
86)
87//////////////////////////////////////////////////////////////////////////////
88//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
89{
[608]90#ifdef GEANT4_QT_DEBUG
[542]91  printf("G4OpenGLQtViewer::SetView ++++++++++++++++++++\n");
[608]92#endif
[564]93  //   if(!fHDC) return;
94  //   if(!fHGLRC) return;
95  //   ::wglMakeCurrent(fHDC,fHGLRC);
96  //  fWindow->makeCurrent();
[579]97  G4OpenGLViewer::SetView ();
[608]98#ifdef GEANT4_QT_DEBUG
[542]99  printf("G4OpenGLQtViewer::SetView --------------------\n");
[608]100#endif
[530]101}
102
[673]103/**
104 * Set the viewport of the scene
105 */
106void G4OpenGLQtViewer::setupViewport(int aWidth, int aHeight)
107{
[709]108  int side = aWidth;
109  if (aHeight < aWidth) side = aHeight;
[673]110  glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side);
111 
112  glMatrixMode(GL_PROJECTION);
113  glLoadIdentity();
114  glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
115  glMatrixMode(GL_MODELVIEW);
116}
[530]117
118
119//////////////////////////////////////////////////////////////////////////////
120/**
[564]121   Implementation of virtual method of G4VViewer
122*/
[530]123void G4OpenGLQtViewer::ShowView (
124)
125//////////////////////////////////////////////////////////////////////////////
126//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
127{
[608]128#ifdef GEANT4_QT_DEBUG
[542]129  printf("G4OpenGLQtViewer::ShowView  +++++++++++++++++++++\n");
[608]130#endif
[579]131  if (!GLWindow) {
[638]132    G4cerr << "Visualization window not defined, please choose one before\n" << G4endl;
[579]133  } else {
[599]134#if QT_VERSION < 0x040000
135    GLWindow->setActiveWindow();
136#else
[579]137    GLWindow->activateWindow();
[599]138#endif
[608]139#ifdef GEANT4_QT_DEBUG
[579]140    printf("G4OpenGLQtViewer::ShowView -----------------------\n");
[608]141#endif
[579]142  }
[678]143  glFlush ();
[564]144  //   // Empty the Windows message queue :
145  //   MSG event;
146  //   while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
147  //     ::TranslateMessage(&event);
148  //     ::DispatchMessage (&event);
149  //   }
[530]150}
151
152
153
154//////////////////////////////////////////////////////////////////////////////
155void G4OpenGLQtViewer::CreateGLQtContext (
156)
157//////////////////////////////////////////////////////////////////////////////
158//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
159{
[608]160#ifdef GEANT4_QT_DEBUG
[530]161  printf("G4OpenGLQtViewer::CreateGLQtContext \n");
[608]162#endif
[530]163}
164
[564]165
[530]166//////////////////////////////////////////////////////////////////////////////
167void G4OpenGLQtViewer::CreateMainWindow (
[585]168 QGLWidget* glWidget
169)
[530]170//////////////////////////////////////////////////////////////////////////////
171//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
172{
173
[538]174  if(fWindow) return; //Done.
[608]175#ifdef GEANT4_QT_DEBUG
[564]176  printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n");
[608]177#endif
[538]178
[539]179  // launch Qt if not
180  G4Qt* interactorManager = G4Qt::getInstance ();
181  //  G4UImanager* UI = G4UImanager::GetUIpointer();
182
[564]183  fWindow = glWidget ;
[543]184  //  fWindow->makeCurrent();
[538]185
[539]186  // create window
[569]187  if (((QApplication*)interactorManager->GetMainInteractor())) {
188    // look for the main window
189    bool found = false;
[599]190#if QT_VERSION < 0x040000
[631]191    // theses lines does nothing exept this one "GLWindow = new QDialog(0..."
[626]192    // but if I comment them, it doesn't work...
193    QWidgetList  *list = QApplication::allWidgets();
194    QWidgetListIt it( *list );         // iterate over the widgets
195    QWidget * widget;
196    while ( (widget=it.current()) != 0 ) {  // for each widget...
197      ++it;
198      if ((found== false) && (widget->inherits("QMainWindow"))) {
199        GLWindow = new QDialog(0,0,FALSE,Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_MinMax );
200        found = true;
201      }
202    }
203    delete list;                      // delete the list, not the widgets
[599]204#else
[626]205    foreach (QWidget *widget, QApplication::allWidgets()) {
206      if ((found== false) && (widget->inherits("QMainWindow"))) {
[650]207        GLWindow = new QDialog(0,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
[626]208        found = true;
209      }
210    }
[608]211#endif
[612]212
213#if QT_VERSION < 0x040000
[610]214    glWidget->reparent(GLWindow,0,QPoint(0,0)); 
[612]215#else
216    glWidget->setParent(GLWindow); 
217#endif
[599]218
[569]219    if (found==false) {
[608]220#ifdef GEANT4_QT_DEBUG
[579]221      printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n");
[608]222#endif
[569]223      GLWindow = new QDialog();
224    }
[539]225  } else {
[608]226#ifdef GEANT4_QT_DEBUG
[579]227    printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
[608]228#endif
[539]229    GLWindow = new QDialog();
230  }
231
[599]232  QHBoxLayout *mainLayout = new QHBoxLayout(GLWindow);
[564]233
[539]234  mainLayout->addWidget(fWindow);
[599]235
236#if QT_VERSION < 0x040000
237  GLWindow->setCaption( tr( "QGl Viewer" ));
238#else
[539]239  GLWindow->setLayout(mainLayout);
[599]240  GLWindow->setWindowTitle(tr("QGl Viewer"));
241#endif
[564]242  GLWindow->resize(300, 300);
[570]243  GLWindow->move(900,300);
[539]244  GLWindow->show();
[530]245 
[579]246  // delete the pointer if close this
247  //  GLWindow->setAttribute(Qt::WA_DeleteOnClose);
248
[610]249#if QT_VERSION >= 0x040000
[711]250//   QObject ::connect(GLWindow,
251//                     SIGNAL(rejected()),
252//                     this,
253//                     SLOT(dialogClosed()));
[610]254#endif
[579]255
[564]256  WinSize_x = 400;
257  WinSize_y = 400;
258  if (WinSize_x < fVP.GetWindowSizeHintX ())
259    WinSize_x = fVP.GetWindowSizeHintX ();
260  if (WinSize_y < fVP.GetWindowSizeHintY ())
261    WinSize_y = fVP.GetWindowSizeHintY ();
[530]262
[564]263  if(!fWindow) return;
[608]264#ifdef GEANT4_QT_DEBUG
[564]265  printf("G4OpenGLQtViewer::CreateMainWindow glWidget END\n");
[608]266#endif
[530]267
[564]268  if (!fContextMenu)
269    createPopupMenu();
[530]270
[564]271}
[530]272
[610]273#if QT_VERSION >= 0x040000
[579]274/**  Close the dialog and set the pointer to NULL
275 */
[711]276// void G4OpenGLQtViewer::dialogClosed() {
277// #ifdef GEANT4_QT_DEBUG
278//   printf("G4OpenGLQtViewer::dialogClosed END\n");
279// #endif
280//   //  GLWindow = NULL;
281// }
[610]282#endif
[579]283
[564]284//////////////////////////////////////////////////////////////////////////////
285G4OpenGLQtViewer::G4OpenGLQtViewer (
286                                    G4OpenGLSceneHandler& scene
287                                    )
288  :G4VViewer (scene, -1)
289  ,G4OpenGLViewer (scene)
290  ,fWindow(0)
[723]291  ,fRecordFrameNumber(0)
[564]292  ,fContextMenu(0)
[696]293  ,fMouseAction(STYLE1)
[728]294  ,fDeltaRotation(1)
[712]295  ,fDeltaSceneTranslation(0.01)
296  ,fDeltaDepth(0.01)
297  ,fDeltaZoom(0.1)
[724]298  ,fDeltaMove(0.05)
[721]299  ,fHoldKeyEvent(false)
[728]300  ,fHoldMoveEvent(false)
301  ,fHoldRotateEvent(false)
[720]302  ,fAutoMove(false)
[739]303  ,fEncoderPath("")
304  ,fTempFolderPath("")
305  ,fMovieTempFolderPath("")
306  ,fSaveFileName("")
[740]307  ,fParameterFileName("mpeg_encode_parameter_file.par")
[732]308  ,fMovieParametersDialog(NULL)
[744]309  ,fRecordingStep(WAIT)
310
[564]311{
[739]312
[735]313  initMovieParameters();
[738]314
[608]315#ifdef GEANT4_QT_DEBUG
[564]316  printf("G4OpenGLQtViewer::G4OpenGLQtViewer \n");
[608]317#endif
[530]318}
319
320//////////////////////////////////////////////////////////////////////////////
[564]321G4OpenGLQtViewer::~G4OpenGLQtViewer (
[539]322)
323//////////////////////////////////////////////////////////////////////////////
324//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
325{
[740]326  G4cout <<removeTempFolder().toStdString().c_str();
[608]327#ifdef GEANT4_QT_DEBUG
[564]328  printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n");
[608]329#endif
[564]330}
[539]331
332
[564]333/**
334   Create a popup menu for the widget. This menu is activated by right-mouse click
335*/
336void G4OpenGLQtViewer::createPopupMenu()    {
[539]337
[599]338#if QT_VERSION < 0x040000
339  fContextMenu = new QPopupMenu( GLWindow,"All" );
340#else
[564]341  fContextMenu = new QMenu("All");
[599]342#endif
[539]343
[599]344#if QT_VERSION < 0x040000
345  QPopupMenu *mMouseAction = new QPopupMenu( fContextMenu );
[717]346  fContextMenu->insertItem("&Mouse actions",mMouseAction);
347#if QT_VERSION < 0x030200
348  fRotateAction =  new QAction("&Rotate","&Rotate",CTRL+Key_R,mMouseAction,0,true);
349  fMoveAction =  new QAction("&Move","&Move",CTRL+Key_M,mMouseAction,0,true);
350  fPickAction =  new QAction("&Pick","&Pick",CTRL+Key_P,mMouseAction,0,true);
[721]351  QAction * shortcutsAction =  new QAction("&Show shortcuts","&Show shortcuts",CTRL+Key_S,mMouseAction,0,true);
[617]352#else
[718]353  fRotateAction =  new QAction("&Rotate",CTRL+Key_R,mMouseAction);
354  fMoveAction =  new QAction("&Move",CTRL+Key_M,mMouseAction);
355  fPickAction =  new QAction("&Pick",CTRL+Key_P,mMouseAction);
[721]356  QAction *shortcutsAction =  new QAction("&Show shortcuts",CTRL+Key_S,mMouseAction);
[617]357#endif
[717]358  fRotateAction->addTo(mMouseAction);
359  fMoveAction->addTo(mMouseAction);
360  fPickAction->addTo(mMouseAction);
[721]361  shortcutsAction->addTo(mMouseAction);
[599]362
[717]363  fRotateAction->setToggleAction(true);
364  fMoveAction->setToggleAction(true);
365  fPickAction->setToggleAction(true);
[721]366  shortcutsAction->setToggleAction(true);
[599]367
[717]368  fRotateAction->setOn(true);
369  fMoveAction->setOn(false);
370  fPickAction->setOn(false);
[721]371  shortcutsAction->setOn(false);
[713]372
[678]373
[717]374  QObject ::connect(fRotateAction,
375                    SIGNAL(activated()),
376                    this,
[678]377                    SLOT(actionMouseRotate()));
378
[717]379  QObject ::connect(fMoveAction,
380                    SIGNAL(activated()),
381                    this,
[713]382                    SLOT(actionMouseMove()));
383
[717]384  QObject ::connect(fPickAction,
385                    SIGNAL(activated()),
386                    this,
[707]387                    SLOT(actionMousePick()));
[678]388
[721]389  QObject ::connect(shortcutsAction,
[717]390                    SIGNAL(activated()),
391                    this,
[721]392                    SLOT(showShortcuts()));
[678]393
394#else
[717]395  QMenu *mMouseAction = fContextMenu->addMenu("&Mouse actions");
[678]396
[717]397  fRotateAction = mMouseAction->addAction("Rotate");
398  fMoveAction = mMouseAction->addAction("Move");
399  fPickAction = mMouseAction->addAction("Pick");
[721]400  QAction *shortcutsAction = mMouseAction->addAction("Show shortcuts");
[717]401
402  fRotateAction->setCheckable(true);
403  fMoveAction->setCheckable(false);
404  fPickAction->setCheckable(false);
[721]405  shortcutsAction->setCheckable(false);
[717]406
407  fRotateAction->setChecked(true);
408  fMoveAction->setChecked(false);
409  fPickAction->setChecked(false);
[721]410  shortcutsAction->setChecked(false);
[717]411
412  QObject ::connect(fRotateAction,
[678]413                    SIGNAL(triggered(bool)),
414                    this,
415                    SLOT(actionMouseRotate()));
416
[717]417  QObject ::connect(fMoveAction,
[713]418                    SIGNAL(triggered(bool)),
419                    this,
420                    SLOT(actionMouseMove()));
421
[717]422  QObject ::connect(fPickAction,
[678]423                    SIGNAL(triggered(bool)),
424                    this,
[707]425                    SLOT(actionMousePick()));
[678]426
[721]427  QObject ::connect(shortcutsAction,
[678]428                    SIGNAL(triggered(bool)),
429                    this,
[721]430                    SLOT(showShortcuts()));
[678]431#endif
432
[599]433#if QT_VERSION < 0x040000
434  // === Style Menu ===
435  QPopupMenu *mStyle = new QPopupMenu(fContextMenu);
436
437  QPopupMenu *mRepresentation = new QPopupMenu(fContextMenu);
438
[703]439  QPopupMenu *mProjection = new QPopupMenu(fContextMenu);
[702]440
[617]441#if QT_VERSION < 0x030200
[715]442  QAction *polyhedron = new QAction("&Polyhedron","&Polyhedron",CTRL+Key_P,mRepresentation,0,true);
443  QAction *nurbs = new QAction("&NURBS","&NURBS",CTRL+Key_N,mRepresentation,0,true);
[702]444
[715]445  QAction *ortho = new QAction("&Orthographic","&Orthographic",CTRL+Key_O,mProjection,0,true);
446  QAction *perspective = new QAction("&Perspective","&Perspective",CTRL+Key_P,mProjection,0,true);
[617]447#else
[599]448  QAction *polyhedron = new QAction("&Polyhedron",CTRL+Key_P,mRepresentation);
449  QAction *nurbs = new QAction("&NURBS",CTRL+Key_N,mRepresentation);
[702]450
451  QAction *ortho = new QAction("&Orthographic",CTRL+Key_O,mProjection);
452  QAction *perspective = new QAction("&Perspective",CTRL+Key_P,mProjection);
[715]453  polyhedron->setToggleAction(true);
454  nurbs->setToggleAction(true);
455  ortho->setToggleAction(true);
456  perspective->setToggleAction(true);
[617]457#endif
[599]458  polyhedron->addTo(mRepresentation);
459  nurbs->addTo(mRepresentation);
460
[702]461  ortho->addTo(mProjection);
462  perspective->addTo(mProjection);
463
[599]464  mStyle->insertItem("&Representation",mRepresentation);
[702]465  mStyle->insertItem("&Projection",mProjection);
[599]466  fContextMenu->insertItem("&Style",mStyle);
467
[702]468
[599]469#else
470  // === Style Menu ===
[564]471  QMenu *mStyle = fContextMenu->addMenu("&Style");
472
473  QMenu *mRepresentation = mStyle->addMenu("&Representation");
[703]474  QMenu *mProjection = mStyle->addMenu("&Projection");
[632]475  QAction *polyhedron = mRepresentation->addAction("Polyhedron");
[564]476  QAction *nurbs = mRepresentation->addAction("NURBS");
[702]477
[703]478  QAction *ortho = mProjection->addAction("Orthographic");
479  QAction *perspective = mProjection->addAction("Persepective");
[599]480#endif
[702]481
482  // INIT mRepresentation
[564]483  G4ViewParameters::RepStyle style;
484  style = fVP.GetRepStyle();
485  if (style == G4ViewParameters::polyhedron) {
486    createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),1);
487  } else if (style == G4ViewParameters::nurbs) {
488    createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),2);
[539]489  } else {
[564]490    mRepresentation->clear();
[539]491  }
492
[702]493  // INIT mProjection
494  if (fVP.GetFieldHalfAngle() == 0) {
495    createRadioAction(ortho, perspective,SLOT(toggleProjection(bool)),1);
496  } else {
497    createRadioAction(ortho, perspective,SLOT(toggleProjection(bool)),2);
498  }
[539]499
[599]500#if QT_VERSION < 0x040000
501  // === Drawing Menu ===
502  QPopupMenu *mDrawing = new QPopupMenu(fContextMenu);
503  fContextMenu->insertItem("&Drawing",mDrawing);
504
[718]505#if QT_VERSION < 0x030200
506  fDrawingWireframe = new QAction("&Wireframe","&Wireframe",CTRL+Key_W,mDrawing,0,true);
507  fDrawingLineRemoval = new QAction("&Hidden line removal","&Hidden line removal",CTRL+Key_L,mDrawing,0,true);
508  fDrawingSurfaceRemoval = new QAction("&Hidden surface removal","&Hidden surface removal",CTRL+Key_S,mDrawing,0,true);
509  fDrawingLineSurfaceRemoval = new QAction("&Hidden line and surface removal","&Hidden line and surface removal",CTRL+Key_R,mDrawing,0,true);
510#else
511  fDrawingWireframe = new QAction("&Wireframe",CTRL+Key_W,mDrawing);
512  fDrawingLineRemoval = new QAction("&Hidden line removal",CTRL+Key_L,mDrawing);
513  fDrawingSurfaceRemoval = new QAction("&Hidden surface removal",CTRL+Key_S,mDrawing);
514  fDrawingLineSurfaceRemoval = new QAction("&Hidden line and surface removal",CTRL+Key_R,mDrawing);
515#endif
516  fDrawingWireframe->setToggleAction(true);
517  fDrawingLineRemoval->setToggleAction(true);
518  fDrawingSurfaceRemoval->setToggleAction(true);
519  fDrawingLineSurfaceRemoval->setToggleAction(true);
[599]520
[718]521  fDrawingWireframe->addTo(mDrawing);
522  fDrawingLineRemoval->addTo(mDrawing);
523  fDrawingSurfaceRemoval->addTo(mDrawing);
524  fDrawingLineSurfaceRemoval->addTo(mDrawing);
[599]525
526
527#else
528  // === Drawing Menu ===
[564]529  QMenu *mDrawing = mStyle->addMenu("&Drawing");
[599]530
[564]531  fDrawingWireframe = mDrawing->addAction("Wireframe");
532  fDrawingWireframe->setCheckable(true);
[599]533
[564]534  fDrawingLineRemoval = mDrawing->addAction("Hidden line removal");
535  fDrawingLineRemoval->setCheckable(true);
[599]536
[564]537  fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal");
538  fDrawingSurfaceRemoval->setCheckable(true);
[599]539
[564]540  fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal");
541  fDrawingLineSurfaceRemoval->setCheckable(true);
[599]542#endif
[564]543  // INIT Drawing
544  G4ViewParameters::DrawingStyle d_style;
545  d_style = fVP.GetDrawingStyle();
546 
[599]547#if QT_VERSION < 0x040000
[564]548  if (d_style == G4ViewParameters::wireframe) {
[718]549    fDrawingWireframe->setOn(true);
[599]550  } else if (d_style == G4ViewParameters::hlr) {
[718]551    fDrawingLineRemoval->setOn(true);
[599]552  } else if (d_style == G4ViewParameters::hsr) {
[718]553    fDrawingSurfaceRemoval->setOn(true);
[599]554  } else if (d_style == G4ViewParameters::hlhsr) {
[718]555    fDrawingLineSurfaceRemoval->setOn(true);
[599]556  } else {
557    mDrawing->clear();
558  }
[610]559#ifdef GEANT4_QT_DEBUG
560  printf("G4OpenGLQtViewer:: fDrawingWireframe 1\n");
561#endif
562  QObject ::connect(fDrawingWireframe,
[717]563                    SIGNAL(activated()),
[610]564                    this,
565                    SLOT(actionDrawingWireframe()));
566#ifdef GEANT4_QT_DEBUG
567  printf("G4OpenGLQtViewer:: fDrawingWireframe 2\n");
568#endif
569  QObject ::connect(fDrawingLineRemoval,
[717]570                    SIGNAL(activated()),
[610]571                    this,
572                    SLOT(actionDrawingLineRemoval()));
573  QObject ::connect(fDrawingSurfaceRemoval,
[717]574                    SIGNAL(activated()),
[610]575                    this,
576                    SLOT(actionDrawingSurfaceRemoval()));
577  QObject ::connect(fDrawingLineSurfaceRemoval,
[717]578                    SIGNAL(activated()),
[610]579                    this,
580                    SLOT(actionDrawingLineSurfaceRemoval()));
[599]581#else
582  if (d_style == G4ViewParameters::wireframe) {
[564]583    fDrawingWireframe->setChecked(true);
584  } else if (d_style == G4ViewParameters::hlr) {
585    fDrawingLineRemoval->setChecked(true);
586  } else if (d_style == G4ViewParameters::hsr) {
587    fDrawingSurfaceRemoval->setChecked(true);
588  } else if (d_style == G4ViewParameters::hlhsr) {
589    fDrawingLineSurfaceRemoval->setChecked(true);
590  } else {
591    mDrawing->clear();
592  }
[565]593  QObject ::connect(fDrawingWireframe,
594                    SIGNAL(triggered(bool)),
595                    this,
596                    SLOT(actionDrawingWireframe()));
597  QObject ::connect(fDrawingLineRemoval,
598                    SIGNAL(triggered(bool)),
599                    this,
600                    SLOT(actionDrawingLineRemoval()));
601  QObject ::connect(fDrawingSurfaceRemoval,
602                    SIGNAL(triggered(bool)),
603                    this,
604                    SLOT(actionDrawingSurfaceRemoval()));
605  QObject ::connect(fDrawingLineSurfaceRemoval,
606                    SIGNAL(triggered(bool)),
607                    this,
608                    SLOT(actionDrawingLineSurfaceRemoval()));
[610]609#endif
[564]610
611
[610]612
[599]613#if QT_VERSION < 0x040000
614  QPopupMenu *mBackground = new QPopupMenu(mStyle);
615  mStyle->insertItem("&Background color",mBackground);
616
[617]617#if QT_VERSION < 0x030200
[715]618  QAction *white = new QAction("&White","&White",CTRL+Key_W,mBackground,0,true);
619  QAction *black =  new QAction("&Black","&Black",CTRL+Key_B,mBackground,0,true);
[617]620#else
[599]621  QAction *white = new QAction("&White",CTRL+Key_W,mBackground);
622  QAction *black =  new QAction("&Black",CTRL+Key_B,mBackground);
[715]623  white->setToggleAction(true);
624  black->setToggleAction(true);
[617]625#endif
[599]626  white->addTo(mBackground);
627  black->addTo(mBackground);
628
629#else
[564]630  QMenu *mBackground = mStyle->addMenu("&Background color");
631  QAction *white = mBackground->addAction("White");
632  QAction *black = mBackground->addAction("Black");
[599]633
634#endif
[564]635  if (background.GetRed() == 1. &&
636      background.GetGreen() == 1. &&
637      background.GetBlue() == 1.) {
638    createRadioAction(white,black,SLOT(toggleBackground(bool)),1);
639  } else {
640    createRadioAction(white,black,SLOT(toggleBackground(bool)),2);
641  }
642
643
[599]644#if QT_VERSION < 0x040000
645  // === Action Menu ===
646  QPopupMenu *mActions = new QPopupMenu(fContextMenu);
647  fContextMenu->insertItem("&Actions",mActions);
648
[617]649#if QT_VERSION < 0x030200
[715]650  QAction *createEPS =  new QAction("&Save as ...","&Save as ...",CTRL+Key_S,mActions,0,true);
[617]651#else
[599]652  QAction *createEPS =  new QAction("&Save as ...",CTRL+Key_S,mActions);
[617]653#endif
[599]654  createEPS->addTo(mActions);
[610]655  QObject ::connect(createEPS,
656                    SIGNAL(activated()),
657                    this,
[731]658                    SLOT(actionSaveImage()));
[599]659
660#else
661  // === Action Menu ===
[564]662  QMenu *mActions = fContextMenu->addMenu("&Actions");
[568]663  QAction *createEPS = mActions->addAction("Save as ...");
[565]664  QObject ::connect(createEPS,
[566]665                    SIGNAL(triggered()),
[565]666                    this,
[731]667                    SLOT(actionSaveImage()));
[610]668#endif
[564]669
[730]670#if QT_VERSION < 0x040000
671#if QT_VERSION < 0x030200
[731]672  QAction *movieParameters =  new QAction("&Movie parameters...","&Make movie ...",CTRL+Key_M,mActions,0,true);
[730]673#else
[733]674  QAction *movieParameters =  new QAction("&Movie parameters...",CTRL+Key_M,mActions);
[730]675#endif
[731]676  movieParameters->addTo(mActions);
677  QObject ::connect(movieParameters,
[730]678                    SIGNAL(activated()),
679                    this,
[731]680                    SLOT(actionMovieParameters()));
[564]681
[730]682#else
683  // === Action Menu ===
[731]684  QAction *movieParameters = mActions->addAction("Movie parameters...");
685  QObject ::connect(movieParameters,
[730]686                    SIGNAL(triggered()),
687                    this,
[731]688                    SLOT(actionMovieParameters()));
[730]689#endif
[610]690
[730]691
692
693
[599]694#if QT_VERSION < 0x040000
695  // === Special Menu ===
696  QPopupMenu *mSpecial = new QPopupMenu(fContextMenu);
697  fContextMenu->insertItem("S&pecial",mSpecial);
698
699  QPopupMenu *mTransparency = new QPopupMenu(mSpecial);
700  mSpecial->insertItem("Transparency",mTransparency);
701
[617]702#if QT_VERSION < 0x030200
[715]703  QAction *transparencyOn = new QAction("&On","&On",CTRL+Key_O,mTransparency,0,true);
704  QAction *transparencyOff = new QAction("&Off","&Off",CTRL+Key_F,mTransparency,0,true);
[617]705#else
[599]706  QAction *transparencyOn = new QAction("&On",CTRL+Key_O,mTransparency);
707  QAction *transparencyOff = new QAction("&Off",CTRL+Key_F,mTransparency);
[715]708  transparencyOn->setToggleAction(true);
709  transparencyOff->setToggleAction(true);
[617]710#endif
[599]711  transparencyOn->addTo(mTransparency);
712  transparencyOff->addTo(mTransparency);
713
714#else
715  // === Special Menu ===
[564]716  QMenu *mSpecial = fContextMenu->addMenu("S&pecial");
[599]717  QMenu *mTransparency = mSpecial->addMenu("Transparency");
718  QAction *transparencyOn = mTransparency->addAction("On");
719  QAction *transparencyOff = mTransparency->addAction("Off");
720#endif
721
[564]722  if (transparency_enabled == false) {
723    createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2);
724  } else if (transparency_enabled == true) {
725    createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),1);
726  } else {
727    mSpecial->clear();
728  }
729
730
[599]731#if QT_VERSION < 0x040000
732  QPopupMenu *mAntialiasing = new QPopupMenu(mSpecial);
733  mSpecial->insertItem("Antialiasing",mAntialiasing);
734
[617]735#if QT_VERSION < 0x030200
[715]736  QAction *antialiasingOn = new QAction("&On","&On",CTRL+Key_O,mAntialiasing,0,true);
737  QAction *antialiasingOff = new QAction("&Off","&Off",CTRL+Key_F,mAntialiasing,0,true);
[617]738#else
[599]739  QAction *antialiasingOn = new QAction("&On",CTRL+Key_O,mAntialiasing);
740  QAction *antialiasingOff = new QAction("&Off",CTRL+Key_F,mAntialiasing);
[715]741  antialiasingOn->setToggleAction(true);
742  antialiasingOff->setToggleAction(true);
[617]743#endif
[599]744  antialiasingOn->addTo(mAntialiasing);
745  antialiasingOff->addTo(mAntialiasing);
746
747#else
[564]748  QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing");
749  QAction *antialiasingOn = mAntialiasing->addAction("On");
750  QAction *antialiasingOff = mAntialiasing->addAction("Off");
[599]751#endif
752
[564]753  if (antialiasing_enabled == false) {
754    createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2);
755  } else if (antialiasing_enabled == true) {
756    createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),1);
757  } else {
758    mAntialiasing->clear();
759  }
760
[599]761#if QT_VERSION < 0x040000
762  QPopupMenu *mHaloing = new QPopupMenu(mSpecial);
763  mSpecial->insertItem("Haloing",mHaloing);
764
[617]765#if QT_VERSION < 0x030200
[715]766  QAction *haloingOn = new QAction("&On","&On",CTRL+Key_O,mHaloing,0,true);
767  QAction *haloingOff = new QAction("&Off","&Off",CTRL+Key_F,mHaloing,0,true);
[617]768#else
[599]769  QAction *haloingOn = new QAction("&On",CTRL+Key_O,mHaloing);
770  QAction *haloingOff = new QAction("&Off",CTRL+Key_F,mHaloing);
[715]771  haloingOn->setToggleAction(true);
772  haloingOff->setToggleAction(true);
[617]773#endif
[599]774  haloingOn->addTo(mHaloing);
775  haloingOff->addTo(mHaloing);
776#else
[564]777  QMenu *mHaloing = mSpecial->addMenu("Haloing");
778  QAction *haloingOn = mHaloing->addAction("On");
779  QAction *haloingOff = mHaloing->addAction("Off");
[599]780#endif
[564]781  if (haloing_enabled == false) {
782    createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2);
783  } else if (haloing_enabled == true) {
784    createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),1);
785  } else {
786    mHaloing->clear();
787  }
788
[599]789#if QT_VERSION < 0x040000
790  QPopupMenu *mAux = new QPopupMenu(mSpecial);
791  mSpecial->insertItem("Auxiliairy edges",mAux);
792
[617]793#if QT_VERSION < 0x030200
[715]794  QAction *auxOn = new QAction("&On","&On",CTRL+Key_O,mAux,0,true);
795  QAction *auxOff = new QAction("&Off","&Off",CTRL+Key_F,mAux,0,true);
[617]796#else
[599]797  QAction *auxOn = new QAction("&On",CTRL+Key_O,mAux);
798  QAction *auxOff = new QAction("&Off",CTRL+Key_F,mAux);
[715]799  auxOn->setToggleAction(true);
800  auxOff->setToggleAction(true);
[617]801#endif
[599]802  auxOn->addTo(mAux);
803  auxOff->addTo(mAux);
804
805#else
[564]806  QMenu *mAux = mSpecial->addMenu("Auxiliary edges");
807  QAction *auxOn = mAux->addAction("On");
808  QAction *auxOff = mAux->addAction("Off");
[599]809#endif
[564]810  if (!fVP.IsAuxEdgeVisible()) {
811    createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1);
812  } else {
813    createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),2);
814  }
815
816
[715]817
[599]818#if QT_VERSION < 0x040000
819  QPopupMenu *mFullScreen = new QPopupMenu(mSpecial);
820  mSpecial->insertItem("Full screen",mFullScreen);
821
[715]822#if QT_VERSION < 0x030200
[717]823  fFullScreenOn = new QAction("&On","&On",CTRL+Key_O,mFullScreen,0,true);
824  fFullScreenOff = new QAction("&Off","&Off",CTRL+Key_F,mFullScreen,0,true);
[715]825#else
[717]826  fFullScreenOn = new QAction("&On",CTRL+Key_O,mFullScreen);
827  fFullScreenOff = new QAction("&Off",CTRL+Key_F,mFullScreen);
828  fFullScreenOn->setToggleAction(true);
829  fFullScreenOff->setToggleAction(true);
[715]830#endif
[717]831  fFullScreenOn->addTo(mFullScreen);
832  fFullScreenOff->addTo(mFullScreen);
[599]833#else
[715]834  QMenu *mFullScreen = mSpecial->addMenu("&Full screen");
[717]835  fFullScreenOn = mFullScreen->addAction("On");
836  fFullScreenOff = mFullScreen->addAction("Off");
[599]837#endif
[717]838  createRadioAction(fFullScreenOn,fFullScreenOff,SLOT(toggleFullScreen(bool)),2);
[564]839
840}
841
842void G4OpenGLQtViewer::manageContextMenuEvent(QContextMenuEvent *e)
843{
[579]844  if (!GLWindow) {
[748]845    G4cerr << "Visualization window not defined, please choose one before" << G4endl;
[579]846  } else {
[539]847 
[579]848    if (!fContextMenu)
849      createPopupMenu();
850   
851    // launch menu
852    if ( fContextMenu ) {
853      fContextMenu->exec( e->globalPos() );
854      //    delete fContextMenu;
855    }
[564]856  }
857  e->accept();
858}
[539]859
860
[564]861/**
862   Create a radio button menu. The two menu will be connected. When click on one,
863   eatch state will be invert and callback method will be called.
864   @param action1 first action to connect
865   @param action2 second action to connect
866   @param method callback method
867   @param nCheck: 1 : first action will be set true. 2 : second action will be set true
868*/
[599]869#if QT_VERSION < 0x040000
[564]870void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
871
[599]872  if (action1->parent()->inherits("QPopupMenu")){
873    ((QPopupMenu*)action1->parent())->setCheckable(true);
[715]874    ((QPopupMenu*)action2->parent())->setCheckable(true);
[599]875  }
[715]876  action1->setOn(false);
877   action2->setOn(false);
[599]878
879  if (nCheck ==1)
[715]880    action1->setOn(true);
[599]881  else
[715]882    action2->setOn(true);
[599]883   
[717]884  //FIXME : Should not work on Qt3
[610]885  QObject ::connect(action1, SIGNAL(activated()),action2, SLOT(toggle()));
886  QObject ::connect(action2, SIGNAL(activated()),action1, SLOT(toggle()));
[599]887
888  QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str());
889}
890
891#else
892void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
893
[564]894  action1->setCheckable(true);
895  action2->setCheckable(true);
896
897  if (nCheck ==1)
898    action1->setChecked (true);
899  else
900    action2->setChecked (true);
901   
902  QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle()));
903  QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle()));
904
905  QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str());
906
907}
[599]908#endif
[564]909
910/**
[678]911   Slot activate when mouseAction->rotate menu is set
912 */
913void G4OpenGLQtViewer::actionMouseRotate() {
[696]914  emit toggleMouseAction(STYLE1);
[678]915}
916
917
918/**
[713]919   Slot activate when mouseAction->rotate menu is set
920 */
921void G4OpenGLQtViewer::actionMouseMove() {
922  emit toggleMouseAction(STYLE2);
923}
924
925
926/**
[707]927   Slot activate when mouseAction->zoom menu is set
[678]928 */
[707]929void G4OpenGLQtViewer::actionMousePick() {
[678]930#ifdef GEANT4_QT_DEBUG
[707]931  printf("G4OpenGLQtViewer::actionMousePick \n");
[678]932#endif
[696]933  emit toggleMouseAction(STYLE3);
[678]934}
935
[681]936
937/**
[564]938   Slot activate when drawing->wireframe menu is set
939 */
940void G4OpenGLQtViewer::actionDrawingWireframe() {
941  emit toggleDrawingAction(1);
942}
943
944/**
945   Slot activate when drawing->line removal menu is set
946 */
947void G4OpenGLQtViewer::actionDrawingLineRemoval() {
948  emit toggleDrawingAction(2);
949}
950
951/**
952   Slot activate when drawing->surface removal menu is set
953 */
954void G4OpenGLQtViewer::actionDrawingSurfaceRemoval() {
955  emit toggleDrawingAction(3);
956}
957
958/**
959   Slot activate when drawing->wireframe menu is set
960 */
961void G4OpenGLQtViewer::actionDrawingLineSurfaceRemoval() {
962  emit toggleDrawingAction(4);
963}
964
965
966/**
[678]967   Slot activated when mouse action is toggle
[696]968   @param aAction : STYLE1, STYLE2, STYLE3
[678]969 */
970void G4OpenGLQtViewer::toggleMouseAction(mouseActions aAction) {
971 
[713]972  if ((aAction == STYLE1) || //initialize all
973      (aAction == STYLE2) ||
[721]974      (aAction == STYLE3))  {
[713]975#if QT_VERSION < 0x040000
[717]976    fRotateAction->setOn (false);
977    fMoveAction->setOn (false);
978    fPickAction->setOn (false);
[713]979#else
[717]980    fRotateAction->setChecked (false);
981    fMoveAction->setChecked (false);
982    fPickAction->setChecked (false);
[713]983#endif
984    fVP.SetPicking(false);
985    fMouseAction = aAction;
986  }
987  // rotate
[707]988  if (aAction == STYLE1) {  // rotate
[721]989    showShortcuts();
[678]990#if QT_VERSION < 0x040000
[717]991    fRotateAction->setOn (true);
[678]992#else
[717]993    fRotateAction->setChecked (true);
[678]994#endif
[713]995  } else  if (aAction == STYLE2) { //move
996#if QT_VERSION < 0x040000
[717]997    fMoveAction->setOn (true);
[713]998#else
[717]999    fMoveAction->setChecked (true);
[713]1000#endif
1001  } else  if (aAction == STYLE3) { //pick
[678]1002#if QT_VERSION < 0x040000
[717]1003    fPickAction->setOn (true);
[678]1004#else
[717]1005    fPickAction->setChecked (true);
[678]1006#endif
[707]1007    fVP.SetPicking(true);
[721]1008  }
1009}
[707]1010
[721]1011/**
1012   Show shortcuts for this mouse action
1013 */
1014void G4OpenGLQtViewer::showShortcuts() {
1015  if (fMouseAction == STYLE1) {  // rotate
[748]1016    G4cout << "Click and move mouse to rotate volume " << G4endl;
1017    G4cout << "Press left/right arrows to move volume left/right" << G4endl;
1018    G4cout << "Press up/down arrows to move volume up/down" << G4endl;
1019    G4cout << "Press ALT+up/down arrows to move volume toward/forward" << G4endl;
1020    G4cout << "Press SHIFT+left/right arrows to rotate volume left/right" << G4endl;
1021    G4cout << "Press SHIFT+up/down arrows to rotate volume up/down" << G4endl;
1022    G4cout << "Press ALT+/- to slow/speed auto rotation/move" << G4endl;
1023    G4cout << "In video mode : " << G4endl;
1024    G4cout << " Press SPACE to Start/Pause video recording " << G4endl;
1025    G4cout << " Press RETURN to Stop video recording " << G4endl;
[721]1026  } else  if (fMouseAction == STYLE2) { //move
[748]1027    G4cout << "Move camera point of view with mouse" << G4endl;
1028    G4cout << "Press left/right arrows to move volume left/right" << G4endl;
1029    G4cout << "Press up/down arrows to move volume up/down" << G4endl;
1030    G4cout << "Press ALT+up/down arrows to move volume toward/forward" << G4endl;
1031    G4cout << "Press SHIFT+left/right arrows to rotate volume left/right" << G4endl;
1032    G4cout << "Press SHIFT+up/down arrows to rotate volume up/down" << G4endl;
1033    G4cout << "Press +/- to zoom into volume" << G4endl;
1034    G4cout << "Press ALT+/- to slow/speed auto rotation/move" << G4endl;
1035    G4cout << "In video mode : " << G4endl;
1036    G4cout << " Press SPACE to Start/Pause video recording " << G4endl;
1037    G4cout << " Press RETURN to Stop video recording " << G4endl;
[721]1038  } else  if (fMouseAction == STYLE3) { //pick
[748]1039    G4cout << "Click and pick " << G4endl;
[678]1040  }
1041
1042}
[721]1043
1044
1045
[678]1046/**
[565]1047   Slot activated when drawing menu is toggle
1048   Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
1049   KernelVisitDecision () will be call and will set the fNeedKernelVisit
1050   to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
1051   It will cause a redraw of the view
1052   @param aAction : 1 wireframe, 2 line removal, 3 surface removal, 4 line & surface removal
1053   @see G4OpenGLStoredQtViewer::DrawView
1054   @see G4XXXStoredViewer::CompareForKernelVisit
[564]1055 */
1056void G4OpenGLQtViewer::toggleDrawingAction(int aAction) {
1057
1058  G4ViewParameters::DrawingStyle d_style;
[539]1059 
1060
[718]1061  // initialize
1062  if ((aAction >0) && (aAction <5)) {
[600]1063#if QT_VERSION < 0x040000
[718]1064    fDrawingWireframe->setOn(false);
1065    fDrawingLineRemoval->setOn(false);
1066    fDrawingSurfaceRemoval->setOn(false);
1067    fDrawingLineSurfaceRemoval->setOn(false);
[600]1068#else
[718]1069    fDrawingWireframe->setChecked (false);
[564]1070    fDrawingLineRemoval->setChecked (false);
1071    fDrawingSurfaceRemoval->setChecked (false);
1072    fDrawingLineSurfaceRemoval->setChecked (false);
[600]1073#endif
[718]1074  }
1075  if (aAction ==1) {
1076#if QT_VERSION < 0x040000
1077    fDrawingWireframe->setOn(true);
1078#else
1079    fDrawingWireframe->setChecked (true);
1080#endif
[564]1081
1082    d_style = G4ViewParameters::wireframe;
1083
1084  } else  if (aAction ==2) {
[600]1085#if QT_VERSION < 0x040000
[718]1086    fDrawingLineRemoval->setOn(true);
[600]1087#else
[564]1088    fDrawingLineRemoval->setChecked (true);
[600]1089#endif
[564]1090
1091    d_style = G4ViewParameters::hlr;
1092
1093  } else  if (aAction ==3) {
[600]1094#if QT_VERSION < 0x040000
[718]1095    fDrawingSurfaceRemoval->setOn(true);
[600]1096#else
[564]1097    fDrawingSurfaceRemoval->setChecked (true);
[600]1098#endif
[564]1099
1100    d_style = G4ViewParameters::hsr;
1101
1102  } else  if (aAction ==4) {
[600]1103#if QT_VERSION < 0x040000
[718]1104    fDrawingLineSurfaceRemoval->setOn(true);
[600]1105#else
[564]1106    fDrawingLineSurfaceRemoval->setChecked (true);
[600]1107#endif
[564]1108    d_style = G4ViewParameters::hlhsr;
1109  }
1110  fVP.SetDrawingStyle(d_style);
1111
1112  updateQWidget();
[539]1113}
1114
[564]1115
1116/**
1117   SLOT Activate by a click on the representation menu
[565]1118   Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
1119   KernelVisitDecision () will be call and will set the fNeedKernelVisit
1120   to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
1121   It will cause a redraw of the view
[564]1122   @param check : 1 polyhedron, 0 nurbs
[565]1123   @see G4OpenGLStoredQtViewer::DrawView
1124   @see G4XXXStoredViewer::CompareForKernelVisit
[564]1125*/
1126void G4OpenGLQtViewer::toggleRepresentation(bool check) {
1127
1128  G4ViewParameters::RepStyle style;
1129  if (check == 1) {
1130    style = G4ViewParameters::polyhedron;
1131  } else {
1132    style = G4ViewParameters::nurbs;
1133  }
1134  fVP.SetRepStyle (style);
1135
1136  updateQWidget();
[530]1137}
1138
[564]1139/**
[702]1140   SLOT Activate by a click on the projection menu
1141   Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
1142   KernelVisitDecision () will be call and will set the fNeedKernelVisit
1143   to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
1144   It will cause a redraw of the view
1145   @param check : 1 orthographic, 2 perspective
1146   @see G4OpenGLStoredQtViewer::DrawView
1147   @see G4XXXStoredViewer::CompareForKernelVisit
1148*/
1149void G4OpenGLQtViewer::toggleProjection(bool check) {
1150
1151  if (check == 1) {
1152    fVP.SetFieldHalfAngle (0);
1153  } else {
[703]1154
[702]1155    // look for the default parameter hidden in G4UIcommand parameters
1156    G4UImanager* UI = G4UImanager::GetUIpointer();
1157    if(UI==NULL)
1158      return;
1159    G4UIcommandTree * treeTop = UI->GetTree();
1160
1161    // find command
1162    G4UIcommand* command = treeTop->FindPath("/vis/viewer/set/projection");
1163    if (!command)
1164      return;
1165
1166    // find param
[703]1167    G4UIparameter * angleParam = NULL;
[702]1168    for(G4int i=0;  i<command->GetParameterEntries(); i++)
1169    {
1170      if( command->GetParameter(i)->GetParameterName() == "field-half-angle" ) {
[703]1171        angleParam = command->GetParameter(i);
[702]1172      }
1173    }
[703]1174    if (!angleParam)
[702]1175      return;
[703]1176
1177    // find unit
1178    G4UIparameter * unitParam = NULL;
1179    for(G4int i=0;  i<command->GetParameterEntries(); i++)
1180    {
1181      if( command->GetParameter(i)->GetParameterName() == "unit" ) {
1182        unitParam = command->GetParameter(i);
1183      }
1184    }
1185    if (!unitParam)
1186      return;
1187
1188    G4double defaultValue = command->ConvertToDouble(angleParam->GetDefaultValue())
1189                            * G4UnitDefinition::GetValueOf(unitParam->GetDefaultValue());
1190    if (defaultValue > 89.5 || defaultValue <= 0.0) {
[748]1191      G4cerr << "Field half angle should be 0 < angle <= 89.5 degrees. Check your default Field half angle parameter";
[703]1192    } else {
[748]1193      G4cout << "Perspective view has been set to default value. Field half angle="<<angleParam->GetDefaultValue() <<" " << G4endl;
[703]1194      fVP.SetFieldHalfAngle (defaultValue);
1195      SetView ();
1196    }
1197  } 
[702]1198  updateQWidget();
1199}
1200
1201
1202/**
[564]1203   SLOT Activate by a click on the background menu
1204@param check : 1 white, 0 black
1205*/
1206void G4OpenGLQtViewer::toggleBackground(bool check) {
1207
1208  //   //I need to revisit the kernel if the background colour changes and
1209  //   //hidden line removal is enabled, because hlr drawing utilises the
1210  //   //background colour in its drawing...
1211  //   // (Note added by JA 13/9/2005) Background now handled in view
1212  //   // parameters.  A kernel visit is triggered on change of background.
1213  if (check == 1) {
1214    ((G4ViewParameters&)this->GetViewParameters()).
1215      SetBackgroundColour(G4Colour(1.,1.,1.));  // White
1216  } else {
1217    ((G4ViewParameters&)this->GetViewParameters()).
1218      SetBackgroundColour(G4Colour(0.,0.,0.));  // Black
1219  }
1220  updateQWidget();
[530]1221}
1222
[564]1223/**
1224   SLOT Activate by a click on the transparency menu
1225@param check : 1 , 0
1226*/
1227void G4OpenGLQtViewer::toggleTransparency(bool check) {
1228 
1229  if (check) {
1230    transparency_enabled = false;
1231  } else {
1232    transparency_enabled = true;
1233  }
1234  SetNeedKernelVisit (true);
1235  updateQWidget();
1236}
[530]1237
[564]1238/**
1239   SLOT Activate by a click on the antialiasing menu
1240@param check : 1 , 0
1241*/
1242void G4OpenGLQtViewer::toggleAntialiasing(bool check) {
1243
1244  if (!check) {
1245    antialiasing_enabled = false;
1246    glDisable (GL_LINE_SMOOTH);
1247    glDisable (GL_POLYGON_SMOOTH);
1248  } else {
1249    antialiasing_enabled = true;
1250    glEnable (GL_LINE_SMOOTH);
1251    glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
1252    glEnable (GL_POLYGON_SMOOTH);
1253    glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
[530]1254  }
[564]1255
1256  updateQWidget();
1257}
1258
1259/**
1260   SLOT Activate by a click on the haloing menu
1261@param check : 1 , 0
[530]1262*/
[564]1263//FIXME : I SEE NOTHING...
1264void G4OpenGLQtViewer::toggleHaloing(bool check) {
1265  if (check) {
1266    haloing_enabled = false;
1267  } else {
1268    haloing_enabled = true;
1269  }
[530]1270
[564]1271  updateQWidget();
[530]1272
[564]1273}
1274
1275/**
1276   SLOT Activate by a click on the auxiliaire edges menu
1277@param check : 1 , 0
1278*/
1279void G4OpenGLQtViewer::toggleAux(bool check) {
1280  if (check) {
1281    fVP.SetAuxEdgeVisible(false);
1282  } else {
1283    fVP.SetAuxEdgeVisible(true);
1284  }
1285  SetNeedKernelVisit (true);
1286  updateQWidget();
1287
1288}
1289
1290/**
1291   SLOT Activate by a click on the full screen menu
1292*/
[717]1293void G4OpenGLQtViewer::toggleFullScreen(bool check) {
1294  if (check != GLWindow->isFullScreen()) { //toggle
[617]1295#if QT_VERSION >= 0x030200
[717]1296    GLWindow->setWindowState(GLWindow->windowState() ^ Qt::WindowFullScreen);
[617]1297#else
[748]1298    G4cerr << "This version of Qt could not do fullScreen. Resizing the widget is the only solution available." << G4endl;
[717]1299#endif
1300  }
[564]1301}
1302
[723]1303
[739]1304void G4OpenGLQtViewer::savePPMToTemp() {
1305  if (fMovieTempFolderPath == "") {
[723]1306    return;
1307  }
[744]1308  QString fileName ="Test"+QString::number(fRecordFrameNumber)+".ppm";
1309  QString filePath =fMovieTempFolderPath+fileName;
[724]1310
[723]1311  QImage image;
1312  image = fWindow->grabFrameBuffer();
1313  bool res = false;
1314 
1315#if QT_VERSION < 0x040000
[744]1316  res = image.save(filePath,"ppm");
[723]1317#else
[744]1318  res = image.save(filePath,0);
[723]1319#endif
[744]1320  if (res == false) {
1321    setRecordingStatus(WAIT);
1322    setRecordingInfos("Can't save tmp file "+filePath);
[739]1323    return;
[723]1324  }
[739]1325 
[744]1326  setRecordingInfos("File "+fileName+" saved");
[739]1327  fRecordFrameNumber++;
[723]1328}
1329
1330
1331
[731]1332void G4OpenGLQtViewer::actionSaveImage() {
[580]1333  QString filters;
[600]1334#if QT_VERSION < 0x040000
1335  QStrList listFormat=QImageIO::outputFormats();
1336  char *tmp=listFormat.first();
1337  while (tmp!=0) {
1338    filters += QString(tmp) + ";;";
1339    tmp=listFormat.next();
1340  }
1341#else
[580]1342  QList<QByteArray> formats =  QImageWriter::supportedImageFormats ();
1343  for (int i = 0; i < formats.size(); ++i) {
[600]1344    filters +=formats.at(i) + ";;";
[580]1345  }
[600]1346#endif
[588]1347  filters += "eps;;";
1348  filters += "ps;;";
1349  filters += "pdf";
[639]1350  QString* selectedFormat = new QString();
[600]1351#if QT_VERSION < 0x040000
1352  QString nomFich =  QFileDialog::getSaveFileName ( ".",
1353                                                    filters,
1354                                                    GLWindow,
1355                                                    "Save file dialog",
1356                                                    tr("Save as ..."),
[639]1357                                                    selectedFormat );
[600]1358#else
[580]1359  QString nomFich =  QFileDialog::getSaveFileName ( GLWindow,
1360                                                    tr("Save as ..."),
1361                                                    ".",
[582]1362                                                    filters,
[639]1363                                                    selectedFormat );
[600]1364#endif
[580]1365  // bmp jpg jpeg png ppm xbm xpm
[582]1366  if (nomFich == "") {
1367    return;
1368  }
[600]1369#if QT_VERSION < 0x040000
[639]1370  nomFich += "."+QString(selectedFormat->ascii());
1371  QString format = selectedFormat->lower();
[600]1372#else
[639]1373  nomFich += "."+QString(selectedFormat->toStdString().c_str());
1374  QString format = selectedFormat->toLower();
[600]1375#endif
[656]1376  G4OpenGLQtExportDialog* exportDialog= new G4OpenGLQtExportDialog(GLWindow,format,fWindow->height(),fWindow->width());
[585]1377  if(  exportDialog->exec()) {
[593]1378
1379    QImage image;
[655]1380    bool res = false;
[635]1381    if ((exportDialog->getWidth() !=fWindow->width()) ||
1382        (exportDialog->getHeight() !=fWindow->height())) {
[655]1383      if (format != QString("eps")) {
[748]1384      G4cerr << "Export->Change Size : This function is not implemented, to export in another size, please resize your frame to what you need" << G4endl;
[585]1385     
[635]1386      //    rescaleImage(exportDialog->getWidth(),exportDialog->getHeight());// re-scale image
1387      //      QGLWidget* glResized = fWindow;
1388
1389      // FIXME :
1390      // L.Garnier : I've try to implement change size function, but the problem is
1391      // the renderPixmap function call the QGLWidget to resize and it doesn't draw
1392      // the content of this widget... It only draw the background.
1393
1394      //      fWindow->renderPixmap (exportDialog->getWidth()*2,exportDialog->getHeight()*2,true );
1395
1396      //      QPixmap pixmap = fWindow->renderPixmap ();
1397     
1398      //      image = pixmap->toImage();
[593]1399      //      glResized->resize(exportDialog->getWidth()*2,exportDialog->getHeight()*2);
1400      //      image = glResized->grabFrameBuffer();
[655]1401      }     
[635]1402    } else {
1403      image = fWindow->grabFrameBuffer();
1404    }   
[639]1405    if (format == QString("eps")) {
[652]1406      if (exportDialog->getVectorEPS()) {
[655]1407        res = generateVectorEPS(nomFich,exportDialog->getWidth(),exportDialog->getHeight(),image);
[652]1408      } else {
[655]1409        res = generateEPS(nomFich,exportDialog->getNbColor(),image);
[652]1410      }
[639]1411    } else if ((format == "ps") || (format == "pdf")) {
[655]1412      res = generatePS_PDF(nomFich,exportDialog->getNbColor(),image);
1413    } else if ((format == "tif") ||
1414               (format == "tiff") ||
1415               (format == "jpg") ||
1416               (format == "jpeg") ||
1417               (format == "png") ||
1418               (format == "pbm") ||
1419               (format == "pgm") ||
1420               (format == "ppm") ||
1421               (format == "bmp") ||
1422               (format == "xbm") ||
1423               (format == "xpm")) {
[639]1424#if QT_VERSION < 0x040000
[655]1425      res = image.save(nomFich,selectedFormat->ascii(),exportDialog->getSliderValue());
[639]1426#else
[655]1427      res = image.save(nomFich,0,exportDialog->getSliderValue());
[639]1428#endif
[585]1429    } else {
[748]1430      G4cerr << "This version of G4UI Could not generate the selected format" << G4endl;
[585]1431    }
[655]1432    if (res == false) {
1433#if QT_VERSION < 0x040000
[748]1434      G4cerr << "Error while saving file... "<<nomFich.ascii()<<"" << G4endl;
[655]1435#else
[748]1436      G4cerr << "Error while saving file... "<<nomFich.toStdString().c_str()<< G4endl;
[655]1437#endif
1438    } else {
1439#if QT_VERSION < 0x040000
[748]1440      G4cout << "File "<<nomFich.ascii()<<" has been saved " << G4endl;
[655]1441#else
[748]1442      G4cout << "File "<<nomFich.toStdString().c_str()<<" has been saved " << G4endl;
[655]1443#endif
1444    }
[585]1445   
1446  } else { // cancel selected
1447    return;
[568]1448  }
[580]1449 
[608]1450#ifdef GEANT4_QT_DEBUG
[731]1451  printf("G4OpenGLQtViewer::actionSaveImage() \n");
[608]1452#endif
[565]1453}
1454
[730]1455
[731]1456void G4OpenGLQtViewer::actionMovieParameters() {
[730]1457
[731]1458  showMovieParametersDialog();
[730]1459#ifdef GEANT4_QT_DEBUG
[731]1460  printf("G4OpenGLQtViewer::actionMovieParameters() \n");
[730]1461#endif
1462}
1463
[731]1464
1465void G4OpenGLQtViewer::showMovieParametersDialog() {
[732]1466  if (!fMovieParametersDialog) {
1467    fMovieParametersDialog= new G4OpenGLQtMovieDialog(this,GLWindow);
[731]1468  }
[732]1469  fMovieParametersDialog->show();
[731]1470}
1471
1472
[580]1473/*
1474// 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]1475
[580]1476void Graph::exportToSVG(const QString& fname)
1477{
1478  // enable workaround for Qt3 misalignments
1479  QwtPainter::setSVGMode(true);
1480  QPicture picture;
1481  QPainter p(&picture);
1482  d_plot->print(&p, d_plot->rect());
1483  p.end();
[565]1484
[580]1485  picture.save(fname, "svg");
1486}
1487*/
1488
1489
1490
1491
[564]1492/**
1493   Save the current mouse press point
1494   @param p mouse click point
1495*/
[720]1496#if QT_VERSION < 0x040000
1497void G4OpenGLQtViewer::G4MousePressEvent(QPoint p,Qt::ButtonState mButtons)
1498#else
1499void G4OpenGLQtViewer::G4MousePressEvent(QPoint p,Qt::MouseButtons mButtons)
1500#endif
[564]1501{
[720]1502  fAutoMove = false; // stop automove
[696]1503  fLastPos = p;
[707]1504  if (fMouseAction == STYLE2){  // pick
[681]1505    Pick(p.x(),p.y());
1506  }
[564]1507}
1508
[696]1509
[564]1510/**
1511   @param pos_x mouse x position
1512   @param pos_y mouse y position
1513   @param mButtons mouse button active
[720]1514   @param mAutoMove true: apply this move till another evnt came, false :one time move
[564]1515*/
[599]1516
1517#if QT_VERSION < 0x040000
[720]1518void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::ButtonState mButtons,bool mAutoMove)
[599]1519#else
[720]1520  void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons,bool mAutoMove)
[599]1521#endif
[564]1522{
[720]1523  fAutoMove = mAutoMove;
[713]1524
[720]1525  if (!fAutoMove) {  // keep old delta if automove
[721]1526    fDeltaPosX = fLastPos.x() - pos_x;
1527    fDeltaPosY = fLastPos.y() - pos_y;
[720]1528  }
[713]1529
[721]1530  if ((fDeltaPosX == 0) && (fDeltaPosY == 0)) {
[720]1531    fAutoMove = false;
1532  }
[713]1533
[696]1534  if (fMouseAction == STYLE1) {  // rotate
[564]1535    if (mButtons & Qt::LeftButton) {
[724]1536      rotateScene(fDeltaPosX,fDeltaPosY,fAutoMove);
[564]1537    }
[713]1538  } else if (fMouseAction == STYLE2) {  // move
1539    if (mButtons & Qt::LeftButton) {
[720]1540      if (fAutoMove) {
1541        while (fAutoMove) {
[724]1542          moveScene(-fDeltaPosX,-fDeltaPosY,0,true,true);
[722]1543          ((QApplication*)G4Qt::getInstance ())->processEvents();
[720]1544        }
1545      } else {
[724]1546        moveScene(-fDeltaPosX,-fDeltaPosY,0,true,false);
[713]1547      }
1548    }
[564]1549  }
[696]1550  fLastPos = QPoint(pos_x, pos_y);
[564]1551}
1552
[720]1553
[696]1554/**
[711]1555   Move the scene of dx, dy, dz values.
[696]1556   @param dx delta mouse x position
1557   @param dy delta mouse y position
[720]1558   @param mouseMove : true if even comes froma mouse move, false if even comes from key action
[696]1559*/
1560
[724]1561void G4OpenGLQtViewer::moveScene(G4double dx,G4double dy, G4double dz,bool mouseMove,bool mAutoMove)
[696]1562{
[728]1563  if (fHoldMoveEvent)
1564    return;
1565  fHoldMoveEvent = true;
1566
[724]1567  if( mAutoMove == false) {
1568    fAutoMove = true;
1569  }
[720]1570  G4double coefTrans = 0;
1571  GLdouble coefDepth = 0;
[724]1572  while (fAutoMove) {
1573    if( mAutoMove == false) {
1574      fAutoMove = false;
[720]1575    }
[724]1576    if(mouseMove) {
1577      coefTrans = ((G4double)getSceneNearWidth())/((G4double)WinSize_x);
1578      if (WinSize_y <WinSize_x) {
1579        coefTrans = ((G4double)getSceneNearWidth())/((G4double)WinSize_y);
1580      }
1581    } else {
1582      coefTrans = getSceneNearWidth()*fDeltaSceneTranslation;
1583      coefDepth = getSceneDepth()*fDeltaDepth;
1584    }
1585    fVP.IncrementPan(-dx*coefTrans,dy*coefTrans,dz*coefDepth);
1586   
1587    updateQWidget();
[729]1588    if (fAutoMove)
1589      ((QApplication*)G4Qt::getInstance ())->processEvents();
[720]1590  }
[728]1591
1592  fHoldMoveEvent = false;
[696]1593}
1594
1595
1596/**
1597   @param dx delta mouse x position
1598   @param dy delta mouse y position
1599*/
1600
[724]1601void G4OpenGLQtViewer::rotateScene(G4double dx, G4double dy,bool mAutoRotate)
[696]1602{
[728]1603  if (fHoldRotateEvent)
1604    return;
1605  fHoldRotateEvent = true;
1606
[724]1607  if( mAutoRotate == false) {
1608    fAutoMove = true;
1609  }
1610  G4Vector3D vp;
1611  G4Vector3D up;
[696]1612 
[724]1613  G4Vector3D xprime;
1614  G4Vector3D yprime;
1615  G4Vector3D zprime;
[696]1616 
1617  G4double delta_alpha;
1618  G4double delta_theta;
1619 
[724]1620  G4Vector3D new_vp;
1621  G4Vector3D new_up;
[696]1622 
[724]1623  G4double cosalpha;
1624  G4double sinalpha;
[696]1625 
[724]1626  G4Vector3D a1;
1627  G4Vector3D a2;
1628  G4Vector3D delta;
1629  G4Vector3D viewPoint;
1630
1631  while (fAutoMove) {
1632    if( mAutoRotate == false) {
1633      fAutoMove = false;
1634    }
1635   
1636    //phi spin stuff here
[696]1637 
[724]1638    vp = fVP.GetViewpointDirection ().unit ();
1639    up = fVP.GetUpVector ().unit ();
[696]1640 
[724]1641    yprime = (up.cross(vp)).unit();
1642    zprime = (vp.cross(yprime)).unit();
[696]1643 
[724]1644    if (fVP.GetLightsMoveWithCamera()) {
[728]1645      delta_alpha = dy * fDeltaRotation;
1646      delta_theta = -dx * fDeltaRotation;
[724]1647    } else {
[728]1648      delta_alpha = -dy * fDeltaRotation;
1649      delta_theta = dx * fDeltaRotation;
[724]1650    }   
[696]1651 
[724]1652    delta_alpha *= deg;
1653    delta_theta *= deg;
1654 
1655    new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime;
[727]1656
1657    // to avoid z rotation flipping
1658    // to allow more than 360° rotation
[724]1659    if (fVP.GetLightsMoveWithCamera()) {
1660      new_up = (new_vp.cross(yprime)).unit();
[727]1661      if (new_vp.z()*vp.z() <0) {
1662        new_up.set(new_up.x(),-new_up.y(),new_up.z());
1663      }
[724]1664    } else {
1665      new_up = up;
[727]1666      if (new_vp.z()*vp.z() <0) {
1667        new_up.set(new_up.x(),-new_up.y(),new_up.z());
1668      }
[724]1669    }
[727]1670    fVP.SetUpVector(new_up);
[724]1671    ////////////////
1672    // Rotates by fixed azimuthal angle delta_theta.
1673   
1674    cosalpha = new_up.dot (new_vp.unit());
1675    sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));
1676    yprime = (new_up.cross (new_vp.unit())).unit ();
1677    xprime = yprime.cross (new_up);
1678    // Projection of vp on plane perpendicular to up...
1679    a1 = sinalpha * xprime;
1680    // Required new projection...
1681    a2 = sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);
1682    // Required Increment vector...
1683    delta = a2 - a1;
1684    // So new viewpoint is...
1685    viewPoint = new_vp.unit() + delta;
1686   
[727]1687#ifdef GEANT4_QT_DEBUG
[729]1688//      printf("vp Vector : %f %f %f delta_alpha:%f delta_theta:%f cosalpha:%f sinalpha:%f\n",viewPoint.x(),viewPoint.y(),viewPoint.z(),delta_alpha,delta_theta,cosalpha,sinalpha);
1689//      printf("up : %f %f %f\n",up.x(),up.y(),up.z());
1690//      printf("new up : %f %f %f\n",new_up.x(),new_up.y(),new_up.z());
1691//      printf("vp : %f %f %f\n",vp.x(),vp.y(),vp.z());
1692//      printf("new_vp : %f %f %f\n",new_vp.x(),new_vp.y(),new_vp.z());
[727]1693#endif
[724]1694    fVP.SetViewAndLights (viewPoint);
1695    updateQWidget();
1696   
[729]1697    if (fAutoMove)
1698      ((QApplication*)G4Qt::getInstance ())->processEvents();
[724]1699  }
[729]1700 
[728]1701  fHoldRotateEvent = false;
[696]1702}
1703
[660]1704/** This is the benning of a rescale function. It does nothing for the moment
1705    @param aWidth : new width
1706    @param aHeight : new height
1707*/
[585]1708void G4OpenGLQtViewer::rescaleImage(
1709 int aWidth
1710,int aHeight
1711){
[608]1712#ifdef GEANT4_QT_DEBUG
[586]1713  printf("should rescale \n");
[608]1714#endif
[660]1715  GLfloat* feedback_buffer;
1716  GLint returned;
1717  FILE* file;
1718 
[673]1719//   feedback_buffer = new GLfloat[size];
1720//   glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer);
1721//   glRenderMode (GL_FEEDBACK);
[660]1722 
[673]1723//   glViewport (0, 0, aWidth, aHeight);
1724//   DrawView();
1725//   returned = glRenderMode (GL_RENDER);
[660]1726
[585]1727}
[586]1728
1729/**
[652]1730   Generate Vectorial Encapsulated Postscript form image
[586]1731   @param aFilename : name of file
1732   @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha
1733   @param aImage : Image to print
1734*/
[652]1735bool G4OpenGLQtViewer::generateVectorEPS (
1736 QString aFilename
1737,int aWidth
1738,int aHeight
1739,QImage aImage
1740)
1741{
1742  // Print vectored PostScript
1743 
1744  G4int size = 5000000;
1745
1746  GLfloat* feedback_buffer;
1747  GLint returned;
1748  FILE* file;
1749 
1750  feedback_buffer = new GLfloat[size];
1751  glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer);
1752  glRenderMode (GL_FEEDBACK);
1753 
[709]1754  int side = aWidth;
1755  if (aHeight < aWidth) side = aHeight;
[675]1756  glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side);
[652]1757  DrawView();
1758
1759  returned = glRenderMode (GL_RENDER);
1760 
1761 
1762#if QT_VERSION < 0x040000
1763  file = fopen (aFilename.ascii(), "w");
1764#else
1765  file = fopen (aFilename.toStdString().c_str(), "w");
1766#endif
1767  if (file) {
1768    spewWireframeEPS (file, returned, feedback_buffer, "rendereps");
1769  } else {
[658]1770#if QT_VERSION < 0x040000
[748]1771    G4cerr << "Could not open "<< aFilename.ascii() << G4endl;
[658]1772#else
[748]1773    G4cerr << "Could not open "<< aFilename.toStdString().c_str() << G4endl;
[658]1774#endif
[652]1775  }
1776 
1777  delete[] feedback_buffer;
1778
1779  return true;
1780}
1781
1782/**
1783   Generate Encapsulated Postscript form image
1784   @param aFilename : name of file
1785   @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha
1786   @param aImage : Image to print
1787*/
[588]1788bool G4OpenGLQtViewer::generateEPS (
[586]1789 QString aFilename
1790,int aInColor
1791,QImage aImage
1792)
1793{
[587]1794  // FIXME
[608]1795#ifdef GEANT4_QT_DEBUG
[586]1796  printf("saving EPS\n");
[608]1797#endif
[586]1798
1799  FILE* fp;
[587]1800
[649]1801  if (aImage.bits () == NULL)
[588]1802    return false;
[586]1803 
[600]1804#if QT_VERSION < 0x040000
1805  fp = fopen (aFilename.ascii(), "w");
1806#else
[602]1807  fp = fopen (aFilename.toStdString().c_str(), "w");
[600]1808#endif
[586]1809  if (fp == NULL) {
[588]1810    return false;
[586]1811  }
1812 
1813  fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n");
[600]1814#if QT_VERSION < 0x040000
1815  fprintf (fp, "%%%%Title: %s\n", aFilename.ascii());
1816#else
[602]1817  fprintf (fp, "%%%%Title: %s\n", aFilename.toStdString().c_str());
[600]1818#endif
[586]1819  fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n");
[587]1820  fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", aImage.width(), aImage.height());
[586]1821  fprintf (fp, "%%%%EndComments\n");
1822  fprintf (fp, "gsave\n");
1823  fprintf (fp, "/bwproc {\n");
1824  fprintf (fp, "    rgbproc\n");
1825  fprintf (fp, "    dup length 3 idiv string 0 3 0 \n");
1826  fprintf (fp, "    5 -1 roll {\n");
1827  fprintf (fp, "    add 2 1 roll 1 sub dup 0 eq\n");
1828  fprintf (fp, "    { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n");
1829  fprintf (fp, "       3 1 roll 5 -1 roll } put 1 add 3 0 \n");
1830  fprintf (fp, "    { 2 1 roll } ifelse\n");
1831  fprintf (fp, "    }forall\n");
1832  fprintf (fp, "    pop pop pop\n");
1833  fprintf (fp, "} def\n");
1834  fprintf (fp, "systemdict /colorimage known not {\n");
1835  fprintf (fp, "   /colorimage {\n");
1836  fprintf (fp, "       pop\n");
1837  fprintf (fp, "       pop\n");
1838  fprintf (fp, "       /rgbproc exch def\n");
1839  fprintf (fp, "       { bwproc } image\n");
1840  fprintf (fp, "   }  def\n");
1841  fprintf (fp, "} if\n");
[587]1842  fprintf (fp, "/picstr %d string def\n", aImage.width() * aInColor);
1843  fprintf (fp, "%d %d scale\n", aImage.width(), aImage.height());
1844  fprintf (fp, "%d %d %d\n", aImage.width(), aImage.height(), 8);
1845  fprintf (fp, "[%d 0 0 %d 0 0]\n", aImage.width(), aImage.height());
[586]1846  fprintf (fp, "{currentfile picstr readhexstring pop}\n");
1847  fprintf (fp, "false %d\n", aInColor);
1848  fprintf (fp, "colorimage\n");
1849 
1850
[588]1851  int width = aImage.width();
1852  int height = aImage.height();
1853  int depth = aImage.depth();
1854  int size = width*height;
1855 
1856  if (depth == 1)
1857    size = (width+7)/8*height;
1858  else if (aInColor == 1)
1859    size = size*3;
1860 
1861  int i = 0;
[649]1862  //  if ( aInColor ==1 ) {
1863  // FIXME : L. Garnier. For the moment 10 dec 2007, I could not find a way
1864  // to save correctly grayscale Image. I mean that color or grayscale image
1865  // have the same file save size !
1866 
1867  /* } else*/ if (depth == 8) {
[588]1868    for(int y=height-1; y >=0 ; y--) {
1869      const uchar * s = aImage.scanLine(y);
1870      for(int x=0; x <width; x++) {
1871        QRgb rgb = aImage.color(s[x]);
1872        if (aInColor == 1) {
1873          fprintf (fp, " %02hx ",(unsigned char)qGray(rgb));
1874          i++;
1875        } else {
1876          fprintf (fp, " %02hx %02hx %02hx",
1877                   (unsigned char) qRed(rgb),
1878                   (unsigned char) qGreen(rgb),
1879                   (unsigned char) qBlue(rgb));
1880          i += 3;
1881        }
1882      }
[586]1883      fprintf (fp, "\n");
[588]1884    }
1885  } else {
[601]1886#if QT_VERSION < 0x040000
[649]1887    bool alpha = aImage.hasAlphaBuffer();
[601]1888#else
[588]1889    bool alpha = aImage.hasAlphaChannel();
1890    for(int y=height-1; y >=0 ; y--) {
1891      QRgb * s = (QRgb*)(aImage.scanLine(y));
1892      for(int x=0; x <width; x++) {
1893        QRgb rgb = (*s++);
1894        if (alpha && qAlpha(rgb) < 0x40) // 25% alpha, convert to white -
1895          rgb = qRgb(0xff, 0xff, 0xff);
1896        if (aInColor == 1) {
1897          fprintf (fp, " %02hx ",(unsigned char)qGray(rgb));
1898          i++;
1899        } else {
1900          fprintf (fp, " %02hx %02hx %02hx",
1901                   (unsigned char) qRed(rgb),
1902                   (unsigned char) qGreen(rgb),
1903                   (unsigned char) qBlue(rgb));
1904          i += 3;
1905        }
[587]1906      }
1907      fprintf (fp, "\n");
[588]1908    }
[601]1909#endif
1910
[586]1911  }
[588]1912
[586]1913  fprintf (fp, "grestore\n");
1914  fprintf (fp, "showpage\n");
1915  fclose (fp);
[588]1916
1917  return true;
[586]1918}
[588]1919/**
1920   Generate Postscript or PDF form image
1921   @param aFilename : name of file
1922   @param aInColor : numbers of colors : 1->BW 2->RGB
1923   @param aImage : Image to print
1924*/
1925bool G4OpenGLQtViewer::generatePS_PDF (
1926 QString aFilename
1927,int aInColor
1928,QImage aImage
1929)
1930{
[638]1931
[600]1932#if QT_VERSION < 0x040000
1933#ifdef Q_WS_MAC || Q_WS_X11
[588]1934  QPrinter printer;
1935  //  printer.setPageSize(pageSize);
1936  if (aInColor == 1) {
1937    printer.setColorMode(QPrinter::GrayScale);
1938  } else {
1939    printer.setColorMode(QPrinter::Color);
1940  }
1941
[600]1942  /* FIXME : I don't know which format it will save...
1943     if (aFilename.endsWith(".ps")) {
1944     printer.setOutputFormat(QPrinter::PostScriptFormat);
1945     } else {
1946     printer.setOutputFormat(QPrinter::PdfFormat);
1947     }
1948  */
1949  printer.setOutputFileName(aFilename);
1950  //  printer.setFullPage ( true);
1951  QPainter paint(&printer);
1952  paint.drawImage (0,0,aImage );
1953  paint.end();
1954#else
[748]1955  G4cerr << "This fonction is only supported on Mac OsX or X11 with Qt3. Full platform supported with Qt4" << G4endl;
[600]1956#endif
1957#else
1958  QPrinter printer;
1959  //  printer.setPageSize(pageSize);
[637]1960
1961  // FIXME : L. Garnier 4/12/07
1962  // This is not working, it does nothing. Image is staying in color mode
1963  // So I have desactivate the B/W button in GUI
1964  if ((!aImage.isGrayscale ()) &&(aInColor ==1 )) {
1965#if QT_VERSION < 0x040000
1966    aImage = aImage.convertDepth(1,Qt::MonoOnly);
1967#else
1968    aImage = aImage.convertToFormat ( aImage.format(), Qt::MonoOnly);
1969#endif
[600]1970  }
1971
[637]1972
[588]1973  if (aFilename.endsWith(".ps")) {
[606]1974#if QT_VERSION > 0x040200
[588]1975    printer.setOutputFormat(QPrinter::PostScriptFormat);
[606]1976#endif
[588]1977  } else {
[606]1978#if QT_VERSION > 0x040100
[588]1979    printer.setOutputFormat(QPrinter::PdfFormat);
[606]1980#endif
[588]1981  }
[606]1982#if QT_VERSION > 0x040100
[588]1983  printer.setOutputFileName(aFilename);
[606]1984#endif
[588]1985  //  printer.setFullPage ( true);
1986  QPainter paint(&printer);
[637]1987  paint.drawImage (0,0,aImage);
[588]1988  paint.end();
[600]1989#endif
[588]1990  return true;
1991}
1992
1993
[720]1994
[696]1995void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * event)
1996{
[721]1997  if (fHoldKeyEvent)
[702]1998    return;
1999
[721]2000  fHoldKeyEvent = true;
[702]2001
[709]2002#if QT_VERSION < 0x040000
2003  if ((event->key() == Qt::Key_Down) && (event->state() & Qt::AltButton )) { // go backward
2004#else
[707]2005  if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::AltModifier )) { // go backward
[709]2006#endif
[712]2007   
[720]2008    moveScene(0,0,1,false);
[707]2009  }
[709]2010#if QT_VERSION < 0x040000
2011  else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::AltButton)) { // go forward
2012#else
[707]2013  else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::AltModifier)) { // go forward
[709]2014#endif
[720]2015    moveScene(0,0,-1,false);
[707]2016  }
[709]2017#if QT_VERSION < 0x040000
2018  if ((event->key() == Qt::Key_Down) && (event->state() & Qt::ShiftButton)) { // rotate phi
2019#else
[707]2020  if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi
[709]2021#endif
[720]2022    rotateScene(0,-1);
[707]2023  }
[709]2024#if QT_VERSION < 0x040000
2025  else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::ShiftButton)) { // rotate phi
2026#else
[707]2027  else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi
[709]2028#endif
[720]2029    rotateScene(0,1);
[707]2030  }
[709]2031#if QT_VERSION < 0x040000
2032  if ((event->key() == Qt::Key_Left) && (event->state() & Qt::ShiftButton)) { // rotate theta
2033#else
[707]2034  if ((event->key() == Qt::Key_Left) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta
[709]2035#endif
[720]2036    rotateScene(1,0);
[707]2037  }
[709]2038#if QT_VERSION < 0x040000
[716]2039  else if ((event->key() == Qt::Key_Right) && (event->state() & Qt::ShiftButton)) { // rotate theta
[709]2040#else
2041  else if ((event->key() == Qt::Key_Right) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta
2042#endif
[720]2043    rotateScene(-1,0);
[707]2044  }
[721]2045
2046#if QT_VERSION < 0x040000
[722]2047  if ((event->state() & Qt::AltButton)) {
[721]2048#else
[722]2049  if ((event->modifiers() & Qt::AltModifier)) {
[721]2050#endif
[722]2051    if (event->key() == Qt::Key_Plus) {
[728]2052      fDeltaRotation = fDeltaRotation/0.7;
[722]2053    }
2054    else if (event->key() == Qt::Key_Minus) {
[728]2055      fDeltaRotation = fDeltaRotation*0.7;
[722]2056    }
2057  } else {
2058    if (event->key() == Qt::Key_Plus) {
2059      fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+fDeltaZoom));
2060      updateQWidget();
2061    }
2062    else if (event->key() == Qt::Key_Minus) {
2063      fVP.SetZoomFactor(fVP.GetZoomFactor()*(1-fDeltaZoom));
2064      updateQWidget();
2065    }
[721]2066  }
[722]2067 
2068 
[704]2069  if (event->key() == Qt::Key_Escape) { // escaped from full screen
[717]2070#if QT_VERSION >= 0x030200
2071    if (GLWindow->isFullScreen()) {
2072#if QT_VERSION < 0x040000
2073      fFullScreenOn->activated();
2074#else
2075      fFullScreenOn->trigger();
2076#endif
2077    }
2078#endif
[707]2079  }
[740]2080  // several case here : If return is pressed, in every case -> display the movie parameters dialog
2081  // If one parameter is wrong -> put it in red (only save filenam could be wrong..)
2082  // If encoder not found-> does nothing.Only display a message in status box
2083  // If all ok-> generate parameter file
2084  // If ok -> put encoder button enabled
2085 
[723]2086  if ((event->key() == Qt::Key_Return) || (event->key() == Qt::Key_Enter)){ // end of video
[744]2087   stopVideo();
[723]2088  }
2089  if (event->key() == Qt::Key_Space){ // start/pause of video
[744]2090   startPauseVideo();
[723]2091  }
2092
[707]2093  // with no modifiers
[716]2094#if QT_VERSION < 0x040000
2095  if (event->state() == Qt::NoButton) {
2096#else
2097  if (event->modifiers() == Qt::NoModifier) {
2098#endif
[707]2099    if (event->key() == Qt::Key_Down) { // go down
[730]2100      moveScene(0,1,0,false);
[696]2101    }
[707]2102    else if (event->key() == Qt::Key_Up) {  // go up
[730]2103      moveScene(0,-1,0,false);
[696]2104    }
[707]2105    if (event->key() == Qt::Key_Left) { // go left
[720]2106      moveScene(-1,0,0,false);
[696]2107    }
[707]2108    else if (event->key() == Qt::Key_Right) { // go right
[720]2109      moveScene(1,0,0,false);
[696]2110    }
[707]2111  }
[721]2112  fHoldKeyEvent = false;
[696]2113}
[730]2114 
[696]2115
[744]2116/** Stop the video. Check all parameters and enable encoder button if all is ok.
2117*/
2118void G4OpenGLQtViewer::stopVideo() {
2119
2120 // if encoder parameter is wrong, display parameters dialog and return
2121  if (!fMovieParametersDialog) {
2122    showMovieParametersDialog();
2123  }
2124  setRecordingStatus(STOP);
2125
2126  if (fRecordFrameNumber >0) {
2127    // check parameters if they were modified (Re APPLY them...)
[747]2128    // It will enable/disable encode button
[744]2129    fMovieParametersDialog->checkAllParameters();
2130  } else {
2131    setRecordingStatus(WAIT);
2132    setRecordingInfos("No frame to encode.");
2133  }
2134}
2135
2136
2137/** Start/Pause the video..
2138*/
2139void G4OpenGLQtViewer::startPauseVideo() {
2140   
2141  // first time, if temp parameter is wrong, display parameters dialog and return
2142  if ( fRecordingStep == WAIT) {
2143    if ( fRecordFrameNumber == 0) {
2144      if (getTempFolderPath() == "") {
2145        showMovieParametersDialog();
2146        setRecordingInfos("You should specified the temp folder in order to make movie");
2147        return;
2148      } else  {
2149        // remove temp folder if it was create
2150        QString tmp = removeTempFolder();
2151        if (tmp !="") {
2152          setRecordingInfos(tmp);
2153          return;
2154        }
2155        tmp = createTempFolder();
2156        if (tmp != "") {
[748]2157          setRecordingInfos("Can't create temp folder."+tmp);
[744]2158          return;
2159        }
2160      }
2161    }
2162  }
2163  if (fRecordingStep == WAIT) {
[745]2164    setRecordingStatus(START);
[744]2165  } else if (fRecordingStep == START) {
[745]2166    setRecordingStatus(PAUSE);
[744]2167  } else if (fRecordingStep == PAUSE) {
[745]2168    setRecordingStatus(CONTINUE);
[744]2169  } else if (fRecordingStep == CONTINUE) {
[745]2170    setRecordingStatus(PAUSE);
[744]2171  }
2172}
2173
2174
2175void G4OpenGLQtViewer::setRecordingStatus(RECORDING_STEP step) {
2176 
[745]2177#ifdef GEANT4_QT_DEBUG
2178  printf("setRecordingStatus \n");
2179#endif
[744]2180  QString txt = "";
2181  if (step == WAIT) {
2182    txt  = "Waiting to start...";
2183    fRecordFrameNumber = 0; // reset the frame number
2184  } else if (step == START) {
2185    txt  = "Start Recording...";
2186  } else if (step == PAUSE) {
2187    txt  = "Pause Recording...";
2188  } else if (step == CONTINUE) {
2189    txt  = "Continue Recording...";
2190  } else if (step == STOP) {
2191    txt  = "Stop Recording...";
[748]2192  } else if (step == READY_TO_ENCODE) {
2193    txt  = "Ready to Encode...";
[744]2194  } else if (step == ENCODE) {
2195    txt  = "Encoding...";
2196  } else {
2197  }
2198
[745]2199  fRecordingStep = step;
2200
[744]2201  if (fMovieParametersDialog) {
[745]2202    fMovieParametersDialog->setRecordingStatus(txt);
[744]2203  } else {
2204#if QT_VERSION < 0x040000
2205    G4cout << txt.ascii() << G4endl;
2206#else
2207    G4cout << txt.toStdString().c_str() << G4endl;
2208#endif
2209  }
2210  setRecordingInfos("");
2211}
2212
2213void G4OpenGLQtViewer::setRecordingInfos(QString txt) {
2214  if (fMovieParametersDialog) {
[745]2215    fMovieParametersDialog->setRecordingInfos(txt);
[744]2216  } else {
2217#if QT_VERSION < 0x040000
2218    G4cout << txt.ascii() << G4endl;
2219#else
2220    G4cout << txt.toStdString().c_str() << G4endl;
2221#endif
2222  }
2223}
2224
[739]2225/** Init the movie parameters. Temp dir and encoder path
2226*/
2227void G4OpenGLQtViewer::initMovieParameters() {
2228  //init encoder
2229 
2230   //look for encoderPath
2231     QProcess search;
2232     search.setReadChannelMode(QProcess::MergedChannels);
2233     search.start ("which mpeg_encode");
2234 
2235     if (search.waitForFinished()) {
2236       fEncoderPath = QString(QString::fromLocal8Bit(search.readAll())).trimmed();
2237       // if not found, return "not found"
2238       if (fEncoderPath.contains(" ")) {
2239         fEncoderPath = "";
2240       } else if (!fEncoderPath.contains("mpeg_encode")) {
2241         fEncoderPath = "";
2242       }
2243     }
2244     setEncoderPath(fEncoderPath);
2245// init temp folder
2246  setTempFolderPath(QDir::temp ().absolutePath ());
2247}
2248
[735]2249/** @return encoder path or "" if it does not exist
[730]2250 */
2251QString G4OpenGLQtViewer::getEncoderPath() {
[737]2252  return fEncoderPath;
[730]2253}
2254 
[720]2255
[730]2256/**
2257 * set the new encoder path
[733]2258 * @return "" if correct. The error otherwise
[730]2259*/
[733]2260QString G4OpenGLQtViewer::setEncoderPath(QString path) {
[735]2261  if (path == "") {
[736]2262    return "File does not exist";
[735]2263  }
[740]2264  path =  QDir::cleanPath(path);
[732]2265  QFile *f = new QFile(path);
2266  if (!f->exists()) {
[736]2267    return "File does not exist";
[732]2268  }
2269  if (!(f->permissions() & QFile::ExeUser)) {
[733]2270    return "File exist but is not executable";
[732]2271  }
[730]2272  fEncoderPath = path;
[733]2273  return "";
[730]2274}
[732]2275
[745]2276
2277bool G4OpenGLQtViewer::isRecording(){
[746]2278  if ((fRecordingStep == START) || (fRecordingStep == CONTINUE)) {
[745]2279    return true;
2280  }
2281  return false;
[740]2282}
2283
[748]2284bool G4OpenGLQtViewer::isStopped(){
2285  if (fRecordingStep == STOP) {
2286    return true;
2287  }
2288  return false;
2289}
[745]2290
[748]2291
[745]2292bool G4OpenGLQtViewer::isReadyToEncode(){
[748]2293  if (fRecordingStep == READY_TO_ENCODE) {
[745]2294    return true;
2295  }
2296  return false;
2297}
2298
2299
[732]2300/**
2301 * set the temp folder path
[733]2302 * @return "" if correct. The error otherwise
[732]2303*/
[733]2304QString G4OpenGLQtViewer::setTempFolderPath(QString path) {
[732]2305
[735]2306  if (path == "") {
2307    return "Path does not exist";
2308  }
[740]2309  path =  QDir::cleanPath(path);
[732]2310  QDir *d = new QDir(path);
2311  if (!d->exists(path)) {
[733]2312    return "Path does not exist";
[732]2313  }
2314
2315  d->setFilter( QDir::Dirs | QDir::Readable | QDir::Writable );
2316  QStringList subDirList = d->entryList();
2317  bool found = false;
2318
2319  for (QStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) {
2320    const QString currentDir = *it;
2321   
2322    if (currentDir == ".") { // we found it
2323      found = true;
2324    }
2325  }
2326
2327  if (!found)
[733]2328    return "Path exist, but is not write accessible";
[732]2329 
2330  fTempFolderPath = path;
[733]2331  return "";
[732]2332}
2333
[735]2334/** @return the temp folder path or "" if it does not exist
[732]2335 */
2336QString G4OpenGLQtViewer::getTempFolderPath() {
[738]2337  return fTempFolderPath;
[732]2338}
[730]2339 
[733]2340/**
2341 * set the save file name path
2342 * @return "" if correct. The error otherwise
2343*/
2344QString G4OpenGLQtViewer::setSaveFileName(QString path) {
[730]2345
[735]2346  if (path == "") {
2347    return "Path does not exist";
2348  }
[740]2349  path =  QDir::cleanPath(path);
2350  QFileInfo *fileInfo = new QFileInfo(path);
2351  QDir dir = fileInfo->absoluteDir();
2352  if (!dir.exists()) {
[748]2353    return "Folder does not exist";
[733]2354  }
2355
[740]2356  dir.setFilter( QDir::Dirs | QDir::Writable );
2357  QStringList subDirList = dir.entryList();
[733]2358  bool found = false;
2359
2360  for (QStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) {
2361    const QString currentDir = *it;
2362   
2363    if (currentDir == ".") { // we found it
2364      found = true;
2365    }
2366  }
2367
2368  if (!found)
2369    return "Path exist, but is not write accessible";
2370 
2371  fSaveFileName = path;
2372  return "";
2373}
2374
2375/** @return the save file path
2376 */
2377QString G4OpenGLQtViewer::getSaveFileName() {
2378  return fSaveFileName ;
2379}
2380
[738]2381/** Create a Qt_temp folder in the temp folder given
[740]2382* The temp folder will be like this /tmp/QtMovie_12-02-2008_12_12_58/
2383* @return "" if success. Error message if not.
[738]2384*/
[740]2385QString G4OpenGLQtViewer::createTempFolder() {
[738]2386  fMovieTempFolderPath = "";
2387
2388  //check
[740]2389  QString tmp = setTempFolderPath(fTempFolderPath);
2390  if (tmp != "") {
2391    return tmp;
[738]2392  }
[744]2393  QString path = QString(QDir::separator())+"QtMovie_"+QDateTime::currentDateTime ().toString("dd-MM-yyyy_hh-mm-ss")+QString(QDir::separator());
[740]2394  QDir *d = new QDir(QDir::cleanPath(fTempFolderPath));
[738]2395  // check if it is already present
2396  if (d->exists(path)) {
[748]2397    return "Folder "+path+" already exists.Please remove it first";
[738]2398  }
[739]2399  if (d->mkdir(fTempFolderPath+path)) {
2400    fMovieTempFolderPath = fTempFolderPath+path;
[740]2401    return "";
2402  } else {
[748]2403    return "Can't create "+fTempFolderPath+path;
[738]2404  }
[740]2405  return "-";
[738]2406}
2407
2408/** Remove the Qt_temp folder in the temp folder
2409*/
[740]2410QString G4OpenGLQtViewer::removeTempFolder() {
[738]2411        // remove files in Qt_temp folder
[742]2412  if (fMovieTempFolderPath == "") {
2413    return "";
2414  }
[740]2415  QDir *d = new QDir(QDir::cleanPath(fMovieTempFolderPath));
[739]2416  if (!d->exists()) {
[740]2417    return "";  // already remove
[738]2418  }
2419
[739]2420  d->setFilter(QDir::Readable | QDir::Writable );
[738]2421  QStringList subDirList = d->entryList();
[739]2422  int res = true;
[740]2423  QString error = "";
[738]2424  for (QStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) {
[739]2425    const QString currentFile = *it;
2426    if (!d->remove(currentFile)) {
2427      res = false;
[743]2428      QString file = fMovieTempFolderPath+currentFile;
[748]2429      error +="Removing file failed : "+file;
[739]2430    }
[738]2431  }
[739]2432  if (res) {
2433    if (d->rmdir(fMovieTempFolderPath)) {
[740]2434      return "";
2435    } else {
[748]2436      return "Dir "+fMovieTempFolderPath+" should be empty, but could not remove it";
[739]2437    }
[740]2438
[738]2439  }
[748]2440  return "Could not remove "+fMovieTempFolderPath+" because of the following errors :"+error;
[738]2441}
2442
[730]2443
[732]2444
[720]2445bool G4OpenGLQtViewer::hasPendingEvents () {
2446  return ((QApplication*)G4Qt::getInstance ())->hasPendingEvents ();
2447}
2448
[740]2449bool G4OpenGLQtViewer::generateMpegEncoderParameters () {
[720]2450
[747]2451                // save the parameter file
[723]2452  FILE* fp;
[740]2453#if QT_VERSION < 0x040000
2454  fp = fopen (QString(fMovieTempFolderPath+fParameterFileName).ascii, "w");
2455#else
2456  fp = fopen (QString(fMovieTempFolderPath+fParameterFileName).toStdString().c_str(), "w");
2457#endif
[723]2458
2459  if (fp == NULL) {
[747]2460    setRecordingInfos("Generation of parameter file failed");
[723]2461    return false;
2462  }
2463
2464  fprintf (fp,"# parameter file template with lots of comments to assist you\n");
2465  fprintf (fp,"#\n");
2466  fprintf (fp,"# you can use this as a template, copying it to a separate file then modifying\n");
2467  fprintf (fp,"# the copy\n");
2468  fprintf (fp,"#\n");
2469  fprintf (fp,"#\n");
2470  fprintf (fp,"# any line beginning with '#' is a comment\n");
2471  fprintf (fp,"#\n");
2472  fprintf (fp,"# no line should be longer than 255 characters\n");
2473  fprintf (fp,"#\n");
2474  fprintf (fp,"#\n");
2475  fprintf (fp,"# general format of each line is:\n");
2476  fprintf (fp,"#          \n");
2477  fprintf (fp,"#\n");
2478  fprintf (fp,"# lines can generally be in any order\n");
2479  fprintf (fp,"#\n");
2480  fprintf (fp,"# an exception is the option 'INPUT' which must be followed by input\n");
2481  fprintf (fp,"# files in the order in which they must appear, followed by 'END_INPUT'\n");
2482  fprintf (fp,"#\n");
2483  fprintf (fp,"# Also, if you use the `command` method of generating input file names,\n");
2484  fprintf (fp,"# the command will only be executed in the INPUT_DIR if INPUT_DIR preceeds\n");
2485  fprintf (fp,"# the INPUT parameter.\n");
2486  fprintf (fp,"#\n");
2487  fprintf (fp,"#  MUST be in UPPER CASE\n");
2488  fprintf (fp,"#\n");
2489  fprintf (fp,"\n");
2490  fprintf (fp,"# Pattern affects speed, quality and compression. See the User's Guide\n");
2491  fprintf (fp,"# for more info.\n");
2492  fprintf (fp,"\n");
2493  fprintf (fp,"PATTERN          IBBPBBPBBPBBPBBP\n");
2494#if QT_VERSION < 0x040000
[742]2495  fprintf (fp,"OUTPUT           %s\n",getSaveFileName().ascii());
[723]2496#else
[742]2497  fprintf (fp,"OUTPUT           %s\n",getSaveFileName().toStdString().c_str());
[723]2498#endif
2499  fprintf (fp,"\n");
2500  fprintf (fp,"# mpeg_encode really only accepts 3 different file formats, but using a\n");
2501  fprintf (fp,"# conversion statement it can effectively handle ANY file format\n");
2502  fprintf (fp,"#\n");
2503  fprintf (fp,"# You must specify the type of the input files.  The choices are:\n");
2504  fprintf (fp,"#    YUV, PPM, JMOVIE, Y, JPEG, PNM\n");
2505  fprintf (fp,"#        (must be upper case)\n");
2506  fprintf (fp,"#\n");
2507  fprintf (fp,"BASE_FILE_FORMAT PPM\n");
2508  fprintf (fp,"\n");
2509  fprintf (fp,"#\n");
2510  fprintf (fp,"# if YUV format (or using parallel version), must provide width and height\n");
2511  fprintf (fp,"# YUV_SIZE       widthxheight\n");
2512  fprintf (fp,"# this option is ignored if BASE_FILE_FORMAT is not YUV and you're running\n");
2513  fprintf (fp,"# on just one machine\n");
2514  fprintf (fp,"#\n");
2515  fprintf (fp,"YUV_SIZE 352x240\n");
2516  fprintf (fp,"\n");
2517  fprintf (fp,"# If you are using YUV, there are different supported file formats.\n");
2518  fprintf (fp,"# EYUV or UCB are the same as previous versions of this encoder.\n");
2519  fprintf (fp,"# (All the Y's, then U's then V's, in 4:2:0 subsampling.)\n");
2520  fprintf (fp,"# Other formats, such as Abekas, Phillips, or a general format are\n");
2521  fprintf (fp,"# permissible, the general format is a string of Y's, U's, and V's\n");
2522  fprintf (fp,"# to specify the file order.\n");
2523  fprintf (fp,"\n");
2524  fprintf (fp,"INPUT_FORMAT UCB\n");
2525  fprintf (fp,"\n");
2526  fprintf (fp,"# the conversion statement\n");
2527  fprintf (fp,"#\n");
2528  fprintf (fp,"# Each occurrence of '*' will be replaced by the input file\n");
2529  fprintf (fp,"#\n");
2530  fprintf (fp,"# e.g., if you have a bunch of GIF files, then this might be:\n");
2531  fprintf (fp,"#        INPUT_CONVERT   giftoppm *\n");
2532  fprintf (fp,"#\n");
2533  fprintf (fp,"# e.g., if you have a bunch of files like a.Y a.U a.V, etc., then:\n");
2534  fprintf (fp,"#        INPUT_CONVERT   cat *.Y *.U *.V\n");
2535  fprintf (fp,"#\n");
2536  fprintf (fp,"# e.g., if you are grabbing from laser disc you might have something like\n");
2537  fprintf (fp,"#        INPUT_CONVERT   goto frame *; grabppm\n");
2538  fprintf (fp,"# 'INPUT_CONVERT *' means the files are already in the base file format\n");
2539  fprintf (fp,"#\n");
2540  fprintf (fp,"INPUT_CONVERT    * \n");
2541  fprintf (fp,"\n");
2542  fprintf (fp,"# number of frames in a GOP.\n");
2543  fprintf (fp,"#\n");
2544  fprintf (fp,"# since each GOP must have at least one I-frame, the encoder will find the\n");
2545  fprintf (fp,"# the first I-frame after GOP_SIZE frames to start the next GOP\n");
2546  fprintf (fp,"#\n");
2547  fprintf (fp,"# later, will add more flexible GOP signalling\n");
2548  fprintf (fp,"#\n");
2549  fprintf (fp,"GOP_SIZE 16\n");
2550  fprintf (fp,"\n");
2551  fprintf (fp,"# number of slices in a frame\n");
2552  fprintf (fp,"#\n");
2553  fprintf (fp,"# 1 is a good number.  another possibility is the number of macroblock rows\n");
2554  fprintf (fp,"# (which is the height divided by 16)\n");
2555  fprintf (fp,"#\n");
2556  fprintf (fp,"SLICES_PER_FRAME 1\n");
2557  fprintf (fp,"\n");
2558  fprintf (fp,"# directory to get all input files from (makes this file easier to read)\n");
[740]2559#if QT_VERSION < 0x040000
2560  fprintf (fp,"INPUT_DIR        %s\n",fMovieTempFolderPath.ascii());
2561#else
2562  fprintf (fp,"INPUT_DIR        %s\n",fMovieTempFolderPath.toStdString().c_str());
2563#endif
[723]2564  fprintf (fp,"\n");
2565  fprintf (fp,"# There are a bunch of ways to specify the input files.\n");
2566  fprintf (fp,"# from a simple one-per-line listing, to the following \n");
2567  fprintf (fp,"# way of numbering them.  See the manual for more information.\n");
2568  fprintf (fp,"INPUT\n");
2569  fprintf (fp,"# '*' is replaced by the numbers 01, 02, 03, 04\n");
2570  fprintf (fp,"# if I instead do [01-11], it would be 01, 02, ..., 09, 10, 11\n");
2571  fprintf (fp,"# if I instead do [1-11], it would be 1, 2, 3, ..., 9, 10, 11\n");
2572  fprintf (fp,"# if I instead do [1-11+3], it would be 1, 4, 7, 10\n");
2573  fprintf (fp,"# the program assumes none of your input files has a name ending in ']'\n");
2574  fprintf (fp,"# if you do, too bad!!!\n");
2575  fprintf (fp,"#\n");
2576  fprintf (fp,"#\n");
2577  fprintf (fp,"Test*.ppm        [0-%d]\n",fRecordFrameNumber);
2578  fprintf (fp,"# can have more files here if you want...there is no limit on the number\n");
2579  fprintf (fp,"# of files\n");
2580  fprintf (fp,"END_INPUT\n");
2581  fprintf (fp,"\n");
2582  fprintf (fp,"\n");
2583  fprintf (fp,"\n");
2584  fprintf (fp,"# Many of the remaining options have to do with the motion search and qscale\n");
2585  fprintf (fp,"\n");
2586  fprintf (fp,"# FULL or HALF -- must be upper case\n");
2587  fprintf (fp,"# Should be FULL for computer generated images\n");
2588  fprintf (fp,"PIXEL            FULL\n");
2589  fprintf (fp,"\n");
2590  fprintf (fp,"# means +/- this many pixels for both P and B frame searches\n");
2591  fprintf (fp,"# specify two numbers if you wish to serc different ranges in the two.\n");
2592  fprintf (fp,"RANGE            10\n");
2593  fprintf (fp,"\n");
2594  fprintf (fp,"# The two search algorithm parameters below mostly affect speed,\n");
2595  fprintf (fp,"# with some affect on compression and almost none on quality.\n");
2596  fprintf (fp,"\n");
2597  fprintf (fp,"# this must be one of {EXHAUSTIVE, SUBSAMPLE, LOGARITHMIC}\n");
2598  fprintf (fp,"PSEARCH_ALG      LOGARITHMIC\n");
2599  fprintf (fp,"\n");
2600  fprintf (fp,"# this must be one of {SIMPLE, CROSS2, EXHAUSTIVE}\n");
2601  fprintf (fp,"#\n");
2602  fprintf (fp,"# note that EXHAUSTIVE is really, really, really slow\n");
2603  fprintf (fp,"#\n");
2604  fprintf (fp,"BSEARCH_ALG      SIMPLE\n");
2605  fprintf (fp,"\n");
2606  fprintf (fp,"#\n");
2607  fprintf (fp,"# these specify the q-scale for I, P, and B frames\n");
2608  fprintf (fp,"# (values must be between 1 and 31)\n");
2609  fprintf (fp,"# These are the Qscale values for the entire frame in variable bit-rate\n");
2610  fprintf (fp,"# mode, and starting points (but not important) for constant bit rate\n");
2611  fprintf (fp,"#\n");
2612  fprintf (fp,"\n");
2613  fprintf (fp,"# Qscale (Quantization scale) affects quality and compression,\n");
2614  fprintf (fp,"# but has very little effect on speed.\n");
2615  fprintf (fp,"\n");
2616  fprintf (fp,"IQSCALE          4\n");
2617  fprintf (fp,"PQSCALE          5\n");
2618  fprintf (fp,"BQSCALE          12\n");
2619  fprintf (fp,"\n");
2620  fprintf (fp,"# this must be ORIGINAL or DECODED\n");
2621  fprintf (fp,"REFERENCE_FRAME  ORIGINAL\n");
2622  fprintf (fp,"\n");
2623  fprintf (fp,"# for parallel parameters see parallel.param in the exmaples subdirectory\n");
2624  fprintf (fp,"\n");
2625  fprintf (fp,"# if you want constant bit-rate mode, specify it as follows (number is bits/sec):\n");
2626  fprintf (fp,"#BIT_RATE  1000000\n");
2627  fprintf (fp,"\n");
2628  fprintf (fp,"# To specify the buffer size (327680 is default, measused in bits, for 16bit words)\n");
2629  fprintf (fp,"BUFFER_SIZE 327680\n");
2630  fprintf (fp,"\n");
2631  fprintf (fp,"# The frame rate is the number of frames/second (legal values:\n");
2632  fprintf (fp,"# 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60\n");
2633  fprintf (fp,"FRAME_RATE 30\n");
2634  fprintf (fp,"\n");
2635  fprintf (fp,"# There are many more options, see the users manual for examples....\n");
2636  fprintf (fp,"# ASPECT_RATIO, USER_DATA, GAMMA, IQTABLE, etc.\n");
2637  fprintf (fp,"\n");
2638  fprintf (fp,"\n");
2639  fclose (fp);
2640
[747]2641  setRecordingInfos("Parameter file "+fParameterFileName+" generated in "+fMovieTempFolderPath);
[748]2642  setRecordingStatus(READY_TO_ENCODE);
[723]2643  return true;
2644}
2645
[749]2646void G4OpenGLQtViewer::encodeVideo()
[740]2647{
[747]2648  if ((getEncoderPath() != "") && (getSaveFileName() != "")) {
[749]2649    fProcess = new QProcess();
2650    fProcess->execute (fEncoderPath, QStringList(fMovieTempFolderPath+fParameterFileName));
2651  QObject ::connect(fProcess,
2652                    SIGNAL(finished ( int exitCode, QProcess::ExitStatus exitStatus )),
2653                    this,
2654                    SLOT(processFinished( int exitCode, QProcess::ExitStatus exitStatus ));
2655  }
2656}
[740]2657
[747]2658      setRecordingStatus(WAIT);
2659      setRecordingInfos(removeTempFolder());
[740]2660
[588]2661/*
[696]2662 
[588]2663void MultiLayer::exportToSVG(const QString& fname)
2664{
2665  QPicture picture;
2666  QPainter p(&picture);
2667  for (int i=0;i<(int)graphsList->count();i++)
2668    {
2669      Graph *gr=(Graph *)graphsList->at(i);
2670      Plot *myPlot= (Plot *)gr->plotWidget();
2671     
2672      QPoint pos=gr->pos();
2673     
2674      int width=int(myPlot->frameGeometry().width());
2675      int height=int(myPlot->frameGeometry().height());
2676     
2677      myPlot->print(&p, QRect(pos,QSize(width,height)));
2678    }
2679 
2680  p.end();
2681  picture.save(fname, "svg");
2682}
2683*/
[707]2684#endif
Note: See TracBrowser for help on using the repository browser.