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

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

amelioration du ticket #66

  • Property svn:mime-type set to text/cpp
File size: 46.7 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//
[632]27// $Id: G4OpenGLQtViewer.cc,v 1.8 2007/11/30 14:47:30 lgarnier Exp $
[593]28// GEANT4 tag $Name: $
[530]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
[635]38#define GEANT4_QT_DEBUG
[610]39
[530]40#include "G4OpenGLQtViewer.hh"
41
42#include "G4ios.hh"
43#include "G4VisExtent.hh"
44#include "G4LogicalVolume.hh"
45#include "G4VSolid.hh"
46#include "G4Point3D.hh"
47#include "G4Normal3D.hh"
[564]48#include "G4Scene.hh"
[581]49#include "G4OpenGLQtExportDialog.hh"
[530]50
[539]51#include "G4Qt.hh"
[569]52#include "G4UIsession.hh"
53#include "G4UImanager.hh"
[595]54#include <qapplication.h>
[599]55#include <qlayout.h>
[595]56#include <qdialog.h>
[599]57
58#if QT_VERSION >= 0x040000
[595]59#include <qmenu.h>
60#include <qimagewriter.h>
[599]61#else
62#include <qaction.h>
63#include <qwidgetlist.h>
64#include <qpopupmenu.h>
65#include <qimage.h>
66#endif
67
[595]68#include <qmessagebox.h>
69#include <qfiledialog.h>
70#include <qprinter.h>
71#include <qpainter.h>
72#include <qgl.h> // include <qglwidget.h>
73#include <qdialog.h>
74#include <qevent.h> //include <qcontextmenuevent.h>
[530]75
[593]76
[530]77//////////////////////////////////////////////////////////////////////////////
78/**
[564]79 Implementation of virtual method of G4VViewer
80*/
[530]81void G4OpenGLQtViewer::SetView (
82)
83//////////////////////////////////////////////////////////////////////////////
84//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
85{
[608]86#ifdef GEANT4_QT_DEBUG
[542]87 printf("G4OpenGLQtViewer::SetView ++++++++++++++++++++\n");
[608]88#endif
[564]89 // if(!fHDC) return;
90 // if(!fHGLRC) return;
91 // ::wglMakeCurrent(fHDC,fHGLRC);
92 // fWindow->makeCurrent();
[579]93 G4OpenGLViewer::SetView ();
[608]94#ifdef GEANT4_QT_DEBUG
[542]95 printf("G4OpenGLQtViewer::SetView --------------------\n");
[608]96#endif
[530]97}
98
99
100
101//////////////////////////////////////////////////////////////////////////////
102/**
[564]103 Implementation of virtual method of G4VViewer
104*/
[530]105void G4OpenGLQtViewer::ShowView (
106)
107//////////////////////////////////////////////////////////////////////////////
108//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
109{
[608]110#ifdef GEANT4_QT_DEBUG
[542]111 printf("G4OpenGLQtViewer::ShowView +++++++++++++++++++++\n");
[608]112#endif
[564]113 glFlush ();
[579]114 if (!GLWindow) {
[638]115 G4cerr << "Visualization window not defined, please choose one before\n" << G4endl;
[579]116 } else {
[599]117#if QT_VERSION < 0x040000
118 GLWindow->setActiveWindow();
119#else
[579]120 GLWindow->activateWindow();
[599]121#endif
[608]122#ifdef GEANT4_QT_DEBUG
[579]123 printf("G4OpenGLQtViewer::ShowView -----------------------\n");
[608]124#endif
[579]125 }
[564]126 // // Empty the Windows message queue :
127 // MSG event;
128 // while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
129 // ::TranslateMessage(&event);
130 // ::DispatchMessage (&event);
131 // }
[530]132}
133
134
135
136//////////////////////////////////////////////////////////////////////////////
137void G4OpenGLQtViewer::CreateGLQtContext (
138)
139//////////////////////////////////////////////////////////////////////////////
140//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
141{
[608]142#ifdef GEANT4_QT_DEBUG
[530]143 printf("G4OpenGLQtViewer::CreateGLQtContext \n");
[608]144#endif
[530]145}
146
[564]147
[530]148//////////////////////////////////////////////////////////////////////////////
149void G4OpenGLQtViewer::CreateMainWindow (
[585]150 QGLWidget* glWidget
151)
[530]152//////////////////////////////////////////////////////////////////////////////
153//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
154{
155
[538]156 if(fWindow) return; //Done.
[608]157#ifdef GEANT4_QT_DEBUG
[564]158 printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n");
[608]159#endif
[538]160
[539]161 // launch Qt if not
162 G4Qt* interactorManager = G4Qt::getInstance ();
163 // G4UImanager* UI = G4UImanager::GetUIpointer();
164
[564]165 fWindow = glWidget ;
[543]166 // fWindow->makeCurrent();
[538]167
[539]168 // create window
[569]169 if (((QApplication*)interactorManager->GetMainInteractor())) {
170 // look for the main window
171 bool found = false;
[599]172#if QT_VERSION < 0x040000
[631]173 // theses lines does nothing exept this one "GLWindow = new QDialog(0..."
[626]174 // but if I comment them, it doesn't work...
175 QWidgetList *list = QApplication::allWidgets();
176 QWidgetListIt it( *list ); // iterate over the widgets
177 QWidget * widget;
178 while ( (widget=it.current()) != 0 ) { // for each widget...
179 ++it;
180 if ((found== false) && (widget->inherits("QMainWindow"))) {
181 GLWindow = new QDialog(0,0,FALSE,Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_MinMax );
182 found = true;
183 }
184 }
185 delete list; // delete the list, not the widgets
[599]186#else
[626]187 foreach (QWidget *widget, QApplication::allWidgets()) {
188 if ((found== false) && (widget->inherits("QMainWindow"))) {
189 GLWindow = new QDialog(widget,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
190 found = true;
191 }
192 }
[608]193#endif
[612]194
195#if QT_VERSION < 0x040000
[610]196 glWidget->reparent(GLWindow,0,QPoint(0,0));
[612]197#else
198 glWidget->setParent(GLWindow);
199#endif
[599]200
[569]201 if (found==false) {
[608]202#ifdef GEANT4_QT_DEBUG
[579]203 printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n");
[608]204#endif
[569]205 GLWindow = new QDialog();
206 }
[539]207 } else {
[608]208#ifdef GEANT4_QT_DEBUG
[579]209 printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
[608]210#endif
[539]211 GLWindow = new QDialog();
212 }
213
[599]214 QHBoxLayout *mainLayout = new QHBoxLayout(GLWindow);
[564]215
[539]216 mainLayout->addWidget(fWindow);
[599]217
218#if QT_VERSION < 0x040000
219 GLWindow->setCaption( tr( "QGl Viewer" ));
220#else
[539]221 GLWindow->setLayout(mainLayout);
[599]222 GLWindow->setWindowTitle(tr("QGl Viewer"));
223#endif
[564]224 GLWindow->resize(300, 300);
[570]225 GLWindow->move(900,300);
[539]226 GLWindow->show();
[530]227
[579]228 // delete the pointer if close this
229 // GLWindow->setAttribute(Qt::WA_DeleteOnClose);
230
[610]231#if QT_VERSION >= 0x040000
[579]232 QObject ::connect(GLWindow,
233 SIGNAL(rejected()),
234 this,
235 SLOT(dialogClosed()));
[610]236#endif
[579]237
[564]238 WinSize_x = 400;
239 WinSize_y = 400;
240 if (WinSize_x < fVP.GetWindowSizeHintX ())
241 WinSize_x = fVP.GetWindowSizeHintX ();
242 if (WinSize_y < fVP.GetWindowSizeHintY ())
243 WinSize_y = fVP.GetWindowSizeHintY ();
[530]244
[564]245 if(!fWindow) return;
[608]246#ifdef GEANT4_QT_DEBUG
[564]247 printf("G4OpenGLQtViewer::CreateMainWindow glWidget END\n");
[608]248#endif
[530]249
[564]250 if (!fContextMenu)
251 createPopupMenu();
[530]252
[564]253}
[530]254
[610]255#if QT_VERSION >= 0x040000
[579]256/** Close the dialog and set the pointer to NULL
257 */
258void G4OpenGLQtViewer::dialogClosed() {
[610]259#ifdef GEANT4_QT_DEBUG
260 printf("G4OpenGLQtViewer::dialogClosed END\n");
261#endif
262 // GLWindow = NULL;
[579]263}
[610]264#endif
[579]265
[564]266//////////////////////////////////////////////////////////////////////////////
267G4OpenGLQtViewer::G4OpenGLQtViewer (
268 G4OpenGLSceneHandler& scene
269 )
270 :G4VViewer (scene, -1)
271 ,G4OpenGLViewer (scene)
272 ,fWindow(0)
273 ,fContextMenu(0)
274 ,fMouseAction(true)
275{
[608]276#ifdef GEANT4_QT_DEBUG
[564]277 printf("G4OpenGLQtViewer::G4OpenGLQtViewer \n");
[608]278#endif
[530]279}
280
281//////////////////////////////////////////////////////////////////////////////
[564]282G4OpenGLQtViewer::~G4OpenGLQtViewer (
[539]283)
284//////////////////////////////////////////////////////////////////////////////
285//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
286{
[608]287#ifdef GEANT4_QT_DEBUG
[564]288 printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n");
[608]289#endif
[579]290 delete fContextMenu;
[564]291}
[539]292
293
[564]294/**
295 Create a popup menu for the widget. This menu is activated by right-mouse click
296*/
297void G4OpenGLQtViewer::createPopupMenu() {
[539]298
[599]299#if QT_VERSION < 0x040000
300 fContextMenu = new QPopupMenu( GLWindow,"All" );
301#else
[564]302 fContextMenu = new QMenu("All");
[599]303#endif
304 Q_CHECK_PTR( fContextMenu );
[539]305
[599]306#if QT_VERSION < 0x040000
307 // === Mouse menu ===
308 QPopupMenu *mMouseAction = new QPopupMenu( fContextMenu );
309 Q_CHECK_PTR( mMouseAction );
310
[617]311#if QT_VERSION < 0x030200
312 QAction *rotate = new QAction("&Rotate scene","&Rotate scene",CTRL+Key_N,mMouseAction);
313 QAction *move = new QAction("&Move scene","&Move scene",CTRL+Key_M,mMouseAction);
314#else
[599]315 QAction *rotate = new QAction("&Rotate scene",CTRL+Key_N,mMouseAction);
316 QAction *move = new QAction("&Move scene",CTRL+Key_M,mMouseAction);
[617]317#endif
[599]318 rotate->addTo(mMouseAction);
319 move->addTo(mMouseAction);
320
321 fContextMenu->insertItem( "&Mouse action", mMouseAction);
322
323#else
324 // === Mouse menu ===
[564]325 QMenu *mMouseAction = fContextMenu->addMenu("&Mouse action");
[599]326
[564]327 QAction *rotate = mMouseAction->addAction("&Rotate scene");
328 QAction *move = mMouseAction->addAction("&Move scene");
[599]329#endif
330
[564]331 // INIT mMouse
332 createRadioAction(rotate,move,SLOT(toggleMouseAction(bool)),1);
333
[599]334#if QT_VERSION < 0x040000
335 // === Style Menu ===
336 QPopupMenu *mStyle = new QPopupMenu(fContextMenu);
337
338 QPopupMenu *mRepresentation = new QPopupMenu(fContextMenu);
339
[617]340#if QT_VERSION < 0x030200
341 QAction *polyhedron = new QAction("&Polyhedron","&Polyhedron",CTRL+Key_P,mRepresentation);
342 QAction *nurbs = new QAction("&NURBS","&NURBS",CTRL+Key_N,mRepresentation);
343#else
[599]344 QAction *polyhedron = new QAction("&Polyhedron",CTRL+Key_P,mRepresentation);
345 QAction *nurbs = new QAction("&NURBS",CTRL+Key_N,mRepresentation);
[617]346#endif
[599]347 polyhedron->addTo(mRepresentation);
348 nurbs->addTo(mRepresentation);
349
350 mStyle->insertItem("&Representation",mRepresentation);
351 fContextMenu->insertItem("&Style",mStyle);
352
353#else
354 // === Style Menu ===
[564]355 QMenu *mStyle = fContextMenu->addMenu("&Style");
356
357 QMenu *mRepresentation = mStyle->addMenu("&Representation");
[632]358 QAction *polyhedron = mRepresentation->addAction("Polyhedron");
[564]359 QAction *nurbs = mRepresentation->addAction("NURBS");
[599]360#endif
[564]361 // INIT mStyle
362 G4ViewParameters::RepStyle style;
363 style = fVP.GetRepStyle();
364 if (style == G4ViewParameters::polyhedron) {
365 createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),1);
366 } else if (style == G4ViewParameters::nurbs) {
367 createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),2);
[539]368 } else {
[564]369 mRepresentation->clear();
[539]370 }
371
372
[599]373#if QT_VERSION < 0x040000
374 // === Drawing Menu ===
375 QPopupMenu *mDrawing = new QPopupMenu(fContextMenu);
376 fContextMenu->insertItem("&Drawing",mDrawing);
377
378 fDrawingWireframe = new QPopupMenu(mDrawing);
379 mDrawing->insertItem("&Wireframe",fDrawingWireframe);
380
381 mDrawing->setCheckable(true);
382 fDrawingWireframe->setCheckable(true);
383
384 fDrawingLineRemoval = new QPopupMenu(mDrawing);
385 mDrawing->insertItem("&Hidden line removal",fDrawingLineRemoval);
386 fDrawingLineRemoval->setCheckable(true);
387
388 fDrawingSurfaceRemoval = new QPopupMenu(mDrawing);
389 mDrawing->insertItem("&Hidden surface removal",fDrawingSurfaceRemoval);
390 fDrawingSurfaceRemoval->setCheckable(true);
391
392 fDrawingLineSurfaceRemoval = new QPopupMenu(mDrawing);
393 mDrawing->insertItem("&Hidden line and surface removal",fDrawingLineSurfaceRemoval);
394 fDrawingLineSurfaceRemoval->setCheckable(true);
395
396#else
397 // === Drawing Menu ===
[564]398 QMenu *mDrawing = mStyle->addMenu("&Drawing");
[599]399
[564]400 fDrawingWireframe = mDrawing->addAction("Wireframe");
401 fDrawingWireframe->setCheckable(true);
[599]402
[564]403 fDrawingLineRemoval = mDrawing->addAction("Hidden line removal");
404 fDrawingLineRemoval->setCheckable(true);
[599]405
[564]406 fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal");
407 fDrawingSurfaceRemoval->setCheckable(true);
[599]408
[564]409 fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal");
410 fDrawingLineSurfaceRemoval->setCheckable(true);
[599]411#endif
[564]412 // INIT Drawing
413 G4ViewParameters::DrawingStyle d_style;
414 d_style = fVP.GetDrawingStyle();
415
[599]416#if QT_VERSION < 0x040000
[564]417 if (d_style == G4ViewParameters::wireframe) {
[599]418 fDrawingWireframe->setItemChecked(0,true);
419 } else if (d_style == G4ViewParameters::hlr) {
420 fDrawingLineRemoval->setItemChecked(0,true);
421 } else if (d_style == G4ViewParameters::hsr) {
422 fDrawingSurfaceRemoval->setItemChecked(0,true);
423 } else if (d_style == G4ViewParameters::hlhsr) {
424 fDrawingLineSurfaceRemoval->setItemChecked(0,true);
425 } else {
426 mDrawing->clear();
427 }
[610]428#ifdef GEANT4_QT_DEBUG
429 printf("G4OpenGLQtViewer:: fDrawingWireframe 1\n");
430#endif
431 QObject ::connect(fDrawingWireframe,
432 SIGNAL(activated(int)),
433 this,
434 SLOT(actionDrawingWireframe()));
435#ifdef GEANT4_QT_DEBUG
436 printf("G4OpenGLQtViewer:: fDrawingWireframe 2\n");
437#endif
438 QObject ::connect(fDrawingLineRemoval,
439 SIGNAL(activated(int)),
440 this,
441 SLOT(actionDrawingLineRemoval()));
442 QObject ::connect(fDrawingSurfaceRemoval,
443 SIGNAL(activated(int)),
444 this,
445 SLOT(actionDrawingSurfaceRemoval()));
446 QObject ::connect(fDrawingLineSurfaceRemoval,
447 SIGNAL(activated(int)),
448 this,
449 SLOT(actionDrawingLineSurfaceRemoval()));
[599]450#else
451 if (d_style == G4ViewParameters::wireframe) {
[564]452 fDrawingWireframe->setChecked(true);
453 } else if (d_style == G4ViewParameters::hlr) {
454 fDrawingLineRemoval->setChecked(true);
455 } else if (d_style == G4ViewParameters::hsr) {
456 fDrawingSurfaceRemoval->setChecked(true);
457 } else if (d_style == G4ViewParameters::hlhsr) {
458 fDrawingLineSurfaceRemoval->setChecked(true);
459 } else {
460 mDrawing->clear();
461 }
[565]462 QObject ::connect(fDrawingWireframe,
463 SIGNAL(triggered(bool)),
464 this,
465 SLOT(actionDrawingWireframe()));
466 QObject ::connect(fDrawingLineRemoval,
467 SIGNAL(triggered(bool)),
468 this,
469 SLOT(actionDrawingLineRemoval()));
470 QObject ::connect(fDrawingSurfaceRemoval,
471 SIGNAL(triggered(bool)),
472 this,
473 SLOT(actionDrawingSurfaceRemoval()));
474 QObject ::connect(fDrawingLineSurfaceRemoval,
475 SIGNAL(triggered(bool)),
476 this,
477 SLOT(actionDrawingLineSurfaceRemoval()));
[610]478#endif
[564]479
480
[610]481
[599]482#if QT_VERSION < 0x040000
483 QPopupMenu *mBackground = new QPopupMenu(mStyle);
484 mStyle->insertItem("&Background color",mBackground);
485
[617]486#if QT_VERSION < 0x030200
487 QAction *white = new QAction("&White","&White",CTRL+Key_W,mBackground);
488 QAction *black = new QAction("&Black","&Black",CTRL+Key_B,mBackground);
489#else
[599]490 QAction *white = new QAction("&White",CTRL+Key_W,mBackground);
491 QAction *black = new QAction("&Black",CTRL+Key_B,mBackground);
[617]492#endif
[599]493 white->addTo(mBackground);
494 black->addTo(mBackground);
495
496#else
[564]497 QMenu *mBackground = mStyle->addMenu("&Background color");
498 QAction *white = mBackground->addAction("White");
499 QAction *black = mBackground->addAction("Black");
[599]500
501#endif
[564]502 if (background.GetRed() == 1. &&
503 background.GetGreen() == 1. &&
504 background.GetBlue() == 1.) {
505 createRadioAction(white,black,SLOT(toggleBackground(bool)),1);
506 } else {
507 createRadioAction(white,black,SLOT(toggleBackground(bool)),2);
508 }
509
510
[599]511#if QT_VERSION < 0x040000
512 // === Action Menu ===
513 QPopupMenu *mActions = new QPopupMenu(fContextMenu);
514 fContextMenu->insertItem("&Actions",mActions);
515
[617]516#if QT_VERSION < 0x030200
517 QAction *controlPanels = new QAction("&Control panels","&Control panels",CTRL+Key_C,mActions);
518 QAction *exitG4 = new QAction("&Exit to G4Vis >","&Exit to G4Vis >",CTRL+Key_E,mActions);
519 QAction *createEPS = new QAction("&Save as ...","&Save as ...",CTRL+Key_S,mActions);
520#else
[599]521 QAction *controlPanels = new QAction("&Control panels",CTRL+Key_C,mActions);
522 QAction *exitG4 = new QAction("&Exit to G4Vis >",CTRL+Key_E,mActions);
523 QAction *createEPS = new QAction("&Save as ...",CTRL+Key_S,mActions);
[617]524#endif
[599]525 controlPanels->addTo(mActions);
526 exitG4->addTo(mActions);
527 createEPS->addTo(mActions);
[610]528 QObject ::connect(controlPanels,
529 SIGNAL(activated()),
530 this,
531 SLOT(actionControlPanels()));
532 QObject ::connect(exitG4,
533 SIGNAL(activated()),
534 this,
535 SLOT(actionExitG4()));
536 QObject ::connect(createEPS,
537 SIGNAL(activated()),
538 this,
539 SLOT(actionCreateEPS()));
[599]540
541#else
542 // === Action Menu ===
[564]543 QMenu *mActions = fContextMenu->addMenu("&Actions");
[565]544 QAction *controlPanels = mActions->addAction("Control panels");
545 QAction *exitG4 = mActions->addAction("Exit to G4Vis >");
[568]546 QAction *createEPS = mActions->addAction("Save as ...");
[565]547 QObject ::connect(controlPanels,
[566]548 SIGNAL(triggered()),
[565]549 this,
550 SLOT(actionControlPanels()));
551 QObject ::connect(exitG4,
[566]552 SIGNAL(triggered()),
[565]553 this,
554 SLOT(actionExitG4()));
555 QObject ::connect(createEPS,
[566]556 SIGNAL(triggered()),
[565]557 this,
558 SLOT(actionCreateEPS()));
[610]559#endif
[564]560
561
[610]562
[599]563#if QT_VERSION < 0x040000
564 // === Special Menu ===
565 QPopupMenu *mSpecial = new QPopupMenu(fContextMenu);
566 fContextMenu->insertItem("S&pecial",mSpecial);
567
568 QPopupMenu *mTransparency = new QPopupMenu(mSpecial);
569 mSpecial->insertItem("Transparency",mTransparency);
570
[617]571#if QT_VERSION < 0x030200
572 QAction *transparencyOn = new QAction("&On","&On",CTRL+Key_O,mTransparency);
573 QAction *transparencyOff = new QAction("&Off","&Off",CTRL+Key_F,mTransparency);
574#else
[599]575 QAction *transparencyOn = new QAction("&On",CTRL+Key_O,mTransparency);
576 QAction *transparencyOff = new QAction("&Off",CTRL+Key_F,mTransparency);
[617]577#endif
[599]578 transparencyOn->addTo(mTransparency);
579 transparencyOff->addTo(mTransparency);
580
581#else
582 // === Special Menu ===
[564]583 QMenu *mSpecial = fContextMenu->addMenu("S&pecial");
[599]584 QMenu *mTransparency = mSpecial->addMenu("Transparency");
585 QAction *transparencyOn = mTransparency->addAction("On");
586 QAction *transparencyOff = mTransparency->addAction("Off");
587#endif
588
[564]589 if (transparency_enabled == false) {
590 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2);
591 } else if (transparency_enabled == true) {
592 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),1);
593 } else {
594 mSpecial->clear();
595 }
596
597
[599]598#if QT_VERSION < 0x040000
599 QPopupMenu *mAntialiasing = new QPopupMenu(mSpecial);
600 mSpecial->insertItem("Antialiasing",mAntialiasing);
601
[617]602#if QT_VERSION < 0x030200
603 QAction *antialiasingOn = new QAction("&On","&On",CTRL+Key_O,mAntialiasing);
604 QAction *antialiasingOff = new QAction("&Off","&Off",CTRL+Key_F,mAntialiasing);
605#else
[599]606 QAction *antialiasingOn = new QAction("&On",CTRL+Key_O,mAntialiasing);
607 QAction *antialiasingOff = new QAction("&Off",CTRL+Key_F,mAntialiasing);
[617]608#endif
[599]609 antialiasingOn->addTo(mAntialiasing);
610 antialiasingOff->addTo(mAntialiasing);
611
612#else
[564]613 QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing");
614 QAction *antialiasingOn = mAntialiasing->addAction("On");
615 QAction *antialiasingOff = mAntialiasing->addAction("Off");
[599]616#endif
617
[564]618 if (antialiasing_enabled == false) {
619 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2);
620 } else if (antialiasing_enabled == true) {
621 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),1);
622 } else {
623 mAntialiasing->clear();
624 }
625
[599]626#if QT_VERSION < 0x040000
627 QPopupMenu *mHaloing = new QPopupMenu(mSpecial);
628 mSpecial->insertItem("Haloing",mHaloing);
629
[617]630#if QT_VERSION < 0x030200
631 QAction *haloingOn = new QAction("&On","&On",CTRL+Key_O,mHaloing);
632 QAction *haloingOff = new QAction("&Off","&Off",CTRL+Key_F,mHaloing);
633#else
[599]634 QAction *haloingOn = new QAction("&On",CTRL+Key_O,mHaloing);
635 QAction *haloingOff = new QAction("&Off",CTRL+Key_F,mHaloing);
[617]636#endif
[599]637 haloingOn->addTo(mHaloing);
638 haloingOff->addTo(mHaloing);
639#else
[564]640 QMenu *mHaloing = mSpecial->addMenu("Haloing");
641 QAction *haloingOn = mHaloing->addAction("On");
642 QAction *haloingOff = mHaloing->addAction("Off");
[599]643#endif
[564]644 if (haloing_enabled == false) {
645 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2);
646 } else if (haloing_enabled == true) {
647 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),1);
648 } else {
649 mHaloing->clear();
650 }
651
[599]652#if QT_VERSION < 0x040000
653 QPopupMenu *mAux = new QPopupMenu(mSpecial);
654 mSpecial->insertItem("Auxiliairy edges",mAux);
655
[617]656#if QT_VERSION < 0x030200
657 QAction *auxOn = new QAction("&On","&On",CTRL+Key_O,mAux);
658 QAction *auxOff = new QAction("&Off","&Off",CTRL+Key_F,mAux);
659#else
[599]660 QAction *auxOn = new QAction("&On",CTRL+Key_O,mAux);
661 QAction *auxOff = new QAction("&Off",CTRL+Key_F,mAux);
[617]662#endif
[599]663 auxOn->addTo(mAux);
664 auxOff->addTo(mAux);
665
666#else
[564]667 QMenu *mAux = mSpecial->addMenu("Auxiliary edges");
668 QAction *auxOn = mAux->addAction("On");
669 QAction *auxOff = mAux->addAction("Off");
[599]670#endif
[564]671 if (!fVP.IsAuxEdgeVisible()) {
672 createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1);
673 } else {
674 createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),2);
675 }
676
677
[617]678#if QT_VERSION >= 0x030200
[599]679#if QT_VERSION < 0x040000
680 QPopupMenu *mFullScreen = new QPopupMenu(mSpecial);
681 mSpecial->insertItem("Full screen",mFullScreen);
682
683 QAction *fullOn = new QAction("&On",CTRL+Key_O,mFullScreen);
684 QAction *fullOff = new QAction("&Off",CTRL+Key_F,mFullScreen);
685 fullOn->addTo(mFullScreen);
686 fullOff->addTo(mFullScreen);
687#else
[564]688 QMenu *mFullScreen = mSpecial->addMenu("Full screen");
689 QAction *fullOn = mFullScreen->addAction("On");
690 QAction *fullOff = mFullScreen->addAction("Off");
[599]691#endif
[564]692 createRadioAction(fullOn,fullOff,SLOT(toggleFullScreen(bool)),2);
[617]693#endif
[564]694
695}
696
697void G4OpenGLQtViewer::manageContextMenuEvent(QContextMenuEvent *e)
698{
[579]699 if (!GLWindow) {
[638]700 G4cerr << "Visualization window not defined, please choose one before\n" << G4endl;
[579]701 } else {
[539]702
[579]703 if (!fContextMenu)
704 createPopupMenu();
705
706 // launch menu
707 if ( fContextMenu ) {
708 fContextMenu->exec( e->globalPos() );
709 // delete fContextMenu;
710 }
[564]711 }
712 e->accept();
713}
[539]714
715
[564]716/**
717 Create a radio button menu. The two menu will be connected. When click on one,
718 eatch state will be invert and callback method will be called.
719 @param action1 first action to connect
720 @param action2 second action to connect
721 @param method callback method
722 @param nCheck: 1 : first action will be set true. 2 : second action will be set true
723*/
[599]724#if QT_VERSION < 0x040000
[564]725void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
726
[599]727 if (action1->parent()->inherits("QPopupMenu")){
728 ((QPopupMenu*)action1->parent())->setCheckable(true);
729 }
730 ((QPopupMenu*)action1->parent())->setItemChecked(0,true);
731 ((QPopupMenu*)action1->parent())->setItemChecked(1,true);
732
733 if (nCheck ==1)
734 ((QPopupMenu*)action1->parent())->setItemChecked(0,true);
735 else
736 ((QPopupMenu*)action1->parent())->setItemChecked(1,true);
737
[610]738 //FIXME : Should not work on Qt3
739 QObject ::connect(action1, SIGNAL(activated()),action2, SLOT(toggle()));
740 QObject ::connect(action2, SIGNAL(activated()),action1, SLOT(toggle()));
[599]741
742 QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str());
743}
744
745#else
746void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
747
[564]748 action1->setCheckable(true);
749 action2->setCheckable(true);
750
751 if (nCheck ==1)
752 action1->setChecked (true);
753 else
754 action2->setChecked (true);
755
756 QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle()));
757 QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle()));
758
759 QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str());
760
761}
[599]762#endif
[564]763
764/**
765 Slot activate when drawing->wireframe menu is set
766 */
767void G4OpenGLQtViewer::actionDrawingWireframe() {
768 emit toggleDrawingAction(1);
769}
770
771/**
772 Slot activate when drawing->line removal menu is set
773 */
774void G4OpenGLQtViewer::actionDrawingLineRemoval() {
775 emit toggleDrawingAction(2);
776}
777
778/**
779 Slot activate when drawing->surface removal menu is set
780 */
781void G4OpenGLQtViewer::actionDrawingSurfaceRemoval() {
782 emit toggleDrawingAction(3);
783}
784
785/**
786 Slot activate when drawing->wireframe menu is set
787 */
788void G4OpenGLQtViewer::actionDrawingLineSurfaceRemoval() {
789 emit toggleDrawingAction(4);
790}
791
792
793/**
[565]794 Slot activated when drawing menu is toggle
795 Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
796 KernelVisitDecision () will be call and will set the fNeedKernelVisit
797 to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
798 It will cause a redraw of the view
799 @param aAction : 1 wireframe, 2 line removal, 3 surface removal, 4 line & surface removal
800 @see G4OpenGLStoredQtViewer::DrawView
801 @see G4XXXStoredViewer::CompareForKernelVisit
[564]802 */
803void G4OpenGLQtViewer::toggleDrawingAction(int aAction) {
804
805 G4ViewParameters::DrawingStyle d_style;
[539]806
807
[564]808 if (aAction ==1) {
[600]809#if QT_VERSION < 0x040000
810 fDrawingWireframe->setItemChecked (0,true);
811 fDrawingLineRemoval->setItemChecked (0,false);
812 fDrawingSurfaceRemoval->setItemChecked (0,false);
813 fDrawingLineSurfaceRemoval->setItemChecked (0,false);
814#else
[564]815 fDrawingWireframe->setChecked (true);
816 fDrawingLineRemoval->setChecked (false);
817 fDrawingSurfaceRemoval->setChecked (false);
818 fDrawingLineSurfaceRemoval->setChecked (false);
[600]819#endif
[564]820
821 d_style = G4ViewParameters::wireframe;
822
823 } else if (aAction ==2) {
[600]824#if QT_VERSION < 0x040000
825 fDrawingWireframe->setItemChecked (0,false);
826 fDrawingLineRemoval->setItemChecked (0,true);
827 fDrawingSurfaceRemoval->setItemChecked (0,false);
828 fDrawingLineSurfaceRemoval->setItemChecked (0,false);
829#else
[564]830 fDrawingWireframe->setChecked (false);
831 fDrawingLineRemoval->setChecked (true);
832 fDrawingSurfaceRemoval->setChecked (false);
833 fDrawingLineSurfaceRemoval->setChecked (false);
[600]834#endif
[564]835
836 d_style = G4ViewParameters::hlr;
837
838 } else if (aAction ==3) {
[600]839#if QT_VERSION < 0x040000
840 fDrawingWireframe->setItemChecked (0,false);
841 fDrawingLineRemoval->setItemChecked (0,false);
842 fDrawingSurfaceRemoval->setItemChecked (0,true);
843 fDrawingLineSurfaceRemoval->setItemChecked (0,false);
844#else
[564]845 fDrawingWireframe->setChecked (false);
846 fDrawingLineRemoval->setChecked (false);
847 fDrawingSurfaceRemoval->setChecked (true);
848 fDrawingLineSurfaceRemoval->setChecked (false);
[600]849#endif
[564]850
851 d_style = G4ViewParameters::hsr;
852
853 } else if (aAction ==4) {
[600]854#if QT_VERSION < 0x040000
855 fDrawingWireframe->setItemChecked (0,false);
856 fDrawingLineRemoval->setItemChecked (0,false);
857 fDrawingSurfaceRemoval->setItemChecked (0,false);
858 fDrawingLineSurfaceRemoval->setItemChecked (0,true);
859#else
[564]860 fDrawingWireframe->setChecked (false);
861 fDrawingLineRemoval->setChecked (false);
862 fDrawingSurfaceRemoval->setChecked (false);
863 fDrawingLineSurfaceRemoval->setChecked (true);
[600]864#endif
[564]865 d_style = G4ViewParameters::hlhsr;
866 }
867 fVP.SetDrawingStyle(d_style);
868
869 updateQWidget();
[608]870#ifdef GEANT4_QT_DEBUG
[564]871 printf("G4OpenGLQtViewer::toggleDrawingAction\n");
[608]872#endif
[539]873}
874
[564]875
876/**
877 SLOT Activate by a click on the representation menu
[565]878 Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
879 KernelVisitDecision () will be call and will set the fNeedKernelVisit
880 to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
881 It will cause a redraw of the view
[564]882 @param check : 1 polyhedron, 0 nurbs
[565]883 @see G4OpenGLStoredQtViewer::DrawView
884 @see G4XXXStoredViewer::CompareForKernelVisit
[564]885*/
886void G4OpenGLQtViewer::toggleRepresentation(bool check) {
887
888 G4ViewParameters::RepStyle style;
889 if (check == 1) {
890 style = G4ViewParameters::polyhedron;
891 } else {
892 style = G4ViewParameters::nurbs;
893 }
894 fVP.SetRepStyle (style);
895
[608]896#ifdef GEANT4_QT_DEBUG
[564]897 printf("G4OpenGLQtViewer::toggleRepresentation 3%d\n",check);
[608]898#endif
[564]899 updateQWidget();
[608]900#ifdef GEANT4_QT_DEBUG
[564]901 printf("G4OpenGLQtViewer::toggleRepresentation 4%d\n",check);
[608]902#endif
[530]903}
904
[564]905/**
906 SLOT Activate by a click on the background menu
907@param check : 1 white, 0 black
908*/
909void G4OpenGLQtViewer::toggleBackground(bool check) {
910
911 // //I need to revisit the kernel if the background colour changes and
912 // //hidden line removal is enabled, because hlr drawing utilises the
913 // //background colour in its drawing...
914 // // (Note added by JA 13/9/2005) Background now handled in view
915 // // parameters. A kernel visit is triggered on change of background.
916 if (check == 1) {
917 ((G4ViewParameters&)this->GetViewParameters()).
918 SetBackgroundColour(G4Colour(1.,1.,1.)); // White
919 } else {
920 ((G4ViewParameters&)this->GetViewParameters()).
921 SetBackgroundColour(G4Colour(0.,0.,0.)); // Black
922 }
923 updateQWidget();
[530]924}
925
[564]926/**
927 SLOT Activate by a click on the transparency menu
928@param check : 1 , 0
929*/
930void G4OpenGLQtViewer::toggleTransparency(bool check) {
931
932 if (check) {
933 transparency_enabled = false;
934 } else {
935 transparency_enabled = true;
936 }
937 SetNeedKernelVisit (true);
938 updateQWidget();
939}
[530]940
[564]941/**
942 SLOT Activate by a click on the antialiasing menu
943@param check : 1 , 0
944*/
945void G4OpenGLQtViewer::toggleAntialiasing(bool check) {
946
947 if (!check) {
948 antialiasing_enabled = false;
949 glDisable (GL_LINE_SMOOTH);
950 glDisable (GL_POLYGON_SMOOTH);
951 } else {
952 antialiasing_enabled = true;
953 glEnable (GL_LINE_SMOOTH);
954 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
955 glEnable (GL_POLYGON_SMOOTH);
956 glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
[530]957 }
[564]958
959 updateQWidget();
[608]960#ifdef GEANT4_QT_DEBUG
[564]961 printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
[608]962#endif
[564]963}
964
965/**
966 SLOT Activate by a click on the haloing menu
967@param check : 1 , 0
[530]968*/
[564]969//FIXME : I SEE NOTHING...
970void G4OpenGLQtViewer::toggleHaloing(bool check) {
971 if (check) {
972 haloing_enabled = false;
973 } else {
974 haloing_enabled = true;
975 }
[530]976
[564]977 updateQWidget();
[530]978
[608]979#ifdef GEANT4_QT_DEBUG
[564]980 printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
[608]981#endif
[564]982}
983
984/**
985 SLOT Activate by a click on the auxiliaire edges menu
986@param check : 1 , 0
987*/
988void G4OpenGLQtViewer::toggleAux(bool check) {
989 if (check) {
990 fVP.SetAuxEdgeVisible(false);
991 } else {
992 fVP.SetAuxEdgeVisible(true);
993 }
994 SetNeedKernelVisit (true);
995 updateQWidget();
996
[608]997#ifdef GEANT4_QT_DEBUG
[564]998 printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
[608]999#endif
[564]1000}
1001
1002/**
1003 SLOT Activate by a click on the full screen menu
1004@param check : 1 , 0
1005*/
1006void G4OpenGLQtViewer::toggleFullScreen(bool check) {
[617]1007#if QT_VERSION >= 0x030200
[564]1008 GLWindow->setWindowState(GLWindow->windowState() ^ Qt::WindowFullScreen);
[617]1009#else
[638]1010 G4cerr << "This version of G4UI Could not generate the selected format\n" << G4endl;
[617]1011#endif
[608]1012#ifdef GEANT4_QT_DEBUG
[564]1013 printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
[608]1014#endif
[564]1015}
1016
1017/**
1018 SLOT Activate by a click on the mouse action menu
1019 @param check : 1 , 0
1020*/
1021void G4OpenGLQtViewer::toggleMouseAction(bool check) {
1022 if (check) { // rotate scene
1023 fMouseAction = true;
1024 } else { // move scene
1025 fMouseAction = false;
1026 }
1027
[608]1028#ifdef GEANT4_QT_DEBUG
[564]1029 printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
[608]1030#endif
[564]1031}
1032
1033
[565]1034void G4OpenGLQtViewer::actionControlPanels() {
[608]1035#ifdef GEANT4_QT_DEBUG
[565]1036 printf("G4OpenGLQtViewer::actionControlPanels \n");
[608]1037#endif
[565]1038}
1039
1040void G4OpenGLQtViewer::actionExitG4() {
[608]1041#ifdef GEANT4_QT_DEBUG
[565]1042 printf("G4OpenGLQtViewer::actionExitG4() \n");
[608]1043#endif
[565]1044}
1045
1046void G4OpenGLQtViewer::actionCreateEPS() {
[580]1047 QString filters;
[600]1048#if QT_VERSION < 0x040000
1049 QStrList listFormat=QImageIO::outputFormats();
1050 char *tmp=listFormat.first();
1051 while (tmp!=0) {
1052 filters += QString(tmp) + ";;";
1053 tmp=listFormat.next();
1054 }
1055#else
[580]1056 QList<QByteArray> formats = QImageWriter::supportedImageFormats ();
1057 for (int i = 0; i < formats.size(); ++i) {
[600]1058 filters +=formats.at(i) + ";;";
[580]1059 }
[600]1060#endif
[588]1061 filters += "eps;;";
1062 filters += "ps;;";
1063 filters += "pdf";
[639]1064 QString* selectedFormat = new QString();
[600]1065#if QT_VERSION < 0x040000
1066 QString nomFich = QFileDialog::getSaveFileName ( ".",
1067 filters,
1068 GLWindow,
1069 "Save file dialog",
1070 tr("Save as ..."),
[639]1071 selectedFormat );
[600]1072#else
[580]1073 QString nomFich = QFileDialog::getSaveFileName ( GLWindow,
1074 tr("Save as ..."),
1075 ".",
[582]1076 filters,
[639]1077 selectedFormat );
[600]1078#endif
[580]1079 // bmp jpg jpeg png ppm xbm xpm
[582]1080 if (nomFich == "") {
1081 return;
1082 }
[600]1083#if QT_VERSION < 0x040000
[639]1084 nomFich += "."+QString(selectedFormat->ascii());
1085 QString format = selectedFormat->lower();
[600]1086#else
[639]1087 nomFich += "."+QString(selectedFormat->toStdString().c_str());
1088 QString format = selectedFormat->toLower();
[600]1089#endif
[639]1090 G4OpenGLQtExportDialog* exportDialog= new G4OpenGLQtExportDialog(GLWindow,nomFich,format,fWindow->height(),fWindow->width());
[585]1091 if( exportDialog->exec()) {
[593]1092
1093 QImage image;
[635]1094 if ((exportDialog->getWidth() !=fWindow->width()) ||
1095 (exportDialog->getHeight() !=fWindow->height())) {
[638]1096 G4cerr << "Export->Change Size : This function is not implemented, to export in another size, please resize your frame to what you need\n" << G4endl;
[585]1097
[635]1098 // rescaleImage(exportDialog->getWidth(),exportDialog->getHeight());// re-scale image
1099 // QGLWidget* glResized = fWindow;
1100
1101 // FIXME :
1102 // L.Garnier : I've try to implement change size function, but the problem is
1103 // the renderPixmap function call the QGLWidget to resize and it doesn't draw
1104 // the content of this widget... It only draw the background.
1105
1106 // fWindow->renderPixmap (exportDialog->getWidth()*2,exportDialog->getHeight()*2,true );
1107
1108 // QPixmap pixmap = fWindow->renderPixmap ();
1109
1110 // image = pixmap->toImage();
[593]1111 // glResized->resize(exportDialog->getWidth()*2,exportDialog->getHeight()*2);
1112 // image = glResized->grabFrameBuffer();
1113
[635]1114 } else {
1115 image = fWindow->grabFrameBuffer();
1116 }
[639]1117 if (format == QString("eps")) {
[586]1118 generateEPS(nomFich,exportDialog->getNbColor(),image);
[639]1119 } else if ((format == "ps") || (format == "pdf")) {
[588]1120 generatePS_PDF(nomFich,exportDialog->getNbColor(),image);
[639]1121 } else if ((format == "tif") ||
1122 (format == "tiff") ||
1123 (format == "jpg") ||
1124 (format == "jpeg") ||
1125 (format == "png") ||
1126 (format == "pbm") ||
1127 (format == "pgm") ||
1128 (format == "ppm") ||
1129 (format == "bmp") ||
1130 (format == "xbm") ||
1131 (format == "xpm")) {
1132#if QT_VERSION < 0x040000
1133 bool res = image.save(nomFich,selectedFormat->ascii(),exportDialog->getSliderValue());
1134#else
[635]1135 bool res = image.save(nomFich,0,exportDialog->getSliderValue());
[639]1136#endif
[635]1137 if (res == false) {
[638]1138 G4cerr << "Error while saving file...\n" << G4endl;
[635]1139 }
[585]1140 } else {
[638]1141 G4cerr << "This version of G4UI Could not generate the selected format\n" << G4endl;
[585]1142 }
1143
1144 } else { // cancel selected
1145 return;
[568]1146 }
[580]1147
[608]1148#ifdef GEANT4_QT_DEBUG
[565]1149 printf("G4OpenGLQtViewer::actionCreateEPS() \n");
[608]1150#endif
[565]1151}
1152
[580]1153/*
1154// 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
[565]1155
[580]1156void Graph::exportToSVG(const QString& fname)
1157{
1158 // enable workaround for Qt3 misalignments
1159 QwtPainter::setSVGMode(true);
1160 QPicture picture;
1161 QPainter p(&picture);
1162 d_plot->print(&p, d_plot->rect());
1163 p.end();
[565]1164
[580]1165 picture.save(fname, "svg");
1166}
1167*/
1168
1169
1170
1171
[564]1172/**
1173 Save the current mouse press point
1174 @param p mouse click point
1175*/
1176void G4OpenGLQtViewer::G4MousePressEvent(QPoint p)
1177{
1178 lastPos = p;
1179}
1180
1181/**
1182 @param pos_x mouse x position
1183 @param pos_y mouse y position
1184 @param mButtons mouse button active
1185*/
[599]1186
1187#if QT_VERSION < 0x040000
1188void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::ButtonState mButtons)
1189#else
[564]1190void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons)
[599]1191#endif
[564]1192{
1193 int dx = pos_x - lastPos.x();
1194 int dy = pos_y - lastPos.y();
[530]1195
[564]1196 if (fMouseAction) { // rotate
1197 if (mButtons & Qt::LeftButton) {
1198 //phi spin stuff here
1199
1200 G4Vector3D vp = fVP.GetViewpointDirection ().unit ();
1201 G4Vector3D up = fVP.GetUpVector ().unit ();
1202
1203 G4Vector3D yprime = (up.cross(vp)).unit();
1204 G4Vector3D zprime = (vp.cross(yprime)).unit();
1205
1206 G4double delta_alpha;
1207 G4double delta_theta;
1208
1209 if (fVP.GetLightsMoveWithCamera()) {
1210 delta_alpha = dy;
1211 delta_theta = -dx;
1212 } else {
1213 delta_alpha = -dy;
1214 delta_theta = dx;
1215 }
[530]1216
[564]1217 delta_alpha *= deg;
1218 delta_theta *= deg;
[530]1219
[564]1220 G4Vector3D new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime;
1221
1222 G4Vector3D new_up;
1223 if (fVP.GetLightsMoveWithCamera()) {
1224 new_up = (new_vp.cross(yprime)).unit();
1225 fVP.SetUpVector(new_up);
1226 } else {
1227 new_up = up;
1228 }
1229 ////////////////
1230 // Rotates by fixed azimuthal angle delta_theta.
1231
1232 G4double cosalpha = new_up.dot (new_vp.unit());
1233 G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));
1234 yprime = (new_up.cross (new_vp.unit())).unit ();
1235 G4Vector3D xprime = yprime.cross (new_up);
1236 // Projection of vp on plane perpendicular to up...
1237 G4Vector3D a1 = sinalpha * xprime;
1238 // Required new projection...
1239 G4Vector3D a2 =
1240 sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);
1241 // Required Increment vector...
1242 G4Vector3D delta = a2 - a1;
1243 // So new viewpoint is...
1244 G4Vector3D viewPoint = new_vp.unit() + delta;
1245
1246 fVP.SetViewAndLights (viewPoint);
1247 updateQWidget();
1248
1249 } else if (mButtons & Qt::RightButton) {
1250 // NEVER DONE BECAUSE OF MOUSE MENU
[608]1251#ifdef GEANT4_QT_DEBUG
[564]1252 // printf("G4OpenGLQtViewer::mouseMoveEvent Right \n");
[608]1253#endif
[564]1254 // setXRotation(xRot + dy/2);
1255 // setZRotation(zRot + dx/2);
1256 // updateQWidget();
1257 }
1258 } else { // move
1259
1260 float dx = pos_x - lastPos.x();
1261 float dy = pos_y - lastPos.y();
1262
1263 G4Point3D stp
1264 = GetSceneHandler()->GetScene()->GetStandardTargetPoint();
1265
1266 G4Point3D tp = stp + fVP.GetCurrentTargetPoint ();
1267
1268 const G4Vector3D& upVector = fVP.GetUpVector ();
1269 const G4Vector3D& vpVector = fVP.GetViewpointDirection ();
1270
1271 G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
1272 G4Vector3D unitUp = (vpVector.cross (unitRight)).unit();
1273
1274 tp += -dx * unitRight + dy * unitUp;
1275 fVP.SetCurrentTargetPoint (tp - stp);
1276
1277 updateQWidget();
1278 }
1279 lastPos = QPoint(pos_x, pos_y);
1280}
1281
[585]1282void G4OpenGLQtViewer::rescaleImage(
1283 int aWidth
1284,int aHeight
1285){
[608]1286#ifdef GEANT4_QT_DEBUG
[586]1287 printf("should rescale \n");
[608]1288#endif
[585]1289}
[586]1290
1291/**
1292 Generate Postscript form image
1293 @param aFilename : name of file
1294 @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha
1295 @param aImage : Image to print
1296*/
[588]1297bool G4OpenGLQtViewer::generateEPS (
[586]1298 QString aFilename
1299,int aInColor
1300,QImage aImage
1301)
1302{
[587]1303 // FIXME
[608]1304#ifdef GEANT4_QT_DEBUG
[586]1305 printf("saving EPS\n");
[608]1306#endif
[586]1307
1308 FILE* fp;
[587]1309
[589]1310 if ((!aImage.isGrayscale ()) &&(aInColor ==1 )) {
[600]1311#if QT_VERSION < 0x040000
[637]1312 aImage = aImage.convertDepth(1,Qt::MonoOnly);
[600]1313#else
[637]1314 aImage = aImage.convertToFormat ( aImage.format(), Qt::MonoOnly);
[600]1315#endif
[589]1316 }
[586]1317 const uchar * pixels = aImage.bits ();
1318
1319 if (pixels == NULL)
[588]1320 return false;
[586]1321
[600]1322#if QT_VERSION < 0x040000
1323 fp = fopen (aFilename.ascii(), "w");
1324#else
[602]1325 fp = fopen (aFilename.toStdString().c_str(), "w");
[600]1326#endif
[586]1327 if (fp == NULL) {
[588]1328 return false;
[586]1329 }
1330
1331 fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n");
[600]1332#if QT_VERSION < 0x040000
1333 fprintf (fp, "%%%%Title: %s\n", aFilename.ascii());
1334#else
[602]1335 fprintf (fp, "%%%%Title: %s\n", aFilename.toStdString().c_str());
[600]1336#endif
[586]1337 fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n");
[587]1338 fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", aImage.width(), aImage.height());
[586]1339 fprintf (fp, "%%%%EndComments\n");
1340 fprintf (fp, "gsave\n");
1341 fprintf (fp, "/bwproc {\n");
1342 fprintf (fp, " rgbproc\n");
1343 fprintf (fp, " dup length 3 idiv string 0 3 0 \n");
1344 fprintf (fp, " 5 -1 roll {\n");
1345 fprintf (fp, " add 2 1 roll 1 sub dup 0 eq\n");
1346 fprintf (fp, " { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n");
1347 fprintf (fp, " 3 1 roll 5 -1 roll } put 1 add 3 0 \n");
1348 fprintf (fp, " { 2 1 roll } ifelse\n");
1349 fprintf (fp, " }forall\n");
1350 fprintf (fp, " pop pop pop\n");
1351 fprintf (fp, "} def\n");
1352 fprintf (fp, "systemdict /colorimage known not {\n");
1353 fprintf (fp, " /colorimage {\n");
1354 fprintf (fp, " pop\n");
1355 fprintf (fp, " pop\n");
1356 fprintf (fp, " /rgbproc exch def\n");
1357 fprintf (fp, " { bwproc } image\n");
1358 fprintf (fp, " } def\n");
1359 fprintf (fp, "} if\n");
[587]1360 fprintf (fp, "/picstr %d string def\n", aImage.width() * aInColor);
1361 fprintf (fp, "%d %d scale\n", aImage.width(), aImage.height());
1362 fprintf (fp, "%d %d %d\n", aImage.width(), aImage.height(), 8);
1363 fprintf (fp, "[%d 0 0 %d 0 0]\n", aImage.width(), aImage.height());
[586]1364 fprintf (fp, "{currentfile picstr readhexstring pop}\n");
1365 fprintf (fp, "false %d\n", aInColor);
1366 fprintf (fp, "colorimage\n");
1367
1368
[588]1369 int width = aImage.width();
1370 int height = aImage.height();
1371 int depth = aImage.depth();
1372 int size = width*height;
1373
1374 if (depth == 1)
1375 size = (width+7)/8*height;
1376 else if (aInColor == 1)
1377 size = size*3;
1378
1379 int i = 0;
1380 if (depth == 1) {
1381 // To be implemented
1382 // QImage::Endian bitOrder = aImage.bitOrder();
1383 /* for(int y=0; y < height; y++) {
1384 const uchar * s = aImage.scanLine(y);
1385 for(int x=0; x < width; x++) {
1386 // need to copy bit for bit...
1387 bool b = (bitOrder == QImage::LittleEndian) ?
1388 (*(s + (x >> 3)) >> (x & 7)) & 1 :
1389 (*(s + (x >> 3)) << (x & 7)) & 0x80 ;
1390 if (b)
1391 pixel[i >> 3] ^= (0x80 >> (i & 7));
1392 i++;
[587]1393 }
[588]1394 // we need to align to 8 bit here
1395 i = (i+7) & 0xffffff8;
1396 }
1397 */
1398 } else if (depth == 8) {
1399 for(int y=height-1; y >=0 ; y--) {
1400 const uchar * s = aImage.scanLine(y);
1401 for(int x=0; x <width; x++) {
1402 QRgb rgb = aImage.color(s[x]);
1403 if (aInColor == 1) {
1404 fprintf (fp, " %02hx ",(unsigned char)qGray(rgb));
1405 i++;
1406 } else {
1407 fprintf (fp, " %02hx %02hx %02hx",
1408 (unsigned char) qRed(rgb),
1409 (unsigned char) qGreen(rgb),
1410 (unsigned char) qBlue(rgb));
1411 i += 3;
1412 }
1413 }
[586]1414 fprintf (fp, "\n");
[588]1415 }
1416 } else {
[601]1417#if QT_VERSION < 0x040000
[638]1418 G4cerr << "GenerateEPS:: No alpha channel image with Qt3. This is only supported with Qt4\n" << G4endl;
[601]1419#else
[588]1420 bool alpha = aImage.hasAlphaChannel();
[608]1421#ifdef GEANT4_QT_DEBUG
[588]1422 printf("has else %d alpha %d\n",depth,alpha);
[608]1423#endif
[588]1424 for(int y=height-1; y >=0 ; y--) {
1425 QRgb * s = (QRgb*)(aImage.scanLine(y));
1426 for(int x=0; x <width; x++) {
1427 QRgb rgb = (*s++);
1428 if (alpha && qAlpha(rgb) < 0x40) // 25% alpha, convert to white -
1429 rgb = qRgb(0xff, 0xff, 0xff);
1430 if (aInColor == 1) {
1431 fprintf (fp, " %02hx ",(unsigned char)qGray(rgb));
1432 i++;
1433 } else {
1434 fprintf (fp, " %02hx %02hx %02hx",
1435 (unsigned char) qRed(rgb),
1436 (unsigned char) qGreen(rgb),
1437 (unsigned char) qBlue(rgb));
1438 i += 3;
1439 }
[587]1440 }
1441 fprintf (fp, "\n");
[588]1442 }
[601]1443#endif
1444
[586]1445 }
[588]1446
[586]1447 fprintf (fp, "grestore\n");
1448 fprintf (fp, "showpage\n");
1449 fclose (fp);
[588]1450
1451 return true;
[586]1452}
[588]1453/**
1454 Generate Postscript or PDF form image
1455 @param aFilename : name of file
1456 @param aInColor : numbers of colors : 1->BW 2->RGB
1457 @param aImage : Image to print
1458*/
1459bool G4OpenGLQtViewer::generatePS_PDF (
1460 QString aFilename
1461,int aInColor
1462,QImage aImage
1463)
1464{
[638]1465
[600]1466#if QT_VERSION < 0x040000
1467#ifdef Q_WS_MAC || Q_WS_X11
[588]1468 QPrinter printer;
1469 // printer.setPageSize(pageSize);
1470 if (aInColor == 1) {
1471 printer.setColorMode(QPrinter::GrayScale);
1472 } else {
1473 printer.setColorMode(QPrinter::Color);
1474 }
1475
[600]1476 /* FIXME : I don't know which format it will save...
1477 if (aFilename.endsWith(".ps")) {
1478 printer.setOutputFormat(QPrinter::PostScriptFormat);
1479 } else {
1480 printer.setOutputFormat(QPrinter::PdfFormat);
1481 }
1482 */
1483 printer.setOutputFileName(aFilename);
1484 // printer.setFullPage ( true);
1485 QPainter paint(&printer);
1486 paint.drawImage (0,0,aImage );
1487 paint.end();
1488#else
[638]1489 G4cerr << "This fonction is only supported on Mac OsX or X11 with Qt3. Full platform supported with Qt4\n" << G4endl;
[600]1490#endif
1491#else
1492 QPrinter printer;
1493 // printer.setPageSize(pageSize);
[637]1494
1495 // FIXME : L. Garnier 4/12/07
1496 // This is not working, it does nothing. Image is staying in color mode
1497 // So I have desactivate the B/W button in GUI
1498 if ((!aImage.isGrayscale ()) &&(aInColor ==1 )) {
1499#if QT_VERSION < 0x040000
1500 aImage = aImage.convertDepth(1,Qt::MonoOnly);
1501#else
1502 aImage = aImage.convertToFormat ( aImage.format(), Qt::MonoOnly);
1503#endif
[600]1504 }
1505
[637]1506
[588]1507 if (aFilename.endsWith(".ps")) {
[606]1508#if QT_VERSION > 0x040200
[588]1509 printer.setOutputFormat(QPrinter::PostScriptFormat);
[606]1510#endif
[588]1511 } else {
[606]1512#if QT_VERSION > 0x040100
[588]1513 printer.setOutputFormat(QPrinter::PdfFormat);
[606]1514#endif
[588]1515 }
[606]1516#if QT_VERSION > 0x040100
[588]1517 printer.setOutputFileName(aFilename);
[606]1518#endif
[588]1519 // printer.setFullPage ( true);
1520 QPainter paint(&printer);
[637]1521 paint.drawImage (0,0,aImage);
[588]1522 paint.end();
[600]1523#endif
[588]1524 return true;
1525}
1526
[530]1527#endif
[588]1528
1529/*
1530
1531void MultiLayer::exportToSVG(const QString& fname)
1532{
1533 QPicture picture;
1534 QPainter p(&picture);
1535 for (int i=0;i<(int)graphsList->count();i++)
1536 {
1537 Graph *gr=(Graph *)graphsList->at(i);
1538 Plot *myPlot= (Plot *)gr->plotWidget();
1539
1540 QPoint pos=gr->pos();
1541
1542 int width=int(myPlot->frameGeometry().width());
1543 int height=int(myPlot->frameGeometry().height());
1544
1545 myPlot->print(&p, QRect(pos,QSize(width,height)));
1546 }
1547
1548 p.end();
1549 picture.save(fname, "svg");
1550}
1551*/
Note: See TracBrowser for help on using the repository browser.