Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh	(revision 722)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh	(revision 723)
@@ -98,4 +98,8 @@
   QDialog* GLWindow;
   bool hasPendingEvents();
+  void saveForVideo(QString);
+  bool saveVideo(QString);
+  bool fRecordFrames;
+  int fRecordFrameNumber;
 
 private:
@@ -142,4 +146,5 @@
   QAction *fDrawingLineSurfaceRemoval;
 
+
 private slots :
   void actionMouseRotate();
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc	(revision 722)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc	(revision 723)
@@ -55,4 +55,5 @@
 #include <qlayout.h>
 #include <qdialog.h>
+#include <qprocess.h>
 
 #if QT_VERSION >= 0x040000
@@ -286,4 +287,6 @@
   ,G4OpenGLViewer (scene)
   ,fWindow(0)
+  ,fRecordFrames(false)
+  ,fRecordFrameNumber(0)
   ,fContextMenu(0)
   ,fMouseAction(STYLE1)
@@ -981,4 +984,7 @@
     G4cout << "Press SHIFT+up/down arrows to rotate volume up/down\n" << G4endl;
     G4cout << "Press ALT+/- to slow/speed auto rotation/move\n" << G4endl;
+    G4cout << "In video mode : \n" << G4endl;
+    G4cout << "  Press SPACE to Start/Pause video recording \n" << G4endl;
+    G4cout << "  Press RETURN to Stop video recording \n" << G4endl;
   } else  if (fMouseAction == STYLE2) { //move
     G4cout << "Move camera point of view with mouse\n" << G4endl;
@@ -990,4 +996,7 @@
     G4cout << "Press +/- to zoom into volume\n" << G4endl;
     G4cout << "Press ALT+/- to slow/speed auto rotation/move\n" << G4endl;
+    G4cout << "In video mode : \n" << G4endl;
+    G4cout << "  Press SPACE to Start/Pause video recording \n" << G4endl;
+    G4cout << "  Press RETURN to Stop video recording \n" << G4endl;
   } else  if (fMouseAction == STYLE3) { //pick
     G4cout << "Click and pick \n" << G4endl;
@@ -1265,4 +1274,31 @@
   }
 }
+
+
+void G4OpenGLQtViewer::saveForVideo(QString nomFich) {
+  if (nomFich == "") {
+    return;
+  }
+  nomFich += "."+QString("ppm");
+  QImage image;
+  image = fWindow->grabFrameBuffer();
+  bool res = false;
+  
+#if QT_VERSION < 0x040000
+  res = image.save(nomFich,"ppm");
+#else
+  res = image.save(nomFich,0);
+#endif
+  if (res == false) {
+#if QT_VERSION < 0x040000
+    G4cerr << "Error while saving file... "<<nomFich.ascii()<<"\n" << G4endl;
+#else
+    G4cerr << "Error while saving file... "<<nomFich.toStdString().c_str()<<"\n" << G4endl;
+#endif
+    fRecordFrames = false;
+  }
+}
+
+
 
 void G4OpenGLQtViewer::actionCreateEPS() {
@@ -1479,7 +1515,7 @@
 #ifdef GEANT4_QT_DEBUG
   if (mButtons & Qt::LeftButton) {
-    printf("                  end of  mouse move event %d %d delta:%d %d\n",pos_x,pos_y,fDeltaPosX,fDeltaPosY);
-  } else {
-    printf("                  end of  mouse move event %d %d delta:%d %d --------------NO BUTTON\n",pos_x,pos_y,fDeltaPosX,fDeltaPosY);
+    printf("                  end of  mouse move event %d %d delta:%f %f\n",pos_x,pos_y,fDeltaPosX,fDeltaPosY);
+  } else {
+    printf("                  end of  mouse move event %d %d delta:%f %f --------------NO BUTTON\n",pos_x,pos_y,fDeltaPosX,fDeltaPosY);
   }
 #endif
@@ -1955,4 +1991,12 @@
   }
 
+  if ((event->key() == Qt::Key_Return) || (event->key() == Qt::Key_Enter)){ // end of video
+    fRecordFrames = false;
+    saveVideo("/temp/output.mpg");
+  }
+  if (event->key() == Qt::Key_Space){ // start/pause of video
+    fRecordFrames = !fRecordFrames;
+  }
+
   // with no modifiers
 #if QT_VERSION < 0x040000
@@ -1982,4 +2026,190 @@
 }
 
+bool G4OpenGLQtViewer::saveVideo (QString outputName) {
+
+  // save the parameter file
+  FILE* fp;
+  fp = fopen ("/temp/parameter_file.par", "w");
+
+  if (fp == NULL) {
+    return false;
+  }
+
+  fprintf (fp,"# parameter file template with lots of comments to assist you\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"# you can use this as a template, copying it to a separate file then modifying\n");
+  fprintf (fp,"# the copy\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"# any line beginning with '#' is a comment\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"# no line should be longer than 255 characters\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"# general format of each line is:\n");
+  fprintf (fp,"#	  \n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"# lines can generally be in any order\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"# an exception is the option 'INPUT' which must be followed by input\n");
+  fprintf (fp,"# files in the order in which they must appear, followed by 'END_INPUT'\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"# Also, if you use the `command` method of generating input file names,\n");
+  fprintf (fp,"# the command will only be executed in the INPUT_DIR if INPUT_DIR preceeds\n");
+  fprintf (fp,"# the INPUT parameter.\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"#  MUST be in UPPER CASE\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# Pattern affects speed, quality and compression. See the User's Guide\n");
+  fprintf (fp,"# for more info.\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"PATTERN		IBBPBBPBBPBBPBBP\n");
+#if QT_VERSION < 0x040000
+  fprintf (fp,"OUTPUT		%s\n",outputName.ascii());
+#else
+  fprintf (fp,"OUTPUT		%s\n",outputName.toStdString().c_str());
+#endif
+  fprintf (fp,"\n");
+  fprintf (fp,"# mpeg_encode really only accepts 3 different file formats, but using a\n");
+  fprintf (fp,"# conversion statement it can effectively handle ANY file format\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"# You must specify the type of the input files.  The choices are:\n");
+  fprintf (fp,"#    YUV, PPM, JMOVIE, Y, JPEG, PNM\n");
+  fprintf (fp,"#	(must be upper case)\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"BASE_FILE_FORMAT	PPM\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"# if YUV format (or using parallel version), must provide width and height\n");
+  fprintf (fp,"# YUV_SIZE	widthxheight\n");
+  fprintf (fp,"# this option is ignored if BASE_FILE_FORMAT is not YUV and you're running\n");
+  fprintf (fp,"# on just one machine\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"YUV_SIZE	352x240\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# If you are using YUV, there are different supported file formats.\n");
+  fprintf (fp,"# EYUV or UCB are the same as previous versions of this encoder.\n");
+  fprintf (fp,"# (All the Y's, then U's then V's, in 4:2:0 subsampling.)\n");
+  fprintf (fp,"# Other formats, such as Abekas, Phillips, or a general format are\n");
+  fprintf (fp,"# permissible, the general format is a string of Y's, U's, and V's\n");
+  fprintf (fp,"# to specify the file order.\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"INPUT_FORMAT UCB\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# the conversion statement\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"# Each occurrence of '*' will be replaced by the input file\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"# e.g., if you have a bunch of GIF files, then this might be:\n");
+  fprintf (fp,"#	INPUT_CONVERT	giftoppm *\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"# e.g., if you have a bunch of files like a.Y a.U a.V, etc., then:\n");
+  fprintf (fp,"#	INPUT_CONVERT	cat *.Y *.U *.V\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"# e.g., if you are grabbing from laser disc you might have something like\n");
+  fprintf (fp,"#	INPUT_CONVERT	goto frame *; grabppm\n");
+  fprintf (fp,"# 'INPUT_CONVERT *' means the files are already in the base file format\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"INPUT_CONVERT	* \n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# number of frames in a GOP.\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"# since each GOP must have at least one I-frame, the encoder will find the\n");
+  fprintf (fp,"# the first I-frame after GOP_SIZE frames to start the next GOP\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"# later, will add more flexible GOP signalling\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"GOP_SIZE	16\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# number of slices in a frame\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"# 1 is a good number.  another possibility is the number of macroblock rows\n");
+  fprintf (fp,"# (which is the height divided by 16)\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"SLICES_PER_FRAME	1\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# directory to get all input files from (makes this file easier to read)\n");
+  fprintf (fp,"INPUT_DIR	/temp\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# There are a bunch of ways to specify the input files.\n");
+  fprintf (fp,"# from a simple one-per-line listing, to the following \n");
+  fprintf (fp,"# way of numbering them.  See the manual for more information.\n");
+  fprintf (fp,"INPUT\n");
+  fprintf (fp,"# '*' is replaced by the numbers 01, 02, 03, 04\n");
+  fprintf (fp,"# if I instead do [01-11], it would be 01, 02, ..., 09, 10, 11\n");
+  fprintf (fp,"# if I instead do [1-11], it would be 1, 2, 3, ..., 9, 10, 11\n");
+  fprintf (fp,"# if I instead do [1-11+3], it would be 1, 4, 7, 10\n");
+  fprintf (fp,"# the program assumes none of your input files has a name ending in ']'\n");
+  fprintf (fp,"# if you do, too bad!!!\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"Test*.ppm	[0-%d]\n",fRecordFrameNumber);
+  fprintf (fp,"# can have more files here if you want...there is no limit on the number\n");
+  fprintf (fp,"# of files\n");
+  fprintf (fp,"END_INPUT\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# Many of the remaining options have to do with the motion search and qscale\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# FULL or HALF -- must be upper case\n");
+  fprintf (fp,"# Should be FULL for computer generated images\n");
+  fprintf (fp,"PIXEL		FULL\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# means +/- this many pixels for both P and B frame searches\n");
+  fprintf (fp,"# specify two numbers if you wish to serc different ranges in the two.\n");
+  fprintf (fp,"RANGE		10\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# The two search algorithm parameters below mostly affect speed,\n");
+  fprintf (fp,"# with some affect on compression and almost none on quality.\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# this must be one of {EXHAUSTIVE, SUBSAMPLE, LOGARITHMIC}\n");
+  fprintf (fp,"PSEARCH_ALG	LOGARITHMIC\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# this must be one of {SIMPLE, CROSS2, EXHAUSTIVE}\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"# note that EXHAUSTIVE is really, really, really slow\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"BSEARCH_ALG	SIMPLE\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"# these specify the q-scale for I, P, and B frames\n");
+  fprintf (fp,"# (values must be between 1 and 31)\n");
+  fprintf (fp,"# These are the Qscale values for the entire frame in variable bit-rate\n");
+  fprintf (fp,"# mode, and starting points (but not important) for constant bit rate\n");
+  fprintf (fp,"#\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# Qscale (Quantization scale) affects quality and compression,\n");
+  fprintf (fp,"# but has very little effect on speed.\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"IQSCALE		4\n");
+  fprintf (fp,"PQSCALE		5\n");
+  fprintf (fp,"BQSCALE		12\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# this must be ORIGINAL or DECODED\n");
+  fprintf (fp,"REFERENCE_FRAME	ORIGINAL\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# for parallel parameters see parallel.param in the exmaples subdirectory\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# if you want constant bit-rate mode, specify it as follows (number is bits/sec):\n");
+  fprintf (fp,"#BIT_RATE  1000000\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# To specify the buffer size (327680 is default, measused in bits, for 16bit words)\n");
+  fprintf (fp,"BUFFER_SIZE 327680\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# The frame rate is the number of frames/second (legal values:\n");
+  fprintf (fp,"# 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60\n");
+  fprintf (fp,"FRAME_RATE 30\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"# There are many more options, see the users manual for examples....\n");
+  fprintf (fp,"# ASPECT_RATIO, USER_DATA, GAMMA, IQTABLE, etc.\n");
+  fprintf (fp,"\n");
+  fprintf (fp,"\n");
+  fclose (fp);
+
+  QProcess::execute ("/sw/bin/mpeg_encode", QStringList("/temp/parameter_file.par"));
+  return true;
+}
 
 /*
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc	(revision 722)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc	(revision 723)
@@ -252,5 +252,4 @@
 void G4OpenGLStoredQtViewer::paintGL()
 {
-     
   if (!readyToPaint) {
 #ifdef GEANT4_QT_DEBUG
@@ -293,4 +292,11 @@
   DrawView();
      
+  if (fRecordFrames) {
+    saveForVideo(QString("/temp/Test")+QString::number(fRecordFrameNumber));
+    fRecordFrameNumber++;
+#ifdef GEANT4_QT_DEBUG
+    printf("G4OpenGLStoredQtViewer::record frame %d\n",fRecordFrameNumber);
+#endif
+  }
   hasToRepaint =false;
      
