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

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

remise a niveau de movie parameters

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