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