Commit a9d86eaa15ef550ab21e7c72013af896e202d8c3

Authored by Benjamin Renard
1 parent 4a7023e8

Fix zoom / unzoom

src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php
... ... @@ -47,7 +47,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass
47 47 $postProcessCmd = "";
48 48  
49 49 if ($forceTimeZoomReset)
50   - $this->resetZoomListForTab($input->{'tab-index'}, $forceTimeZoomReset);
  50 + $this->resetZoomList(PLOT_RESULT_FILE_KEY."_".$input->{'tab-index'}, $forceTimeZoomReset);
51 51  
52 52 $requestNode = $this->paramsData->addRequestNode();
53 53 $outputsNode = $requestNode->getOutputsNode();
... ... @@ -1465,6 +1465,26 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass
1465 1465 return NULL;
1466 1466 return json_decode(file_get_contents($path));
1467 1467 }
  1468 +
  1469 +
  1470 +
  1471 + private function loadZoomList($interactiveId)
  1472 + {
  1473 + $path = $this->getWorkingPath()."zoom.list.".$interactiveId;
  1474 + if (!file_exists($path))
  1475 + return NULL;
  1476 + return json_decode(file_get_contents($path));
  1477 + }
  1478 +
  1479 + private function saveZoomList($interactiveId, $zoomList)
  1480 + {
  1481 + $path = $this->getWorkingPath()."zoom.list.".$interactiveId;
  1482 + if (!is_dir($this->getWorkingPath()))
  1483 + mkdir($this->getWorkingPath(),0777);
  1484 + $file = fopen($path, 'w');
  1485 + fwrite($file, json_encode($zoomList));
  1486 + fclose($file);
  1487 + }
1468 1488  
1469 1489 private function unmarshallActionRequest($input)
1470 1490 {
... ... @@ -1502,34 +1522,27 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass
1502 1522 //if $isInterval == true, $minOrFileIndex is the min and $maxOrInetrvalIndex is the max
1503 1523 //if $isInterval == false, $minOrFileIndex is the fileIndex and $maxOrInetrvalIndex is the intervalIndex
1504 1524  
1505   - $zoomList = $this->loadZoomList();
  1525 + $zoomList = $this->loadZoomList($input->interactiveId);
1506 1526  
1507   - if (!isset($zoomList->tabs))
  1527 + if (!isset($zoomList))
1508 1528 {
1509 1529 //Init zoom list
1510 1530 $zoomList = (Object)array(
1511   - 'tabs' => (Object)array()
1512   - );
1513   - }
1514   -
1515   - if (!isset($zoomList->tabs->{$input->{'tabId'}}))
1516   - {
1517   - $zoomList->tabs->{$input->{'tabId'}} = (Object)array(
1518   - 'times' => array(),
1519   - 'panels' => (Object)array()
  1531 + 'times' => array(),
  1532 + 'panels' => (Object)array()
1520 1533 );
1521 1534 }
1522 1535  
1523 1536 if ($input->{'axeId'} == 'timeAxis')
1524 1537 {
1525 1538 if ($isInterval)
1526   - array_push ($zoomList->tabs->{$input->{'tabId'}}->times, (Object)array(
  1539 + array_push ($zoomList->times, (Object)array(
1527 1540 'isInterval' => true,
1528 1541 'min' => $minOrFileIndex,
1529 1542 'max' => $maxOrIntervalIndex
1530 1543 ));
1531 1544 else
1532   - array_push ($zoomList->tabs->{$input->{'tabId'}}->times, (Object)array(
  1545 + array_push ($zoomList->times, (Object)array(
1533 1546 'isInterval' => false,
1534 1547 'ttFileIndex' => $minOrFileIndex,
1535 1548 'intIndex' => $maxOrIntervalIndex
... ... @@ -1537,141 +1550,103 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass
1537 1550 }
1538 1551 else
1539 1552 {
1540   - if (!isset($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}))
  1553 + if (!isset($zoomList->panels->{$input->{'panelId'}}))
1541 1554 {
1542   - $zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}} = (Object) array(
  1555 + $zoomList->panels->{$input->{'panelId'}} = (Object) array(
1543 1556 'axes' => (Object)array()
1544 1557 );
1545 1558 }
1546 1559  
1547   - if (!isset($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}}))
  1560 + if (!isset($zoomList->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}}))
1548 1561 {
1549   - $zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}} = array();
  1562 + $zoomList->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}} = array();
1550 1563 }
1551 1564  
1552   - array_push ($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}}, (Object)array(
  1565 + array_push ($zoomList->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}}, (Object)array(
1553 1566 'min' => $minOrFileIndex,
1554 1567 'max' => $maxOrIntervalIndex
1555 1568 ));
1556 1569 }
1557 1570  
1558   - //save zoom list
1559   - $path = $this->getWorkingPath()."zoom.list";
1560   - if (!is_dir($this->getWorkingPath()))
1561   - mkdir($this->getWorkingPath(),0777);
1562   - $file = fopen($path, 'w');
1563   - fwrite($file, json_encode($zoomList));
1564   - fclose($file);
1565   - }
1566   -
1567   - private function loadZoomList()
1568   - {
1569   - $path = $this->getWorkingPath()."zoom.list";
1570   - if (!file_exists($path))
1571   - return NULL;
1572   - return json_decode(file_get_contents($path));
  1571 + $this->saveZoomList($input->interactiveId, $zoomList);
1573 1572 }
1574 1573  
1575   - private function resetZoomListForTab($tabId, $resetOnlyTimeZoom = false)
  1574 + private function resetZoomList($interactiveId, $resetOnlyTimeZoom = false)
1576 1575 {
1577   - $zoomList = $this->loadZoomList();
1578   -
1579   - if (isset($zoomList->tabs) && isset($zoomList->tabs->{PLOT_RESULT_FILE_KEY."_".$tabId}))
1580   - {
1581   - if (!$resetOnlyTimeZoom)
1582   - unset($zoomList->tabs->{PLOT_RESULT_FILE_KEY."_".$tabId});
1583   - else
1584   - $zoomList->tabs->{PLOT_RESULT_FILE_KEY."_".$tabId}->times = array();
  1576 + if (!$resetOnlyTimeZoom) {
  1577 + $zoomList = (Object)array(
  1578 + 'times' => array(),
  1579 + 'panels' => (Object)array()
  1580 + );
1585 1581 }
1586   -
1587   - $path = $this->getWorkingPath()."zoom.list";
1588   - if (!is_dir($this->getWorkingPath()))
1589   - mkdir($this->getWorkingPath(),0777);
1590   - $file = fopen($path, 'w');
1591   - fwrite($file, json_encode($zoomList));
1592   - fclose($file);
  1582 + else {
  1583 + $zoomList = $this->loadZoomList($interactiveId);
  1584 + $zoomList->times = array();
  1585 + }
  1586 +
  1587 + $this->saveZoomList($interactiveId, $zoomList);
1593 1588 }
1594 1589  
1595 1590 private function undoZoomInList($input)
1596 1591 {
1597   - $zoomList = $this->loadZoomList();
  1592 + $zoomList = $this->loadZoomList($input->interactiveId);
1598 1593  
1599 1594 $result = NULL;
1600   - if (isset($zoomList->tabs) && isset($zoomList->tabs->{$input->{'tabId'}}))
  1595 + if ($zoomList)
1601 1596 {
1602 1597 if ($input->{'axeId'} == 'timeAxis')
1603 1598 {
1604   - if (count($zoomList->tabs->{$input->{'tabId'}}->times) <= 0)
  1599 + if (count($zoomList->times) <= 0)
1605 1600 return NULL;
1606   - $result = array_pop($zoomList->tabs->{$input->{'tabId'}}->times);
  1601 + $result = array_pop($zoomList->times);
1607 1602 }
1608 1603 else
1609 1604 {
1610   - if (!isset($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}))
  1605 + if (!isset($zoomList->panels->{$input->{'panelId'}}))
1611 1606 return NULL;
1612 1607  
1613   - if (!isset($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}}))
  1608 + if (!isset($zoomList->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}}))
1614 1609 return NULL;
1615 1610  
1616   - $result = array_pop($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}});
  1611 + $result = array_pop($zoomList->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}});
1617 1612 }
1618 1613 }
1619 1614 else
1620 1615 return NULL;
1621 1616  
1622   - $path = $this->getWorkingPath()."zoom.list";
1623   - if (!is_dir($this->getWorkingPath()))
1624   - mkdir($this->getWorkingPath(),0777);
1625   - $file = fopen($path, 'w');
1626   - fwrite($file, json_encode($zoomList));
1627   - fclose($file);
  1617 + $this->saveZoomList($input->interactiveId, $zoomList);
1628 1618  
1629 1619 return $result;
1630 1620 }
1631 1621  
1632 1622 private function unmarshallZoom($input, $plotInput, $isUndo = false)
1633 1623 {
1634   - //Find current tab
1635   - $crtTab = NULL;
1636   - foreach ($plotInput->{'tabs'} as $tab)
1637   - {
1638   - if ($input->{'tabId'} == PLOT_RESULT_FILE_KEY."_".$tab->{'id'})
1639   - {
1640   - $crtTab = $tab;
1641   - break;
1642   - }
1643   - }
1644   -
1645   - if (!$crtTab)
1646   - throw new Exception('Cannot retrieve plot tab for navigation action.');
1647   -
1648 1624 if ($input->{'axeId'} == 'timeAxis')
1649 1625 {
1650 1626 //Zoom on Time Axis
1651   - if ($crtTab->{'timesrc'} != 'Interval')
  1627 + if ($plotInput->{'timesrc'} != 'Interval')
1652 1628 {
1653   - $crtTab->{'timesrc'} = 'Interval';
  1629 + $plotInput->{'timesrc'} = 'Interval';
1654 1630 if (!$isUndo)
1655 1631 $this->addZoomInList($input,false,
1656   - isset($crtTab->{'ttFileIndex'}) ? $crtTab->{'ttFileIndex'} : 0,
1657   - isset($crtTab->{'intIndex'}) ? $crtTab->{'intIndex'} : 0);
  1632 + isset($plotInput->{'ttFileIndex'}) ? $plotInput->{'ttFileIndex'} : 0,
  1633 + isset($plotInput->{'intIndex'}) ? $plotInput->{'intIndex'} : 0);
1658 1634 }
1659 1635 else
1660 1636 {
1661 1637 if (!$isUndo)
1662   - $this->addZoomInList($input,true,$crtTab->{'startDate'},$crtTab->{'stopDate'});
  1638 + $this->addZoomInList($input,true,$plotInput->{'startDate'},$plotInput->{'stopDate'});
1663 1639 }
1664   - $crtTab->{'startDate'} = $input->{'min'};
1665   - $crtTab->{'stopDate'} = $input->{'max'};
  1640 + $plotInput->{'startDate'} = $input->{'min'};
  1641 + $plotInput->{'stopDate'} = $input->{'max'};
1666 1642  
1667   - $plotInput->{'last-plotted-tab'} = $crtTab->{'id'};
1668 1643 $plotInput->{'force-time-zoom-reset'} = false;
1669   - $this->saveIHMRequest($plotInput);
  1644 + $this->saveIHMRequest($input->interactiveId, $plotInput);
1670 1645 return $plotInput;
1671 1646 }
1672 1647  
1673 1648 //Digital axis zoom
1674   - foreach ($crtTab->{'panels'} as $panel)
  1649 + foreach ($plotInput->{'panels'} as $panel)
1675 1650 {
1676 1651 if ($input->{'panelId'} == $panel->{'id'})
1677 1652 {
... ... @@ -1684,8 +1659,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass
1684 1659 $oldMax = $axis->{'axis-range-max'};
1685 1660 $axis->{'axis-range-min'} = $input->{'min'};
1686 1661 $axis->{'axis-range-max'} = $input->{'max'};
1687   - $plotInput->{'last-plotted-tab'} = $crtTab->{'id'};
1688   - $this->saveIHMRequest($plotInput);
  1662 + $this->saveIHMRequest($input->interactiveId, $plotInput);
1689 1663 //Do not save 'force-single-replot' in request file!
1690 1664 $plotInput->{'force-single-replot'} = true;
1691 1665 $plotInput->{'force-time-zoom-reset'} = false;
... ...