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