1256 {
1257 SoCamera *cam = getCamera();
1258 const SoType type(ev->getTypeId());
1259
1260 if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
1261 SoMouseButtonEvent * me = (SoMouseButtonEvent *) ev;
1262
1263 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
1264 || currentState == PAUSED_ANIMATION) {
1265 switch (me->getButton()) {
1266 case SoMouseButtonEvent::BUTTON4:
1267 if (me->getState() == SoButtonEvent::DOWN) {
1268 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1269 float hAngle =
1270 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
1271 ((SoPerspectiveCamera *) cam)->heightAngle = hAngle
1272 + 0.01f;
1274 } else if (cam->isOfType(
1275 SoOrthographicCamera::getClassTypeId())) {
1276 float height =
1277 ((SoOrthographicCamera *) cam)->height.getValue();
1278 ((SoOrthographicCamera *) cam)->height = height + 5;
1280 }
1281 }
1282 break;
1283 case SoMouseButtonEvent::BUTTON5:
1284 if (me->getState() == SoButtonEvent::DOWN) {
1285 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1286 float hAngle =
1287 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
1288 if (hAngle > 0.01)
1289 ((SoPerspectiveCamera *) cam)->heightAngle = hAngle
1290 - 0.01f;
1292 } else if (cam->isOfType(
1293 SoOrthographicCamera::getClassTypeId())) {
1294 float height =
1295 ((SoOrthographicCamera *) cam)->height.getValue();
1296 if (height > 5)
1297 ((SoOrthographicCamera *) cam)->height = height - 5;
1299 }
1300 }
1301 break;
1302 default:
1303 break;
1304 }
1305 }
1306 if (currentState == GENERAL) {
1307
1308 }
1309 }
1310
1311 if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
1312 SoKeyboardEvent * ke = (SoKeyboardEvent *) ev;
1313
1314 if (SoKeyboardEvent::isKeyPressEvent(ev, ke->getKey())) {
1315 switch (ke->getKey()) {
1316 case SoKeyboardEvent::LEFT_SHIFT:
1317 this->lshiftdown = true;
1319 case SoKeyboardEvent::RIGHT_SHIFT:
1320 this->rshiftdown = true;
1322 case SoKeyboardEvent::LEFT_CONTROL:
1323 this->lctrldown = true;
1325 case SoKeyboardEvent::RIGHT_CONTROL:
1326 this->rctrldown = true;
1328 case SoKeyboardEvent::SPACE:
1329 if (currentState == ANIMATION
1330 || currentState == REVERSED_ANIMATION) {
1331 beforePausing = currentState;
1332 currentState = PAUSED_ANIMATION;
1333 if (animateSensor->isScheduled())
1334 animateSensor->unschedule();
1336 } else if (currentState == PAUSED_ANIMATION) {
1337 if (maxSpeed) {
1338 if ((beforePausing == ANIMATION
1339 && refParticleIdx
1340 < (int) refParticleTrajectory.size() - 1)
1341 || (beforePausing == REVERSED_ANIMATION
1342 && refParticleIdx > 0)) {
1343 currentState = beforePausing;
1344 animateRefParticle();
1345 }
1346 }
1348 }
1349 break;
1350 case SoKeyboardEvent::ESCAPE:
1351 if (currentState == ANIMATION
1352 || currentState == REVERSED_ANIMATION
1353 || currentState == PAUSED_ANIMATION) {
1354
1355 if (animateSensor->isScheduled())
1356 animateSensor->unschedule();
1357 currentState = prevState;
1358 refParticleIdx = prevRefIdx;
1359 setSuperimpositionEnabled(superimposition,
FALSE);
1360 maxSpeed = 0.0f;
1361 step = 1;
1362
1363 scheduleRedraw();
1364 if (currentState == VIEWPOINT) {
1365 setSuperimpositionEnabled(superimposition,
TRUE);
1366 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
1367 animSpeedOutlineSwitch->whichChild.setValue(
1368 SO_SWITCH_NONE);
1369 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
1370
1371 scheduleRedraw();
1372 }
1373 restoreCamera();
1375 }
1376 break;
1377 case SoKeyboardEvent::DELETE:
1378 if (viewPtList.size()
1379 && (currentState != ANIMATION
1380 || currentState != REVERSED_ANIMATION
1381 || currentState != PAUSED_ANIMATION)) {
1382 String dialogName = (char *) "Delete Viewpoint";
1383 std::string msg = "Are you sure you want to delete current viewpoint?";
1386 }
1387 break;
1388 case SoKeyboardEvent::LEFT_ARROW:
1389 switch (currentState) {
1390 case BEAMLINE:
1391 if ((this->lshiftdown) || (this->rshiftdown)){
1392 refParticleIdx -= step;
1394 }
1395 else if ((this->lctrldown) || (this->rctrldown)){
1396 if (SoXtExaminerViewer::isAnimating())
1397 stopAnimating();
1398 prevState = currentState;
1399 currentState = ROTATING;
1400 animateBtwPtsPeriod = 0.08f;
1401
1403 tmp.negate();
1404 rotAxis = tmp;
1405
1408
1410 }
1411 else{
1412 if (SoXtExaminerViewer::isAnimating())
1413 stopAnimating();
1414 prevState = currentState;
1415 currentState = ROTATING;
1416 animateBtwPtsPeriod = 0.08f;
1417
1419 tmp.negate();
1420 rotAxis = tmp;
1421
1424
1426
1427 }
1429
1430 case ANIMATION:
1431 case REVERSED_ANIMATION:
1432 left_right -= 1.5f;
1434 case PAUSED_ANIMATION:
1435 left_right -= 1.5f;
1436 setStartingPtForAnimation();
1437 cam->position = myCam->position;
1439 case GENERAL:
1440 case VIEWPOINT:
1441 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1442
1443
1444 this->bottomWheelMotion(
1445 this->getBottomWheelValue() + 0.1f);
1446
1448 }
1449 break;
1450 case ROTATING:
1451
1452
1453 break;
1454 default:
1455 SoDebugError::post("G4OpenInventorXtExaminerViewer::processSoEvent",
1456 "Unhandled viewer state");
1457 break;
1458 }
1459 break;
1460
1461 case SoKeyboardEvent::RIGHT_ARROW:
1462 switch(currentState){
1463 case BEAMLINE:
1464 if ((this->lshiftdown) || (this->rshiftdown)){
1465 refParticleIdx += step;
1467 }
1468 else if ((this->lctrldown) || (this->rctrldown)){
1469 if (SoXtExaminerViewer::isAnimating())
1470 stopAnimating();
1471 prevState = currentState;
1472 currentState = ROTATING;
1473 animateBtwPtsPeriod = 0.08f;
1474
1476
1479
1481 }
1482 else{
1483 if (SoXtExaminerViewer::isAnimating())
1484 stopAnimating();
1485 prevState = currentState;
1486 currentState = ROTATING;
1487 animateBtwPtsPeriod = 0.08f;
1488
1490
1493
1495 }
1497
1498 case ANIMATION:
1499 case REVERSED_ANIMATION:
1500 left_right += 1.5f;
1502 case PAUSED_ANIMATION:
1503 left_right += 1.5f;
1504 setStartingPtForAnimation();
1505 cam->position = myCam->position;
1507 case GENERAL:
1508 case VIEWPOINT:
1509 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1510
1511
1512 this->bottomWheelMotion(
1513 this->getBottomWheelValue() - 0.1f);
1515 }
1516 break;
1517 case ROTATING:
1518
1519
1520 break;
1521 default:
1522 SoDebugError::post("G4OpenInventorXtExaminerViewer::processSoEvent",
1523 "Unhandled viewer state");
1524 break;
1525 }
1526 break;
1527
1528 case SoKeyboardEvent::DOWN_ARROW:
1529 switch(currentState){
1530 case BEAMLINE:
1531
1532 if ((this->lshiftdown) || (this->rshiftdown)){
1533 refParticleIdx -= step;
1535 }
1536 else{
1537 if (SoXtExaminerViewer::isAnimating())
1538 stopAnimating();
1539 prevState = currentState;
1540 currentState = ROTATING;
1541 animateBtwPtsPeriod = 0.08f;
1542
1544
1547
1549
1550 }
1552
1553 case ANIMATION:
1554 case REVERSED_ANIMATION:
1555 up_down -= 1.5f;
1557 case PAUSED_ANIMATION:
1558 up_down -= 1.5f;
1559 setStartingPtForAnimation();
1560 cam->position = myCam->position;
1562 case GENERAL:
1563 case VIEWPOINT:
1564
1565
1566 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1567 this->leftWheelMotion(this->getLeftWheelValue() - 0.1f);
1569 }
1570 break;
1571 case ROTATING:
1572
1573
1574 break;
1575 default:
1576 SoDebugError::post("G4OpenInventorXtExaminerViewer::processSoEvent",
1577 "Unhandled viewer state");
1578 break;
1579 }
1580 break;
1581
1582 case SoKeyboardEvent::UP_ARROW:
1583 switch(currentState){
1584 case BEAMLINE:
1585 if ((this->lshiftdown) || (this->rshiftdown)){
1586 refParticleIdx -= step;
1588 }
1589 else{
1590 if (SoXtExaminerViewer::isAnimating())
1591 stopAnimating();
1592 prevState = currentState;
1593 currentState = ROTATING;
1594 animateBtwPtsPeriod = 0.08f;
1595
1597
1600
1602
1603
1604 }
1606 case ANIMATION:
1607 case REVERSED_ANIMATION:
1608 up_down += 1.5f;
1610 case PAUSED_ANIMATION:
1611 up_down += 1.5f;
1612 setStartingPtForAnimation();
1613 cam->position = myCam->position;
1615 case GENERAL:
1616 case VIEWPOINT:
1617
1618
1619 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1620 this->leftWheelMotion(this->getLeftWheelValue() + 0.1f);
1622 }
1623 break;
1624 case ROTATING:
1625
1626
1627 break;
1628 default:
1629 SoDebugError::post("G4OpenInventorXtExaminerViewer::processSoEvent",
1630 "Unhandled viewer state");
1631 break;
1632 }
1633 break;
1634
1635 case SoKeyboardEvent::PAGE_UP:
1636 switch(currentState){
1637 case BEAMLINE:
1638 if (step < (int) refParticleTrajectory.size() / 5)
1639 step++;
1641 case ANIMATION:
1642 incSpeed();
1644 if (maxSpeed > 0.8)
1646 scheduleRedraw();
1647
1649 case REVERSED_ANIMATION:
1650 if(!animateSensor->isScheduled()){
1651 currentState = ANIMATION;
1652 if (refParticleIdx
1653 < (int) refParticleTrajectory.size() - 1) {
1654 refParticleIdx++;
1656 scheduleRedraw();
1657 animateRefParticle();
1658 }
1659 }
1660 else{
1662 decSpeed();
1663 scheduleRedraw();
1664 }
1666 case PAUSED_ANIMATION:
1668 if (maxSpeed > 0.8)
1670
1671 if (beforePausing == ANIMATION) {
1672 incSpeed();
1673 } else {
1674 decSpeed();
1676 beforePausing = ANIMATION;
1677 }
1678
1679 scheduleRedraw();
1681 default:
1682 break;
1683 }
1684 break;
1685
1686 case SoKeyboardEvent::PAGE_DOWN:
1687 switch(currentState){
1688 case BEAMLINE:
1689 if (step > 1)
1690 step--;
1692 case ANIMATION:
1693 if(!animateSensor->isScheduled()){
1694 currentState = REVERSED_ANIMATION;
1695 if (refParticleIdx > 1) {
1696 refParticleIdx--;
1698 scheduleRedraw();
1699 animateRefParticle();
1700 }
1701 }
1702 else{
1704 decSpeed();
1705 scheduleRedraw();
1706 }
1708 case REVERSED_ANIMATION:
1709 incSpeed();
1711 if (maxSpeed < -0.8)
1713 scheduleRedraw();
1715 case PAUSED_ANIMATION:
1717 if (maxSpeed < -0.8)
1719 if (beforePausing == REVERSED_ANIMATION) {
1720 incSpeed();
1721 } else {
1722 decSpeed();
1724 beforePausing = REVERSED_ANIMATION;
1725 }
1726 scheduleRedraw();
1728 default:
1729
1730 break;
1731 }
1732 break;
1733
1734 case SoKeyboardEvent::E:
1735 this->escapeCallback(this->examinerObject);
1736 break;
1737
1738 default:
1739 break;
1740 }
1741 }
1742 if (SoKeyboardEvent::isKeyReleaseEvent(ev, ke->getKey())) {
1743 switch (ke->getKey()) {
1744 case SoKeyboardEvent::LEFT_SHIFT:
1745 this->lshiftdown = false;
1747 case SoKeyboardEvent::RIGHT_SHIFT:
1748 this->rshiftdown = false;
1750 case SoKeyboardEvent::LEFT_CONTROL:
1751 this->lctrldown = false;
1753 case SoKeyboardEvent::RIGHT_CONTROL:
1754 this->rctrldown = false;
1756 default:
1757 break;
1758 }
1759 }
1760 }
1761
1762 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
1763 || currentState == ROTATING)
1765 else
1766 return SoXtExaminerViewer::processSoEvent(ev);
1767}
#define MAX_SPEED_INDICATOR
#define SPEED_INDICATOR_STEP
void moveCamera(float dist=0, bool lookdown=false)