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

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

modifs de test pour rubberband et mise en place du button mouse zoom

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