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.10 2008/01/30 10:54:13 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 | #include "G4UnitsTable.hh" |
---|
51 | #include "G4Qt.hh" |
---|
52 | #include "G4UImanager.hh" |
---|
53 | #include "G4UIcommandTree.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 <qapplication.h> |
---|
69 | #include <qmessagebox.h> |
---|
70 | #include <qfiledialog.h> |
---|
71 | #include <qprinter.h> |
---|
72 | #include <qpainter.h> |
---|
73 | #include <qgl.h> // include <qglwidget.h> |
---|
74 | #include <qdialog.h> |
---|
75 | #include <qevent.h> //include <qcontextmenuevent.h> |
---|
76 | |
---|
77 | |
---|
78 | ////////////////////////////////////////////////////////////////////////////// |
---|
79 | /** |
---|
80 | Implementation of virtual method of G4VViewer |
---|
81 | */ |
---|
82 | void G4OpenGLQtViewer::SetView ( |
---|
83 | ) |
---|
84 | ////////////////////////////////////////////////////////////////////////////// |
---|
85 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
86 | { |
---|
87 | #ifdef GEANT4_QT_DEBUG |
---|
88 | printf("G4OpenGLQtViewer::SetView ++++++++++++++++++++\n"); |
---|
89 | #endif |
---|
90 | // if(!fHDC) return; |
---|
91 | // if(!fHGLRC) return; |
---|
92 | // ::wglMakeCurrent(fHDC,fHGLRC); |
---|
93 | // fWindow->makeCurrent(); |
---|
94 | G4OpenGLViewer::SetView (); |
---|
95 | #ifdef GEANT4_QT_DEBUG |
---|
96 | printf("G4OpenGLQtViewer::SetView --------------------\n"); |
---|
97 | #endif |
---|
98 | } |
---|
99 | |
---|
100 | /** |
---|
101 | * Set the viewport of the scene |
---|
102 | */ |
---|
103 | void G4OpenGLQtViewer::setupViewport(int aWidth, int aHeight) |
---|
104 | { |
---|
105 | int side = aWidth; |
---|
106 | if (aHeight < aWidth) side = aHeight; |
---|
107 | glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side); |
---|
108 | |
---|
109 | glMatrixMode(GL_PROJECTION); |
---|
110 | glLoadIdentity(); |
---|
111 | glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0); |
---|
112 | glMatrixMode(GL_MODELVIEW); |
---|
113 | } |
---|
114 | |
---|
115 | |
---|
116 | ////////////////////////////////////////////////////////////////////////////// |
---|
117 | /** |
---|
118 | Implementation of virtual method of G4VViewer |
---|
119 | */ |
---|
120 | void G4OpenGLQtViewer::ShowView ( |
---|
121 | ) |
---|
122 | ////////////////////////////////////////////////////////////////////////////// |
---|
123 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
124 | { |
---|
125 | #ifdef GEANT4_QT_DEBUG |
---|
126 | printf("G4OpenGLQtViewer::ShowView +++++++++++++++++++++\n"); |
---|
127 | #endif |
---|
128 | if (!GLWindow) { |
---|
129 | G4cerr << "Visualization window not defined, please choose one before\n" << G4endl; |
---|
130 | } else { |
---|
131 | #if QT_VERSION < 0x040000 |
---|
132 | GLWindow->setActiveWindow(); |
---|
133 | #else |
---|
134 | GLWindow->activateWindow(); |
---|
135 | #endif |
---|
136 | #ifdef GEANT4_QT_DEBUG |
---|
137 | printf("G4OpenGLQtViewer::ShowView -----------------------\n"); |
---|
138 | #endif |
---|
139 | } |
---|
140 | glFlush (); |
---|
141 | // // Empty the Windows message queue : |
---|
142 | // MSG event; |
---|
143 | // while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) { |
---|
144 | // ::TranslateMessage(&event); |
---|
145 | // ::DispatchMessage (&event); |
---|
146 | // } |
---|
147 | } |
---|
148 | |
---|
149 | |
---|
150 | |
---|
151 | ////////////////////////////////////////////////////////////////////////////// |
---|
152 | void G4OpenGLQtViewer::CreateGLQtContext ( |
---|
153 | ) |
---|
154 | ////////////////////////////////////////////////////////////////////////////// |
---|
155 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
156 | { |
---|
157 | #ifdef GEANT4_QT_DEBUG |
---|
158 | printf("G4OpenGLQtViewer::CreateGLQtContext \n"); |
---|
159 | #endif |
---|
160 | } |
---|
161 | |
---|
162 | |
---|
163 | ////////////////////////////////////////////////////////////////////////////// |
---|
164 | void G4OpenGLQtViewer::CreateMainWindow ( |
---|
165 | QGLWidget* glWidget |
---|
166 | ) |
---|
167 | ////////////////////////////////////////////////////////////////////////////// |
---|
168 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
169 | { |
---|
170 | |
---|
171 | if(fWindow) return; //Done. |
---|
172 | #ifdef GEANT4_QT_DEBUG |
---|
173 | printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n"); |
---|
174 | #endif |
---|
175 | |
---|
176 | // launch Qt if not |
---|
177 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
178 | // G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
179 | |
---|
180 | fWindow = glWidget ; |
---|
181 | // fWindow->makeCurrent(); |
---|
182 | |
---|
183 | // create window |
---|
184 | if (((QApplication*)interactorManager->GetMainInteractor())) { |
---|
185 | // look for the main window |
---|
186 | bool found = false; |
---|
187 | #if QT_VERSION < 0x040000 |
---|
188 | // theses lines does nothing exept this one "GLWindow = new QDialog(0..." |
---|
189 | // but if I comment them, it doesn't work... |
---|
190 | QWidgetList *list = QApplication::allWidgets(); |
---|
191 | QWidgetListIt it( *list ); // iterate over the widgets |
---|
192 | QWidget * widget; |
---|
193 | while ( (widget=it.current()) != 0 ) { // for each widget... |
---|
194 | ++it; |
---|
195 | if ((found== false) && (widget->inherits("QMainWindow"))) { |
---|
196 | GLWindow = new QDialog(0,0,FALSE,Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_MinMax ); |
---|
197 | found = true; |
---|
198 | } |
---|
199 | } |
---|
200 | delete list; // delete the list, not the widgets |
---|
201 | #else |
---|
202 | foreach (QWidget *widget, QApplication::allWidgets()) { |
---|
203 | if ((found== false) && (widget->inherits("QMainWindow"))) { |
---|
204 | GLWindow = new QDialog(0,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint); |
---|
205 | found = true; |
---|
206 | } |
---|
207 | } |
---|
208 | #endif |
---|
209 | |
---|
210 | #if QT_VERSION < 0x040000 |
---|
211 | glWidget->reparent(GLWindow,0,QPoint(0,0)); |
---|
212 | #else |
---|
213 | glWidget->setParent(GLWindow); |
---|
214 | #endif |
---|
215 | |
---|
216 | if (found==false) { |
---|
217 | #ifdef GEANT4_QT_DEBUG |
---|
218 | printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n"); |
---|
219 | #endif |
---|
220 | GLWindow = new QDialog(); |
---|
221 | } |
---|
222 | } else { |
---|
223 | #ifdef GEANT4_QT_DEBUG |
---|
224 | printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n"); |
---|
225 | #endif |
---|
226 | GLWindow = new QDialog(); |
---|
227 | } |
---|
228 | |
---|
229 | QHBoxLayout *mainLayout = new QHBoxLayout(GLWindow); |
---|
230 | |
---|
231 | mainLayout->addWidget(fWindow); |
---|
232 | |
---|
233 | #if QT_VERSION < 0x040000 |
---|
234 | GLWindow->setCaption( tr( "QGl Viewer" )); |
---|
235 | #else |
---|
236 | GLWindow->setLayout(mainLayout); |
---|
237 | GLWindow->setWindowTitle(tr("QGl Viewer")); |
---|
238 | #endif |
---|
239 | GLWindow->resize(300, 300); |
---|
240 | GLWindow->move(900,300); |
---|
241 | GLWindow->show(); |
---|
242 | |
---|
243 | // delete the pointer if close this |
---|
244 | // GLWindow->setAttribute(Qt::WA_DeleteOnClose); |
---|
245 | |
---|
246 | #if QT_VERSION >= 0x040000 |
---|
247 | // QObject ::connect(GLWindow, |
---|
248 | // SIGNAL(rejected()), |
---|
249 | // this, |
---|
250 | // SLOT(dialogClosed())); |
---|
251 | #endif |
---|
252 | |
---|
253 | WinSize_x = 400; |
---|
254 | WinSize_y = 400; |
---|
255 | if (WinSize_x < fVP.GetWindowSizeHintX ()) |
---|
256 | WinSize_x = fVP.GetWindowSizeHintX (); |
---|
257 | if (WinSize_y < fVP.GetWindowSizeHintY ()) |
---|
258 | WinSize_y = fVP.GetWindowSizeHintY (); |
---|
259 | |
---|
260 | if(!fWindow) return; |
---|
261 | #ifdef GEANT4_QT_DEBUG |
---|
262 | printf("G4OpenGLQtViewer::CreateMainWindow glWidget END\n"); |
---|
263 | #endif |
---|
264 | |
---|
265 | if (!fContextMenu) |
---|
266 | createPopupMenu(); |
---|
267 | |
---|
268 | } |
---|
269 | |
---|
270 | #if QT_VERSION >= 0x040000 |
---|
271 | /** Close the dialog and set the pointer to NULL |
---|
272 | */ |
---|
273 | // void G4OpenGLQtViewer::dialogClosed() { |
---|
274 | // #ifdef GEANT4_QT_DEBUG |
---|
275 | // printf("G4OpenGLQtViewer::dialogClosed END\n"); |
---|
276 | // #endif |
---|
277 | // // GLWindow = NULL; |
---|
278 | // } |
---|
279 | #endif |
---|
280 | |
---|
281 | ////////////////////////////////////////////////////////////////////////////// |
---|
282 | G4OpenGLQtViewer::G4OpenGLQtViewer ( |
---|
283 | G4OpenGLSceneHandler& scene |
---|
284 | ) |
---|
285 | :G4VViewer (scene, -1) |
---|
286 | ,G4OpenGLViewer (scene) |
---|
287 | ,fWindow(0) |
---|
288 | ,fContextMenu(0) |
---|
289 | ,fMouseAction(STYLE1) |
---|
290 | ,fDeltaRotation(1) |
---|
291 | ,fDeltaSceneTranslation(0.01) |
---|
292 | ,fDeltaDepth(0.01) |
---|
293 | ,fDeltaZoom(0.1) |
---|
294 | ,holdKeyEvent(false) |
---|
295 | ,fAutoMove(false) |
---|
296 | { |
---|
297 | #ifdef GEANT4_QT_DEBUG |
---|
298 | printf("G4OpenGLQtViewer::G4OpenGLQtViewer \n"); |
---|
299 | #endif |
---|
300 | } |
---|
301 | |
---|
302 | ////////////////////////////////////////////////////////////////////////////// |
---|
303 | G4OpenGLQtViewer::~G4OpenGLQtViewer ( |
---|
304 | ) |
---|
305 | ////////////////////////////////////////////////////////////////////////////// |
---|
306 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
307 | { |
---|
308 | #ifdef GEANT4_QT_DEBUG |
---|
309 | printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n"); |
---|
310 | #endif |
---|
311 | } |
---|
312 | |
---|
313 | |
---|
314 | /** |
---|
315 | Create a popup menu for the widget. This menu is activated by right-mouse click |
---|
316 | */ |
---|
317 | void G4OpenGLQtViewer::createPopupMenu() { |
---|
318 | |
---|
319 | #if QT_VERSION < 0x040000 |
---|
320 | fContextMenu = new QPopupMenu( GLWindow,"All" ); |
---|
321 | #else |
---|
322 | fContextMenu = new QMenu("All"); |
---|
323 | #endif |
---|
324 | |
---|
325 | #if QT_VERSION < 0x040000 |
---|
326 | QPopupMenu *mMouseAction = new QPopupMenu( fContextMenu ); |
---|
327 | fContextMenu->insertItem("&Mouse actions",mMouseAction); |
---|
328 | #if QT_VERSION < 0x030200 |
---|
329 | fRotateAction = new QAction("&Rotate","&Rotate",CTRL+Key_R,mMouseAction,0,true); |
---|
330 | fMoveAction = new QAction("&Move","&Move",CTRL+Key_M,mMouseAction,0,true); |
---|
331 | fPickAction = new QAction("&Pick","&Pick",CTRL+Key_P,mMouseAction,0,true); |
---|
332 | fShortcutsAction = new QAction("&Show shortcuts","&Show shortcuts",CTRL+Key_S,mMouseAction,0,true); |
---|
333 | #else |
---|
334 | fRotateAction = new QAction("&Rotate",CTRL+Key_R,mMouseAction); |
---|
335 | fMoveAction = new QAction("&Move",CTRL+Key_M,mMouseAction); |
---|
336 | fPickAction = new QAction("&Pick",CTRL+Key_P,mMouseAction); |
---|
337 | fShortcutsAction = new QAction("&Show shortcuts",CTRL+Key_S,mMouseAction); |
---|
338 | #endif |
---|
339 | fRotateAction->addTo(mMouseAction); |
---|
340 | fMoveAction->addTo(mMouseAction); |
---|
341 | fPickAction->addTo(mMouseAction); |
---|
342 | fShortcutsAction->addTo(mMouseAction); |
---|
343 | |
---|
344 | fRotateAction->setToggleAction(true); |
---|
345 | fMoveAction->setToggleAction(true); |
---|
346 | fPickAction->setToggleAction(true); |
---|
347 | fShortcutsAction->setToggleAction(true); |
---|
348 | |
---|
349 | fRotateAction->setOn(true); |
---|
350 | fMoveAction->setOn(false); |
---|
351 | fPickAction->setOn(false); |
---|
352 | fShortcutsAction->setOn(false); |
---|
353 | |
---|
354 | |
---|
355 | QObject ::connect(fRotateAction, |
---|
356 | SIGNAL(activated()), |
---|
357 | this, |
---|
358 | SLOT(actionMouseRotate())); |
---|
359 | |
---|
360 | QObject ::connect(fMoveAction, |
---|
361 | SIGNAL(activated()), |
---|
362 | this, |
---|
363 | SLOT(actionMouseMove())); |
---|
364 | |
---|
365 | QObject ::connect(fPickAction, |
---|
366 | SIGNAL(activated()), |
---|
367 | this, |
---|
368 | SLOT(actionMousePick())); |
---|
369 | |
---|
370 | QObject ::connect(fShortcutsAction, |
---|
371 | SIGNAL(activated()), |
---|
372 | this, |
---|
373 | SLOT(actionMouseShortcuts())); |
---|
374 | |
---|
375 | #else |
---|
376 | QMenu *mMouseAction = fContextMenu->addMenu("&Mouse actions"); |
---|
377 | |
---|
378 | fRotateAction = mMouseAction->addAction("Rotate"); |
---|
379 | fMoveAction = mMouseAction->addAction("Move"); |
---|
380 | fPickAction = mMouseAction->addAction("Pick"); |
---|
381 | fShortcutsAction = mMouseAction->addAction("Show shortcuts"); |
---|
382 | |
---|
383 | fRotateAction->setCheckable(true); |
---|
384 | fMoveAction->setCheckable(false); |
---|
385 | fPickAction->setCheckable(false); |
---|
386 | fShortcutsAction->setCheckable(false); |
---|
387 | |
---|
388 | fRotateAction->setChecked(true); |
---|
389 | fMoveAction->setChecked(false); |
---|
390 | fPickAction->setChecked(false); |
---|
391 | fShortcutsAction->setChecked(false); |
---|
392 | |
---|
393 | QObject ::connect(fRotateAction, |
---|
394 | SIGNAL(triggered(bool)), |
---|
395 | this, |
---|
396 | SLOT(actionMouseRotate())); |
---|
397 | |
---|
398 | QObject ::connect(fMoveAction, |
---|
399 | SIGNAL(triggered(bool)), |
---|
400 | this, |
---|
401 | SLOT(actionMouseMove())); |
---|
402 | |
---|
403 | QObject ::connect(fPickAction, |
---|
404 | SIGNAL(triggered(bool)), |
---|
405 | this, |
---|
406 | SLOT(actionMousePick())); |
---|
407 | |
---|
408 | QObject ::connect(fShortcutsAction, |
---|
409 | SIGNAL(triggered(bool)), |
---|
410 | this, |
---|
411 | SLOT(actionMouseShortcuts())); |
---|
412 | #endif |
---|
413 | |
---|
414 | #if QT_VERSION < 0x040000 |
---|
415 | // === Style Menu === |
---|
416 | QPopupMenu *mStyle = new QPopupMenu(fContextMenu); |
---|
417 | |
---|
418 | QPopupMenu *mRepresentation = new QPopupMenu(fContextMenu); |
---|
419 | |
---|
420 | QPopupMenu *mProjection = new QPopupMenu(fContextMenu); |
---|
421 | |
---|
422 | #if QT_VERSION < 0x030200 |
---|
423 | QAction *polyhedron = new QAction("&Polyhedron","&Polyhedron",CTRL+Key_P,mRepresentation,0,true); |
---|
424 | QAction *nurbs = new QAction("&NURBS","&NURBS",CTRL+Key_N,mRepresentation,0,true); |
---|
425 | |
---|
426 | QAction *ortho = new QAction("&Orthographic","&Orthographic",CTRL+Key_O,mProjection,0,true); |
---|
427 | QAction *perspective = new QAction("&Perspective","&Perspective",CTRL+Key_P,mProjection,0,true); |
---|
428 | #else |
---|
429 | QAction *polyhedron = new QAction("&Polyhedron",CTRL+Key_P,mRepresentation); |
---|
430 | QAction *nurbs = new QAction("&NURBS",CTRL+Key_N,mRepresentation); |
---|
431 | |
---|
432 | QAction *ortho = new QAction("&Orthographic",CTRL+Key_O,mProjection); |
---|
433 | QAction *perspective = new QAction("&Perspective",CTRL+Key_P,mProjection); |
---|
434 | polyhedron->setToggleAction(true); |
---|
435 | nurbs->setToggleAction(true); |
---|
436 | ortho->setToggleAction(true); |
---|
437 | perspective->setToggleAction(true); |
---|
438 | #endif |
---|
439 | polyhedron->addTo(mRepresentation); |
---|
440 | nurbs->addTo(mRepresentation); |
---|
441 | |
---|
442 | ortho->addTo(mProjection); |
---|
443 | perspective->addTo(mProjection); |
---|
444 | |
---|
445 | mStyle->insertItem("&Representation",mRepresentation); |
---|
446 | mStyle->insertItem("&Projection",mProjection); |
---|
447 | fContextMenu->insertItem("&Style",mStyle); |
---|
448 | |
---|
449 | |
---|
450 | #else |
---|
451 | // === Style Menu === |
---|
452 | QMenu *mStyle = fContextMenu->addMenu("&Style"); |
---|
453 | |
---|
454 | QMenu *mRepresentation = mStyle->addMenu("&Representation"); |
---|
455 | QMenu *mProjection = mStyle->addMenu("&Projection"); |
---|
456 | QAction *polyhedron = mRepresentation->addAction("Polyhedron"); |
---|
457 | QAction *nurbs = mRepresentation->addAction("NURBS"); |
---|
458 | |
---|
459 | QAction *ortho = mProjection->addAction("Orthographic"); |
---|
460 | QAction *perspective = mProjection->addAction("Persepective"); |
---|
461 | #endif |
---|
462 | |
---|
463 | // INIT mRepresentation |
---|
464 | G4ViewParameters::RepStyle style; |
---|
465 | style = fVP.GetRepStyle(); |
---|
466 | if (style == G4ViewParameters::polyhedron) { |
---|
467 | createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),1); |
---|
468 | } else if (style == G4ViewParameters::nurbs) { |
---|
469 | createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),2); |
---|
470 | } else { |
---|
471 | mRepresentation->clear(); |
---|
472 | } |
---|
473 | |
---|
474 | // INIT mProjection |
---|
475 | if (fVP.GetFieldHalfAngle() == 0) { |
---|
476 | createRadioAction(ortho, perspective,SLOT(toggleProjection(bool)),1); |
---|
477 | } else { |
---|
478 | createRadioAction(ortho, perspective,SLOT(toggleProjection(bool)),2); |
---|
479 | } |
---|
480 | |
---|
481 | #if QT_VERSION < 0x040000 |
---|
482 | // === Drawing Menu === |
---|
483 | QPopupMenu *mDrawing = new QPopupMenu(fContextMenu); |
---|
484 | fContextMenu->insertItem("&Drawing",mDrawing); |
---|
485 | |
---|
486 | #if QT_VERSION < 0x030200 |
---|
487 | fDrawingWireframe = new QAction("&Wireframe","&Wireframe",CTRL+Key_W,mDrawing,0,true); |
---|
488 | fDrawingLineRemoval = new QAction("&Hidden line removal","&Hidden line removal",CTRL+Key_L,mDrawing,0,true); |
---|
489 | fDrawingSurfaceRemoval = new QAction("&Hidden surface removal","&Hidden surface removal",CTRL+Key_S,mDrawing,0,true); |
---|
490 | fDrawingLineSurfaceRemoval = new QAction("&Hidden line and surface removal","&Hidden line and surface removal",CTRL+Key_R,mDrawing,0,true); |
---|
491 | #else |
---|
492 | fDrawingWireframe = new QAction("&Wireframe",CTRL+Key_W,mDrawing); |
---|
493 | fDrawingLineRemoval = new QAction("&Hidden line removal",CTRL+Key_L,mDrawing); |
---|
494 | fDrawingSurfaceRemoval = new QAction("&Hidden surface removal",CTRL+Key_S,mDrawing); |
---|
495 | fDrawingLineSurfaceRemoval = new QAction("&Hidden line and surface removal",CTRL+Key_R,mDrawing); |
---|
496 | #endif |
---|
497 | fDrawingWireframe->setToggleAction(true); |
---|
498 | fDrawingLineRemoval->setToggleAction(true); |
---|
499 | fDrawingSurfaceRemoval->setToggleAction(true); |
---|
500 | fDrawingLineSurfaceRemoval->setToggleAction(true); |
---|
501 | |
---|
502 | fDrawingWireframe->addTo(mDrawing); |
---|
503 | fDrawingLineRemoval->addTo(mDrawing); |
---|
504 | fDrawingSurfaceRemoval->addTo(mDrawing); |
---|
505 | fDrawingLineSurfaceRemoval->addTo(mDrawing); |
---|
506 | |
---|
507 | |
---|
508 | #else |
---|
509 | // === Drawing Menu === |
---|
510 | QMenu *mDrawing = mStyle->addMenu("&Drawing"); |
---|
511 | |
---|
512 | fDrawingWireframe = mDrawing->addAction("Wireframe"); |
---|
513 | fDrawingWireframe->setCheckable(true); |
---|
514 | |
---|
515 | fDrawingLineRemoval = mDrawing->addAction("Hidden line removal"); |
---|
516 | fDrawingLineRemoval->setCheckable(true); |
---|
517 | |
---|
518 | fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal"); |
---|
519 | fDrawingSurfaceRemoval->setCheckable(true); |
---|
520 | |
---|
521 | fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal"); |
---|
522 | fDrawingLineSurfaceRemoval->setCheckable(true); |
---|
523 | #endif |
---|
524 | // INIT Drawing |
---|
525 | G4ViewParameters::DrawingStyle d_style; |
---|
526 | d_style = fVP.GetDrawingStyle(); |
---|
527 | |
---|
528 | #if QT_VERSION < 0x040000 |
---|
529 | if (d_style == G4ViewParameters::wireframe) { |
---|
530 | fDrawingWireframe->setOn(true); |
---|
531 | } else if (d_style == G4ViewParameters::hlr) { |
---|
532 | fDrawingLineRemoval->setOn(true); |
---|
533 | } else if (d_style == G4ViewParameters::hsr) { |
---|
534 | fDrawingSurfaceRemoval->setOn(true); |
---|
535 | } else if (d_style == G4ViewParameters::hlhsr) { |
---|
536 | fDrawingLineSurfaceRemoval->setOn(true); |
---|
537 | } else { |
---|
538 | mDrawing->clear(); |
---|
539 | } |
---|
540 | #ifdef GEANT4_QT_DEBUG |
---|
541 | printf("G4OpenGLQtViewer:: fDrawingWireframe 1\n"); |
---|
542 | #endif |
---|
543 | QObject ::connect(fDrawingWireframe, |
---|
544 | SIGNAL(activated()), |
---|
545 | this, |
---|
546 | SLOT(actionDrawingWireframe())); |
---|
547 | #ifdef GEANT4_QT_DEBUG |
---|
548 | printf("G4OpenGLQtViewer:: fDrawingWireframe 2\n"); |
---|
549 | #endif |
---|
550 | QObject ::connect(fDrawingLineRemoval, |
---|
551 | SIGNAL(activated()), |
---|
552 | this, |
---|
553 | SLOT(actionDrawingLineRemoval())); |
---|
554 | QObject ::connect(fDrawingSurfaceRemoval, |
---|
555 | SIGNAL(activated()), |
---|
556 | this, |
---|
557 | SLOT(actionDrawingSurfaceRemoval())); |
---|
558 | QObject ::connect(fDrawingLineSurfaceRemoval, |
---|
559 | SIGNAL(activated()), |
---|
560 | this, |
---|
561 | SLOT(actionDrawingLineSurfaceRemoval())); |
---|
562 | #else |
---|
563 | if (d_style == G4ViewParameters::wireframe) { |
---|
564 | fDrawingWireframe->setChecked(true); |
---|
565 | } else if (d_style == G4ViewParameters::hlr) { |
---|
566 | fDrawingLineRemoval->setChecked(true); |
---|
567 | } else if (d_style == G4ViewParameters::hsr) { |
---|
568 | fDrawingSurfaceRemoval->setChecked(true); |
---|
569 | } else if (d_style == G4ViewParameters::hlhsr) { |
---|
570 | fDrawingLineSurfaceRemoval->setChecked(true); |
---|
571 | } else { |
---|
572 | mDrawing->clear(); |
---|
573 | } |
---|
574 | QObject ::connect(fDrawingWireframe, |
---|
575 | SIGNAL(triggered(bool)), |
---|
576 | this, |
---|
577 | SLOT(actionDrawingWireframe())); |
---|
578 | QObject ::connect(fDrawingLineRemoval, |
---|
579 | SIGNAL(triggered(bool)), |
---|
580 | this, |
---|
581 | SLOT(actionDrawingLineRemoval())); |
---|
582 | QObject ::connect(fDrawingSurfaceRemoval, |
---|
583 | SIGNAL(triggered(bool)), |
---|
584 | this, |
---|
585 | SLOT(actionDrawingSurfaceRemoval())); |
---|
586 | QObject ::connect(fDrawingLineSurfaceRemoval, |
---|
587 | SIGNAL(triggered(bool)), |
---|
588 | this, |
---|
589 | SLOT(actionDrawingLineSurfaceRemoval())); |
---|
590 | #endif |
---|
591 | |
---|
592 | |
---|
593 | |
---|
594 | #if QT_VERSION < 0x040000 |
---|
595 | QPopupMenu *mBackground = new QPopupMenu(mStyle); |
---|
596 | mStyle->insertItem("&Background color",mBackground); |
---|
597 | |
---|
598 | #if QT_VERSION < 0x030200 |
---|
599 | QAction *white = new QAction("&White","&White",CTRL+Key_W,mBackground,0,true); |
---|
600 | QAction *black = new QAction("&Black","&Black",CTRL+Key_B,mBackground,0,true); |
---|
601 | #else |
---|
602 | QAction *white = new QAction("&White",CTRL+Key_W,mBackground); |
---|
603 | QAction *black = new QAction("&Black",CTRL+Key_B,mBackground); |
---|
604 | white->setToggleAction(true); |
---|
605 | black->setToggleAction(true); |
---|
606 | #endif |
---|
607 | white->addTo(mBackground); |
---|
608 | black->addTo(mBackground); |
---|
609 | |
---|
610 | #else |
---|
611 | QMenu *mBackground = mStyle->addMenu("&Background color"); |
---|
612 | QAction *white = mBackground->addAction("White"); |
---|
613 | QAction *black = mBackground->addAction("Black"); |
---|
614 | |
---|
615 | #endif |
---|
616 | if (background.GetRed() == 1. && |
---|
617 | background.GetGreen() == 1. && |
---|
618 | background.GetBlue() == 1.) { |
---|
619 | createRadioAction(white,black,SLOT(toggleBackground(bool)),1); |
---|
620 | } else { |
---|
621 | createRadioAction(white,black,SLOT(toggleBackground(bool)),2); |
---|
622 | } |
---|
623 | |
---|
624 | |
---|
625 | #if QT_VERSION < 0x040000 |
---|
626 | // === Action Menu === |
---|
627 | QPopupMenu *mActions = new QPopupMenu(fContextMenu); |
---|
628 | fContextMenu->insertItem("&Actions",mActions); |
---|
629 | |
---|
630 | #if QT_VERSION < 0x030200 |
---|
631 | QAction *createEPS = new QAction("&Save as ...","&Save as ...",CTRL+Key_S,mActions,0,true); |
---|
632 | #else |
---|
633 | QAction *createEPS = new QAction("&Save as ...",CTRL+Key_S,mActions); |
---|
634 | #endif |
---|
635 | createEPS->addTo(mActions); |
---|
636 | QObject ::connect(createEPS, |
---|
637 | SIGNAL(activated()), |
---|
638 | this, |
---|
639 | SLOT(actionCreateEPS())); |
---|
640 | |
---|
641 | #else |
---|
642 | // === Action Menu === |
---|
643 | QMenu *mActions = fContextMenu->addMenu("&Actions"); |
---|
644 | QAction *createEPS = mActions->addAction("Save as ..."); |
---|
645 | QObject ::connect(createEPS, |
---|
646 | SIGNAL(triggered()), |
---|
647 | this, |
---|
648 | SLOT(actionCreateEPS())); |
---|
649 | #endif |
---|
650 | |
---|
651 | |
---|
652 | |
---|
653 | #if QT_VERSION < 0x040000 |
---|
654 | // === Special Menu === |
---|
655 | QPopupMenu *mSpecial = new QPopupMenu(fContextMenu); |
---|
656 | fContextMenu->insertItem("S&pecial",mSpecial); |
---|
657 | |
---|
658 | QPopupMenu *mTransparency = new QPopupMenu(mSpecial); |
---|
659 | mSpecial->insertItem("Transparency",mTransparency); |
---|
660 | |
---|
661 | #if QT_VERSION < 0x030200 |
---|
662 | QAction *transparencyOn = new QAction("&On","&On",CTRL+Key_O,mTransparency,0,true); |
---|
663 | QAction *transparencyOff = new QAction("&Off","&Off",CTRL+Key_F,mTransparency,0,true); |
---|
664 | #else |
---|
665 | QAction *transparencyOn = new QAction("&On",CTRL+Key_O,mTransparency); |
---|
666 | QAction *transparencyOff = new QAction("&Off",CTRL+Key_F,mTransparency); |
---|
667 | transparencyOn->setToggleAction(true); |
---|
668 | transparencyOff->setToggleAction(true); |
---|
669 | #endif |
---|
670 | transparencyOn->addTo(mTransparency); |
---|
671 | transparencyOff->addTo(mTransparency); |
---|
672 | |
---|
673 | #else |
---|
674 | // === Special Menu === |
---|
675 | QMenu *mSpecial = fContextMenu->addMenu("S&pecial"); |
---|
676 | QMenu *mTransparency = mSpecial->addMenu("Transparency"); |
---|
677 | QAction *transparencyOn = mTransparency->addAction("On"); |
---|
678 | QAction *transparencyOff = mTransparency->addAction("Off"); |
---|
679 | #endif |
---|
680 | |
---|
681 | if (transparency_enabled == false) { |
---|
682 | createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2); |
---|
683 | } else if (transparency_enabled == true) { |
---|
684 | createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),1); |
---|
685 | } else { |
---|
686 | mSpecial->clear(); |
---|
687 | } |
---|
688 | |
---|
689 | |
---|
690 | #if QT_VERSION < 0x040000 |
---|
691 | QPopupMenu *mAntialiasing = new QPopupMenu(mSpecial); |
---|
692 | mSpecial->insertItem("Antialiasing",mAntialiasing); |
---|
693 | |
---|
694 | #if QT_VERSION < 0x030200 |
---|
695 | QAction *antialiasingOn = new QAction("&On","&On",CTRL+Key_O,mAntialiasing,0,true); |
---|
696 | QAction *antialiasingOff = new QAction("&Off","&Off",CTRL+Key_F,mAntialiasing,0,true); |
---|
697 | #else |
---|
698 | QAction *antialiasingOn = new QAction("&On",CTRL+Key_O,mAntialiasing); |
---|
699 | QAction *antialiasingOff = new QAction("&Off",CTRL+Key_F,mAntialiasing); |
---|
700 | antialiasingOn->setToggleAction(true); |
---|
701 | antialiasingOff->setToggleAction(true); |
---|
702 | #endif |
---|
703 | antialiasingOn->addTo(mAntialiasing); |
---|
704 | antialiasingOff->addTo(mAntialiasing); |
---|
705 | |
---|
706 | #else |
---|
707 | QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing"); |
---|
708 | QAction *antialiasingOn = mAntialiasing->addAction("On"); |
---|
709 | QAction *antialiasingOff = mAntialiasing->addAction("Off"); |
---|
710 | #endif |
---|
711 | |
---|
712 | if (antialiasing_enabled == false) { |
---|
713 | createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2); |
---|
714 | } else if (antialiasing_enabled == true) { |
---|
715 | createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),1); |
---|
716 | } else { |
---|
717 | mAntialiasing->clear(); |
---|
718 | } |
---|
719 | |
---|
720 | #if QT_VERSION < 0x040000 |
---|
721 | QPopupMenu *mHaloing = new QPopupMenu(mSpecial); |
---|
722 | mSpecial->insertItem("Haloing",mHaloing); |
---|
723 | |
---|
724 | #if QT_VERSION < 0x030200 |
---|
725 | QAction *haloingOn = new QAction("&On","&On",CTRL+Key_O,mHaloing,0,true); |
---|
726 | QAction *haloingOff = new QAction("&Off","&Off",CTRL+Key_F,mHaloing,0,true); |
---|
727 | #else |
---|
728 | QAction *haloingOn = new QAction("&On",CTRL+Key_O,mHaloing); |
---|
729 | QAction *haloingOff = new QAction("&Off",CTRL+Key_F,mHaloing); |
---|
730 | haloingOn->setToggleAction(true); |
---|
731 | haloingOff->setToggleAction(true); |
---|
732 | #endif |
---|
733 | haloingOn->addTo(mHaloing); |
---|
734 | haloingOff->addTo(mHaloing); |
---|
735 | #else |
---|
736 | QMenu *mHaloing = mSpecial->addMenu("Haloing"); |
---|
737 | QAction *haloingOn = mHaloing->addAction("On"); |
---|
738 | QAction *haloingOff = mHaloing->addAction("Off"); |
---|
739 | #endif |
---|
740 | if (haloing_enabled == false) { |
---|
741 | createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2); |
---|
742 | } else if (haloing_enabled == true) { |
---|
743 | createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),1); |
---|
744 | } else { |
---|
745 | mHaloing->clear(); |
---|
746 | } |
---|
747 | |
---|
748 | #if QT_VERSION < 0x040000 |
---|
749 | QPopupMenu *mAux = new QPopupMenu(mSpecial); |
---|
750 | mSpecial->insertItem("Auxiliairy edges",mAux); |
---|
751 | |
---|
752 | #if QT_VERSION < 0x030200 |
---|
753 | QAction *auxOn = new QAction("&On","&On",CTRL+Key_O,mAux,0,true); |
---|
754 | QAction *auxOff = new QAction("&Off","&Off",CTRL+Key_F,mAux,0,true); |
---|
755 | #else |
---|
756 | QAction *auxOn = new QAction("&On",CTRL+Key_O,mAux); |
---|
757 | QAction *auxOff = new QAction("&Off",CTRL+Key_F,mAux); |
---|
758 | auxOn->setToggleAction(true); |
---|
759 | auxOff->setToggleAction(true); |
---|
760 | #endif |
---|
761 | auxOn->addTo(mAux); |
---|
762 | auxOff->addTo(mAux); |
---|
763 | |
---|
764 | #else |
---|
765 | QMenu *mAux = mSpecial->addMenu("Auxiliary edges"); |
---|
766 | QAction *auxOn = mAux->addAction("On"); |
---|
767 | QAction *auxOff = mAux->addAction("Off"); |
---|
768 | #endif |
---|
769 | if (!fVP.IsAuxEdgeVisible()) { |
---|
770 | createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1); |
---|
771 | } else { |
---|
772 | createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),2); |
---|
773 | } |
---|
774 | |
---|
775 | |
---|
776 | |
---|
777 | #if QT_VERSION < 0x040000 |
---|
778 | QPopupMenu *mFullScreen = new QPopupMenu(mSpecial); |
---|
779 | mSpecial->insertItem("Full screen",mFullScreen); |
---|
780 | |
---|
781 | #if QT_VERSION < 0x030200 |
---|
782 | fFullScreenOn = new QAction("&On","&On",CTRL+Key_O,mFullScreen,0,true); |
---|
783 | fFullScreenOff = new QAction("&Off","&Off",CTRL+Key_F,mFullScreen,0,true); |
---|
784 | #else |
---|
785 | fFullScreenOn = new QAction("&On",CTRL+Key_O,mFullScreen); |
---|
786 | fFullScreenOff = new QAction("&Off",CTRL+Key_F,mFullScreen); |
---|
787 | fFullScreenOn->setToggleAction(true); |
---|
788 | fFullScreenOff->setToggleAction(true); |
---|
789 | #endif |
---|
790 | fFullScreenOn->addTo(mFullScreen); |
---|
791 | fFullScreenOff->addTo(mFullScreen); |
---|
792 | #else |
---|
793 | QMenu *mFullScreen = mSpecial->addMenu("&Full screen"); |
---|
794 | fFullScreenOn = mFullScreen->addAction("On"); |
---|
795 | fFullScreenOff = mFullScreen->addAction("Off"); |
---|
796 | #endif |
---|
797 | createRadioAction(fFullScreenOn,fFullScreenOff,SLOT(toggleFullScreen(bool)),2); |
---|
798 | |
---|
799 | } |
---|
800 | |
---|
801 | void G4OpenGLQtViewer::manageContextMenuEvent(QContextMenuEvent *e) |
---|
802 | { |
---|
803 | if (!GLWindow) { |
---|
804 | G4cerr << "Visualization window not defined, please choose one before\n" << G4endl; |
---|
805 | } else { |
---|
806 | |
---|
807 | if (!fContextMenu) |
---|
808 | createPopupMenu(); |
---|
809 | |
---|
810 | // launch menu |
---|
811 | if ( fContextMenu ) { |
---|
812 | fContextMenu->exec( e->globalPos() ); |
---|
813 | // delete fContextMenu; |
---|
814 | } |
---|
815 | } |
---|
816 | e->accept(); |
---|
817 | } |
---|
818 | |
---|
819 | |
---|
820 | /** |
---|
821 | Create a radio button menu. The two menu will be connected. When click on one, |
---|
822 | eatch state will be invert and callback method will be called. |
---|
823 | @param action1 first action to connect |
---|
824 | @param action2 second action to connect |
---|
825 | @param method callback method |
---|
826 | @param nCheck: 1 : first action will be set true. 2 : second action will be set true |
---|
827 | */ |
---|
828 | #if QT_VERSION < 0x040000 |
---|
829 | void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) { |
---|
830 | |
---|
831 | if (action1->parent()->inherits("QPopupMenu")){ |
---|
832 | ((QPopupMenu*)action1->parent())->setCheckable(true); |
---|
833 | ((QPopupMenu*)action2->parent())->setCheckable(true); |
---|
834 | } |
---|
835 | action1->setOn(false); |
---|
836 | action2->setOn(false); |
---|
837 | |
---|
838 | if (nCheck ==1) |
---|
839 | action1->setOn(true); |
---|
840 | else |
---|
841 | action2->setOn(true); |
---|
842 | |
---|
843 | //FIXME : Should not work on Qt3 |
---|
844 | QObject ::connect(action1, SIGNAL(activated()),action2, SLOT(toggle())); |
---|
845 | QObject ::connect(action2, SIGNAL(activated()),action1, SLOT(toggle())); |
---|
846 | |
---|
847 | QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str()); |
---|
848 | } |
---|
849 | |
---|
850 | #else |
---|
851 | void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) { |
---|
852 | |
---|
853 | action1->setCheckable(true); |
---|
854 | action2->setCheckable(true); |
---|
855 | |
---|
856 | if (nCheck ==1) |
---|
857 | action1->setChecked (true); |
---|
858 | else |
---|
859 | action2->setChecked (true); |
---|
860 | |
---|
861 | QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle())); |
---|
862 | QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle())); |
---|
863 | |
---|
864 | QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str()); |
---|
865 | |
---|
866 | } |
---|
867 | #endif |
---|
868 | |
---|
869 | /** |
---|
870 | Slot activate when mouseAction->rotate menu is set |
---|
871 | */ |
---|
872 | void G4OpenGLQtViewer::actionMouseRotate() { |
---|
873 | emit toggleMouseAction(STYLE1); |
---|
874 | } |
---|
875 | |
---|
876 | |
---|
877 | /** |
---|
878 | Slot activate when mouseAction->rotate menu is set |
---|
879 | */ |
---|
880 | void G4OpenGLQtViewer::actionMouseMove() { |
---|
881 | emit toggleMouseAction(STYLE2); |
---|
882 | } |
---|
883 | |
---|
884 | |
---|
885 | /** |
---|
886 | Slot activate when mouseAction->zoom menu is set |
---|
887 | */ |
---|
888 | void G4OpenGLQtViewer::actionMousePick() { |
---|
889 | #ifdef GEANT4_QT_DEBUG |
---|
890 | printf("G4OpenGLQtViewer::actionMousePick \n"); |
---|
891 | #endif |
---|
892 | emit toggleMouseAction(STYLE3); |
---|
893 | } |
---|
894 | |
---|
895 | /** |
---|
896 | Slot activate when mouseAction->zoom menu is set |
---|
897 | */ |
---|
898 | void G4OpenGLQtViewer::actionMouseShortcuts() { |
---|
899 | #ifdef GEANT4_QT_DEBUG |
---|
900 | printf("G4OpenGLQtViewer::actionMouseShortcuts \n"); |
---|
901 | #endif |
---|
902 | emit toggleMouseAction(STYLE4); |
---|
903 | } |
---|
904 | |
---|
905 | /** |
---|
906 | Slot activate when drawing->wireframe menu is set |
---|
907 | */ |
---|
908 | void G4OpenGLQtViewer::actionDrawingWireframe() { |
---|
909 | emit toggleDrawingAction(1); |
---|
910 | } |
---|
911 | |
---|
912 | /** |
---|
913 | Slot activate when drawing->line removal menu is set |
---|
914 | */ |
---|
915 | void G4OpenGLQtViewer::actionDrawingLineRemoval() { |
---|
916 | emit toggleDrawingAction(2); |
---|
917 | } |
---|
918 | |
---|
919 | /** |
---|
920 | Slot activate when drawing->surface removal menu is set |
---|
921 | */ |
---|
922 | void G4OpenGLQtViewer::actionDrawingSurfaceRemoval() { |
---|
923 | emit toggleDrawingAction(3); |
---|
924 | } |
---|
925 | |
---|
926 | /** |
---|
927 | Slot activate when drawing->wireframe menu is set |
---|
928 | */ |
---|
929 | void G4OpenGLQtViewer::actionDrawingLineSurfaceRemoval() { |
---|
930 | emit toggleDrawingAction(4); |
---|
931 | } |
---|
932 | |
---|
933 | |
---|
934 | /** |
---|
935 | Slot activated when mouse action is toggle |
---|
936 | @param aAction : STYLE1, STYLE2, STYLE3 |
---|
937 | */ |
---|
938 | void G4OpenGLQtViewer::toggleMouseAction(mouseActions aAction) { |
---|
939 | |
---|
940 | if ((aAction == STYLE1) || //initialize all |
---|
941 | (aAction == STYLE2) || |
---|
942 | (aAction == STYLE3) || |
---|
943 | (aAction == STYLE4)) { |
---|
944 | #if QT_VERSION < 0x040000 |
---|
945 | fRotateAction->setOn (false); |
---|
946 | fMoveAction->setOn (false); |
---|
947 | fPickAction->setOn (false); |
---|
948 | fShortcutsAction->setOn (false); |
---|
949 | #else |
---|
950 | fRotateAction->setChecked (false); |
---|
951 | fMoveAction->setChecked (false); |
---|
952 | fPickAction->setChecked (false); |
---|
953 | fShortcutsAction->setChecked (false); |
---|
954 | #endif |
---|
955 | fVP.SetPicking(false); |
---|
956 | fMouseAction = aAction; |
---|
957 | } |
---|
958 | // rotate |
---|
959 | if (aAction == STYLE1) { // rotate |
---|
960 | G4cout << "Click and move mouse to rotate volume \n" << G4endl; |
---|
961 | G4cout << "Press left/right arrows to move volume left/right\n" << G4endl; |
---|
962 | G4cout << "Press up/down arrows to move volume up/down\n" << G4endl; |
---|
963 | G4cout << "Press ALT+up/down arrows to move volume toward/forward\n" << G4endl; |
---|
964 | G4cout << "Press SHIFT+left/right arrows to rotate volume left/right\n" << G4endl; |
---|
965 | G4cout << "Press SHIFT+up/down arrows to rotate volume up/down\n" << G4endl; |
---|
966 | G4cout << "Press +/- to zoom into volume\n" << G4endl; |
---|
967 | #if QT_VERSION < 0x040000 |
---|
968 | fRotateAction->setOn (true); |
---|
969 | #else |
---|
970 | fRotateAction->setChecked (true); |
---|
971 | #endif |
---|
972 | } else if (aAction == STYLE2) { //move |
---|
973 | G4cout << "Move camera point of view with mouse\n" << G4endl; |
---|
974 | #if QT_VERSION < 0x040000 |
---|
975 | fMoveAction->setOn (true); |
---|
976 | #else |
---|
977 | fMoveAction->setChecked (true); |
---|
978 | #endif |
---|
979 | } else if (aAction == STYLE3) { //pick |
---|
980 | G4cout << "Click and pick \n" << G4endl; |
---|
981 | #if QT_VERSION < 0x040000 |
---|
982 | fPickAction->setOn (true); |
---|
983 | #else |
---|
984 | fPickAction->setChecked (true); |
---|
985 | #endif |
---|
986 | fVP.SetPicking(true); |
---|
987 | } else if (aAction == STYLE4) { // display shortcuts |
---|
988 | #if QT_VERSION < 0x040000 |
---|
989 | // fShortcutsAction->setOn (true); |
---|
990 | #else |
---|
991 | // fShortcutsAction->setChecked (true); |
---|
992 | #endif |
---|
993 | |
---|
994 | G4cout << "Click and move mouse to rotate volume \n" << G4endl; |
---|
995 | G4cout << "Press left/right arrows to move volume left/right\n" << G4endl; |
---|
996 | G4cout << "Press up/down arrows to move volume up/down\n" << G4endl; |
---|
997 | G4cout << "Press CONTROL+up/down arrows to move volume toward/forward\n" << G4endl; |
---|
998 | G4cout << "Press SHIFT+left/right arrows to rotate volume left/right\n" << G4endl; |
---|
999 | G4cout << "Press SHIFT+up/down arrows to rotate volume up/down\n" << G4endl; |
---|
1000 | G4cout << "Press +/- to zoom into volume\n" << G4endl; |
---|
1001 | } |
---|
1002 | |
---|
1003 | } |
---|
1004 | /** |
---|
1005 | Slot activated when drawing menu is toggle |
---|
1006 | Warning : When G4OpenGLStoredQtViewer::DrawView() method call, |
---|
1007 | KernelVisitDecision () will be call and will set the fNeedKernelVisit |
---|
1008 | to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. |
---|
1009 | It will cause a redraw of the view |
---|
1010 | @param aAction : 1 wireframe, 2 line removal, 3 surface removal, 4 line & surface removal |
---|
1011 | @see G4OpenGLStoredQtViewer::DrawView |
---|
1012 | @see G4XXXStoredViewer::CompareForKernelVisit |
---|
1013 | */ |
---|
1014 | void G4OpenGLQtViewer::toggleDrawingAction(int aAction) { |
---|
1015 | |
---|
1016 | G4ViewParameters::DrawingStyle d_style; |
---|
1017 | |
---|
1018 | |
---|
1019 | // initialize |
---|
1020 | if ((aAction >0) && (aAction <5)) { |
---|
1021 | #if QT_VERSION < 0x040000 |
---|
1022 | fDrawingWireframe->setOn(false); |
---|
1023 | fDrawingLineRemoval->setOn(false); |
---|
1024 | fDrawingSurfaceRemoval->setOn(false); |
---|
1025 | fDrawingLineSurfaceRemoval->setOn(false); |
---|
1026 | #else |
---|
1027 | fDrawingWireframe->setChecked (false); |
---|
1028 | fDrawingLineRemoval->setChecked (false); |
---|
1029 | fDrawingSurfaceRemoval->setChecked (false); |
---|
1030 | fDrawingLineSurfaceRemoval->setChecked (false); |
---|
1031 | #endif |
---|
1032 | } |
---|
1033 | if (aAction ==1) { |
---|
1034 | #if QT_VERSION < 0x040000 |
---|
1035 | fDrawingWireframe->setOn(true); |
---|
1036 | #else |
---|
1037 | fDrawingWireframe->setChecked (true); |
---|
1038 | #endif |
---|
1039 | |
---|
1040 | d_style = G4ViewParameters::wireframe; |
---|
1041 | |
---|
1042 | } else if (aAction ==2) { |
---|
1043 | #if QT_VERSION < 0x040000 |
---|
1044 | fDrawingLineRemoval->setOn(true); |
---|
1045 | #else |
---|
1046 | fDrawingLineRemoval->setChecked (true); |
---|
1047 | #endif |
---|
1048 | |
---|
1049 | d_style = G4ViewParameters::hlr; |
---|
1050 | |
---|
1051 | } else if (aAction ==3) { |
---|
1052 | #if QT_VERSION < 0x040000 |
---|
1053 | fDrawingSurfaceRemoval->setOn(true); |
---|
1054 | #else |
---|
1055 | fDrawingSurfaceRemoval->setChecked (true); |
---|
1056 | #endif |
---|
1057 | |
---|
1058 | d_style = G4ViewParameters::hsr; |
---|
1059 | |
---|
1060 | } else if (aAction ==4) { |
---|
1061 | #if QT_VERSION < 0x040000 |
---|
1062 | fDrawingLineSurfaceRemoval->setOn(true); |
---|
1063 | #else |
---|
1064 | fDrawingLineSurfaceRemoval->setChecked (true); |
---|
1065 | #endif |
---|
1066 | d_style = G4ViewParameters::hlhsr; |
---|
1067 | } |
---|
1068 | fVP.SetDrawingStyle(d_style); |
---|
1069 | |
---|
1070 | updateQWidget(); |
---|
1071 | } |
---|
1072 | |
---|
1073 | |
---|
1074 | /** |
---|
1075 | SLOT Activate by a click on the representation menu |
---|
1076 | Warning : When G4OpenGLStoredQtViewer::DrawView() method call, |
---|
1077 | KernelVisitDecision () will be call and will set the fNeedKernelVisit |
---|
1078 | to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. |
---|
1079 | It will cause a redraw of the view |
---|
1080 | @param check : 1 polyhedron, 0 nurbs |
---|
1081 | @see G4OpenGLStoredQtViewer::DrawView |
---|
1082 | @see G4XXXStoredViewer::CompareForKernelVisit |
---|
1083 | */ |
---|
1084 | void G4OpenGLQtViewer::toggleRepresentation(bool check) { |
---|
1085 | |
---|
1086 | G4ViewParameters::RepStyle style; |
---|
1087 | if (check == 1) { |
---|
1088 | style = G4ViewParameters::polyhedron; |
---|
1089 | } else { |
---|
1090 | style = G4ViewParameters::nurbs; |
---|
1091 | } |
---|
1092 | fVP.SetRepStyle (style); |
---|
1093 | |
---|
1094 | updateQWidget(); |
---|
1095 | } |
---|
1096 | |
---|
1097 | /** |
---|
1098 | SLOT Activate by a click on the projection menu |
---|
1099 | Warning : When G4OpenGLStoredQtViewer::DrawView() method call, |
---|
1100 | KernelVisitDecision () will be call and will set the fNeedKernelVisit |
---|
1101 | to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. |
---|
1102 | It will cause a redraw of the view |
---|
1103 | @param check : 1 orthographic, 2 perspective |
---|
1104 | @see G4OpenGLStoredQtViewer::DrawView |
---|
1105 | @see G4XXXStoredViewer::CompareForKernelVisit |
---|
1106 | */ |
---|
1107 | void G4OpenGLQtViewer::toggleProjection(bool check) { |
---|
1108 | |
---|
1109 | if (check == 1) { |
---|
1110 | fVP.SetFieldHalfAngle (0); |
---|
1111 | } else { |
---|
1112 | |
---|
1113 | // look for the default parameter hidden in G4UIcommand parameters |
---|
1114 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
1115 | if(UI==NULL) |
---|
1116 | return; |
---|
1117 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
1118 | |
---|
1119 | // find command |
---|
1120 | G4UIcommand* command = treeTop->FindPath("/vis/viewer/set/projection"); |
---|
1121 | if (!command) |
---|
1122 | return; |
---|
1123 | |
---|
1124 | // find param |
---|
1125 | G4UIparameter * angleParam = NULL; |
---|
1126 | for(G4int i=0; i<command->GetParameterEntries(); i++) |
---|
1127 | { |
---|
1128 | if( command->GetParameter(i)->GetParameterName() == "field-half-angle" ) { |
---|
1129 | angleParam = command->GetParameter(i); |
---|
1130 | } |
---|
1131 | } |
---|
1132 | if (!angleParam) |
---|
1133 | return; |
---|
1134 | |
---|
1135 | // find unit |
---|
1136 | G4UIparameter * unitParam = NULL; |
---|
1137 | for(G4int i=0; i<command->GetParameterEntries(); i++) |
---|
1138 | { |
---|
1139 | if( command->GetParameter(i)->GetParameterName() == "unit" ) { |
---|
1140 | unitParam = command->GetParameter(i); |
---|
1141 | } |
---|
1142 | } |
---|
1143 | if (!unitParam) |
---|
1144 | return; |
---|
1145 | |
---|
1146 | G4double defaultValue = command->ConvertToDouble(angleParam->GetDefaultValue()) |
---|
1147 | * G4UnitDefinition::GetValueOf(unitParam->GetDefaultValue()); |
---|
1148 | if (defaultValue > 89.5 || defaultValue <= 0.0) { |
---|
1149 | G4cerr << "Field half angle should be 0 < angle <= 89.5 degrees. Check your default Field half angle parameter\n"; |
---|
1150 | } else { |
---|
1151 | G4cout << "Perspective view has been set to default value. Field half angle="<<angleParam->GetDefaultValue() <<" \n" << G4endl; |
---|
1152 | fVP.SetFieldHalfAngle (defaultValue); |
---|
1153 | SetView (); |
---|
1154 | } |
---|
1155 | } |
---|
1156 | updateQWidget(); |
---|
1157 | } |
---|
1158 | |
---|
1159 | |
---|
1160 | /** |
---|
1161 | SLOT Activate by a click on the background menu |
---|
1162 | @param check : 1 white, 0 black |
---|
1163 | */ |
---|
1164 | void G4OpenGLQtViewer::toggleBackground(bool check) { |
---|
1165 | |
---|
1166 | // //I need to revisit the kernel if the background colour changes and |
---|
1167 | // //hidden line removal is enabled, because hlr drawing utilises the |
---|
1168 | // //background colour in its drawing... |
---|
1169 | // // (Note added by JA 13/9/2005) Background now handled in view |
---|
1170 | // // parameters. A kernel visit is triggered on change of background. |
---|
1171 | if (check == 1) { |
---|
1172 | ((G4ViewParameters&)this->GetViewParameters()). |
---|
1173 | SetBackgroundColour(G4Colour(1.,1.,1.)); // White |
---|
1174 | } else { |
---|
1175 | ((G4ViewParameters&)this->GetViewParameters()). |
---|
1176 | SetBackgroundColour(G4Colour(0.,0.,0.)); // Black |
---|
1177 | } |
---|
1178 | updateQWidget(); |
---|
1179 | } |
---|
1180 | |
---|
1181 | /** |
---|
1182 | SLOT Activate by a click on the transparency menu |
---|
1183 | @param check : 1 , 0 |
---|
1184 | */ |
---|
1185 | void G4OpenGLQtViewer::toggleTransparency(bool check) { |
---|
1186 | |
---|
1187 | if (check) { |
---|
1188 | transparency_enabled = false; |
---|
1189 | } else { |
---|
1190 | transparency_enabled = true; |
---|
1191 | } |
---|
1192 | SetNeedKernelVisit (true); |
---|
1193 | updateQWidget(); |
---|
1194 | } |
---|
1195 | |
---|
1196 | /** |
---|
1197 | SLOT Activate by a click on the antialiasing menu |
---|
1198 | @param check : 1 , 0 |
---|
1199 | */ |
---|
1200 | void G4OpenGLQtViewer::toggleAntialiasing(bool check) { |
---|
1201 | |
---|
1202 | if (!check) { |
---|
1203 | antialiasing_enabled = false; |
---|
1204 | glDisable (GL_LINE_SMOOTH); |
---|
1205 | glDisable (GL_POLYGON_SMOOTH); |
---|
1206 | } else { |
---|
1207 | antialiasing_enabled = true; |
---|
1208 | glEnable (GL_LINE_SMOOTH); |
---|
1209 | glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); |
---|
1210 | glEnable (GL_POLYGON_SMOOTH); |
---|
1211 | glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST); |
---|
1212 | } |
---|
1213 | |
---|
1214 | updateQWidget(); |
---|
1215 | } |
---|
1216 | |
---|
1217 | /** |
---|
1218 | SLOT Activate by a click on the haloing menu |
---|
1219 | @param check : 1 , 0 |
---|
1220 | */ |
---|
1221 | //FIXME : I SEE NOTHING... |
---|
1222 | void G4OpenGLQtViewer::toggleHaloing(bool check) { |
---|
1223 | if (check) { |
---|
1224 | haloing_enabled = false; |
---|
1225 | } else { |
---|
1226 | haloing_enabled = true; |
---|
1227 | } |
---|
1228 | |
---|
1229 | updateQWidget(); |
---|
1230 | |
---|
1231 | } |
---|
1232 | |
---|
1233 | /** |
---|
1234 | SLOT Activate by a click on the auxiliaire edges menu |
---|
1235 | @param check : 1 , 0 |
---|
1236 | */ |
---|
1237 | void G4OpenGLQtViewer::toggleAux(bool check) { |
---|
1238 | if (check) { |
---|
1239 | fVP.SetAuxEdgeVisible(false); |
---|
1240 | } else { |
---|
1241 | fVP.SetAuxEdgeVisible(true); |
---|
1242 | } |
---|
1243 | SetNeedKernelVisit (true); |
---|
1244 | updateQWidget(); |
---|
1245 | |
---|
1246 | } |
---|
1247 | |
---|
1248 | /** |
---|
1249 | SLOT Activate by a click on the full screen menu |
---|
1250 | */ |
---|
1251 | void G4OpenGLQtViewer::toggleFullScreen(bool check) { |
---|
1252 | #ifdef GEANT4_QT_DEBUG |
---|
1253 | printf("G4OpenGLQtViewer::toggleFullScreen checked:%d() \n",check); |
---|
1254 | #endif |
---|
1255 | if (check != GLWindow->isFullScreen()) { //toggle |
---|
1256 | #if QT_VERSION >= 0x030200 |
---|
1257 | #if QT_VERSION < 0x040000 |
---|
1258 | GLWindow->setWindowState(GLWindow->windowState() ^ Qt::WindowFullScreen); |
---|
1259 | // fFullScreenOn->setOn(check); |
---|
1260 | // fFullScreenOff->setOn(!check); |
---|
1261 | #else |
---|
1262 | GLWindow->setWindowState(GLWindow->windowState() ^ Qt::WindowFullScreen); |
---|
1263 | // fFullScreenOn->setChecked(check); |
---|
1264 | // fFullScreenOff->setChecked(!check); |
---|
1265 | #endif |
---|
1266 | #else |
---|
1267 | G4cerr << "This version of Qt could not do fullScreen. Resizing the widget is the only solution available.\n" << G4endl; |
---|
1268 | #endif |
---|
1269 | } |
---|
1270 | } |
---|
1271 | |
---|
1272 | void G4OpenGLQtViewer::actionCreateEPS() { |
---|
1273 | QString filters; |
---|
1274 | #if QT_VERSION < 0x040000 |
---|
1275 | QStrList listFormat=QImageIO::outputFormats(); |
---|
1276 | char *tmp=listFormat.first(); |
---|
1277 | while (tmp!=0) { |
---|
1278 | filters += QString(tmp) + ";;"; |
---|
1279 | tmp=listFormat.next(); |
---|
1280 | } |
---|
1281 | #else |
---|
1282 | QList<QByteArray> formats = QImageWriter::supportedImageFormats (); |
---|
1283 | for (int i = 0; i < formats.size(); ++i) { |
---|
1284 | filters +=formats.at(i) + ";;"; |
---|
1285 | } |
---|
1286 | #endif |
---|
1287 | filters += "eps;;"; |
---|
1288 | filters += "ps;;"; |
---|
1289 | filters += "pdf"; |
---|
1290 | QString* selectedFormat = new QString(); |
---|
1291 | #if QT_VERSION < 0x040000 |
---|
1292 | QString nomFich = QFileDialog::getSaveFileName ( ".", |
---|
1293 | filters, |
---|
1294 | GLWindow, |
---|
1295 | "Save file dialog", |
---|
1296 | tr("Save as ..."), |
---|
1297 | selectedFormat ); |
---|
1298 | #else |
---|
1299 | QString nomFich = QFileDialog::getSaveFileName ( GLWindow, |
---|
1300 | tr("Save as ..."), |
---|
1301 | ".", |
---|
1302 | filters, |
---|
1303 | selectedFormat ); |
---|
1304 | #endif |
---|
1305 | // bmp jpg jpeg png ppm xbm xpm |
---|
1306 | if (nomFich == "") { |
---|
1307 | return; |
---|
1308 | } |
---|
1309 | #if QT_VERSION < 0x040000 |
---|
1310 | nomFich += "."+QString(selectedFormat->ascii()); |
---|
1311 | QString format = selectedFormat->lower(); |
---|
1312 | #else |
---|
1313 | nomFich += "."+QString(selectedFormat->toStdString().c_str()); |
---|
1314 | QString format = selectedFormat->toLower(); |
---|
1315 | #endif |
---|
1316 | G4OpenGLQtExportDialog* exportDialog= new G4OpenGLQtExportDialog(GLWindow,format,fWindow->height(),fWindow->width()); |
---|
1317 | if( exportDialog->exec()) { |
---|
1318 | |
---|
1319 | QImage image; |
---|
1320 | bool res = false; |
---|
1321 | if ((exportDialog->getWidth() !=fWindow->width()) || |
---|
1322 | (exportDialog->getHeight() !=fWindow->height())) { |
---|
1323 | if (format != QString("eps")) { |
---|
1324 | G4cerr << "Export->Change Size : This function is not implemented, to export in another size, please resize your frame to what you need\n" << G4endl; |
---|
1325 | |
---|
1326 | // rescaleImage(exportDialog->getWidth(),exportDialog->getHeight());// re-scale image |
---|
1327 | // QGLWidget* glResized = fWindow; |
---|
1328 | |
---|
1329 | // FIXME : |
---|
1330 | // L.Garnier : I've try to implement change size function, but the problem is |
---|
1331 | // the renderPixmap function call the QGLWidget to resize and it doesn't draw |
---|
1332 | // the content of this widget... It only draw the background. |
---|
1333 | |
---|
1334 | // fWindow->renderPixmap (exportDialog->getWidth()*2,exportDialog->getHeight()*2,true ); |
---|
1335 | |
---|
1336 | // QPixmap pixmap = fWindow->renderPixmap (); |
---|
1337 | |
---|
1338 | // image = pixmap->toImage(); |
---|
1339 | // glResized->resize(exportDialog->getWidth()*2,exportDialog->getHeight()*2); |
---|
1340 | // image = glResized->grabFrameBuffer(); |
---|
1341 | } |
---|
1342 | } else { |
---|
1343 | image = fWindow->grabFrameBuffer(); |
---|
1344 | } |
---|
1345 | if (format == QString("eps")) { |
---|
1346 | if (exportDialog->getVectorEPS()) { |
---|
1347 | res = generateVectorEPS(nomFich,exportDialog->getWidth(),exportDialog->getHeight(),image); |
---|
1348 | } else { |
---|
1349 | res = generateEPS(nomFich,exportDialog->getNbColor(),image); |
---|
1350 | } |
---|
1351 | } else if ((format == "ps") || (format == "pdf")) { |
---|
1352 | res = generatePS_PDF(nomFich,exportDialog->getNbColor(),image); |
---|
1353 | } else if ((format == "tif") || |
---|
1354 | (format == "tiff") || |
---|
1355 | (format == "jpg") || |
---|
1356 | (format == "jpeg") || |
---|
1357 | (format == "png") || |
---|
1358 | (format == "pbm") || |
---|
1359 | (format == "pgm") || |
---|
1360 | (format == "ppm") || |
---|
1361 | (format == "bmp") || |
---|
1362 | (format == "xbm") || |
---|
1363 | (format == "xpm")) { |
---|
1364 | #if QT_VERSION < 0x040000 |
---|
1365 | res = image.save(nomFich,selectedFormat->ascii(),exportDialog->getSliderValue()); |
---|
1366 | #else |
---|
1367 | res = image.save(nomFich,0,exportDialog->getSliderValue()); |
---|
1368 | #endif |
---|
1369 | } else { |
---|
1370 | G4cerr << "This version of G4UI Could not generate the selected format\n" << G4endl; |
---|
1371 | } |
---|
1372 | if (res == false) { |
---|
1373 | #if QT_VERSION < 0x040000 |
---|
1374 | G4cerr << "Error while saving file... "<<nomFich.ascii()<<"\n" << G4endl; |
---|
1375 | #else |
---|
1376 | G4cerr << "Error while saving file... "<<nomFich.toStdString().c_str()<<"\n" << G4endl; |
---|
1377 | #endif |
---|
1378 | } else { |
---|
1379 | #if QT_VERSION < 0x040000 |
---|
1380 | G4cout << "File "<<nomFich.ascii()<<" has been saved \n" << G4endl; |
---|
1381 | #else |
---|
1382 | G4cout << "File "<<nomFich.toStdString().c_str()<<" has been saved \n" << G4endl; |
---|
1383 | #endif |
---|
1384 | } |
---|
1385 | |
---|
1386 | } else { // cancel selected |
---|
1387 | return; |
---|
1388 | } |
---|
1389 | |
---|
1390 | #ifdef GEANT4_QT_DEBUG |
---|
1391 | printf("G4OpenGLQtViewer::actionCreateEPS() \n"); |
---|
1392 | #endif |
---|
1393 | } |
---|
1394 | |
---|
1395 | /* |
---|
1396 | // 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 |
---|
1397 | |
---|
1398 | void Graph::exportToSVG(const QString& fname) |
---|
1399 | { |
---|
1400 | // enable workaround for Qt3 misalignments |
---|
1401 | QwtPainter::setSVGMode(true); |
---|
1402 | QPicture picture; |
---|
1403 | QPainter p(&picture); |
---|
1404 | d_plot->print(&p, d_plot->rect()); |
---|
1405 | p.end(); |
---|
1406 | |
---|
1407 | picture.save(fname, "svg"); |
---|
1408 | } |
---|
1409 | */ |
---|
1410 | |
---|
1411 | |
---|
1412 | |
---|
1413 | |
---|
1414 | /** |
---|
1415 | Save the current mouse press point |
---|
1416 | @param p mouse click point |
---|
1417 | */ |
---|
1418 | #if QT_VERSION < 0x040000 |
---|
1419 | void G4OpenGLQtViewer::G4MousePressEvent(QPoint p,Qt::ButtonState mButtons) |
---|
1420 | #else |
---|
1421 | void G4OpenGLQtViewer::G4MousePressEvent(QPoint p,Qt::MouseButtons mButtons) |
---|
1422 | #endif |
---|
1423 | { |
---|
1424 | fAutoMove = false; // stop automove |
---|
1425 | fLastPos = p; |
---|
1426 | if (fMouseAction == STYLE2){ // pick |
---|
1427 | Pick(p.x(),p.y()); |
---|
1428 | } |
---|
1429 | } |
---|
1430 | |
---|
1431 | |
---|
1432 | /** |
---|
1433 | @param pos_x mouse x position |
---|
1434 | @param pos_y mouse y position |
---|
1435 | @param mButtons mouse button active |
---|
1436 | @param mAutoMove true: apply this move till another evnt came, false :one time move |
---|
1437 | */ |
---|
1438 | |
---|
1439 | #if QT_VERSION < 0x040000 |
---|
1440 | void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::ButtonState mButtons,bool mAutoMove) |
---|
1441 | #else |
---|
1442 | void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons,bool mAutoMove) |
---|
1443 | #endif |
---|
1444 | { |
---|
1445 | fAutoMove = mAutoMove; |
---|
1446 | #ifdef GEANT4_QT_DEBUG |
---|
1447 | printf(" mouse move event %d %d\n",pos_x,pos_y); |
---|
1448 | #endif |
---|
1449 | |
---|
1450 | if (!fAutoMove) { // keep old delta if automove |
---|
1451 | fDeltaPos = QPoint(fLastPos.x() - pos_x, fLastPos.y() - pos_y); |
---|
1452 | } |
---|
1453 | |
---|
1454 | if ((fDeltaPos.x() == 0) && (fDeltaPos.y() == 0)) { |
---|
1455 | fAutoMove = false; |
---|
1456 | } |
---|
1457 | |
---|
1458 | if (fMouseAction == STYLE1) { // rotate |
---|
1459 | if (mButtons & Qt::LeftButton) { |
---|
1460 | if (fAutoMove) { |
---|
1461 | while (fAutoMove) { |
---|
1462 | rotateScene(fDeltaPos.x(),fDeltaPos.y()); |
---|
1463 | #ifdef GEANT4_QT_DEBUG |
---|
1464 | printf(" Processiongevent %d %d\n",fDeltaPos.x(),fDeltaPos.y()); |
---|
1465 | #endif |
---|
1466 | ((QApplication*)G4Qt::getInstance ())->processEvents(); |
---|
1467 | } |
---|
1468 | } else { |
---|
1469 | rotateScene(fDeltaPos.x(),fDeltaPos.y()); |
---|
1470 | } |
---|
1471 | } |
---|
1472 | } else if (fMouseAction == STYLE2) { // move |
---|
1473 | if (mButtons & Qt::LeftButton) { |
---|
1474 | if (fAutoMove) { |
---|
1475 | while (fAutoMove) { |
---|
1476 | moveScene(-fDeltaPos.x(),-fDeltaPos.y(),0,true); |
---|
1477 | } |
---|
1478 | } else { |
---|
1479 | moveScene(-fDeltaPos.x(),-fDeltaPos.y(),0,true); |
---|
1480 | } |
---|
1481 | } |
---|
1482 | } |
---|
1483 | fLastPos = QPoint(pos_x, pos_y); |
---|
1484 | #ifdef GEANT4_QT_DEBUG |
---|
1485 | if (mButtons & Qt::LeftButton) { |
---|
1486 | printf(" end of mouse move event %d %d delta:%d %d\n",pos_x,pos_y,fDeltaPos.x(),fDeltaPos.y()); |
---|
1487 | } else { |
---|
1488 | printf(" end of mouse move event %d %d delta:%d %d --------------NO BUTTON\n",pos_x,pos_y,fDeltaPos.x(),fDeltaPos.y()); |
---|
1489 | } |
---|
1490 | #endif |
---|
1491 | } |
---|
1492 | |
---|
1493 | |
---|
1494 | /** |
---|
1495 | Move the scene of dx, dy, dz values. |
---|
1496 | @param dx delta mouse x position |
---|
1497 | @param dy delta mouse y position |
---|
1498 | @param mouseMove : true if even comes froma mouse move, false if even comes from key action |
---|
1499 | */ |
---|
1500 | |
---|
1501 | void G4OpenGLQtViewer::moveScene(G4double dx,G4double dy, G4double dz,bool mouseMove) |
---|
1502 | { |
---|
1503 | G4double coefTrans = 0; |
---|
1504 | GLdouble coefDepth = 0; |
---|
1505 | if(mouseMove) { |
---|
1506 | coefTrans = ((G4double)getSceneNearWidth())/((G4double)WinSize_x); |
---|
1507 | if (WinSize_y <WinSize_x) { |
---|
1508 | coefTrans = ((G4double)getSceneNearWidth())/((G4double)WinSize_y); |
---|
1509 | } |
---|
1510 | } else { |
---|
1511 | coefTrans = getSceneNearWidth()*fDeltaSceneTranslation; |
---|
1512 | coefDepth = getSceneDepth()*fDeltaDepth; |
---|
1513 | } |
---|
1514 | fVP.IncrementPan(-dx*coefTrans,dy*coefTrans,dz*coefDepth); |
---|
1515 | |
---|
1516 | updateQWidget(); |
---|
1517 | } |
---|
1518 | |
---|
1519 | |
---|
1520 | /** |
---|
1521 | @param dx delta mouse x position |
---|
1522 | @param dy delta mouse y position |
---|
1523 | */ |
---|
1524 | |
---|
1525 | void G4OpenGLQtViewer::rotateScene(G4double dx, G4double dy) |
---|
1526 | { |
---|
1527 | dx = dx * fDeltaRotation; |
---|
1528 | dy = dy * fDeltaRotation; |
---|
1529 | |
---|
1530 | //phi spin stuff here |
---|
1531 | |
---|
1532 | G4Vector3D vp = fVP.GetViewpointDirection ().unit (); |
---|
1533 | G4Vector3D up = fVP.GetUpVector ().unit (); |
---|
1534 | |
---|
1535 | G4Vector3D yprime = (up.cross(vp)).unit(); |
---|
1536 | G4Vector3D zprime = (vp.cross(yprime)).unit(); |
---|
1537 | |
---|
1538 | G4double delta_alpha; |
---|
1539 | G4double delta_theta; |
---|
1540 | |
---|
1541 | if (fVP.GetLightsMoveWithCamera()) { |
---|
1542 | delta_alpha = dy; |
---|
1543 | delta_theta = -dx; |
---|
1544 | } else { |
---|
1545 | delta_alpha = -dy; |
---|
1546 | delta_theta = dx; |
---|
1547 | } |
---|
1548 | |
---|
1549 | delta_alpha *= deg; |
---|
1550 | delta_theta *= deg; |
---|
1551 | |
---|
1552 | G4Vector3D new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime; |
---|
1553 | |
---|
1554 | G4Vector3D new_up; |
---|
1555 | if (fVP.GetLightsMoveWithCamera()) { |
---|
1556 | new_up = (new_vp.cross(yprime)).unit(); |
---|
1557 | fVP.SetUpVector(new_up); |
---|
1558 | } else { |
---|
1559 | new_up = up; |
---|
1560 | } |
---|
1561 | //////////////// |
---|
1562 | // Rotates by fixed azimuthal angle delta_theta. |
---|
1563 | |
---|
1564 | G4double cosalpha = new_up.dot (new_vp.unit()); |
---|
1565 | G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2)); |
---|
1566 | yprime = (new_up.cross (new_vp.unit())).unit (); |
---|
1567 | G4Vector3D xprime = yprime.cross (new_up); |
---|
1568 | // Projection of vp on plane perpendicular to up... |
---|
1569 | G4Vector3D a1 = sinalpha * xprime; |
---|
1570 | // Required new projection... |
---|
1571 | G4Vector3D a2 = |
---|
1572 | sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime); |
---|
1573 | // Required Increment vector... |
---|
1574 | G4Vector3D delta = a2 - a1; |
---|
1575 | // So new viewpoint is... |
---|
1576 | G4Vector3D viewPoint = new_vp.unit() + delta; |
---|
1577 | |
---|
1578 | fVP.SetViewAndLights (viewPoint); |
---|
1579 | updateQWidget(); |
---|
1580 | |
---|
1581 | } |
---|
1582 | |
---|
1583 | /** This is the benning of a rescale function. It does nothing for the moment |
---|
1584 | @param aWidth : new width |
---|
1585 | @param aHeight : new height |
---|
1586 | */ |
---|
1587 | void G4OpenGLQtViewer::rescaleImage( |
---|
1588 | int aWidth |
---|
1589 | ,int aHeight |
---|
1590 | ){ |
---|
1591 | #ifdef GEANT4_QT_DEBUG |
---|
1592 | printf("should rescale \n"); |
---|
1593 | #endif |
---|
1594 | GLfloat* feedback_buffer; |
---|
1595 | GLint returned; |
---|
1596 | FILE* file; |
---|
1597 | |
---|
1598 | // feedback_buffer = new GLfloat[size]; |
---|
1599 | // glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer); |
---|
1600 | // glRenderMode (GL_FEEDBACK); |
---|
1601 | |
---|
1602 | // glViewport (0, 0, aWidth, aHeight); |
---|
1603 | // DrawView(); |
---|
1604 | // returned = glRenderMode (GL_RENDER); |
---|
1605 | |
---|
1606 | } |
---|
1607 | |
---|
1608 | /** |
---|
1609 | Generate Vectorial Encapsulated Postscript form image |
---|
1610 | @param aFilename : name of file |
---|
1611 | @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha |
---|
1612 | @param aImage : Image to print |
---|
1613 | */ |
---|
1614 | bool G4OpenGLQtViewer::generateVectorEPS ( |
---|
1615 | QString aFilename |
---|
1616 | ,int aWidth |
---|
1617 | ,int aHeight |
---|
1618 | ,QImage aImage |
---|
1619 | ) |
---|
1620 | { |
---|
1621 | // Print vectored PostScript |
---|
1622 | |
---|
1623 | G4int size = 5000000; |
---|
1624 | |
---|
1625 | GLfloat* feedback_buffer; |
---|
1626 | GLint returned; |
---|
1627 | FILE* file; |
---|
1628 | |
---|
1629 | feedback_buffer = new GLfloat[size]; |
---|
1630 | glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer); |
---|
1631 | glRenderMode (GL_FEEDBACK); |
---|
1632 | |
---|
1633 | int side = aWidth; |
---|
1634 | if (aHeight < aWidth) side = aHeight; |
---|
1635 | glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side); |
---|
1636 | DrawView(); |
---|
1637 | |
---|
1638 | returned = glRenderMode (GL_RENDER); |
---|
1639 | |
---|
1640 | |
---|
1641 | #if QT_VERSION < 0x040000 |
---|
1642 | file = fopen (aFilename.ascii(), "w"); |
---|
1643 | #else |
---|
1644 | file = fopen (aFilename.toStdString().c_str(), "w"); |
---|
1645 | #endif |
---|
1646 | if (file) { |
---|
1647 | spewWireframeEPS (file, returned, feedback_buffer, "rendereps"); |
---|
1648 | } else { |
---|
1649 | #if QT_VERSION < 0x040000 |
---|
1650 | G4cerr << "Could not open "<< aFilename.ascii()<<"\n" << G4endl; |
---|
1651 | #else |
---|
1652 | G4cerr << "Could not open "<< aFilename.toStdString().c_str()<<"\n" << G4endl; |
---|
1653 | #endif |
---|
1654 | } |
---|
1655 | |
---|
1656 | delete[] feedback_buffer; |
---|
1657 | |
---|
1658 | return true; |
---|
1659 | } |
---|
1660 | |
---|
1661 | /** |
---|
1662 | Generate Encapsulated Postscript form image |
---|
1663 | @param aFilename : name of file |
---|
1664 | @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha |
---|
1665 | @param aImage : Image to print |
---|
1666 | */ |
---|
1667 | bool G4OpenGLQtViewer::generateEPS ( |
---|
1668 | QString aFilename |
---|
1669 | ,int aInColor |
---|
1670 | ,QImage aImage |
---|
1671 | ) |
---|
1672 | { |
---|
1673 | // FIXME |
---|
1674 | #ifdef GEANT4_QT_DEBUG |
---|
1675 | printf("saving EPS\n"); |
---|
1676 | #endif |
---|
1677 | |
---|
1678 | FILE* fp; |
---|
1679 | |
---|
1680 | if (aImage.bits () == NULL) |
---|
1681 | return false; |
---|
1682 | |
---|
1683 | #if QT_VERSION < 0x040000 |
---|
1684 | fp = fopen (aFilename.ascii(), "w"); |
---|
1685 | #else |
---|
1686 | fp = fopen (aFilename.toStdString().c_str(), "w"); |
---|
1687 | #endif |
---|
1688 | if (fp == NULL) { |
---|
1689 | return false; |
---|
1690 | } |
---|
1691 | |
---|
1692 | fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n"); |
---|
1693 | #if QT_VERSION < 0x040000 |
---|
1694 | fprintf (fp, "%%%%Title: %s\n", aFilename.ascii()); |
---|
1695 | #else |
---|
1696 | fprintf (fp, "%%%%Title: %s\n", aFilename.toStdString().c_str()); |
---|
1697 | #endif |
---|
1698 | fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n"); |
---|
1699 | fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", aImage.width(), aImage.height()); |
---|
1700 | fprintf (fp, "%%%%EndComments\n"); |
---|
1701 | fprintf (fp, "gsave\n"); |
---|
1702 | fprintf (fp, "/bwproc {\n"); |
---|
1703 | fprintf (fp, " rgbproc\n"); |
---|
1704 | fprintf (fp, " dup length 3 idiv string 0 3 0 \n"); |
---|
1705 | fprintf (fp, " 5 -1 roll {\n"); |
---|
1706 | fprintf (fp, " add 2 1 roll 1 sub dup 0 eq\n"); |
---|
1707 | fprintf (fp, " { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n"); |
---|
1708 | fprintf (fp, " 3 1 roll 5 -1 roll } put 1 add 3 0 \n"); |
---|
1709 | fprintf (fp, " { 2 1 roll } ifelse\n"); |
---|
1710 | fprintf (fp, " }forall\n"); |
---|
1711 | fprintf (fp, " pop pop pop\n"); |
---|
1712 | fprintf (fp, "} def\n"); |
---|
1713 | fprintf (fp, "systemdict /colorimage known not {\n"); |
---|
1714 | fprintf (fp, " /colorimage {\n"); |
---|
1715 | fprintf (fp, " pop\n"); |
---|
1716 | fprintf (fp, " pop\n"); |
---|
1717 | fprintf (fp, " /rgbproc exch def\n"); |
---|
1718 | fprintf (fp, " { bwproc } image\n"); |
---|
1719 | fprintf (fp, " } def\n"); |
---|
1720 | fprintf (fp, "} if\n"); |
---|
1721 | fprintf (fp, "/picstr %d string def\n", aImage.width() * aInColor); |
---|
1722 | fprintf (fp, "%d %d scale\n", aImage.width(), aImage.height()); |
---|
1723 | fprintf (fp, "%d %d %d\n", aImage.width(), aImage.height(), 8); |
---|
1724 | fprintf (fp, "[%d 0 0 %d 0 0]\n", aImage.width(), aImage.height()); |
---|
1725 | fprintf (fp, "{currentfile picstr readhexstring pop}\n"); |
---|
1726 | fprintf (fp, "false %d\n", aInColor); |
---|
1727 | fprintf (fp, "colorimage\n"); |
---|
1728 | |
---|
1729 | |
---|
1730 | int width = aImage.width(); |
---|
1731 | int height = aImage.height(); |
---|
1732 | int depth = aImage.depth(); |
---|
1733 | int size = width*height; |
---|
1734 | |
---|
1735 | if (depth == 1) |
---|
1736 | size = (width+7)/8*height; |
---|
1737 | else if (aInColor == 1) |
---|
1738 | size = size*3; |
---|
1739 | |
---|
1740 | int i = 0; |
---|
1741 | // if ( aInColor ==1 ) { |
---|
1742 | // FIXME : L. Garnier. For the moment 10 dec 2007, I could not find a way |
---|
1743 | // to save correctly grayscale Image. I mean that color or grayscale image |
---|
1744 | // have the same file save size ! |
---|
1745 | |
---|
1746 | /* } else*/ if (depth == 8) { |
---|
1747 | for(int y=height-1; y >=0 ; y--) { |
---|
1748 | const uchar * s = aImage.scanLine(y); |
---|
1749 | for(int x=0; x <width; x++) { |
---|
1750 | QRgb rgb = aImage.color(s[x]); |
---|
1751 | if (aInColor == 1) { |
---|
1752 | fprintf (fp, " %02hx ",(unsigned char)qGray(rgb)); |
---|
1753 | i++; |
---|
1754 | } else { |
---|
1755 | fprintf (fp, " %02hx %02hx %02hx", |
---|
1756 | (unsigned char) qRed(rgb), |
---|
1757 | (unsigned char) qGreen(rgb), |
---|
1758 | (unsigned char) qBlue(rgb)); |
---|
1759 | i += 3; |
---|
1760 | } |
---|
1761 | } |
---|
1762 | fprintf (fp, "\n"); |
---|
1763 | } |
---|
1764 | } else { |
---|
1765 | #if QT_VERSION < 0x040000 |
---|
1766 | bool alpha = aImage.hasAlphaBuffer(); |
---|
1767 | #else |
---|
1768 | bool alpha = aImage.hasAlphaChannel(); |
---|
1769 | for(int y=height-1; y >=0 ; y--) { |
---|
1770 | QRgb * s = (QRgb*)(aImage.scanLine(y)); |
---|
1771 | for(int x=0; x <width; x++) { |
---|
1772 | QRgb rgb = (*s++); |
---|
1773 | if (alpha && qAlpha(rgb) < 0x40) // 25% alpha, convert to white - |
---|
1774 | rgb = qRgb(0xff, 0xff, 0xff); |
---|
1775 | if (aInColor == 1) { |
---|
1776 | fprintf (fp, " %02hx ",(unsigned char)qGray(rgb)); |
---|
1777 | i++; |
---|
1778 | } else { |
---|
1779 | fprintf (fp, " %02hx %02hx %02hx", |
---|
1780 | (unsigned char) qRed(rgb), |
---|
1781 | (unsigned char) qGreen(rgb), |
---|
1782 | (unsigned char) qBlue(rgb)); |
---|
1783 | i += 3; |
---|
1784 | } |
---|
1785 | } |
---|
1786 | fprintf (fp, "\n"); |
---|
1787 | } |
---|
1788 | #endif |
---|
1789 | |
---|
1790 | } |
---|
1791 | |
---|
1792 | fprintf (fp, "grestore\n"); |
---|
1793 | fprintf (fp, "showpage\n"); |
---|
1794 | fclose (fp); |
---|
1795 | |
---|
1796 | return true; |
---|
1797 | } |
---|
1798 | /** |
---|
1799 | Generate Postscript or PDF form image |
---|
1800 | @param aFilename : name of file |
---|
1801 | @param aInColor : numbers of colors : 1->BW 2->RGB |
---|
1802 | @param aImage : Image to print |
---|
1803 | */ |
---|
1804 | bool G4OpenGLQtViewer::generatePS_PDF ( |
---|
1805 | QString aFilename |
---|
1806 | ,int aInColor |
---|
1807 | ,QImage aImage |
---|
1808 | ) |
---|
1809 | { |
---|
1810 | |
---|
1811 | #if QT_VERSION < 0x040000 |
---|
1812 | #ifdef Q_WS_MAC || Q_WS_X11 |
---|
1813 | QPrinter printer; |
---|
1814 | // printer.setPageSize(pageSize); |
---|
1815 | if (aInColor == 1) { |
---|
1816 | printer.setColorMode(QPrinter::GrayScale); |
---|
1817 | } else { |
---|
1818 | printer.setColorMode(QPrinter::Color); |
---|
1819 | } |
---|
1820 | |
---|
1821 | /* FIXME : I don't know which format it will save... |
---|
1822 | if (aFilename.endsWith(".ps")) { |
---|
1823 | printer.setOutputFormat(QPrinter::PostScriptFormat); |
---|
1824 | } else { |
---|
1825 | printer.setOutputFormat(QPrinter::PdfFormat); |
---|
1826 | } |
---|
1827 | */ |
---|
1828 | printer.setOutputFileName(aFilename); |
---|
1829 | // printer.setFullPage ( true); |
---|
1830 | QPainter paint(&printer); |
---|
1831 | paint.drawImage (0,0,aImage ); |
---|
1832 | paint.end(); |
---|
1833 | #else |
---|
1834 | G4cerr << "This fonction is only supported on Mac OsX or X11 with Qt3. Full platform supported with Qt4\n" << G4endl; |
---|
1835 | #endif |
---|
1836 | #else |
---|
1837 | QPrinter printer; |
---|
1838 | // printer.setPageSize(pageSize); |
---|
1839 | |
---|
1840 | // FIXME : L. Garnier 4/12/07 |
---|
1841 | // This is not working, it does nothing. Image is staying in color mode |
---|
1842 | // So I have desactivate the B/W button in GUI |
---|
1843 | if ((!aImage.isGrayscale ()) &&(aInColor ==1 )) { |
---|
1844 | #if QT_VERSION < 0x040000 |
---|
1845 | aImage = aImage.convertDepth(1,Qt::MonoOnly); |
---|
1846 | #else |
---|
1847 | aImage = aImage.convertToFormat ( aImage.format(), Qt::MonoOnly); |
---|
1848 | #endif |
---|
1849 | } |
---|
1850 | |
---|
1851 | |
---|
1852 | if (aFilename.endsWith(".ps")) { |
---|
1853 | #if QT_VERSION > 0x040200 |
---|
1854 | printer.setOutputFormat(QPrinter::PostScriptFormat); |
---|
1855 | #endif |
---|
1856 | } else { |
---|
1857 | #if QT_VERSION > 0x040100 |
---|
1858 | printer.setOutputFormat(QPrinter::PdfFormat); |
---|
1859 | #endif |
---|
1860 | } |
---|
1861 | #if QT_VERSION > 0x040100 |
---|
1862 | printer.setOutputFileName(aFilename); |
---|
1863 | #endif |
---|
1864 | // printer.setFullPage ( true); |
---|
1865 | QPainter paint(&printer); |
---|
1866 | paint.drawImage (0,0,aImage); |
---|
1867 | paint.end(); |
---|
1868 | #endif |
---|
1869 | return true; |
---|
1870 | } |
---|
1871 | |
---|
1872 | |
---|
1873 | |
---|
1874 | void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * event) |
---|
1875 | { |
---|
1876 | if (holdKeyEvent) |
---|
1877 | return; |
---|
1878 | |
---|
1879 | holdKeyEvent = true; |
---|
1880 | |
---|
1881 | #if QT_VERSION < 0x040000 |
---|
1882 | if ((event->key() == Qt::Key_Down) && (event->state() & Qt::AltButton )) { // go backward |
---|
1883 | #else |
---|
1884 | if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::AltModifier )) { // go backward |
---|
1885 | #endif |
---|
1886 | |
---|
1887 | moveScene(0,0,1,false); |
---|
1888 | } |
---|
1889 | #if QT_VERSION < 0x040000 |
---|
1890 | else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::AltButton)) { // go forward |
---|
1891 | #else |
---|
1892 | else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::AltModifier)) { // go forward |
---|
1893 | #endif |
---|
1894 | moveScene(0,0,-1,false); |
---|
1895 | } |
---|
1896 | #if QT_VERSION < 0x040000 |
---|
1897 | if ((event->key() == Qt::Key_Down) && (event->state() & Qt::ShiftButton)) { // rotate phi |
---|
1898 | #else |
---|
1899 | if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi |
---|
1900 | #endif |
---|
1901 | rotateScene(0,-1); |
---|
1902 | } |
---|
1903 | #if QT_VERSION < 0x040000 |
---|
1904 | else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::ShiftButton)) { // rotate phi |
---|
1905 | #else |
---|
1906 | else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi |
---|
1907 | #endif |
---|
1908 | rotateScene(0,1); |
---|
1909 | } |
---|
1910 | #if QT_VERSION < 0x040000 |
---|
1911 | if ((event->key() == Qt::Key_Left) && (event->state() & Qt::ShiftButton)) { // rotate theta |
---|
1912 | #else |
---|
1913 | if ((event->key() == Qt::Key_Left) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta |
---|
1914 | #endif |
---|
1915 | rotateScene(1,0); |
---|
1916 | } |
---|
1917 | #if QT_VERSION < 0x040000 |
---|
1918 | else if ((event->key() == Qt::Key_Right) && (event->state() & Qt::ShiftButton)) { // rotate theta |
---|
1919 | #else |
---|
1920 | else if ((event->key() == Qt::Key_Right) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta |
---|
1921 | #endif |
---|
1922 | rotateScene(-1,0); |
---|
1923 | } |
---|
1924 | if (event->key() == Qt::Key_Escape) { // escaped from full screen |
---|
1925 | #if QT_VERSION >= 0x030200 |
---|
1926 | if (GLWindow->isFullScreen()) { |
---|
1927 | #if QT_VERSION < 0x040000 |
---|
1928 | fFullScreenOn->activated(); |
---|
1929 | #else |
---|
1930 | fFullScreenOn->trigger(); |
---|
1931 | #endif |
---|
1932 | } |
---|
1933 | #endif |
---|
1934 | } |
---|
1935 | if (event->key() == Qt::Key_Plus) { // zoom in |
---|
1936 | fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+fDeltaZoom)); |
---|
1937 | updateQWidget(); |
---|
1938 | } |
---|
1939 | else if (event->key() == Qt::Key_Minus) { // zoom out |
---|
1940 | fVP.SetZoomFactor(fVP.GetZoomFactor()*(1-fDeltaZoom)); |
---|
1941 | updateQWidget(); |
---|
1942 | } |
---|
1943 | // with no modifiers |
---|
1944 | #if QT_VERSION < 0x040000 |
---|
1945 | if (event->state() == Qt::NoButton) { |
---|
1946 | #else |
---|
1947 | if (event->modifiers() == Qt::NoModifier) { |
---|
1948 | #endif |
---|
1949 | if (event->key() == Qt::Key_Down) { // go down |
---|
1950 | moveScene(0,-1,0,false); |
---|
1951 | } |
---|
1952 | else if (event->key() == Qt::Key_Up) { // go up |
---|
1953 | moveScene(0,1,0,false); |
---|
1954 | } |
---|
1955 | if (event->key() == Qt::Key_Left) { // go left |
---|
1956 | moveScene(-1,0,0,false); |
---|
1957 | } |
---|
1958 | else if (event->key() == Qt::Key_Right) { // go right |
---|
1959 | moveScene(1,0,0,false); |
---|
1960 | } |
---|
1961 | } |
---|
1962 | holdKeyEvent = false; |
---|
1963 | } |
---|
1964 | |
---|
1965 | |
---|
1966 | bool G4OpenGLQtViewer::hasPendingEvents () { |
---|
1967 | return ((QApplication*)G4Qt::getInstance ())->hasPendingEvents (); |
---|
1968 | } |
---|
1969 | |
---|
1970 | |
---|
1971 | /* |
---|
1972 | |
---|
1973 | void MultiLayer::exportToSVG(const QString& fname) |
---|
1974 | { |
---|
1975 | QPicture picture; |
---|
1976 | QPainter p(&picture); |
---|
1977 | for (int i=0;i<(int)graphsList->count();i++) |
---|
1978 | { |
---|
1979 | Graph *gr=(Graph *)graphsList->at(i); |
---|
1980 | Plot *myPlot= (Plot *)gr->plotWidget(); |
---|
1981 | |
---|
1982 | QPoint pos=gr->pos(); |
---|
1983 | |
---|
1984 | int width=int(myPlot->frameGeometry().width()); |
---|
1985 | int height=int(myPlot->frameGeometry().height()); |
---|
1986 | |
---|
1987 | myPlot->print(&p, QRect(pos,QSize(width,height))); |
---|
1988 | } |
---|
1989 | |
---|
1990 | p.end(); |
---|
1991 | picture.save(fname, "svg"); |
---|
1992 | } |
---|
1993 | */ |
---|
1994 | #endif |
---|