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