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

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

marche des que l on a lance un run : dessine un rubber band. Pb de alpha channel soupsonne

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