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

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

begin to code a rescale function

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