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

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

r599@mac-90108: laurentgarnier | 2007-09-18 18:43:19 +0200
correction du ticket #72 et la suppresion de la fenetre OpenGL entraine desormais un message d erreur lors du prochain BeamOn

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