source: trunk/source/visualization/OpenGL/src/G4OpenGLQtViewer.cc @ 1305

Last change on this file since 1305 was 1274, checked in by garnier, 14 years ago

update...

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