Ignore:
Timestamp:
Jan 25, 2008, 2:51:33 PM (16 years ago)
Author:
garnier
Message:

avancement sur la zone de recherche

Location:
trunk/geant4/visualization/OpenGL
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh

    r688 r696  
    5555class QImage;
    5656class QAction;
     57class QMouseEvent;
     58class QKeyEvent;
    5759
    5860class G4OpenGLSceneHandler;
     
    7880  void G4MouseDoubleClickEvent(QPoint p);
    7981#if QT_VERSION < 0x040000
    80   void G4MouseMoveEvent(int, int, Qt::ButtonState);
     82  void G4MouseEvent(int, int, Qt::ButtonState);
    8183#else
    82   void G4MouseMoveEvent(int, int, Qt::MouseButtons);
     84  void G4MouseEvent(int, int, Qt::MouseButtons);
    8385#endif
     86  void G4MouseRotateEvent(int, int);
     87  void G4MouseMoveEvent(int, int, int);
     88  void G4keyPressEvent (QKeyEvent * event);
    8489
    8590
     
    103108  QMenu *fContextMenu;
    104109#endif
    105   enum mouseActions {ROTATE, MOVE, ZOOM, PICK};
     110  enum mouseActions {STYLE1,STYLE2,STYLE3,STYLE4};
    106111  mouseActions fMouseAction; // 1: rotate 0:move
    107   QPoint lastPos;
     112  QPoint fLastPos;
     113  /* delta of scene translation. This delta is put in % of the scene view */
     114  float fDeltaSceneTranslation;
     115  /* delta of left right move. This delta is put in % of the scene view */
     116  float fDeltaZoom;
     117
    108118#if QT_VERSION < 0x040000
    109119  QPopupMenu *fMouseRotate;
  • trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredQtViewer.hh

    r688 r696  
    6969  void mouseReleaseEvent(QMouseEvent *event);
    7070  void contextMenuEvent(QContextMenuEvent *e);
     71  void keyPressEvent (QKeyEvent * event);
    7172
    7273private :
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLQtExportDialog.cc

    r694 r696  
    3030//
    3131
    32 //#define GEANT4_QT_DEBUG
     32#define GEANT4_QT_DEBUG
    3333#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
    3434
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc

    r694 r696  
    3636#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
    3737
    38 //#define GEANT4_QT_DEBUG
     38#define GEANT4_QT_DEBUG
    3939
    4040#include "G4OpenGLQtViewer.hh"
     
    285285  ,fWindow(0)
    286286  ,fContextMenu(0)
    287   ,fMouseAction(ROTATE)
     287  ,fMouseAction(STYLE1)
     288  ,fDeltaSceneTranslation(1/100)
     289  ,fDeltaZoom(2)
    288290{
    289291#ifdef GEANT4_QT_DEBUG
     
    817819 */
    818820void G4OpenGLQtViewer::actionMouseRotate() {
    819   emit toggleMouseAction(ROTATE);
     821  emit toggleMouseAction(STYLE1);
    820822}
    821823
     
    824826 */
    825827void G4OpenGLQtViewer::actionMouseMove() {
    826   emit toggleMouseAction(MOVE);
     828  emit toggleMouseAction(STYLE2);
    827829}
    828830
     
    834836  printf("G4OpenGLQtViewer::actionMouseZoom \n");
    835837#endif
    836   emit toggleMouseAction(ZOOM);
     838  emit toggleMouseAction(STYLE3);
    837839}
    838840
     
    844846  printf("G4OpenGLQtViewer::actionMousePick \n");
    845847#endif
    846   emit toggleMouseAction(PICK);
     848  emit toggleMouseAction(STYLE4);
    847849}
    848850
     
    878880/**
    879881   Slot activated when mouse action is toggle
    880    @param aAction : ROTATE, MOVE, ZOOM
     882   @param aAction : STYLE1, STYLE2, STYLE3
    881883 */
    882884void G4OpenGLQtViewer::toggleMouseAction(mouseActions aAction) {
    883885 
    884   if (aAction == ROTATE) {
     886  if (aAction == STYLE1) {
     887    G4cout << "Clic and move mouse to rotate Volume \n" << G4endl;
     888    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;
     891    G4cout << "Press +/- to zoom into volume\n" << G4endl;
    885892#if QT_VERSION < 0x040000
    886893    fMouseRotate->setItemChecked (0,true);
     
    894901    fMousePick->setChecked (false);
    895902#endif
    896     fMouseAction = ROTATE;
     903    fMouseAction = STYLE1;
    897904    fVP.SetPicking(false);
    898   } else  if (aAction == MOVE) {
     905  } else  if (aAction == STYLE2) {
     906    G4cout << "Clic and move mouse to move Volume \n" << G4endl;
    899907#if QT_VERSION < 0x040000
    900908    fMouseRotate->setItemChecked (0,false);
     
    908916    fMousePick->setChecked (false);
    909917#endif
    910     fMouseAction = MOVE;
     918    fMouseAction = STYLE2;
    911919    fVP.SetPicking(false);
    912   } else  if (aAction == ZOOM) {
     920  } else  if (aAction == STYLE3) {
     921    G4cout << "Clic and move mouse to rotate Volume \n" << G4endl;
    913922#if QT_VERSION < 0x040000
    914923    fMouseRotate->setItemChecked (0,false);
     
    922931    fMousePick->setChecked (false);
    923932#endif
    924     fMouseAction = ZOOM;
     933    fMouseAction = STYLE3;
    925934    fVP.SetPicking(false);
    926   } else  if (aAction == PICK) {
     935  } else  if (aAction == STYLE4) {
    927936#if QT_VERSION < 0x040000
    928937    fMouseRotate->setItemChecked (0,false);
     
    937946#endif
    938947    fVP.SetPicking(true);
    939     fMouseAction = PICK;
     948    fMouseAction = STYLE4;
    940949  }
    941950
     
    13131322void G4OpenGLQtViewer::G4MousePressEvent(QPoint p)
    13141323{
    1315   lastPos = p;
    1316   if (fMouseAction == PICK){  // pick
     1324  fLastPos = p;
     1325  if (fMouseAction == STYLE4){  // pick
    13171326    Pick(p.x(),p.y());
    13181327  }
    13191328}
     1329
    13201330
    13211331/**
     
    13261336
    13271337#if QT_VERSION < 0x040000
    1328 void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::ButtonState mButtons)
    1329 #else
    1330 void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons)
     1338void G4OpenGLQtViewer::G4MouseEvent(int pos_x, int pos_y,Qt::ButtonState mButtons)
     1339#else
     1340void G4OpenGLQtViewer::G4MouseEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons)
    13311341#endif
    13321342{
    1333   int dx = pos_x - lastPos.x();
    1334   int dy = pos_y - lastPos.y();
    1335   if (fMouseAction == ROTATE) {  // rotate
     1343  int dx = pos_x - fLastPos.x();
     1344  int dy = pos_y - fLastPos.y();
     1345  if (fMouseAction == STYLE1) {  // rotate
    13361346    if (mButtons & Qt::LeftButton) {
    1337       //phi spin stuff here
    1338      
    1339       G4Vector3D vp = fVP.GetViewpointDirection ().unit ();
    1340       G4Vector3D up = fVP.GetUpVector ().unit ();
    1341      
    1342       G4Vector3D yprime = (up.cross(vp)).unit();
    1343       G4Vector3D zprime = (vp.cross(yprime)).unit();
    1344      
    1345       G4double delta_alpha;
    1346       G4double delta_theta;
    1347      
    1348       if (fVP.GetLightsMoveWithCamera()) {
    1349         delta_alpha = dy;
    1350         delta_theta = -dx;
    1351       } else {
    1352         delta_alpha = -dy;
    1353         delta_theta = dx;
    1354       }   
    1355 
    1356       delta_alpha *= deg;
    1357       delta_theta *= deg;
    1358 
    1359       G4Vector3D new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime;
    1360      
    1361       G4Vector3D new_up;
    1362       if (fVP.GetLightsMoveWithCamera()) {
    1363         new_up = (new_vp.cross(yprime)).unit();
    1364         fVP.SetUpVector(new_up);
    1365       } else {
    1366         new_up = up;
    1367       }
    1368       ////////////////
    1369       // Rotates by fixed azimuthal angle delta_theta.
    1370 
    1371       G4double cosalpha = new_up.dot (new_vp.unit());
    1372       G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));
    1373       yprime = (new_up.cross (new_vp.unit())).unit ();
    1374       G4Vector3D xprime = yprime.cross (new_up);
    1375       // Projection of vp on plane perpendicular to up...
    1376       G4Vector3D a1 = sinalpha * xprime;
    1377       // Required new projection...
    1378       G4Vector3D a2 =
    1379         sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);
    1380       // Required Increment vector...
    1381       G4Vector3D delta = a2 - a1;
    1382       // So new viewpoint is...
    1383       G4Vector3D viewPoint = new_vp.unit() + delta;
    1384 
    1385       fVP.SetViewAndLights (viewPoint);
    1386       updateQWidget();
    1387      
    1388     } else if (mButtons & Qt::RightButton) {
    1389       // NEVER DONE BECAUSE OF MOUSE MENU
    1390       //       setXRotation(xRot + dy/2);
    1391       //       setZRotation(zRot + dx/2);
    1392       //       updateQWidget();
     1347      G4MouseRotateEvent(dx,dy);
    13931348    }
    1394   } else   if (fMouseAction == MOVE){  // move
     1349  } else   if (fMouseAction == STYLE2){  // move
    13951350    if (mButtons & Qt::LeftButton) {
    1396      
    1397       float dx = pos_x - lastPos.x();
    1398       float dy = pos_y - lastPos.y();
    1399      
    1400       G4Point3D stp
    1401         = GetSceneHandler()->GetScene()->GetStandardTargetPoint();
    1402      
    1403       G4Point3D tp = stp + fVP.GetCurrentTargetPoint ();
    1404      
    1405       const G4Vector3D& upVector = fVP.GetUpVector ();
    1406       const G4Vector3D& vpVector = fVP.GetViewpointDirection ();
    1407      
    1408       G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
    1409       G4Vector3D unitUp    = (vpVector.cross (unitRight)).unit();
    1410      
    1411       tp += -dx * unitRight + dy * unitUp;
    1412       fVP.SetCurrentTargetPoint (tp - stp);
    1413      
    1414       updateQWidget();
     1351      G4MouseMoveEvent(dx,dy,0);
    14151352    }
    1416   } else   if (fMouseAction == ZOOM){  // zoom
     1353  } else   if (fMouseAction == STYLE3){  // zoom
    14171354    if (mButtons & Qt::LeftButton) {
    14181355      G4cerr << "Zoom not implemented for the moment\n" << G4endl;
    14191356    }
    14201357  }
    1421   lastPos = QPoint(pos_x, pos_y);
     1358  fLastPos = QPoint(pos_x, pos_y);
     1359}
     1360
     1361/**
     1362   @param dx delta mouse x position
     1363   @param dy delta mouse y position
     1364*/
     1365
     1366void G4OpenGLQtViewer::G4MouseMoveEvent(int dx, int dy, int dz)
     1367{
     1368  G4Point3D stp
     1369    = GetSceneHandler()->GetScene()->GetStandardTargetPoint();
     1370 
     1371  G4Point3D tp = stp + fVP.GetCurrentTargetPoint ();
     1372 
     1373  const G4Vector3D& upVector = fVP.GetUpVector ();
     1374  const G4Vector3D& vpVector = fVP.GetViewpointDirection ();
     1375 
     1376  G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
     1377  G4Vector3D unitUp    = (vpVector.cross (unitRight)).unit();
     1378 
     1379#ifdef GEANT4_QT_DEBUG
     1380  G4cout << fVP<<G4endl;
     1381  printf("Mouse event Target Point : %f %f %f\n",tp.x(),tp.y(),tp.z());
     1382  printf("Mouse event upVector : %f %f %f\n",upVector.x(),upVector.y(),upVector.z());
     1383  printf("Mouse event vpVector Point : %f %f %f\n",vpVector.x(),vpVector.y(),vpVector.z());
     1384  printf("Mouse event unitRight Point : %f %f %f\n",unitRight.x(),unitRight.y(),unitRight.z());
     1385  printf("Mouse event unitUp Point : %f %f %f\n",unitUp.x(),unitUp.y(),unitUp.z());
     1386#endif
     1387  tp += -dx * unitRight + dy * unitUp + dz * vpVector;
     1388  fVP.SetCurrentTargetPoint (tp - stp);
     1389 
     1390  updateQWidget();
     1391}
     1392
     1393
     1394/**
     1395   @param dx delta mouse x position
     1396   @param dy delta mouse y position
     1397*/
     1398
     1399void G4OpenGLQtViewer::G4MouseRotateEvent(int dx, int dy)
     1400{
     1401  //phi spin stuff here
     1402 
     1403  G4Vector3D vp = fVP.GetViewpointDirection ().unit ();
     1404  G4Vector3D up = fVP.GetUpVector ().unit ();
     1405 
     1406  G4Vector3D yprime = (up.cross(vp)).unit();
     1407  G4Vector3D zprime = (vp.cross(yprime)).unit();
     1408 
     1409  G4double delta_alpha;
     1410  G4double delta_theta;
     1411 
     1412  if (fVP.GetLightsMoveWithCamera()) {
     1413    delta_alpha = dy;
     1414    delta_theta = -dx;
     1415  } else {
     1416    delta_alpha = -dy;
     1417    delta_theta = dx;
     1418  }   
     1419 
     1420  delta_alpha *= deg;
     1421  delta_theta *= deg;
     1422 
     1423  G4Vector3D new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime;
     1424 
     1425  G4Vector3D new_up;
     1426  if (fVP.GetLightsMoveWithCamera()) {
     1427    new_up = (new_vp.cross(yprime)).unit();
     1428    fVP.SetUpVector(new_up);
     1429  } else {
     1430    new_up = up;
     1431  }
     1432  ////////////////
     1433  // Rotates by fixed azimuthal angle delta_theta.
     1434 
     1435  G4double cosalpha = new_up.dot (new_vp.unit());
     1436  G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));
     1437  yprime = (new_up.cross (new_vp.unit())).unit ();
     1438  G4Vector3D xprime = yprime.cross (new_up);
     1439  // Projection of vp on plane perpendicular to up...
     1440  G4Vector3D a1 = sinalpha * xprime;
     1441  // Required new projection...
     1442  G4Vector3D a2 =
     1443    sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);
     1444  // Required Increment vector...
     1445  G4Vector3D delta = a2 - a1;
     1446  // So new viewpoint is...
     1447  G4Vector3D viewPoint = new_vp.unit() + delta;
     1448 
     1449  fVP.SetViewAndLights (viewPoint);
     1450  updateQWidget();
     1451 
    14221452}
    14231453
     
    17121742#endif
    17131743
     1744void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * event)
     1745{
     1746#ifdef GEANT4_QT_DEBUG
     1747  printf("G4OpenGLQtViewer::keyPressEvent count:%d autoRepeat:%d key:%d\n",event->count(),event->isAutoRepeat(),event->key());
     1748#endif
     1749  if (event->key() == Qt::Key_Down)
     1750    {
     1751      G4MouseMoveEvent(0,0,-1);
     1752    }
     1753  if (event->key() == Qt::Key_Up)
     1754    {
     1755      G4MouseMoveEvent(0,0,1);
     1756    }
     1757  if (event->key() == Qt::Key_Left)
     1758    {
     1759      G4MouseMoveEvent(-1,0,0);
     1760    }
     1761  if (event->key() == Qt::Key_Right)
     1762    {
     1763      G4MouseMoveEvent(1,0,0);
     1764    }
     1765  if (event->key() == Qt::Key_Plus)
     1766    {
     1767      fVP.SetZoomFactor(fVP.GetZoomFactor()*fDeltaZoom);
     1768      updateQWidget();
     1769    }
     1770  if (event->key() == Qt::Key_Minus)
     1771    {
     1772      fVP.SetZoomFactor(fVP.GetZoomFactor()/fDeltaZoom);
     1773      updateQWidget();
     1774    }
     1775}
     1776
    17141777/*
    1715 
     1778 
    17161779void MultiLayer::exportToSVG(const QString& fname)
    17171780{
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc

    r690 r696  
    5252  QGLWidget(QGLFormat(QGL::SampleBuffers))             // FIXME : gerer le pb du parent !
    5353{
     54  setFocusPolicy(Qt::StrongFocus); // enable keybord events
    5455  nbPaint =0;
    5556  hasToRepaint =false;
     
    311312}
    312313
     314void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
     315{
     316  G4keyPressEvent(event);
     317}
     318
    313319/**
    314320 * This function was build in order to make a zoom on double clic event.
     
    336342
    337343#if QT_VERSION < 0x040000
    338   G4MouseMoveEvent(event->x(),event->y(),event->state());
     344  G4MouseEvent(event->x(),event->y(),event->state());
    339345#else
    340   G4MouseMoveEvent(event->x(),event->y(),event->buttons());
     346  G4MouseEvent(event->x(),event->y(),event->buttons());
    341347#endif
    342348}
Note: See TracChangeset for help on using the changeset viewer.