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

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

r601@mac-90108: laurentgarnier | 2007-09-20 15:47:27 +0200
passage du fileSave en natif mac

  • Property svn:mime-type set to text/cpp
File size: 28.6 KB
RevLine 
[530]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"
[564]46#include "G4Scene.hh"
[580]47#include "G4OpenGLQtExportDialog.h"
[530]48
[539]49#include "G4Qt.hh"
[569]50#include "G4UIsession.hh"
51#include "G4UImanager.hh"
[539]52#include <QtGui/qboxlayout.h>
53#include <QtGui/qdialog.h>
[564]54#include <QtGui/qmenu.h>
[580]55#include <QImageWriter>
56#include <QMessageBox>
[565]57#include <QFileDialog.h>
[530]58
59//////////////////////////////////////////////////////////////////////////////
60/**
[564]61 Implementation of virtual method of G4VViewer
62*/
[530]63void G4OpenGLQtViewer::SetView (
64)
65//////////////////////////////////////////////////////////////////////////////
66//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
67{
[542]68 printf("G4OpenGLQtViewer::SetView ++++++++++++++++++++\n");
[564]69 // if(!fHDC) return;
70 // if(!fHGLRC) return;
71 // ::wglMakeCurrent(fHDC,fHGLRC);
72 // fWindow->makeCurrent();
[579]73 G4OpenGLViewer::SetView ();
[542]74 printf("G4OpenGLQtViewer::SetView --------------------\n");
[530]75}
76
77
78
79//////////////////////////////////////////////////////////////////////////////
80/**
[564]81 Implementation of virtual method of G4VViewer
82*/
[530]83void G4OpenGLQtViewer::ShowView (
84)
85//////////////////////////////////////////////////////////////////////////////
86//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
87{
[542]88 printf("G4OpenGLQtViewer::ShowView +++++++++++++++++++++\n");
[564]89 glFlush ();
[579]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 }
[564]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 // }
[530]102}
103
104
105
106//////////////////////////////////////////////////////////////////////////////
107void G4OpenGLQtViewer::CreateGLQtContext (
108)
109//////////////////////////////////////////////////////////////////////////////
110//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
111{
112 printf("G4OpenGLQtViewer::CreateGLQtContext \n");
113}
114
[564]115
[530]116//////////////////////////////////////////////////////////////////////////////
117void G4OpenGLQtViewer::CreateMainWindow (
[564]118 QGLWidget* glWidget
119 )
[530]120//////////////////////////////////////////////////////////////////////////////
121//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
122{
123
[538]124 if(fWindow) return; //Done.
[564]125 printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n");
[538]126
[539]127 // launch Qt if not
128 G4Qt* interactorManager = G4Qt::getInstance ();
129 // G4UImanager* UI = G4UImanager::GetUIpointer();
130
[564]131 fWindow = glWidget ;
[543]132 // fWindow->makeCurrent();
[538]133
[539]134 // create window
[569]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"))) {
[579]140 printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
141 GLWindow = new QDialog(widget,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
[569]142 found = true;
143 }
144 }
145 if (found==false) {
[579]146 printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n");
[569]147 GLWindow = new QDialog();
148 }
[539]149 } else {
[579]150 printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
[539]151 GLWindow = new QDialog();
152 }
153
154 QHBoxLayout *mainLayout = new QHBoxLayout;
[564]155
[539]156 mainLayout->addWidget(fWindow);
157 GLWindow->setLayout(mainLayout);
158 GLWindow->setWindowTitle("QGl Viewer");
[564]159 GLWindow->resize(300, 300);
[570]160 GLWindow->move(900,300);
[539]161 GLWindow->show();
[530]162
[579]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
[564]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 ();
[530]177
[564]178 if(!fWindow) return;
179 printf("G4OpenGLQtViewer::CreateMainWindow glWidget END\n");
[530]180
[564]181 if (!fContextMenu)
182 createPopupMenu();
[530]183
[564]184}
[530]185
[579]186/** Close the dialog and set the pointer to NULL
187 */
188void G4OpenGLQtViewer::dialogClosed() {
189 GLWindow = NULL;
190}
191
192
[564]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");
[530]204}
205
206//////////////////////////////////////////////////////////////////////////////
[564]207G4OpenGLQtViewer::~G4OpenGLQtViewer (
[539]208)
209//////////////////////////////////////////////////////////////////////////////
210//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
211{
[564]212 printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n");
[579]213 delete fContextMenu;
[564]214}
[539]215
216
[564]217/**
218 Create a popup menu for the widget. This menu is activated by right-mouse click
219*/
220void G4OpenGLQtViewer::createPopupMenu() {
[539]221
[564]222 fContextMenu = new QMenu("All");
[539]223
[564]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);
[539]243 } else {
[564]244 mRepresentation->clear();
[539]245 }
246
247
[564]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);
[539]266
[564]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
[565]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()));
[564]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");
[565]311 QAction *controlPanels = mActions->addAction("Control panels");
312 QAction *exitG4 = mActions->addAction("Exit to G4Vis >");
[568]313 QAction *createEPS = mActions->addAction("Save as ...");
[565]314 QObject ::connect(controlPanels,
[566]315 SIGNAL(triggered()),
[565]316 this,
317 SLOT(actionControlPanels()));
318 QObject ::connect(exitG4,
[566]319 SIGNAL(triggered()),
[565]320 this,
321 SLOT(actionExitG4()));
322 QObject ::connect(createEPS,
[566]323 SIGNAL(triggered()),
[565]324 this,
325 SLOT(actionCreateEPS()));
[564]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{
[579]383 if (!GLWindow) {
384 G4cerr << "Visualization window not defined, please choose one before" << G4endl;
385 } else {
[539]386
[579]387 if (!fContextMenu)
388 createPopupMenu();
389
390 // launch menu
391 if ( fContextMenu ) {
392 fContextMenu->exec( e->globalPos() );
393 // delete fContextMenu;
394 }
[564]395 }
396 e->accept();
397}
[539]398
399
[564]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/**
[565]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
[564]463 */
464void G4OpenGLQtViewer::toggleDrawingAction(int aAction) {
465
466 G4ViewParameters::DrawingStyle d_style;
[539]467
468
[564]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");
[539]505}
506
[564]507
508/**
509 SLOT Activate by a click on the representation menu
[565]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
[564]514 @param check : 1 polyhedron, 0 nurbs
[565]515 @see G4OpenGLStoredQtViewer::DrawView
516 @see G4XXXStoredViewer::CompareForKernelVisit
[564]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);
[530]531}
532
[564]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();
[530]552}
553
[564]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}
[530]568
[564]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);
[530]585 }
[564]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
[530]594*/
[564]595//FIXME : I SEE NOTHING...
596void G4OpenGLQtViewer::toggleHaloing(bool check) {
597 if (check) {
598 haloing_enabled = false;
599 } else {
600 haloing_enabled = true;
601 }
[530]602
[564]603 updateQWidget();
[530]604
[564]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
[565]649void G4OpenGLQtViewer::actionControlPanels() {
650 printf("G4OpenGLQtViewer::actionControlPanels \n");
651}
652
653void G4OpenGLQtViewer::actionExitG4() {
654 printf("G4OpenGLQtViewer::actionExitG4() \n");
655}
656
657void G4OpenGLQtViewer::actionCreateEPS() {
[580]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
667 QString nomFich = QFileDialog::getSaveFileName ( GLWindow,
668 tr("Save as ..."),
669 ".",
670 filters );
671 // bmp jpg jpeg png ppm xbm xpm
672 if(nomFich.endsWith(".eps")) {
673 G4cerr << "This version of G4UI Could not generate EPS." << G4endl;
674 } else if(nomFich.endsWith(".jpg") || nomFich.endsWith(".jpeg")) {
675 G4cerr << "Should display a quality selector" << G4endl;
676 G4OpenGLQtExportDialog* exportDialog= new G4OpenGLQtExportDialog(false, this,"exportDialog",TRUE,WStyle_Tool|WDestructiveClose);
677 fWindow->grabFrameBuffer().save(nomFich);
[568]678 } else {
679 fWindow->grabFrameBuffer().save(nomFich);
[580]680 // grabFrameBuffer() :: Returns an image of the frame buffer. If withAlpha is true the alpha channel is included.
[568]681 }
[580]682
[565]683 printf("G4OpenGLQtViewer::actionCreateEPS() \n");
684}
685
[580]686/*
687// 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
688void ApplicationWindow::exportLayer()
689{
690 QWidget *w=ws->activeWindow();
691 if (!w || !w->isA("MultiLayer"))
692 return;
693
694 Graph* g = ((MultiLayer*)w)->activeGraph();
695 if (!g)
696 return;
697
698 ImageExportDialog *ied = new ImageExportDialog(this, 0);
699 ied->setDir(workingDir);
700 if ( ied->exec() == QDialog::Accepted )
701 {
702 workingDir = ied->dirPath();
703 QString fname = ied->selectedFile();
704 QString selectedFilter = ied->selectedFilter();
705
706 QFileInfo fi(fname);
707 QString baseName = fi.fileName();
708
709 if (baseName.contains(".")==0)
710 fname.append(selectedFilter.remove("*"));
711
712 if ( QFile::exists(fname) &&
713 QMessageBox::question(0, tr("QtiPlot - Overwrite File?"),
714 tr("A file called: <p><b>%1</b><p>already exists. "
715 "Do you want to overwrite it?")
716 .arg(fname),
717 tr("&Yes"), tr("&No"),
718 QString::null, 0, 1 ) )
719 return ;
720 else
721 {
722 QFile f(fname);
723 if ( !f.open( IO_WriteOnly ) )
724 {
725 QMessageBox::critical(0, tr("QtiPlot - Export Error"),
726 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));
727 return;
728 }
729
730 if (selectedFilter.contains(".eps"))
731 {
732 if (ied->showExportOptions())
733 {
734 epsExportDialog *ed= new epsExportDialog (fname, this, "exportDialog", TRUE, WStyle_Tool|WDestructiveClose);
735 connect (ed, SIGNAL(exportToEPS(const QString&, int, QPrinter::Orientation, QPrinter::PageSize, QPrinter::ColorMode)),
736 g, SLOT(exportToEPS(const QString&, int, QPrinter::Orientation, QPrinter::PageSize, QPrinter::ColorMode)));
737
738 ed->showNormal();
739 ed->setActiveWindow();
740 }
741 else
742 g->exportToEPS(fname);
743
744 if (((MultiLayer*)w)->hasOverlapingLayers())
745 ((MultiLayer*)w)->updateTransparency();
746 return;
747 }
748 else if (selectedFilter.contains(".svg"))
749 {
750 g->exportToSVG(fname);
751 return;
752 }
753 // else if (selectedFilter.contains(".wmf"))
754 // {
755 // g->exportToWmf(fname);
756 // return;
757 }
758 QStringList list=QImage::outputFormatList ();
759 for (int i=0; i<(int)list.count(); i++)
760 {
761 if (selectedFilter.contains("."+(list[i]).lower()))
762 {
763 if (ied->showExportOptions())
764 {
765 imageExportDialog* ed= new imageExportDialog(false, this,"exportDialog",TRUE,WStyle_Tool|WDestructiveClose);
766 connect (ed, SIGNAL(options(const QString&, const QString&, int, bool)),
767 g, SLOT(exportImage(const QString&, const QString&, int, bool)));
768
769 ed->setExportPath(fname, list[i]);
770 ed->enableTransparency();
771 ed->showNormal();
772 ed->setActiveWindow();
773 }
774 else
775 g->exportImage(fname, list[i], 100, true);
776
777 if (((MultiLayer*)w)->hasOverlapingLayers())
778 ((MultiLayer*)w)->updateTransparency();
779 return;
780 }
781 }
782 }
783}
784}
[565]785
[580]786void Graph::exportToSVG(const QString& fname)
787{
788 // enable workaround for Qt3 misalignments
789 QwtPainter::setSVGMode(true);
790 QPicture picture;
791 QPainter p(&picture);
792 d_plot->print(&p, d_plot->rect());
793 p.end();
[565]794
[580]795 picture.save(fname, "svg");
796}
797*/
798
799
800
801
[564]802/**
803 Save the current mouse press point
804 @param p mouse click point
805*/
806void G4OpenGLQtViewer::G4MousePressEvent(QPoint p)
807{
808 lastPos = p;
809}
810
811/**
812 @param pos_x mouse x position
813 @param pos_y mouse y position
814 @param mButtons mouse button active
815*/
816void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons)
817{
818 int dx = pos_x - lastPos.x();
819 int dy = pos_y - lastPos.y();
[530]820
[564]821 if (fMouseAction) { // rotate
822 if (mButtons & Qt::LeftButton) {
823 //phi spin stuff here
824
825 G4Vector3D vp = fVP.GetViewpointDirection ().unit ();
826 G4Vector3D up = fVP.GetUpVector ().unit ();
827
828 G4Vector3D yprime = (up.cross(vp)).unit();
829 G4Vector3D zprime = (vp.cross(yprime)).unit();
830
831 G4double delta_alpha;
832 G4double delta_theta;
833
834 if (fVP.GetLightsMoveWithCamera()) {
835 delta_alpha = dy;
836 delta_theta = -dx;
837 } else {
838 delta_alpha = -dy;
839 delta_theta = dx;
840 }
[530]841
[564]842 delta_alpha *= deg;
843 delta_theta *= deg;
[530]844
[564]845 G4Vector3D new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime;
846
847 G4Vector3D new_up;
848 if (fVP.GetLightsMoveWithCamera()) {
849 new_up = (new_vp.cross(yprime)).unit();
850 fVP.SetUpVector(new_up);
851 } else {
852 new_up = up;
853 }
854 ////////////////
855 // Rotates by fixed azimuthal angle delta_theta.
856
857 G4double cosalpha = new_up.dot (new_vp.unit());
858 G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));
859 yprime = (new_up.cross (new_vp.unit())).unit ();
860 G4Vector3D xprime = yprime.cross (new_up);
861 // Projection of vp on plane perpendicular to up...
862 G4Vector3D a1 = sinalpha * xprime;
863 // Required new projection...
864 G4Vector3D a2 =
865 sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);
866 // Required Increment vector...
867 G4Vector3D delta = a2 - a1;
868 // So new viewpoint is...
869 G4Vector3D viewPoint = new_vp.unit() + delta;
870
871 fVP.SetViewAndLights (viewPoint);
872 updateQWidget();
873
874 } else if (mButtons & Qt::RightButton) {
875 // NEVER DONE BECAUSE OF MOUSE MENU
876 // printf("G4OpenGLQtViewer::mouseMoveEvent Right \n");
877 // setXRotation(xRot + dy/2);
878 // setZRotation(zRot + dx/2);
879 // updateQWidget();
880 }
881 } else { // move
882
883 float dx = pos_x - lastPos.x();
884 float dy = pos_y - lastPos.y();
885
886 G4Point3D stp
887 = GetSceneHandler()->GetScene()->GetStandardTargetPoint();
888
889 G4Point3D tp = stp + fVP.GetCurrentTargetPoint ();
890
891 const G4Vector3D& upVector = fVP.GetUpVector ();
892 const G4Vector3D& vpVector = fVP.GetViewpointDirection ();
893
894 G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
895 G4Vector3D unitUp = (vpVector.cross (unitRight)).unit();
896
897 tp += -dx * unitRight + dy * unitUp;
898 fVP.SetCurrentTargetPoint (tp - stp);
899
900 updateQWidget();
901 }
902 lastPos = QPoint(pos_x, pos_y);
903}
904
[568]905
[530]906#endif
Note: See TracBrowser for help on using the repository browser.