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