// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // // $Id: G4OpenGLQtViewer.cc 77557 2013-11-26 08:57:39Z gcosmo $ // // // G4OpenGLQtViewer : Class to provide Qt specific // functionality for OpenGL in GEANT4 // // 27/06/2003 : G.Barrand : implementation (at last !). #ifdef G4VIS_BUILD_OPENGLQT_DRIVER #include "G4OpenGLQtViewer.hh" #include "G4OpenGLSceneHandler.hh" #include "G4VSolid.hh" #include "G4OpenGLQtExportDialog.hh" #include "G4OpenGLQtMovieDialog.hh" #include "G4Qt.hh" #include "G4UIQt.hh" #include "G4UImanager.hh" #include "G4UIcommandTree.hh" #include "G4LogicalVolumeStore.hh" #include "G4PhysicalVolumeStore.hh" #include "G4VisCommandsGeometrySet.hh" #include "G4PhysicalVolumeModel.hh" #include "G4Text.hh" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // include #include #include #include //include #include #include #include #include #include ////////////////////////////////////////////////////////////////////////////// void G4OpenGLQtViewer::CreateMainWindow ( QGLWidget* glWidget ,const QString& name ) ////////////////////////////////////////////////////////////////////////////// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// { if(fWindow) return; //Done. fWindow = glWidget ; // fWindow->makeCurrent(); G4Qt* interactorManager = G4Qt::getInstance (); ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY()); // FIXME L.Garnier 9/11/09 Has to be check !!! // Qt UI with Qt Vis // Qt UI with X Vis // X UI with Qt Vis // X UI with X Vis // Ne marche pas avec un UIBatch !! (ecran blanc) // return false if G4UIQt was not launch G4UImanager* UI = G4UImanager::GetUIpointer(); if (UI == NULL) return; if (! static_cast (UI->GetG4UIWindow())) { // NO UI, should be batch mode fBatchMode = true; return; } fUiQt = static_cast (UI->GetG4UIWindow()); bool isTabbedView = false; if ( fUiQt) { if (!fBatchMode) { if (!interactorManager->IsExternalApp()) { isTabbedView = fUiQt->AddTabWidget((QWidget*)fWindow,name,getWinWidth(),getWinHeight()); fUISceneTreeComponentsTBWidget = fUiQt->GetSceneTreeComponentsTBWidget(); isTabbedView = true; } } } #ifdef G4DEBUG_VIS_OGL else { printf("G4OpenGLQtViewer::CreateMainWindow :: UIQt NOt found \n"); } #endif if (!isTabbedView) { // we have to do a dialog QWidget *myParent = getParentWidget(); #ifdef G4DEBUG_VIS_OGL printf("G4OpenGLQtViewer::CreateMainWindow :: getParent OK \n"); #endif if (myParent != NULL) { glWidget->setParent(myParent); } QHBoxLayout *mainLayout = new QHBoxLayout(); mainLayout->setMargin(0); mainLayout->setSpacing(0); mainLayout->addWidget(fWindow); if (fGLWindow->inherits("QMainWindow")) { fGLWindow->setWindowTitle( name); } fGLWindow->setLayout(mainLayout); //useful for MACOSX, we have to compt the menuBar height int offset = QApplication::desktop()->height() - QApplication::desktop()->availableGeometry().height(); G4int YPos= fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height()); if (fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height())< offset) { YPos = offset; } #ifdef G4DEBUG_VIS_OGL printf("G4OpenGLQtViewer::CreateMainWindow :: resizing to %d %d \n",getWinWidth(), getWinHeight()); #endif fGLWindow->move(fVP.GetWindowAbsoluteLocationHintX(QApplication::desktop()->width()),YPos); fGLWindow->show(); } else { fGLWindow = fWindow; } if(!fWindow) return; if (!fContextMenu) createPopupMenu(); } ////////////////////////////////////////////////////////////////////////////// G4OpenGLQtViewer::G4OpenGLQtViewer ( G4OpenGLSceneHandler& scene ) :G4VViewer (scene, -1) ,G4OpenGLViewer (scene) ,fWindow(NULL) ,fGLWindow(NULL) ,fRecordFrameNumber(0) ,fContextMenu(0) ,fDeltaDepth(0.01) ,fDeltaZoom(0.05) ,fHoldKeyEvent(false) ,fHoldMoveEvent(false) ,fHoldRotateEvent(false) ,fAutoMove(false) ,fEncoderPath("") ,fTempFolderPath("") ,fMovieTempFolderPath("") ,fSaveFileName("") ,fParameterFileName("ppmtompeg_encode_parameter_file.par") ,fMovieParametersDialog(NULL) ,fRecordingStep(WAIT) ,fProcess(NULL) ,fNbMaxFramesPerSec(100) ,fNbMaxAnglePerSec(360) ,fLaunchSpinDelay(100) ,fUISceneTreeComponentsTBWidget(NULL) ,fNoKeyPress(true) ,fAltKeyPress(false) ,fControlKeyPress(false) ,fShiftKeyPress(false) ,fBatchMode(false) ,fCheckSceneTreeComponentSignalLock(false) ,fSceneTreeComponentTreeWidget(NULL) ,fOldSceneTreeComponentTreeWidget(NULL) ,fSceneTreeWidget(NULL) ,fPVRootNodeCreate(false) ,fHelpLine(NULL) ,fNbRotation(0) ,fTimeRotation(0) ,fTouchableVolumes("Touchables") ,fShortcutsDialog(NULL) ,fSceneTreeDepthSlider(NULL) ,fSceneTreeDepth(1) ,fModelShortNameItem(NULL) ,fMaxPOindexInserted(-1) ,fUiQt(NULL) ,signalMapperMouse(NULL) ,signalMapperSurface(NULL) { // launch Qt if not if (QCoreApplication::instance () == NULL) { fBatchMode = true; } G4Qt::getInstance (); fLastPos3 = QPoint(-1,-1); fLastPos2 = QPoint(-1,-1); fLastPos1 = QPoint(-1,-1); initMovieParameters(); fLastEventTime = new QTime(); signalMapperMouse = new QSignalMapper(this); signalMapperSurface = new QSignalMapper(this); // Set default path and format fFileSavePath = QDir::currentPath(); fDefaultSaveFileFormat = "png"; #ifdef G4DEBUG_VIS_OGL printf("G4OpenGLQtViewer::G4OpenGLQtViewer END\n"); #endif } ////////////////////////////////////////////////////////////////////////////// G4OpenGLQtViewer::~G4OpenGLQtViewer ( ) ////////////////////////////////////////////////////////////////////////////// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// { // remove scene tree from layout // Delete all the existing buttons in the layout QLayoutItem *wItem; if (fSceneTreeWidget != NULL) { if (fSceneTreeWidget->layout() != NULL) { while ((wItem = fSceneTreeWidget->layout()->takeAt(0)) != 0) { delete wItem->widget(); delete wItem; } } if (fUISceneTreeComponentsTBWidget != NULL) { fUISceneTreeComponentsTBWidget->removeTab(fUISceneTreeComponentsTBWidget->indexOf(fSceneTreeWidget)); } } G4cout <addMenu("&Mouse actions"); fMouseRotateAction = mMouseAction->addAction("Rotate", signalMapperMouse, SLOT(map())); fMouseMoveAction = mMouseAction->addAction("Move", signalMapperMouse, SLOT(map())); fMousePickAction = mMouseAction->addAction("Pick", signalMapperMouse, SLOT(map())); fMouseZoomOutAction = mMouseAction->addAction("Zoom out", signalMapperMouse, SLOT(map())); fMouseZoomInAction = mMouseAction->addAction("Zoom in", signalMapperMouse, SLOT(map())); QAction *shortcutsAction = mMouseAction->addAction("Show shortcuts"); fMouseRotateAction->setCheckable(true); fMouseMoveAction->setCheckable(true); fMousePickAction->setCheckable(true); fMouseZoomOutAction->setCheckable(true); fMouseZoomInAction->setCheckable(true); shortcutsAction->setCheckable(false); connect(signalMapperMouse, SIGNAL(mapped(int)),this, SLOT(toggleMouseAction(int))); signalMapperMouse->setMapping(fMouseRotateAction,1); signalMapperMouse->setMapping(fMouseMoveAction,2); signalMapperMouse->setMapping(fMousePickAction,3); signalMapperMouse->setMapping(fMouseZoomOutAction,4); signalMapperMouse->setMapping(fMouseZoomInAction,5); QObject::connect(shortcutsAction, SIGNAL(triggered(bool)), this, SLOT(showShortcuts())); // === Style Menu === QMenu *mStyle = fContextMenu->addMenu("&Style"); QMenu *mProjection = mStyle->addMenu("&Projection"); fProjectionOrtho = mProjection->addAction("Orthographic", signalMapperSurface, SLOT(map())); fProjectionPerspective = mProjection->addAction("Persepective", signalMapperSurface, SLOT(map())); // INIT mProjection if (fVP.GetFieldHalfAngle() == 0) { createRadioAction(fProjectionOrtho, fProjectionPerspective,SLOT(toggleProjection(bool)),1); } else { createRadioAction(fProjectionOrtho, fProjectionPerspective,SLOT(toggleProjection(bool)),2); } // === Drawing Menu === QMenu *mDrawing = mStyle->addMenu("&Drawing"); fDrawingWireframe = mDrawing->addAction("Wireframe", signalMapperSurface, SLOT(map())); fDrawingLineRemoval = mDrawing->addAction("Hidden line removal", signalMapperSurface, SLOT(map())); fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal", signalMapperSurface, SLOT(map())); fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal", signalMapperSurface, SLOT(map())); fDrawingWireframe->setCheckable(true); fDrawingLineRemoval->setCheckable(true); fDrawingSurfaceRemoval->setCheckable(true); fDrawingLineSurfaceRemoval->setCheckable(true); connect(signalMapperSurface, SIGNAL(mapped(int)),this, SLOT(toggleSurfaceAction(int))); signalMapperSurface->setMapping(fDrawingWireframe,1); signalMapperSurface->setMapping(fDrawingLineRemoval,2); signalMapperSurface->setMapping(fDrawingSurfaceRemoval,3); signalMapperSurface->setMapping(fDrawingLineSurfaceRemoval,4); // Background Color QAction *backgroundColorChooser ; // === Action Menu === backgroundColorChooser = mStyle->addAction("Background color"); QObject ::connect(backgroundColorChooser, SIGNAL(triggered()), this, SLOT(actionChangeBackgroundColor())); // Text Color QAction *textColorChooser ; // === Action Menu === textColorChooser = mStyle->addAction("Text color"); QObject ::connect(textColorChooser, SIGNAL(triggered()), this, SLOT(actionChangeTextColor())); // Default Color QAction *defaultColorChooser ; // === Action Menu === defaultColorChooser = mStyle->addAction("Default color"); QObject ::connect(defaultColorChooser, SIGNAL(triggered()), this, SLOT(actionChangeDefaultColor())); // === Action Menu === QMenu *mActions = fContextMenu->addMenu("&Actions"); QAction *createEPS = mActions->addAction("Save as ..."); QObject ::connect(createEPS, SIGNAL(triggered()), this, SLOT(actionSaveImage())); // === Action Menu === QAction *movieParameters = mActions->addAction("Movie parameters..."); QObject ::connect(movieParameters, SIGNAL(triggered()), this, SLOT(actionMovieParameters())); // === Special Menu === QMenu *mSpecial = fContextMenu->addMenu("S&pecial"); QMenu *mTransparency = mSpecial->addMenu("Transparency"); QAction *transparencyOn = mTransparency->addAction("On"); QAction *transparencyOff = mTransparency->addAction("Off"); if (transparency_enabled == false) { createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2); } else if (transparency_enabled == true) { createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),1); } else { mSpecial->clear(); } QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing"); QAction *antialiasingOn = mAntialiasing->addAction("On"); QAction *antialiasingOff = mAntialiasing->addAction("Off"); if (antialiasing_enabled == false) { createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2); } else if (antialiasing_enabled == true) { createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),1); } else { mAntialiasing->clear(); } QMenu *mHaloing = mSpecial->addMenu("Haloing"); QAction *haloingOn = mHaloing->addAction("On"); QAction *haloingOff = mHaloing->addAction("Off"); if (haloing_enabled == false) { createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2); } else if (haloing_enabled == true) { createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),1); } else { mHaloing->clear(); } QMenu *mAux = mSpecial->addMenu("Auxiliary edges"); QAction *auxOn = mAux->addAction("On"); QAction *auxOff = mAux->addAction("Off"); if (!fVP.IsAuxEdgeVisible()) { createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),2); } else { createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1); } QMenu *mHiddenMarkers = mSpecial->addMenu("Hidden markers"); QAction *hiddenMarkersOn = mHiddenMarkers->addAction("On"); QAction *hiddenMarkersOff = mHiddenMarkers->addAction("Off"); if (fVP.IsMarkerNotHidden()) { createRadioAction(hiddenMarkersOn,hiddenMarkersOff,SLOT(toggleHiddenMarkers(bool)),2); } else { createRadioAction(hiddenMarkersOn,hiddenMarkersOff,SLOT(toggleHiddenMarkers(bool)),1); } QMenu *mFullScreen = mSpecial->addMenu("&Full screen"); fFullScreenOn = mFullScreen->addAction("On"); fFullScreenOff = mFullScreen->addAction("Off"); createRadioAction(fFullScreenOn,fFullScreenOff,SLOT(toggleFullScreen(bool)),2); // INIT All updateToolbarAndMouseContextMenu(); } void G4OpenGLQtViewer::G4manageContextMenuEvent(QContextMenuEvent *e) { if (!fGLWindow) { G4cerr << "Visualization window not defined, please choose one before" << G4endl; } else { if (!fContextMenu) createPopupMenu(); // launch menu if ( fContextMenu ) { fContextMenu->exec( e->globalPos() ); // delete fContextMenu; } } e->accept(); } /** Create a radio button menu. The two menu will be connected. When click on one, eatch state will be invert and callback method will be called. @param action1 first action to connect @param action2 second action to connect @param method callback method @param nCheck: 1 : first action will be set true. 2 : second action will be set true */ void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) { action1->setCheckable(true); action2->setCheckable(true); if (nCheck ==1) action1->setChecked (true); else action2->setChecked (true); QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle())); QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle())); QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str()); } /** Show shortcuts for this mouse action */ void G4OpenGLQtViewer::showShortcuts() { G4String text; text = "========= Mouse Shortcuts =========\n"; if (fUiQt != NULL) { if (fUiQt->IsIconRotateSelected()) { // rotate text += "Click and move mouse to rotate volume \n"; text += "ALT + Click and move mouse to rotate volume (Toggle View/Theta-Phi Direction) \n"; text += "CTRL + Click and move mouse to zoom in/out \n"; text += "SHIFT + Click and move mouse to change camera point of view \n"; } else if (fUiQt->IsIconMoveSelected()) { //move text += "Move camera point of view with mouse \n"; } else if (fUiQt->IsIconPickSelected()) { //pick text += "Click and pick \n"; } } else { text += "Click and move mouse to rotate volume \n"; text += "ALT + Click and move mouse to rotate volume (Toggle View/Theta-Phi Direction) \n"; text += "CTRL + Click and zoom mouse to zoom in/out \n"; text += "SHIFT + Click and zoommove camera point of view \n"; } text += "========= Move Shortcuts ========= \n"; text += "Press left/right arrows to move volume left/right \n"; text += "Press up/down arrows to move volume up/down \n"; text += "Press '+'/'-' to move volume toward/forward \n"; text += "\n"; text += "========= Rotation (Theta/Phi) Shortcuts ========= \n"; text += "Press SHIFT + left/right arrows to rotate volume left/right \n"; text += "Press SHIFT + up/down arrows to rotate volume up/down \n"; text += "\n"; text += "========= Rotation (View Direction) Shortcuts ========= \n"; text += "Press ALT + left/right to rotate volume around vertical direction \n"; text += "Press ALT + up/down to rotate volume around horizontal direction \n"; text += "\n"; text += "========= Zoom View ========= \n"; text += "Press CTRL + '+'/'-' to zoom into volume \n"; text += "\n"; text += "========= Misc ========= \n"; text += "Press ALT +/- to slow/speed rotation/move \n"; text += "Press H to reset view \n"; text += "Press Esc to exit FullScreen \n"; text += "\n"; text += "========= Video ========= \n"; text += "In video mode : \n"; text += " Press SPACE to Start/Pause video recording \n"; text += " Press RETURN to Stop video recording \n"; text += "\n"; G4cout << text; if ( fShortcutsDialog == NULL) { fShortcutsDialog = new QDialog(); fShortcutsDialogInfos = new QTextEdit() ; QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(fShortcutsDialogInfos); fShortcutsDialog->setLayout(mainLayout); fShortcutsDialog->setWindowTitle(tr("Shortcuts")); } fShortcutsDialogInfos->setPlainText(text.data()); fShortcutsDialog->show(); } /** Slot activated when mouse action is toggle @param aAction : 1 rotate, 2 move, 3 pick, 4 zoom out, 5 zoom in @see G4OpenGLStoredQtViewer::DrawView @see G4XXXStoredViewer::CompareForKernelVisit */ void G4OpenGLQtViewer::toggleMouseAction(int aAction) { if (aAction == 1) { fUiQt->SetIconRotateSelected(); } else if (aAction == 2) { fUiQt->SetIconMoveSelected(); } else if (aAction == 3) { fUiQt->SetIconPickSelected(); } else if (aAction == 4) { fUiQt->SetIconZoomOutSelected(); } else if (aAction == 5) { fUiQt->SetIconZoomInSelected(); } updateToolbarAndMouseContextMenu(); } /** Slot activated when drawing menu is toggle Warning : When G4OpenGLStoredQtViewer::DrawView() method call, KernelVisitDecision () will be call and will set the fNeedKernelVisit to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. It will cause a redraw of the view @param aAction : 1 wireframe, 2 line removal, 3 surface removal, 4 line & surface removal @see G4OpenGLStoredQtViewer::DrawView @see G4XXXStoredViewer::CompareForKernelVisit */ void G4OpenGLQtViewer::toggleSurfaceAction(int aAction) { G4ViewParameters::DrawingStyle d_style = G4ViewParameters::wireframe; if (aAction ==1) { d_style = G4ViewParameters::wireframe; } else if (aAction ==2) { d_style = G4ViewParameters::hlr; } else if (aAction ==3) { d_style = G4ViewParameters::hsr; } else if (aAction ==4) { d_style = G4ViewParameters::hlhsr; } fVP.SetDrawingStyle(d_style); updateToolbarAndMouseContextMenu(); updateQWidget(); } /** SLOT Activate by a click on the projection menu Warning : When G4OpenGLStoredQtViewer::DrawView() method call, KernelVisitDecision () will be call and will set the fNeedKernelVisit to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. It will cause a redraw of the view @param check : 1 orthographic, 2 perspective @see G4OpenGLStoredQtViewer::DrawView @see G4XXXStoredViewer::CompareForKernelVisit */ void G4OpenGLQtViewer::toggleProjection(bool check) { if (check == 1) { fVP.SetOrthogonalProjection (); } else { fVP.SetPerspectiveProjection(); } updateToolbarAndMouseContextMenu(); updateQWidget(); } /** SLOT Activate by a click on the transparency menu @param check : 1 , 0 */ void G4OpenGLQtViewer::toggleTransparency(bool check) { if (check) { transparency_enabled = true; } else { transparency_enabled = false; } SetNeedKernelVisit (true); updateToolbarAndMouseContextMenu(); updateQWidget(); } /** SLOT Activate by a click on the antialiasing menu @param check : 1 , 0 */ void G4OpenGLQtViewer::toggleAntialiasing(bool check) { if (!check) { antialiasing_enabled = false; glDisable (GL_LINE_SMOOTH); glDisable (GL_POLYGON_SMOOTH); } else { antialiasing_enabled = true; glEnable (GL_LINE_SMOOTH); glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); glEnable (GL_POLYGON_SMOOTH); glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST); } updateToolbarAndMouseContextMenu(); updateQWidget(); } /** SLOT Activate by a click on the haloing menu @param check : 1 , 0 */ //FIXME : I SEE NOTHING... void G4OpenGLQtViewer::toggleHaloing(bool check) { if (check) { haloing_enabled = false; } else { haloing_enabled = true; } updateToolbarAndMouseContextMenu(); updateQWidget(); } /** SLOT Activate by a click on the auxiliaire edges menu @param check : 1 , 0 */ void G4OpenGLQtViewer::toggleAux(bool check) { if (check) { fVP.SetAuxEdgeVisible(true); } else { fVP.SetAuxEdgeVisible(false); } SetNeedKernelVisit (true); updateToolbarAndMouseContextMenu(); updateQWidget(); } /** SLOT Activate by a click on the hidden marker menu @param check : 1 , 0 */ void G4OpenGLQtViewer::toggleHiddenMarkers(bool check) { if (check) { fVP.SetMarkerHidden(); } else { fVP.SetMarkerNotHidden(); } // SetNeedKernelVisit (true); updateToolbarAndMouseContextMenu(); updateQWidget(); } /** SLOT Activate by a click on the full screen menu */ void G4OpenGLQtViewer::toggleFullScreen(bool check) { if (check != fGLWindow->isFullScreen()) { //toggle fGLWindow->setWindowState(fGLWindow->windowState() ^ Qt::WindowFullScreen); } } void G4OpenGLQtViewer::savePPMToTemp() { if (fMovieTempFolderPath == "") { return; } QString fileName ="Test"+QString::number(fRecordFrameNumber)+".ppm"; QString filePath =fMovieTempFolderPath+fileName; QImage image; image = fWindow->grabFrameBuffer(); bool res = false; res = image.save(filePath,0); if (res == false) { resetRecording(); setRecordingInfos("Can't save tmp file "+filePath); return; } setRecordingInfos("File "+fileName+" saved"); fRecordFrameNumber++; } void G4OpenGLQtViewer::actionSaveImage() { QString filters; QList formats = QImageWriter::supportedImageFormats (); for (int i = 0; i < formats.size(); ++i) { filters +=formats.at(i) + ";;"; } filters += "eps;;"; filters += "ps;;"; filters += "pdf"; QString* selectedFormat = new QString(fDefaultSaveFileFormat); QString qFilename; qFilename = QFileDialog::getSaveFileName ( fGLWindow, tr("Save as ..."), ".", filters, selectedFormat ); std::string name = qFilename.toStdString().c_str(); // bmp jpg jpeg png ppm xbm xpm if (name.empty()) { return; } fFileSavePath = QFileInfo(qFilename).path(); if (! qFilename.endsWith(QString(selectedFormat->toStdString().c_str()),Qt::CaseInsensitive)) { name += "." + selectedFormat->toStdString(); } QString format = selectedFormat->toLower(); // set the default format to current fDefaultSaveFileFormat = format; setPrintFilename(name.c_str(),0); G4OpenGLQtExportDialog* exportDialog= new G4OpenGLQtExportDialog(fGLWindow,format,fWindow->height(),fWindow->width()); if( exportDialog->exec()) { QImage image; bool res = false; if ((exportDialog->getWidth() !=fWindow->width()) || (exportDialog->getHeight() !=fWindow->height())) { setPrintSize(exportDialog->getWidth(),exportDialog->getHeight()); if ((format != QString("eps")) && (format != QString("ps"))) { G4cerr << "Export->Change Size : This function is not implemented, to export in another size, please resize your frame to what you need" << G4endl; // rescaleImage(exportDialog->getWidth(),exportDialog->getHeight());// re-scale image // QGLWidget* glResized = fWindow; // FIXME : // L.Garnier : I've try to implement change size function, but the problem is // the renderPixmap function call the QGLWidget to resize and it doesn't draw // the content of this widget... It only draw the background. // fWindow->renderPixmap (exportDialog->getWidth()*2,exportDialog->getHeight()*2,true ); // QPixmap pixmap = fWindow->renderPixmap (); // image = pixmap->toImage(); // glResized->resize(exportDialog->getWidth()*2,exportDialog->getHeight()*2); // image = glResized->grabFrameBuffer(); } } else { image = fWindow->grabFrameBuffer(); } if (format == QString("eps")) { fVectoredPs = exportDialog->getVectorEPS(); printEPS(); } else if (format == "ps") { fVectoredPs = true; printEPS(); } else if (format == "pdf") { res = printPDF(name,exportDialog->getNbColor(),image); } else if ((format == "tif") || (format == "tiff") || (format == "jpg") || (format == "jpeg") || (format == "png") || (format == "pbm") || (format == "pgm") || (format == "ppm") || (format == "bmp") || (format == "xbm") || (format == "xpm")) { res = image.save(QString(name.c_str()),0,exportDialog->getSliderValue()); } else { G4cerr << "This version of G4UI Could not generate the selected format" << G4endl; } if ((format == QString("eps")) && (format == QString("ps"))) { if (res == false) { G4cerr << "Error while saving file... "<