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

Last change on this file since 739 was 739, checked in by garnier, 17 years ago

debut de merge en cours NE COMPILE PAS

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