// // ******************************************************************** // * 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.9 2008/01/15 11:05:08 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 #define GEANT4_QT_DEBUG #include "G4OpenGLQtViewer.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 "G4Qt.hh" #include "G4UImanager.hh" #include "G4UIcommandTree.hh" #include #include #include #if QT_VERSION >= 0x040000 #include #include #else #include #include #include #include #endif #include #include #include #include #include // include #include #include //include ////////////////////////////////////////////////////////////////////////////// /** Implementation of virtual method of G4VViewer */ void G4OpenGLQtViewer::SetView ( ) ////////////////////////////////////////////////////////////////////////////// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// { #ifdef GEANT4_QT_DEBUG printf("G4OpenGLQtViewer::SetView ++++++++++++++++++++\n"); #endif // if(!fHDC) return; // if(!fHGLRC) return; // ::wglMakeCurrent(fHDC,fHGLRC); // fWindow->makeCurrent(); G4OpenGLViewer::SetView (); #ifdef GEANT4_QT_DEBUG printf("G4OpenGLQtViewer::SetView --------------------\n"); #endif } /** * Set the viewport of the scene */ void G4OpenGLQtViewer::setupViewport(int aWidth, int aHeight) { int side = qMin(aWidth, aHeight); glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0); glMatrixMode(GL_MODELVIEW); } ////////////////////////////////////////////////////////////////////////////// /** Implementation of virtual method of G4VViewer */ void G4OpenGLQtViewer::ShowView ( ) ////////////////////////////////////////////////////////////////////////////// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// { #ifdef GEANT4_QT_DEBUG printf("G4OpenGLQtViewer::ShowView +++++++++++++++++++++\n"); #endif if (!GLWindow) { G4cerr << "Visualization window not defined, please choose one before\n" << G4endl; } else { #if QT_VERSION < 0x040000 GLWindow->setActiveWindow(); #else GLWindow->activateWindow(); #endif #ifdef GEANT4_QT_DEBUG printf("G4OpenGLQtViewer::ShowView -----------------------\n"); #endif } glFlush (); // // Empty the Windows message queue : // MSG event; // while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) { // ::TranslateMessage(&event); // ::DispatchMessage (&event); // } } ////////////////////////////////////////////////////////////////////////////// void G4OpenGLQtViewer::CreateGLQtContext ( ) ////////////////////////////////////////////////////////////////////////////// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// { #ifdef GEANT4_QT_DEBUG printf("G4OpenGLQtViewer::CreateGLQtContext \n"); #endif } ////////////////////////////////////////////////////////////////////////////// void G4OpenGLQtViewer::CreateMainWindow ( QGLWidget* glWidget ) ////////////////////////////////////////////////////////////////////////////// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// { if(fWindow) return; //Done. #ifdef GEANT4_QT_DEBUG printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n"); #endif // launch Qt if not G4Qt* interactorManager = G4Qt::getInstance (); // G4UImanager* UI = G4UImanager::GetUIpointer(); fWindow = glWidget ; // fWindow->makeCurrent(); // create window if (((QApplication*)interactorManager->GetMainInteractor())) { // look for the main window bool found = false; #if QT_VERSION < 0x040000 // theses lines does nothing exept this one "GLWindow = new QDialog(0..." // but if I comment them, it doesn't work... QWidgetList *list = QApplication::allWidgets(); QWidgetListIt it( *list ); // iterate over the widgets QWidget * widget; while ( (widget=it.current()) != 0 ) { // for each widget... ++it; if ((found== false) && (widget->inherits("QMainWindow"))) { GLWindow = new QDialog(0,0,FALSE,Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_MinMax ); found = true; } } delete list; // delete the list, not the widgets #else foreach (QWidget *widget, QApplication::allWidgets()) { if ((found== false) && (widget->inherits("QMainWindow"))) { GLWindow = new QDialog(0,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint); found = true; } } #endif #if QT_VERSION < 0x040000 glWidget->reparent(GLWindow,0,QPoint(0,0)); #else glWidget->setParent(GLWindow); #endif if (found==false) { #ifdef GEANT4_QT_DEBUG printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n"); #endif GLWindow = new QDialog(); } } else { #ifdef GEANT4_QT_DEBUG printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n"); #endif GLWindow = new QDialog(); } QHBoxLayout *mainLayout = new QHBoxLayout(GLWindow); mainLayout->addWidget(fWindow); #if QT_VERSION < 0x040000 GLWindow->setCaption( tr( "QGl Viewer" )); #else GLWindow->setLayout(mainLayout); GLWindow->setWindowTitle(tr("QGl Viewer")); #endif GLWindow->resize(300, 300); GLWindow->move(900,300); GLWindow->show(); // delete the pointer if close this // GLWindow->setAttribute(Qt::WA_DeleteOnClose); #if QT_VERSION >= 0x040000 QObject ::connect(GLWindow, SIGNAL(rejected()), this, SLOT(dialogClosed())); #endif WinSize_x = 400; WinSize_y = 400; if (WinSize_x < fVP.GetWindowSizeHintX ()) WinSize_x = fVP.GetWindowSizeHintX (); if (WinSize_y < fVP.GetWindowSizeHintY ()) WinSize_y = fVP.GetWindowSizeHintY (); if(!fWindow) return; #ifdef GEANT4_QT_DEBUG printf("G4OpenGLQtViewer::CreateMainWindow glWidget END\n"); #endif if (!fContextMenu) createPopupMenu(); } #if QT_VERSION >= 0x040000 /** Close the dialog and set the pointer to NULL */ void G4OpenGLQtViewer::dialogClosed() { #ifdef GEANT4_QT_DEBUG printf("G4OpenGLQtViewer::dialogClosed END\n"); #endif // GLWindow = NULL; } #endif ////////////////////////////////////////////////////////////////////////////// G4OpenGLQtViewer::G4OpenGLQtViewer ( G4OpenGLSceneHandler& scene ) :G4VViewer (scene, -1) ,G4OpenGLViewer (scene) ,fWindow(0) ,fContextMenu(0) ,fMouseAction(STYLE1) ,fDeltaSceneTranslation(1/100) ,fDeltaZoom(2) ,holdKeyEvent(false) { #ifdef GEANT4_QT_DEBUG printf("G4OpenGLQtViewer::G4OpenGLQtViewer \n"); #endif } ////////////////////////////////////////////////////////////////////////////// G4OpenGLQtViewer::~G4OpenGLQtViewer ( ) ////////////////////////////////////////////////////////////////////////////// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// { #ifdef GEANT4_QT_DEBUG printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n"); #endif } /** 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( GLWindow,"All" ); #else fContextMenu = new QMenu("All"); #endif #if QT_VERSION < 0x040000 QPopupMenu *mMouseAction = new QPopupMenu( fContextMenu ); fContextMenu->insertItem("&Mouse actions"); #else QMenu *mMouseAction = fContextMenu->addMenu("&Mouse actions"); #endif #if QT_VERSION < 0x040000 // === Mouse menu === fMouseRotate = new QPopupMenu(mMouseAction); mMouseAction->insertItem("&Rotate",fMouseRotate); mMouseAction->setCheckable(true); fMouseRotate->setCheckable(true); fMouseMove = new QPopupMenu(mMouseAction); mMouseAction->insertItem("&Move",fMouseMove); fMouseMove->setCheckable(true); fMouseZoom = new QPopupMenu(mMouseAction); mMouseAction->insertItem("&Zoom",fMouseZoom); fMouseZoom->setCheckable(true); fMousePick = new QPopupMenu(mMouseAction); mMouseAction->insertItem("&Pick",fMousePick); fMousePick->setCheckable(true); #else // === Mouse menu === fMouseRotate = mMouseAction->addAction("Rotate"); fMouseRotate->setCheckable(true); fMouseMove = mMouseAction->addAction("Move"); fMouseMove->setCheckable(true); fMouseZoom = mMouseAction->addAction("Zoom"); fMouseZoom->setCheckable(true); fMousePick = mMouseAction->addAction("Pick"); fMousePick->setCheckable(true); #endif // INIT mMouse #if QT_VERSION < 0x040000 fMouseRotate->setItemCheckeded(0,true); QObject ::connect(fMouseRotate, SIGNAL(activated(int)), this, SLOT(actionMouseRotate())); QObject ::connect(fMouseMove, SIGNAL(activated(int)), this, SLOT(actionMouseMove())); QObject ::connect(fMouseZoom, SIGNAL(activated(int)), this, SLOT(actionMouseZoom())); QObject ::connect(fMousePick, SIGNAL(activated(int)), this, SLOT(actionMousePick())); #else fMouseRotate->setChecked(true); QObject ::connect(fMouseRotate, SIGNAL(triggered(bool)), this, SLOT(actionMouseRotate())); QObject ::connect(fMouseMove, SIGNAL(triggered(bool)), this, SLOT(actionMouseMove())); QObject ::connect(fMouseZoom, SIGNAL(triggered(bool)), this, SLOT(actionMouseZoom())); QObject ::connect(fMousePick, SIGNAL(triggered(bool)), this, SLOT(actionMousePick())); #endif #if QT_VERSION < 0x040000 // === Style Menu === QPopupMenu *mStyle = new QPopupMenu(fContextMenu); QPopupMenu *mRepresentation = new QPopupMenu(fContextMenu); QPopupMenu *mProjection = new QPopupMenu(fProjection); #if QT_VERSION < 0x030200 QAction *polyhedron = new QAction("&Polyhedron","&Polyhedron",CTRL+Key_P,mRepresentation); QAction *nurbs = new QAction("&NURBS","&NURBS",CTRL+Key_N,mRepresentation); QAction *ortho = new QAction("&Orthographic","&Orthographic",CTRL+Key_O,mProjection); QAction *perspective = new QAction("&Perspective","&Perspective",CTRL+Key_P,mProjection); #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); #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"); QAction *polyhedron = mRepresentation->addAction("Polyhedron"); QAction *nurbs = mRepresentation->addAction("NURBS"); QAction *ortho = mRepresentation->addAction("Orthographic"); QAction *perspective = mRepresentation->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); fDrawingWireframe = new QPopupMenu(mDrawing); mDrawing->insertItem("&Wireframe",fDrawingWireframe); mDrawing->setCheckable(true); fDrawingWireframe->setCheckable(true); fDrawingLineRemoval = new QPopupMenu(mDrawing); mDrawing->insertItem("&Hidden line removal",fDrawingLineRemoval); fDrawingLineRemoval->setCheckable(true); fDrawingSurfaceRemoval = new QPopupMenu(mDrawing); mDrawing->insertItem("&Hidden surface removal",fDrawingSurfaceRemoval); fDrawingSurfaceRemoval->setCheckable(true); fDrawingLineSurfaceRemoval = new QPopupMenu(mDrawing); mDrawing->insertItem("&Hidden line and surface removal",fDrawingLineSurfaceRemoval); fDrawingLineSurfaceRemoval->setCheckable(true); #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->setItemChecked(0,true); } else if (d_style == G4ViewParameters::hlr) { fDrawingLineRemoval->setItemChecked(0,true); } else if (d_style == G4ViewParameters::hsr) { fDrawingSurfaceRemoval->setItemChecked(0,true); } else if (d_style == G4ViewParameters::hlhsr) { fDrawingLineSurfaceRemoval->setItemChecked(0,true); } else { mDrawing->clear(); } #ifdef GEANT4_QT_DEBUG printf("G4OpenGLQtViewer:: fDrawingWireframe 1\n"); #endif QObject ::connect(fDrawingWireframe, SIGNAL(activated(int)), this, SLOT(actionDrawingWireframe())); #ifdef GEANT4_QT_DEBUG printf("G4OpenGLQtViewer:: fDrawingWireframe 2\n"); #endif QObject ::connect(fDrawingLineRemoval, SIGNAL(activated(int)), this, SLOT(actionDrawingLineRemoval())); QObject ::connect(fDrawingSurfaceRemoval, SIGNAL(activated(int)), this, SLOT(actionDrawingSurfaceRemoval())); QObject ::connect(fDrawingLineSurfaceRemoval, SIGNAL(activated(int)), 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 #if QT_VERSION < 0x040000 QPopupMenu *mBackground = new QPopupMenu(mStyle); mStyle->insertItem("&Background color",mBackground); #if QT_VERSION < 0x030200 QAction *white = new QAction("&White","&White",CTRL+Key_W,mBackground); QAction *black = new QAction("&Black","&Black",CTRL+Key_B,mBackground); #else QAction *white = new QAction("&White",CTRL+Key_W,mBackground); QAction *black = new QAction("&Black",CTRL+Key_B,mBackground); #endif white->addTo(mBackground); black->addTo(mBackground); #else QMenu *mBackground = mStyle->addMenu("&Background color"); QAction *white = mBackground->addAction("White"); QAction *black = mBackground->addAction("Black"); #endif if (background.GetRed() == 1. && background.GetGreen() == 1. && background.GetBlue() == 1.) { createRadioAction(white,black,SLOT(toggleBackground(bool)),1); } else { createRadioAction(white,black,SLOT(toggleBackground(bool)),2); } #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); #else QAction *createEPS = new QAction("&Save as ...",CTRL+Key_S,mActions); #endif createEPS->addTo(mActions); QObject ::connect(createEPS, SIGNAL(activated()), this, SLOT(actionCreateEPS())); #else // === Action Menu === QMenu *mActions = fContextMenu->addMenu("&Actions"); QAction *createEPS = mActions->addAction("Save as ..."); QObject ::connect(createEPS, SIGNAL(triggered()), this, SLOT(actionCreateEPS())); #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); QAction *transparencyOff = new QAction("&Off","&Off",CTRL+Key_F,mTransparency); #else QAction *transparencyOn = new QAction("&On",CTRL+Key_O,mTransparency); QAction *transparencyOff = new QAction("&Off",CTRL+Key_F,mTransparency); #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); QAction *antialiasingOff = new QAction("&Off","&Off",CTRL+Key_F,mAntialiasing); #else QAction *antialiasingOn = new QAction("&On",CTRL+Key_O,mAntialiasing); QAction *antialiasingOff = new QAction("&Off",CTRL+Key_F,mAntialiasing); #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); QAction *haloingOff = new QAction("&Off","&Off",CTRL+Key_F,mHaloing); #else QAction *haloingOn = new QAction("&On",CTRL+Key_O,mHaloing); QAction *haloingOff = new QAction("&Off",CTRL+Key_F,mHaloing); #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); QAction *auxOff = new QAction("&Off","&Off",CTRL+Key_F,mAux); #else QAction *auxOn = new QAction("&On",CTRL+Key_O,mAux); QAction *auxOff = new QAction("&Off",CTRL+Key_F,mAux); #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 >= 0x030200 #if QT_VERSION < 0x040000 QPopupMenu *mFullScreen = new QPopupMenu(mSpecial); mSpecial->insertItem("Full screen",mFullScreen); QAction *fullOn = new QAction("&On",CTRL+Key_O,mFullScreen); QAction *fullOff = new QAction("&Off",CTRL+Key_F,mFullScreen); fullOn->addTo(mFullScreen); fullOff->addTo(mFullScreen); #else QMenu *mFullScreen = mSpecial->addMenu("Full screen"); QAction *fullOn = mFullScreen->addAction("On"); QAction *fullOff = mFullScreen->addAction("Off"); #endif createRadioAction(fullOn,fullOff,SLOT(toggleFullScreen(bool)),2); #endif } void G4OpenGLQtViewer::manageContextMenuEvent(QContextMenuEvent *e) { if (!GLWindow) { G4cerr << "Visualization window not defined, please choose one before\n" << 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*)action1->parent())->setItemChecked(0,true); ((QPopupMenu*)action1->parent())->setItemChecked(1,true); if (nCheck ==1) ((QPopupMenu*)action1->parent())->setItemChecked(0,true); else ((QPopupMenu*)action1->parent())->setItemChecked(1,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->move menu is set */ void G4OpenGLQtViewer::actionMouseMove() { emit toggleMouseAction(STYLE2); } /** Slot activate when mouseAction->pick menu is set */ void G4OpenGLQtViewer::actionMouseZoom() { #ifdef GEANT4_QT_DEBUG printf("G4OpenGLQtViewer::actionMouseZoom \n"); #endif emit toggleMouseAction(STYLE3); } /** Slot activate when mouseAction->zoom menu is set */ void G4OpenGLQtViewer::actionMousePick() { #ifdef GEANT4_QT_DEBUG printf("G4OpenGLQtViewer::actionMousePick \n"); #endif emit toggleMouseAction(STYLE4); } /** 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) { G4cout << "Clic and move mouse to rotate Volume \n" << G4endl; G4cout << "Press left/right arrows to move camera left/right\n" << G4endl; G4cout << "Press up/down arrows to move camera up/down\n" << G4endl; G4cout << "Press SHIFT+up/down arrows to move camera toward/forward\n" << G4endl; G4cout << "Press +/- to zoom into volume\n" << G4endl; #if QT_VERSION < 0x040000 fMouseRotate->setItemChecked (0,true); fMouseMove->setItemChecked (0,false); fMouseZoom->setItemChecked (0,false); fMousePick->setItemChecked (0,false); #else fMouseRotate->setChecked (true); fMouseMove->setChecked (false); fMouseZoom->setChecked (false); fMousePick->setChecked (false); #endif fMouseAction = STYLE1; fVP.SetPicking(false); } else if (aAction == STYLE2) { G4cout << "Clic and move mouse to move Volume \n" << G4endl; #if QT_VERSION < 0x040000 fMouseRotate->setItemChecked (0,false); fMouseMove->setItemChecked (0,true); fMouseZoom->setItemChecked (0,false); fMousePick->setItemChecked (0,false); #else fMouseRotate->setChecked (false); fMouseMove->setChecked (true); fMouseZoom->setChecked (false); fMousePick->setChecked (false); #endif fMouseAction = STYLE2; fVP.SetPicking(false); } else if (aAction == STYLE3) { G4cout << "Clic and move mouse to rotate Volume \n" << G4endl; #if QT_VERSION < 0x040000 fMouseRotate->setItemChecked (0,false); fMouseMove->setItemChecked (0,false); fMouseZoom->setItemChecked (0,true); fMousePick->setItemChecked (0,false); #else fMouseRotate->setChecked (false); fMouseMove->setChecked (false); fMouseZoom->setChecked (true); fMousePick->setChecked (false); #endif fMouseAction = STYLE3; fVP.SetPicking(false); } else if (aAction == STYLE4) { #if QT_VERSION < 0x040000 fMouseRotate->setItemChecked (0,false); fMouseMove->setItemChecked (0,false); fMouseZoom->setItemChecked (0,false); fMousePick->setItemChecked (0,true); #else fMouseRotate->setChecked (false); fMouseMove->setChecked (false); fMouseZoom->setChecked (false); fMousePick->setChecked (true); #endif fVP.SetPicking(true); fMouseAction = STYLE4; } } /** 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; if (aAction ==1) { #if QT_VERSION < 0x040000 fDrawingWireframe->setItemChecked (0,true); fDrawingLineRemoval->setItemChecked (0,false); fDrawingSurfaceRemoval->setItemChecked (0,false); fDrawingLineSurfaceRemoval->setItemChecked (0,false); #else fDrawingWireframe->setChecked (true); fDrawingLineRemoval->setChecked (false); fDrawingSurfaceRemoval->setChecked (false); fDrawingLineSurfaceRemoval->setChecked (false); #endif d_style = G4ViewParameters::wireframe; } else if (aAction ==2) { #if QT_VERSION < 0x040000 fDrawingWireframe->setItemChecked (0,false); fDrawingLineRemoval->setItemChecked (0,true); fDrawingSurfaceRemoval->setItemChecked (0,false); fDrawingLineSurfaceRemoval->setItemChecked (0,false); #else fDrawingWireframe->setChecked (false); fDrawingLineRemoval->setChecked (true); fDrawingSurfaceRemoval->setChecked (false); fDrawingLineSurfaceRemoval->setChecked (false); #endif d_style = G4ViewParameters::hlr; } else if (aAction ==3) { #if QT_VERSION < 0x040000 fDrawingWireframe->setItemChecked (0,false); fDrawingLineRemoval->setItemChecked (0,false); fDrawingSurfaceRemoval->setItemChecked (0,true); fDrawingLineSurfaceRemoval->setItemChecked (0,false); #else fDrawingWireframe->setChecked (false); fDrawingLineRemoval->setChecked (false); fDrawingSurfaceRemoval->setChecked (true); fDrawingLineSurfaceRemoval->setChecked (false); #endif d_style = G4ViewParameters::hsr; } else if (aAction ==4) { #if QT_VERSION < 0x040000 fDrawingWireframe->setItemChecked (0,false); fDrawingLineRemoval->setItemChecked (0,false); fDrawingSurfaceRemoval->setItemChecked (0,false); fDrawingLineSurfaceRemoval->setItemChecked (0,true); #else fDrawingWireframe->setChecked (false); fDrawingLineRemoval->setChecked (false); fDrawingSurfaceRemoval->setChecked (false); fDrawingLineSurfaceRemoval->setChecked (true); #endif d_style = G4ViewParameters::hlhsr; } fVP.SetDrawingStyle(d_style); updateQWidget(); #ifdef GEANT4_QT_DEBUG printf("G4OpenGLQtViewer::toggleDrawingAction\n"); #endif } /** 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); #ifdef GEANT4_QT_DEBUG printf("G4OpenGLQtViewer::toggleRepresentation 3%d\n",check); #endif updateQWidget(); #ifdef GEANT4_QT_DEBUG printf("G4OpenGLQtViewer::toggleRepresentation 4%d\n",check); #endif } /** 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.SetFieldHalfAngle (0); } else { // look for the default parameter hidden in G4UIcommand parameters G4UImanager* UI = G4UImanager::GetUIpointer(); if(UI==NULL) return; G4UIcommandTree * treeTop = UI->GetTree(); // find command G4UIcommand* command = treeTop->FindPath("/vis/viewer/set/projection"); if (!command) return; // find param G4UIparameter * param = NULL; for(G4int i=0; iGetParameterEntries(); i++) { if( command->GetParameter(i)->GetParameterName() == "field-half-angle" ) { param = command->GetParameter(i); } } if (!param) return; G4double defaultValue = command->ConvertToDouble(param->GetDefaultValue()); G4cout << "Perspective view has been set to default value. Field half angle="<