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 "G4OpenGLQtMovieDialog.hh" |
---|
51 | #include "G4UnitsTable.hh" |
---|
52 | #include "G4Qt.hh" |
---|
53 | #include "G4UImanager.hh" |
---|
54 | #include "G4UIcommandTree.hh" |
---|
55 | #include <qapplication.h> |
---|
56 | #include <qlayout.h> |
---|
57 | #include <qdialog.h> |
---|
58 | #include <qprocess.h> |
---|
59 | |
---|
60 | #if QT_VERSION >= 0x040000 |
---|
61 | #include <qmenu.h> |
---|
62 | #include <qimagewriter.h> |
---|
63 | #else |
---|
64 | #include <qaction.h> |
---|
65 | #include <qwidgetlist.h> |
---|
66 | #include <qpopupmenu.h> |
---|
67 | #include <qimage.h> |
---|
68 | #endif |
---|
69 | |
---|
70 | #include <qapplication.h> |
---|
71 | #include <qmessagebox.h> |
---|
72 | #include <qfiledialog.h> |
---|
73 | #include <qprinter.h> |
---|
74 | #include <qpainter.h> |
---|
75 | #include <qgl.h> // include <qglwidget.h> |
---|
76 | #include <qdialog.h> |
---|
77 | #include <qevent.h> //include <qcontextmenuevent.h> |
---|
78 | |
---|
79 | |
---|
80 | ////////////////////////////////////////////////////////////////////////////// |
---|
81 | /** |
---|
82 | Implementation of virtual method of G4VViewer |
---|
83 | */ |
---|
84 | void G4OpenGLQtViewer::SetView ( |
---|
85 | ) |
---|
86 | ////////////////////////////////////////////////////////////////////////////// |
---|
87 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
88 | { |
---|
89 | #ifdef GEANT4_QT_DEBUG |
---|
90 | printf("G4OpenGLQtViewer::SetView ++++++++++++++++++++\n"); |
---|
91 | #endif |
---|
92 | // if(!fHDC) return; |
---|
93 | // if(!fHGLRC) return; |
---|
94 | // ::wglMakeCurrent(fHDC,fHGLRC); |
---|
95 | // fWindow->makeCurrent(); |
---|
96 | G4OpenGLViewer::SetView (); |
---|
97 | #ifdef GEANT4_QT_DEBUG |
---|
98 | printf("G4OpenGLQtViewer::SetView --------------------\n"); |
---|
99 | #endif |
---|
100 | } |
---|
101 | |
---|
102 | /** |
---|
103 | * Set the viewport of the scene |
---|
104 | */ |
---|
105 | void G4OpenGLQtViewer::setupViewport(int aWidth, int aHeight) |
---|
106 | { |
---|
107 | int side = aWidth; |
---|
108 | if (aHeight < aWidth) side = aHeight; |
---|
109 | glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side); |
---|
110 | |
---|
111 | glMatrixMode(GL_PROJECTION); |
---|
112 | glLoadIdentity(); |
---|
113 | glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0); |
---|
114 | glMatrixMode(GL_MODELVIEW); |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | ////////////////////////////////////////////////////////////////////////////// |
---|
119 | /** |
---|
120 | Implementation of virtual method of G4VViewer |
---|
121 | */ |
---|
122 | void G4OpenGLQtViewer::ShowView ( |
---|
123 | ) |
---|
124 | ////////////////////////////////////////////////////////////////////////////// |
---|
125 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
126 | { |
---|
127 | #ifdef GEANT4_QT_DEBUG |
---|
128 | printf("G4OpenGLQtViewer::ShowView +++++++++++++++++++++\n"); |
---|
129 | #endif |
---|
130 | if (!GLWindow) { |
---|
131 | G4cerr << "Visualization window not defined, please choose one before\n" << G4endl; |
---|
132 | } else { |
---|
133 | #if QT_VERSION < 0x040000 |
---|
134 | GLWindow->setActiveWindow(); |
---|
135 | #else |
---|
136 | GLWindow->activateWindow(); |
---|
137 | #endif |
---|
138 | #ifdef GEANT4_QT_DEBUG |
---|
139 | printf("G4OpenGLQtViewer::ShowView -----------------------\n"); |
---|
140 | #endif |
---|
141 | } |
---|
142 | glFlush (); |
---|
143 | // // Empty the Windows message queue : |
---|
144 | // MSG event; |
---|
145 | // while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) { |
---|
146 | // ::TranslateMessage(&event); |
---|
147 | // ::DispatchMessage (&event); |
---|
148 | // } |
---|
149 | } |
---|
150 | |
---|
151 | |
---|
152 | |
---|
153 | ////////////////////////////////////////////////////////////////////////////// |
---|
154 | void G4OpenGLQtViewer::CreateGLQtContext ( |
---|
155 | ) |
---|
156 | ////////////////////////////////////////////////////////////////////////////// |
---|
157 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
158 | { |
---|
159 | #ifdef GEANT4_QT_DEBUG |
---|
160 | printf("G4OpenGLQtViewer::CreateGLQtContext \n"); |
---|
161 | #endif |
---|
162 | } |
---|
163 | |
---|
164 | |
---|
165 | ////////////////////////////////////////////////////////////////////////////// |
---|
166 | void G4OpenGLQtViewer::CreateMainWindow ( |
---|
167 | QGLWidget* glWidget |
---|
168 | ) |
---|
169 | ////////////////////////////////////////////////////////////////////////////// |
---|
170 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
171 | { |
---|
172 | |
---|
173 | if(fWindow) return; //Done. |
---|
174 | #ifdef GEANT4_QT_DEBUG |
---|
175 | printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n"); |
---|
176 | #endif |
---|
177 | |
---|
178 | // launch Qt if not |
---|
179 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
180 | // G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
181 | |
---|
182 | fWindow = glWidget ; |
---|
183 | // fWindow->makeCurrent(); |
---|
184 | |
---|
185 | // create window |
---|
186 | if (((QApplication*)interactorManager->GetMainInteractor())) { |
---|
187 | // look for the main window |
---|
188 | bool found = false; |
---|
189 | #if QT_VERSION < 0x040000 |
---|
190 | // theses lines does nothing exept this one "GLWindow = new QDialog(0..." |
---|
191 | // but if I comment them, it doesn't work... |
---|
192 | QWidgetList *list = QApplication::allWidgets(); |
---|
193 | QWidgetListIt it( *list ); // iterate over the widgets |
---|
194 | QWidget * widget; |
---|
195 | while ( (widget=it.current()) != 0 ) { // for each widget... |
---|
196 | ++it; |
---|
197 | if ((found== false) && (widget->inherits("QMainWindow"))) { |
---|
198 | GLWindow = new QDialog(0,0,FALSE,Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_MinMax ); |
---|
199 | found = true; |
---|
200 | } |
---|
201 | } |
---|
202 | delete list; // delete the list, not the widgets |
---|
203 | #else |
---|
204 | foreach (QWidget *widget, QApplication::allWidgets()) { |
---|
205 | if ((found== false) && (widget->inherits("QMainWindow"))) { |
---|
206 | GLWindow = new QDialog(0,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint); |
---|
207 | found = true; |
---|
208 | } |
---|
209 | } |
---|
210 | #endif |
---|
211 | |
---|
212 | #if QT_VERSION < 0x040000 |
---|
213 | glWidget->reparent(GLWindow,0,QPoint(0,0)); |
---|
214 | #else |
---|
215 | glWidget->setParent(GLWindow); |
---|
216 | #endif |
---|
217 | |
---|
218 | if (found==false) { |
---|
219 | #ifdef GEANT4_QT_DEBUG |
---|
220 | printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n"); |
---|
221 | #endif |
---|
222 | GLWindow = new QDialog(); |
---|
223 | } |
---|
224 | } else { |
---|
225 | #ifdef GEANT4_QT_DEBUG |
---|
226 | printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n"); |
---|
227 | #endif |
---|
228 | GLWindow = new QDialog(); |
---|
229 | } |
---|
230 | |
---|
231 | QHBoxLayout *mainLayout = new QHBoxLayout(GLWindow); |
---|
232 | |
---|
233 | mainLayout->addWidget(fWindow); |
---|
234 | |
---|
235 | #if QT_VERSION < 0x040000 |
---|
236 | GLWindow->setCaption( tr( "QGl Viewer" )); |
---|
237 | #else |
---|
238 | GLWindow->setLayout(mainLayout); |
---|
239 | GLWindow->setWindowTitle(tr("QGl Viewer")); |
---|
240 | #endif |
---|
241 | GLWindow->resize(300, 300); |
---|
242 | GLWindow->move(900,300); |
---|
243 | GLWindow->show(); |
---|
244 | |
---|
245 | // delete the pointer if close this |
---|
246 | // GLWindow->setAttribute(Qt::WA_DeleteOnClose); |
---|
247 | |
---|
248 | #if QT_VERSION >= 0x040000 |
---|
249 | // QObject ::connect(GLWindow, |
---|
250 | // SIGNAL(rejected()), |
---|
251 | // this, |
---|
252 | // SLOT(dialogClosed())); |
---|
253 | #endif |
---|
254 | |
---|
255 | WinSize_x = 400; |
---|
256 | WinSize_y = 400; |
---|
257 | if (WinSize_x < fVP.GetWindowSizeHintX ()) |
---|
258 | WinSize_x = fVP.GetWindowSizeHintX (); |
---|
259 | if (WinSize_y < fVP.GetWindowSizeHintY ()) |
---|
260 | WinSize_y = fVP.GetWindowSizeHintY (); |
---|
261 | |
---|
262 | if(!fWindow) return; |
---|
263 | #ifdef GEANT4_QT_DEBUG |
---|
264 | printf("G4OpenGLQtViewer::CreateMainWindow glWidget END\n"); |
---|
265 | #endif |
---|
266 | |
---|
267 | if (!fContextMenu) |
---|
268 | createPopupMenu(); |
---|
269 | |
---|
270 | } |
---|
271 | |
---|
272 | #if QT_VERSION >= 0x040000 |
---|
273 | /** Close the dialog and set the pointer to NULL |
---|
274 | */ |
---|
275 | // void G4OpenGLQtViewer::dialogClosed() { |
---|
276 | // #ifdef GEANT4_QT_DEBUG |
---|
277 | // printf("G4OpenGLQtViewer::dialogClosed END\n"); |
---|
278 | // #endif |
---|
279 | // // GLWindow = NULL; |
---|
280 | // } |
---|
281 | #endif |
---|
282 | |
---|
283 | ////////////////////////////////////////////////////////////////////////////// |
---|
284 | G4OpenGLQtViewer::G4OpenGLQtViewer ( |
---|
285 | G4OpenGLSceneHandler& scene |
---|
286 | ) |
---|
287 | :G4VViewer (scene, -1) |
---|
288 | ,G4OpenGLViewer (scene) |
---|
289 | ,fWindow(0) |
---|
290 | ,fRecordFrames(false) |
---|
291 | ,fRecordFrameNumber(0) |
---|
292 | ,fContextMenu(0) |
---|
293 | ,fMouseAction(STYLE1) |
---|
294 | ,fDeltaRotation(1) |
---|
295 | ,fDeltaSceneTranslation(0.01) |
---|
296 | ,fDeltaDepth(0.01) |
---|
297 | ,fDeltaZoom(0.1) |
---|
298 | ,fDeltaMove(0.05) |
---|
299 | ,fHoldKeyEvent(false) |
---|
300 | ,fHoldMoveEvent(false) |
---|
301 | ,fHoldRotateEvent(false) |
---|
302 | ,fAutoMove(false) |
---|
303 | ,fMovieParametersDialog(NULL) |
---|
304 | { |
---|
305 | initMovieParameters(); |
---|
306 | createTempFolder(); |
---|
307 | removeTempFolder(); |
---|
308 | |
---|
309 | #ifdef GEANT4_QT_DEBUG |
---|
310 | printf("G4OpenGLQtViewer::G4OpenGLQtViewer \n"); |
---|
311 | #endif |
---|
312 | } |
---|
313 | |
---|
314 | ////////////////////////////////////////////////////////////////////////////// |
---|
315 | G4OpenGLQtViewer::~G4OpenGLQtViewer ( |
---|
316 | ) |
---|
317 | ////////////////////////////////////////////////////////////////////////////// |
---|
318 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
319 | { |
---|
320 | #ifdef GEANT4_QT_DEBUG |
---|
321 | printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n"); |
---|
322 | #endif |
---|
323 | } |
---|
324 | |
---|
325 | |
---|
326 | /** |
---|
327 | Create a popup menu for the widget. This menu is activated by right-mouse click |
---|
328 | */ |
---|
329 | void G4OpenGLQtViewer::createPopupMenu() { |
---|
330 | |
---|
331 | #if QT_VERSION < 0x040000 |
---|
332 | fContextMenu = new QPopupMenu( GLWindow,"All" ); |
---|
333 | #else |
---|
334 | fContextMenu = new QMenu("All"); |
---|
335 | #endif |
---|
336 | |
---|
337 | #if QT_VERSION < 0x040000 |
---|
338 | QPopupMenu *mMouseAction = new QPopupMenu( fContextMenu ); |
---|
339 | fContextMenu->insertItem("&Mouse actions",mMouseAction); |
---|
340 | #if QT_VERSION < 0x030200 |
---|
341 | fRotateAction = new QAction("&Rotate","&Rotate",CTRL+Key_R,mMouseAction,0,true); |
---|
342 | fMoveAction = new QAction("&Move","&Move",CTRL+Key_M,mMouseAction,0,true); |
---|
343 | fPickAction = new QAction("&Pick","&Pick",CTRL+Key_P,mMouseAction,0,true); |
---|
344 | QAction * shortcutsAction = new QAction("&Show shortcuts","&Show shortcuts",CTRL+Key_S,mMouseAction,0,true); |
---|
345 | #else |
---|
346 | fRotateAction = new QAction("&Rotate",CTRL+Key_R,mMouseAction); |
---|
347 | fMoveAction = new QAction("&Move",CTRL+Key_M,mMouseAction); |
---|
348 | fPickAction = new QAction("&Pick",CTRL+Key_P,mMouseAction); |
---|
349 | QAction *shortcutsAction = new QAction("&Show shortcuts",CTRL+Key_S,mMouseAction); |
---|
350 | #endif |
---|
351 | fRotateAction->addTo(mMouseAction); |
---|
352 | fMoveAction->addTo(mMouseAction); |
---|
353 | fPickAction->addTo(mMouseAction); |
---|
354 | shortcutsAction->addTo(mMouseAction); |
---|
355 | |
---|
356 | fRotateAction->setToggleAction(true); |
---|
357 | fMoveAction->setToggleAction(true); |
---|
358 | fPickAction->setToggleAction(true); |
---|
359 | shortcutsAction->setToggleAction(true); |
---|
360 | |
---|
361 | fRotateAction->setOn(true); |
---|
362 | fMoveAction->setOn(false); |
---|
363 | fPickAction->setOn(false); |
---|
364 | shortcutsAction->setOn(false); |
---|
365 | |
---|
366 | |
---|
367 | QObject ::connect(fRotateAction, |
---|
368 | SIGNAL(activated()), |
---|
369 | this, |
---|
370 | SLOT(actionMouseRotate())); |
---|
371 | |
---|
372 | QObject ::connect(fMoveAction, |
---|
373 | SIGNAL(activated()), |
---|
374 | this, |
---|
375 | SLOT(actionMouseMove())); |
---|
376 | |
---|
377 | QObject ::connect(fPickAction, |
---|
378 | SIGNAL(activated()), |
---|
379 | this, |
---|
380 | SLOT(actionMousePick())); |
---|
381 | |
---|
382 | QObject ::connect(shortcutsAction, |
---|
383 | SIGNAL(activated()), |
---|
384 | this, |
---|
385 | SLOT(showShortcuts())); |
---|
386 | |
---|
387 | #else |
---|
388 | QMenu *mMouseAction = fContextMenu->addMenu("&Mouse actions"); |
---|
389 | |
---|
390 | fRotateAction = mMouseAction->addAction("Rotate"); |
---|
391 | fMoveAction = mMouseAction->addAction("Move"); |
---|
392 | fPickAction = mMouseAction->addAction("Pick"); |
---|
393 | QAction *shortcutsAction = mMouseAction->addAction("Show shortcuts"); |
---|
394 | |
---|
395 | fRotateAction->setCheckable(true); |
---|
396 | fMoveAction->setCheckable(false); |
---|
397 | fPickAction->setCheckable(false); |
---|
398 | shortcutsAction->setCheckable(false); |
---|
399 | |
---|
400 | fRotateAction->setChecked(true); |
---|
401 | fMoveAction->setChecked(false); |
---|
402 | fPickAction->setChecked(false); |
---|
403 | shortcutsAction->setChecked(false); |
---|
404 | |
---|
405 | QObject ::connect(fRotateAction, |
---|
406 | SIGNAL(triggered(bool)), |
---|
407 | this, |
---|
408 | SLOT(actionMouseRotate())); |
---|
409 | |
---|
410 | QObject ::connect(fMoveAction, |
---|
411 | SIGNAL(triggered(bool)), |
---|
412 | this, |
---|
413 | SLOT(actionMouseMove())); |
---|
414 | |
---|
415 | QObject ::connect(fPickAction, |
---|
416 | SIGNAL(triggered(bool)), |
---|
417 | this, |
---|
418 | SLOT(actionMousePick())); |
---|
419 | |
---|
420 | QObject ::connect(shortcutsAction, |
---|
421 | SIGNAL(triggered(bool)), |
---|
422 | this, |
---|
423 | SLOT(showShortcuts())); |
---|
424 | #endif |
---|
425 | |
---|
426 | #if QT_VERSION < 0x040000 |
---|
427 | // === Style Menu === |
---|
428 | QPopupMenu *mStyle = new QPopupMenu(fContextMenu); |
---|
429 | |
---|
430 | QPopupMenu *mRepresentation = new QPopupMenu(fContextMenu); |
---|
431 | |
---|
432 | QPopupMenu *mProjection = new QPopupMenu(fContextMenu); |
---|
433 | |
---|
434 | #if QT_VERSION < 0x030200 |
---|
435 | QAction *polyhedron = new QAction("&Polyhedron","&Polyhedron",CTRL+Key_P,mRepresentation,0,true); |
---|
436 | QAction *nurbs = new QAction("&NURBS","&NURBS",CTRL+Key_N,mRepresentation,0,true); |
---|
437 | |
---|
438 | QAction *ortho = new QAction("&Orthographic","&Orthographic",CTRL+Key_O,mProjection,0,true); |
---|
439 | QAction *perspective = new QAction("&Perspective","&Perspective",CTRL+Key_P,mProjection,0,true); |
---|
440 | #else |
---|
441 | QAction *polyhedron = new QAction("&Polyhedron",CTRL+Key_P,mRepresentation); |
---|
442 | QAction *nurbs = new QAction("&NURBS",CTRL+Key_N,mRepresentation); |
---|
443 | |
---|
444 | QAction *ortho = new QAction("&Orthographic",CTRL+Key_O,mProjection); |
---|
445 | QAction *perspective = new QAction("&Perspective",CTRL+Key_P,mProjection); |
---|
446 | polyhedron->setToggleAction(true); |
---|
447 | nurbs->setToggleAction(true); |
---|
448 | ortho->setToggleAction(true); |
---|
449 | perspective->setToggleAction(true); |
---|
450 | #endif |
---|
451 | polyhedron->addTo(mRepresentation); |
---|
452 | nurbs->addTo(mRepresentation); |
---|
453 | |
---|
454 | ortho->addTo(mProjection); |
---|
455 | perspective->addTo(mProjection); |
---|
456 | |
---|
457 | mStyle->insertItem("&Representation",mRepresentation); |
---|
458 | mStyle->insertItem("&Projection",mProjection); |
---|
459 | fContextMenu->insertItem("&Style",mStyle); |
---|
460 | |
---|
461 | |
---|
462 | #else |
---|
463 | // === Style Menu === |
---|
464 | QMenu *mStyle = fContextMenu->addMenu("&Style"); |
---|
465 | |
---|
466 | QMenu *mRepresentation = mStyle->addMenu("&Representation"); |
---|
467 | QMenu *mProjection = mStyle->addMenu("&Projection"); |
---|
468 | QAction *polyhedron = mRepresentation->addAction("Polyhedron"); |
---|
469 | QAction *nurbs = mRepresentation->addAction("NURBS"); |
---|
470 | |
---|
471 | QAction *ortho = mProjection->addAction("Orthographic"); |
---|
472 | QAction *perspective = mProjection->addAction("Persepective"); |
---|
473 | #endif |
---|
474 | |
---|
475 | // INIT mRepresentation |
---|
476 | G4ViewParameters::RepStyle style; |
---|
477 | style = fVP.GetRepStyle(); |
---|
478 | if (style == G4ViewParameters::polyhedron) { |
---|
479 | createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),1); |
---|
480 | } else if (style == G4ViewParameters::nurbs) { |
---|
481 | createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),2); |
---|
482 | } else { |
---|
483 | mRepresentation->clear(); |
---|
484 | } |
---|
485 | |
---|
486 | // INIT mProjection |
---|
487 | if (fVP.GetFieldHalfAngle() == 0) { |
---|
488 | createRadioAction(ortho, perspective,SLOT(toggleProjection(bool)),1); |
---|
489 | } else { |
---|
490 | createRadioAction(ortho, perspective,SLOT(toggleProjection(bool)),2); |
---|
491 | } |
---|
492 | |
---|
493 | #if QT_VERSION < 0x040000 |
---|
494 | // === Drawing Menu === |
---|
495 | QPopupMenu *mDrawing = new QPopupMenu(fContextMenu); |
---|
496 | fContextMenu->insertItem("&Drawing",mDrawing); |
---|
497 | |
---|
498 | #if QT_VERSION < 0x030200 |
---|
499 | fDrawingWireframe = new QAction("&Wireframe","&Wireframe",CTRL+Key_W,mDrawing,0,true); |
---|
500 | fDrawingLineRemoval = new QAction("&Hidden line removal","&Hidden line removal",CTRL+Key_L,mDrawing,0,true); |
---|
501 | fDrawingSurfaceRemoval = new QAction("&Hidden surface removal","&Hidden surface removal",CTRL+Key_S,mDrawing,0,true); |
---|
502 | fDrawingLineSurfaceRemoval = new QAction("&Hidden line and surface removal","&Hidden line and surface removal",CTRL+Key_R,mDrawing,0,true); |
---|
503 | #else |
---|
504 | fDrawingWireframe = new QAction("&Wireframe",CTRL+Key_W,mDrawing); |
---|
505 | fDrawingLineRemoval = new QAction("&Hidden line removal",CTRL+Key_L,mDrawing); |
---|
506 | fDrawingSurfaceRemoval = new QAction("&Hidden surface removal",CTRL+Key_S,mDrawing); |
---|
507 | fDrawingLineSurfaceRemoval = new QAction("&Hidden line and surface removal",CTRL+Key_R,mDrawing); |
---|
508 | #endif |
---|
509 | fDrawingWireframe->setToggleAction(true); |
---|
510 | fDrawingLineRemoval->setToggleAction(true); |
---|
511 | fDrawingSurfaceRemoval->setToggleAction(true); |
---|
512 | fDrawingLineSurfaceRemoval->setToggleAction(true); |
---|
513 | |
---|
514 | fDrawingWireframe->addTo(mDrawing); |
---|
515 | fDrawingLineRemoval->addTo(mDrawing); |
---|
516 | fDrawingSurfaceRemoval->addTo(mDrawing); |
---|
517 | fDrawingLineSurfaceRemoval->addTo(mDrawing); |
---|
518 | |
---|
519 | |
---|
520 | #else |
---|
521 | // === Drawing Menu === |
---|
522 | QMenu *mDrawing = mStyle->addMenu("&Drawing"); |
---|
523 | |
---|
524 | fDrawingWireframe = mDrawing->addAction("Wireframe"); |
---|
525 | fDrawingWireframe->setCheckable(true); |
---|
526 | |
---|
527 | fDrawingLineRemoval = mDrawing->addAction("Hidden line removal"); |
---|
528 | fDrawingLineRemoval->setCheckable(true); |
---|
529 | |
---|
530 | fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal"); |
---|
531 | fDrawingSurfaceRemoval->setCheckable(true); |
---|
532 | |
---|
533 | fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal"); |
---|
534 | fDrawingLineSurfaceRemoval->setCheckable(true); |
---|
535 | #endif |
---|
536 | // INIT Drawing |
---|
537 | G4ViewParameters::DrawingStyle d_style; |
---|
538 | d_style = fVP.GetDrawingStyle(); |
---|
539 | |
---|
540 | #if QT_VERSION < 0x040000 |
---|
541 | if (d_style == G4ViewParameters::wireframe) { |
---|
542 | fDrawingWireframe->setOn(true); |
---|
543 | } else if (d_style == G4ViewParameters::hlr) { |
---|
544 | fDrawingLineRemoval->setOn(true); |
---|
545 | } else if (d_style == G4ViewParameters::hsr) { |
---|
546 | fDrawingSurfaceRemoval->setOn(true); |
---|
547 | } else if (d_style == G4ViewParameters::hlhsr) { |
---|
548 | fDrawingLineSurfaceRemoval->setOn(true); |
---|
549 | } else { |
---|
550 | mDrawing->clear(); |
---|
551 | } |
---|
552 | #ifdef GEANT4_QT_DEBUG |
---|
553 | printf("G4OpenGLQtViewer:: fDrawingWireframe 1\n"); |
---|
554 | #endif |
---|
555 | QObject ::connect(fDrawingWireframe, |
---|
556 | SIGNAL(activated()), |
---|
557 | this, |
---|
558 | SLOT(actionDrawingWireframe())); |
---|
559 | #ifdef GEANT4_QT_DEBUG |
---|
560 | printf("G4OpenGLQtViewer:: fDrawingWireframe 2\n"); |
---|
561 | #endif |
---|
562 | QObject ::connect(fDrawingLineRemoval, |
---|
563 | SIGNAL(activated()), |
---|
564 | this, |
---|
565 | SLOT(actionDrawingLineRemoval())); |
---|
566 | QObject ::connect(fDrawingSurfaceRemoval, |
---|
567 | SIGNAL(activated()), |
---|
568 | this, |
---|
569 | SLOT(actionDrawingSurfaceRemoval())); |
---|
570 | QObject ::connect(fDrawingLineSurfaceRemoval, |
---|
571 | SIGNAL(activated()), |
---|
572 | this, |
---|
573 | SLOT(actionDrawingLineSurfaceRemoval())); |
---|
574 | #else |
---|
575 | if (d_style == G4ViewParameters::wireframe) { |
---|
576 | fDrawingWireframe->setChecked(true); |
---|
577 | } else if (d_style == G4ViewParameters::hlr) { |
---|
578 | fDrawingLineRemoval->setChecked(true); |
---|
579 | } else if (d_style == G4ViewParameters::hsr) { |
---|
580 | fDrawingSurfaceRemoval->setChecked(true); |
---|
581 | } else if (d_style == G4ViewParameters::hlhsr) { |
---|
582 | fDrawingLineSurfaceRemoval->setChecked(true); |
---|
583 | } else { |
---|
584 | mDrawing->clear(); |
---|
585 | } |
---|
586 | QObject ::connect(fDrawingWireframe, |
---|
587 | SIGNAL(triggered(bool)), |
---|
588 | this, |
---|
589 | SLOT(actionDrawingWireframe())); |
---|
590 | QObject ::connect(fDrawingLineRemoval, |
---|
591 | SIGNAL(triggered(bool)), |
---|
592 | this, |
---|
593 | SLOT(actionDrawingLineRemoval())); |
---|
594 | QObject ::connect(fDrawingSurfaceRemoval, |
---|
595 | SIGNAL(triggered(bool)), |
---|
596 | this, |
---|
597 | SLOT(actionDrawingSurfaceRemoval())); |
---|
598 | QObject ::connect(fDrawingLineSurfaceRemoval, |
---|
599 | SIGNAL(triggered(bool)), |
---|
600 | this, |
---|
601 | SLOT(actionDrawingLineSurfaceRemoval())); |
---|
602 | #endif |
---|
603 | |
---|
604 | |
---|
605 | |
---|
606 | #if QT_VERSION < 0x040000 |
---|
607 | QPopupMenu *mBackground = new QPopupMenu(mStyle); |
---|
608 | mStyle->insertItem("&Background color",mBackground); |
---|
609 | |
---|
610 | #if QT_VERSION < 0x030200 |
---|
611 | QAction *white = new QAction("&White","&White",CTRL+Key_W,mBackground,0,true); |
---|
612 | QAction *black = new QAction("&Black","&Black",CTRL+Key_B,mBackground,0,true); |
---|
613 | #else |
---|
614 | QAction *white = new QAction("&White",CTRL+Key_W,mBackground); |
---|
615 | QAction *black = new QAction("&Black",CTRL+Key_B,mBackground); |
---|
616 | white->setToggleAction(true); |
---|
617 | black->setToggleAction(true); |
---|
618 | #endif |
---|
619 | white->addTo(mBackground); |
---|
620 | black->addTo(mBackground); |
---|
621 | |
---|
622 | #else |
---|
623 | QMenu *mBackground = mStyle->addMenu("&Background color"); |
---|
624 | QAction *white = mBackground->addAction("White"); |
---|
625 | QAction *black = mBackground->addAction("Black"); |
---|
626 | |
---|
627 | #endif |
---|
628 | if (background.GetRed() == 1. && |
---|
629 | background.GetGreen() == 1. && |
---|
630 | background.GetBlue() == 1.) { |
---|
631 | createRadioAction(white,black,SLOT(toggleBackground(bool)),1); |
---|
632 | } else { |
---|
633 | createRadioAction(white,black,SLOT(toggleBackground(bool)),2); |
---|
634 | } |
---|
635 | |
---|
636 | |
---|
637 | #if QT_VERSION < 0x040000 |
---|
638 | // === Action Menu === |
---|
639 | QPopupMenu *mActions = new QPopupMenu(fContextMenu); |
---|
640 | fContextMenu->insertItem("&Actions",mActions); |
---|
641 | |
---|
642 | #if QT_VERSION < 0x030200 |
---|
643 | QAction *createEPS = new QAction("&Save as ...","&Save as ...",CTRL+Key_S,mActions,0,true); |
---|
644 | #else |
---|
645 | QAction *createEPS = new QAction("&Save as ...",CTRL+Key_S,mActions); |
---|
646 | #endif |
---|
647 | createEPS->addTo(mActions); |
---|
648 | QObject ::connect(createEPS, |
---|
649 | SIGNAL(activated()), |
---|
650 | this, |
---|
651 | SLOT(actionSaveImage())); |
---|
652 | |
---|
653 | #else |
---|
654 | // === Action Menu === |
---|
655 | QMenu *mActions = fContextMenu->addMenu("&Actions"); |
---|
656 | QAction *createEPS = mActions->addAction("Save as ..."); |
---|
657 | QObject ::connect(createEPS, |
---|
658 | SIGNAL(triggered()), |
---|
659 | this, |
---|
660 | SLOT(actionSaveImage())); |
---|
661 | #endif |
---|
662 | |
---|
663 | #if QT_VERSION < 0x040000 |
---|
664 | #if QT_VERSION < 0x030200 |
---|
665 | QAction *movieParameters = new QAction("&Movie parameters...","&Make movie ...",CTRL+Key_M,mActions,0,true); |
---|
666 | #else |
---|
667 | QAction *movieParameters = new QAction("&Movie parameters...",CTRL+Key_M,mActions); |
---|
668 | #endif |
---|
669 | movieParameters->addTo(mActions); |
---|
670 | QObject ::connect(movieParameters, |
---|
671 | SIGNAL(activated()), |
---|
672 | this, |
---|
673 | SLOT(actionMovieParameters())); |
---|
674 | |
---|
675 | #else |
---|
676 | // === Action Menu === |
---|
677 | QAction *movieParameters = mActions->addAction("Movie parameters..."); |
---|
678 | QObject ::connect(movieParameters, |
---|
679 | SIGNAL(triggered()), |
---|
680 | this, |
---|
681 | SLOT(actionMovieParameters())); |
---|
682 | #endif |
---|
683 | |
---|
684 | |
---|
685 | |
---|
686 | |
---|
687 | #if QT_VERSION < 0x040000 |
---|
688 | // === Special Menu === |
---|
689 | QPopupMenu *mSpecial = new QPopupMenu(fContextMenu); |
---|
690 | fContextMenu->insertItem("S&pecial",mSpecial); |
---|
691 | |
---|
692 | QPopupMenu *mTransparency = new QPopupMenu(mSpecial); |
---|
693 | mSpecial->insertItem("Transparency",mTransparency); |
---|
694 | |
---|
695 | #if QT_VERSION < 0x030200 |
---|
696 | QAction *transparencyOn = new QAction("&On","&On",CTRL+Key_O,mTransparency,0,true); |
---|
697 | QAction *transparencyOff = new QAction("&Off","&Off",CTRL+Key_F,mTransparency,0,true); |
---|
698 | #else |
---|
699 | QAction *transparencyOn = new QAction("&On",CTRL+Key_O,mTransparency); |
---|
700 | QAction *transparencyOff = new QAction("&Off",CTRL+Key_F,mTransparency); |
---|
701 | transparencyOn->setToggleAction(true); |
---|
702 | transparencyOff->setToggleAction(true); |
---|
703 | #endif |
---|
704 | transparencyOn->addTo(mTransparency); |
---|
705 | transparencyOff->addTo(mTransparency); |
---|
706 | |
---|
707 | #else |
---|
708 | // === Special Menu === |
---|
709 | QMenu *mSpecial = fContextMenu->addMenu("S&pecial"); |
---|
710 | QMenu *mTransparency = mSpecial->addMenu("Transparency"); |
---|
711 | QAction *transparencyOn = mTransparency->addAction("On"); |
---|
712 | QAction *transparencyOff = mTransparency->addAction("Off"); |
---|
713 | #endif |
---|
714 | |
---|
715 | if (transparency_enabled == false) { |
---|
716 | createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2); |
---|
717 | } else if (transparency_enabled == true) { |
---|
718 | createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),1); |
---|
719 | } else { |
---|
720 | mSpecial->clear(); |
---|
721 | } |
---|
722 | |
---|
723 | |
---|
724 | #if QT_VERSION < 0x040000 |
---|
725 | QPopupMenu *mAntialiasing = new QPopupMenu(mSpecial); |
---|
726 | mSpecial->insertItem("Antialiasing",mAntialiasing); |
---|
727 | |
---|
728 | #if QT_VERSION < 0x030200 |
---|
729 | QAction *antialiasingOn = new QAction("&On","&On",CTRL+Key_O,mAntialiasing,0,true); |
---|
730 | QAction *antialiasingOff = new QAction("&Off","&Off",CTRL+Key_F,mAntialiasing,0,true); |
---|
731 | #else |
---|
732 | QAction *antialiasingOn = new QAction("&On",CTRL+Key_O,mAntialiasing); |
---|
733 | QAction *antialiasingOff = new QAction("&Off",CTRL+Key_F,mAntialiasing); |
---|
734 | antialiasingOn->setToggleAction(true); |
---|
735 | antialiasingOff->setToggleAction(true); |
---|
736 | #endif |
---|
737 | antialiasingOn->addTo(mAntialiasing); |
---|
738 | antialiasingOff->addTo(mAntialiasing); |
---|
739 | |
---|
740 | #else |
---|
741 | QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing"); |
---|
742 | QAction *antialiasingOn = mAntialiasing->addAction("On"); |
---|
743 | QAction *antialiasingOff = mAntialiasing->addAction("Off"); |
---|
744 | #endif |
---|
745 | |
---|
746 | if (antialiasing_enabled == false) { |
---|
747 | createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2); |
---|
748 | } else if (antialiasing_enabled == true) { |
---|
749 | createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),1); |
---|
750 | } else { |
---|
751 | mAntialiasing->clear(); |
---|
752 | } |
---|
753 | |
---|
754 | #if QT_VERSION < 0x040000 |
---|
755 | QPopupMenu *mHaloing = new QPopupMenu(mSpecial); |
---|
756 | mSpecial->insertItem("Haloing",mHaloing); |
---|
757 | |
---|
758 | #if QT_VERSION < 0x030200 |
---|
759 | QAction *haloingOn = new QAction("&On","&On",CTRL+Key_O,mHaloing,0,true); |
---|
760 | QAction *haloingOff = new QAction("&Off","&Off",CTRL+Key_F,mHaloing,0,true); |
---|
761 | #else |
---|
762 | QAction *haloingOn = new QAction("&On",CTRL+Key_O,mHaloing); |
---|
763 | QAction *haloingOff = new QAction("&Off",CTRL+Key_F,mHaloing); |
---|
764 | haloingOn->setToggleAction(true); |
---|
765 | haloingOff->setToggleAction(true); |
---|
766 | #endif |
---|
767 | haloingOn->addTo(mHaloing); |
---|
768 | haloingOff->addTo(mHaloing); |
---|
769 | #else |
---|
770 | QMenu *mHaloing = mSpecial->addMenu("Haloing"); |
---|
771 | QAction *haloingOn = mHaloing->addAction("On"); |
---|
772 | QAction *haloingOff = mHaloing->addAction("Off"); |
---|
773 | #endif |
---|
774 | if (haloing_enabled == false) { |
---|
775 | createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2); |
---|
776 | } else if (haloing_enabled == true) { |
---|
777 | createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),1); |
---|
778 | } else { |
---|
779 | mHaloing->clear(); |
---|
780 | } |
---|
781 | |
---|
782 | #if QT_VERSION < 0x040000 |
---|
783 | QPopupMenu *mAux = new QPopupMenu(mSpecial); |
---|
784 | mSpecial->insertItem("Auxiliairy edges",mAux); |
---|
785 | |
---|
786 | #if QT_VERSION < 0x030200 |
---|
787 | QAction *auxOn = new QAction("&On","&On",CTRL+Key_O,mAux,0,true); |
---|
788 | QAction *auxOff = new QAction("&Off","&Off",CTRL+Key_F,mAux,0,true); |
---|
789 | #else |
---|
790 | QAction *auxOn = new QAction("&On",CTRL+Key_O,mAux); |
---|
791 | QAction *auxOff = new QAction("&Off",CTRL+Key_F,mAux); |
---|
792 | auxOn->setToggleAction(true); |
---|
793 | auxOff->setToggleAction(true); |
---|
794 | #endif |
---|
795 | auxOn->addTo(mAux); |
---|
796 | auxOff->addTo(mAux); |
---|
797 | |
---|
798 | #else |
---|
799 | QMenu *mAux = mSpecial->addMenu("Auxiliary edges"); |
---|
800 | QAction *auxOn = mAux->addAction("On"); |
---|
801 | QAction *auxOff = mAux->addAction("Off"); |
---|
802 | #endif |
---|
803 | if (!fVP.IsAuxEdgeVisible()) { |
---|
804 | createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1); |
---|
805 | } else { |
---|
806 | createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),2); |
---|
807 | } |
---|
808 | |
---|
809 | |
---|
810 | |
---|
811 | #if QT_VERSION < 0x040000 |
---|
812 | QPopupMenu *mFullScreen = new QPopupMenu(mSpecial); |
---|
813 | mSpecial->insertItem("Full screen",mFullScreen); |
---|
814 | |
---|
815 | #if QT_VERSION < 0x030200 |
---|
816 | fFullScreenOn = new QAction("&On","&On",CTRL+Key_O,mFullScreen,0,true); |
---|
817 | fFullScreenOff = new QAction("&Off","&Off",CTRL+Key_F,mFullScreen,0,true); |
---|
818 | #else |
---|
819 | fFullScreenOn = new QAction("&On",CTRL+Key_O,mFullScreen); |
---|
820 | fFullScreenOff = new QAction("&Off",CTRL+Key_F,mFullScreen); |
---|
821 | fFullScreenOn->setToggleAction(true); |
---|
822 | fFullScreenOff->setToggleAction(true); |
---|
823 | #endif |
---|
824 | fFullScreenOn->addTo(mFullScreen); |
---|
825 | fFullScreenOff->addTo(mFullScreen); |
---|
826 | #else |
---|
827 | QMenu *mFullScreen = mSpecial->addMenu("&Full screen"); |
---|
828 | fFullScreenOn = mFullScreen->addAction("On"); |
---|
829 | fFullScreenOff = mFullScreen->addAction("Off"); |
---|
830 | #endif |
---|
831 | createRadioAction(fFullScreenOn,fFullScreenOff,SLOT(toggleFullScreen(bool)),2); |
---|
832 | |
---|
833 | } |
---|
834 | |
---|
835 | void G4OpenGLQtViewer::manageContextMenuEvent(QContextMenuEvent *e) |
---|
836 | { |
---|
837 | if (!GLWindow) { |
---|
838 | G4cerr << "Visualization window not defined, please choose one before\n" << G4endl; |
---|
839 | } else { |
---|
840 | |
---|
841 | if (!fContextMenu) |
---|
842 | createPopupMenu(); |
---|
843 | |
---|
844 | // launch menu |
---|
845 | if ( fContextMenu ) { |
---|
846 | fContextMenu->exec( e->globalPos() ); |
---|
847 | // delete fContextMenu; |
---|
848 | } |
---|
849 | } |
---|
850 | e->accept(); |
---|
851 | } |
---|
852 | |
---|
853 | |
---|
854 | /** |
---|
855 | Create a radio button menu. The two menu will be connected. When click on one, |
---|
856 | eatch state will be invert and callback method will be called. |
---|
857 | @param action1 first action to connect |
---|
858 | @param action2 second action to connect |
---|
859 | @param method callback method |
---|
860 | @param nCheck: 1 : first action will be set true. 2 : second action will be set true |
---|
861 | */ |
---|
862 | #if QT_VERSION < 0x040000 |
---|
863 | void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) { |
---|
864 | |
---|
865 | if (action1->parent()->inherits("QPopupMenu")){ |
---|
866 | ((QPopupMenu*)action1->parent())->setCheckable(true); |
---|
867 | ((QPopupMenu*)action2->parent())->setCheckable(true); |
---|
868 | } |
---|
869 | action1->setOn(false); |
---|
870 | action2->setOn(false); |
---|
871 | |
---|
872 | if (nCheck ==1) |
---|
873 | action1->setOn(true); |
---|
874 | else |
---|
875 | action2->setOn(true); |
---|
876 | |
---|
877 | //FIXME : Should not work on Qt3 |
---|
878 | QObject ::connect(action1, SIGNAL(activated()),action2, SLOT(toggle())); |
---|
879 | QObject ::connect(action2, SIGNAL(activated()),action1, SLOT(toggle())); |
---|
880 | |
---|
881 | QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str()); |
---|
882 | } |
---|
883 | |
---|
884 | #else |
---|
885 | void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) { |
---|
886 | |
---|
887 | action1->setCheckable(true); |
---|
888 | action2->setCheckable(true); |
---|
889 | |
---|
890 | if (nCheck ==1) |
---|
891 | action1->setChecked (true); |
---|
892 | else |
---|
893 | action2->setChecked (true); |
---|
894 | |
---|
895 | QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle())); |
---|
896 | QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle())); |
---|
897 | |
---|
898 | QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str()); |
---|
899 | |
---|
900 | } |
---|
901 | #endif |
---|
902 | |
---|
903 | /** |
---|
904 | Slot activate when mouseAction->rotate menu is set |
---|
905 | */ |
---|
906 | void G4OpenGLQtViewer::actionMouseRotate() { |
---|
907 | emit toggleMouseAction(STYLE1); |
---|
908 | } |
---|
909 | |
---|
910 | |
---|
911 | /** |
---|
912 | Slot activate when mouseAction->rotate menu is set |
---|
913 | */ |
---|
914 | void G4OpenGLQtViewer::actionMouseMove() { |
---|
915 | emit toggleMouseAction(STYLE2); |
---|
916 | } |
---|
917 | |
---|
918 | |
---|
919 | /** |
---|
920 | Slot activate when mouseAction->zoom menu is set |
---|
921 | */ |
---|
922 | void G4OpenGLQtViewer::actionMousePick() { |
---|
923 | #ifdef GEANT4_QT_DEBUG |
---|
924 | printf("G4OpenGLQtViewer::actionMousePick \n"); |
---|
925 | #endif |
---|
926 | emit toggleMouseAction(STYLE3); |
---|
927 | } |
---|
928 | |
---|
929 | |
---|
930 | /** |
---|
931 | Slot activate when drawing->wireframe menu is set |
---|
932 | */ |
---|
933 | void G4OpenGLQtViewer::actionDrawingWireframe() { |
---|
934 | emit toggleDrawingAction(1); |
---|
935 | } |
---|
936 | |
---|
937 | /** |
---|
938 | Slot activate when drawing->line removal menu is set |
---|
939 | */ |
---|
940 | void G4OpenGLQtViewer::actionDrawingLineRemoval() { |
---|
941 | emit toggleDrawingAction(2); |
---|
942 | } |
---|
943 | |
---|
944 | /** |
---|
945 | Slot activate when drawing->surface removal menu is set |
---|
946 | */ |
---|
947 | void G4OpenGLQtViewer::actionDrawingSurfaceRemoval() { |
---|
948 | emit toggleDrawingAction(3); |
---|
949 | } |
---|
950 | |
---|
951 | /** |
---|
952 | Slot activate when drawing->wireframe menu is set |
---|
953 | */ |
---|
954 | void G4OpenGLQtViewer::actionDrawingLineSurfaceRemoval() { |
---|
955 | emit toggleDrawingAction(4); |
---|
956 | } |
---|
957 | |
---|
958 | |
---|
959 | /** |
---|
960 | Slot activated when mouse action is toggle |
---|
961 | @param aAction : STYLE1, STYLE2, STYLE3 |
---|
962 | */ |
---|
963 | void G4OpenGLQtViewer::toggleMouseAction(mouseActions aAction) { |
---|
964 | |
---|
965 | if ((aAction == STYLE1) || //initialize all |
---|
966 | (aAction == STYLE2) || |
---|
967 | (aAction == STYLE3)) { |
---|
968 | #if QT_VERSION < 0x040000 |
---|
969 | fRotateAction->setOn (false); |
---|
970 | fMoveAction->setOn (false); |
---|
971 | fPickAction->setOn (false); |
---|
972 | #else |
---|
973 | fRotateAction->setChecked (false); |
---|
974 | fMoveAction->setChecked (false); |
---|
975 | fPickAction->setChecked (false); |
---|
976 | #endif |
---|
977 | fVP.SetPicking(false); |
---|
978 | fMouseAction = aAction; |
---|
979 | } |
---|
980 | // rotate |
---|
981 | if (aAction == STYLE1) { // rotate |
---|
982 | showShortcuts(); |
---|
983 | #if QT_VERSION < 0x040000 |
---|
984 | fRotateAction->setOn (true); |
---|
985 | #else |
---|
986 | fRotateAction->setChecked (true); |
---|
987 | #endif |
---|
988 | } else if (aAction == STYLE2) { //move |
---|
989 | #if QT_VERSION < 0x040000 |
---|
990 | fMoveAction->setOn (true); |
---|
991 | #else |
---|
992 | fMoveAction->setChecked (true); |
---|
993 | #endif |
---|
994 | } else if (aAction == STYLE3) { //pick |
---|
995 | #if QT_VERSION < 0x040000 |
---|
996 | fPickAction->setOn (true); |
---|
997 | #else |
---|
998 | fPickAction->setChecked (true); |
---|
999 | #endif |
---|
1000 | fVP.SetPicking(true); |
---|
1001 | } |
---|
1002 | } |
---|
1003 | |
---|
1004 | /** |
---|
1005 | Show shortcuts for this mouse action |
---|
1006 | */ |
---|
1007 | void G4OpenGLQtViewer::showShortcuts() { |
---|
1008 | if (fMouseAction == STYLE1) { // rotate |
---|
1009 | G4cout << "Click and move mouse to rotate volume \n" << G4endl; |
---|
1010 | G4cout << "Press left/right arrows to move volume left/right\n" << G4endl; |
---|
1011 | G4cout << "Press up/down arrows to move volume up/down\n" << G4endl; |
---|
1012 | G4cout << "Press ALT+up/down arrows to move volume toward/forward\n" << G4endl; |
---|
1013 | G4cout << "Press SHIFT+left/right arrows to rotate volume left/right\n" << G4endl; |
---|
1014 | G4cout << "Press SHIFT+up/down arrows to rotate volume up/down\n" << G4endl; |
---|
1015 | G4cout << "Press ALT+/- to slow/speed auto rotation/move\n" << G4endl; |
---|
1016 | G4cout << "In video mode : \n" << G4endl; |
---|
1017 | G4cout << " Press SPACE to Start/Pause video recording \n" << G4endl; |
---|
1018 | G4cout << " Press RETURN to Stop video recording \n" << G4endl; |
---|
1019 | } else if (fMouseAction == STYLE2) { //move |
---|
1020 | G4cout << "Move camera point of view with mouse\n" << G4endl; |
---|
1021 | G4cout << "Press left/right arrows to move volume left/right\n" << G4endl; |
---|
1022 | G4cout << "Press up/down arrows to move volume up/down\n" << G4endl; |
---|
1023 | G4cout << "Press ALT+up/down arrows to move volume toward/forward\n" << G4endl; |
---|
1024 | G4cout << "Press SHIFT+left/right arrows to rotate volume left/right\n" << G4endl; |
---|
1025 | G4cout << "Press SHIFT+up/down arrows to rotate volume up/down\n" << G4endl; |
---|
1026 | G4cout << "Press +/- to zoom into volume\n" << G4endl; |
---|
1027 | G4cout << "Press ALT+/- to slow/speed auto rotation/move\n" << G4endl; |
---|
1028 | G4cout << "In video mode : \n" << G4endl; |
---|
1029 | G4cout << " Press SPACE to Start/Pause video recording \n" << G4endl; |
---|
1030 | G4cout << " Press RETURN to Stop video recording \n" << G4endl; |
---|
1031 | } else if (fMouseAction == STYLE3) { //pick |
---|
1032 | G4cout << "Click and pick \n" << G4endl; |
---|
1033 | } |
---|
1034 | |
---|
1035 | } |
---|
1036 | |
---|
1037 | |
---|
1038 | |
---|
1039 | /** |
---|
1040 | Slot activated when drawing menu is toggle |
---|
1041 | Warning : When G4OpenGLStoredQtViewer::DrawView() method call, |
---|
1042 | KernelVisitDecision () will be call and will set the fNeedKernelVisit |
---|
1043 | to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. |
---|
1044 | It will cause a redraw of the view |
---|
1045 | @param aAction : 1 wireframe, 2 line removal, 3 surface removal, 4 line & surface removal |
---|
1046 | @see G4OpenGLStoredQtViewer::DrawView |
---|
1047 | @see G4XXXStoredViewer::CompareForKernelVisit |
---|
1048 | */ |
---|
1049 | void G4OpenGLQtViewer::toggleDrawingAction(int aAction) { |
---|
1050 | |
---|
1051 | G4ViewParameters::DrawingStyle d_style; |
---|
1052 | |
---|
1053 | |
---|
1054 | // initialize |
---|
1055 | if ((aAction >0) && (aAction <5)) { |
---|
1056 | #if QT_VERSION < 0x040000 |
---|
1057 | fDrawingWireframe->setOn(false); |
---|
1058 | fDrawingLineRemoval->setOn(false); |
---|
1059 | fDrawingSurfaceRemoval->setOn(false); |
---|
1060 | fDrawingLineSurfaceRemoval->setOn(false); |
---|
1061 | #else |
---|
1062 | fDrawingWireframe->setChecked (false); |
---|
1063 | fDrawingLineRemoval->setChecked (false); |
---|
1064 | fDrawingSurfaceRemoval->setChecked (false); |
---|
1065 | fDrawingLineSurfaceRemoval->setChecked (false); |
---|
1066 | #endif |
---|
1067 | } |
---|
1068 | if (aAction ==1) { |
---|
1069 | #if QT_VERSION < 0x040000 |
---|
1070 | fDrawingWireframe->setOn(true); |
---|
1071 | #else |
---|
1072 | fDrawingWireframe->setChecked (true); |
---|
1073 | #endif |
---|
1074 | |
---|
1075 | d_style = G4ViewParameters::wireframe; |
---|
1076 | |
---|
1077 | } else if (aAction ==2) { |
---|
1078 | #if QT_VERSION < 0x040000 |
---|
1079 | fDrawingLineRemoval->setOn(true); |
---|
1080 | #else |
---|
1081 | fDrawingLineRemoval->setChecked (true); |
---|
1082 | #endif |
---|
1083 | |
---|
1084 | d_style = G4ViewParameters::hlr; |
---|
1085 | |
---|
1086 | } else if (aAction ==3) { |
---|
1087 | #if QT_VERSION < 0x040000 |
---|
1088 | fDrawingSurfaceRemoval->setOn(true); |
---|
1089 | #else |
---|
1090 | fDrawingSurfaceRemoval->setChecked (true); |
---|
1091 | #endif |
---|
1092 | |
---|
1093 | d_style = G4ViewParameters::hsr; |
---|
1094 | |
---|
1095 | } else if (aAction ==4) { |
---|
1096 | #if QT_VERSION < 0x040000 |
---|
1097 | fDrawingLineSurfaceRemoval->setOn(true); |
---|
1098 | #else |
---|
1099 | fDrawingLineSurfaceRemoval->setChecked (true); |
---|
1100 | #endif |
---|
1101 | d_style = G4ViewParameters::hlhsr; |
---|
1102 | } |
---|
1103 | fVP.SetDrawingStyle(d_style); |
---|
1104 | |
---|
1105 | updateQWidget(); |
---|
1106 | } |
---|
1107 | |
---|
1108 | |
---|
1109 | /** |
---|
1110 | SLOT Activate by a click on the representation menu |
---|
1111 | Warning : When G4OpenGLStoredQtViewer::DrawView() method call, |
---|
1112 | KernelVisitDecision () will be call and will set the fNeedKernelVisit |
---|
1113 | to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. |
---|
1114 | It will cause a redraw of the view |
---|
1115 | @param check : 1 polyhedron, 0 nurbs |
---|
1116 | @see G4OpenGLStoredQtViewer::DrawView |
---|
1117 | @see G4XXXStoredViewer::CompareForKernelVisit |
---|
1118 | */ |
---|
1119 | void G4OpenGLQtViewer::toggleRepresentation(bool check) { |
---|
1120 | |
---|
1121 | G4ViewParameters::RepStyle style; |
---|
1122 | if (check == 1) { |
---|
1123 | style = G4ViewParameters::polyhedron; |
---|
1124 | } else { |
---|
1125 | style = G4ViewParameters::nurbs; |
---|
1126 | } |
---|
1127 | fVP.SetRepStyle (style); |
---|
1128 | |
---|
1129 | updateQWidget(); |
---|
1130 | } |
---|
1131 | |
---|
1132 | /** |
---|
1133 | SLOT Activate by a click on the projection menu |
---|
1134 | Warning : When G4OpenGLStoredQtViewer::DrawView() method call, |
---|
1135 | KernelVisitDecision () will be call and will set the fNeedKernelVisit |
---|
1136 | to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. |
---|
1137 | It will cause a redraw of the view |
---|
1138 | @param check : 1 orthographic, 2 perspective |
---|
1139 | @see G4OpenGLStoredQtViewer::DrawView |
---|
1140 | @see G4XXXStoredViewer::CompareForKernelVisit |
---|
1141 | */ |
---|
1142 | void G4OpenGLQtViewer::toggleProjection(bool check) { |
---|
1143 | |
---|
1144 | if (check == 1) { |
---|
1145 | fVP.SetFieldHalfAngle (0); |
---|
1146 | } else { |
---|
1147 | |
---|
1148 | // look for the default parameter hidden in G4UIcommand parameters |
---|
1149 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
1150 | if(UI==NULL) |
---|
1151 | return; |
---|
1152 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
1153 | |
---|
1154 | // find command |
---|
1155 | G4UIcommand* command = treeTop->FindPath("/vis/viewer/set/projection"); |
---|
1156 | if (!command) |
---|
1157 | return; |
---|
1158 | |
---|
1159 | // find param |
---|
1160 | G4UIparameter * angleParam = NULL; |
---|
1161 | for(G4int i=0; i<command->GetParameterEntries(); i++) |
---|
1162 | { |
---|
1163 | if( command->GetParameter(i)->GetParameterName() == "field-half-angle" ) { |
---|
1164 | angleParam = command->GetParameter(i); |
---|
1165 | } |
---|
1166 | } |
---|
1167 | if (!angleParam) |
---|
1168 | return; |
---|
1169 | |
---|
1170 | // find unit |
---|
1171 | G4UIparameter * unitParam = NULL; |
---|
1172 | for(G4int i=0; i<command->GetParameterEntries(); i++) |
---|
1173 | { |
---|
1174 | if( command->GetParameter(i)->GetParameterName() == "unit" ) { |
---|
1175 | unitParam = command->GetParameter(i); |
---|
1176 | } |
---|
1177 | } |
---|
1178 | if (!unitParam) |
---|
1179 | return; |
---|
1180 | |
---|
1181 | G4double defaultValue = command->ConvertToDouble(angleParam->GetDefaultValue()) |
---|
1182 | * G4UnitDefinition::GetValueOf(unitParam->GetDefaultValue()); |
---|
1183 | if (defaultValue > 89.5 || defaultValue <= 0.0) { |
---|
1184 | G4cerr << "Field half angle should be 0 < angle <= 89.5 degrees. Check your default Field half angle parameter\n"; |
---|
1185 | } else { |
---|
1186 | G4cout << "Perspective view has been set to default value. Field half angle="<<angleParam->GetDefaultValue() <<" \n" << G4endl; |
---|
1187 | fVP.SetFieldHalfAngle (defaultValue); |
---|
1188 | SetView (); |
---|
1189 | } |
---|
1190 | } |
---|
1191 | updateQWidget(); |
---|
1192 | } |
---|
1193 | |
---|
1194 | |
---|
1195 | /** |
---|
1196 | SLOT Activate by a click on the background menu |
---|
1197 | @param check : 1 white, 0 black |
---|
1198 | */ |
---|
1199 | void G4OpenGLQtViewer::toggleBackground(bool check) { |
---|
1200 | |
---|
1201 | // //I need to revisit the kernel if the background colour changes and |
---|
1202 | // //hidden line removal is enabled, because hlr drawing utilises the |
---|
1203 | // //background colour in its drawing... |
---|
1204 | // // (Note added by JA 13/9/2005) Background now handled in view |
---|
1205 | // // parameters. A kernel visit is triggered on change of background. |
---|
1206 | if (check == 1) { |
---|
1207 | ((G4ViewParameters&)this->GetViewParameters()). |
---|
1208 | SetBackgroundColour(G4Colour(1.,1.,1.)); // White |
---|
1209 | } else { |
---|
1210 | ((G4ViewParameters&)this->GetViewParameters()). |
---|
1211 | SetBackgroundColour(G4Colour(0.,0.,0.)); // Black |
---|
1212 | } |
---|
1213 | updateQWidget(); |
---|
1214 | } |
---|
1215 | |
---|
1216 | /** |
---|
1217 | SLOT Activate by a click on the transparency menu |
---|
1218 | @param check : 1 , 0 |
---|
1219 | */ |
---|
1220 | void G4OpenGLQtViewer::toggleTransparency(bool check) { |
---|
1221 | |
---|
1222 | if (check) { |
---|
1223 | transparency_enabled = false; |
---|
1224 | } else { |
---|
1225 | transparency_enabled = true; |
---|
1226 | } |
---|
1227 | SetNeedKernelVisit (true); |
---|
1228 | updateQWidget(); |
---|
1229 | } |
---|
1230 | |
---|
1231 | /** |
---|
1232 | SLOT Activate by a click on the antialiasing menu |
---|
1233 | @param check : 1 , 0 |
---|
1234 | */ |
---|
1235 | void G4OpenGLQtViewer::toggleAntialiasing(bool check) { |
---|
1236 | |
---|
1237 | if (!check) { |
---|
1238 | antialiasing_enabled = false; |
---|
1239 | glDisable (GL_LINE_SMOOTH); |
---|
1240 | glDisable (GL_POLYGON_SMOOTH); |
---|
1241 | } else { |
---|
1242 | antialiasing_enabled = true; |
---|
1243 | glEnable (GL_LINE_SMOOTH); |
---|
1244 | glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); |
---|
1245 | glEnable (GL_POLYGON_SMOOTH); |
---|
1246 | glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST); |
---|
1247 | } |
---|
1248 | |
---|
1249 | updateQWidget(); |
---|
1250 | } |
---|
1251 | |
---|
1252 | /** |
---|
1253 | SLOT Activate by a click on the haloing menu |
---|
1254 | @param check : 1 , 0 |
---|
1255 | */ |
---|
1256 | //FIXME : I SEE NOTHING... |
---|
1257 | void G4OpenGLQtViewer::toggleHaloing(bool check) { |
---|
1258 | if (check) { |
---|
1259 | haloing_enabled = false; |
---|
1260 | } else { |
---|
1261 | haloing_enabled = true; |
---|
1262 | } |
---|
1263 | |
---|
1264 | updateQWidget(); |
---|
1265 | |
---|
1266 | } |
---|
1267 | |
---|
1268 | /** |
---|
1269 | SLOT Activate by a click on the auxiliaire edges menu |
---|
1270 | @param check : 1 , 0 |
---|
1271 | */ |
---|
1272 | void G4OpenGLQtViewer::toggleAux(bool check) { |
---|
1273 | if (check) { |
---|
1274 | fVP.SetAuxEdgeVisible(false); |
---|
1275 | } else { |
---|
1276 | fVP.SetAuxEdgeVisible(true); |
---|
1277 | } |
---|
1278 | SetNeedKernelVisit (true); |
---|
1279 | updateQWidget(); |
---|
1280 | |
---|
1281 | } |
---|
1282 | |
---|
1283 | /** |
---|
1284 | SLOT Activate by a click on the full screen menu |
---|
1285 | */ |
---|
1286 | void G4OpenGLQtViewer::toggleFullScreen(bool check) { |
---|
1287 | if (check != GLWindow->isFullScreen()) { //toggle |
---|
1288 | #if QT_VERSION >= 0x030200 |
---|
1289 | GLWindow->setWindowState(GLWindow->windowState() ^ Qt::WindowFullScreen); |
---|
1290 | #else |
---|
1291 | G4cerr << "This version of Qt could not do fullScreen. Resizing the widget is the only solution available.\n" << G4endl; |
---|
1292 | #endif |
---|
1293 | } |
---|
1294 | } |
---|
1295 | |
---|
1296 | |
---|
1297 | void G4OpenGLQtViewer::saveForVideo(QString nomFich) { |
---|
1298 | if (nomFich == "") { |
---|
1299 | return; |
---|
1300 | } |
---|
1301 | |
---|
1302 | QImage image; |
---|
1303 | image = fWindow->grabFrameBuffer(); |
---|
1304 | bool res = false; |
---|
1305 | |
---|
1306 | nomFich += "."+QString("ppm"); |
---|
1307 | #if QT_VERSION < 0x040000 |
---|
1308 | res = image.save(nomFich,"ppm"); |
---|
1309 | #else |
---|
1310 | res = image.save(nomFich,0); |
---|
1311 | #endif |
---|
1312 | if (res == false) { |
---|
1313 | #if QT_VERSION < 0x040000 |
---|
1314 | G4cerr << "Error while saving file... "<<nomFich.ascii()<<"\n" << G4endl; |
---|
1315 | #else |
---|
1316 | G4cerr << "Error while saving file... "<<nomFich.toStdString().c_str()<<"\n" << G4endl; |
---|
1317 | #endif |
---|
1318 | fRecordFrames = false; |
---|
1319 | } |
---|
1320 | |
---|
1321 | #if QT_VERSION < 0x040000 |
---|
1322 | printf("SaveForVideo ^^^^^^^^^^^^^^^^^^^^^^^^ %s\n",nomFich.ascii()); |
---|
1323 | #else |
---|
1324 | printf("SaveForVideo ^^^^^^^^^^^^^^^^^^^^^^^^ %s\n",nomFich.toStdString().c_str()); |
---|
1325 | #endif |
---|
1326 | } |
---|
1327 | |
---|
1328 | |
---|
1329 | |
---|
1330 | void G4OpenGLQtViewer::actionSaveImage() { |
---|
1331 | QString filters; |
---|
1332 | #if QT_VERSION < 0x040000 |
---|
1333 | QStrList listFormat=QImageIO::outputFormats(); |
---|
1334 | char *tmp=listFormat.first(); |
---|
1335 | while (tmp!=0) { |
---|
1336 | filters += QString(tmp) + ";;"; |
---|
1337 | tmp=listFormat.next(); |
---|
1338 | } |
---|
1339 | #else |
---|
1340 | QList<QByteArray> formats = QImageWriter::supportedImageFormats (); |
---|
1341 | for (int i = 0; i < formats.size(); ++i) { |
---|
1342 | filters +=formats.at(i) + ";;"; |
---|
1343 | } |
---|
1344 | #endif |
---|
1345 | filters += "eps;;"; |
---|
1346 | filters += "ps;;"; |
---|
1347 | filters += "pdf"; |
---|
1348 | QString* selectedFormat = new QString(); |
---|
1349 | #if QT_VERSION < 0x040000 |
---|
1350 | QString nomFich = QFileDialog::getSaveFileName ( ".", |
---|
1351 | filters, |
---|
1352 | GLWindow, |
---|
1353 | "Save file dialog", |
---|
1354 | tr("Save as ..."), |
---|
1355 | selectedFormat ); |
---|
1356 | #else |
---|
1357 | QString nomFich = QFileDialog::getSaveFileName ( GLWindow, |
---|
1358 | tr("Save as ..."), |
---|
1359 | ".", |
---|
1360 | filters, |
---|
1361 | selectedFormat ); |
---|
1362 | #endif |
---|
1363 | // bmp jpg jpeg png ppm xbm xpm |
---|
1364 | if (nomFich == "") { |
---|
1365 | return; |
---|
1366 | } |
---|
1367 | #if QT_VERSION < 0x040000 |
---|
1368 | nomFich += "."+QString(selectedFormat->ascii()); |
---|
1369 | QString format = selectedFormat->lower(); |
---|
1370 | #else |
---|
1371 | nomFich += "."+QString(selectedFormat->toStdString().c_str()); |
---|
1372 | QString format = selectedFormat->toLower(); |
---|
1373 | #endif |
---|
1374 | G4OpenGLQtExportDialog* exportDialog= new G4OpenGLQtExportDialog(GLWindow,format,fWindow->height(),fWindow->width()); |
---|
1375 | if( exportDialog->exec()) { |
---|
1376 | |
---|
1377 | QImage image; |
---|
1378 | bool res = false; |
---|
1379 | if ((exportDialog->getWidth() !=fWindow->width()) || |
---|
1380 | (exportDialog->getHeight() !=fWindow->height())) { |
---|
1381 | if (format != QString("eps")) { |
---|
1382 | G4cerr << "Export->Change Size : This function is not implemented, to export in another size, please resize your frame to what you need\n" << G4endl; |
---|
1383 | |
---|
1384 | // rescaleImage(exportDialog->getWidth(),exportDialog->getHeight());// re-scale image |
---|
1385 | // QGLWidget* glResized = fWindow; |
---|
1386 | |
---|
1387 | // FIXME : |
---|
1388 | // L.Garnier : I've try to implement change size function, but the problem is |
---|
1389 | // the renderPixmap function call the QGLWidget to resize and it doesn't draw |
---|
1390 | // the content of this widget... It only draw the background. |
---|
1391 | |
---|
1392 | // fWindow->renderPixmap (exportDialog->getWidth()*2,exportDialog->getHeight()*2,true ); |
---|
1393 | |
---|
1394 | // QPixmap pixmap = fWindow->renderPixmap (); |
---|
1395 | |
---|
1396 | // image = pixmap->toImage(); |
---|
1397 | // glResized->resize(exportDialog->getWidth()*2,exportDialog->getHeight()*2); |
---|
1398 | // image = glResized->grabFrameBuffer(); |
---|
1399 | } |
---|
1400 | } else { |
---|
1401 | image = fWindow->grabFrameBuffer(); |
---|
1402 | } |
---|
1403 | if (format == QString("eps")) { |
---|
1404 | if (exportDialog->getVectorEPS()) { |
---|
1405 | res = generateVectorEPS(nomFich,exportDialog->getWidth(),exportDialog->getHeight(),image); |
---|
1406 | } else { |
---|
1407 | res = generateEPS(nomFich,exportDialog->getNbColor(),image); |
---|
1408 | } |
---|
1409 | } else if ((format == "ps") || (format == "pdf")) { |
---|
1410 | res = generatePS_PDF(nomFich,exportDialog->getNbColor(),image); |
---|
1411 | } else if ((format == "tif") || |
---|
1412 | (format == "tiff") || |
---|
1413 | (format == "jpg") || |
---|
1414 | (format == "jpeg") || |
---|
1415 | (format == "png") || |
---|
1416 | (format == "pbm") || |
---|
1417 | (format == "pgm") || |
---|
1418 | (format == "ppm") || |
---|
1419 | (format == "bmp") || |
---|
1420 | (format == "xbm") || |
---|
1421 | (format == "xpm")) { |
---|
1422 | #if QT_VERSION < 0x040000 |
---|
1423 | res = image.save(nomFich,selectedFormat->ascii(),exportDialog->getSliderValue()); |
---|
1424 | #else |
---|
1425 | res = image.save(nomFich,0,exportDialog->getSliderValue()); |
---|
1426 | #endif |
---|
1427 | } else { |
---|
1428 | G4cerr << "This version of G4UI Could not generate the selected format\n" << G4endl; |
---|
1429 | } |
---|
1430 | if (res == false) { |
---|
1431 | #if QT_VERSION < 0x040000 |
---|
1432 | G4cerr << "Error while saving file... "<<nomFich.ascii()<<"\n" << G4endl; |
---|
1433 | #else |
---|
1434 | G4cerr << "Error while saving file... "<<nomFich.toStdString().c_str()<<"\n" << G4endl; |
---|
1435 | #endif |
---|
1436 | } else { |
---|
1437 | #if QT_VERSION < 0x040000 |
---|
1438 | G4cout << "File "<<nomFich.ascii()<<" has been saved \n" << G4endl; |
---|
1439 | #else |
---|
1440 | G4cout << "File "<<nomFich.toStdString().c_str()<<" has been saved \n" << G4endl; |
---|
1441 | #endif |
---|
1442 | } |
---|
1443 | |
---|
1444 | } else { // cancel selected |
---|
1445 | return; |
---|
1446 | } |
---|
1447 | |
---|
1448 | #ifdef GEANT4_QT_DEBUG |
---|
1449 | printf("G4OpenGLQtViewer::actionSaveImage() \n"); |
---|
1450 | #endif |
---|
1451 | } |
---|
1452 | |
---|
1453 | |
---|
1454 | void G4OpenGLQtViewer::actionMovieParameters() { |
---|
1455 | |
---|
1456 | showMovieParametersDialog(); |
---|
1457 | #ifdef GEANT4_QT_DEBUG |
---|
1458 | printf("G4OpenGLQtViewer::actionMovieParameters() \n"); |
---|
1459 | #endif |
---|
1460 | } |
---|
1461 | |
---|
1462 | |
---|
1463 | void G4OpenGLQtViewer::showMovieParametersDialog() { |
---|
1464 | if (!fMovieParametersDialog) { |
---|
1465 | fMovieParametersDialog= new G4OpenGLQtMovieDialog(this,GLWindow); |
---|
1466 | } |
---|
1467 | fMovieParametersDialog->show(); |
---|
1468 | } |
---|
1469 | |
---|
1470 | |
---|
1471 | /* |
---|
1472 | // 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 |
---|
1473 | |
---|
1474 | void Graph::exportToSVG(const QString& fname) |
---|
1475 | { |
---|
1476 | // enable workaround for Qt3 misalignments |
---|
1477 | QwtPainter::setSVGMode(true); |
---|
1478 | QPicture picture; |
---|
1479 | QPainter p(&picture); |
---|
1480 | d_plot->print(&p, d_plot->rect()); |
---|
1481 | p.end(); |
---|
1482 | |
---|
1483 | picture.save(fname, "svg"); |
---|
1484 | } |
---|
1485 | */ |
---|
1486 | |
---|
1487 | |
---|
1488 | |
---|
1489 | |
---|
1490 | /** |
---|
1491 | Save the current mouse press point |
---|
1492 | @param p mouse click point |
---|
1493 | */ |
---|
1494 | #if QT_VERSION < 0x040000 |
---|
1495 | void G4OpenGLQtViewer::G4MousePressEvent(QPoint p,Qt::ButtonState mButtons) |
---|
1496 | #else |
---|
1497 | void G4OpenGLQtViewer::G4MousePressEvent(QPoint p,Qt::MouseButtons mButtons) |
---|
1498 | #endif |
---|
1499 | { |
---|
1500 | fAutoMove = false; // stop automove |
---|
1501 | fLastPos = p; |
---|
1502 | if (fMouseAction == STYLE2){ // pick |
---|
1503 | Pick(p.x(),p.y()); |
---|
1504 | } |
---|
1505 | } |
---|
1506 | |
---|
1507 | |
---|
1508 | /** |
---|
1509 | @param pos_x mouse x position |
---|
1510 | @param pos_y mouse y position |
---|
1511 | @param mButtons mouse button active |
---|
1512 | @param mAutoMove true: apply this move till another evnt came, false :one time move |
---|
1513 | */ |
---|
1514 | |
---|
1515 | #if QT_VERSION < 0x040000 |
---|
1516 | void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::ButtonState mButtons,bool mAutoMove) |
---|
1517 | #else |
---|
1518 | void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons,bool mAutoMove) |
---|
1519 | #endif |
---|
1520 | { |
---|
1521 | fAutoMove = mAutoMove; |
---|
1522 | |
---|
1523 | if (!fAutoMove) { // keep old delta if automove |
---|
1524 | fDeltaPosX = fLastPos.x() - pos_x; |
---|
1525 | fDeltaPosY = fLastPos.y() - pos_y; |
---|
1526 | } |
---|
1527 | |
---|
1528 | if ((fDeltaPosX == 0) && (fDeltaPosY == 0)) { |
---|
1529 | fAutoMove = false; |
---|
1530 | } |
---|
1531 | |
---|
1532 | if (fMouseAction == STYLE1) { // rotate |
---|
1533 | if (mButtons & Qt::LeftButton) { |
---|
1534 | rotateScene(fDeltaPosX,fDeltaPosY,fAutoMove); |
---|
1535 | } |
---|
1536 | } else if (fMouseAction == STYLE2) { // move |
---|
1537 | if (mButtons & Qt::LeftButton) { |
---|
1538 | if (fAutoMove) { |
---|
1539 | while (fAutoMove) { |
---|
1540 | moveScene(-fDeltaPosX,-fDeltaPosY,0,true,true); |
---|
1541 | ((QApplication*)G4Qt::getInstance ())->processEvents(); |
---|
1542 | } |
---|
1543 | } else { |
---|
1544 | moveScene(-fDeltaPosX,-fDeltaPosY,0,true,false); |
---|
1545 | } |
---|
1546 | } |
---|
1547 | } |
---|
1548 | fLastPos = QPoint(pos_x, pos_y); |
---|
1549 | } |
---|
1550 | |
---|
1551 | |
---|
1552 | /** |
---|
1553 | Move the scene of dx, dy, dz values. |
---|
1554 | @param dx delta mouse x position |
---|
1555 | @param dy delta mouse y position |
---|
1556 | @param mouseMove : true if even comes froma mouse move, false if even comes from key action |
---|
1557 | */ |
---|
1558 | |
---|
1559 | void G4OpenGLQtViewer::moveScene(G4double dx,G4double dy, G4double dz,bool mouseMove,bool mAutoMove) |
---|
1560 | { |
---|
1561 | if (fHoldMoveEvent) |
---|
1562 | return; |
---|
1563 | fHoldMoveEvent = true; |
---|
1564 | |
---|
1565 | if( mAutoMove == false) { |
---|
1566 | fAutoMove = true; |
---|
1567 | } |
---|
1568 | G4double coefTrans = 0; |
---|
1569 | GLdouble coefDepth = 0; |
---|
1570 | while (fAutoMove) { |
---|
1571 | if( mAutoMove == false) { |
---|
1572 | fAutoMove = false; |
---|
1573 | } |
---|
1574 | if(mouseMove) { |
---|
1575 | coefTrans = ((G4double)getSceneNearWidth())/((G4double)WinSize_x); |
---|
1576 | if (WinSize_y <WinSize_x) { |
---|
1577 | coefTrans = ((G4double)getSceneNearWidth())/((G4double)WinSize_y); |
---|
1578 | } |
---|
1579 | } else { |
---|
1580 | coefTrans = getSceneNearWidth()*fDeltaSceneTranslation; |
---|
1581 | coefDepth = getSceneDepth()*fDeltaDepth; |
---|
1582 | } |
---|
1583 | fVP.IncrementPan(-dx*coefTrans,dy*coefTrans,dz*coefDepth); |
---|
1584 | |
---|
1585 | updateQWidget(); |
---|
1586 | if (fAutoMove) |
---|
1587 | ((QApplication*)G4Qt::getInstance ())->processEvents(); |
---|
1588 | } |
---|
1589 | |
---|
1590 | fHoldMoveEvent = false; |
---|
1591 | } |
---|
1592 | |
---|
1593 | |
---|
1594 | /** |
---|
1595 | @param dx delta mouse x position |
---|
1596 | @param dy delta mouse y position |
---|
1597 | */ |
---|
1598 | |
---|
1599 | void G4OpenGLQtViewer::rotateScene(G4double dx, G4double dy,bool mAutoRotate) |
---|
1600 | { |
---|
1601 | if (fHoldRotateEvent) |
---|
1602 | return; |
---|
1603 | fHoldRotateEvent = true; |
---|
1604 | |
---|
1605 | if( mAutoRotate == false) { |
---|
1606 | fAutoMove = true; |
---|
1607 | } |
---|
1608 | G4Vector3D vp; |
---|
1609 | G4Vector3D up; |
---|
1610 | |
---|
1611 | G4Vector3D xprime; |
---|
1612 | G4Vector3D yprime; |
---|
1613 | G4Vector3D zprime; |
---|
1614 | |
---|
1615 | G4double delta_alpha; |
---|
1616 | G4double delta_theta; |
---|
1617 | |
---|
1618 | G4Vector3D new_vp; |
---|
1619 | G4Vector3D new_up; |
---|
1620 | |
---|
1621 | G4double cosalpha; |
---|
1622 | G4double sinalpha; |
---|
1623 | |
---|
1624 | G4Vector3D a1; |
---|
1625 | G4Vector3D a2; |
---|
1626 | G4Vector3D delta; |
---|
1627 | G4Vector3D viewPoint; |
---|
1628 | |
---|
1629 | while (fAutoMove) { |
---|
1630 | if( mAutoRotate == false) { |
---|
1631 | fAutoMove = false; |
---|
1632 | } |
---|
1633 | |
---|
1634 | //phi spin stuff here |
---|
1635 | |
---|
1636 | vp = fVP.GetViewpointDirection ().unit (); |
---|
1637 | up = fVP.GetUpVector ().unit (); |
---|
1638 | |
---|
1639 | yprime = (up.cross(vp)).unit(); |
---|
1640 | zprime = (vp.cross(yprime)).unit(); |
---|
1641 | |
---|
1642 | if (fVP.GetLightsMoveWithCamera()) { |
---|
1643 | delta_alpha = dy * fDeltaRotation; |
---|
1644 | delta_theta = -dx * fDeltaRotation; |
---|
1645 | } else { |
---|
1646 | delta_alpha = -dy * fDeltaRotation; |
---|
1647 | delta_theta = dx * fDeltaRotation; |
---|
1648 | } |
---|
1649 | |
---|
1650 | delta_alpha *= deg; |
---|
1651 | delta_theta *= deg; |
---|
1652 | |
---|
1653 | new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime; |
---|
1654 | |
---|
1655 | // to avoid z rotation flipping |
---|
1656 | // to allow more than 360° rotation |
---|
1657 | if (fVP.GetLightsMoveWithCamera()) { |
---|
1658 | new_up = (new_vp.cross(yprime)).unit(); |
---|
1659 | if (new_vp.z()*vp.z() <0) { |
---|
1660 | new_up.set(new_up.x(),-new_up.y(),new_up.z()); |
---|
1661 | } |
---|
1662 | } else { |
---|
1663 | new_up = up; |
---|
1664 | if (new_vp.z()*vp.z() <0) { |
---|
1665 | new_up.set(new_up.x(),-new_up.y(),new_up.z()); |
---|
1666 | } |
---|
1667 | } |
---|
1668 | fVP.SetUpVector(new_up); |
---|
1669 | //////////////// |
---|
1670 | // Rotates by fixed azimuthal angle delta_theta. |
---|
1671 | |
---|
1672 | cosalpha = new_up.dot (new_vp.unit()); |
---|
1673 | sinalpha = std::sqrt (1. - std::pow (cosalpha, 2)); |
---|
1674 | yprime = (new_up.cross (new_vp.unit())).unit (); |
---|
1675 | xprime = yprime.cross (new_up); |
---|
1676 | // Projection of vp on plane perpendicular to up... |
---|
1677 | a1 = sinalpha * xprime; |
---|
1678 | // Required new projection... |
---|
1679 | a2 = sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime); |
---|
1680 | // Required Increment vector... |
---|
1681 | delta = a2 - a1; |
---|
1682 | // So new viewpoint is... |
---|
1683 | viewPoint = new_vp.unit() + delta; |
---|
1684 | |
---|
1685 | #ifdef GEANT4_QT_DEBUG |
---|
1686 | // printf("vp Vector : %f %f %f delta_alpha:%f delta_theta:%f cosalpha:%f sinalpha:%f\n",viewPoint.x(),viewPoint.y(),viewPoint.z(),delta_alpha,delta_theta,cosalpha,sinalpha); |
---|
1687 | // printf("up : %f %f %f\n",up.x(),up.y(),up.z()); |
---|
1688 | // printf("new up : %f %f %f\n",new_up.x(),new_up.y(),new_up.z()); |
---|
1689 | // printf("vp : %f %f %f\n",vp.x(),vp.y(),vp.z()); |
---|
1690 | // printf("new_vp : %f %f %f\n",new_vp.x(),new_vp.y(),new_vp.z()); |
---|
1691 | #endif |
---|
1692 | fVP.SetViewAndLights (viewPoint); |
---|
1693 | updateQWidget(); |
---|
1694 | |
---|
1695 | if (fAutoMove) |
---|
1696 | ((QApplication*)G4Qt::getInstance ())->processEvents(); |
---|
1697 | } |
---|
1698 | |
---|
1699 | fHoldRotateEvent = false; |
---|
1700 | } |
---|
1701 | |
---|
1702 | /** This is the benning of a rescale function. It does nothing for the moment |
---|
1703 | @param aWidth : new width |
---|
1704 | @param aHeight : new height |
---|
1705 | */ |
---|
1706 | void G4OpenGLQtViewer::rescaleImage( |
---|
1707 | int aWidth |
---|
1708 | ,int aHeight |
---|
1709 | ){ |
---|
1710 | #ifdef GEANT4_QT_DEBUG |
---|
1711 | printf("should rescale \n"); |
---|
1712 | #endif |
---|
1713 | GLfloat* feedback_buffer; |
---|
1714 | GLint returned; |
---|
1715 | FILE* file; |
---|
1716 | |
---|
1717 | // feedback_buffer = new GLfloat[size]; |
---|
1718 | // glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer); |
---|
1719 | // glRenderMode (GL_FEEDBACK); |
---|
1720 | |
---|
1721 | // glViewport (0, 0, aWidth, aHeight); |
---|
1722 | // DrawView(); |
---|
1723 | // returned = glRenderMode (GL_RENDER); |
---|
1724 | |
---|
1725 | } |
---|
1726 | |
---|
1727 | /** |
---|
1728 | Generate Vectorial Encapsulated Postscript form image |
---|
1729 | @param aFilename : name of file |
---|
1730 | @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha |
---|
1731 | @param aImage : Image to print |
---|
1732 | */ |
---|
1733 | bool G4OpenGLQtViewer::generateVectorEPS ( |
---|
1734 | QString aFilename |
---|
1735 | ,int aWidth |
---|
1736 | ,int aHeight |
---|
1737 | ,QImage aImage |
---|
1738 | ) |
---|
1739 | { |
---|
1740 | // Print vectored PostScript |
---|
1741 | |
---|
1742 | G4int size = 5000000; |
---|
1743 | |
---|
1744 | GLfloat* feedback_buffer; |
---|
1745 | GLint returned; |
---|
1746 | FILE* file; |
---|
1747 | |
---|
1748 | feedback_buffer = new GLfloat[size]; |
---|
1749 | glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer); |
---|
1750 | glRenderMode (GL_FEEDBACK); |
---|
1751 | |
---|
1752 | int side = aWidth; |
---|
1753 | if (aHeight < aWidth) side = aHeight; |
---|
1754 | glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side); |
---|
1755 | DrawView(); |
---|
1756 | |
---|
1757 | returned = glRenderMode (GL_RENDER); |
---|
1758 | |
---|
1759 | |
---|
1760 | #if QT_VERSION < 0x040000 |
---|
1761 | file = fopen (aFilename.ascii(), "w"); |
---|
1762 | #else |
---|
1763 | file = fopen (aFilename.toStdString().c_str(), "w"); |
---|
1764 | #endif |
---|
1765 | if (file) { |
---|
1766 | spewWireframeEPS (file, returned, feedback_buffer, "rendereps"); |
---|
1767 | } else { |
---|
1768 | #if QT_VERSION < 0x040000 |
---|
1769 | G4cerr << "Could not open "<< aFilename.ascii()<<"\n" << G4endl; |
---|
1770 | #else |
---|
1771 | G4cerr << "Could not open "<< aFilename.toStdString().c_str()<<"\n" << G4endl; |
---|
1772 | #endif |
---|
1773 | } |
---|
1774 | |
---|
1775 | delete[] feedback_buffer; |
---|
1776 | |
---|
1777 | return true; |
---|
1778 | } |
---|
1779 | |
---|
1780 | /** |
---|
1781 | Generate Encapsulated Postscript form image |
---|
1782 | @param aFilename : name of file |
---|
1783 | @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha |
---|
1784 | @param aImage : Image to print |
---|
1785 | */ |
---|
1786 | bool G4OpenGLQtViewer::generateEPS ( |
---|
1787 | QString aFilename |
---|
1788 | ,int aInColor |
---|
1789 | ,QImage aImage |
---|
1790 | ) |
---|
1791 | { |
---|
1792 | // FIXME |
---|
1793 | #ifdef GEANT4_QT_DEBUG |
---|
1794 | printf("saving EPS\n"); |
---|
1795 | #endif |
---|
1796 | |
---|
1797 | FILE* fp; |
---|
1798 | |
---|
1799 | if (aImage.bits () == NULL) |
---|
1800 | return false; |
---|
1801 | |
---|
1802 | #if QT_VERSION < 0x040000 |
---|
1803 | fp = fopen (aFilename.ascii(), "w"); |
---|
1804 | #else |
---|
1805 | fp = fopen (aFilename.toStdString().c_str(), "w"); |
---|
1806 | #endif |
---|
1807 | if (fp == NULL) { |
---|
1808 | return false; |
---|
1809 | } |
---|
1810 | |
---|
1811 | fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n"); |
---|
1812 | #if QT_VERSION < 0x040000 |
---|
1813 | fprintf (fp, "%%%%Title: %s\n", aFilename.ascii()); |
---|
1814 | #else |
---|
1815 | fprintf (fp, "%%%%Title: %s\n", aFilename.toStdString().c_str()); |
---|
1816 | #endif |
---|
1817 | fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n"); |
---|
1818 | fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", aImage.width(), aImage.height()); |
---|
1819 | fprintf (fp, "%%%%EndComments\n"); |
---|
1820 | fprintf (fp, "gsave\n"); |
---|
1821 | fprintf (fp, "/bwproc {\n"); |
---|
1822 | fprintf (fp, " rgbproc\n"); |
---|
1823 | fprintf (fp, " dup length 3 idiv string 0 3 0 \n"); |
---|
1824 | fprintf (fp, " 5 -1 roll {\n"); |
---|
1825 | fprintf (fp, " add 2 1 roll 1 sub dup 0 eq\n"); |
---|
1826 | fprintf (fp, " { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n"); |
---|
1827 | fprintf (fp, " 3 1 roll 5 -1 roll } put 1 add 3 0 \n"); |
---|
1828 | fprintf (fp, " { 2 1 roll } ifelse\n"); |
---|
1829 | fprintf (fp, " }forall\n"); |
---|
1830 | fprintf (fp, " pop pop pop\n"); |
---|
1831 | fprintf (fp, "} def\n"); |
---|
1832 | fprintf (fp, "systemdict /colorimage known not {\n"); |
---|
1833 | fprintf (fp, " /colorimage {\n"); |
---|
1834 | fprintf (fp, " pop\n"); |
---|
1835 | fprintf (fp, " pop\n"); |
---|
1836 | fprintf (fp, " /rgbproc exch def\n"); |
---|
1837 | fprintf (fp, " { bwproc } image\n"); |
---|
1838 | fprintf (fp, " } def\n"); |
---|
1839 | fprintf (fp, "} if\n"); |
---|
1840 | fprintf (fp, "/picstr %d string def\n", aImage.width() * aInColor); |
---|
1841 | fprintf (fp, "%d %d scale\n", aImage.width(), aImage.height()); |
---|
1842 | fprintf (fp, "%d %d %d\n", aImage.width(), aImage.height(), 8); |
---|
1843 | fprintf (fp, "[%d 0 0 %d 0 0]\n", aImage.width(), aImage.height()); |
---|
1844 | fprintf (fp, "{currentfile picstr readhexstring pop}\n"); |
---|
1845 | fprintf (fp, "false %d\n", aInColor); |
---|
1846 | fprintf (fp, "colorimage\n"); |
---|
1847 | |
---|
1848 | |
---|
1849 | int width = aImage.width(); |
---|
1850 | int height = aImage.height(); |
---|
1851 | int depth = aImage.depth(); |
---|
1852 | int size = width*height; |
---|
1853 | |
---|
1854 | if (depth == 1) |
---|
1855 | size = (width+7)/8*height; |
---|
1856 | else if (aInColor == 1) |
---|
1857 | size = size*3; |
---|
1858 | |
---|
1859 | int i = 0; |
---|
1860 | // if ( aInColor ==1 ) { |
---|
1861 | // FIXME : L. Garnier. For the moment 10 dec 2007, I could not find a way |
---|
1862 | // to save correctly grayscale Image. I mean that color or grayscale image |
---|
1863 | // have the same file save size ! |
---|
1864 | |
---|
1865 | /* } else*/ if (depth == 8) { |
---|
1866 | for(int y=height-1; y >=0 ; y--) { |
---|
1867 | const uchar * s = aImage.scanLine(y); |
---|
1868 | for(int x=0; x <width; x++) { |
---|
1869 | QRgb rgb = aImage.color(s[x]); |
---|
1870 | if (aInColor == 1) { |
---|
1871 | fprintf (fp, " %02hx ",(unsigned char)qGray(rgb)); |
---|
1872 | i++; |
---|
1873 | } else { |
---|
1874 | fprintf (fp, " %02hx %02hx %02hx", |
---|
1875 | (unsigned char) qRed(rgb), |
---|
1876 | (unsigned char) qGreen(rgb), |
---|
1877 | (unsigned char) qBlue(rgb)); |
---|
1878 | i += 3; |
---|
1879 | } |
---|
1880 | } |
---|
1881 | fprintf (fp, "\n"); |
---|
1882 | } |
---|
1883 | } else { |
---|
1884 | #if QT_VERSION < 0x040000 |
---|
1885 | bool alpha = aImage.hasAlphaBuffer(); |
---|
1886 | #else |
---|
1887 | bool alpha = aImage.hasAlphaChannel(); |
---|
1888 | for(int y=height-1; y >=0 ; y--) { |
---|
1889 | QRgb * s = (QRgb*)(aImage.scanLine(y)); |
---|
1890 | for(int x=0; x <width; x++) { |
---|
1891 | QRgb rgb = (*s++); |
---|
1892 | if (alpha && qAlpha(rgb) < 0x40) // 25% alpha, convert to white - |
---|
1893 | rgb = qRgb(0xff, 0xff, 0xff); |
---|
1894 | if (aInColor == 1) { |
---|
1895 | fprintf (fp, " %02hx ",(unsigned char)qGray(rgb)); |
---|
1896 | i++; |
---|
1897 | } else { |
---|
1898 | fprintf (fp, " %02hx %02hx %02hx", |
---|
1899 | (unsigned char) qRed(rgb), |
---|
1900 | (unsigned char) qGreen(rgb), |
---|
1901 | (unsigned char) qBlue(rgb)); |
---|
1902 | i += 3; |
---|
1903 | } |
---|
1904 | } |
---|
1905 | fprintf (fp, "\n"); |
---|
1906 | } |
---|
1907 | #endif |
---|
1908 | |
---|
1909 | } |
---|
1910 | |
---|
1911 | fprintf (fp, "grestore\n"); |
---|
1912 | fprintf (fp, "showpage\n"); |
---|
1913 | fclose (fp); |
---|
1914 | |
---|
1915 | return true; |
---|
1916 | } |
---|
1917 | /** |
---|
1918 | Generate Postscript or PDF form image |
---|
1919 | @param aFilename : name of file |
---|
1920 | @param aInColor : numbers of colors : 1->BW 2->RGB |
---|
1921 | @param aImage : Image to print |
---|
1922 | */ |
---|
1923 | bool G4OpenGLQtViewer::generatePS_PDF ( |
---|
1924 | QString aFilename |
---|
1925 | ,int aInColor |
---|
1926 | ,QImage aImage |
---|
1927 | ) |
---|
1928 | { |
---|
1929 | |
---|
1930 | #if QT_VERSION < 0x040000 |
---|
1931 | #ifdef Q_WS_MAC || Q_WS_X11 |
---|
1932 | QPrinter printer; |
---|
1933 | // printer.setPageSize(pageSize); |
---|
1934 | if (aInColor == 1) { |
---|
1935 | printer.setColorMode(QPrinter::GrayScale); |
---|
1936 | } else { |
---|
1937 | printer.setColorMode(QPrinter::Color); |
---|
1938 | } |
---|
1939 | |
---|
1940 | /* FIXME : I don't know which format it will save... |
---|
1941 | if (aFilename.endsWith(".ps")) { |
---|
1942 | printer.setOutputFormat(QPrinter::PostScriptFormat); |
---|
1943 | } else { |
---|
1944 | printer.setOutputFormat(QPrinter::PdfFormat); |
---|
1945 | } |
---|
1946 | */ |
---|
1947 | printer.setOutputFileName(aFilename); |
---|
1948 | // printer.setFullPage ( true); |
---|
1949 | QPainter paint(&printer); |
---|
1950 | paint.drawImage (0,0,aImage ); |
---|
1951 | paint.end(); |
---|
1952 | #else |
---|
1953 | G4cerr << "This fonction is only supported on Mac OsX or X11 with Qt3. Full platform supported with Qt4\n" << G4endl; |
---|
1954 | #endif |
---|
1955 | #else |
---|
1956 | QPrinter printer; |
---|
1957 | // printer.setPageSize(pageSize); |
---|
1958 | |
---|
1959 | // FIXME : L. Garnier 4/12/07 |
---|
1960 | // This is not working, it does nothing. Image is staying in color mode |
---|
1961 | // So I have desactivate the B/W button in GUI |
---|
1962 | if ((!aImage.isGrayscale ()) &&(aInColor ==1 )) { |
---|
1963 | #if QT_VERSION < 0x040000 |
---|
1964 | aImage = aImage.convertDepth(1,Qt::MonoOnly); |
---|
1965 | #else |
---|
1966 | aImage = aImage.convertToFormat ( aImage.format(), Qt::MonoOnly); |
---|
1967 | #endif |
---|
1968 | } |
---|
1969 | |
---|
1970 | |
---|
1971 | if (aFilename.endsWith(".ps")) { |
---|
1972 | #if QT_VERSION > 0x040200 |
---|
1973 | printer.setOutputFormat(QPrinter::PostScriptFormat); |
---|
1974 | #endif |
---|
1975 | } else { |
---|
1976 | #if QT_VERSION > 0x040100 |
---|
1977 | printer.setOutputFormat(QPrinter::PdfFormat); |
---|
1978 | #endif |
---|
1979 | } |
---|
1980 | #if QT_VERSION > 0x040100 |
---|
1981 | printer.setOutputFileName(aFilename); |
---|
1982 | #endif |
---|
1983 | // printer.setFullPage ( true); |
---|
1984 | QPainter paint(&printer); |
---|
1985 | paint.drawImage (0,0,aImage); |
---|
1986 | paint.end(); |
---|
1987 | #endif |
---|
1988 | return true; |
---|
1989 | } |
---|
1990 | |
---|
1991 | |
---|
1992 | |
---|
1993 | void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * event) |
---|
1994 | { |
---|
1995 | if (fHoldKeyEvent) |
---|
1996 | return; |
---|
1997 | |
---|
1998 | fHoldKeyEvent = true; |
---|
1999 | if (event->key() == Qt::Key_Down) { |
---|
2000 | #ifdef GEANT4_QT_DEBUG |
---|
2001 | printf("G4OpenGLQtViewer::G4keyPressEvent Down\n"); |
---|
2002 | #endif |
---|
2003 | } else if (event->key() == Qt::Key_Up) { |
---|
2004 | #ifdef GEANT4_QT_DEBUG |
---|
2005 | printf("G4OpenGLQtViewer::G4keyPressEvent Up\n"); |
---|
2006 | #endif |
---|
2007 | } else if (event->key() == Qt::Key_Plus) { |
---|
2008 | #ifdef GEANT4_QT_DEBUG |
---|
2009 | printf("G4OpenGLQtViewer::G4keyPressEvent Plus\n"); |
---|
2010 | #endif |
---|
2011 | } else if (event->key() == Qt::Key_Minus) { |
---|
2012 | #ifdef GEANT4_QT_DEBUG |
---|
2013 | printf("G4OpenGLQtViewer::G4keyPressEvent Minus\n"); |
---|
2014 | #endif |
---|
2015 | } |
---|
2016 | if (event->modifiers() & Qt::AltModifier ) { |
---|
2017 | #ifdef GEANT4_QT_DEBUG |
---|
2018 | printf("G4OpenGLQtViewer::G4keyPressEvent Alt\n"); |
---|
2019 | #endif |
---|
2020 | } else if (event->modifiers() & Qt::ShiftModifier) { |
---|
2021 | #ifdef GEANT4_QT_DEBUG |
---|
2022 | printf("G4OpenGLQtViewer::G4keyPressEvent Shift\n"); |
---|
2023 | #endif |
---|
2024 | } |
---|
2025 | |
---|
2026 | #if QT_VERSION < 0x040000 |
---|
2027 | if ((event->key() == Qt::Key_Down) && (event->state() & Qt::AltButton )) { // go backward |
---|
2028 | #else |
---|
2029 | if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::AltModifier )) { // go backward |
---|
2030 | #endif |
---|
2031 | |
---|
2032 | moveScene(0,0,1,false); |
---|
2033 | } |
---|
2034 | #if QT_VERSION < 0x040000 |
---|
2035 | else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::AltButton)) { // go forward |
---|
2036 | #else |
---|
2037 | else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::AltModifier)) { // go forward |
---|
2038 | #endif |
---|
2039 | moveScene(0,0,-1,false); |
---|
2040 | } |
---|
2041 | #if QT_VERSION < 0x040000 |
---|
2042 | if ((event->key() == Qt::Key_Down) && (event->state() & Qt::ShiftButton)) { // rotate phi |
---|
2043 | #else |
---|
2044 | if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi |
---|
2045 | #endif |
---|
2046 | rotateScene(0,-1); |
---|
2047 | } |
---|
2048 | #if QT_VERSION < 0x040000 |
---|
2049 | else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::ShiftButton)) { // rotate phi |
---|
2050 | #else |
---|
2051 | else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi |
---|
2052 | #endif |
---|
2053 | rotateScene(0,1); |
---|
2054 | } |
---|
2055 | #if QT_VERSION < 0x040000 |
---|
2056 | if ((event->key() == Qt::Key_Left) && (event->state() & Qt::ShiftButton)) { // rotate theta |
---|
2057 | #else |
---|
2058 | if ((event->key() == Qt::Key_Left) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta |
---|
2059 | #endif |
---|
2060 | rotateScene(1,0); |
---|
2061 | } |
---|
2062 | #if QT_VERSION < 0x040000 |
---|
2063 | else if ((event->key() == Qt::Key_Right) && (event->state() & Qt::ShiftButton)) { // rotate theta |
---|
2064 | #else |
---|
2065 | else if ((event->key() == Qt::Key_Right) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta |
---|
2066 | #endif |
---|
2067 | rotateScene(-1,0); |
---|
2068 | } |
---|
2069 | |
---|
2070 | #if QT_VERSION < 0x040000 |
---|
2071 | if ((event->state() & Qt::AltButton)) { |
---|
2072 | #else |
---|
2073 | if ((event->modifiers() & Qt::AltModifier)) { |
---|
2074 | #endif |
---|
2075 | if (event->key() == Qt::Key_Plus) { |
---|
2076 | fDeltaRotation = fDeltaRotation/0.7; |
---|
2077 | } |
---|
2078 | else if (event->key() == Qt::Key_Minus) { |
---|
2079 | fDeltaRotation = fDeltaRotation*0.7; |
---|
2080 | } |
---|
2081 | } else { |
---|
2082 | if (event->key() == Qt::Key_Plus) { |
---|
2083 | fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+fDeltaZoom)); |
---|
2084 | updateQWidget(); |
---|
2085 | } |
---|
2086 | else if (event->key() == Qt::Key_Minus) { |
---|
2087 | fVP.SetZoomFactor(fVP.GetZoomFactor()*(1-fDeltaZoom)); |
---|
2088 | updateQWidget(); |
---|
2089 | } |
---|
2090 | } |
---|
2091 | |
---|
2092 | |
---|
2093 | if (event->key() == Qt::Key_Escape) { // escaped from full screen |
---|
2094 | #if QT_VERSION >= 0x030200 |
---|
2095 | if (GLWindow->isFullScreen()) { |
---|
2096 | #if QT_VERSION < 0x040000 |
---|
2097 | fFullScreenOn->activated(); |
---|
2098 | #else |
---|
2099 | fFullScreenOn->trigger(); |
---|
2100 | #endif |
---|
2101 | } |
---|
2102 | #endif |
---|
2103 | } |
---|
2104 | |
---|
2105 | if ((event->key() == Qt::Key_Return) || (event->key() == Qt::Key_Enter)){ // end of video |
---|
2106 | G4cout << "Stop Recording \n" << G4endl; |
---|
2107 | G4cout << "Saving /temp/output.mpg \n" << G4endl; |
---|
2108 | saveVideo("/temp/output.mpg"); |
---|
2109 | fRecordFrames = false; |
---|
2110 | } |
---|
2111 | if (event->key() == Qt::Key_Space){ // start/pause of video |
---|
2112 | |
---|
2113 | // first time, if parameters are wrong, display parameters dialog and return |
---|
2114 | if ((fRecordFrames == false) && (getEncoderPath() == NULL)) { |
---|
2115 | showMovieParametersDialog(); |
---|
2116 | return; |
---|
2117 | } |
---|
2118 | fRecordFrames = !fRecordFrames; |
---|
2119 | if (fRecordFrames) { |
---|
2120 | G4cout << " Start Recording \n" << G4endl; |
---|
2121 | } else { |
---|
2122 | G4cout << "Pause Recording \n" << G4endl; |
---|
2123 | } |
---|
2124 | } |
---|
2125 | |
---|
2126 | // with no modifiers |
---|
2127 | #if QT_VERSION < 0x040000 |
---|
2128 | if (event->state() == Qt::NoButton) { |
---|
2129 | #else |
---|
2130 | if (event->modifiers() == Qt::NoModifier) { |
---|
2131 | #endif |
---|
2132 | if (event->key() == Qt::Key_Down) { // go down |
---|
2133 | moveScene(0,1,0,false); |
---|
2134 | } |
---|
2135 | else if (event->key() == Qt::Key_Up) { // go up |
---|
2136 | moveScene(0,-1,0,false); |
---|
2137 | } |
---|
2138 | if (event->key() == Qt::Key_Left) { // go left |
---|
2139 | moveScene(-1,0,0,false); |
---|
2140 | } |
---|
2141 | else if (event->key() == Qt::Key_Right) { // go right |
---|
2142 | moveScene(1,0,0,false); |
---|
2143 | } |
---|
2144 | } |
---|
2145 | fHoldKeyEvent = false; |
---|
2146 | } |
---|
2147 | |
---|
2148 | |
---|
2149 | /** @return encoder path or "" if it does not exist |
---|
2150 | */ |
---|
2151 | QString G4OpenGLQtViewer::getEncoderPath() { |
---|
2152 | return fEncoderPath; |
---|
2153 | } |
---|
2154 | |
---|
2155 | |
---|
2156 | /** |
---|
2157 | * set the new encoder path |
---|
2158 | * @return "" if correct. The error otherwise |
---|
2159 | */ |
---|
2160 | QString G4OpenGLQtViewer::setEncoderPath(QString path) { |
---|
2161 | if (path == "") { |
---|
2162 | return "File does not exist"; |
---|
2163 | } |
---|
2164 | QFile *f = new QFile(path); |
---|
2165 | if (!f->exists()) { |
---|
2166 | return "File does not exist"; |
---|
2167 | } |
---|
2168 | if (!(f->permissions() & QFile::ExeUser)) { |
---|
2169 | return "File exist but is not executable"; |
---|
2170 | } |
---|
2171 | fEncoderPath = path; |
---|
2172 | return ""; |
---|
2173 | } |
---|
2174 | |
---|
2175 | /** |
---|
2176 | * set the temp folder path |
---|
2177 | * @return "" if correct. The error otherwise |
---|
2178 | */ |
---|
2179 | QString G4OpenGLQtViewer::setTempFolderPath(QString path) { |
---|
2180 | |
---|
2181 | if (path == "") { |
---|
2182 | return "Path does not exist"; |
---|
2183 | } |
---|
2184 | QDir *d = new QDir(path); |
---|
2185 | if (!d->exists(path)) { |
---|
2186 | return "Path does not exist"; |
---|
2187 | } |
---|
2188 | |
---|
2189 | d->setFilter( QDir::Dirs | QDir::Readable | QDir::Writable ); |
---|
2190 | QStringList subDirList = d->entryList(); |
---|
2191 | bool found = false; |
---|
2192 | |
---|
2193 | for (QStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) { |
---|
2194 | const QString currentDir = *it; |
---|
2195 | |
---|
2196 | if (currentDir == ".") { // we found it |
---|
2197 | found = true; |
---|
2198 | } |
---|
2199 | } |
---|
2200 | |
---|
2201 | if (!found) |
---|
2202 | return "Path exist, but is not write accessible"; |
---|
2203 | |
---|
2204 | fTempFolderPath = path; |
---|
2205 | return ""; |
---|
2206 | } |
---|
2207 | |
---|
2208 | /** @return the temp folder path or "" if it does not exist |
---|
2209 | */ |
---|
2210 | QString G4OpenGLQtViewer::getTempFolderPath() { |
---|
2211 | return fTempFolderPath; |
---|
2212 | } |
---|
2213 | |
---|
2214 | /** |
---|
2215 | * set the save file name path |
---|
2216 | * @return "" if correct. The error otherwise |
---|
2217 | */ |
---|
2218 | QString G4OpenGLQtViewer::setSaveFileName(QString path) { |
---|
2219 | |
---|
2220 | if (path == "") { |
---|
2221 | return "Path does not exist"; |
---|
2222 | } |
---|
2223 | QDir *d = new QDir(path); |
---|
2224 | if (!d->exists(path)) { |
---|
2225 | return "Path does not exist"; |
---|
2226 | } |
---|
2227 | |
---|
2228 | d->setFilter( QDir::Dirs | QDir::Readable | QDir::Writable ); |
---|
2229 | QStringList subDirList = d->entryList(); |
---|
2230 | bool found = false; |
---|
2231 | |
---|
2232 | for (QStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) { |
---|
2233 | const QString currentDir = *it; |
---|
2234 | |
---|
2235 | if (currentDir == ".") { // we found it |
---|
2236 | found = true; |
---|
2237 | } |
---|
2238 | } |
---|
2239 | |
---|
2240 | if (!found) |
---|
2241 | return "Path exist, but is not write accessible"; |
---|
2242 | |
---|
2243 | fSaveFileName = path; |
---|
2244 | return ""; |
---|
2245 | } |
---|
2246 | |
---|
2247 | /** @return the save file path |
---|
2248 | */ |
---|
2249 | QString G4OpenGLQtViewer::getSaveFileName() { |
---|
2250 | return fSaveFileName ; |
---|
2251 | } |
---|
2252 | |
---|
2253 | /** Create a Qt_temp folder in the temp folder given |
---|
2254 | */ |
---|
2255 | bool G4OpenGLQtViewer::createTempFolder() { |
---|
2256 | fMovieTempFolderPath = ""; |
---|
2257 | |
---|
2258 | //check |
---|
2259 | if (setTempFolderPath(fTempFolderPath) == "") { |
---|
2260 | return false; |
---|
2261 | } |
---|
2262 | QString path = QString("QtMovie_")+QDateTime::currentDateTime ().toString("dd--MM--yyyy_hh-mm-ss"); |
---|
2263 | QDir *d = new QDir(fTempFolderPath); |
---|
2264 | // check if it is already present |
---|
2265 | if (d->exists(path)) { |
---|
2266 | return false; |
---|
2267 | } |
---|
2268 | if (d.mkdir(path)){ |
---|
2269 | #ifdef GEANT4_QT_DEBUG |
---|
2270 | printf("G4OpenGLQtViewer::removeTempFolder. remove file %s\n",fMovieTempFolderPath.toStdString().c_str()); |
---|
2271 | #endif |
---|
2272 | fMovieTempFolderPath = path; |
---|
2273 | return true; |
---|
2274 | } |
---|
2275 | return false: |
---|
2276 | } |
---|
2277 | |
---|
2278 | /** Remove the Qt_temp folder in the temp folder |
---|
2279 | */ |
---|
2280 | bool G4OpenGLQtViewer::removeTempFolder() { |
---|
2281 | // remove files in Qt_temp folder |
---|
2282 | QDir *d = new QDir(fTempFolderPath+fMovieTempFolderPath); |
---|
2283 | if (!d->exists(path)) { |
---|
2284 | return false; // already remove |
---|
2285 | } |
---|
2286 | |
---|
2287 | d->setFilter( QDir::Dirs | QDir::Readable | QDir::Writable ); |
---|
2288 | QStringList subDirList = d->entryList(); |
---|
2289 | bool found = false; |
---|
2290 | |
---|
2291 | for (QStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) { |
---|
2292 | const QString currentDir = *it; |
---|
2293 | #ifdef GEANT4_QT_DEBUG |
---|
2294 | printf("G4OpenGLQtViewer::removeTempFolder. remove file %s\n",currentDir.toStdString().c_str()); |
---|
2295 | #endif |
---|
2296 | } |
---|
2297 | if (d.rmdir(fTempFolderPath+fMovieTempFolderPath)) { |
---|
2298 | return true; |
---|
2299 | } |
---|
2300 | return false; |
---|
2301 | } |
---|
2302 | |
---|
2303 | /** Init the movie parameters. Temp dir and encoder path |
---|
2304 | */ |
---|
2305 | void G4OpenGLQtViewer::initMovieParameters() { |
---|
2306 | //init encoder |
---|
2307 | |
---|
2308 | //look for encoderPath |
---|
2309 | QProcess search; |
---|
2310 | search.setReadChannelMode(QProcess::MergedChannels); |
---|
2311 | search.start ("which mpeg_encode"); |
---|
2312 | |
---|
2313 | if (search.waitForFinished()) { |
---|
2314 | fEncoderPath = QString(QString::fromLocal8Bit(search.readAll())).trimmed(); |
---|
2315 | // if not found, return "not found" |
---|
2316 | if (fEncoderPath.contains(" ")) { |
---|
2317 | fEncoderPath = ""; |
---|
2318 | } else if (!fEncoderPath.contains("mpeg_encode")) { |
---|
2319 | fEncoderPath = ""; |
---|
2320 | } |
---|
2321 | } |
---|
2322 | setEncoderPath(fEncoderPath); |
---|
2323 | // init temp folder |
---|
2324 | setTempFolderPath(QDir::temp ().absolutePath ()); |
---|
2325 | } |
---|
2326 | |
---|
2327 | |
---|
2328 | bool G4OpenGLQtViewer::hasPendingEvents () { |
---|
2329 | return ((QApplication*)G4Qt::getInstance ())->hasPendingEvents (); |
---|
2330 | } |
---|
2331 | |
---|
2332 | bool G4OpenGLQtViewer::saveVideo (QString outputName) { |
---|
2333 | |
---|
2334 | // save the parameter file |
---|
2335 | FILE* fp; |
---|
2336 | fp = fopen ("/temp/parameter_file.par", "w"); |
---|
2337 | |
---|
2338 | if (fp == NULL) { |
---|
2339 | return false; |
---|
2340 | } |
---|
2341 | |
---|
2342 | fprintf (fp,"# parameter file template with lots of comments to assist you\n"); |
---|
2343 | fprintf (fp,"#\n"); |
---|
2344 | fprintf (fp,"# you can use this as a template, copying it to a separate file then modifying\n"); |
---|
2345 | fprintf (fp,"# the copy\n"); |
---|
2346 | fprintf (fp,"#\n"); |
---|
2347 | fprintf (fp,"#\n"); |
---|
2348 | fprintf (fp,"# any line beginning with '#' is a comment\n"); |
---|
2349 | fprintf (fp,"#\n"); |
---|
2350 | fprintf (fp,"# no line should be longer than 255 characters\n"); |
---|
2351 | fprintf (fp,"#\n"); |
---|
2352 | fprintf (fp,"#\n"); |
---|
2353 | fprintf (fp,"# general format of each line is:\n"); |
---|
2354 | fprintf (fp,"# \n"); |
---|
2355 | fprintf (fp,"#\n"); |
---|
2356 | fprintf (fp,"# lines can generally be in any order\n"); |
---|
2357 | fprintf (fp,"#\n"); |
---|
2358 | fprintf (fp,"# an exception is the option 'INPUT' which must be followed by input\n"); |
---|
2359 | fprintf (fp,"# files in the order in which they must appear, followed by 'END_INPUT'\n"); |
---|
2360 | fprintf (fp,"#\n"); |
---|
2361 | fprintf (fp,"# Also, if you use the `command` method of generating input file names,\n"); |
---|
2362 | fprintf (fp,"# the command will only be executed in the INPUT_DIR if INPUT_DIR preceeds\n"); |
---|
2363 | fprintf (fp,"# the INPUT parameter.\n"); |
---|
2364 | fprintf (fp,"#\n"); |
---|
2365 | fprintf (fp,"# MUST be in UPPER CASE\n"); |
---|
2366 | fprintf (fp,"#\n"); |
---|
2367 | fprintf (fp,"\n"); |
---|
2368 | fprintf (fp,"# Pattern affects speed, quality and compression. See the User's Guide\n"); |
---|
2369 | fprintf (fp,"# for more info.\n"); |
---|
2370 | fprintf (fp,"\n"); |
---|
2371 | fprintf (fp,"PATTERN IBBPBBPBBPBBPBBP\n"); |
---|
2372 | #if QT_VERSION < 0x040000 |
---|
2373 | fprintf (fp,"OUTPUT %s\n",outputName.ascii()); |
---|
2374 | #else |
---|
2375 | fprintf (fp,"OUTPUT %s\n",outputName.toStdString().c_str()); |
---|
2376 | #endif |
---|
2377 | fprintf (fp,"\n"); |
---|
2378 | fprintf (fp,"# mpeg_encode really only accepts 3 different file formats, but using a\n"); |
---|
2379 | fprintf (fp,"# conversion statement it can effectively handle ANY file format\n"); |
---|
2380 | fprintf (fp,"#\n"); |
---|
2381 | fprintf (fp,"# You must specify the type of the input files. The choices are:\n"); |
---|
2382 | fprintf (fp,"# YUV, PPM, JMOVIE, Y, JPEG, PNM\n"); |
---|
2383 | fprintf (fp,"# (must be upper case)\n"); |
---|
2384 | fprintf (fp,"#\n"); |
---|
2385 | fprintf (fp,"BASE_FILE_FORMAT PPM\n"); |
---|
2386 | fprintf (fp,"\n"); |
---|
2387 | fprintf (fp,"#\n"); |
---|
2388 | fprintf (fp,"# if YUV format (or using parallel version), must provide width and height\n"); |
---|
2389 | fprintf (fp,"# YUV_SIZE widthxheight\n"); |
---|
2390 | fprintf (fp,"# this option is ignored if BASE_FILE_FORMAT is not YUV and you're running\n"); |
---|
2391 | fprintf (fp,"# on just one machine\n"); |
---|
2392 | fprintf (fp,"#\n"); |
---|
2393 | fprintf (fp,"YUV_SIZE 352x240\n"); |
---|
2394 | fprintf (fp,"\n"); |
---|
2395 | fprintf (fp,"# If you are using YUV, there are different supported file formats.\n"); |
---|
2396 | fprintf (fp,"# EYUV or UCB are the same as previous versions of this encoder.\n"); |
---|
2397 | fprintf (fp,"# (All the Y's, then U's then V's, in 4:2:0 subsampling.)\n"); |
---|
2398 | fprintf (fp,"# Other formats, such as Abekas, Phillips, or a general format are\n"); |
---|
2399 | fprintf (fp,"# permissible, the general format is a string of Y's, U's, and V's\n"); |
---|
2400 | fprintf (fp,"# to specify the file order.\n"); |
---|
2401 | fprintf (fp,"\n"); |
---|
2402 | fprintf (fp,"INPUT_FORMAT UCB\n"); |
---|
2403 | fprintf (fp,"\n"); |
---|
2404 | fprintf (fp,"# the conversion statement\n"); |
---|
2405 | fprintf (fp,"#\n"); |
---|
2406 | fprintf (fp,"# Each occurrence of '*' will be replaced by the input file\n"); |
---|
2407 | fprintf (fp,"#\n"); |
---|
2408 | fprintf (fp,"# e.g., if you have a bunch of GIF files, then this might be:\n"); |
---|
2409 | fprintf (fp,"# INPUT_CONVERT giftoppm *\n"); |
---|
2410 | fprintf (fp,"#\n"); |
---|
2411 | fprintf (fp,"# e.g., if you have a bunch of files like a.Y a.U a.V, etc., then:\n"); |
---|
2412 | fprintf (fp,"# INPUT_CONVERT cat *.Y *.U *.V\n"); |
---|
2413 | fprintf (fp,"#\n"); |
---|
2414 | fprintf (fp,"# e.g., if you are grabbing from laser disc you might have something like\n"); |
---|
2415 | fprintf (fp,"# INPUT_CONVERT goto frame *; grabppm\n"); |
---|
2416 | fprintf (fp,"# 'INPUT_CONVERT *' means the files are already in the base file format\n"); |
---|
2417 | fprintf (fp,"#\n"); |
---|
2418 | fprintf (fp,"INPUT_CONVERT * \n"); |
---|
2419 | fprintf (fp,"\n"); |
---|
2420 | fprintf (fp,"# number of frames in a GOP.\n"); |
---|
2421 | fprintf (fp,"#\n"); |
---|
2422 | fprintf (fp,"# since each GOP must have at least one I-frame, the encoder will find the\n"); |
---|
2423 | fprintf (fp,"# the first I-frame after GOP_SIZE frames to start the next GOP\n"); |
---|
2424 | fprintf (fp,"#\n"); |
---|
2425 | fprintf (fp,"# later, will add more flexible GOP signalling\n"); |
---|
2426 | fprintf (fp,"#\n"); |
---|
2427 | fprintf (fp,"GOP_SIZE 16\n"); |
---|
2428 | fprintf (fp,"\n"); |
---|
2429 | fprintf (fp,"# number of slices in a frame\n"); |
---|
2430 | fprintf (fp,"#\n"); |
---|
2431 | fprintf (fp,"# 1 is a good number. another possibility is the number of macroblock rows\n"); |
---|
2432 | fprintf (fp,"# (which is the height divided by 16)\n"); |
---|
2433 | fprintf (fp,"#\n"); |
---|
2434 | fprintf (fp,"SLICES_PER_FRAME 1\n"); |
---|
2435 | fprintf (fp,"\n"); |
---|
2436 | fprintf (fp,"# directory to get all input files from (makes this file easier to read)\n"); |
---|
2437 | fprintf (fp,"INPUT_DIR /temp\n"); |
---|
2438 | fprintf (fp,"\n"); |
---|
2439 | fprintf (fp,"# There are a bunch of ways to specify the input files.\n"); |
---|
2440 | fprintf (fp,"# from a simple one-per-line listing, to the following \n"); |
---|
2441 | fprintf (fp,"# way of numbering them. See the manual for more information.\n"); |
---|
2442 | fprintf (fp,"INPUT\n"); |
---|
2443 | fprintf (fp,"# '*' is replaced by the numbers 01, 02, 03, 04\n"); |
---|
2444 | fprintf (fp,"# if I instead do [01-11], it would be 01, 02, ..., 09, 10, 11\n"); |
---|
2445 | fprintf (fp,"# if I instead do [1-11], it would be 1, 2, 3, ..., 9, 10, 11\n"); |
---|
2446 | fprintf (fp,"# if I instead do [1-11+3], it would be 1, 4, 7, 10\n"); |
---|
2447 | fprintf (fp,"# the program assumes none of your input files has a name ending in ']'\n"); |
---|
2448 | fprintf (fp,"# if you do, too bad!!!\n"); |
---|
2449 | fprintf (fp,"#\n"); |
---|
2450 | fprintf (fp,"#\n"); |
---|
2451 | fprintf (fp,"Test*.ppm [0-%d]\n",fRecordFrameNumber); |
---|
2452 | fprintf (fp,"# can have more files here if you want...there is no limit on the number\n"); |
---|
2453 | fprintf (fp,"# of files\n"); |
---|
2454 | fprintf (fp,"END_INPUT\n"); |
---|
2455 | fprintf (fp,"\n"); |
---|
2456 | fprintf (fp,"\n"); |
---|
2457 | fprintf (fp,"\n"); |
---|
2458 | fprintf (fp,"# Many of the remaining options have to do with the motion search and qscale\n"); |
---|
2459 | fprintf (fp,"\n"); |
---|
2460 | fprintf (fp,"# FULL or HALF -- must be upper case\n"); |
---|
2461 | fprintf (fp,"# Should be FULL for computer generated images\n"); |
---|
2462 | fprintf (fp,"PIXEL FULL\n"); |
---|
2463 | fprintf (fp,"\n"); |
---|
2464 | fprintf (fp,"# means +/- this many pixels for both P and B frame searches\n"); |
---|
2465 | fprintf (fp,"# specify two numbers if you wish to serc different ranges in the two.\n"); |
---|
2466 | fprintf (fp,"RANGE 10\n"); |
---|
2467 | fprintf (fp,"\n"); |
---|
2468 | fprintf (fp,"# The two search algorithm parameters below mostly affect speed,\n"); |
---|
2469 | fprintf (fp,"# with some affect on compression and almost none on quality.\n"); |
---|
2470 | fprintf (fp,"\n"); |
---|
2471 | fprintf (fp,"# this must be one of {EXHAUSTIVE, SUBSAMPLE, LOGARITHMIC}\n"); |
---|
2472 | fprintf (fp,"PSEARCH_ALG LOGARITHMIC\n"); |
---|
2473 | fprintf (fp,"\n"); |
---|
2474 | fprintf (fp,"# this must be one of {SIMPLE, CROSS2, EXHAUSTIVE}\n"); |
---|
2475 | fprintf (fp,"#\n"); |
---|
2476 | fprintf (fp,"# note that EXHAUSTIVE is really, really, really slow\n"); |
---|
2477 | fprintf (fp,"#\n"); |
---|
2478 | fprintf (fp,"BSEARCH_ALG SIMPLE\n"); |
---|
2479 | fprintf (fp,"\n"); |
---|
2480 | fprintf (fp,"#\n"); |
---|
2481 | fprintf (fp,"# these specify the q-scale for I, P, and B frames\n"); |
---|
2482 | fprintf (fp,"# (values must be between 1 and 31)\n"); |
---|
2483 | fprintf (fp,"# These are the Qscale values for the entire frame in variable bit-rate\n"); |
---|
2484 | fprintf (fp,"# mode, and starting points (but not important) for constant bit rate\n"); |
---|
2485 | fprintf (fp,"#\n"); |
---|
2486 | fprintf (fp,"\n"); |
---|
2487 | fprintf (fp,"# Qscale (Quantization scale) affects quality and compression,\n"); |
---|
2488 | fprintf (fp,"# but has very little effect on speed.\n"); |
---|
2489 | fprintf (fp,"\n"); |
---|
2490 | fprintf (fp,"IQSCALE 4\n"); |
---|
2491 | fprintf (fp,"PQSCALE 5\n"); |
---|
2492 | fprintf (fp,"BQSCALE 12\n"); |
---|
2493 | fprintf (fp,"\n"); |
---|
2494 | fprintf (fp,"# this must be ORIGINAL or DECODED\n"); |
---|
2495 | fprintf (fp,"REFERENCE_FRAME ORIGINAL\n"); |
---|
2496 | fprintf (fp,"\n"); |
---|
2497 | fprintf (fp,"# for parallel parameters see parallel.param in the exmaples subdirectory\n"); |
---|
2498 | fprintf (fp,"\n"); |
---|
2499 | fprintf (fp,"# if you want constant bit-rate mode, specify it as follows (number is bits/sec):\n"); |
---|
2500 | fprintf (fp,"#BIT_RATE 1000000\n"); |
---|
2501 | fprintf (fp,"\n"); |
---|
2502 | fprintf (fp,"# To specify the buffer size (327680 is default, measused in bits, for 16bit words)\n"); |
---|
2503 | fprintf (fp,"BUFFER_SIZE 327680\n"); |
---|
2504 | fprintf (fp,"\n"); |
---|
2505 | fprintf (fp,"# The frame rate is the number of frames/second (legal values:\n"); |
---|
2506 | fprintf (fp,"# 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60\n"); |
---|
2507 | fprintf (fp,"FRAME_RATE 30\n"); |
---|
2508 | fprintf (fp,"\n"); |
---|
2509 | fprintf (fp,"# There are many more options, see the users manual for examples....\n"); |
---|
2510 | fprintf (fp,"# ASPECT_RATIO, USER_DATA, GAMMA, IQTABLE, etc.\n"); |
---|
2511 | fprintf (fp,"\n"); |
---|
2512 | fprintf (fp,"\n"); |
---|
2513 | fclose (fp); |
---|
2514 | |
---|
2515 | QProcess::execute (fEncoderPath, QStringList("/temp/parameter_file.par")); |
---|
2516 | return true; |
---|
2517 | } |
---|
2518 | |
---|
2519 | /* |
---|
2520 | |
---|
2521 | void MultiLayer::exportToSVG(const QString& fname) |
---|
2522 | { |
---|
2523 | QPicture picture; |
---|
2524 | QPainter p(&picture); |
---|
2525 | for (int i=0;i<(int)graphsList->count();i++) |
---|
2526 | { |
---|
2527 | Graph *gr=(Graph *)graphsList->at(i); |
---|
2528 | Plot *myPlot= (Plot *)gr->plotWidget(); |
---|
2529 | |
---|
2530 | QPoint pos=gr->pos(); |
---|
2531 | |
---|
2532 | int width=int(myPlot->frameGeometry().width()); |
---|
2533 | int height=int(myPlot->frameGeometry().height()); |
---|
2534 | |
---|
2535 | myPlot->print(&p, QRect(pos,QSize(width,height))); |
---|
2536 | } |
---|
2537 | |
---|
2538 | p.end(); |
---|
2539 | picture.save(fname, "svg"); |
---|
2540 | } |
---|
2541 | */ |
---|
2542 | #endif |
---|