// // ******************************************************************** // * 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,v 1.55 2010/10/08 10:07:31 lgarnier Exp $ // GEANT4 tag $Name: $ // // // 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 "G4VViewer.hh" #include "G4VSceneHandler.hh" #include "G4OpenGLSceneHandler.hh" #include "G4ios.hh" #include "G4VisExtent.hh" #include "G4LogicalVolume.hh" #include "G4VSolid.hh" #include "G4Point3D.hh" #include "G4Normal3D.hh" #include "G4Scene.hh" #include "G4OpenGLQtExportDialog.hh" #include "G4OpenGLQtMovieDialog.hh" #include "G4UnitsTable.hh" #include "G4Qt.hh" #include "G4UIQt.hh" #include "G4UImanager.hh" #include "G4UIcommandTree.hh" #include #include #include #include #include #if QT_VERSION >= 0x040000 #include #include #else #include #include #include #include #endif #include #include #include #include #include #include #include // include #include #include #include //include ////////////////////////////////////////////////////////////////////////////// /** Implementation of virtual method of G4VViewer */ void G4OpenGLQtViewer::SetView ( ) ////////////////////////////////////////////////////////////////////////////// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// { G4OpenGLViewer::SetView (); } ////////////////////////////////////////////////////////////////////////////// void G4OpenGLQtViewer::CreateMainWindow ( QGLWidget* glWidget ,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())) return; G4UIQt * uiQt = static_cast (UI->GetG4UIWindow()); bool isTabbedView = false; if ( uiQt) { isTabbedView = uiQt->AddTabWidget(fWindow,name,getWinWidth(),getWinHeight()); } #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) { #if QT_VERSION < 0x040000 glWidget->reparent(myParent,0,QPoint(0,0)); #else glWidget->setParent(myParent); #endif } QHBoxLayout *mainLayout = new QHBoxLayout(fGLWindow); mainLayout->setMargin(0); mainLayout->setSpacing(0); mainLayout->addWidget(fWindow); if (fGLWindow->inherits("QMainWindow")) { #if QT_VERSION < 0x040000 fGLWindow->setCaption(name ); #else fGLWindow->setWindowTitle( name); #endif } #if QT_VERSION >= 0x040000 fGLWindow->setLayout(mainLayout); #endif //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; } fGLWindow->resize(getWinWidth(), getWinHeight()); #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; fGLWindow->resize(getWinWidth(), getWinHeight()); } if(!fWindow) return; if (!fContextMenu) createPopupMenu(); //dummy call to init Text display list drawText("",0,0,0,10); } #if QT_VERSION >= 0x040000 /** Close the dialog and set the pointer to NULL */ // void G4OpenGLQtViewer::dialogClosed() { // // fGLWindow = NULL; // } #endif ////////////////////////////////////////////////////////////////////////////// G4OpenGLQtViewer::G4OpenGLQtViewer ( G4OpenGLSceneHandler& scene ) :G4VViewer (scene, -1) ,G4OpenGLViewer (scene) ,fWindow(0) ,fRecordFrameNumber(0) ,fContextMenu(0) ,fMouseAction(STYLE1) ,fDeltaRotation(1) ,fDeltaSceneTranslation(0.01) ,fDeltaDepth(0.01) ,fDeltaZoom(0.05) ,fDeltaMove(0.05) ,fHoldKeyEvent(false) ,fHoldMoveEvent(false) ,fHoldRotateEvent(false) ,fAutoMove(false) ,fEncoderPath("") ,fTempFolderPath("") ,fMovieTempFolderPath("") ,fSaveFileName("") ,fParameterFileName("mpeg_encode_parameter_file.par") ,fMovieParametersDialog(NULL) ,fRecordingStep(WAIT) ,fProcess(NULL) ,fNbMaxFramesPerSec(100) ,fNbMaxAnglePerSec(360) ,fLaunchSpinDelay(100) ,fXRot(0) ,fYRot(0) ,fNoKeyPress(true) ,fAltKeyPress(false) ,fControlKeyPress(false) ,fShiftKeyPress(false) { // launch Qt if not G4Qt::getInstance (); fLastPos3 = QPoint(-1,-1); fLastPos2 = QPoint(-1,-1); fLastPos1 = QPoint(-1,-1); initMovieParameters(); fLastEventTime = new QTime(); #ifdef G4DEBUG_VIS_OGL printf("G4OpenGLQtViewer::G4OpenGLQtViewer END\n"); #endif } ////////////////////////////////////////////////////////////////////////////// G4OpenGLQtViewer::~G4OpenGLQtViewer ( ) ////////////////////////////////////////////////////////////////////////////// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// { #if QT_VERSION < 0x040000 G4cout < fontsize) { fontsize = font.pointSize(); } #ifdef G4DEBUG_VIS_OGL printf("G4OpenGLQtViewer::drawText :: renderText.............. \n"); #endif if (! drawGl2psText(textString,fontsize)) { fWindow->renderText(x,y,z, textString,font); } } /** Create a popup menu for the widget. This menu is activated by right-mouse click */ void G4OpenGLQtViewer::createPopupMenu() { #if QT_VERSION < 0x040000 fContextMenu = new QPopupMenu( fGLWindow,"All" ); #else fContextMenu = new QMenu("All"); #endif #if QT_VERSION < 0x040000 QPopupMenu *mMouseAction = new QPopupMenu( fContextMenu ); fContextMenu->insertItem("&Mouse actions",mMouseAction); #if QT_VERSION < 0x030200 fRotateAction = new QAction("&Rotate","&Rotate",CTRL+Key_R,mMouseAction,0,true); fMoveAction = new QAction("&Move","&Move",CTRL+Key_M,mMouseAction,0,true); fPickAction = new QAction("&Pick","&Pick",CTRL+Key_P,mMouseAction,0,true); QAction * shortcutsAction = new QAction("&Show shortcuts","&Show shortcuts",CTRL+Key_S,mMouseAction,0,true); #else fRotateAction = new QAction("&Rotate",CTRL+Key_R,mMouseAction); fMoveAction = new QAction("&Move",CTRL+Key_M,mMouseAction); fPickAction = new QAction("&Pick",CTRL+Key_P,mMouseAction); QAction *shortcutsAction = new QAction("&Show shortcuts",CTRL+Key_S,mMouseAction); #endif fRotateAction->addTo(mMouseAction); fMoveAction->addTo(mMouseAction); fPickAction->addTo(mMouseAction); shortcutsAction->addTo(mMouseAction); fRotateAction->setToggleAction(true); fMoveAction->setToggleAction(true); fPickAction->setToggleAction(true); shortcutsAction->setToggleAction(true); fRotateAction->setOn(true); fMoveAction->setOn(false); fPickAction->setOn(false); shortcutsAction->setOn(false); QObject ::connect(fRotateAction, SIGNAL(activated()), this, SLOT(actionMouseRotate())); QObject ::connect(fMoveAction, SIGNAL(activated()), this, SLOT(actionMouseMove())); QObject ::connect(fPickAction, SIGNAL(activated()), this, SLOT(actionMousePick())); QObject ::connect(shortcutsAction, SIGNAL(activated()), this, SLOT(showShortcuts())); #else QMenu *mMouseAction = fContextMenu->addMenu("&Mouse actions"); fRotateAction = mMouseAction->addAction("Rotate"); fMoveAction = mMouseAction->addAction("Move"); fPickAction = mMouseAction->addAction("Pick"); QAction *shortcutsAction = mMouseAction->addAction("Show shortcuts"); fRotateAction->setCheckable(true); fMoveAction->setCheckable(false); fPickAction->setCheckable(false); shortcutsAction->setCheckable(false); fRotateAction->setChecked(true); fMoveAction->setChecked(false); fPickAction->setChecked(false); shortcutsAction->setChecked(false); QObject ::connect(fRotateAction, SIGNAL(triggered(bool)), this, SLOT(actionMouseRotate())); QObject ::connect(fMoveAction, SIGNAL(triggered(bool)), this, SLOT(actionMouseMove())); QObject ::connect(fPickAction, SIGNAL(triggered(bool)), this, SLOT(actionMousePick())); QObject ::connect(shortcutsAction, SIGNAL(triggered(bool)), this, SLOT(showShortcuts())); #endif #if QT_VERSION < 0x040000 // === Style Menu === QPopupMenu *mStyle = new QPopupMenu(fContextMenu); QPopupMenu *mRepresentation = new QPopupMenu(fContextMenu); QPopupMenu *mProjection = new QPopupMenu(fContextMenu); #if QT_VERSION < 0x030200 QAction *polyhedron = new QAction("&Polyhedron","&Polyhedron",CTRL+Key_P,mRepresentation,0,true); QAction *nurbs = new QAction("&NURBS","&NURBS",CTRL+Key_N,mRepresentation,0,true); QAction *ortho = new QAction("&Orthographic","&Orthographic",CTRL+Key_O,mProjection,0,true); QAction *perspective = new QAction("&Perspective","&Perspective",CTRL+Key_P,mProjection,0,true); #else QAction *polyhedron = new QAction("&Polyhedron",CTRL+Key_P,mRepresentation); QAction *nurbs = new QAction("&NURBS",CTRL+Key_N,mRepresentation); QAction *ortho = new QAction("&Orthographic",CTRL+Key_O,mProjection); QAction *perspective = new QAction("&Perspective",CTRL+Key_P,mProjection); polyhedron->setToggleAction(true); nurbs->setToggleAction(true); ortho->setToggleAction(true); perspective->setToggleAction(true); #endif polyhedron->addTo(mRepresentation); nurbs->addTo(mRepresentation); ortho->addTo(mProjection); perspective->addTo(mProjection); mStyle->insertItem("&Representation",mRepresentation); mStyle->insertItem("&Projection",mProjection); fContextMenu->insertItem("&Style",mStyle); #else // === Style Menu === QMenu *mStyle = fContextMenu->addMenu("&Style"); QMenu *mRepresentation = mStyle->addMenu("&Representation"); QMenu *mProjection = mStyle->addMenu("&Projection"); QAction *polyhedron = mRepresentation->addAction("Polyhedron"); QAction *nurbs = mRepresentation->addAction("NURBS"); QAction *ortho = mProjection->addAction("Orthographic"); QAction *perspective = mProjection->addAction("Persepective"); #endif // INIT mRepresentation G4ViewParameters::RepStyle style; style = fVP.GetRepStyle(); if (style == G4ViewParameters::polyhedron) { createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),1); } else if (style == G4ViewParameters::nurbs) { createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),2); } else { mRepresentation->clear(); } // INIT mProjection if (fVP.GetFieldHalfAngle() == 0) { createRadioAction(ortho, perspective,SLOT(toggleProjection(bool)),1); } else { createRadioAction(ortho, perspective,SLOT(toggleProjection(bool)),2); } #if QT_VERSION < 0x040000 // === Drawing Menu === QPopupMenu *mDrawing = new QPopupMenu(fContextMenu); fContextMenu->insertItem("&Drawing",mDrawing); #if QT_VERSION < 0x030200 fDrawingWireframe = new QAction("&Wireframe","&Wireframe",CTRL+Key_W,mDrawing,0,true); fDrawingLineRemoval = new QAction("&Hidden line removal","&Hidden line removal",CTRL+Key_L,mDrawing,0,true); fDrawingSurfaceRemoval = new QAction("&Hidden surface removal","&Hidden surface removal",CTRL+Key_S,mDrawing,0,true); fDrawingLineSurfaceRemoval = new QAction("&Hidden line and surface removal","&Hidden line and surface removal",CTRL+Key_R,mDrawing,0,true); #else fDrawingWireframe = new QAction("&Wireframe",CTRL+Key_W,mDrawing); fDrawingLineRemoval = new QAction("&Hidden line removal",CTRL+Key_L,mDrawing); fDrawingSurfaceRemoval = new QAction("&Hidden surface removal",CTRL+Key_S,mDrawing); fDrawingLineSurfaceRemoval = new QAction("&Hidden line and surface removal",CTRL+Key_R,mDrawing); #endif fDrawingWireframe->setToggleAction(true); fDrawingLineRemoval->setToggleAction(true); fDrawingSurfaceRemoval->setToggleAction(true); fDrawingLineSurfaceRemoval->setToggleAction(true); fDrawingWireframe->addTo(mDrawing); fDrawingLineRemoval->addTo(mDrawing); fDrawingSurfaceRemoval->addTo(mDrawing); fDrawingLineSurfaceRemoval->addTo(mDrawing); #else // === Drawing Menu === QMenu *mDrawing = mStyle->addMenu("&Drawing"); fDrawingWireframe = mDrawing->addAction("Wireframe"); fDrawingWireframe->setCheckable(true); fDrawingLineRemoval = mDrawing->addAction("Hidden line removal"); fDrawingLineRemoval->setCheckable(true); fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal"); fDrawingSurfaceRemoval->setCheckable(true); fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal"); fDrawingLineSurfaceRemoval->setCheckable(true); #endif // INIT Drawing G4ViewParameters::DrawingStyle d_style; d_style = fVP.GetDrawingStyle(); #if QT_VERSION < 0x040000 if (d_style == G4ViewParameters::wireframe) { fDrawingWireframe->setOn(true); } else if (d_style == G4ViewParameters::hlr) { fDrawingLineRemoval->setOn(true); } else if (d_style == G4ViewParameters::hsr) { fDrawingSurfaceRemoval->setOn(true); } else if (d_style == G4ViewParameters::hlhsr) { fDrawingLineSurfaceRemoval->setOn(true); } else { mDrawing->clear(); } QObject ::connect(fDrawingWireframe, SIGNAL(activated()), this, SLOT(actionDrawingWireframe())); QObject ::connect(fDrawingLineRemoval, SIGNAL(activated()), this, SLOT(actionDrawingLineRemoval())); QObject ::connect(fDrawingSurfaceRemoval, SIGNAL(activated()), this, SLOT(actionDrawingSurfaceRemoval())); QObject ::connect(fDrawingLineSurfaceRemoval, SIGNAL(activated()), this, SLOT(actionDrawingLineSurfaceRemoval())); #else if (d_style == G4ViewParameters::wireframe) { fDrawingWireframe->setChecked(true); } else if (d_style == G4ViewParameters::hlr) { fDrawingLineRemoval->setChecked(true); } else if (d_style == G4ViewParameters::hsr) { fDrawingSurfaceRemoval->setChecked(true); } else if (d_style == G4ViewParameters::hlhsr) { fDrawingLineSurfaceRemoval->setChecked(true); } else { mDrawing->clear(); } QObject ::connect(fDrawingWireframe, SIGNAL(triggered(bool)), this, SLOT(actionDrawingWireframe())); QObject ::connect(fDrawingLineRemoval, SIGNAL(triggered(bool)), this, SLOT(actionDrawingLineRemoval())); QObject ::connect(fDrawingSurfaceRemoval, SIGNAL(triggered(bool)), this, SLOT(actionDrawingSurfaceRemoval())); QObject ::connect(fDrawingLineSurfaceRemoval, SIGNAL(triggered(bool)), this, SLOT(actionDrawingLineSurfaceRemoval())); #endif // Background Color QAction *backgroundColorChooser ; #if QT_VERSION < 0x040000 QPopupMenu *mBackgroundColor = new QPopupMenu(mStyle); mStyle->insertItem("&Background color",mBackgroundColor); #if QT_VERSION < 0x030200 backgroundColorChooser = new QAction("&Choose ...","&Choose ...",CTRL+Key_C,mBackgroundColor,0,true); #else backgroundColorChooser = new QAction("&Choose ...","&Choose ...",CTRL+Key_C,mBackgroundColor); #endif backgroundColorChooser->addTo(mBackgroundColor); QObject ::connect(backgroundColorChooser, SIGNAL(activated()), this, SLOT(actionChangeBackgroundColor())); #else // === Action Menu === backgroundColorChooser = mStyle->addAction("Background color"); QObject ::connect(backgroundColorChooser, SIGNAL(triggered()), this, SLOT(actionChangeBackgroundColor())); #endif // Text Color QAction *textColorChooser ; #if QT_VERSION < 0x040000 QPopupMenu *mTextColor = new QPopupMenu(mStyle); mStyle->insertItem("&Text color",mTextColor); #if QT_VERSION < 0x030200 textColorChooser = new QAction("&Choose ...","&Choose ...",CTRL+Key_C,mTextColor,0,true); #else textColorChooser = new QAction("&Choose ...","&Choose ...",CTRL+Key_C,mTextColor); #endif textColorChooser->addTo(mTextColor); QObject ::connect(textColorChooser, SIGNAL(activated()), this, SLOT(actionChangeTextColor())); #else // === Action Menu === textColorChooser = mStyle->addAction("Text color"); QObject ::connect(textColorChooser, SIGNAL(triggered()), this, SLOT(actionChangeTextColor())); #endif // Default Color QAction *defaultColorChooser ; #if QT_VERSION < 0x040000 QPopupMenu *mDefaultColor = new QPopupMenu(mStyle); mStyle->insertItem("&Default color",mDefaultColor); #if QT_VERSION < 0x030200 defaultColorChooser = new QAction("&Choose ...","&Choose ...",CTRL+Key_C,mDefaultColor,0,true); #else defaultColorChooser = new QAction("&Choose ...","&Choose ...",CTRL+Key_C,mDefaultColor); #endif defaultColorChooser->addTo(mDefaultColor); QObject ::connect(defaultColorChooser, SIGNAL(activated()), this, SLOT(actionChangeDefaultColor())); #else // === Action Menu === defaultColorChooser = mStyle->addAction("Default color"); QObject ::connect(defaultColorChooser, SIGNAL(triggered()), this, SLOT(actionChangeDefaultColor())); #endif #if QT_VERSION < 0x040000 // === Action Menu === QPopupMenu *mActions = new QPopupMenu(fContextMenu); fContextMenu->insertItem("&Actions",mActions); #if QT_VERSION < 0x030200 QAction *createEPS = new QAction("&Save as ...","&Save as ...",CTRL+Key_S,mActions,0,true); #else QAction *createEPS = new QAction("&Save as ...",CTRL+Key_S,mActions); #endif createEPS->addTo(mActions); QObject ::connect(createEPS, SIGNAL(activated()), this, SLOT(actionSaveImage())); #else // === Action Menu === QMenu *mActions = fContextMenu->addMenu("&Actions"); QAction *createEPS = mActions->addAction("Save as ..."); QObject ::connect(createEPS, SIGNAL(triggered()), this, SLOT(actionSaveImage())); #endif #if QT_VERSION < 0x040000 #if QT_VERSION < 0x030200 QAction *movieParameters = new QAction("&Make Movie...","&Make movie ...",CTRL+Key_M,mActions,0,true); #else QAction *movieParameters = new QAction("&Make Movie...",CTRL+Key_M,mActions); #endif movieParameters->addTo(mActions); QObject ::connect(movieParameters, SIGNAL(activated()), this, SLOT(actionMovieParameters())); #else // === Action Menu === QAction *movieParameters = mActions->addAction("Movie parameters..."); QObject ::connect(movieParameters, SIGNAL(triggered()), this, SLOT(actionMovieParameters())); #endif #if QT_VERSION < 0x040000 // === Special Menu === QPopupMenu *mSpecial = new QPopupMenu(fContextMenu); fContextMenu->insertItem("S&pecial",mSpecial); QPopupMenu *mTransparency = new QPopupMenu(mSpecial); mSpecial->insertItem("Transparency",mTransparency); #if QT_VERSION < 0x030200 QAction *transparencyOn = new QAction("&On","&On",CTRL+Key_O,mTransparency,0,true); QAction *transparencyOff = new QAction("&Off","&Off",CTRL+Key_F,mTransparency,0,true); #else QAction *transparencyOn = new QAction("&On",CTRL+Key_O,mTransparency); QAction *transparencyOff = new QAction("&Off",CTRL+Key_F,mTransparency); transparencyOn->setToggleAction(true); transparencyOff->setToggleAction(true); #endif transparencyOn->addTo(mTransparency); transparencyOff->addTo(mTransparency); #else // === Special Menu === QMenu *mSpecial = fContextMenu->addMenu("S&pecial"); QMenu *mTransparency = mSpecial->addMenu("Transparency"); QAction *transparencyOn = mTransparency->addAction("On"); QAction *transparencyOff = mTransparency->addAction("Off"); #endif 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(); } #if QT_VERSION < 0x040000 QPopupMenu *mAntialiasing = new QPopupMenu(mSpecial); mSpecial->insertItem("Antialiasing",mAntialiasing); #if QT_VERSION < 0x030200 QAction *antialiasingOn = new QAction("&On","&On",CTRL+Key_O,mAntialiasing,0,true); QAction *antialiasingOff = new QAction("&Off","&Off",CTRL+Key_F,mAntialiasing,0,true); #else QAction *antialiasingOn = new QAction("&On",CTRL+Key_O,mAntialiasing); QAction *antialiasingOff = new QAction("&Off",CTRL+Key_F,mAntialiasing); antialiasingOn->setToggleAction(true); antialiasingOff->setToggleAction(true); #endif antialiasingOn->addTo(mAntialiasing); antialiasingOff->addTo(mAntialiasing); #else QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing"); QAction *antialiasingOn = mAntialiasing->addAction("On"); QAction *antialiasingOff = mAntialiasing->addAction("Off"); #endif 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(); } #if QT_VERSION < 0x040000 QPopupMenu *mHaloing = new QPopupMenu(mSpecial); mSpecial->insertItem("Haloing",mHaloing); #if QT_VERSION < 0x030200 QAction *haloingOn = new QAction("&On","&On",CTRL+Key_O,mHaloing,0,true); QAction *haloingOff = new QAction("&Off","&Off",CTRL+Key_F,mHaloing,0,true); #else QAction *haloingOn = new QAction("&On",CTRL+Key_O,mHaloing); QAction *haloingOff = new QAction("&Off",CTRL+Key_F,mHaloing); haloingOn->setToggleAction(true); haloingOff->setToggleAction(true); #endif haloingOn->addTo(mHaloing); haloingOff->addTo(mHaloing); #else QMenu *mHaloing = mSpecial->addMenu("Haloing"); QAction *haloingOn = mHaloing->addAction("On"); QAction *haloingOff = mHaloing->addAction("Off"); #endif 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(); } #if QT_VERSION < 0x040000 QPopupMenu *mAux = new QPopupMenu(mSpecial); mSpecial->insertItem("Auxiliairy edges",mAux); #if QT_VERSION < 0x030200 QAction *auxOn = new QAction("&On","&On",CTRL+Key_O,mAux,0,true); QAction *auxOff = new QAction("&Off","&Off",CTRL+Key_F,mAux,0,true); #else QAction *auxOn = new QAction("&On",CTRL+Key_O,mAux); QAction *auxOff = new QAction("&Off",CTRL+Key_F,mAux); auxOn->setToggleAction(true); auxOff->setToggleAction(true); #endif auxOn->addTo(mAux); auxOff->addTo(mAux); #else QMenu *mAux = mSpecial->addMenu("Auxiliary edges"); QAction *auxOn = mAux->addAction("On"); QAction *auxOff = mAux->addAction("Off"); #endif if (!fVP.IsAuxEdgeVisible()) { createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1); } else { createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),2); } #if QT_VERSION < 0x040000 QPopupMenu *mFullScreen = new QPopupMenu(mSpecial); mSpecial->insertItem("Full screen",mFullScreen); #if QT_VERSION < 0x030200 fFullScreenOn = new QAction("&On","&On",CTRL+Key_O,mFullScreen,0,true); fFullScreenOff = new QAction("&Off","&Off",CTRL+Key_F,mFullScreen,0,true); #else fFullScreenOn = new QAction("&On",CTRL+Key_O,mFullScreen); fFullScreenOff = new QAction("&Off",CTRL+Key_F,mFullScreen); fFullScreenOn->setToggleAction(true); fFullScreenOff->setToggleAction(true); #endif fFullScreenOn->addTo(mFullScreen); fFullScreenOff->addTo(mFullScreen); #else QMenu *mFullScreen = mSpecial->addMenu("&Full screen"); fFullScreenOn = mFullScreen->addAction("On"); fFullScreenOff = mFullScreen->addAction("Off"); #endif createRadioAction(fFullScreenOn,fFullScreenOff,SLOT(toggleFullScreen(bool)),2); } 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 */ #if QT_VERSION < 0x040000 void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) { if (action1->parent()->inherits("QPopupMenu")){ ((QPopupMenu*)action1->parent())->setCheckable(true); ((QPopupMenu*)action2->parent())->setCheckable(true); } action1->setOn(false); action2->setOn(false); if (nCheck ==1) action1->setOn(true); else action2->setOn(true); //FIXME : Should not work on Qt3 QObject ::connect(action1, SIGNAL(activated()),action2, SLOT(toggle())); QObject ::connect(action2, SIGNAL(activated()),action1, SLOT(toggle())); QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str()); } #else 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()); } #endif /** Slot activate when mouseAction->rotate menu is set */ void G4OpenGLQtViewer::actionMouseRotate() { emit toggleMouseAction(STYLE1); } /** Slot activate when mouseAction->rotate menu is set */ void G4OpenGLQtViewer::actionMouseMove() { emit toggleMouseAction(STYLE2); } /** Slot activate when mouseAction->zoom menu is set */ void G4OpenGLQtViewer::actionMousePick() { emit toggleMouseAction(STYLE3); } /** Slot activate when drawing->wireframe menu is set */ void G4OpenGLQtViewer::actionDrawingWireframe() { emit toggleDrawingAction(1); } /** Slot activate when drawing->line removal menu is set */ void G4OpenGLQtViewer::actionDrawingLineRemoval() { emit toggleDrawingAction(2); } /** Slot activate when drawing->surface removal menu is set */ void G4OpenGLQtViewer::actionDrawingSurfaceRemoval() { emit toggleDrawingAction(3); } /** Slot activate when drawing->wireframe menu is set */ void G4OpenGLQtViewer::actionDrawingLineSurfaceRemoval() { emit toggleDrawingAction(4); } /** Slot activated when mouse action is toggle @param aAction : STYLE1, STYLE2, STYLE3 */ void G4OpenGLQtViewer::toggleMouseAction(mouseActions aAction) { if ((aAction == STYLE1) || //initialize all (aAction == STYLE2) || (aAction == STYLE3)) { #if QT_VERSION < 0x040000 fRotateAction->setOn (false); fMoveAction->setOn (false); fPickAction->setOn (false); #else fRotateAction->setChecked (false); fMoveAction->setChecked (false); fPickAction->setChecked (false); #endif fVP.SetPicking(false); fMouseAction = aAction; } // rotate if (aAction == STYLE1) { // rotate showShortcuts(); #if QT_VERSION < 0x040000 fRotateAction->setOn (true); #else fRotateAction->setChecked (true); #endif } else if (aAction == STYLE2) { //move #if QT_VERSION < 0x040000 fMoveAction->setOn (true); #else fMoveAction->setChecked (true); #endif } else if (aAction == STYLE3) { //pick #if QT_VERSION < 0x040000 fPickAction->setOn (true); #else fPickAction->setChecked (true); #endif fVP.SetPicking(true); } } /** Show shortcuts for this mouse action */ void G4OpenGLQtViewer::showShortcuts() { G4cout << "========= Mouse Shortcuts =========" << G4endl; if (fMouseAction == STYLE1) { // rotate G4cout << "Click and move mouse to rotate volume " << G4endl; G4cout << "ALT + Click and move mouse to rotate volume (View Direction)" << G4endl; G4cout << "CTRL + Click and zoom mouse to zoom in/out" << G4endl; G4cout << "SHIFT + Click and zoommove camera point of view" << G4endl; } else if (fMouseAction == STYLE2) { //move G4cout << "Move camera point of view with mouse" << G4endl; } else if (fMouseAction == STYLE3) { //pick G4cout << "Click and pick " << G4endl; } G4cout << "========= Move Shortcuts =========" << G4endl; G4cout << "Press left/right arrows to move volume left/right" << G4endl; G4cout << "Press up/down arrows to move volume up/down" << G4endl; G4cout << "Press '+'/'-' to move volume toward/forward" << G4endl; G4cout << G4endl; G4cout << "========= Rotation (Theta/Phi) Shortcuts =========" << G4endl; G4cout << "Press SHIFT + left/right arrows to rotate volume left/right" << G4endl; G4cout << "Press SHIFT + up/down arrows to rotate volume up/down" << G4endl; G4cout << G4endl; G4cout << "========= Rotation (View Direction) Shortcuts =========" << G4endl; G4cout << "Press ALT + left/right to rotate volume around vertical direction" << G4endl; G4cout << "Press ALT + up/down to rotate volume around horizontal direction" << G4endl; G4cout << G4endl; G4cout << "========= Zoom View =========" << G4endl; G4cout << "Press CTRL + '+'/'-' to zoom into volume" << G4endl; G4cout << G4endl; G4cout << "========= Misc =========" << G4endl; G4cout << "Press ALT +/- to slow/speed rotation/move" << G4endl; G4cout << "Press H to reset view" << G4endl; G4cout << "Press Esc to exit FullScreen" << G4endl; G4cout << G4endl; G4cout << "========= Video =========" << G4endl; G4cout << "In video mode : " << G4endl; G4cout << " Press SPACE to Start/Pause video recording " << G4endl; G4cout << " Press RETURN to Stop video recording " << G4endl; G4cout << G4endl; } /** 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::toggleDrawingAction(int aAction) { G4ViewParameters::DrawingStyle d_style = G4ViewParameters::wireframe; // initialize if ((aAction >0) && (aAction <5)) { #if QT_VERSION < 0x040000 fDrawingWireframe->setOn(false); fDrawingLineRemoval->setOn(false); fDrawingSurfaceRemoval->setOn(false); fDrawingLineSurfaceRemoval->setOn(false); #else fDrawingWireframe->setChecked (false); fDrawingLineRemoval->setChecked (false); fDrawingSurfaceRemoval->setChecked (false); fDrawingLineSurfaceRemoval->setChecked (false); #endif } if (aAction ==1) { #if QT_VERSION < 0x040000 fDrawingWireframe->setOn(true); #else fDrawingWireframe->setChecked (true); #endif d_style = G4ViewParameters::wireframe; } else if (aAction ==2) { #if QT_VERSION < 0x040000 fDrawingLineRemoval->setOn(true); #else fDrawingLineRemoval->setChecked (true); #endif d_style = G4ViewParameters::hlr; } else if (aAction ==3) { #if QT_VERSION < 0x040000 fDrawingSurfaceRemoval->setOn(true); #else fDrawingSurfaceRemoval->setChecked (true); #endif d_style = G4ViewParameters::hsr; } else if (aAction ==4) { #if QT_VERSION < 0x040000 fDrawingLineSurfaceRemoval->setOn(true); #else fDrawingLineSurfaceRemoval->setChecked (true); #endif d_style = G4ViewParameters::hlhsr; } fVP.SetDrawingStyle(d_style); updateQWidget(); } /** SLOT Activate by a click on the representation 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 polyhedron, 0 nurbs @see G4OpenGLStoredQtViewer::DrawView @see G4XXXStoredViewer::CompareForKernelVisit */ void G4OpenGLQtViewer::toggleRepresentation(bool check) { G4ViewParameters::RepStyle style; if (check == 1) { style = G4ViewParameters::polyhedron; } else { style = G4ViewParameters::nurbs; } fVP.SetRepStyle (style); 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) { G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection o"); } else { G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection p"); } updateQWidget(); } /** SLOT Activate by a click on the transparency menu @param check : 1 , 0 */ void G4OpenGLQtViewer::toggleTransparency(bool check) { if (check) { transparency_enabled = false; } else { transparency_enabled = true; } SetNeedKernelVisit (true); 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); } 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; } 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); updateQWidget(); } /** SLOT Activate by a click on the full screen menu */ void G4OpenGLQtViewer::toggleFullScreen(bool check) { if (check != fGLWindow->isFullScreen()) { //toggle #if QT_VERSION >= 0x030200 fGLWindow->setWindowState(fGLWindow->windowState() ^ Qt::WindowFullScreen); #else G4cerr << "This version of Qt could not do fullScreen. Resizing the widget is the only solution available." << G4endl; #endif } } 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; #if QT_VERSION < 0x040000 res = image.save(filePath,"PPM"); #else res = image.save(filePath,0); #endif if (res == false) { resetRecording(); setRecordingInfos("Can't save tmp file "+filePath); return; } setRecordingInfos("File "+fileName+" saved"); fRecordFrameNumber++; } void G4OpenGLQtViewer::actionSaveImage() { QString filters; #if QT_VERSION < 0x040000 QStrList listFormat=QImageIO::outputFormats(); char *tmp=listFormat.first(); while (tmp!=0) { filters += QString(tmp) + ";;"; tmp=listFormat.next(); } #else QList formats = QImageWriter::supportedImageFormats (); for (int i = 0; i < formats.size(); ++i) { filters +=formats.at(i) + ";;"; } #endif filters += "eps;;"; filters += "ps;;"; filters += "pdf"; QString* selectedFormat = new QString(); std::string name; #if QT_VERSION < 0x040000 name = QFileDialog::getSaveFileName ( ".", filters, fGLWindow, "Save file dialog", tr("Save as ..."), selectedFormat ).ascii(); #else name = QFileDialog::getSaveFileName ( fGLWindow, tr("Save as ..."), ".", filters, selectedFormat ).toStdString().c_str(); #endif // bmp jpg jpeg png ppm xbm xpm if (name.empty()) { return; } #if QT_VERSION < 0x040000 name += "." + std::string(selectedFormat->ascii()); QString format = selectedFormat->lower(); #else name += "." + selectedFormat->toStdString(); QString format = selectedFormat->toLower(); #endif 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")) { #if QT_VERSION < 0x040000 res = image.save(QString(name.c_str()),selectedFormat->ascii(),exportDialog->getSliderValue()); #else res = image.save(QString(name.c_str()),0,exportDialog->getSliderValue()); #endif } 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... "<