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

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

r610@mac-90108: laurentgarnier | 2007-09-25 16:54:15 +0200
boite de dialogue presque ok, reste plus qu a connecter

  • Property svn:mime-type set to text/cpp
File size: 29.8 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#include "G4OpenGLQtExportDialog.hh"
48
49#include "G4Qt.hh"
50#include "G4UIsession.hh"
51#include "G4UImanager.hh"
52#include <QtGui/qboxlayout.h>
53#include <QtGui/qdialog.h>
54#include <QtGui/qmenu.h>
55#include <QImageWriter>
56#include <QMessageBox>
57#include <QFileDialog.h>
58
59//////////////////////////////////////////////////////////////////////////////
60/**
61   Implementation of virtual method of G4VViewer
62*/
63void G4OpenGLQtViewer::SetView (
64)
65//////////////////////////////////////////////////////////////////////////////
66//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
67{
68  printf("G4OpenGLQtViewer::SetView ++++++++++++++++++++\n");
69  //   if(!fHDC) return;
70  //   if(!fHGLRC) return;
71  //   ::wglMakeCurrent(fHDC,fHGLRC);
72  //  fWindow->makeCurrent();
73  G4OpenGLViewer::SetView ();
74  printf("G4OpenGLQtViewer::SetView --------------------\n");
75}
76
77
78
79//////////////////////////////////////////////////////////////////////////////
80/**
81   Implementation of virtual method of G4VViewer
82*/
83void G4OpenGLQtViewer::ShowView (
84)
85//////////////////////////////////////////////////////////////////////////////
86//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
87{
88  printf("G4OpenGLQtViewer::ShowView  +++++++++++++++++++++\n");
89  glFlush ();
90  if (!GLWindow) {
91    G4cerr << "Visualization window not defined, please choose one before" << G4endl;
92  } else {
93    GLWindow->activateWindow();
94    printf("G4OpenGLQtViewer::ShowView -----------------------\n");
95  }
96  //   // Empty the Windows message queue :
97  //   MSG event;
98  //   while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
99  //     ::TranslateMessage(&event);
100  //     ::DispatchMessage (&event);
101  //   }
102}
103
104
105
106//////////////////////////////////////////////////////////////////////////////
107void G4OpenGLQtViewer::CreateGLQtContext (
108)
109//////////////////////////////////////////////////////////////////////////////
110//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
111{
112  printf("G4OpenGLQtViewer::CreateGLQtContext \n");
113}
114
115
116//////////////////////////////////////////////////////////////////////////////
117void G4OpenGLQtViewer::CreateMainWindow (
118 QGLWidget* glWidget
119)
120//////////////////////////////////////////////////////////////////////////////
121//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
122{
123
124  if(fWindow) return; //Done.
125  printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n");
126
127  // launch Qt if not
128  G4Qt* interactorManager = G4Qt::getInstance ();
129  //  G4UImanager* UI = G4UImanager::GetUIpointer();
130
131  fWindow = glWidget ;
132  //  fWindow->makeCurrent();
133
134  // create window
135  if (((QApplication*)interactorManager->GetMainInteractor())) {
136    // look for the main window
137    bool found = false;
138    foreach (QWidget *widget, QApplication::allWidgets()) {
139      if ((found== false) && (widget->inherits("QMainWindow"))) {
140        printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
141        GLWindow = new QDialog(widget,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
142        found = true;
143      }
144    }
145    if (found==false) {
146      printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n");
147      GLWindow = new QDialog();
148    }
149  } else {
150    printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
151    GLWindow = new QDialog();
152  }
153
154  QHBoxLayout *mainLayout = new QHBoxLayout;
155
156  mainLayout->addWidget(fWindow);
157  GLWindow->setLayout(mainLayout);
158  GLWindow->setWindowTitle("QGl Viewer");
159  GLWindow->resize(300, 300);
160  GLWindow->move(900,300);
161  GLWindow->show();
162 
163  // delete the pointer if close this
164  //  GLWindow->setAttribute(Qt::WA_DeleteOnClose);
165
166  QObject ::connect(GLWindow,
167                    SIGNAL(rejected()),
168                    this,
169                    SLOT(dialogClosed()));
170
171  WinSize_x = 400;
172  WinSize_y = 400;
173  if (WinSize_x < fVP.GetWindowSizeHintX ())
174    WinSize_x = fVP.GetWindowSizeHintX ();
175  if (WinSize_y < fVP.GetWindowSizeHintY ())
176    WinSize_y = fVP.GetWindowSizeHintY ();
177
178  if(!fWindow) return;
179  printf("G4OpenGLQtViewer::CreateMainWindow glWidget END\n");
180
181  if (!fContextMenu)
182    createPopupMenu();
183
184}
185
186/**  Close the dialog and set the pointer to NULL
187 */
188void G4OpenGLQtViewer::dialogClosed() {
189  GLWindow = NULL;
190}
191
192
193//////////////////////////////////////////////////////////////////////////////
194G4OpenGLQtViewer::G4OpenGLQtViewer (
195                                    G4OpenGLSceneHandler& scene
196                                    )
197  :G4VViewer (scene, -1)
198  ,G4OpenGLViewer (scene)
199  ,fWindow(0)
200  ,fContextMenu(0)
201  ,fMouseAction(true)
202{
203  printf("G4OpenGLQtViewer::G4OpenGLQtViewer \n");
204}
205
206//////////////////////////////////////////////////////////////////////////////
207G4OpenGLQtViewer::~G4OpenGLQtViewer (
208)
209//////////////////////////////////////////////////////////////////////////////
210//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
211{
212  printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n");
213  delete fContextMenu;
214}
215
216
217/**
218   Create a popup menu for the widget. This menu is activated by right-mouse click
219*/
220void G4OpenGLQtViewer::createPopupMenu()    {
221
222  fContextMenu = new QMenu("All");
223
224  QMenu *mMouseAction = fContextMenu->addMenu("&Mouse action");
225  QAction *rotate = mMouseAction->addAction("&Rotate scene");
226  QAction *move = mMouseAction->addAction("&Move scene");
227  // INIT mMouse
228  createRadioAction(rotate,move,SLOT(toggleMouseAction(bool)),1);
229
230  //Style Menu
231  QMenu *mStyle = fContextMenu->addMenu("&Style");
232
233  QMenu *mRepresentation = mStyle->addMenu("&Representation");
234  QAction *polyhedron = mRepresentation->addAction("Polyhedron");
235  QAction *nurbs = mRepresentation->addAction("NURBS");
236  // INIT mStyle
237  G4ViewParameters::RepStyle style;
238  style = fVP.GetRepStyle();
239  if (style == G4ViewParameters::polyhedron) {
240    createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),1);
241  } else if (style == G4ViewParameters::nurbs) {
242    createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),2);
243  } else {
244    mRepresentation->clear();
245  }
246
247
248  QMenu *mDrawing = mStyle->addMenu("&Drawing");
249  fDrawingWireframe = mDrawing->addAction("Wireframe");
250  fDrawingWireframe->setCheckable(true);
251  fDrawingWireframe->setChecked(true);
252  fDrawingLineRemoval = mDrawing->addAction("Hidden line removal");
253  fDrawingLineRemoval->setCheckable(true);
254  fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal");
255  fDrawingSurfaceRemoval->setCheckable(true);
256  fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal");
257  fDrawingLineSurfaceRemoval->setCheckable(true);
258  // INIT Drawing
259  G4ViewParameters::DrawingStyle d_style;
260  d_style = fVP.GetDrawingStyle();
261 
262  fDrawingWireframe->setCheckable(true);
263  fDrawingLineRemoval->setCheckable(true);
264  fDrawingSurfaceRemoval->setCheckable(true);
265  fDrawingLineSurfaceRemoval->setCheckable(true);
266
267  if (d_style == G4ViewParameters::wireframe) {
268    fDrawingWireframe->setChecked(true);
269  } else if (d_style == G4ViewParameters::hlr) {
270    fDrawingLineRemoval->setChecked(true);
271  } else if (d_style == G4ViewParameters::hsr) {
272    fDrawingSurfaceRemoval->setChecked(true);
273  } else if (d_style == G4ViewParameters::hlhsr) {
274    fDrawingLineSurfaceRemoval->setChecked(true);
275  } else {
276    mDrawing->clear();
277  }
278
279  QObject ::connect(fDrawingWireframe,
280                    SIGNAL(triggered(bool)),
281                    this,
282                    SLOT(actionDrawingWireframe()));
283  QObject ::connect(fDrawingLineRemoval,
284                    SIGNAL(triggered(bool)),
285                    this,
286                    SLOT(actionDrawingLineRemoval()));
287  QObject ::connect(fDrawingSurfaceRemoval,
288                    SIGNAL(triggered(bool)),
289                    this,
290                    SLOT(actionDrawingSurfaceRemoval()));
291  QObject ::connect(fDrawingLineSurfaceRemoval,
292                    SIGNAL(triggered(bool)),
293                    this,
294                    SLOT(actionDrawingLineSurfaceRemoval()));
295
296
297  QMenu *mBackground = mStyle->addMenu("&Background color");
298  QAction *white = mBackground->addAction("White");
299  QAction *black = mBackground->addAction("Black");
300  if (background.GetRed() == 1. &&
301      background.GetGreen() == 1. &&
302      background.GetBlue() == 1.) {
303    createRadioAction(white,black,SLOT(toggleBackground(bool)),1);
304  } else {
305    createRadioAction(white,black,SLOT(toggleBackground(bool)),2);
306  }
307
308
309  // Action Menu
310  QMenu *mActions = fContextMenu->addMenu("&Actions");
311  QAction *controlPanels = mActions->addAction("Control panels");
312  QAction *exitG4 = mActions->addAction("Exit to G4Vis >");
313  QAction *createEPS = mActions->addAction("Save as ...");
314  QObject ::connect(controlPanels,
315                    SIGNAL(triggered()),
316                    this,
317                    SLOT(actionControlPanels()));
318  QObject ::connect(exitG4,
319                    SIGNAL(triggered()),
320                    this,
321                    SLOT(actionExitG4()));
322  QObject ::connect(createEPS,
323                    SIGNAL(triggered()),
324                    this,
325                    SLOT(actionCreateEPS()));
326
327
328  // Special Menu
329  QMenu *mSpecial = fContextMenu->addMenu("S&pecial");
330  QMenu *transparency = mSpecial->addMenu("Transparency");
331  QAction *transparencyOn = transparency->addAction("On");
332  QAction *transparencyOff = transparency->addAction("Off");
333  if (transparency_enabled == false) {
334    createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2);
335  } else if (transparency_enabled == true) {
336    createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),1);
337  } else {
338    mSpecial->clear();
339  }
340
341
342  QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing");
343  QAction *antialiasingOn = mAntialiasing->addAction("On");
344  QAction *antialiasingOff = mAntialiasing->addAction("Off");
345  if (antialiasing_enabled == false) {
346    createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2);
347  } else if (antialiasing_enabled == true) {
348    createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),1);
349  } else {
350    mAntialiasing->clear();
351  }
352
353  QMenu *mHaloing = mSpecial->addMenu("Haloing");
354  QAction *haloingOn = mHaloing->addAction("On");
355  QAction *haloingOff = mHaloing->addAction("Off");
356  if (haloing_enabled == false) {
357    createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2);
358  } else if (haloing_enabled == true) {
359    createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),1);
360  } else {
361    mHaloing->clear();
362  }
363
364  QMenu *mAux = mSpecial->addMenu("Auxiliary edges");
365  QAction *auxOn = mAux->addAction("On");
366  QAction *auxOff = mAux->addAction("Off");
367  if (!fVP.IsAuxEdgeVisible()) {
368    createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1);
369  } else {
370    createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),2);
371  }
372
373
374  QMenu *mFullScreen = mSpecial->addMenu("Full screen");
375  QAction *fullOn = mFullScreen->addAction("On");
376  QAction *fullOff = mFullScreen->addAction("Off");
377  createRadioAction(fullOn,fullOff,SLOT(toggleFullScreen(bool)),2);
378
379}
380
381void G4OpenGLQtViewer::manageContextMenuEvent(QContextMenuEvent *e)
382{
383  if (!GLWindow) {
384    G4cerr << "Visualization window not defined, please choose one before" << G4endl;
385  } else {
386 
387    if (!fContextMenu)
388      createPopupMenu();
389   
390    // launch menu
391    if ( fContextMenu ) {
392      fContextMenu->exec( e->globalPos() );
393      //    delete fContextMenu;
394    }
395  }
396  e->accept();
397}
398
399
400/**
401   Create a radio button menu. The two menu will be connected. When click on one,
402   eatch state will be invert and callback method will be called.
403   @param action1 first action to connect
404   @param action2 second action to connect
405   @param method callback method
406   @param nCheck: 1 : first action will be set true. 2 : second action will be set true
407*/
408void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
409
410  action1->setCheckable(true);
411  action2->setCheckable(true);
412
413  if (nCheck ==1)
414    action1->setChecked (true);
415  else
416    action2->setChecked (true);
417   
418  QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle()));
419  QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle()));
420
421  QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str());
422
423}
424
425/**
426   Slot activate when drawing->wireframe menu is set
427 */
428void G4OpenGLQtViewer::actionDrawingWireframe() {
429  emit toggleDrawingAction(1);
430}
431
432/**
433   Slot activate when drawing->line removal menu is set
434 */
435void G4OpenGLQtViewer::actionDrawingLineRemoval() {
436  emit toggleDrawingAction(2);
437}
438
439/**
440   Slot activate when drawing->surface removal menu is set
441 */
442void G4OpenGLQtViewer::actionDrawingSurfaceRemoval() {
443  emit toggleDrawingAction(3);
444}
445
446/**
447   Slot activate when drawing->wireframe menu is set
448 */
449void G4OpenGLQtViewer::actionDrawingLineSurfaceRemoval() {
450  emit toggleDrawingAction(4);
451}
452
453
454/**
455   Slot activated when drawing menu is toggle
456   Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
457   KernelVisitDecision () will be call and will set the fNeedKernelVisit
458   to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
459   It will cause a redraw of the view
460   @param aAction : 1 wireframe, 2 line removal, 3 surface removal, 4 line & surface removal
461   @see G4OpenGLStoredQtViewer::DrawView
462   @see G4XXXStoredViewer::CompareForKernelVisit
463 */
464void G4OpenGLQtViewer::toggleDrawingAction(int aAction) {
465
466  G4ViewParameters::DrawingStyle d_style;
467 
468
469  if (aAction ==1) {
470    fDrawingWireframe->setChecked (true);
471    fDrawingLineRemoval->setChecked (false);
472    fDrawingSurfaceRemoval->setChecked (false);
473    fDrawingLineSurfaceRemoval->setChecked (false);
474
475    d_style = G4ViewParameters::wireframe;
476
477  } else  if (aAction ==2) {
478    fDrawingWireframe->setChecked (false);
479    fDrawingLineRemoval->setChecked (true);
480    fDrawingSurfaceRemoval->setChecked (false);
481    fDrawingLineSurfaceRemoval->setChecked (false);
482
483    d_style = G4ViewParameters::hlr;
484
485  } else  if (aAction ==3) {
486    fDrawingWireframe->setChecked (false);
487    fDrawingLineRemoval->setChecked (false);
488    fDrawingSurfaceRemoval->setChecked (true);
489    fDrawingLineSurfaceRemoval->setChecked (false);
490
491    d_style = G4ViewParameters::hsr;
492
493  } else  if (aAction ==4) {
494    fDrawingWireframe->setChecked (false);
495    fDrawingLineRemoval->setChecked (false);
496    fDrawingSurfaceRemoval->setChecked (false);
497    fDrawingLineSurfaceRemoval->setChecked (true);
498
499    d_style = G4ViewParameters::hlhsr;
500  }
501  fVP.SetDrawingStyle(d_style);
502
503  updateQWidget();
504  printf("G4OpenGLQtViewer::toggleDrawingAction\n");
505}
506
507
508/**
509   SLOT Activate by a click on the representation menu
510   Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
511   KernelVisitDecision () will be call and will set the fNeedKernelVisit
512   to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
513   It will cause a redraw of the view
514   @param check : 1 polyhedron, 0 nurbs
515   @see G4OpenGLStoredQtViewer::DrawView
516   @see G4XXXStoredViewer::CompareForKernelVisit
517*/
518void G4OpenGLQtViewer::toggleRepresentation(bool check) {
519
520  G4ViewParameters::RepStyle style;
521  if (check == 1) {
522    style = G4ViewParameters::polyhedron;
523  } else {
524    style = G4ViewParameters::nurbs;
525  }
526  fVP.SetRepStyle (style);
527
528  printf("G4OpenGLQtViewer::toggleRepresentation 3%d\n",check);
529  updateQWidget();
530  printf("G4OpenGLQtViewer::toggleRepresentation 4%d\n",check);
531}
532
533/**
534   SLOT Activate by a click on the background menu
535@param check : 1 white, 0 black
536*/
537void G4OpenGLQtViewer::toggleBackground(bool check) {
538
539  //   //I need to revisit the kernel if the background colour changes and
540  //   //hidden line removal is enabled, because hlr drawing utilises the
541  //   //background colour in its drawing...
542  //   // (Note added by JA 13/9/2005) Background now handled in view
543  //   // parameters.  A kernel visit is triggered on change of background.
544  if (check == 1) {
545    ((G4ViewParameters&)this->GetViewParameters()).
546      SetBackgroundColour(G4Colour(1.,1.,1.));  // White
547  } else {
548    ((G4ViewParameters&)this->GetViewParameters()).
549      SetBackgroundColour(G4Colour(0.,0.,0.));  // Black
550  }
551  updateQWidget();
552}
553
554/**
555   SLOT Activate by a click on the transparency menu
556@param check : 1 , 0
557*/
558void G4OpenGLQtViewer::toggleTransparency(bool check) {
559 
560  if (check) {
561    transparency_enabled = false;
562  } else {
563    transparency_enabled = true;
564  }
565  SetNeedKernelVisit (true);
566  updateQWidget();
567}
568
569/**
570   SLOT Activate by a click on the antialiasing menu
571@param check : 1 , 0
572*/
573void G4OpenGLQtViewer::toggleAntialiasing(bool check) {
574
575  if (!check) {
576    antialiasing_enabled = false;
577    glDisable (GL_LINE_SMOOTH);
578    glDisable (GL_POLYGON_SMOOTH);
579  } else {
580    antialiasing_enabled = true;
581    glEnable (GL_LINE_SMOOTH);
582    glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
583    glEnable (GL_POLYGON_SMOOTH);
584    glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
585  }
586
587  updateQWidget();
588  printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
589}
590
591/**
592   SLOT Activate by a click on the haloing menu
593@param check : 1 , 0
594*/
595//FIXME : I SEE NOTHING...
596void G4OpenGLQtViewer::toggleHaloing(bool check) {
597  if (check) {
598    haloing_enabled = false;
599  } else {
600    haloing_enabled = true;
601  }
602
603  updateQWidget();
604
605  printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
606}
607
608/**
609   SLOT Activate by a click on the auxiliaire edges menu
610@param check : 1 , 0
611*/
612void G4OpenGLQtViewer::toggleAux(bool check) {
613  if (check) {
614    fVP.SetAuxEdgeVisible(false);
615  } else {
616    fVP.SetAuxEdgeVisible(true);
617  }
618  SetNeedKernelVisit (true);
619  updateQWidget();
620
621  printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
622}
623
624/**
625   SLOT Activate by a click on the full screen menu
626@param check : 1 , 0
627*/
628void G4OpenGLQtViewer::toggleFullScreen(bool check) {
629  GLWindow->setWindowState(GLWindow->windowState() ^ Qt::WindowFullScreen);
630
631  printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
632}
633
634/**
635   SLOT Activate by a click on the mouse action menu
636   @param check : 1 , 0
637*/
638void G4OpenGLQtViewer::toggleMouseAction(bool check) {
639  if (check) { // rotate scene
640    fMouseAction = true;
641  } else { // move scene
642    fMouseAction = false;
643  }
644
645  printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
646}
647
648
649void G4OpenGLQtViewer::actionControlPanels() {
650  printf("G4OpenGLQtViewer::actionControlPanels \n");
651}
652
653void G4OpenGLQtViewer::actionExitG4() {
654  printf("G4OpenGLQtViewer::actionExitG4() \n");
655}
656
657void G4OpenGLQtViewer::actionCreateEPS() {
658  QString filters;
659  QList<QByteArray> formats =  QImageWriter::supportedImageFormats ();
660  for (int i = 0; i < formats.size(); ++i) {
661    filters +=formats.at(i);
662    if ((i+1) <formats.size()) {
663      filters += ";;";
664    }
665  }
666  QString* selectedFilter = new QString();
667  QString nomFich =  QFileDialog::getSaveFileName ( GLWindow,
668                                                    tr("Save as ..."),
669                                                    ".",
670                                                    filters,
671                                                    selectedFilter );
672  // bmp jpg jpeg png ppm xbm xpm
673  if (nomFich == "") {
674    return;
675  }
676  nomFich += "."+selectedFilter->toLower();
677  printf("G4OpenGLQtViewer::name %s\n",nomFich.toStdString().c_str());
678  G4OpenGLQtExportDialog* exportDialog= new G4OpenGLQtExportDialog(GLWindow,nomFich,fWindow->height(),fWindow->width());
679  if(  exportDialog->exec()) {
680   
681    printf("rescaling before\n");
682    QPixmap * pixmap = new QPixmap(fWindow->renderPixmap (exportDialog->getWidth(),exportDialog->getHeight() )) ;//fWindow->grabFrameBuffer();
683    printf("rescaling after\n");
684     
685    if ((exportDialog->getWidth() !=fWindow->width()) ||
686         (exportDialog->getWidth() !=fWindow->width())) {
687
688      //      rescaleImage(exportDialog->getWidth(),exportDialog->getHeight());// re-scale image
689      printf("rescaling\n");
690    }
691   
692    // jpeg format
693    if (nomFich.endsWith(".jpg") ||
694        nomFich.endsWith(".jpeg")) {
695      // grabFrameBuffer() :: Returns an image of the frame buffer. If withAlpha is true the alpha channel is included.
696      pixmap->save(nomFich,0,exportDialog->getSliderValue());
697      printf("saving jpeg quality : %d\n",exportDialog->getSliderValue());
698    } else if (nomFich.endsWith(".eps")) {
699      printf("saving EPS\n");
700    } else if (nomFich.endsWith(".tif") ||
701               nomFich.endsWith(".tiff") ||
702               nomFich.endsWith(".jpg") ||
703               nomFich.endsWith(".png") ||
704               nomFich.endsWith(".bmp") ||
705               nomFich.endsWith(".xpm")) {
706      pixmap->save(nomFich,0,exportDialog->getSliderValue());
707      printf("saving ELSE\n");
708    } else {
709      G4cerr << "This version of G4UI Could not generate the selected format" << G4endl;
710    }
711   
712  } else { // cancel selected
713    return;
714  }
715 
716  printf("G4OpenGLQtViewer::actionCreateEPS() \n");
717}
718
719/*
720// 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
721void ApplicationWindow::exportLayer()
722{
723  QWidget *w=ws->activeWindow();
724  if (!w || !w->isA("MultiLayer"))
725    return;
726 
727  Graph* g = ((MultiLayer*)w)->activeGraph();
728  if (!g)
729    return;
730 
731  ImageExportDialog *ied = new ImageExportDialog(this, 0);
732  ied->setDir(workingDir);
733  if ( ied->exec() == QDialog::Accepted )
734    {
735      workingDir = ied->dirPath();
736      QString fname = ied->selectedFile();
737      QString selectedFilter = ied->selectedFilter();
738 
739      QFileInfo fi(fname);
740      QString baseName = fi.fileName();
741 
742      if (baseName.contains(".")==0)
743        fname.append(selectedFilter.remove("*"));
744 
745      if ( QFile::exists(fname) &&
746           QMessageBox::question(0, tr("QtiPlot - Overwrite File?"),
747                                 tr("A file called: <p><b>%1</b><p>already exists. "
748                                    "Do you want to overwrite it?")
749                                 .arg(fname),
750                                 tr("&Yes"), tr("&No"),
751                                 QString::null, 0, 1 ) )
752        return ;
753      else
754        {
755          QFile f(fname);
756          if ( !f.open( IO_WriteOnly ) )
757            {
758              QMessageBox::critical(0, tr("QtiPlot - Export Error"),
759                                    tr("Could not write to file: <br><h4> %1 </h4><p>Please verify that you have the right to write to this location!").arg(fname));
760              return;
761            }
762 
763          if (selectedFilter.contains(".eps"))
764            {
765              if (ied->showExportOptions())
766                {
767                  epsExportDialog *ed= new epsExportDialog (fname, this, "exportDialog", TRUE, WStyle_Tool|WDestructiveClose);
768                  connect (ed, SIGNAL(exportToEPS(const QString&, int, QPrinter::Orientation, QPrinter::PageSize, QPrinter::ColorMode)),
769                           g, SLOT(exportToEPS(const QString&, int, QPrinter::Orientation, QPrinter::PageSize, QPrinter::ColorMode)));
770 
771                  ed->showNormal();
772                  ed->setActiveWindow();
773                }
774              else
775                g->exportToEPS(fname);
776 
777              if (((MultiLayer*)w)->hasOverlapingLayers())
778                ((MultiLayer*)w)->updateTransparency();
779              return;
780            }
781          else if (selectedFilter.contains(".svg"))
782            {
783              g->exportToSVG(fname);
784              return;
785            }
786          //  else if (selectedFilter.contains(".wmf"))
787          //  {
788          //  g->exportToWmf(fname);
789          //  return;
790        }
791QStringList list=QImage::outputFormatList ();
792      for (int i=0; i<(int)list.count(); i++)
793        {
794          if (selectedFilter.contains("."+(list[i]).lower()))
795            {
796            if (ied->showExportOptions())
797              {
798              imageExportDialog* ed= new imageExportDialog(false, this,"exportDialog",TRUE,WStyle_Tool|WDestructiveClose);
799                  connect (ed, SIGNAL(options(const QString&, const QString&, int, bool)),
800                           g, SLOT(exportImage(const QString&, const QString&, int, bool)));
801 
802                  ed->setExportPath(fname, list[i]);
803                  ed->enableTransparency();
804                  ed->showNormal();
805                  ed->setActiveWindow();
806                }
807              else
808                g->exportImage(fname, list[i], 100, true);
809 
810              if (((MultiLayer*)w)->hasOverlapingLayers())
811                ((MultiLayer*)w)->updateTransparency();
812              return;
813            }
814        }
815    }
816}
817}
818
819void Graph::exportToSVG(const QString& fname)
820{
821  // enable workaround for Qt3 misalignments
822  QwtPainter::setSVGMode(true);
823  QPicture picture;
824  QPainter p(&picture);
825  d_plot->print(&p, d_plot->rect());
826  p.end();
827
828  picture.save(fname, "svg");
829}
830*/
831
832
833
834
835/**
836   Save the current mouse press point
837   @param p mouse click point
838*/
839void G4OpenGLQtViewer::G4MousePressEvent(QPoint p)
840{
841  lastPos = p;
842}
843
844/**
845   @param pos_x mouse x position
846   @param pos_y mouse y position
847   @param mButtons mouse button active
848*/
849void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons)
850{
851  int dx = pos_x - lastPos.x();
852  int dy = pos_y - lastPos.y();
853 
854  if (fMouseAction) {  // rotate
855    if (mButtons & Qt::LeftButton) {
856      //phi spin stuff here
857     
858      G4Vector3D vp = fVP.GetViewpointDirection ().unit ();
859      G4Vector3D up = fVP.GetUpVector ().unit ();
860     
861      G4Vector3D yprime = (up.cross(vp)).unit();
862      G4Vector3D zprime = (vp.cross(yprime)).unit();
863     
864      G4double delta_alpha;
865      G4double delta_theta;
866     
867      if (fVP.GetLightsMoveWithCamera()) {
868        delta_alpha = dy;
869        delta_theta = -dx;
870      } else {
871        delta_alpha = -dy;
872        delta_theta = dx;
873      }   
874
875      delta_alpha *= deg;
876      delta_theta *= deg;
877
878      G4Vector3D new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime;
879     
880      G4Vector3D new_up;
881      if (fVP.GetLightsMoveWithCamera()) {
882        new_up = (new_vp.cross(yprime)).unit();
883        fVP.SetUpVector(new_up);
884      } else {
885        new_up = up;
886      }
887      ////////////////
888      // Rotates by fixed azimuthal angle delta_theta.
889
890      G4double cosalpha = new_up.dot (new_vp.unit());
891      G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));
892      yprime = (new_up.cross (new_vp.unit())).unit ();
893      G4Vector3D xprime = yprime.cross (new_up);
894      // Projection of vp on plane perpendicular to up...
895      G4Vector3D a1 = sinalpha * xprime;
896      // Required new projection...
897      G4Vector3D a2 =
898        sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);
899      // Required Increment vector...
900      G4Vector3D delta = a2 - a1;
901      // So new viewpoint is...
902      G4Vector3D viewPoint = new_vp.unit() + delta;
903
904      fVP.SetViewAndLights (viewPoint);
905      updateQWidget();
906     
907    } else if (mButtons & Qt::RightButton) {
908      // NEVER DONE BECAUSE OF MOUSE MENU
909      //       printf("G4OpenGLQtViewer::mouseMoveEvent Right \n");
910      //       setXRotation(xRot + dy/2);
911      //       setZRotation(zRot + dx/2);
912      //       updateQWidget();
913    }
914  } else {  // move
915
916    float dx = pos_x - lastPos.x();
917    float dy = pos_y - lastPos.y();
918   
919    G4Point3D stp
920      = GetSceneHandler()->GetScene()->GetStandardTargetPoint();
921   
922    G4Point3D tp = stp + fVP.GetCurrentTargetPoint ();
923   
924    const G4Vector3D& upVector = fVP.GetUpVector ();
925    const G4Vector3D& vpVector = fVP.GetViewpointDirection ();
926   
927    G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
928    G4Vector3D unitUp    = (vpVector.cross (unitRight)).unit();
929   
930    tp += -dx * unitRight + dy * unitUp;
931    fVP.SetCurrentTargetPoint (tp - stp);
932   
933    updateQWidget();
934  }
935  lastPos = QPoint(pos_x, pos_y);
936}
937
938void G4OpenGLQtViewer::rescaleImage(
939 int aWidth
940,int aHeight
941){
942  printf("");
943}
944#endif
Note: See TracBrowser for help on using the repository browser.