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

Last change on this file since 610 was 610, checked in by garnier, 17 years ago

r661@mac-90108: laurentgarnier | 2007-11-22 18:10:43 +0100
en debug

  • Property svn:mime-type set to text/cpp
File size: 45.0 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.7 2007/11/15 18:24:28 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
51#include "G4Qt.hh"
52#include "G4UIsession.hh"
53#include "G4UImanager.hh"
54#include <qapplication.h>
55#include <qlayout.h>
56#include <qdialog.h>
57
58#if QT_VERSION >= 0x040000
59#include <qmenu.h>
60#include <qimagewriter.h>
61#else
62#include <qaction.h>
63#include <qwidgetlist.h>
64#include <qpopupmenu.h>
65#include <qimage.h>
66#endif
67
68#include <qmessagebox.h>
69#include <qfiledialog.h>
70#include <qprinter.h>
71#include <qpainter.h>
72#include <qgl.h> // include <qglwidget.h>
73#include <qdialog.h>
74#include <qevent.h> //include <qcontextmenuevent.h>
75
76
77//////////////////////////////////////////////////////////////////////////////
78/**
79   Implementation of virtual method of G4VViewer
80*/
81void G4OpenGLQtViewer::SetView (
82)
83//////////////////////////////////////////////////////////////////////////////
84//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
85{
86#ifdef GEANT4_QT_DEBUG
87  printf("G4OpenGLQtViewer::SetView ++++++++++++++++++++\n");
88#endif
89  //   if(!fHDC) return;
90  //   if(!fHGLRC) return;
91  //   ::wglMakeCurrent(fHDC,fHGLRC);
92  //  fWindow->makeCurrent();
93  G4OpenGLViewer::SetView ();
94#ifdef GEANT4_QT_DEBUG
95  printf("G4OpenGLQtViewer::SetView --------------------\n");
96#endif
97}
98
99
100
101//////////////////////////////////////////////////////////////////////////////
102/**
103   Implementation of virtual method of G4VViewer
104*/
105void G4OpenGLQtViewer::ShowView (
106)
107//////////////////////////////////////////////////////////////////////////////
108//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
109{
110#ifdef GEANT4_QT_DEBUG
111  printf("G4OpenGLQtViewer::ShowView  +++++++++++++++++++++\n");
112#endif
113  glFlush ();
114  if (!GLWindow) {
115    G4cerr << "Visualization window not defined, please choose one before" << G4endl;
116  } else {
117#if QT_VERSION < 0x040000
118    GLWindow->setActiveWindow();
119#else
120    GLWindow->activateWindow();
121#endif
122#ifdef GEANT4_QT_DEBUG
123    printf("G4OpenGLQtViewer::ShowView -----------------------\n");
124#endif
125  }
126  //   // Empty the Windows message queue :
127  //   MSG event;
128  //   while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
129  //     ::TranslateMessage(&event);
130  //     ::DispatchMessage (&event);
131  //   }
132}
133
134
135
136//////////////////////////////////////////////////////////////////////////////
137void G4OpenGLQtViewer::CreateGLQtContext (
138)
139//////////////////////////////////////////////////////////////////////////////
140//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
141{
142#ifdef GEANT4_QT_DEBUG
143  printf("G4OpenGLQtViewer::CreateGLQtContext \n");
144#endif
145}
146
147
148//////////////////////////////////////////////////////////////////////////////
149void G4OpenGLQtViewer::CreateMainWindow (
150 QGLWidget* glWidget
151)
152//////////////////////////////////////////////////////////////////////////////
153//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
154{
155
156  if(fWindow) return; //Done.
157#ifdef GEANT4_QT_DEBUG
158  printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n");
159#endif
160
161  // launch Qt if not
162  G4Qt* interactorManager = G4Qt::getInstance ();
163  //  G4UImanager* UI = G4UImanager::GetUIpointer();
164
165  fWindow = glWidget ;
166  //  fWindow->makeCurrent();
167
168  // create window
169  if (((QApplication*)interactorManager->GetMainInteractor())) {
170    // look for the main window
171    bool found = false;
172#if QT_VERSION < 0x040000
173    QWidgetList  *list = QApplication::allWidgets();
174    QWidgetListIt it( *list );         // iterate over the widgets
175    QWidget * widget;
176    while ( (widget=it.current()) != 0 ) {  // for each widget...
177      ++it;
178      if ((found== false) && (widget->inherits("QMainWindow"))) {
179#ifdef GEANT4_QT_DEBUG
180        printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
181#endif
182        GLWindow = new QDialog(widget,0,FALSE,Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_MinMax );
183        found = true;
184      }
185    }
186    delete list;                      // delete the list, not the widgets
187#else
188    foreach (QWidget *widget, QApplication::allWidgets()) {
189      if ((found== false) && (widget->inherits("QMainWindow"))) {
190#ifdef GEANT4_QT_DEBUG
191        printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
192#endif
193        GLWindow = new QDialog(widget,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
194        found = true;
195      }
196    }
197#endif
198    // FIXME : not tested in Qt4
199    glWidget->reparent(GLWindow,0,QPoint(0,0)); 
200
201    if (found==false) {
202#ifdef GEANT4_QT_DEBUG
203      printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n");
204#endif
205      GLWindow = new QDialog();
206    }
207  } else {
208#ifdef GEANT4_QT_DEBUG
209    printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
210#endif
211    GLWindow = new QDialog();
212  }
213
214#if QT_VERSION < 0x040000
215  QHBoxLayout *mainLayout = new QHBoxLayout(GLWindow);
216#else
217  QHBoxLayout *mainLayout = new QHBoxLayout;
218#endif
219
220  mainLayout->addWidget(fWindow);
221
222#if QT_VERSION < 0x040000
223  GLWindow->setCaption( tr( "QGl Viewer" ));
224#else
225  GLWindow->setLayout(mainLayout);
226  GLWindow->setWindowTitle(tr("QGl Viewer"));
227#endif
228  GLWindow->resize(300, 300);
229  GLWindow->move(900,300);
230#ifdef GEANT4_QT_DEBUG
231  printf("G4OpenGLQtViewer::Should show glWidget\n");
232#endif
233  GLWindow->show();
234 
235  // delete the pointer if close this
236  //  GLWindow->setAttribute(Qt::WA_DeleteOnClose);
237
238#if QT_VERSION >= 0x040000
239  QObject ::connect(GLWindow,
240                    SIGNAL(rejected()),
241                    this,
242                    SLOT(dialogClosed()));
243#endif
244
245  WinSize_x = 400;
246  WinSize_y = 400;
247  if (WinSize_x < fVP.GetWindowSizeHintX ())
248    WinSize_x = fVP.GetWindowSizeHintX ();
249  if (WinSize_y < fVP.GetWindowSizeHintY ())
250    WinSize_y = fVP.GetWindowSizeHintY ();
251
252  if(!fWindow) return;
253#ifdef GEANT4_QT_DEBUG
254  printf("G4OpenGLQtViewer::CreateMainWindow glWidget END\n");
255#endif
256
257  if (!fContextMenu)
258    createPopupMenu();
259
260}
261
262#if QT_VERSION >= 0x040000
263/**  Close the dialog and set the pointer to NULL
264 */
265void G4OpenGLQtViewer::dialogClosed() {
266#ifdef GEANT4_QT_DEBUG
267  printf("G4OpenGLQtViewer::dialogClosed END\n");
268#endif
269  //  GLWindow = NULL;
270}
271#endif
272
273//////////////////////////////////////////////////////////////////////////////
274G4OpenGLQtViewer::G4OpenGLQtViewer (
275                                    G4OpenGLSceneHandler& scene
276                                    )
277  :G4VViewer (scene, -1)
278  ,G4OpenGLViewer (scene)
279  ,fWindow(0)
280  ,fContextMenu(0)
281  ,fMouseAction(true)
282{
283#ifdef GEANT4_QT_DEBUG
284  printf("G4OpenGLQtViewer::G4OpenGLQtViewer \n");
285#endif
286}
287
288//////////////////////////////////////////////////////////////////////////////
289G4OpenGLQtViewer::~G4OpenGLQtViewer (
290)
291//////////////////////////////////////////////////////////////////////////////
292//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
293{
294#ifdef GEANT4_QT_DEBUG
295  printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n");
296#endif
297  delete fContextMenu;
298}
299
300
301/**
302   Create a popup menu for the widget. This menu is activated by right-mouse click
303*/
304void G4OpenGLQtViewer::createPopupMenu()    {
305
306#if QT_VERSION < 0x040000
307  fContextMenu = new QPopupMenu( GLWindow,"All" );
308#else
309  fContextMenu = new QMenu("All");
310#endif
311  Q_CHECK_PTR( fContextMenu );
312
313#if QT_VERSION < 0x040000
314  // === Mouse menu ===
315  QPopupMenu *mMouseAction = new QPopupMenu( fContextMenu );
316  Q_CHECK_PTR( mMouseAction );
317
318  QAction *rotate = new QAction("&Rotate scene",CTRL+Key_N,mMouseAction);
319  QAction *move =  new QAction("&Move scene",CTRL+Key_M,mMouseAction);
320  rotate->addTo(mMouseAction);
321  move->addTo(mMouseAction);
322
323  fContextMenu->insertItem( "&Mouse action", mMouseAction);
324
325#else
326  // === Mouse menu ===
327  QMenu *mMouseAction = fContextMenu->addMenu("&Mouse action");
328
329  QAction *rotate = mMouseAction->addAction("&Rotate scene");
330  QAction *move = mMouseAction->addAction("&Move scene");
331#endif
332
333  // INIT mMouse
334  createRadioAction(rotate,move,SLOT(toggleMouseAction(bool)),1);
335
336#if QT_VERSION < 0x040000
337  // === Style Menu ===
338  QPopupMenu *mStyle = new QPopupMenu(fContextMenu);
339
340  QPopupMenu *mRepresentation = new QPopupMenu(fContextMenu);
341
342  QAction *polyhedron = new QAction("&Polyhedron",CTRL+Key_P,mRepresentation);
343  QAction *nurbs = new QAction("&NURBS",CTRL+Key_N,mRepresentation);
344  polyhedron->addTo(mRepresentation);
345  nurbs->addTo(mRepresentation);
346
347  mStyle->insertItem("&Representation",mRepresentation);
348  fContextMenu->insertItem("&Style",mStyle);
349
350#else
351  // === Style Menu ===
352  QMenu *mStyle = fContextMenu->addMenu("&Style");
353
354  QMenu *mRepresentation = mStyle->addMenu("&Representation");
355 QAction *polyhedron = mRepresentation->addAction("Polyhedron");
356  QAction *nurbs = mRepresentation->addAction("NURBS");
357#endif
358  // INIT mStyle
359  G4ViewParameters::RepStyle style;
360  style = fVP.GetRepStyle();
361  if (style == G4ViewParameters::polyhedron) {
362    createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),1);
363  } else if (style == G4ViewParameters::nurbs) {
364    createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),2);
365  } else {
366    mRepresentation->clear();
367  }
368
369
370#if QT_VERSION < 0x040000
371  // === Drawing Menu ===
372  QPopupMenu *mDrawing = new QPopupMenu(fContextMenu);
373  fContextMenu->insertItem("&Drawing",mDrawing);
374
375  fDrawingWireframe = new QPopupMenu(mDrawing);
376  mDrawing->insertItem("&Wireframe",fDrawingWireframe);
377#ifdef GEANT4_QT_DEBUG
378  printf("G4OpenGLQtViewer:: fDrawingWireframe creation\n");
379#endif
380
381  mDrawing->setCheckable(true);
382  fDrawingWireframe->setCheckable(true);
383
384  fDrawingLineRemoval = new QPopupMenu(mDrawing);
385  mDrawing->insertItem("&Hidden line removal",fDrawingLineRemoval);
386  fDrawingLineRemoval->setCheckable(true);
387
388  fDrawingSurfaceRemoval = new QPopupMenu(mDrawing);
389  mDrawing->insertItem("&Hidden surface removal",fDrawingSurfaceRemoval);
390  fDrawingSurfaceRemoval->setCheckable(true);
391
392  fDrawingLineSurfaceRemoval = new QPopupMenu(mDrawing);
393  mDrawing->insertItem("&Hidden line and surface removal",fDrawingLineSurfaceRemoval);
394  fDrawingLineSurfaceRemoval->setCheckable(true);
395
396#else
397  // === Drawing Menu ===
398  QMenu *mDrawing = mStyle->addMenu("&Drawing");
399
400  fDrawingWireframe = mDrawing->addAction("Wireframe");
401  fDrawingWireframe->setCheckable(true);
402
403  fDrawingLineRemoval = mDrawing->addAction("Hidden line removal");
404  fDrawingLineRemoval->setCheckable(true);
405
406  fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal");
407  fDrawingSurfaceRemoval->setCheckable(true);
408
409  fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal");
410  fDrawingLineSurfaceRemoval->setCheckable(true);
411#endif
412  // INIT Drawing
413  G4ViewParameters::DrawingStyle d_style;
414  d_style = fVP.GetDrawingStyle();
415 
416#if QT_VERSION < 0x040000
417  if (d_style == G4ViewParameters::wireframe) {
418    fDrawingWireframe->setItemChecked(0,true);
419  } else if (d_style == G4ViewParameters::hlr) {
420    fDrawingLineRemoval->setItemChecked(0,true);
421  } else if (d_style == G4ViewParameters::hsr) {
422    fDrawingSurfaceRemoval->setItemChecked(0,true);
423  } else if (d_style == G4ViewParameters::hlhsr) {
424    fDrawingLineSurfaceRemoval->setItemChecked(0,true);
425  } else {
426    mDrawing->clear();
427  }
428#ifdef GEANT4_QT_DEBUG
429  printf("G4OpenGLQtViewer:: fDrawingWireframe 1\n");
430#endif
431  QObject ::connect(fDrawingWireframe,
432                    SIGNAL(activated(int)),
433                    this,
434                    SLOT(actionDrawingWireframe()));
435#ifdef GEANT4_QT_DEBUG
436  printf("G4OpenGLQtViewer:: fDrawingWireframe 2\n");
437#endif
438  QObject ::connect(fDrawingLineRemoval,
439                    SIGNAL(activated(int)),
440                    this,
441                    SLOT(actionDrawingLineRemoval()));
442  QObject ::connect(fDrawingSurfaceRemoval,
443                    SIGNAL(activated(int)),
444                    this,
445                    SLOT(actionDrawingSurfaceRemoval()));
446  QObject ::connect(fDrawingLineSurfaceRemoval,
447                    SIGNAL(activated(int)),
448                    this,
449                    SLOT(actionDrawingLineSurfaceRemoval()));
450#else
451  if (d_style == G4ViewParameters::wireframe) {
452    fDrawingWireframe->setChecked(true);
453  } else if (d_style == G4ViewParameters::hlr) {
454    fDrawingLineRemoval->setChecked(true);
455  } else if (d_style == G4ViewParameters::hsr) {
456    fDrawingSurfaceRemoval->setChecked(true);
457  } else if (d_style == G4ViewParameters::hlhsr) {
458    fDrawingLineSurfaceRemoval->setChecked(true);
459  } else {
460    mDrawing->clear();
461  }
462  QObject ::connect(fDrawingWireframe,
463                    SIGNAL(triggered(bool)),
464                    this,
465                    SLOT(actionDrawingWireframe()));
466  QObject ::connect(fDrawingLineRemoval,
467                    SIGNAL(triggered(bool)),
468                    this,
469                    SLOT(actionDrawingLineRemoval()));
470  QObject ::connect(fDrawingSurfaceRemoval,
471                    SIGNAL(triggered(bool)),
472                    this,
473                    SLOT(actionDrawingSurfaceRemoval()));
474  QObject ::connect(fDrawingLineSurfaceRemoval,
475                    SIGNAL(triggered(bool)),
476                    this,
477                    SLOT(actionDrawingLineSurfaceRemoval()));
478#endif
479
480
481
482#if QT_VERSION < 0x040000
483  QPopupMenu *mBackground = new QPopupMenu(mStyle);
484  mStyle->insertItem("&Background color",mBackground);
485
486  QAction *white = new QAction("&White",CTRL+Key_W,mBackground);
487  QAction *black =  new QAction("&Black",CTRL+Key_B,mBackground);
488  white->addTo(mBackground);
489  black->addTo(mBackground);
490
491#else
492  QMenu *mBackground = mStyle->addMenu("&Background color");
493  QAction *white = mBackground->addAction("White");
494  QAction *black = mBackground->addAction("Black");
495
496#endif
497  if (background.GetRed() == 1. &&
498      background.GetGreen() == 1. &&
499      background.GetBlue() == 1.) {
500    createRadioAction(white,black,SLOT(toggleBackground(bool)),1);
501  } else {
502    createRadioAction(white,black,SLOT(toggleBackground(bool)),2);
503  }
504
505
506#if QT_VERSION < 0x040000
507  // === Action Menu ===
508  QPopupMenu *mActions = new QPopupMenu(fContextMenu);
509  fContextMenu->insertItem("&Actions",mActions);
510
511  QAction *controlPanels = new QAction("&Control panels",CTRL+Key_C,mActions);
512  QAction *exitG4 =  new QAction("&Exit to G4Vis >",CTRL+Key_E,mActions);
513  QAction *createEPS =  new QAction("&Save as ...",CTRL+Key_S,mActions);
514  controlPanels->addTo(mActions);
515  exitG4->addTo(mActions);
516  createEPS->addTo(mActions);
517  QObject ::connect(controlPanels,
518                    SIGNAL(activated()),
519                    this,
520                    SLOT(actionControlPanels()));
521  QObject ::connect(exitG4,
522                    SIGNAL(activated()),
523                    this,
524                    SLOT(actionExitG4()));
525  QObject ::connect(createEPS,
526                    SIGNAL(activated()),
527                    this,
528                    SLOT(actionCreateEPS()));
529
530#else
531  // === Action Menu ===
532  QMenu *mActions = fContextMenu->addMenu("&Actions");
533  QAction *controlPanels = mActions->addAction("Control panels");
534  QAction *exitG4 = mActions->addAction("Exit to G4Vis >");
535  QAction *createEPS = mActions->addAction("Save as ...");
536  QObject ::connect(controlPanels,
537                    SIGNAL(triggered()),
538                    this,
539                    SLOT(actionControlPanels()));
540  QObject ::connect(exitG4,
541                    SIGNAL(triggered()),
542                    this,
543                    SLOT(actionExitG4()));
544  QObject ::connect(createEPS,
545                    SIGNAL(triggered()),
546                    this,
547                    SLOT(actionCreateEPS()));
548#endif
549
550
551
552#if QT_VERSION < 0x040000
553  // === Special Menu ===
554  QPopupMenu *mSpecial = new QPopupMenu(fContextMenu);
555  fContextMenu->insertItem("S&pecial",mSpecial);
556
557  QPopupMenu *mTransparency = new QPopupMenu(mSpecial);
558  mSpecial->insertItem("Transparency",mTransparency);
559
560  QAction *transparencyOn = new QAction("&On",CTRL+Key_O,mTransparency);
561  QAction *transparencyOff = new QAction("&Off",CTRL+Key_F,mTransparency);
562  transparencyOn->addTo(mTransparency);
563  transparencyOff->addTo(mTransparency);
564
565#else
566  // === Special Menu ===
567  QMenu *mSpecial = fContextMenu->addMenu("S&pecial");
568  QMenu *mTransparency = mSpecial->addMenu("Transparency");
569  QAction *transparencyOn = mTransparency->addAction("On");
570  QAction *transparencyOff = mTransparency->addAction("Off");
571#endif
572
573  if (transparency_enabled == false) {
574    createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2);
575  } else if (transparency_enabled == true) {
576    createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),1);
577  } else {
578    mSpecial->clear();
579  }
580
581
582#if QT_VERSION < 0x040000
583  QPopupMenu *mAntialiasing = new QPopupMenu(mSpecial);
584  mSpecial->insertItem("Antialiasing",mAntialiasing);
585
586  QAction *antialiasingOn = new QAction("&On",CTRL+Key_O,mAntialiasing);
587  QAction *antialiasingOff = new QAction("&Off",CTRL+Key_F,mAntialiasing);
588  antialiasingOn->addTo(mAntialiasing);
589  antialiasingOff->addTo(mAntialiasing);
590
591#else
592  QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing");
593  QAction *antialiasingOn = mAntialiasing->addAction("On");
594  QAction *antialiasingOff = mAntialiasing->addAction("Off");
595#endif
596
597  if (antialiasing_enabled == false) {
598    createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2);
599  } else if (antialiasing_enabled == true) {
600    createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),1);
601  } else {
602    mAntialiasing->clear();
603  }
604
605#if QT_VERSION < 0x040000
606  QPopupMenu *mHaloing = new QPopupMenu(mSpecial);
607  mSpecial->insertItem("Haloing",mHaloing);
608
609  QAction *haloingOn = new QAction("&On",CTRL+Key_O,mHaloing);
610  QAction *haloingOff = new QAction("&Off",CTRL+Key_F,mHaloing);
611  haloingOn->addTo(mHaloing);
612  haloingOff->addTo(mHaloing);
613#else
614  QMenu *mHaloing = mSpecial->addMenu("Haloing");
615  QAction *haloingOn = mHaloing->addAction("On");
616  QAction *haloingOff = mHaloing->addAction("Off");
617#endif
618  if (haloing_enabled == false) {
619    createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2);
620  } else if (haloing_enabled == true) {
621    createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),1);
622  } else {
623    mHaloing->clear();
624  }
625
626#if QT_VERSION < 0x040000
627  QPopupMenu *mAux = new QPopupMenu(mSpecial);
628  mSpecial->insertItem("Auxiliairy edges",mAux);
629
630  QAction *auxOn = new QAction("&On",CTRL+Key_O,mAux);
631  QAction *auxOff = new QAction("&Off",CTRL+Key_F,mAux);
632  auxOn->addTo(mAux);
633  auxOff->addTo(mAux);
634
635#else
636  QMenu *mAux = mSpecial->addMenu("Auxiliary edges");
637  QAction *auxOn = mAux->addAction("On");
638  QAction *auxOff = mAux->addAction("Off");
639#endif
640  if (!fVP.IsAuxEdgeVisible()) {
641    createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1);
642  } else {
643    createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),2);
644  }
645
646
647#if QT_VERSION < 0x040000
648  QPopupMenu *mFullScreen = new QPopupMenu(mSpecial);
649  mSpecial->insertItem("Full screen",mFullScreen);
650
651  QAction *fullOn = new QAction("&On",CTRL+Key_O,mFullScreen);
652  QAction *fullOff = new QAction("&Off",CTRL+Key_F,mFullScreen);
653  fullOn->addTo(mFullScreen);
654  fullOff->addTo(mFullScreen);
655#else
656  QMenu *mFullScreen = mSpecial->addMenu("Full screen");
657  QAction *fullOn = mFullScreen->addAction("On");
658  QAction *fullOff = mFullScreen->addAction("Off");
659#endif
660  createRadioAction(fullOn,fullOff,SLOT(toggleFullScreen(bool)),2);
661
662}
663
664void G4OpenGLQtViewer::manageContextMenuEvent(QContextMenuEvent *e)
665{
666  if (!GLWindow) {
667    G4cerr << "Visualization window not defined, please choose one before" << G4endl;
668  } else {
669 
670    if (!fContextMenu)
671      createPopupMenu();
672   
673    // launch menu
674    if ( fContextMenu ) {
675      fContextMenu->exec( e->globalPos() );
676      //    delete fContextMenu;
677    }
678  }
679  e->accept();
680}
681
682
683/**
684   Create a radio button menu. The two menu will be connected. When click on one,
685   eatch state will be invert and callback method will be called.
686   @param action1 first action to connect
687   @param action2 second action to connect
688   @param method callback method
689   @param nCheck: 1 : first action will be set true. 2 : second action will be set true
690*/
691#if QT_VERSION < 0x040000
692void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
693
694  if (action1->parent()->inherits("QPopupMenu")){
695    ((QPopupMenu*)action1->parent())->setCheckable(true);
696  }
697  ((QPopupMenu*)action1->parent())->setItemChecked(0,true);
698  ((QPopupMenu*)action1->parent())->setItemChecked(1,true);
699
700  if (nCheck ==1)
701    ((QPopupMenu*)action1->parent())->setItemChecked(0,true);
702  else
703    ((QPopupMenu*)action1->parent())->setItemChecked(1,true);
704   
705  //FIXME : Should not work on Qt3
706  QObject ::connect(action1, SIGNAL(activated()),action2, SLOT(toggle()));
707  QObject ::connect(action2, SIGNAL(activated()),action1, SLOT(toggle()));
708
709  QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str());
710}
711
712#else
713void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
714
715  action1->setCheckable(true);
716  action2->setCheckable(true);
717
718  if (nCheck ==1)
719    action1->setChecked (true);
720  else
721    action2->setChecked (true);
722   
723  QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle()));
724  QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle()));
725
726  QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str());
727
728}
729#endif
730
731/**
732   Slot activate when drawing->wireframe menu is set
733 */
734void G4OpenGLQtViewer::actionDrawingWireframe() {
735  emit toggleDrawingAction(1);
736}
737
738/**
739   Slot activate when drawing->line removal menu is set
740 */
741void G4OpenGLQtViewer::actionDrawingLineRemoval() {
742  emit toggleDrawingAction(2);
743}
744
745/**
746   Slot activate when drawing->surface removal menu is set
747 */
748void G4OpenGLQtViewer::actionDrawingSurfaceRemoval() {
749  emit toggleDrawingAction(3);
750}
751
752/**
753   Slot activate when drawing->wireframe menu is set
754 */
755void G4OpenGLQtViewer::actionDrawingLineSurfaceRemoval() {
756  emit toggleDrawingAction(4);
757}
758
759
760/**
761   Slot activated when drawing menu is toggle
762   Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
763   KernelVisitDecision () will be call and will set the fNeedKernelVisit
764   to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
765   It will cause a redraw of the view
766   @param aAction : 1 wireframe, 2 line removal, 3 surface removal, 4 line & surface removal
767   @see G4OpenGLStoredQtViewer::DrawView
768   @see G4XXXStoredViewer::CompareForKernelVisit
769 */
770void G4OpenGLQtViewer::toggleDrawingAction(int aAction) {
771
772  G4ViewParameters::DrawingStyle d_style;
773 
774
775  if (aAction ==1) {
776#if QT_VERSION < 0x040000
777    fDrawingWireframe->setItemChecked (0,true);
778    fDrawingLineRemoval->setItemChecked (0,false);
779    fDrawingSurfaceRemoval->setItemChecked (0,false);
780    fDrawingLineSurfaceRemoval->setItemChecked (0,false);
781#else
782    fDrawingWireframe->setChecked (true);
783    fDrawingLineRemoval->setChecked (false);
784    fDrawingSurfaceRemoval->setChecked (false);
785    fDrawingLineSurfaceRemoval->setChecked (false);
786#endif
787
788    d_style = G4ViewParameters::wireframe;
789
790  } else  if (aAction ==2) {
791#if QT_VERSION < 0x040000
792    fDrawingWireframe->setItemChecked (0,false);
793    fDrawingLineRemoval->setItemChecked (0,true);
794    fDrawingSurfaceRemoval->setItemChecked (0,false);
795    fDrawingLineSurfaceRemoval->setItemChecked (0,false);
796#else
797    fDrawingWireframe->setChecked (false);
798    fDrawingLineRemoval->setChecked (true);
799    fDrawingSurfaceRemoval->setChecked (false);
800    fDrawingLineSurfaceRemoval->setChecked (false);
801#endif
802
803    d_style = G4ViewParameters::hlr;
804
805  } else  if (aAction ==3) {
806#if QT_VERSION < 0x040000
807    fDrawingWireframe->setItemChecked (0,false);
808    fDrawingLineRemoval->setItemChecked (0,false);
809    fDrawingSurfaceRemoval->setItemChecked (0,true);
810    fDrawingLineSurfaceRemoval->setItemChecked (0,false);
811#else
812    fDrawingWireframe->setChecked (false);
813    fDrawingLineRemoval->setChecked (false);
814    fDrawingSurfaceRemoval->setChecked (true);
815    fDrawingLineSurfaceRemoval->setChecked (false);
816#endif
817
818    d_style = G4ViewParameters::hsr;
819
820  } else  if (aAction ==4) {
821#if QT_VERSION < 0x040000
822    fDrawingWireframe->setItemChecked (0,false);
823    fDrawingLineRemoval->setItemChecked (0,false);
824    fDrawingSurfaceRemoval->setItemChecked (0,false);
825    fDrawingLineSurfaceRemoval->setItemChecked (0,true);
826#else
827    fDrawingWireframe->setChecked (false);
828    fDrawingLineRemoval->setChecked (false);
829    fDrawingSurfaceRemoval->setChecked (false);
830    fDrawingLineSurfaceRemoval->setChecked (true);
831#endif
832    d_style = G4ViewParameters::hlhsr;
833  }
834  fVP.SetDrawingStyle(d_style);
835
836  updateQWidget();
837#ifdef GEANT4_QT_DEBUG
838  printf("G4OpenGLQtViewer::toggleDrawingAction\n");
839#endif
840}
841
842
843/**
844   SLOT Activate by a click on the representation menu
845   Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
846   KernelVisitDecision () will be call and will set the fNeedKernelVisit
847   to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
848   It will cause a redraw of the view
849   @param check : 1 polyhedron, 0 nurbs
850   @see G4OpenGLStoredQtViewer::DrawView
851   @see G4XXXStoredViewer::CompareForKernelVisit
852*/
853void G4OpenGLQtViewer::toggleRepresentation(bool check) {
854
855  G4ViewParameters::RepStyle style;
856  if (check == 1) {
857    style = G4ViewParameters::polyhedron;
858  } else {
859    style = G4ViewParameters::nurbs;
860  }
861  fVP.SetRepStyle (style);
862
863#ifdef GEANT4_QT_DEBUG
864  printf("G4OpenGLQtViewer::toggleRepresentation 3%d\n",check);
865#endif
866  updateQWidget();
867#ifdef GEANT4_QT_DEBUG
868  printf("G4OpenGLQtViewer::toggleRepresentation 4%d\n",check);
869#endif
870}
871
872/**
873   SLOT Activate by a click on the background menu
874@param check : 1 white, 0 black
875*/
876void G4OpenGLQtViewer::toggleBackground(bool check) {
877
878  //   //I need to revisit the kernel if the background colour changes and
879  //   //hidden line removal is enabled, because hlr drawing utilises the
880  //   //background colour in its drawing...
881  //   // (Note added by JA 13/9/2005) Background now handled in view
882  //   // parameters.  A kernel visit is triggered on change of background.
883  if (check == 1) {
884    ((G4ViewParameters&)this->GetViewParameters()).
885      SetBackgroundColour(G4Colour(1.,1.,1.));  // White
886  } else {
887    ((G4ViewParameters&)this->GetViewParameters()).
888      SetBackgroundColour(G4Colour(0.,0.,0.));  // Black
889  }
890  updateQWidget();
891}
892
893/**
894   SLOT Activate by a click on the transparency menu
895@param check : 1 , 0
896*/
897void G4OpenGLQtViewer::toggleTransparency(bool check) {
898 
899  if (check) {
900    transparency_enabled = false;
901  } else {
902    transparency_enabled = true;
903  }
904  SetNeedKernelVisit (true);
905  updateQWidget();
906}
907
908/**
909   SLOT Activate by a click on the antialiasing menu
910@param check : 1 , 0
911*/
912void G4OpenGLQtViewer::toggleAntialiasing(bool check) {
913
914  if (!check) {
915    antialiasing_enabled = false;
916    glDisable (GL_LINE_SMOOTH);
917    glDisable (GL_POLYGON_SMOOTH);
918  } else {
919    antialiasing_enabled = true;
920    glEnable (GL_LINE_SMOOTH);
921    glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
922    glEnable (GL_POLYGON_SMOOTH);
923    glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
924  }
925
926  updateQWidget();
927#ifdef GEANT4_QT_DEBUG
928  printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
929#endif
930}
931
932/**
933   SLOT Activate by a click on the haloing menu
934@param check : 1 , 0
935*/
936//FIXME : I SEE NOTHING...
937void G4OpenGLQtViewer::toggleHaloing(bool check) {
938  if (check) {
939    haloing_enabled = false;
940  } else {
941    haloing_enabled = true;
942  }
943
944  updateQWidget();
945
946#ifdef GEANT4_QT_DEBUG
947  printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
948#endif
949}
950
951/**
952   SLOT Activate by a click on the auxiliaire edges menu
953@param check : 1 , 0
954*/
955void G4OpenGLQtViewer::toggleAux(bool check) {
956  if (check) {
957    fVP.SetAuxEdgeVisible(false);
958  } else {
959    fVP.SetAuxEdgeVisible(true);
960  }
961  SetNeedKernelVisit (true);
962  updateQWidget();
963
964#ifdef GEANT4_QT_DEBUG
965  printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
966#endif
967}
968
969/**
970   SLOT Activate by a click on the full screen menu
971@param check : 1 , 0
972*/
973void G4OpenGLQtViewer::toggleFullScreen(bool check) {
974  GLWindow->setWindowState(GLWindow->windowState() ^ Qt::WindowFullScreen);
975
976#ifdef GEANT4_QT_DEBUG
977  printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
978#endif
979}
980
981/**
982   SLOT Activate by a click on the mouse action menu
983   @param check : 1 , 0
984*/
985void G4OpenGLQtViewer::toggleMouseAction(bool check) {
986  if (check) { // rotate scene
987    fMouseAction = true;
988  } else { // move scene
989    fMouseAction = false;
990  }
991
992#ifdef GEANT4_QT_DEBUG
993  printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
994#endif
995}
996
997
998void G4OpenGLQtViewer::actionControlPanels() {
999#ifdef GEANT4_QT_DEBUG
1000  printf("G4OpenGLQtViewer::actionControlPanels \n");
1001#endif
1002}
1003
1004void G4OpenGLQtViewer::actionExitG4() {
1005#ifdef GEANT4_QT_DEBUG
1006  printf("G4OpenGLQtViewer::actionExitG4() \n");
1007#endif
1008}
1009
1010void G4OpenGLQtViewer::actionCreateEPS() {
1011  QString filters;
1012#if QT_VERSION < 0x040000
1013  QStrList listFormat=QImageIO::outputFormats();
1014  char *tmp=listFormat.first();
1015  while (tmp!=0) {
1016    filters += QString(tmp) + ";;";
1017    tmp=listFormat.next();
1018  }
1019#else
1020  QList<QByteArray> formats =  QImageWriter::supportedImageFormats ();
1021  for (int i = 0; i < formats.size(); ++i) {
1022    filters +=formats.at(i) + ";;";
1023  }
1024#endif
1025  filters += "eps;;";
1026  filters += "ps;;";
1027  filters += "pdf";
1028  QString* selectedFilter = new QString();
1029#if QT_VERSION < 0x040000
1030  QString nomFich =  QFileDialog::getSaveFileName ( ".",
1031                                                    filters,
1032                                                    GLWindow,
1033                                                    "Save file dialog",
1034                                                    tr("Save as ..."),
1035                                                    selectedFilter );
1036#else
1037  QString nomFich =  QFileDialog::getSaveFileName ( GLWindow,
1038                                                    tr("Save as ..."),
1039                                                    ".",
1040                                                    filters,
1041                                                    selectedFilter );
1042#endif
1043  // bmp jpg jpeg png ppm xbm xpm
1044  if (nomFich == "") {
1045    return;
1046  }
1047#if QT_VERSION < 0x040000
1048  nomFich += "."+selectedFilter->lower();
1049#ifdef GEANT4_QT_DEBUG
1050  printf("G4OpenGLQtViewer::name %s\n",nomFich.ascii());
1051#endif
1052#else
1053  nomFich += "."+selectedFilter->toLower();
1054#ifdef GEANT4_QT_DEBUG
1055  printf("G4OpenGLQtViewer::name %s\n",nomFich.toStdString().c_str());
1056#endif
1057#endif
1058  G4OpenGLQtExportDialog* exportDialog= new G4OpenGLQtExportDialog(GLWindow,nomFich,fWindow->height(),fWindow->width());
1059  if(  exportDialog->exec()) {
1060
1061    QImage image;
1062    //    if ((exportDialog->getWidth() !=fWindow->width()) ||
1063    //        (exportDialog->getHeight() !=fWindow->height())) {
1064     
1065      //      rescaleImage(exportDialog->getWidth(),exportDialog->getHeight());// re-scale image
1066#ifdef GEANT4_QT_DEBUG
1067      printf("rescaling\n");
1068#endif
1069      QGLWidget* glResized = fWindow;
1070      fWindow->renderPixmap (exportDialog->getWidth()*2,exportDialog->getHeight()*2 ).save("/Users/laurentgarnier/Desktop/zzz.jpg","jpg");
1071      QPixmap * pixmap = new QPixmap(fWindow->renderPixmap (exportDialog->getWidth(),exportDialog->getHeight() )) ;
1072      //      image = pixmap.toImage();
1073      //      glResized->resize(exportDialog->getWidth()*2,exportDialog->getHeight()*2);
1074#ifdef GEANT4_QT_DEBUG
1075      printf("rescaling after\n");
1076#endif
1077      //      image = glResized->grabFrameBuffer();
1078     
1079      //    } else {
1080      // image = fWindow->grabFrameBuffer();
1081      //  }   
1082    // jpeg format
1083    if (nomFich.endsWith(".jpg") ||
1084        nomFich.endsWith(".jpeg")) {
1085      // grabFrameBuffer() :: Returns an image of the frame buffer. If withAlpha is true the alpha channel is included.
1086      image.save(nomFich,0,exportDialog->getSliderValue());
1087#ifdef GEANT4_QT_DEBUG
1088      printf("saving jpeg quality : %d\n",exportDialog->getSliderValue());
1089#endif
1090    } else if (nomFich.endsWith(".eps")) {
1091      generateEPS(nomFich,exportDialog->getNbColor(),image);
1092    } else if (nomFich.endsWith(".ps") ||nomFich.endsWith(".pdf")) {
1093      generatePS_PDF(nomFich,exportDialog->getNbColor(),image);
1094    } else if (nomFich.endsWith(".tif") ||
1095               nomFich.endsWith(".tiff") ||
1096               nomFich.endsWith(".jpg") ||
1097               nomFich.endsWith(".png") ||
1098               nomFich.endsWith(".bmp") ||
1099               nomFich.endsWith(".xpm")) {
1100      image.save(nomFich,0,exportDialog->getSliderValue());
1101#ifdef GEANT4_QT_DEBUG
1102      printf("saving ELSE\n");
1103#endif
1104    } else {
1105      G4cerr << "This version of G4UI Could not generate the selected format" << G4endl;
1106    }
1107   
1108  } else { // cancel selected
1109    return;
1110  }
1111 
1112#ifdef GEANT4_QT_DEBUG
1113  printf("G4OpenGLQtViewer::actionCreateEPS() \n");
1114#endif
1115}
1116
1117/*
1118// 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
1119
1120void Graph::exportToSVG(const QString& fname)
1121{
1122  // enable workaround for Qt3 misalignments
1123  QwtPainter::setSVGMode(true);
1124  QPicture picture;
1125  QPainter p(&picture);
1126  d_plot->print(&p, d_plot->rect());
1127  p.end();
1128
1129  picture.save(fname, "svg");
1130}
1131*/
1132
1133
1134
1135
1136/**
1137   Save the current mouse press point
1138   @param p mouse click point
1139*/
1140void G4OpenGLQtViewer::G4MousePressEvent(QPoint p)
1141{
1142  lastPos = p;
1143}
1144
1145/**
1146   @param pos_x mouse x position
1147   @param pos_y mouse y position
1148   @param mButtons mouse button active
1149*/
1150
1151#if QT_VERSION < 0x040000
1152void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::ButtonState mButtons)
1153#else
1154void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons)
1155#endif
1156{
1157  int dx = pos_x - lastPos.x();
1158  int dy = pos_y - lastPos.y();
1159 
1160  if (fMouseAction) {  // rotate
1161    if (mButtons & Qt::LeftButton) {
1162      //phi spin stuff here
1163     
1164      G4Vector3D vp = fVP.GetViewpointDirection ().unit ();
1165      G4Vector3D up = fVP.GetUpVector ().unit ();
1166     
1167      G4Vector3D yprime = (up.cross(vp)).unit();
1168      G4Vector3D zprime = (vp.cross(yprime)).unit();
1169     
1170      G4double delta_alpha;
1171      G4double delta_theta;
1172     
1173      if (fVP.GetLightsMoveWithCamera()) {
1174        delta_alpha = dy;
1175        delta_theta = -dx;
1176      } else {
1177        delta_alpha = -dy;
1178        delta_theta = dx;
1179      }   
1180
1181      delta_alpha *= deg;
1182      delta_theta *= deg;
1183
1184      G4Vector3D new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime;
1185     
1186      G4Vector3D new_up;
1187      if (fVP.GetLightsMoveWithCamera()) {
1188        new_up = (new_vp.cross(yprime)).unit();
1189        fVP.SetUpVector(new_up);
1190      } else {
1191        new_up = up;
1192      }
1193      ////////////////
1194      // Rotates by fixed azimuthal angle delta_theta.
1195
1196      G4double cosalpha = new_up.dot (new_vp.unit());
1197      G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));
1198      yprime = (new_up.cross (new_vp.unit())).unit ();
1199      G4Vector3D xprime = yprime.cross (new_up);
1200      // Projection of vp on plane perpendicular to up...
1201      G4Vector3D a1 = sinalpha * xprime;
1202      // Required new projection...
1203      G4Vector3D a2 =
1204        sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);
1205      // Required Increment vector...
1206      G4Vector3D delta = a2 - a1;
1207      // So new viewpoint is...
1208      G4Vector3D viewPoint = new_vp.unit() + delta;
1209
1210      fVP.SetViewAndLights (viewPoint);
1211      updateQWidget();
1212     
1213    } else if (mButtons & Qt::RightButton) {
1214      // NEVER DONE BECAUSE OF MOUSE MENU
1215#ifdef GEANT4_QT_DEBUG
1216      //       printf("G4OpenGLQtViewer::mouseMoveEvent Right \n");
1217#endif
1218      //       setXRotation(xRot + dy/2);
1219      //       setZRotation(zRot + dx/2);
1220      //       updateQWidget();
1221    }
1222  } else {  // move
1223
1224    float dx = pos_x - lastPos.x();
1225    float dy = pos_y - lastPos.y();
1226   
1227    G4Point3D stp
1228      = GetSceneHandler()->GetScene()->GetStandardTargetPoint();
1229   
1230    G4Point3D tp = stp + fVP.GetCurrentTargetPoint ();
1231   
1232    const G4Vector3D& upVector = fVP.GetUpVector ();
1233    const G4Vector3D& vpVector = fVP.GetViewpointDirection ();
1234   
1235    G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
1236    G4Vector3D unitUp    = (vpVector.cross (unitRight)).unit();
1237   
1238    tp += -dx * unitRight + dy * unitUp;
1239    fVP.SetCurrentTargetPoint (tp - stp);
1240   
1241    updateQWidget();
1242  }
1243  lastPos = QPoint(pos_x, pos_y);
1244}
1245
1246void G4OpenGLQtViewer::rescaleImage(
1247 int aWidth
1248,int aHeight
1249){
1250#ifdef GEANT4_QT_DEBUG
1251  printf("should rescale \n");
1252#endif
1253}
1254
1255/**
1256   Generate Postscript form image
1257   @param aFilename : name of file
1258   @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha
1259   @param aImage : Image to print
1260*/
1261bool G4OpenGLQtViewer::generateEPS (
1262 QString aFilename
1263,int aInColor
1264,QImage aImage
1265)
1266{
1267  // FIXME
1268#ifdef GEANT4_QT_DEBUG
1269  printf("saving EPS\n");
1270#endif
1271
1272  FILE* fp;
1273
1274  if ((!aImage.isGrayscale ()) &&(aInColor ==1 )) {
1275#if QT_VERSION < 0x040000
1276    aImage.convertDepth(1,Qt::MonoOnly);
1277#else
1278    aImage.convertToFormat ( aImage.format(), Qt::MonoOnly);
1279#endif
1280  }
1281  const uchar * pixels = aImage.bits ();
1282   
1283  if (pixels == NULL)
1284    return false;
1285 
1286#if QT_VERSION < 0x040000
1287  fp = fopen (aFilename.ascii(), "w");
1288#else
1289  fp = fopen (aFilename.toStdString().c_str(), "w");
1290#endif
1291  if (fp == NULL) {
1292    return false;
1293  }
1294 
1295  fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n");
1296#if QT_VERSION < 0x040000
1297  fprintf (fp, "%%%%Title: %s\n", aFilename.ascii());
1298#else
1299  fprintf (fp, "%%%%Title: %s\n", aFilename.toStdString().c_str());
1300#endif
1301  fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n");
1302  fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", aImage.width(), aImage.height());
1303  fprintf (fp, "%%%%EndComments\n");
1304  fprintf (fp, "gsave\n");
1305  fprintf (fp, "/bwproc {\n");
1306  fprintf (fp, "    rgbproc\n");
1307  fprintf (fp, "    dup length 3 idiv string 0 3 0 \n");
1308  fprintf (fp, "    5 -1 roll {\n");
1309  fprintf (fp, "    add 2 1 roll 1 sub dup 0 eq\n");
1310  fprintf (fp, "    { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n");
1311  fprintf (fp, "       3 1 roll 5 -1 roll } put 1 add 3 0 \n");
1312  fprintf (fp, "    { 2 1 roll } ifelse\n");
1313  fprintf (fp, "    }forall\n");
1314  fprintf (fp, "    pop pop pop\n");
1315  fprintf (fp, "} def\n");
1316  fprintf (fp, "systemdict /colorimage known not {\n");
1317  fprintf (fp, "   /colorimage {\n");
1318  fprintf (fp, "       pop\n");
1319  fprintf (fp, "       pop\n");
1320  fprintf (fp, "       /rgbproc exch def\n");
1321  fprintf (fp, "       { bwproc } image\n");
1322  fprintf (fp, "   }  def\n");
1323  fprintf (fp, "} if\n");
1324  fprintf (fp, "/picstr %d string def\n", aImage.width() * aInColor);
1325  fprintf (fp, "%d %d scale\n", aImage.width(), aImage.height());
1326  fprintf (fp, "%d %d %d\n", aImage.width(), aImage.height(), 8);
1327  fprintf (fp, "[%d 0 0 %d 0 0]\n", aImage.width(), aImage.height());
1328  fprintf (fp, "{currentfile picstr readhexstring pop}\n");
1329  fprintf (fp, "false %d\n", aInColor);
1330  fprintf (fp, "colorimage\n");
1331 
1332
1333  int width = aImage.width();
1334  int height = aImage.height();
1335  int depth = aImage.depth();
1336  int size = width*height;
1337 
1338  if (depth == 1)
1339    size = (width+7)/8*height;
1340  else if (aInColor == 1)
1341    size = size*3;
1342 
1343  int i = 0;
1344  if (depth == 1) {
1345    //  To be implemented
1346    //    QImage::Endian bitOrder = aImage.bitOrder();
1347    /*    for(int y=0; y < height; y++) {
1348      const uchar * s = aImage.scanLine(y);
1349      for(int x=0; x < width; x++) {
1350        // need to copy bit for bit...
1351        bool b = (bitOrder == QImage::LittleEndian) ?
1352          (*(s + (x >> 3)) >> (x & 7)) & 1 :
1353          (*(s + (x >> 3)) << (x & 7)) & 0x80 ;
1354        if (b)
1355          pixel[i >> 3] ^= (0x80 >> (i & 7));
1356        i++;
1357      }
1358      // we need to align to 8 bit here
1359      i = (i+7) & 0xffffff8;
1360    }
1361    */
1362  } else if (depth == 8) {
1363#ifdef GEANT4_QT_DEBUG
1364    printf("has 8 bit\n");
1365#endif
1366    for(int y=height-1; y >=0 ; y--) {
1367      const uchar * s = aImage.scanLine(y);
1368      for(int x=0; x <width; x++) {
1369        QRgb rgb = aImage.color(s[x]);
1370        if (aInColor == 1) {
1371          fprintf (fp, " %02hx ",(unsigned char)qGray(rgb));
1372          i++;
1373        } else {
1374          fprintf (fp, " %02hx %02hx %02hx",
1375                   (unsigned char) qRed(rgb),
1376                   (unsigned char) qGreen(rgb),
1377                   (unsigned char) qBlue(rgb));
1378          i += 3;
1379        }
1380      }
1381      fprintf (fp, "\n");
1382    }
1383  } else {
1384#if QT_VERSION < 0x040000
1385  G4cerr << "GenerateEPS:: No alpha channel image with Qt3. This is only supported with Qt4" << G4endl;
1386#else
1387    bool alpha = aImage.hasAlphaChannel();
1388#ifdef GEANT4_QT_DEBUG
1389    printf("has else %d alpha %d\n",depth,alpha);
1390#endif
1391    for(int y=height-1; y >=0 ; y--) {
1392      QRgb * s = (QRgb*)(aImage.scanLine(y));
1393      for(int x=0; x <width; x++) {
1394        QRgb rgb = (*s++);
1395        if (alpha && qAlpha(rgb) < 0x40) // 25% alpha, convert to white -
1396          rgb = qRgb(0xff, 0xff, 0xff);
1397        if (aInColor == 1) {
1398          fprintf (fp, " %02hx ",(unsigned char)qGray(rgb));
1399          i++;
1400        } else {
1401          fprintf (fp, " %02hx %02hx %02hx",
1402                   (unsigned char) qRed(rgb),
1403                   (unsigned char) qGreen(rgb),
1404                   (unsigned char) qBlue(rgb));
1405          i += 3;
1406        }
1407      }
1408      fprintf (fp, "\n");
1409    }
1410#endif
1411
1412  }
1413
1414  fprintf (fp, "grestore\n");
1415  fprintf (fp, "showpage\n");
1416  fclose (fp);
1417
1418  return true;
1419}
1420/**
1421   Generate Postscript or PDF form image
1422   @param aFilename : name of file
1423   @param aInColor : numbers of colors : 1->BW 2->RGB
1424   @param aImage : Image to print
1425*/
1426bool G4OpenGLQtViewer::generatePS_PDF (
1427 QString aFilename
1428,int aInColor
1429,QImage aImage
1430)
1431{
1432#if QT_VERSION < 0x040000
1433#ifdef Q_WS_MAC || Q_WS_X11
1434  QPrinter printer;
1435  //  printer.setPageSize(pageSize);
1436  if (aInColor == 1) {
1437    printer.setColorMode(QPrinter::GrayScale);
1438  } else {
1439    printer.setColorMode(QPrinter::Color);
1440  }
1441
1442  /* FIXME : I don't know which format it will save...
1443     if (aFilename.endsWith(".ps")) {
1444     printer.setOutputFormat(QPrinter::PostScriptFormat);
1445     } else {
1446     printer.setOutputFormat(QPrinter::PdfFormat);
1447     }
1448  */
1449  printer.setOutputFileName(aFilename);
1450  //  printer.setFullPage ( true);
1451  QPainter paint(&printer);
1452  paint.drawImage (0,0,aImage );
1453  paint.end();
1454#else
1455  G4cerr << "This fonction is only supported on Mac OsX or X11 with Qt3. Full platform supported with Qt4" << G4endl;
1456#endif
1457#else
1458  QPrinter printer;
1459  //  printer.setPageSize(pageSize);
1460  if (aInColor == 1) {
1461    printer.setColorMode(QPrinter::GrayScale);
1462  } else {
1463    printer.setColorMode(QPrinter::Color);
1464  }
1465
1466  if (aFilename.endsWith(".ps")) {
1467#if QT_VERSION > 0x040200
1468    printer.setOutputFormat(QPrinter::PostScriptFormat);
1469#endif
1470  } else {
1471#if QT_VERSION > 0x040100
1472    printer.setOutputFormat(QPrinter::PdfFormat);
1473#endif
1474  }
1475#if QT_VERSION > 0x040100
1476  printer.setOutputFileName(aFilename);
1477#endif
1478  //  printer.setFullPage ( true);
1479  QPainter paint(&printer);
1480  paint.drawImage (0,0,aImage );
1481  paint.end();
1482#endif
1483  return true;
1484}
1485
1486#endif
1487
1488/*
1489
1490void MultiLayer::exportToSVG(const QString& fname)
1491{
1492  QPicture picture;
1493  QPainter p(&picture);
1494  for (int i=0;i<(int)graphsList->count();i++)
1495    {
1496      Graph *gr=(Graph *)graphsList->at(i);
1497      Plot *myPlot= (Plot *)gr->plotWidget();
1498     
1499      QPoint pos=gr->pos();
1500     
1501      int width=int(myPlot->frameGeometry().width());
1502      int height=int(myPlot->frameGeometry().height());
1503     
1504      myPlot->print(&p, QRect(pos,QSize(width,height)));
1505    }
1506 
1507  p.end();
1508  picture.save(fname, "svg");
1509}
1510*/
Note: See TracBrowser for help on using the repository browser.