diff --git a/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php b/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php index 8fd1ba9..3c25614 100644 --- a/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php +++ b/src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php @@ -9,6 +9,8 @@ define ("PLOT_RESULT_FILE_KEY","plot"); */ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass { + private $isInteractiveRequest = false; + /* * @brief method to unmarshall a plot request */ @@ -19,6 +21,8 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass //Request $requestIndex = 0; + $this->isInteractiveRequest = ($input->{'file-output'} == 'INTERACTIVE'); + $postProcessCmd = ""; foreach ($input->tabs as $tab) { $requestNode = $this->paramsData->addRequestNode(); @@ -29,15 +33,23 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass $plotOutputNode = $outputsNode->addNewOutput(RequestOutputTypeEnum::PLOT); - switch ($input->{'file-output'}) + $compression = ""; + if (!$this->isInteractiveRequest) { - case 'TGZ' : - $plotOutputNode->addPostProcessing(RequestOutputPostProcessingEnumClass::TAR); - $plotOutputNode->addPostProcessing(RequestOutputPostProcessingEnumClass::GZIP); - break; - case 'ZIP' : - $plotOutputNode->addPostProcessing(RequestOutputPostProcessingEnumClass::ZIP); - break; + switch ($input->{'file-output'}) + { + case 'TGZ' : + $plotOutputNode->addPostProcessing(RequestOutputPostProcessingEnumClass::TAR); + $plotOutputNode->addPostProcessing(RequestOutputPostProcessingEnumClass::GZIP); + $compression = ".tar.gz"; + break; + case 'ZIP' : + $plotOutputNode->addPostProcessing(RequestOutputPostProcessingEnumClass::ZIP); + $compression = ".zip"; + break; + default: + throw new Exception('Compression not implemented.'); + } } if ($input->{'one-file-per-interval'}) @@ -46,10 +58,8 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass $plotOutputNode->setStructure(RequestOutputPlotStructureEnum::ONE_FILE); //prefix - $filePrefix = ""; - if ($input->{'file-prefix'} == "") - $filePrefix = "plot"; - else + $filePrefix = "plot"; + if ($input->{'file-prefix'} && ($input->{'file-prefix'} != "")) $filePrefix = $input->{'file-prefix'}; $filePrefix .= $requestIndex; @@ -59,19 +69,24 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass $pageNode = $plotOutputNode->getPage(); $fileFormat = RequestOutputPlotPageFormatEnum::PNG; + $extension = ".png"; switch ($input->{'file-format'}) { case 'PNG' : $fileFormat = RequestOutputPlotPageFormatEnum::PNG; + $extension = ".png"; break; case 'PDF' : $fileFormat = RequestOutputPlotPageFormatEnum::PDF; + $extension = ".pdf"; break; case 'PS' : $fileFormat = RequestOutputPlotPageFormatEnum::PS; + $extension = ".ps"; break; case 'SVG' : $fileFormat = RequestOutputPlotPageFormatEnum::SVG; + $extension = ".svg"; break; default: throw new Exception('File format not implemented.'); @@ -81,6 +96,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass $this->unmarshallTitle($tab, 'page-title', $pageNode->getTitle()); + $isPortrait = false; switch ($tab->{'page-orientation'}) { case 'landscape' : @@ -88,6 +104,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass break; case 'portrait' : $pageNode->setOrientation(RequestOutputPlotPageOrientationEnum::PORTRAIT); + $isPortrait = true; break; } @@ -126,10 +143,37 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass $pageNode->getLayout()->setType(RequestOutputPlotLayoutTypeEnum::VERTICAL); + if ($this->isInteractiveRequest) + { + $resultFile = $filePrefix."_*".$extension; + $waitingResultFile = $filePrefix.$extension; + } + else + { + $resultFile = $filePrefix."_*".$compression; + $waitingResultFile = $filePrefix.$compression; + } + + $this->paramsData->addWaitingResult(PLOT_RESULT_FILE_KEY."_".$requestIndex, $waitingResultFile); + + //Remove old result files + foreach (glob($this->paramsData->getWorkingPath().$resultFile) as $oldFile) { + unlink($oldFile); + } + + //Post process command to apply to the result file + if ($postProcessCmd != "") + $postProcessCmd .= " | "; + $postProcessCmd .= "mv ".$resultFile." ".$waitingResultFile; + + if ($this->isInteractiveRequest && $isPortrait) + $postProcessCmd .= " | convert ".$resultFile." -rotate -90 ".$resultFile; + ++$requestIndex; } - $this->paramsData->setBatchEnable(!(($fileFormat == RequestOutputPlotPageFormatEnum::PNG) && ($input->{'file-output'} == 'INTERACTIVE'))); + $this->paramsData->setBatchEnable(!(($fileFormat == RequestOutputPlotPageFormatEnum::PNG) && $this->isInteractiveRequest)); + $this->paramsData->setPostCmd($postProcessCmd); //determine extension and add post processing if needed return $this->paramsData; @@ -220,10 +264,10 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass */ protected function marshallResult($data) { - if (!$this->isInterractive) + if (!$this->isInteractiveRequest) { //add to job - $commonRes = $this->commonMarshallResult($data,PLOT_RESULT_FILE_KEY); + $commonRes = $this->commonMarshallResult($data,PLOT_RESULT_FILE_KEY."_0"); return $commonRes; } @@ -235,12 +279,12 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass switch ($data->getStatus()) { - case ProcessStatusEnumClass::DONE : + case ProcessStatusEnumClass::DONE : return array( 'success' => true, 'id' => $data->getId(), 'folder' => $this->getWorkingDirName(), - 'result' => $data->getWaitingResult(PLOT_RESULT_FILE_KEY), + 'result' => $data->getWaitingResults(), 'format' => 'PNG', 'compression' => 'unknown', 'status' => 'done', @@ -252,7 +296,6 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass "umax" => "1" ) ), - 'tabId' => $this->currentTabId, 'startDate' => $this->startTime, 'stopDate' => $this->stopTime ); diff --git a/src/Request/ParamsRequestImpl/ParamsRequestDataClass.php b/src/Request/ParamsRequestImpl/ParamsRequestDataClass.php index 4f342e6..e43a514 100644 --- a/src/Request/ParamsRequestImpl/ParamsRequestDataClass.php +++ b/src/Request/ParamsRequestImpl/ParamsRequestDataClass.php @@ -76,6 +76,11 @@ class ParamsRequestDataClass extends ProcessRequestDataClass return $this->requestNodes; } + public function getWaitingResults() + { + return $this->waitingResults; + } + public function getWaitingResult($key) { return $this->waitingResults[$key]; -- libgit2 0.21.2