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