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

Last change on this file since 569 was 569, checked in by garnier, 18 years ago

r579@mac-90108: laurentgarnier | 2007-08-16 15:58:30 +0200
desormais le glWidget est accroche au mainWindow

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