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

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

en test

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