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

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

corrections de bugs

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