1375 {
1376 SoCamera *cam = getCamera();
1377 const SoType type(ev->getTypeId());
1378
1379 if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
1380 SoMouseButtonEvent * me = (SoMouseButtonEvent *) ev;
1381
1382 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
1383 || currentState == PAUSED_ANIMATION) {
1384 switch (me->getButton()) {
1385 case SoMouseButtonEvent::BUTTON4:
1386 if (me->getState() == SoButtonEvent::DOWN) {
1387 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1388 float hAngle =
1389 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
1390 ((SoPerspectiveCamera *) cam)->heightAngle = hAngle
1391 + 0.01f;
1393 } else if (cam->isOfType(
1394 SoOrthographicCamera::getClassTypeId())) {
1395 float height =
1396 ((SoOrthographicCamera *) cam)->height.getValue();
1397 ((SoOrthographicCamera *) cam)->height = height + 5;
1399 }
1400 }
1401 break;
1402 case SoMouseButtonEvent::BUTTON5:
1403 if (me->getState() == SoButtonEvent::DOWN) {
1404 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1405 float hAngle =
1406 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
1407 if (hAngle > 0.01)
1408 ((SoPerspectiveCamera *) cam)->heightAngle = hAngle
1409 - 0.01f;
1411 } else if (cam->isOfType(
1412 SoOrthographicCamera::getClassTypeId())) {
1413 float height =
1414 ((SoOrthographicCamera *) cam)->height.getValue();
1415 if (height > 5)
1416 ((SoOrthographicCamera *) cam)->height = height - 5;
1418 }
1419 }
1420 break;
1421 default:
1422 break;
1423 }
1424 }
1425 if (currentState == GENERAL) {
1426
1427 }
1428 }
1429
1430 if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
1431 SoKeyboardEvent * ke = (SoKeyboardEvent *) ev;
1432
1433 if (SoKeyboardEvent::isKeyPressEvent(ev, ke->getKey())) {
1434 switch (ke->getKey()) {
1435 case SoKeyboardEvent::LEFT_SHIFT:
1436 this->lshiftdown = true;
1438 case SoKeyboardEvent::RIGHT_SHIFT:
1439 this->rshiftdown = true;
1441 case SoKeyboardEvent::LEFT_CONTROL:
1442 this->lctrldown = true;
1444 case SoKeyboardEvent::RIGHT_CONTROL:
1445 this->rctrldown = true;
1447 case SoKeyboardEvent::SPACE:
1448 if (currentState == ANIMATION
1449 || currentState == REVERSED_ANIMATION) {
1450 beforePausing = currentState;
1451 currentState = PAUSED_ANIMATION;
1452 if (animateSensor->isScheduled())
1453 animateSensor->unschedule();
1455 } else if (currentState == PAUSED_ANIMATION) {
1456 if (maxSpeed) {
1457 if ((beforePausing == ANIMATION
1458 && refParticleIdx
1459 < (int) refParticleTrajectory.size() - 1)
1460 || (beforePausing == REVERSED_ANIMATION
1461 && refParticleIdx > 0)) {
1462 currentState = beforePausing;
1463 animateRefParticle();
1464 }
1465 }
1467 }
1468 break;
1469 case SoKeyboardEvent::ESCAPE:
1470 if (currentState == ANIMATION
1471 || currentState == REVERSED_ANIMATION
1472 || currentState == PAUSED_ANIMATION) {
1473
1474 if (animateSensor->isScheduled())
1475 animateSensor->unschedule();
1476 currentState = prevState;
1477 refParticleIdx = prevRefIdx;
1478 setSuperimpositionEnabled(superimposition,
FALSE);
1479 maxSpeed = 0.0f;
1480 step = 1;
1481
1482 scheduleRedraw();
1483 if (currentState == VIEWPOINT) {
1484 setSuperimpositionEnabled(superimposition,
TRUE);
1485 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
1486 animSpeedOutlineSwitch->whichChild.setValue(
1487 SO_SWITCH_NONE);
1488 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
1489
1490 scheduleRedraw();
1491 }
1492 restoreCamera();
1494 }
1495 break;
1496 case SoKeyboardEvent::DELETE:
1497 if (viewPtList.size()
1498 && (currentState != ANIMATION
1499 && currentState != REVERSED_ANIMATION
1500 && currentState != PAUSED_ANIMATION)) {
1501 String dialogName = (char *) "Delete Viewpoint";
1502 std::string msg = "Are you sure you want to delete current viewpoint?";
1505 }
1506 break;
1507 case SoKeyboardEvent::LEFT_ARROW:
1508 switch (currentState) {
1509 case BEAMLINE:
1510 if ((this->lshiftdown) || (this->rshiftdown)){
1511 refParticleIdx -= step;
1513 }
1514 else if ((this->lctrldown) || (this->rctrldown)){
1515 if (SoXtExaminerViewer::isAnimating())
1516 stopAnimating();
1517 prevState = currentState;
1518 currentState = ROTATING;
1519 animateBtwPtsPeriod = 0.08f;
1520
1522 tmp.negate();
1523 rotAxis = tmp;
1524
1527
1529 }
1530 else{
1531 if (SoXtExaminerViewer::isAnimating())
1532 stopAnimating();
1533 prevState = currentState;
1534 currentState = ROTATING;
1535 animateBtwPtsPeriod = 0.08f;
1536
1538 tmp.negate();
1539 rotAxis = tmp;
1540
1543
1545
1546 }
1548
1549 case ANIMATION:
1550 case REVERSED_ANIMATION:
1551 left_right -= 1.5f;
1553 case PAUSED_ANIMATION:
1554 left_right -= 1.5f;
1555 setStartingPtForAnimation();
1556 cam->position = myCam->position;
1558 case GENERAL:
1559 case VIEWPOINT:
1560 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1561
1562
1563 this->bottomWheelMotion(
1564 this->getBottomWheelValue() + 0.1f);
1565
1567 }
1568 break;
1569 case ROTATING:
1570
1571
1572 break;
1573 default:
1574 SoDebugError::post("G4OpenInventorXtExaminerViewer::processSoEvent",
1575 "Unhandled viewer state");
1576 break;
1577 }
1578 break;
1579
1580 case SoKeyboardEvent::RIGHT_ARROW:
1581 switch(currentState){
1582 case BEAMLINE:
1583 if ((this->lshiftdown) || (this->rshiftdown)){
1584 refParticleIdx += step;
1586 }
1587 else if ((this->lctrldown) || (this->rctrldown)){
1588 if (SoXtExaminerViewer::isAnimating())
1589 stopAnimating();
1590 prevState = currentState;
1591 currentState = ROTATING;
1592 animateBtwPtsPeriod = 0.08f;
1593
1595
1598
1600 }
1601 else{
1602 if (SoXtExaminerViewer::isAnimating())
1603 stopAnimating();
1604 prevState = currentState;
1605 currentState = ROTATING;
1606 animateBtwPtsPeriod = 0.08f;
1607
1609
1612
1614 }
1616
1617 case ANIMATION:
1618 case REVERSED_ANIMATION:
1619 left_right += 1.5f;
1621 case PAUSED_ANIMATION:
1622 left_right += 1.5f;
1623 setStartingPtForAnimation();
1624 cam->position = myCam->position;
1626 case GENERAL:
1627 case VIEWPOINT:
1628 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1629
1630
1631 this->bottomWheelMotion(
1632 this->getBottomWheelValue() - 0.1f);
1634 }
1635 break;
1636 case ROTATING:
1637
1638
1639 break;
1640 default:
1641 SoDebugError::post("G4OpenInventorXtExaminerViewer::processSoEvent",
1642 "Unhandled viewer state");
1643 break;
1644 }
1645 break;
1646
1647 case SoKeyboardEvent::DOWN_ARROW:
1648 switch(currentState){
1649 case BEAMLINE:
1650
1651 if ((this->lshiftdown) || (this->rshiftdown)){
1652 refParticleIdx -= step;
1654 }
1655 else{
1656 if (SoXtExaminerViewer::isAnimating())
1657 stopAnimating();
1658 prevState = currentState;
1659 currentState = ROTATING;
1660 animateBtwPtsPeriod = 0.08f;
1661
1663
1666
1668
1669 }
1671
1672 case ANIMATION:
1673 case REVERSED_ANIMATION:
1674 up_down -= 1.5f;
1676 case PAUSED_ANIMATION:
1677 up_down -= 1.5f;
1678 setStartingPtForAnimation();
1679 cam->position = myCam->position;
1681 case GENERAL:
1682 case VIEWPOINT:
1683
1684
1685 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1686 this->leftWheelMotion(this->getLeftWheelValue() - 0.1f);
1688 }
1689 break;
1690 case ROTATING:
1691
1692
1693 break;
1694 default:
1695 SoDebugError::post("G4OpenInventorXtExaminerViewer::processSoEvent",
1696 "Unhandled viewer state");
1697 break;
1698 }
1699 break;
1700
1701 case SoKeyboardEvent::UP_ARROW:
1702 switch(currentState){
1703 case BEAMLINE:
1704 if ((this->lshiftdown) || (this->rshiftdown)){
1705 refParticleIdx -= step;
1707 }
1708 else{
1709 if (SoXtExaminerViewer::isAnimating())
1710 stopAnimating();
1711 prevState = currentState;
1712 currentState = ROTATING;
1713 animateBtwPtsPeriod = 0.08f;
1714
1716
1719
1721
1722
1723 }
1725 case ANIMATION:
1726 case REVERSED_ANIMATION:
1727 up_down += 1.5f;
1729 case PAUSED_ANIMATION:
1730 up_down += 1.5f;
1731 setStartingPtForAnimation();
1732 cam->position = myCam->position;
1734 case GENERAL:
1735 case VIEWPOINT:
1736
1737
1738 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1739 this->leftWheelMotion(this->getLeftWheelValue() + 0.1f);
1741 }
1742 break;
1743 case ROTATING:
1744
1745
1746 break;
1747 default:
1748 SoDebugError::post("G4OpenInventorXtExaminerViewer::processSoEvent",
1749 "Unhandled viewer state");
1750 break;
1751 }
1752 break;
1753
1754 case SoKeyboardEvent::PAGE_UP:
1755 switch(currentState){
1756 case BEAMLINE:
1757 if (step < (int) refParticleTrajectory.size() / 5)
1758 step++;
1760 case ANIMATION:
1761 incSpeed();
1763 if (maxSpeed > 0.8)
1765 scheduleRedraw();
1766
1768 case REVERSED_ANIMATION:
1769 if(!animateSensor->isScheduled()){
1770 currentState = ANIMATION;
1771 if (refParticleIdx
1772 < (int) refParticleTrajectory.size() - 1) {
1773 refParticleIdx++;
1775 scheduleRedraw();
1776 animateRefParticle();
1777 }
1778 }
1779 else{
1781 decSpeed();
1782 scheduleRedraw();
1783 }
1785 case PAUSED_ANIMATION:
1787 if (maxSpeed > 0.8)
1789
1790 if (beforePausing == ANIMATION) {
1791 incSpeed();
1792 } else {
1793 decSpeed();
1795 beforePausing = ANIMATION;
1796 }
1797
1798 scheduleRedraw();
1800 default:
1801 break;
1802 }
1803 break;
1804
1805 case SoKeyboardEvent::PAGE_DOWN:
1806 switch(currentState){
1807 case BEAMLINE:
1808 if (step > 1)
1809 step--;
1811 case ANIMATION:
1812 if(!animateSensor->isScheduled()){
1813 currentState = REVERSED_ANIMATION;
1814 if (refParticleIdx > 1) {
1815 refParticleIdx--;
1817 scheduleRedraw();
1818 animateRefParticle();
1819 }
1820 }
1821 else{
1823 decSpeed();
1824 scheduleRedraw();
1825 }
1827 case REVERSED_ANIMATION:
1828 incSpeed();
1830 if (maxSpeed < -0.8)
1832 scheduleRedraw();
1834 case PAUSED_ANIMATION:
1836 if (maxSpeed < -0.8)
1838 if (beforePausing == REVERSED_ANIMATION) {
1839 incSpeed();
1840 } else {
1841 decSpeed();
1843 beforePausing = REVERSED_ANIMATION;
1844 }
1845 scheduleRedraw();
1847 default:
1848
1849 break;
1850 }
1851 break;
1852
1853 case SoKeyboardEvent::E:
1854 this->escapeCallback(this->examinerObject);
1855 break;
1856
1857 default:
1858 break;
1859 }
1860 }
1861 if (SoKeyboardEvent::isKeyReleaseEvent(ev, ke->getKey())) {
1862 switch (ke->getKey()) {
1863 case SoKeyboardEvent::LEFT_SHIFT:
1864 this->lshiftdown = false;
1866 case SoKeyboardEvent::RIGHT_SHIFT:
1867 this->rshiftdown = false;
1869 case SoKeyboardEvent::LEFT_CONTROL:
1870 this->lctrldown = false;
1872 case SoKeyboardEvent::RIGHT_CONTROL:
1873 this->rctrldown = false;
1875 default:
1876 break;
1877 }
1878 }
1879 }
1880
1881 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
1882 || currentState == ROTATING)
1884 else
1885 return SoXtExaminerViewer::processSoEvent(ev);
1886}
#define MAX_SPEED_INDICATOR
#define SPEED_INDICATOR_STEP
void moveCamera(float dist=0, bool lookdown=false)