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

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

commit sur geant4

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