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

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

r580@mac-90108: laurentgarnier | 2007-08-16 16:13:11 +0200
correction de la position des widgets et du focus sur le gl

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