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