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