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

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

r670@mac-90108: laurentgarnier | 2007-11-26 18:13:28 +0100
mise a jour pour Qt3 linux

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