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

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

corrections de bugs

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