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

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

r581@mac-90108: laurentgarnier | 2007-08-17 17:30:26 +0200
deplacement de frame

  • Property svn:mime-type set to text/cpp
File size: 23.3 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.17 2006/06/29 21:19:36 gunter Exp $
28// GEANT4 tag $Name: geant4-08-01-patch-01 $
29//
30//
31// G4OpenGLQtViewer : Class to provide Qt specific
32//                     functionality for OpenGL in GEANT4
33//
34// 27/06/2003 : G.Barrand : implementation (at last !).
35
36#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
37
38#include "G4OpenGLQtViewer.hh"
39
40#include "G4ios.hh"
41#include "G4VisExtent.hh"
42#include "G4LogicalVolume.hh"
43#include "G4VSolid.hh"
44#include "G4Point3D.hh"
45#include "G4Normal3D.hh"
46#include "G4Scene.hh"
47
48#include "G4Qt.hh"
49#include "G4UIsession.hh"
50#include "G4UImanager.hh"
51#include <QtGui/qboxlayout.h>
52#include <QtGui/qdialog.h>
53#include <QtGui/qmenu.h>
54#include <QFileDialog.h>
55
56//////////////////////////////////////////////////////////////////////////////
57/**
58   Implementation of virtual method of G4VViewer
59*/
60void G4OpenGLQtViewer::SetView (
61)
62//////////////////////////////////////////////////////////////////////////////
63//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
64{
65  printf("G4OpenGLQtViewer::SetView ++++++++++++++++++++\n");
66  //   if(!fHDC) return;
67  //   if(!fHGLRC) return;
68  //   ::wglMakeCurrent(fHDC,fHGLRC);
69  //  fWindow->makeCurrent();
70  G4OpenGLViewer::SetView (); 
71  printf("G4OpenGLQtViewer::SetView --------------------\n");
72}
73
74
75
76//////////////////////////////////////////////////////////////////////////////
77/**
78   Implementation of virtual method of G4VViewer
79*/
80void G4OpenGLQtViewer::ShowView (
81)
82//////////////////////////////////////////////////////////////////////////////
83//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
84{
85  printf("G4OpenGLQtViewer::ShowView  +++++++++++++++++++++\n");
86  glFlush ();
87  GLWindow->activateWindow();
88  printf("G4OpenGLQtViewer::ShowView -----------------------\n");
89
90  //   // Empty the Windows message queue :
91  //   MSG event;
92  //   while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
93  //     ::TranslateMessage(&event);
94  //     ::DispatchMessage (&event);
95  //   }
96}
97
98
99
100//////////////////////////////////////////////////////////////////////////////
101void G4OpenGLQtViewer::CreateGLQtContext (
102)
103//////////////////////////////////////////////////////////////////////////////
104//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
105{
106  printf("G4OpenGLQtViewer::CreateGLQtContext \n");
107}
108
109
110//////////////////////////////////////////////////////////////////////////////
111void G4OpenGLQtViewer::CreateMainWindow (
112                                         QGLWidget* glWidget
113                                         )
114//////////////////////////////////////////////////////////////////////////////
115//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
116{
117
118  if(fWindow) return; //Done.
119  printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n");
120
121  // launch Qt if not
122  G4Qt* interactorManager = G4Qt::getInstance ();
123  //  G4UImanager* UI = G4UImanager::GetUIpointer();
124
125  fWindow = glWidget ;
126  //  fWindow->makeCurrent();
127
128  // create window
129  if (((QApplication*)interactorManager->GetMainInteractor())) {
130    // look for the main window
131    bool found = false;
132    foreach (QWidget *widget, QApplication::allWidgets()) {
133      if ((found== false) && (widget->inherits("QMainWindow"))) {
134        GLWindow = new QDialog(widget);
135        found = true;
136      }
137    }
138    if (found==false) {
139      GLWindow = new QDialog();
140    }
141  } else {
142    GLWindow = new QDialog();
143  }
144
145  QHBoxLayout *mainLayout = new QHBoxLayout;
146
147  mainLayout->addWidget(fWindow);
148  GLWindow->setLayout(mainLayout);
149  GLWindow->setWindowTitle("QGl Viewer");
150  GLWindow->resize(300, 300);
151  GLWindow->move(900,300);
152  GLWindow->show();
153 
154  WinSize_x = 400;
155  WinSize_y = 400;
156  if (WinSize_x < fVP.GetWindowSizeHintX ())
157    WinSize_x = fVP.GetWindowSizeHintX ();
158  if (WinSize_y < fVP.GetWindowSizeHintY ())
159    WinSize_y = fVP.GetWindowSizeHintY ();
160
161  if(!fWindow) return;
162  printf("G4OpenGLQtViewer::CreateMainWindow glWidget END\n");
163
164  if (!fContextMenu)
165    createPopupMenu();
166
167}
168
169//////////////////////////////////////////////////////////////////////////////
170G4OpenGLQtViewer::G4OpenGLQtViewer (
171                                    G4OpenGLSceneHandler& scene
172                                    )
173  :G4VViewer (scene, -1)
174  ,G4OpenGLViewer (scene)
175  ,fWindow(0)
176  ,fContextMenu(0)
177  ,fMouseAction(true)
178{
179  printf("G4OpenGLQtViewer::G4OpenGLQtViewer \n");
180}
181
182//////////////////////////////////////////////////////////////////////////////
183G4OpenGLQtViewer::~G4OpenGLQtViewer (
184)
185//////////////////////////////////////////////////////////////////////////////
186//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
187{
188  printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n");
189  delete fContextMenu;   
190}
191
192
193/**
194   Create a popup menu for the widget. This menu is activated by right-mouse click
195*/
196void G4OpenGLQtViewer::createPopupMenu()    {
197
198  fContextMenu = new QMenu("All");
199
200  QMenu *mMouseAction = fContextMenu->addMenu("&Mouse action");
201  QAction *rotate = mMouseAction->addAction("&Rotate scene");
202  QAction *move = mMouseAction->addAction("&Move scene");
203  // INIT mMouse
204  createRadioAction(rotate,move,SLOT(toggleMouseAction(bool)),1);
205
206  //Style Menu
207  QMenu *mStyle = fContextMenu->addMenu("&Style");
208
209  QMenu *mRepresentation = mStyle->addMenu("&Representation");
210  QAction *polyhedron = mRepresentation->addAction("Polyhedron");
211  QAction *nurbs = mRepresentation->addAction("NURBS");
212  // INIT mStyle
213  G4ViewParameters::RepStyle style;
214  style = fVP.GetRepStyle();
215  if (style == G4ViewParameters::polyhedron) {
216    createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),1);
217  } else if (style == G4ViewParameters::nurbs) {
218    createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),2);
219  } else {
220    mRepresentation->clear();
221  }
222
223
224  QMenu *mDrawing = mStyle->addMenu("&Drawing");
225  fDrawingWireframe = mDrawing->addAction("Wireframe");
226  fDrawingWireframe->setCheckable(true);
227  fDrawingWireframe->setChecked(true);
228  fDrawingLineRemoval = mDrawing->addAction("Hidden line removal");
229  fDrawingLineRemoval->setCheckable(true);
230  fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal");
231  fDrawingSurfaceRemoval->setCheckable(true);
232  fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal");
233  fDrawingLineSurfaceRemoval->setCheckable(true);
234  // INIT Drawing
235  G4ViewParameters::DrawingStyle d_style;
236  d_style = fVP.GetDrawingStyle();
237 
238  fDrawingWireframe->setCheckable(true);
239  fDrawingLineRemoval->setCheckable(true);
240  fDrawingSurfaceRemoval->setCheckable(true);
241  fDrawingLineSurfaceRemoval->setCheckable(true);
242
243  if (d_style == G4ViewParameters::wireframe) {
244    fDrawingWireframe->setChecked(true);
245  } else if (d_style == G4ViewParameters::hlr) {
246    fDrawingLineRemoval->setChecked(true);
247  } else if (d_style == G4ViewParameters::hsr) {
248    fDrawingSurfaceRemoval->setChecked(true);
249  } else if (d_style == G4ViewParameters::hlhsr) {
250    fDrawingLineSurfaceRemoval->setChecked(true);
251  } else {
252    mDrawing->clear();
253  }
254
255  QObject ::connect(fDrawingWireframe,
256                    SIGNAL(triggered(bool)),
257                    this,
258                    SLOT(actionDrawingWireframe()));
259  QObject ::connect(fDrawingLineRemoval,
260                    SIGNAL(triggered(bool)),
261                    this,
262                    SLOT(actionDrawingLineRemoval()));
263  QObject ::connect(fDrawingSurfaceRemoval,
264                    SIGNAL(triggered(bool)),
265                    this,
266                    SLOT(actionDrawingSurfaceRemoval()));
267  QObject ::connect(fDrawingLineSurfaceRemoval,
268                    SIGNAL(triggered(bool)),
269                    this,
270                    SLOT(actionDrawingLineSurfaceRemoval()));
271
272
273  QMenu *mBackground = mStyle->addMenu("&Background color");
274  QAction *white = mBackground->addAction("White");
275  QAction *black = mBackground->addAction("Black");
276  if (background.GetRed() == 1. &&
277      background.GetGreen() == 1. &&
278      background.GetBlue() == 1.) {
279    createRadioAction(white,black,SLOT(toggleBackground(bool)),1);
280  } else {
281    createRadioAction(white,black,SLOT(toggleBackground(bool)),2);
282  }
283
284
285  // Action Menu
286  QMenu *mActions = fContextMenu->addMenu("&Actions");
287  QAction *controlPanels = mActions->addAction("Control panels");
288  QAction *exitG4 = mActions->addAction("Exit to G4Vis >");
289  QAction *createEPS = mActions->addAction("Save as ...");
290  QObject ::connect(controlPanels,
291                    SIGNAL(triggered()),
292                    this,
293                    SLOT(actionControlPanels()));
294  QObject ::connect(exitG4,
295                    SIGNAL(triggered()),
296                    this,
297                    SLOT(actionExitG4()));
298  QObject ::connect(createEPS,
299                    SIGNAL(triggered()),
300                    this,
301                    SLOT(actionCreateEPS()));
302
303
304  // Special Menu
305  QMenu *mSpecial = fContextMenu->addMenu("S&pecial");
306  QMenu *transparency = mSpecial->addMenu("Transparency");
307  QAction *transparencyOn = transparency->addAction("On");
308  QAction *transparencyOff = transparency->addAction("Off");
309  if (transparency_enabled == false) {
310    createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2);
311  } else if (transparency_enabled == true) {
312    createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),1);
313  } else {
314    mSpecial->clear();
315  }
316
317
318  QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing");
319  QAction *antialiasingOn = mAntialiasing->addAction("On");
320  QAction *antialiasingOff = mAntialiasing->addAction("Off");
321  if (antialiasing_enabled == false) {
322    createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2);
323  } else if (antialiasing_enabled == true) {
324    createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),1);
325  } else {
326    mAntialiasing->clear();
327  }
328
329  QMenu *mHaloing = mSpecial->addMenu("Haloing");
330  QAction *haloingOn = mHaloing->addAction("On");
331  QAction *haloingOff = mHaloing->addAction("Off");
332  if (haloing_enabled == false) {
333    createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2);
334  } else if (haloing_enabled == true) {
335    createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),1);
336  } else {
337    mHaloing->clear();
338  }
339
340  QMenu *mAux = mSpecial->addMenu("Auxiliary edges");
341  QAction *auxOn = mAux->addAction("On");
342  QAction *auxOff = mAux->addAction("Off");
343  if (!fVP.IsAuxEdgeVisible()) {
344    createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1);
345  } else {
346    createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),2);
347  }
348
349
350  QMenu *mFullScreen = mSpecial->addMenu("Full screen");
351  QAction *fullOn = mFullScreen->addAction("On");
352  QAction *fullOff = mFullScreen->addAction("Off");
353  createRadioAction(fullOn,fullOff,SLOT(toggleFullScreen(bool)),2);
354
355}
356
357void G4OpenGLQtViewer::manageContextMenuEvent(QContextMenuEvent *e)
358{
359  if (!GLWindow) return;
360 
361  if (!fContextMenu)
362    createPopupMenu();
363
364  // launch menu
365  if ( fContextMenu ) {
366    fContextMenu->exec( e->globalPos() );
367    //    delete fContextMenu;
368  }
369  e->accept();
370}
371
372
373/**
374   Create a radio button menu. The two menu will be connected. When click on one,
375   eatch state will be invert and callback method will be called.
376   @param action1 first action to connect
377   @param action2 second action to connect
378   @param method callback method
379   @param nCheck: 1 : first action will be set true. 2 : second action will be set true
380*/
381void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
382
383  action1->setCheckable(true);
384  action2->setCheckable(true);
385
386  if (nCheck ==1)
387    action1->setChecked (true);
388  else
389    action2->setChecked (true);
390   
391  QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle()));
392  QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle()));
393
394  QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str());
395
396}
397
398/**
399   Slot activate when drawing->wireframe menu is set
400 */
401void G4OpenGLQtViewer::actionDrawingWireframe() {
402  emit toggleDrawingAction(1);
403}
404
405/**
406   Slot activate when drawing->line removal menu is set
407 */
408void G4OpenGLQtViewer::actionDrawingLineRemoval() {
409  emit toggleDrawingAction(2);
410}
411
412/**
413   Slot activate when drawing->surface removal menu is set
414 */
415void G4OpenGLQtViewer::actionDrawingSurfaceRemoval() {
416  emit toggleDrawingAction(3);
417}
418
419/**
420   Slot activate when drawing->wireframe menu is set
421 */
422void G4OpenGLQtViewer::actionDrawingLineSurfaceRemoval() {
423  emit toggleDrawingAction(4);
424}
425
426
427/**
428   Slot activated when drawing menu is toggle
429   Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
430   KernelVisitDecision () will be call and will set the fNeedKernelVisit
431   to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
432   It will cause a redraw of the view
433   @param aAction : 1 wireframe, 2 line removal, 3 surface removal, 4 line & surface removal
434   @see G4OpenGLStoredQtViewer::DrawView
435   @see G4XXXStoredViewer::CompareForKernelVisit
436 */
437void G4OpenGLQtViewer::toggleDrawingAction(int aAction) {
438
439  G4ViewParameters::DrawingStyle d_style;
440 
441
442  if (aAction ==1) {
443    fDrawingWireframe->setChecked (true);
444    fDrawingLineRemoval->setChecked (false);
445    fDrawingSurfaceRemoval->setChecked (false);
446    fDrawingLineSurfaceRemoval->setChecked (false);
447
448    d_style = G4ViewParameters::wireframe;
449
450  } else  if (aAction ==2) {
451    fDrawingWireframe->setChecked (false);
452    fDrawingLineRemoval->setChecked (true);
453    fDrawingSurfaceRemoval->setChecked (false);
454    fDrawingLineSurfaceRemoval->setChecked (false);
455
456    d_style = G4ViewParameters::hlr;
457
458  } else  if (aAction ==3) {
459    fDrawingWireframe->setChecked (false);
460    fDrawingLineRemoval->setChecked (false);
461    fDrawingSurfaceRemoval->setChecked (true);
462    fDrawingLineSurfaceRemoval->setChecked (false);
463
464    d_style = G4ViewParameters::hsr;
465
466  } else  if (aAction ==4) {
467    fDrawingWireframe->setChecked (false);
468    fDrawingLineRemoval->setChecked (false);
469    fDrawingSurfaceRemoval->setChecked (false);
470    fDrawingLineSurfaceRemoval->setChecked (true);
471
472    d_style = G4ViewParameters::hlhsr;
473  }
474  fVP.SetDrawingStyle(d_style);
475
476  updateQWidget();
477  printf("G4OpenGLQtViewer::toggleDrawingAction\n");
478}
479
480
481/**
482   SLOT Activate by a click on the representation menu
483   Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
484   KernelVisitDecision () will be call and will set the fNeedKernelVisit
485   to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
486   It will cause a redraw of the view
487   @param check : 1 polyhedron, 0 nurbs
488   @see G4OpenGLStoredQtViewer::DrawView
489   @see G4XXXStoredViewer::CompareForKernelVisit
490*/
491void G4OpenGLQtViewer::toggleRepresentation(bool check) {
492
493  G4ViewParameters::RepStyle style;
494  if (check == 1) {
495    style = G4ViewParameters::polyhedron;
496  } else {
497    style = G4ViewParameters::nurbs;
498  }
499  fVP.SetRepStyle (style);
500
501  printf("G4OpenGLQtViewer::toggleRepresentation 3%d\n",check);
502  updateQWidget();
503  printf("G4OpenGLQtViewer::toggleRepresentation 4%d\n",check);
504}
505
506/**
507   SLOT Activate by a click on the background menu
508@param check : 1 white, 0 black
509*/
510void G4OpenGLQtViewer::toggleBackground(bool check) {
511
512  //   //I need to revisit the kernel if the background colour changes and
513  //   //hidden line removal is enabled, because hlr drawing utilises the
514  //   //background colour in its drawing...
515  //   // (Note added by JA 13/9/2005) Background now handled in view
516  //   // parameters.  A kernel visit is triggered on change of background.
517  if (check == 1) {
518    ((G4ViewParameters&)this->GetViewParameters()).
519      SetBackgroundColour(G4Colour(1.,1.,1.));  // White
520  } else {
521    ((G4ViewParameters&)this->GetViewParameters()).
522      SetBackgroundColour(G4Colour(0.,0.,0.));  // Black
523  }
524  updateQWidget();
525}
526
527/**
528   SLOT Activate by a click on the transparency menu
529@param check : 1 , 0
530*/
531void G4OpenGLQtViewer::toggleTransparency(bool check) {
532 
533  if (check) {
534    transparency_enabled = false;
535  } else {
536    transparency_enabled = true;
537  }
538  SetNeedKernelVisit (true);
539  updateQWidget();
540}
541
542/**
543   SLOT Activate by a click on the antialiasing menu
544@param check : 1 , 0
545*/
546void G4OpenGLQtViewer::toggleAntialiasing(bool check) {
547
548  if (!check) {
549    antialiasing_enabled = false;
550    glDisable (GL_LINE_SMOOTH);
551    glDisable (GL_POLYGON_SMOOTH);
552  } else {
553    antialiasing_enabled = true;
554    glEnable (GL_LINE_SMOOTH);
555    glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
556    glEnable (GL_POLYGON_SMOOTH);
557    glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
558  }
559
560  updateQWidget();
561  printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
562}
563
564/**
565   SLOT Activate by a click on the haloing menu
566@param check : 1 , 0
567*/
568//FIXME : I SEE NOTHING...
569void G4OpenGLQtViewer::toggleHaloing(bool check) {
570  if (check) {
571    haloing_enabled = false;
572  } else {
573    haloing_enabled = true;
574  }
575
576  updateQWidget();
577
578  printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
579}
580
581/**
582   SLOT Activate by a click on the auxiliaire edges menu
583@param check : 1 , 0
584*/
585void G4OpenGLQtViewer::toggleAux(bool check) {
586  if (check) {
587    fVP.SetAuxEdgeVisible(false);
588  } else {
589    fVP.SetAuxEdgeVisible(true);
590  }
591  SetNeedKernelVisit (true);
592  updateQWidget();
593
594  printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
595}
596
597/**
598   SLOT Activate by a click on the full screen menu
599@param check : 1 , 0
600*/
601void G4OpenGLQtViewer::toggleFullScreen(bool check) {
602  GLWindow->setWindowState(GLWindow->windowState() ^ Qt::WindowFullScreen);
603
604  printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
605}
606
607/**
608   SLOT Activate by a click on the mouse action menu
609   @param check : 1 , 0
610*/
611void G4OpenGLQtViewer::toggleMouseAction(bool check) {
612  if (check) { // rotate scene
613    fMouseAction = true;
614  } else { // move scene
615    fMouseAction = false;
616  }
617
618  printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
619}
620
621
622void G4OpenGLQtViewer::actionControlPanels() {
623  printf("G4OpenGLQtViewer::actionControlPanels \n");
624}
625
626void G4OpenGLQtViewer::actionExitG4() {
627  printf("G4OpenGLQtViewer::actionExitG4() \n");
628}
629
630void G4OpenGLQtViewer::actionCreateEPS() {
631  //QString QFileDialog::getSaveFileName ( QWidget * parent = 0,
632  //  const QString & caption = QString(),
633  // const QString & dir = QString(),
634  // const QString & filter = QString(),
635  // QString * selectedFilter = 0, Options options = 0 )
636  QString nomFich = QFileDialog::getSaveFileName(GLWindow,
637                                                 "Choose a file",
638                                                 ".", tr("Images (*.BMP *.GIF *.JPG *.JPEG *.PNG *.PBM *.PGM *.PPM *.TIFF *.XBM *.XPM)") );
639
640  if(!nomFich.endsWith(".eps")) {
641    printf("G4OpenGLQtViewer::actionCreateEPS() COULD NOT GENERATE EPS FOR THE MOMENT\n");
642  } else {
643    fWindow->grabFrameBuffer().save(nomFich);
644  }
645  printf("G4OpenGLQtViewer::actionCreateEPS() \n");
646}
647
648
649
650/**
651   Save the current mouse press point
652   @param p mouse click point
653*/
654void G4OpenGLQtViewer::G4MousePressEvent(QPoint p)
655{
656  lastPos = p;
657}
658
659/**
660   @param pos_x mouse x position
661   @param pos_y mouse y position
662   @param mButtons mouse button active
663*/
664void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons)
665{
666  int dx = pos_x - lastPos.x();
667  int dy = pos_y - lastPos.y();
668 
669  if (fMouseAction) {  // rotate
670    if (mButtons & Qt::LeftButton) {
671      //phi spin stuff here
672     
673      G4Vector3D vp = fVP.GetViewpointDirection ().unit ();
674      G4Vector3D up = fVP.GetUpVector ().unit ();
675     
676      G4Vector3D yprime = (up.cross(vp)).unit();
677      G4Vector3D zprime = (vp.cross(yprime)).unit();
678     
679      G4double delta_alpha;
680      G4double delta_theta;
681     
682      if (fVP.GetLightsMoveWithCamera()) {
683        delta_alpha = dy;
684        delta_theta = -dx;
685      } else {
686        delta_alpha = -dy;
687        delta_theta = dx;
688      }   
689
690      delta_alpha *= deg;
691      delta_theta *= deg;
692
693      G4Vector3D new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime;
694     
695      G4Vector3D new_up;
696      if (fVP.GetLightsMoveWithCamera()) {
697        new_up = (new_vp.cross(yprime)).unit();
698        fVP.SetUpVector(new_up);
699      } else {
700        new_up = up;
701      }
702      ////////////////
703      // Rotates by fixed azimuthal angle delta_theta.
704
705      G4double cosalpha = new_up.dot (new_vp.unit());
706      G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));
707      yprime = (new_up.cross (new_vp.unit())).unit ();
708      G4Vector3D xprime = yprime.cross (new_up);
709      // Projection of vp on plane perpendicular to up...
710      G4Vector3D a1 = sinalpha * xprime;
711      // Required new projection...
712      G4Vector3D a2 =
713        sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);
714      // Required Increment vector...
715      G4Vector3D delta = a2 - a1;
716      // So new viewpoint is...
717      G4Vector3D viewPoint = new_vp.unit() + delta;
718
719      fVP.SetViewAndLights (viewPoint);
720      updateQWidget();
721     
722    } else if (mButtons & Qt::RightButton) {
723      // NEVER DONE BECAUSE OF MOUSE MENU
724      //       printf("G4OpenGLQtViewer::mouseMoveEvent Right \n");
725      //       setXRotation(xRot + dy/2);
726      //       setZRotation(zRot + dx/2);
727      //       updateQWidget();
728    }
729  } else {  // move
730
731    float dx = pos_x - lastPos.x();
732    float dy = pos_y - lastPos.y();
733   
734    G4Point3D stp
735      = GetSceneHandler()->GetScene()->GetStandardTargetPoint();
736   
737    G4Point3D tp = stp + fVP.GetCurrentTargetPoint ();
738   
739    const G4Vector3D& upVector = fVP.GetUpVector ();
740    const G4Vector3D& vpVector = fVP.GetViewpointDirection ();
741   
742    G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
743    G4Vector3D unitUp    = (vpVector.cross (unitRight)).unit();
744   
745    tp += -dx * unitRight + dy * unitUp;
746    fVP.SetCurrentTargetPoint (tp - stp);
747   
748    updateQWidget();
749  }
750  lastPos = QPoint(pos_x, pos_y);
751}
752
753
754#endif
Note: See TracBrowser for help on using the repository browser.