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