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

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

modif pour les formats d export

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