Changeset 696 for trunk/geant4
- Timestamp:
- Jan 25, 2008, 2:51:33 PM (17 years ago)
- Location:
- trunk/geant4/visualization/OpenGL
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh
r688 r696 55 55 class QImage; 56 56 class QAction; 57 class QMouseEvent; 58 class QKeyEvent; 57 59 58 60 class G4OpenGLSceneHandler; … … 78 80 void G4MouseDoubleClickEvent(QPoint p); 79 81 #if QT_VERSION < 0x040000 80 void G4Mouse MoveEvent(int, int, Qt::ButtonState);82 void G4MouseEvent(int, int, Qt::ButtonState); 81 83 #else 82 void G4Mouse MoveEvent(int, int, Qt::MouseButtons);84 void G4MouseEvent(int, int, Qt::MouseButtons); 83 85 #endif 86 void G4MouseRotateEvent(int, int); 87 void G4MouseMoveEvent(int, int, int); 88 void G4keyPressEvent (QKeyEvent * event); 84 89 85 90 … … 103 108 QMenu *fContextMenu; 104 109 #endif 105 enum mouseActions { ROTATE, MOVE, ZOOM, PICK};110 enum mouseActions {STYLE1,STYLE2,STYLE3,STYLE4}; 106 111 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 108 118 #if QT_VERSION < 0x040000 109 119 QPopupMenu *fMouseRotate; -
trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredQtViewer.hh
r688 r696 69 69 void mouseReleaseEvent(QMouseEvent *event); 70 70 void contextMenuEvent(QContextMenuEvent *e); 71 void keyPressEvent (QKeyEvent * event); 71 72 72 73 private : -
trunk/geant4/visualization/OpenGL/src/G4OpenGLQtExportDialog.cc
r694 r696 30 30 // 31 31 32 //#define GEANT4_QT_DEBUG32 #define GEANT4_QT_DEBUG 33 33 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER 34 34 -
trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc
r694 r696 36 36 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER 37 37 38 //#define GEANT4_QT_DEBUG38 #define GEANT4_QT_DEBUG 39 39 40 40 #include "G4OpenGLQtViewer.hh" … … 285 285 ,fWindow(0) 286 286 ,fContextMenu(0) 287 ,fMouseAction(ROTATE) 287 ,fMouseAction(STYLE1) 288 ,fDeltaSceneTranslation(1/100) 289 ,fDeltaZoom(2) 288 290 { 289 291 #ifdef GEANT4_QT_DEBUG … … 817 819 */ 818 820 void G4OpenGLQtViewer::actionMouseRotate() { 819 emit toggleMouseAction( ROTATE);821 emit toggleMouseAction(STYLE1); 820 822 } 821 823 … … 824 826 */ 825 827 void G4OpenGLQtViewer::actionMouseMove() { 826 emit toggleMouseAction( MOVE);828 emit toggleMouseAction(STYLE2); 827 829 } 828 830 … … 834 836 printf("G4OpenGLQtViewer::actionMouseZoom \n"); 835 837 #endif 836 emit toggleMouseAction( ZOOM);838 emit toggleMouseAction(STYLE3); 837 839 } 838 840 … … 844 846 printf("G4OpenGLQtViewer::actionMousePick \n"); 845 847 #endif 846 emit toggleMouseAction( PICK);848 emit toggleMouseAction(STYLE4); 847 849 } 848 850 … … 878 880 /** 879 881 Slot activated when mouse action is toggle 880 @param aAction : ROTATE, MOVE, ZOOM882 @param aAction : STYLE1, STYLE2, STYLE3 881 883 */ 882 884 void G4OpenGLQtViewer::toggleMouseAction(mouseActions aAction) { 883 885 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; 885 892 #if QT_VERSION < 0x040000 886 893 fMouseRotate->setItemChecked (0,true); … … 894 901 fMousePick->setChecked (false); 895 902 #endif 896 fMouseAction = ROTATE;903 fMouseAction = STYLE1; 897 904 fVP.SetPicking(false); 898 } else if (aAction == MOVE) { 905 } else if (aAction == STYLE2) { 906 G4cout << "Clic and move mouse to move Volume \n" << G4endl; 899 907 #if QT_VERSION < 0x040000 900 908 fMouseRotate->setItemChecked (0,false); … … 908 916 fMousePick->setChecked (false); 909 917 #endif 910 fMouseAction = MOVE;918 fMouseAction = STYLE2; 911 919 fVP.SetPicking(false); 912 } else if (aAction == ZOOM) { 920 } else if (aAction == STYLE3) { 921 G4cout << "Clic and move mouse to rotate Volume \n" << G4endl; 913 922 #if QT_VERSION < 0x040000 914 923 fMouseRotate->setItemChecked (0,false); … … 922 931 fMousePick->setChecked (false); 923 932 #endif 924 fMouseAction = ZOOM;933 fMouseAction = STYLE3; 925 934 fVP.SetPicking(false); 926 } else if (aAction == PICK) {935 } else if (aAction == STYLE4) { 927 936 #if QT_VERSION < 0x040000 928 937 fMouseRotate->setItemChecked (0,false); … … 937 946 #endif 938 947 fVP.SetPicking(true); 939 fMouseAction = PICK;948 fMouseAction = STYLE4; 940 949 } 941 950 … … 1313 1322 void G4OpenGLQtViewer::G4MousePressEvent(QPoint p) 1314 1323 { 1315 lastPos = p;1316 if (fMouseAction == PICK){ // pick1324 fLastPos = p; 1325 if (fMouseAction == STYLE4){ // pick 1317 1326 Pick(p.x(),p.y()); 1318 1327 } 1319 1328 } 1329 1320 1330 1321 1331 /** … … 1326 1336 1327 1337 #if QT_VERSION < 0x040000 1328 void G4OpenGLQtViewer::G4Mouse MoveEvent(int pos_x, int pos_y,Qt::ButtonState mButtons)1329 #else 1330 void G4OpenGLQtViewer::G4Mouse MoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons)1338 void G4OpenGLQtViewer::G4MouseEvent(int pos_x, int pos_y,Qt::ButtonState mButtons) 1339 #else 1340 void G4OpenGLQtViewer::G4MouseEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons) 1331 1341 #endif 1332 1342 { 1333 int dx = pos_x - lastPos.x();1334 int dy = pos_y - lastPos.y();1335 if (fMouseAction == ROTATE) { // rotate1343 int dx = pos_x - fLastPos.x(); 1344 int dy = pos_y - fLastPos.y(); 1345 if (fMouseAction == STYLE1) { // rotate 1336 1346 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); 1393 1348 } 1394 } else if (fMouseAction == MOVE){ // move1349 } else if (fMouseAction == STYLE2){ // move 1395 1350 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); 1415 1352 } 1416 } else if (fMouseAction == ZOOM){ // zoom1353 } else if (fMouseAction == STYLE3){ // zoom 1417 1354 if (mButtons & Qt::LeftButton) { 1418 1355 G4cerr << "Zoom not implemented for the moment\n" << G4endl; 1419 1356 } 1420 1357 } 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 1366 void 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 1399 void 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 1422 1452 } 1423 1453 … … 1712 1742 #endif 1713 1743 1744 void 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 1714 1777 /* 1715 1778 1716 1779 void MultiLayer::exportToSVG(const QString& fname) 1717 1780 { -
trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc
r690 r696 52 52 QGLWidget(QGLFormat(QGL::SampleBuffers)) // FIXME : gerer le pb du parent ! 53 53 { 54 setFocusPolicy(Qt::StrongFocus); // enable keybord events 54 55 nbPaint =0; 55 56 hasToRepaint =false; … … 311 312 } 312 313 314 void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event) 315 { 316 G4keyPressEvent(event); 317 } 318 313 319 /** 314 320 * This function was build in order to make a zoom on double clic event. … … 336 342 337 343 #if QT_VERSION < 0x040000 338 G4Mouse MoveEvent(event->x(),event->y(),event->state());344 G4MouseEvent(event->x(),event->y(),event->state()); 339 345 #else 340 G4Mouse MoveEvent(event->x(),event->y(),event->buttons());346 G4MouseEvent(event->x(),event->y(),event->buttons()); 341 347 #endif 342 348 }
Note: See TracChangeset
for help on using the changeset viewer.