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

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

on avance

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