Commit 6341283745f2d44c5e8f7b9bc7ff179d2d2c4521

Authored by Benjamin Renard
1 parent 98881737

Retrieve plot context info after a plot request

src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php
... ... @@ -33,6 +33,8 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass
33 33  
34 34 $plotOutputNode = $outputsNode->addNewOutput(RequestOutputTypeEnum::PLOT);
35 35  
  36 + $plotOutputNode->setWriteContextFile($this->isInteractiveRequest ? "true" : "false");
  37 +
36 38 $compression = "";
37 39 if (!$this->isInteractiveRequest)
38 40 {
... ... @@ -280,24 +282,23 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass
280 282 switch ($data->getStatus())
281 283 {
282 284 case ProcessStatusEnumClass::DONE :
  285 +
  286 + $result = array();
  287 + foreach ($data->getWaitingResults() as $waitingResult)
  288 + {
  289 + $contextResult = str_replace(".png","_context.xml",$waitingResult);
  290 +
  291 + $result[] = array(
  292 + "context" => IHMPlotContextFileClass::parse($this->getWorkingPath().$contextResult),
  293 + "plot" => $waitingResult
  294 + );
  295 + }
  296 +
283 297 return array(
284 298 'success' => true,
285 299 'id' => $data->getId(),
286 300 'folder' => $this->getWorkingDirName(),
287   - 'result' => $data->getWaitingResults(),
288   - 'format' => 'PNG',
289   - 'compression' => 'unknown',
290   - 'status' => 'done',
291   - 'children' => array(
292   - array(
293   - "xmin" => "0",
294   - "xmax" => "1",
295   - "ymin" => "0",
296   - "umax" => "1"
297   - )
298   - ),
299   - 'startDate' => $this->startTime,
300   - 'stopDate' => $this->stopTime
  301 + 'result' => $result
301 302 );
302 303 default :
303 304 return array(
... ...
src/InputOutput/IHMImpl/Tools/IHMPlotContextFileClass.php 0 → 100644
... ... @@ -0,0 +1,37 @@
  1 +<?php
  2 +
  3 +class IHMPlotContextFileClass {
  4 + public static function parse($filePath) {
  5 + if (!file_exists($filePath))
  6 + return array("success" => false, "message" => "Cannot load plot context file");
  7 +
  8 + $doc = new DOMDocument("1.0", "UTF-8");
  9 + $doc->preserveWhiteSpace = false;
  10 + $doc->formatOutput = true;
  11 +
  12 + if (!$doc->load($filePath))
  13 + return array("success" => false, "message" => "Cannot load plot context file");
  14 +
  15 + //<page>
  16 + $pageNodes = $doc->getElementsByTagName('page');
  17 +
  18 + if ($pageNodes->length <= 0)
  19 + return array("success" => false, "message" => "Cannot load context page node");
  20 +
  21 + $pageNode = $pageNodes->item(0);
  22 +
  23 + $pageContext = array(
  24 + 'startTime' => $pageNode->getAttribute('startTime'),
  25 + 'stopTime' => $pageNode->getAttribute('stopTime'),
  26 + 'portrait' => ($pageNode->getAttribute('portrait') == "true"),
  27 + //An image rotation of 90 deg. is done after request execution if a page is in "portrait" mode
  28 + 'width' => ($pageNode->getAttribute('portrait') == "true" ? $pageNode->getAttribute('height') : $pageNode->getAttribute('width')),
  29 + 'height' => ($pageNode->getAttribute('portrait') == "true" ? $pageNode->getAttribute('width') : $pageNode->getAttribute('height')),
  30 + 'panels' => array()
  31 + );
  32 +
  33 + return array("success" => true, "page" => $pageContext);
  34 + }
  35 +}
  36 +
  37 +?>
0 38 \ No newline at end of file
... ...
src/Request/ParamsRequestImpl/Nodes/Requests/RequestOutputPlotNodeClass.php
... ... @@ -4,6 +4,7 @@ require_once(&quot;RequestOutputPlotPageNodeClass.php&quot;);
4 4 require_once("RequestOutputPostProcessingNodeClass.php");
5 5  
6 6 define ("REQUESTOUTPUTPLOT_NAME", "plot");
  7 +define ("REQUESTOUTPUTPLOT_WRITECONTEXTFILE", "writeContextFile");
7 8 define ("REQUESTOUTPUTPLOT_STRUCTURE", "outputStructure");
8 9 define ("REQUESTOUTPUTPLOT_FILEPREFIX", "filePrefix");
9 10  
... ... @@ -42,6 +43,16 @@ class RequestOutputPlotNodeClass extends NodeClass
42 43 $node = $this->getChildInstanceByName(REQUESTOUTPUTPLOT_STRUCTURE);
43 44 return (($node == NULL) ? RequestOutputPlotStructureEnum::ONE_FILE : $node->getValue());
44 45 }
  46 +
  47 + public function setWriteContextFile($write)
  48 + {
  49 + $this->setAttribute(REQUESTOUTPUTPLOT_WRITECONTEXTFILE, $write);
  50 + }
  51 +
  52 + public function getWriteContextFile()
  53 + {
  54 + return $this->getAttribute(REQUESTOUTPUTPLOT_WRITECONTEXTFILE);
  55 + }
45 56  
46 57 public function setFilePrefix($prefix)
47 58 {
... ...