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

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

Update pour les Tabs

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