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

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

debut de la boite de dialog pour les param video

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