Commit d3c3608d781d194df494c6f1c7ee61bbba60e82c
1 parent
ef480e03
Exists in
master
and in
66 other branches
Add undo zoom
Showing
1 changed file
with
208 additions
and
4 deletions
Show diff stats
src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php
... | ... | @@ -26,12 +26,20 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
26 | 26 | { |
27 | 27 | $this->interactiveRequestRealIndexes = array(); |
28 | 28 | |
29 | + $fullResetZoom = false; | |
30 | + | |
29 | 31 | if (isset($input->{'action'})) |
32 | + { | |
30 | 33 | $input = $this->unmarshallActionRequest($input); |
34 | + $forceTimeZoomReset = isset($input->{'force-time-zoom-reset'}) ? $input->{'force-time-zoom-reset'} : false; | |
35 | + } | |
31 | 36 | else |
37 | + { | |
38 | + $resetZoom = true; | |
32 | 39 | //save request |
33 | 40 | $this->saveIHMRequest($input); |
34 | - | |
41 | + } | |
42 | + | |
35 | 43 | //Get active tab |
36 | 44 | $activeTab = NULL; |
37 | 45 | foreach ($input->tabs as $tab) |
... | ... | @@ -72,6 +80,9 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
72 | 80 | //Plot only current active tab when 'force-single-replot' is active |
73 | 81 | continue; |
74 | 82 | } |
83 | + //Reset zoom list if needed | |
84 | + if ($fullResetZoom || $forceTimeZoomReset) | |
85 | + $this->resetZoomListForTab($tab->{'id'}, $forceTimeZoomReset && !$fullResetZoom); | |
75 | 86 | } |
76 | 87 | else |
77 | 88 | { |
... | ... | @@ -81,6 +92,9 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
81 | 92 | //In no interactive request, plot only active tab |
82 | 93 | continue; |
83 | 94 | } |
95 | + //Reset zoom list if needed | |
96 | + if ($fullResetZoom || $forceTimeZoomReset) | |
97 | + $this->resetZoomListForTab($tab->{'id'}, $forceTimeZoomReset && !$fullResetZoom); | |
84 | 98 | } |
85 | 99 | } |
86 | 100 | |
... | ... | @@ -1496,12 +1510,146 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
1496 | 1510 | return $this->unmarshallSynchronize($actionInput, $plotInput); |
1497 | 1511 | case 'instant' : |
1498 | 1512 | return $this->unmarshallInstant($actionInput, $plotInput); |
1513 | + case 'undozoom' : | |
1514 | + return $this->unmarshallUndoZoom($actionInput, $plotInput); | |
1499 | 1515 | default : |
1500 | 1516 | throw new Exception('Interactive action not implemented.'); |
1501 | 1517 | } |
1502 | 1518 | } |
1503 | 1519 | |
1504 | - private function unmarshallZoom($input, $plotInput) | |
1520 | + private function addZoomInList($input, $isInterval, $minOrFileIndex, $maxOrIntervalIndex) | |
1521 | + { | |
1522 | + //if $isInterval == true, $minOrFileIndex is the min and $maxOrInetrvalIndex is the max | |
1523 | + //if $isInterval == false, $minOrFileIndex is the fileIndex and $maxOrInetrvalIndex is the intervalIndex | |
1524 | + | |
1525 | + $zoomList = $this->loadZoomList(); | |
1526 | + | |
1527 | + if (!isset($zoomList->tabs)) | |
1528 | + { | |
1529 | + //Init zoom list | |
1530 | + $zoomList = (Object)array( | |
1531 | + 'tabs' => (Object)array() | |
1532 | + ); | |
1533 | + } | |
1534 | + | |
1535 | + if (!isset($zoomList->tabs->{$input->{'tabId'}})) | |
1536 | + { | |
1537 | + $zoomList->tabs->{$input->{'tabId'}} = (Object)array( | |
1538 | + 'times' => array(), | |
1539 | + 'panels' => (Object)array() | |
1540 | + ); | |
1541 | + } | |
1542 | + | |
1543 | + if ($input->{'axeId'} == 'timeAxis') | |
1544 | + { | |
1545 | + if ($isInterval) | |
1546 | + array_push ($zoomList->tabs->{$input->{'tabId'}}->times, (Object)array( | |
1547 | + 'isInterval' => true, | |
1548 | + 'min' => $minOrFileIndex, | |
1549 | + 'max' => $maxOrIntervalIndex | |
1550 | + )); | |
1551 | + else | |
1552 | + array_push ($zoomList->tabs->{$input->{'tabId'}}->times, (Object)array( | |
1553 | + 'isInterval' => false, | |
1554 | + 'ttFileIndex' => $minOrFileIndex, | |
1555 | + 'intIndex' => $maxOrIntervalIndex | |
1556 | + )); | |
1557 | + } | |
1558 | + else | |
1559 | + { | |
1560 | + if (!isset($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}})) | |
1561 | + { | |
1562 | + $zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}} = (Object) array( | |
1563 | + 'axes' => (Object)array() | |
1564 | + ); | |
1565 | + } | |
1566 | + | |
1567 | + if (!isset($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}})) | |
1568 | + { | |
1569 | + $zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}} = array(); | |
1570 | + } | |
1571 | + | |
1572 | + array_push ($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}}, (Object)array( | |
1573 | + 'min' => $minOrFileIndex, | |
1574 | + 'max' => $maxOrIntervalIndex | |
1575 | + )); | |
1576 | + } | |
1577 | + | |
1578 | + //save zoom list | |
1579 | + $path = $this->getWorkingPath()."zoom.list"; | |
1580 | + if (!is_dir($this->getWorkingPath())) | |
1581 | + mkdir($this->getWorkingPath(),0777); | |
1582 | + $file = fopen($path, 'w'); | |
1583 | + fwrite($file, json_encode($zoomList)); | |
1584 | + fclose($file); | |
1585 | + } | |
1586 | + | |
1587 | + private function loadZoomList() | |
1588 | + { | |
1589 | + $path = $this->getWorkingPath()."zoom.list"; | |
1590 | + if (!file_exists($path)) | |
1591 | + return NULL; | |
1592 | + return json_decode(file_get_contents($path)); | |
1593 | + } | |
1594 | + | |
1595 | + private function resetZoomListForTab($tabId, $resetOnlyTimeZoom = false) | |
1596 | + { | |
1597 | + $zoomList = $this->loadZoomList(); | |
1598 | + | |
1599 | + if (isset($zoomList->tabs) && isset($zoomList->tabs->{PLOT_RESULT_FILE_KEY."_".$tabId})) | |
1600 | + { | |
1601 | + if (!$resetOnlyTimeZoom) | |
1602 | + unset($zoomList->tabs->{PLOT_RESULT_FILE_KEY."_".$tabId}); | |
1603 | + else | |
1604 | + $zoomList->tabs->{PLOT_RESULT_FILE_KEY."_".$tabId}->times = array(); | |
1605 | + } | |
1606 | + | |
1607 | + $path = $this->getWorkingPath()."zoom.list"; | |
1608 | + if (!is_dir($this->getWorkingPath())) | |
1609 | + mkdir($this->getWorkingPath(),0777); | |
1610 | + $file = fopen($path, 'w'); | |
1611 | + fwrite($file, json_encode($zoomList)); | |
1612 | + fclose($file); | |
1613 | + } | |
1614 | + | |
1615 | + private function undoZoomInList($input) | |
1616 | + { | |
1617 | + $zoomList = $this->loadZoomList(); | |
1618 | + | |
1619 | + $result = NULL; | |
1620 | + if (isset($zoomList->tabs) && isset($zoomList->tabs->{$input->{'tabId'}})) | |
1621 | + { | |
1622 | + if ($input->{'axeId'} == 'timeAxis') | |
1623 | + { | |
1624 | + if (count($zoomList->tabs->{$input->{'tabId'}}->times) <= 0) | |
1625 | + return NULL; | |
1626 | + $result = array_pop($zoomList->tabs->{$input->{'tabId'}}->times); | |
1627 | + } | |
1628 | + else | |
1629 | + { | |
1630 | + if (!isset($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}})) | |
1631 | + return NULL; | |
1632 | + | |
1633 | + if (!isset($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}})) | |
1634 | + return NULL; | |
1635 | + | |
1636 | + $result = array_pop($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}}); | |
1637 | + } | |
1638 | + } | |
1639 | + else | |
1640 | + return NULL; | |
1641 | + | |
1642 | + $path = $this->getWorkingPath()."zoom.list"; | |
1643 | + if (!is_dir($this->getWorkingPath())) | |
1644 | + mkdir($this->getWorkingPath(),0777); | |
1645 | + $file = fopen($path, 'w'); | |
1646 | + fwrite($file, json_encode($zoomList)); | |
1647 | + fclose($file); | |
1648 | + | |
1649 | + return $result; | |
1650 | + } | |
1651 | + | |
1652 | + private function unmarshallZoom($input, $plotInput, $isUndo = false) | |
1505 | 1653 | { |
1506 | 1654 | //Find current tab |
1507 | 1655 | $crtTab = NULL; |
... | ... | @@ -1523,18 +1671,43 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
1523 | 1671 | if ($crtTab->{'multi-plot-linked'}) |
1524 | 1672 | { |
1525 | 1673 | //Update multi plot time definition |
1526 | - $plotInput->{'timesrc'} = 'Interval'; | |
1674 | + if ($plotInput->{'timesrc'} != 'Interval') | |
1675 | + { | |
1676 | + $plotInput->{'timesrc'} = 'Interval'; | |
1677 | + if (!$isUndo) | |
1678 | + $this->addZoomInList($input,false, | |
1679 | + isset($plotInput->{'ttFileIndex'}) ? $plotInput->{'ttFileIndex'}: 0, | |
1680 | + isset($plotInput->{'intIndex'}) ? $plotInput->{'intIndex'}: 0); | |
1681 | + } | |
1682 | + else | |
1683 | + { | |
1684 | + if (!$isUndo) | |
1685 | + $this->addZoomInList($input,true,$plotInput->{'startDate'},$plotInput->{'stopDate'}); | |
1686 | + } | |
1527 | 1687 | $plotInput->{'startDate'} = $input->{'min'}; |
1528 | 1688 | $plotInput->{'stopDate'} = $input->{'max'}; |
1529 | 1689 | } |
1530 | 1690 | else |
1531 | 1691 | { |
1532 | - $crtTab->{'timesrc'} = 'Interval'; | |
1692 | + if ($crtTab->{'timesrc'} != 'Interval') | |
1693 | + { | |
1694 | + $crtTab->{'timesrc'} = 'Interval'; | |
1695 | + if (!$isUndo) | |
1696 | + $this->addZoomInList($input,false, | |
1697 | + isset($crtTab->{'ttFileIndex'}) ? $crtTab->{'ttFileIndex'} : 0, | |
1698 | + isset($crtTab->{'intIndex'}) ? $crtTab->{'intIndex'} : 0); | |
1699 | + } | |
1700 | + else | |
1701 | + { | |
1702 | + if (!$isUndo) | |
1703 | + $this->addZoomInList($input,true,$crtTab->{'startDate'},$crtTab->{'stopDate'}); | |
1704 | + } | |
1533 | 1705 | $crtTab->{'startDate'} = $input->{'min'}; |
1534 | 1706 | $crtTab->{'stopDate'} = $input->{'max'}; |
1535 | 1707 | } |
1536 | 1708 | |
1537 | 1709 | $plotInput->{'last-plotted-tab'} = $crtTab->{'id'}; |
1710 | + $plotInput->{'force-time-zoom-reset'} = false; | |
1538 | 1711 | $this->saveIHMRequest($plotInput); |
1539 | 1712 | return $plotInput; |
1540 | 1713 | } |
... | ... | @@ -1549,12 +1722,17 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
1549 | 1722 | if ($input->{'axeId'} == $axis->{'id'}) |
1550 | 1723 | { |
1551 | 1724 | $axis->{'axis-range-extend'} = false; |
1725 | + $oldMin = $axis->{'axis-range-min'}; | |
1726 | + $oldMax = $axis->{'axis-range-max'}; | |
1552 | 1727 | $axis->{'axis-range-min'} = $input->{'min'}; |
1553 | 1728 | $axis->{'axis-range-max'} = $input->{'max'}; |
1554 | 1729 | $plotInput->{'last-plotted-tab'} = $crtTab->{'id'}; |
1555 | 1730 | $this->saveIHMRequest($plotInput); |
1556 | 1731 | //Do not save 'force-single-replot' in request file! |
1557 | 1732 | $plotInput->{'force-single-replot'} = true; |
1733 | + $plotInput->{'force-time-zoom-reset'} = false; | |
1734 | + if (!$isUndo) | |
1735 | + $this->addZoomInList($input,true,$oldMin,$oldMax); | |
1558 | 1736 | return $plotInput; |
1559 | 1737 | } |
1560 | 1738 | } |
... | ... | @@ -1564,6 +1742,27 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
1564 | 1742 | throw new Exception('Cannot retrieve plot panel for zoom action.'); |
1565 | 1743 | } |
1566 | 1744 | |
1745 | + private function unmarshallUndoZoom($input, $plotInput) | |
1746 | + { | |
1747 | + $result = $this->undoZoomInList($input); | |
1748 | + if ($result != NULL) | |
1749 | + { | |
1750 | + if (isset($result->isInterval)) | |
1751 | + { | |
1752 | + if (!$result->isInterval) | |
1753 | + { | |
1754 | + $input->ttFileIndex = $result->ttFileIndex; | |
1755 | + $input->intIndex = $result->intIndex; | |
1756 | + return $this->unmarshallTTGoto($input, $plotInput); | |
1757 | + } | |
1758 | + } | |
1759 | + $input->min = $result->min; | |
1760 | + $input->max = $result->max; | |
1761 | + return $this->unmarshallZoom($input, $plotInput, true); | |
1762 | + } | |
1763 | + throw new Exception('No undo zoom to apply.'); | |
1764 | + } | |
1765 | + | |
1567 | 1766 | private function unmarshallNavigation($input, $plotInput) |
1568 | 1767 | { |
1569 | 1768 | //Find current tab |
... | ... | @@ -1644,6 +1843,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
1644 | 1843 | } |
1645 | 1844 | |
1646 | 1845 | $plotInput->{'last-plotted-tab'} = $crtTab->{'id'}; |
1846 | + $plotInput->{'force-time-zoom-reset'} = true; | |
1647 | 1847 | $this->saveIHMRequest($plotInput); |
1648 | 1848 | return $plotInput; |
1649 | 1849 | } |
... | ... | @@ -1668,15 +1868,18 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
1668 | 1868 | |
1669 | 1869 | if ($crtTab->{'multi-plot-linked'}) |
1670 | 1870 | { |
1871 | + $plotInput->{'timesrc'} = 'TimeTable'; | |
1671 | 1872 | $plotInput->{'ttFileIndex'} = $input->{'ttFileIndex'}; |
1672 | 1873 | $plotInput->{'intIndex'} = $input->{'intIndex'}; |
1673 | 1874 | } |
1674 | 1875 | else |
1675 | 1876 | { |
1877 | + $crtTab->{'timesrc'} = 'TimeTable'; | |
1676 | 1878 | $crtTab->{'ttFileIndex'} = $input->{'ttFileIndex'}; |
1677 | 1879 | $crtTab->{'intIndex'} = $input->{'intIndex'}; |
1678 | 1880 | } |
1679 | 1881 | |
1882 | + $plotInput->{'force-time-zoom-reset'} = true; | |
1680 | 1883 | $this->saveIHMRequest($plotInput); |
1681 | 1884 | return $plotInput; |
1682 | 1885 | } |
... | ... | @@ -1712,6 +1915,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
1712 | 1915 | $crtTab->{'stopDate'} = $plotInput->{'stopDate'}; |
1713 | 1916 | } |
1714 | 1917 | |
1918 | + $plotInput->{'force-time-zoom-reset'} = true; | |
1715 | 1919 | $this->saveIHMRequest($plotInput); |
1716 | 1920 | return $plotInput; |
1717 | 1921 | } |
... | ... |