Ignore:
Timestamp:
Jan 29, 2008, 3:21:26 PM (16 years ago)
Author:
garnier
Message:

deplacement keys ok. Debut d a jout bouton perspective

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc

    r701 r702  
    5050
    5151#include "G4Qt.hh"
    52 #include "G4UIsession.hh"
    5352#include "G4UImanager.hh"
     53#include "G4UIcommandTree.hh"
    5454#include <qapplication.h>
    5555#include <qlayout.h>
     
    288288  ,fDeltaSceneTranslation(1/100)
    289289  ,fDeltaZoom(2)
     290  ,holdKeyEvent(false)
    290291{
    291292#ifdef GEANT4_QT_DEBUG
     
    415416  QPopupMenu *mRepresentation = new QPopupMenu(fContextMenu);
    416417
     418  QPopupMenu *mProjection = new QPopupMenu(fProjection);
     419
    417420#if QT_VERSION < 0x030200
    418421  QAction *polyhedron = new QAction("&Polyhedron","&Polyhedron",CTRL+Key_P,mRepresentation);
    419422  QAction *nurbs = new QAction("&NURBS","&NURBS",CTRL+Key_N,mRepresentation);
     423
     424  QAction *ortho = new QAction("&Orthographic","&Orthographic",CTRL+Key_O,mProjection);
     425  QAction *perspective = new QAction("&Perspective","&Perspective",CTRL+Key_P,mProjection);
    420426#else
    421427  QAction *polyhedron = new QAction("&Polyhedron",CTRL+Key_P,mRepresentation);
    422428  QAction *nurbs = new QAction("&NURBS",CTRL+Key_N,mRepresentation);
     429
     430  QAction *ortho = new QAction("&Orthographic",CTRL+Key_O,mProjection);
     431  QAction *perspective = new QAction("&Perspective",CTRL+Key_P,mProjection);
    423432#endif
    424433  polyhedron->addTo(mRepresentation);
    425434  nurbs->addTo(mRepresentation);
    426435
     436  ortho->addTo(mProjection);
     437  perspective->addTo(mProjection);
     438
    427439  mStyle->insertItem("&Representation",mRepresentation);
     440  mStyle->insertItem("&Projection",mProjection);
    428441  fContextMenu->insertItem("&Style",mStyle);
     442
    429443
    430444#else
     
    435449  QAction *polyhedron = mRepresentation->addAction("Polyhedron");
    436450  QAction *nurbs = mRepresentation->addAction("NURBS");
    437 #endif
    438   // INIT mStyle
     451
     452  QAction *ortho = mRepresentation->addAction("Orthographic");
     453  QAction *perspective = mRepresentation->addAction("Persepective");
     454#endif
     455
     456  // INIT mRepresentation
    439457  G4ViewParameters::RepStyle style;
    440458  style = fVP.GetRepStyle();
     
    447465  }
    448466
     467  // INIT mProjection
     468  if (fVP.GetFieldHalfAngle() == 0) {
     469    createRadioAction(ortho, perspective,SLOT(toggleProjection(bool)),1);
     470  } else {
     471    createRadioAction(ortho, perspective,SLOT(toggleProjection(bool)),2);
     472  }
    449473
    450474#if QT_VERSION < 0x040000
     
    887911    G4cout << "Clic and move mouse to rotate Volume \n" << G4endl;
    888912    G4cout << "Press left/right arrows to move camera left/right\n" << G4endl;
    889     G4cout << "Press up/down arrows to move camera toward/forward\n" << G4endl;
    890     G4cout << "Press SHIFT+up/down arrows to move camera up/down\n" << G4endl;
     913    G4cout << "Press up/down arrows to move camera up/down\n" << G4endl;
     914    G4cout << "Press SHIFT+up/down arrows to move camera toward/forward\n" << G4endl;
    891915    G4cout << "Press +/- to zoom into volume\n" << G4endl;
    892916#if QT_VERSION < 0x040000
     
    10611085#endif
    10621086}
     1087
     1088/**
     1089   SLOT Activate by a click on the projection menu
     1090   Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
     1091   KernelVisitDecision () will be call and will set the fNeedKernelVisit
     1092   to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
     1093   It will cause a redraw of the view
     1094   @param check : 1 orthographic, 2 perspective
     1095   @see G4OpenGLStoredQtViewer::DrawView
     1096   @see G4XXXStoredViewer::CompareForKernelVisit
     1097*/
     1098void G4OpenGLQtViewer::toggleProjection(bool check) {
     1099
     1100  if (check == 1) {
     1101    fVP.SetFieldHalfAngle (0);
     1102  } else {
     1103    // look for the default parameter hidden in G4UIcommand parameters
     1104    G4UImanager* UI = G4UImanager::GetUIpointer();
     1105    if(UI==NULL)
     1106      return;
     1107    G4UIcommandTree * treeTop = UI->GetTree();
     1108
     1109    // find command
     1110    G4UIcommand* command = treeTop->FindPath("/vis/viewer/set/projection");
     1111    if (!command)
     1112      return;
     1113
     1114    // find param
     1115    G4UIparameter * param = NULL;
     1116
     1117    for(G4int i=0;  i<command->GetParameterEntries(); i++)
     1118    {
     1119      if( command->GetParameter(i)->GetParameterName() == "field-half-angle" ) {
     1120        param = command->GetParameter(i);
     1121      }
     1122    }
     1123    if (!param)
     1124      return;
     1125    G4double defaultValue = command->ConvertToDouble(param->GetDefaultValue());
     1126    G4cout << "Perspective view has been set to default value. Field half angle="<<defaultValue <<" \n" << G4endl;
     1127    fVP.SetFieldHalfAngle (defaultValue);
     1128  }
     1129 
     1130#ifdef GEANT4_QT_DEBUG
     1131  printf("G4OpenGLQtViewer::toggleRepresentation 3%d\n",check);
     1132#endif
     1133  updateQWidget();
     1134#ifdef GEANT4_QT_DEBUG
     1135  printf("G4OpenGLQtViewer::toggleRepresentation 4%d\n",check);
     1136#endif
     1137}
     1138
    10631139
    10641140/**
     
    17441820void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * event)
    17451821{
     1822  if (holdKeyEvent)
     1823    return;
     1824
     1825  holdKeyEvent = true;
     1826
    17461827#ifdef GEANT4_QT_DEBUG
    17471828  printf("G4OpenGLQtViewer::keyPressEvent count:%d autoRepeat:%d key:%d\n",event->count(),event->isAutoRepeat(),event->key());
     
    17521833    }
    17531834
    1754   if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::ShiftModifier)) // go up
     1835  if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::ShiftModifier)) // go backward
     1836    {
     1837      G4MouseMoveEvent(0,0,1);
     1838    }
     1839  else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::ShiftModifier))  // go forward
     1840    {
     1841      G4MouseMoveEvent(0,0,-1);
     1842    }
     1843 else if (event->key() == Qt::Key_Down) // go down
    17551844    {
    17561845      G4MouseMoveEvent(0,1,0);
    17571846    }
    1758   else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::ShiftModifier))  // go down
     1847  else if (event->key() == Qt::Key_Up)  // go up
    17591848    {
    17601849      G4MouseMoveEvent(0,-1,0);
    1761     }
    1762  else if (event->key() == Qt::Key_Down) // go backward
    1763     {
    1764       G4MouseMoveEvent(0,0,-1);
    1765     }
    1766   else if (event->key() == Qt::Key_Up)  // go forward
    1767     {
    1768       G4MouseMoveEvent(0,0,1);
    17691850    }
    17701851  else if (event->key() == Qt::Key_Left) // go left
     
    17861867      updateQWidget();
    17871868    }
     1869#ifdef GEANT4_QT_DEBUG
     1870  printf("G4OpenGLQtViewer::keyPressEvent END\n");
     1871#endif
     1872  holdKeyEvent = false;
    17881873}
    17891874
     
    18111896}
    18121897*/
     1898
Note: See TracChangeset for help on using the changeset viewer.