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

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

test

  • Property svn:mime-type set to text/cpp
File size: 70.5 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 
[725]1287  nomFich += "."+QString("ppm");
[723]1288#if QT_VERSION < 0x040000
[725]1289  res = image.save(nomFich,"ppm");
[723]1290#else
[725]1291  res = image.save(nomFich,0);
[723]1292#endif
[725]1293  if (res == false) {
[723]1294#if QT_VERSION < 0x040000
[725]1295    G4cerr << "Error while saving file... "<<nomFich.ascii()<<"\n" << G4endl;
[723]1296#else
[725]1297    G4cerr << "Error while saving file... "<<nomFich.toStdString().c_str()<<"\n" << G4endl;
[723]1298#endif
[725]1299    fRecordFrames = false;
[723]1300  }
[725]1301
1302#if QT_VERSION < 0x040000
1303  printf("SaveForVideo ^^^^^^^^^^^^^^^^^^^^^^^^ %s\n",nomFich.ascii());
1304#else
1305  printf("SaveForVideo ^^^^^^^^^^^^^^^^^^^^^^^^ %s\n",nomFich.toStdString().c_str());
1306#endif
[723]1307}
1308
1309
1310
[565]1311void G4OpenGLQtViewer::actionCreateEPS() {
[580]1312  QString filters;
[600]1313#if QT_VERSION < 0x040000
1314  QStrList listFormat=QImageIO::outputFormats();
1315  char *tmp=listFormat.first();
1316  while (tmp!=0) {
1317    filters += QString(tmp) + ";;";
1318    tmp=listFormat.next();
1319  }
1320#else
[580]1321  QList<QByteArray> formats =  QImageWriter::supportedImageFormats ();
1322  for (int i = 0; i < formats.size(); ++i) {
[600]1323    filters +=formats.at(i) + ";;";
[580]1324  }
[600]1325#endif
[588]1326  filters += "eps;;";
1327  filters += "ps;;";
1328  filters += "pdf";
[639]1329  QString* selectedFormat = new QString();
[600]1330#if QT_VERSION < 0x040000
1331  QString nomFich =  QFileDialog::getSaveFileName ( ".",
1332                                                    filters,
1333                                                    GLWindow,
1334                                                    "Save file dialog",
1335                                                    tr("Save as ..."),
[639]1336                                                    selectedFormat );
[600]1337#else
[580]1338  QString nomFich =  QFileDialog::getSaveFileName ( GLWindow,
1339                                                    tr("Save as ..."),
1340                                                    ".",
[582]1341                                                    filters,
[639]1342                                                    selectedFormat );
[600]1343#endif
[580]1344  // bmp jpg jpeg png ppm xbm xpm
[582]1345  if (nomFich == "") {
1346    return;
1347  }
[600]1348#if QT_VERSION < 0x040000
[639]1349  nomFich += "."+QString(selectedFormat->ascii());
1350  QString format = selectedFormat->lower();
[600]1351#else
[639]1352  nomFich += "."+QString(selectedFormat->toStdString().c_str());
1353  QString format = selectedFormat->toLower();
[600]1354#endif
[656]1355  G4OpenGLQtExportDialog* exportDialog= new G4OpenGLQtExportDialog(GLWindow,format,fWindow->height(),fWindow->width());
[585]1356  if(  exportDialog->exec()) {
[593]1357
1358    QImage image;
[655]1359    bool res = false;
[635]1360    if ((exportDialog->getWidth() !=fWindow->width()) ||
1361        (exportDialog->getHeight() !=fWindow->height())) {
[655]1362      if (format != QString("eps")) {
[638]1363      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]1364     
[635]1365      //    rescaleImage(exportDialog->getWidth(),exportDialog->getHeight());// re-scale image
1366      //      QGLWidget* glResized = fWindow;
1367
1368      // FIXME :
1369      // L.Garnier : I've try to implement change size function, but the problem is
1370      // the renderPixmap function call the QGLWidget to resize and it doesn't draw
1371      // the content of this widget... It only draw the background.
1372
1373      //      fWindow->renderPixmap (exportDialog->getWidth()*2,exportDialog->getHeight()*2,true );
1374
1375      //      QPixmap pixmap = fWindow->renderPixmap ();
1376     
1377      //      image = pixmap->toImage();
[593]1378      //      glResized->resize(exportDialog->getWidth()*2,exportDialog->getHeight()*2);
1379      //      image = glResized->grabFrameBuffer();
[655]1380      }     
[635]1381    } else {
1382      image = fWindow->grabFrameBuffer();
1383    }   
[639]1384    if (format == QString("eps")) {
[652]1385      if (exportDialog->getVectorEPS()) {
[655]1386        res = generateVectorEPS(nomFich,exportDialog->getWidth(),exportDialog->getHeight(),image);
[652]1387      } else {
[655]1388        res = generateEPS(nomFich,exportDialog->getNbColor(),image);
[652]1389      }
[639]1390    } else if ((format == "ps") || (format == "pdf")) {
[655]1391      res = generatePS_PDF(nomFich,exportDialog->getNbColor(),image);
1392    } else if ((format == "tif") ||
1393               (format == "tiff") ||
1394               (format == "jpg") ||
1395               (format == "jpeg") ||
1396               (format == "png") ||
1397               (format == "pbm") ||
1398               (format == "pgm") ||
1399               (format == "ppm") ||
1400               (format == "bmp") ||
1401               (format == "xbm") ||
1402               (format == "xpm")) {
[639]1403#if QT_VERSION < 0x040000
[655]1404      res = image.save(nomFich,selectedFormat->ascii(),exportDialog->getSliderValue());
[639]1405#else
[655]1406      res = image.save(nomFich,0,exportDialog->getSliderValue());
[639]1407#endif
[585]1408    } else {
[638]1409      G4cerr << "This version of G4UI Could not generate the selected format\n" << G4endl;
[585]1410    }
[655]1411    if (res == false) {
1412#if QT_VERSION < 0x040000
1413      G4cerr << "Error while saving file... "<<nomFich.ascii()<<"\n" << G4endl;
1414#else
1415      G4cerr << "Error while saving file... "<<nomFich.toStdString().c_str()<<"\n" << G4endl;
1416#endif
1417    } else {
1418#if QT_VERSION < 0x040000
[656]1419      G4cout << "File "<<nomFich.ascii()<<" has been saved \n" << G4endl;
[655]1420#else
[656]1421      G4cout << "File "<<nomFich.toStdString().c_str()<<" has been saved \n" << G4endl;
[655]1422#endif
1423    }
[585]1424   
1425  } else { // cancel selected
1426    return;
[568]1427  }
[580]1428 
[608]1429#ifdef GEANT4_QT_DEBUG
[565]1430  printf("G4OpenGLQtViewer::actionCreateEPS() \n");
[608]1431#endif
[565]1432}
1433
[580]1434/*
1435// 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]1436
[580]1437void Graph::exportToSVG(const QString& fname)
1438{
1439  // enable workaround for Qt3 misalignments
1440  QwtPainter::setSVGMode(true);
1441  QPicture picture;
1442  QPainter p(&picture);
1443  d_plot->print(&p, d_plot->rect());
1444  p.end();
[565]1445
[580]1446  picture.save(fname, "svg");
1447}
1448*/
1449
1450
1451
1452
[564]1453/**
1454   Save the current mouse press point
1455   @param p mouse click point
1456*/
[720]1457#if QT_VERSION < 0x040000
1458void G4OpenGLQtViewer::G4MousePressEvent(QPoint p,Qt::ButtonState mButtons)
1459#else
1460void G4OpenGLQtViewer::G4MousePressEvent(QPoint p,Qt::MouseButtons mButtons)
1461#endif
[564]1462{
[720]1463  fAutoMove = false; // stop automove
[696]1464  fLastPos = p;
[707]1465  if (fMouseAction == STYLE2){  // pick
[681]1466    Pick(p.x(),p.y());
1467  }
[564]1468}
1469
[696]1470
[564]1471/**
1472   @param pos_x mouse x position
1473   @param pos_y mouse y position
1474   @param mButtons mouse button active
[720]1475   @param mAutoMove true: apply this move till another evnt came, false :one time move
[564]1476*/
[599]1477
1478#if QT_VERSION < 0x040000
[720]1479void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::ButtonState mButtons,bool mAutoMove)
[599]1480#else
[720]1481  void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons,bool mAutoMove)
[599]1482#endif
[564]1483{
[720]1484  fAutoMove = mAutoMove;
1485#ifdef GEANT4_QT_DEBUG
1486  printf("                   mouse move event %d %d\n",pos_x,pos_y);
1487#endif
[713]1488
[720]1489  if (!fAutoMove) {  // keep old delta if automove
[721]1490    fDeltaPosX = fLastPos.x() - pos_x;
1491    fDeltaPosY = fLastPos.y() - pos_y;
[720]1492  }
[713]1493
[721]1494  if ((fDeltaPosX == 0) && (fDeltaPosY == 0)) {
[720]1495    fAutoMove = false;
1496  }
[713]1497
[696]1498  if (fMouseAction == STYLE1) {  // rotate
[564]1499    if (mButtons & Qt::LeftButton) {
[724]1500      rotateScene(fDeltaPosX,fDeltaPosY,fAutoMove);
[564]1501    }
[713]1502  } else if (fMouseAction == STYLE2) {  // move
1503    if (mButtons & Qt::LeftButton) {
[720]1504      if (fAutoMove) {
1505        while (fAutoMove) {
[724]1506          moveScene(-fDeltaPosX,-fDeltaPosY,0,true,true);
[722]1507          ((QApplication*)G4Qt::getInstance ())->processEvents();
[720]1508        }
1509      } else {
[724]1510        moveScene(-fDeltaPosX,-fDeltaPosY,0,true,false);
[713]1511      }
1512    }
[564]1513  }
[696]1514  fLastPos = QPoint(pos_x, pos_y);
[720]1515#ifdef GEANT4_QT_DEBUG
1516  if (mButtons & Qt::LeftButton) {
[723]1517    printf("                  end of  mouse move event %d %d delta:%f %f\n",pos_x,pos_y,fDeltaPosX,fDeltaPosY);
[720]1518  } else {
[723]1519    printf("                  end of  mouse move event %d %d delta:%f %f --------------NO BUTTON\n",pos_x,pos_y,fDeltaPosX,fDeltaPosY);
[720]1520  }
1521#endif
[564]1522}
1523
[720]1524
[696]1525/**
[711]1526   Move the scene of dx, dy, dz values.
[696]1527   @param dx delta mouse x position
1528   @param dy delta mouse y position
[720]1529   @param mouseMove : true if even comes froma mouse move, false if even comes from key action
[696]1530*/
1531
[724]1532void G4OpenGLQtViewer::moveScene(G4double dx,G4double dy, G4double dz,bool mouseMove,bool mAutoMove)
[696]1533{
[724]1534  if( mAutoMove == false) {
1535    fAutoMove = true;
1536  }
[720]1537  G4double coefTrans = 0;
1538  GLdouble coefDepth = 0;
[724]1539  while (fAutoMove) {
1540    if( mAutoMove == false) {
1541      fAutoMove = false;
[720]1542    }
[724]1543    if(mouseMove) {
1544      coefTrans = ((G4double)getSceneNearWidth())/((G4double)WinSize_x);
1545      if (WinSize_y <WinSize_x) {
1546        coefTrans = ((G4double)getSceneNearWidth())/((G4double)WinSize_y);
1547      }
1548    } else {
1549      coefTrans = getSceneNearWidth()*fDeltaSceneTranslation;
1550      coefDepth = getSceneDepth()*fDeltaDepth;
1551    }
1552    fVP.IncrementPan(-dx*coefTrans,dy*coefTrans,dz*coefDepth);
1553   
1554    updateQWidget();
1555    ((QApplication*)G4Qt::getInstance ())->processEvents();
[720]1556  }
[696]1557}
1558
1559
1560/**
1561   @param dx delta mouse x position
1562   @param dy delta mouse y position
1563*/
1564
[724]1565void G4OpenGLQtViewer::rotateScene(G4double dx, G4double dy,bool mAutoRotate)
[696]1566{
[724]1567  if( mAutoRotate == false) {
1568    fAutoMove = true;
1569  }
[713]1570  dx = dx * fDeltaRotation;
1571  dy = dy * fDeltaRotation;
[724]1572  G4Vector3D vp;
1573  G4Vector3D up;
[696]1574 
[724]1575  G4Vector3D xprime;
1576  G4Vector3D yprime;
1577  G4Vector3D zprime;
[696]1578 
1579  G4double delta_alpha;
1580  G4double delta_theta;
1581 
[724]1582  G4Vector3D new_vp;
1583  G4Vector3D new_up;
[696]1584 
[724]1585  G4double cosalpha;
1586  G4double sinalpha;
[696]1587 
[724]1588  G4Vector3D a1;
1589  G4Vector3D a2;
1590  G4Vector3D delta;
1591  G4Vector3D viewPoint;
1592
1593  while (fAutoMove) {
1594    if( mAutoRotate == false) {
1595      fAutoMove = false;
1596    }
1597   
1598    //phi spin stuff here
[696]1599 
[724]1600    vp = fVP.GetViewpointDirection ().unit ();
1601    up = fVP.GetUpVector ().unit ();
[696]1602 
[724]1603    yprime = (up.cross(vp)).unit();
1604    zprime = (vp.cross(yprime)).unit();
[696]1605 
[724]1606    if (fVP.GetLightsMoveWithCamera()) {
1607      delta_alpha = dy;
1608      delta_theta = -dx;
1609    } else {
1610      delta_alpha = -dy;
1611      delta_theta = dx;
1612    }   
[696]1613 
[724]1614    delta_alpha *= deg;
1615    delta_theta *= deg;
1616 
1617    new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime;
1618 
1619    if (fVP.GetLightsMoveWithCamera()) {
1620      new_up = (new_vp.cross(yprime)).unit();
1621      fVP.SetUpVector(new_up);
1622    } else {
1623      new_up = up;
1624    }
1625    ////////////////
1626    // Rotates by fixed azimuthal angle delta_theta.
1627   
1628    cosalpha = new_up.dot (new_vp.unit());
1629    sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));
1630    yprime = (new_up.cross (new_vp.unit())).unit ();
1631    xprime = yprime.cross (new_up);
1632    // Projection of vp on plane perpendicular to up...
1633    a1 = sinalpha * xprime;
1634    // Required new projection...
1635    a2 = sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);
1636    // Required Increment vector...
1637    delta = a2 - a1;
1638    // So new viewpoint is...
1639    viewPoint = new_vp.unit() + delta;
1640   
1641    fVP.SetViewAndLights (viewPoint);
1642    updateQWidget();
1643   
1644    ((QApplication*)G4Qt::getInstance ())->processEvents();
1645  }
[696]1646}
1647
[660]1648/** This is the benning of a rescale function. It does nothing for the moment
1649    @param aWidth : new width
1650    @param aHeight : new height
1651*/
[585]1652void G4OpenGLQtViewer::rescaleImage(
1653 int aWidth
1654,int aHeight
1655){
[608]1656#ifdef GEANT4_QT_DEBUG
[586]1657  printf("should rescale \n");
[608]1658#endif
[660]1659  GLfloat* feedback_buffer;
1660  GLint returned;
1661  FILE* file;
1662 
[673]1663//   feedback_buffer = new GLfloat[size];
1664//   glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer);
1665//   glRenderMode (GL_FEEDBACK);
[660]1666 
[673]1667//   glViewport (0, 0, aWidth, aHeight);
1668//   DrawView();
1669//   returned = glRenderMode (GL_RENDER);
[660]1670
[585]1671}
[586]1672
1673/**
[652]1674   Generate Vectorial Encapsulated Postscript form image
[586]1675   @param aFilename : name of file
1676   @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha
1677   @param aImage : Image to print
1678*/
[652]1679bool G4OpenGLQtViewer::generateVectorEPS (
1680 QString aFilename
1681,int aWidth
1682,int aHeight
1683,QImage aImage
1684)
1685{
1686  // Print vectored PostScript
1687 
1688  G4int size = 5000000;
1689
1690  GLfloat* feedback_buffer;
1691  GLint returned;
1692  FILE* file;
1693 
1694  feedback_buffer = new GLfloat[size];
1695  glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer);
1696  glRenderMode (GL_FEEDBACK);
1697 
[709]1698  int side = aWidth;
1699  if (aHeight < aWidth) side = aHeight;
[675]1700  glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side);
[652]1701  DrawView();
1702
1703  returned = glRenderMode (GL_RENDER);
1704 
1705 
1706#if QT_VERSION < 0x040000
1707  file = fopen (aFilename.ascii(), "w");
1708#else
1709  file = fopen (aFilename.toStdString().c_str(), "w");
1710#endif
1711  if (file) {
1712    spewWireframeEPS (file, returned, feedback_buffer, "rendereps");
1713  } else {
[658]1714#if QT_VERSION < 0x040000
[673]1715    G4cerr << "Could not open "<< aFilename.ascii()<<"\n" << G4endl;
[658]1716#else
[673]1717    G4cerr << "Could not open "<< aFilename.toStdString().c_str()<<"\n" << G4endl;
[658]1718#endif
[652]1719  }
1720 
1721  delete[] feedback_buffer;
1722
1723  return true;
1724}
1725
1726/**
1727   Generate Encapsulated Postscript form image
1728   @param aFilename : name of file
1729   @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha
1730   @param aImage : Image to print
1731*/
[588]1732bool G4OpenGLQtViewer::generateEPS (
[586]1733 QString aFilename
1734,int aInColor
1735,QImage aImage
1736)
1737{
[587]1738  // FIXME
[608]1739#ifdef GEANT4_QT_DEBUG
[586]1740  printf("saving EPS\n");
[608]1741#endif
[586]1742
1743  FILE* fp;
[587]1744
[649]1745  if (aImage.bits () == NULL)
[588]1746    return false;
[586]1747 
[600]1748#if QT_VERSION < 0x040000
1749  fp = fopen (aFilename.ascii(), "w");
1750#else
[602]1751  fp = fopen (aFilename.toStdString().c_str(), "w");
[600]1752#endif
[586]1753  if (fp == NULL) {
[588]1754    return false;
[586]1755  }
1756 
1757  fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n");
[600]1758#if QT_VERSION < 0x040000
1759  fprintf (fp, "%%%%Title: %s\n", aFilename.ascii());
1760#else
[602]1761  fprintf (fp, "%%%%Title: %s\n", aFilename.toStdString().c_str());
[600]1762#endif
[586]1763  fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n");
[587]1764  fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", aImage.width(), aImage.height());
[586]1765  fprintf (fp, "%%%%EndComments\n");
1766  fprintf (fp, "gsave\n");
1767  fprintf (fp, "/bwproc {\n");
1768  fprintf (fp, "    rgbproc\n");
1769  fprintf (fp, "    dup length 3 idiv string 0 3 0 \n");
1770  fprintf (fp, "    5 -1 roll {\n");
1771  fprintf (fp, "    add 2 1 roll 1 sub dup 0 eq\n");
1772  fprintf (fp, "    { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n");
1773  fprintf (fp, "       3 1 roll 5 -1 roll } put 1 add 3 0 \n");
1774  fprintf (fp, "    { 2 1 roll } ifelse\n");
1775  fprintf (fp, "    }forall\n");
1776  fprintf (fp, "    pop pop pop\n");
1777  fprintf (fp, "} def\n");
1778  fprintf (fp, "systemdict /colorimage known not {\n");
1779  fprintf (fp, "   /colorimage {\n");
1780  fprintf (fp, "       pop\n");
1781  fprintf (fp, "       pop\n");
1782  fprintf (fp, "       /rgbproc exch def\n");
1783  fprintf (fp, "       { bwproc } image\n");
1784  fprintf (fp, "   }  def\n");
1785  fprintf (fp, "} if\n");
[587]1786  fprintf (fp, "/picstr %d string def\n", aImage.width() * aInColor);
1787  fprintf (fp, "%d %d scale\n", aImage.width(), aImage.height());
1788  fprintf (fp, "%d %d %d\n", aImage.width(), aImage.height(), 8);
1789  fprintf (fp, "[%d 0 0 %d 0 0]\n", aImage.width(), aImage.height());
[586]1790  fprintf (fp, "{currentfile picstr readhexstring pop}\n");
1791  fprintf (fp, "false %d\n", aInColor);
1792  fprintf (fp, "colorimage\n");
1793 
1794
[588]1795  int width = aImage.width();
1796  int height = aImage.height();
1797  int depth = aImage.depth();
1798  int size = width*height;
1799 
1800  if (depth == 1)
1801    size = (width+7)/8*height;
1802  else if (aInColor == 1)
1803    size = size*3;
1804 
1805  int i = 0;
[649]1806  //  if ( aInColor ==1 ) {
1807  // FIXME : L. Garnier. For the moment 10 dec 2007, I could not find a way
1808  // to save correctly grayscale Image. I mean that color or grayscale image
1809  // have the same file save size !
1810 
1811  /* } else*/ if (depth == 8) {
[588]1812    for(int y=height-1; y >=0 ; y--) {
1813      const uchar * s = aImage.scanLine(y);
1814      for(int x=0; x <width; x++) {
1815        QRgb rgb = aImage.color(s[x]);
1816        if (aInColor == 1) {
1817          fprintf (fp, " %02hx ",(unsigned char)qGray(rgb));
1818          i++;
1819        } else {
1820          fprintf (fp, " %02hx %02hx %02hx",
1821                   (unsigned char) qRed(rgb),
1822                   (unsigned char) qGreen(rgb),
1823                   (unsigned char) qBlue(rgb));
1824          i += 3;
1825        }
1826      }
[586]1827      fprintf (fp, "\n");
[588]1828    }
1829  } else {
[601]1830#if QT_VERSION < 0x040000
[649]1831    bool alpha = aImage.hasAlphaBuffer();
[601]1832#else
[588]1833    bool alpha = aImage.hasAlphaChannel();
1834    for(int y=height-1; y >=0 ; y--) {
1835      QRgb * s = (QRgb*)(aImage.scanLine(y));
1836      for(int x=0; x <width; x++) {
1837        QRgb rgb = (*s++);
1838        if (alpha && qAlpha(rgb) < 0x40) // 25% alpha, convert to white -
1839          rgb = qRgb(0xff, 0xff, 0xff);
1840        if (aInColor == 1) {
1841          fprintf (fp, " %02hx ",(unsigned char)qGray(rgb));
1842          i++;
1843        } else {
1844          fprintf (fp, " %02hx %02hx %02hx",
1845                   (unsigned char) qRed(rgb),
1846                   (unsigned char) qGreen(rgb),
1847                   (unsigned char) qBlue(rgb));
1848          i += 3;
1849        }
[587]1850      }
1851      fprintf (fp, "\n");
[588]1852    }
[601]1853#endif
1854
[586]1855  }
[588]1856
[586]1857  fprintf (fp, "grestore\n");
1858  fprintf (fp, "showpage\n");
1859  fclose (fp);
[588]1860
1861  return true;
[586]1862}
[588]1863/**
1864   Generate Postscript or PDF form image
1865   @param aFilename : name of file
1866   @param aInColor : numbers of colors : 1->BW 2->RGB
1867   @param aImage : Image to print
1868*/
1869bool G4OpenGLQtViewer::generatePS_PDF (
1870 QString aFilename
1871,int aInColor
1872,QImage aImage
1873)
1874{
[638]1875
[600]1876#if QT_VERSION < 0x040000
1877#ifdef Q_WS_MAC || Q_WS_X11
[588]1878  QPrinter printer;
1879  //  printer.setPageSize(pageSize);
1880  if (aInColor == 1) {
1881    printer.setColorMode(QPrinter::GrayScale);
1882  } else {
1883    printer.setColorMode(QPrinter::Color);
1884  }
1885
[600]1886  /* FIXME : I don't know which format it will save...
1887     if (aFilename.endsWith(".ps")) {
1888     printer.setOutputFormat(QPrinter::PostScriptFormat);
1889     } else {
1890     printer.setOutputFormat(QPrinter::PdfFormat);
1891     }
1892  */
1893  printer.setOutputFileName(aFilename);
1894  //  printer.setFullPage ( true);
1895  QPainter paint(&printer);
1896  paint.drawImage (0,0,aImage );
1897  paint.end();
1898#else
[638]1899  G4cerr << "This fonction is only supported on Mac OsX or X11 with Qt3. Full platform supported with Qt4\n" << G4endl;
[600]1900#endif
1901#else
1902  QPrinter printer;
1903  //  printer.setPageSize(pageSize);
[637]1904
1905  // FIXME : L. Garnier 4/12/07
1906  // This is not working, it does nothing. Image is staying in color mode
1907  // So I have desactivate the B/W button in GUI
1908  if ((!aImage.isGrayscale ()) &&(aInColor ==1 )) {
1909#if QT_VERSION < 0x040000
1910    aImage = aImage.convertDepth(1,Qt::MonoOnly);
1911#else
1912    aImage = aImage.convertToFormat ( aImage.format(), Qt::MonoOnly);
1913#endif
[600]1914  }
1915
[637]1916
[588]1917  if (aFilename.endsWith(".ps")) {
[606]1918#if QT_VERSION > 0x040200
[588]1919    printer.setOutputFormat(QPrinter::PostScriptFormat);
[606]1920#endif
[588]1921  } else {
[606]1922#if QT_VERSION > 0x040100
[588]1923    printer.setOutputFormat(QPrinter::PdfFormat);
[606]1924#endif
[588]1925  }
[606]1926#if QT_VERSION > 0x040100
[588]1927  printer.setOutputFileName(aFilename);
[606]1928#endif
[588]1929  //  printer.setFullPage ( true);
1930  QPainter paint(&printer);
[637]1931  paint.drawImage (0,0,aImage);
[588]1932  paint.end();
[600]1933#endif
[588]1934  return true;
1935}
1936
1937
[720]1938
[696]1939void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * event)
1940{
[721]1941  if (fHoldKeyEvent)
[702]1942    return;
1943
[721]1944  fHoldKeyEvent = true;
[702]1945
[709]1946#if QT_VERSION < 0x040000
1947  if ((event->key() == Qt::Key_Down) && (event->state() & Qt::AltButton )) { // go backward
1948#else
[707]1949  if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::AltModifier )) { // go backward
[709]1950#endif
[712]1951   
[720]1952    moveScene(0,0,1,false);
[707]1953  }
[709]1954#if QT_VERSION < 0x040000
1955  else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::AltButton)) { // go forward
1956#else
[707]1957  else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::AltModifier)) { // go forward
[709]1958#endif
[720]1959    moveScene(0,0,-1,false);
[707]1960  }
[709]1961#if QT_VERSION < 0x040000
1962  if ((event->key() == Qt::Key_Down) && (event->state() & Qt::ShiftButton)) { // rotate phi
1963#else
[707]1964  if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi
[709]1965#endif
[720]1966    rotateScene(0,-1);
[707]1967  }
[709]1968#if QT_VERSION < 0x040000
1969  else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::ShiftButton)) { // rotate phi
1970#else
[707]1971  else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi
[709]1972#endif
[720]1973    rotateScene(0,1);
[707]1974  }
[709]1975#if QT_VERSION < 0x040000
1976  if ((event->key() == Qt::Key_Left) && (event->state() & Qt::ShiftButton)) { // rotate theta
1977#else
[707]1978  if ((event->key() == Qt::Key_Left) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta
[709]1979#endif
[720]1980    rotateScene(1,0);
[707]1981  }
[709]1982#if QT_VERSION < 0x040000
[716]1983  else if ((event->key() == Qt::Key_Right) && (event->state() & Qt::ShiftButton)) { // rotate theta
[709]1984#else
1985  else if ((event->key() == Qt::Key_Right) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta
1986#endif
[720]1987    rotateScene(-1,0);
[707]1988  }
[721]1989
1990#if QT_VERSION < 0x040000
[722]1991  if ((event->state() & Qt::AltButton)) {
[721]1992#else
[722]1993  if ((event->modifiers() & Qt::AltModifier)) {
[721]1994#endif
[722]1995    if (event->key() == Qt::Key_Plus) {
1996      fDeltaPosX =fDeltaPosX*(1+fDeltaMove);
1997      fDeltaPosY =fDeltaPosY*(1+fDeltaMove);
1998    }
1999    else if (event->key() == Qt::Key_Minus) {
2000      fDeltaPosX =fDeltaPosX*(1-fDeltaMove);
2001      fDeltaPosY =fDeltaPosY*(1-fDeltaMove);
2002    }
2003  } else {
2004    if (event->key() == Qt::Key_Plus) {
2005      fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+fDeltaZoom));
2006      updateQWidget();
2007    }
2008    else if (event->key() == Qt::Key_Minus) {
2009      fVP.SetZoomFactor(fVP.GetZoomFactor()*(1-fDeltaZoom));
2010      updateQWidget();
2011    }
[721]2012  }
[722]2013 
2014 
[704]2015  if (event->key() == Qt::Key_Escape) { // escaped from full screen
[717]2016#if QT_VERSION >= 0x030200
2017    if (GLWindow->isFullScreen()) {
2018#if QT_VERSION < 0x040000
2019      fFullScreenOn->activated();
2020#else
2021      fFullScreenOn->trigger();
2022#endif
2023    }
2024#endif
[707]2025  }
[722]2026
[723]2027  if ((event->key() == Qt::Key_Return) || (event->key() == Qt::Key_Enter)){ // end of video
2028    fRecordFrames = false;
[724]2029    G4cout << "Recording Stop... \n" << G4endl;
2030    G4cout << "Saving /temp/output.mpg \n" << G4endl;
[723]2031    saveVideo("/temp/output.mpg");
2032  }
2033  if (event->key() == Qt::Key_Space){ // start/pause of video
2034    fRecordFrames = !fRecordFrames;
[724]2035    if (fRecordFrames) {
2036      G4cout << "Recording Start... \n" << G4endl;
2037    } else {
2038      G4cout << "Recording Pause... \n" << G4endl;
2039    }
[723]2040  }
2041
[707]2042  // with no modifiers
[716]2043#if QT_VERSION < 0x040000
2044  if (event->state() == Qt::NoButton) {
2045#else
2046  if (event->modifiers() == Qt::NoModifier) {
2047#endif
[707]2048    if (event->key() == Qt::Key_Down) { // go down
[720]2049      moveScene(0,-1,0,false);
[696]2050    }
[707]2051    else if (event->key() == Qt::Key_Up) {  // go up
[720]2052      moveScene(0,1,0,false);
[696]2053    }
[707]2054    if (event->key() == Qt::Key_Left) { // go left
[720]2055      moveScene(-1,0,0,false);
[696]2056    }
[707]2057    else if (event->key() == Qt::Key_Right) { // go right
[720]2058      moveScene(1,0,0,false);
[696]2059    }
[707]2060  }
[721]2061  fHoldKeyEvent = false;
[696]2062}
2063
[720]2064
2065bool G4OpenGLQtViewer::hasPendingEvents () {
2066  return ((QApplication*)G4Qt::getInstance ())->hasPendingEvents ();
2067}
2068
[723]2069bool G4OpenGLQtViewer::saveVideo (QString outputName) {
[720]2070
[723]2071  // save the parameter file
2072  FILE* fp;
2073  fp = fopen ("/temp/parameter_file.par", "w");
2074
2075  if (fp == NULL) {
2076    return false;
2077  }
2078
2079  fprintf (fp,"# parameter file template with lots of comments to assist you\n");
2080  fprintf (fp,"#\n");
2081  fprintf (fp,"# you can use this as a template, copying it to a separate file then modifying\n");
2082  fprintf (fp,"# the copy\n");
2083  fprintf (fp,"#\n");
2084  fprintf (fp,"#\n");
2085  fprintf (fp,"# any line beginning with '#' is a comment\n");
2086  fprintf (fp,"#\n");
2087  fprintf (fp,"# no line should be longer than 255 characters\n");
2088  fprintf (fp,"#\n");
2089  fprintf (fp,"#\n");
2090  fprintf (fp,"# general format of each line is:\n");
2091  fprintf (fp,"#          \n");
2092  fprintf (fp,"#\n");
2093  fprintf (fp,"# lines can generally be in any order\n");
2094  fprintf (fp,"#\n");
2095  fprintf (fp,"# an exception is the option 'INPUT' which must be followed by input\n");
2096  fprintf (fp,"# files in the order in which they must appear, followed by 'END_INPUT'\n");
2097  fprintf (fp,"#\n");
2098  fprintf (fp,"# Also, if you use the `command` method of generating input file names,\n");
2099  fprintf (fp,"# the command will only be executed in the INPUT_DIR if INPUT_DIR preceeds\n");
2100  fprintf (fp,"# the INPUT parameter.\n");
2101  fprintf (fp,"#\n");
2102  fprintf (fp,"#  MUST be in UPPER CASE\n");
2103  fprintf (fp,"#\n");
2104  fprintf (fp,"\n");
2105  fprintf (fp,"# Pattern affects speed, quality and compression. See the User's Guide\n");
2106  fprintf (fp,"# for more info.\n");
2107  fprintf (fp,"\n");
2108  fprintf (fp,"PATTERN          IBBPBBPBBPBBPBBP\n");
2109#if QT_VERSION < 0x040000
2110  fprintf (fp,"OUTPUT           %s\n",outputName.ascii());
2111#else
2112  fprintf (fp,"OUTPUT           %s\n",outputName.toStdString().c_str());
2113#endif
2114  fprintf (fp,"\n");
2115  fprintf (fp,"# mpeg_encode really only accepts 3 different file formats, but using a\n");
2116  fprintf (fp,"# conversion statement it can effectively handle ANY file format\n");
2117  fprintf (fp,"#\n");
2118  fprintf (fp,"# You must specify the type of the input files.  The choices are:\n");
2119  fprintf (fp,"#    YUV, PPM, JMOVIE, Y, JPEG, PNM\n");
2120  fprintf (fp,"#        (must be upper case)\n");
2121  fprintf (fp,"#\n");
2122  fprintf (fp,"BASE_FILE_FORMAT PPM\n");
2123  fprintf (fp,"\n");
2124  fprintf (fp,"#\n");
2125  fprintf (fp,"# if YUV format (or using parallel version), must provide width and height\n");
2126  fprintf (fp,"# YUV_SIZE       widthxheight\n");
2127  fprintf (fp,"# this option is ignored if BASE_FILE_FORMAT is not YUV and you're running\n");
2128  fprintf (fp,"# on just one machine\n");
2129  fprintf (fp,"#\n");
2130  fprintf (fp,"YUV_SIZE 352x240\n");
2131  fprintf (fp,"\n");
2132  fprintf (fp,"# If you are using YUV, there are different supported file formats.\n");
2133  fprintf (fp,"# EYUV or UCB are the same as previous versions of this encoder.\n");
2134  fprintf (fp,"# (All the Y's, then U's then V's, in 4:2:0 subsampling.)\n");
2135  fprintf (fp,"# Other formats, such as Abekas, Phillips, or a general format are\n");
2136  fprintf (fp,"# permissible, the general format is a string of Y's, U's, and V's\n");
2137  fprintf (fp,"# to specify the file order.\n");
2138  fprintf (fp,"\n");
2139  fprintf (fp,"INPUT_FORMAT UCB\n");
2140  fprintf (fp,"\n");
2141  fprintf (fp,"# the conversion statement\n");
2142  fprintf (fp,"#\n");
2143  fprintf (fp,"# Each occurrence of '*' will be replaced by the input file\n");
2144  fprintf (fp,"#\n");
2145  fprintf (fp,"# e.g., if you have a bunch of GIF files, then this might be:\n");
2146  fprintf (fp,"#        INPUT_CONVERT   giftoppm *\n");
2147  fprintf (fp,"#\n");
2148  fprintf (fp,"# e.g., if you have a bunch of files like a.Y a.U a.V, etc., then:\n");
2149  fprintf (fp,"#        INPUT_CONVERT   cat *.Y *.U *.V\n");
2150  fprintf (fp,"#\n");
2151  fprintf (fp,"# e.g., if you are grabbing from laser disc you might have something like\n");
2152  fprintf (fp,"#        INPUT_CONVERT   goto frame *; grabppm\n");
2153  fprintf (fp,"# 'INPUT_CONVERT *' means the files are already in the base file format\n");
2154  fprintf (fp,"#\n");
2155  fprintf (fp,"INPUT_CONVERT    * \n");
2156  fprintf (fp,"\n");
2157  fprintf (fp,"# number of frames in a GOP.\n");
2158  fprintf (fp,"#\n");
2159  fprintf (fp,"# since each GOP must have at least one I-frame, the encoder will find the\n");
2160  fprintf (fp,"# the first I-frame after GOP_SIZE frames to start the next GOP\n");
2161  fprintf (fp,"#\n");
2162  fprintf (fp,"# later, will add more flexible GOP signalling\n");
2163  fprintf (fp,"#\n");
2164  fprintf (fp,"GOP_SIZE 16\n");
2165  fprintf (fp,"\n");
2166  fprintf (fp,"# number of slices in a frame\n");
2167  fprintf (fp,"#\n");
2168  fprintf (fp,"# 1 is a good number.  another possibility is the number of macroblock rows\n");
2169  fprintf (fp,"# (which is the height divided by 16)\n");
2170  fprintf (fp,"#\n");
2171  fprintf (fp,"SLICES_PER_FRAME 1\n");
2172  fprintf (fp,"\n");
2173  fprintf (fp,"# directory to get all input files from (makes this file easier to read)\n");
2174  fprintf (fp,"INPUT_DIR        /temp\n");
2175  fprintf (fp,"\n");
2176  fprintf (fp,"# There are a bunch of ways to specify the input files.\n");
2177  fprintf (fp,"# from a simple one-per-line listing, to the following \n");
2178  fprintf (fp,"# way of numbering them.  See the manual for more information.\n");
2179  fprintf (fp,"INPUT\n");
2180  fprintf (fp,"# '*' is replaced by the numbers 01, 02, 03, 04\n");
2181  fprintf (fp,"# if I instead do [01-11], it would be 01, 02, ..., 09, 10, 11\n");
2182  fprintf (fp,"# if I instead do [1-11], it would be 1, 2, 3, ..., 9, 10, 11\n");
2183  fprintf (fp,"# if I instead do [1-11+3], it would be 1, 4, 7, 10\n");
2184  fprintf (fp,"# the program assumes none of your input files has a name ending in ']'\n");
2185  fprintf (fp,"# if you do, too bad!!!\n");
2186  fprintf (fp,"#\n");
2187  fprintf (fp,"#\n");
2188  fprintf (fp,"Test*.ppm        [0-%d]\n",fRecordFrameNumber);
2189  fprintf (fp,"# can have more files here if you want...there is no limit on the number\n");
2190  fprintf (fp,"# of files\n");
2191  fprintf (fp,"END_INPUT\n");
2192  fprintf (fp,"\n");
2193  fprintf (fp,"\n");
2194  fprintf (fp,"\n");
2195  fprintf (fp,"# Many of the remaining options have to do with the motion search and qscale\n");
2196  fprintf (fp,"\n");
2197  fprintf (fp,"# FULL or HALF -- must be upper case\n");
2198  fprintf (fp,"# Should be FULL for computer generated images\n");
2199  fprintf (fp,"PIXEL            FULL\n");
2200  fprintf (fp,"\n");
2201  fprintf (fp,"# means +/- this many pixels for both P and B frame searches\n");
2202  fprintf (fp,"# specify two numbers if you wish to serc different ranges in the two.\n");
2203  fprintf (fp,"RANGE            10\n");
2204  fprintf (fp,"\n");
2205  fprintf (fp,"# The two search algorithm parameters below mostly affect speed,\n");
2206  fprintf (fp,"# with some affect on compression and almost none on quality.\n");
2207  fprintf (fp,"\n");
2208  fprintf (fp,"# this must be one of {EXHAUSTIVE, SUBSAMPLE, LOGARITHMIC}\n");
2209  fprintf (fp,"PSEARCH_ALG      LOGARITHMIC\n");
2210  fprintf (fp,"\n");
2211  fprintf (fp,"# this must be one of {SIMPLE, CROSS2, EXHAUSTIVE}\n");
2212  fprintf (fp,"#\n");
2213  fprintf (fp,"# note that EXHAUSTIVE is really, really, really slow\n");
2214  fprintf (fp,"#\n");
2215  fprintf (fp,"BSEARCH_ALG      SIMPLE\n");
2216  fprintf (fp,"\n");
2217  fprintf (fp,"#\n");
2218  fprintf (fp,"# these specify the q-scale for I, P, and B frames\n");
2219  fprintf (fp,"# (values must be between 1 and 31)\n");
2220  fprintf (fp,"# These are the Qscale values for the entire frame in variable bit-rate\n");
2221  fprintf (fp,"# mode, and starting points (but not important) for constant bit rate\n");
2222  fprintf (fp,"#\n");
2223  fprintf (fp,"\n");
2224  fprintf (fp,"# Qscale (Quantization scale) affects quality and compression,\n");
2225  fprintf (fp,"# but has very little effect on speed.\n");
2226  fprintf (fp,"\n");
2227  fprintf (fp,"IQSCALE          4\n");
2228  fprintf (fp,"PQSCALE          5\n");
2229  fprintf (fp,"BQSCALE          12\n");
2230  fprintf (fp,"\n");
2231  fprintf (fp,"# this must be ORIGINAL or DECODED\n");
2232  fprintf (fp,"REFERENCE_FRAME  ORIGINAL\n");
2233  fprintf (fp,"\n");
2234  fprintf (fp,"# for parallel parameters see parallel.param in the exmaples subdirectory\n");
2235  fprintf (fp,"\n");
2236  fprintf (fp,"# if you want constant bit-rate mode, specify it as follows (number is bits/sec):\n");
2237  fprintf (fp,"#BIT_RATE  1000000\n");
2238  fprintf (fp,"\n");
2239  fprintf (fp,"# To specify the buffer size (327680 is default, measused in bits, for 16bit words)\n");
2240  fprintf (fp,"BUFFER_SIZE 327680\n");
2241  fprintf (fp,"\n");
2242  fprintf (fp,"# The frame rate is the number of frames/second (legal values:\n");
2243  fprintf (fp,"# 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60\n");
2244  fprintf (fp,"FRAME_RATE 30\n");
2245  fprintf (fp,"\n");
2246  fprintf (fp,"# There are many more options, see the users manual for examples....\n");
2247  fprintf (fp,"# ASPECT_RATIO, USER_DATA, GAMMA, IQTABLE, etc.\n");
2248  fprintf (fp,"\n");
2249  fprintf (fp,"\n");
2250  fclose (fp);
2251
2252  QProcess::execute ("/sw/bin/mpeg_encode", QStringList("/temp/parameter_file.par"));
2253  return true;
2254}
2255
[588]2256/*
[696]2257 
[588]2258void MultiLayer::exportToSVG(const QString& fname)
2259{
2260  QPicture picture;
2261  QPainter p(&picture);
2262  for (int i=0;i<(int)graphsList->count();i++)
2263    {
2264      Graph *gr=(Graph *)graphsList->at(i);
2265      Plot *myPlot= (Plot *)gr->plotWidget();
2266     
2267      QPoint pos=gr->pos();
2268     
2269      int width=int(myPlot->frameGeometry().width());
2270      int height=int(myPlot->frameGeometry().height());
2271     
2272      myPlot->print(&p, QRect(pos,QSize(width,height)));
2273    }
2274 
2275  p.end();
2276  picture.save(fname, "svg");
2277}
2278*/
[707]2279#endif
Note: See TracBrowser for help on using the repository browser.