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

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

en test

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