source: trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc@ 733

Last change on this file since 733 was 733, checked in by garnier, 18 years ago

remise a niveau de movie parameters

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