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