source: trunk/source/visualization/OpenGL/src/G4OpenGLQtViewer.cc@ 1130

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

update par rapport a cvs

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