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

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

for qt3

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