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

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

video avec de vector:en test

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