saveIHMRequest($input); //Request $requestIndex = 0; $this->isInteractiveRequest = ($input->{'file-output'} == 'INTERACTIVE'); $postProcessCmd = ""; foreach ($input->tabs as $tab) { $requestNode = $this->paramsData->addRequestNode(); $outputsNode = $requestNode->getOutputsNode(); $paramsNode = $requestNode->getParamsNode(); //unmarshall time definition $this->unmarshallTimeDefinition($input, $requestIndex, $this->isInteractiveRequest && !$tab->{'page-superpose-mode'}); $plotOutputNode = $outputsNode->addNewOutput(RequestOutputTypeEnum::PLOT); $plotOutputNode->setWriteContextFile($this->isInteractiveRequest ? "true" : "false"); $compression = ""; if (!$this->isInteractiveRequest) { 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'}) $plotOutputNode->setStructure(RequestOutputPlotStructureEnum::ONE_FILE_PER_INTERVAL); else $plotOutputNode->setStructure(RequestOutputPlotStructureEnum::ONE_FILE); //prefix $filePrefix = "plot"; if ($input->{'file-prefix'} && ($input->{'file-prefix'} != "")) $filePrefix = $input->{'file-prefix'}; $filePrefix .= $requestIndex; $plotOutputNode->setFilePrefix($filePrefix); //page $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.'); } $pageNode->setFormat($fileFormat); $this->unmarshallTitle($tab, 'page-title', $pageNode->getTitle()); $isPortrait = false; switch ($tab->{'page-orientation'}) { case 'landscape' : $pageNode->setOrientation(RequestOutputPlotPageOrientationEnum::LANDSCAPE); break; case 'portrait' : $pageNode->setOrientation(RequestOutputPlotPageOrientationEnum::PORTRAIT); $isPortrait = true; break; } switch ($tab->{'page-dimension'}) { case 'ISO A4' : $pageNode->setDimension(RequestOutputPlotPageDimensionEnum::ISO_A4); break; case 'US letter' : $pageNode->setDimension(RequestOutputPlotPageDimensionEnum::US_LETTER); break; default: throw new Exception('Page dimension not implemented.'); } switch ($tab->{'page-mode'}) { case 'color' : $pageNode->setMode(RequestOutputPlotPageModeEnum::COLOR); break; case 'grayscale' : $pageNode->setMode(RequestOutputPlotPageModeEnum::GRAYSCALE); break; default: throw new Exception('Page mode not implemented.'); } if ($tab->{'page-margins-activated'}) { $pageNode->getMargins()->setHorizontal($tab->{'page-margin-x'}); $pageNode->getMargins()->setVertical($tab->{'page-margin-y'}); } if ($tab->{'page-font-activated'}) $this->unmarshallFont($tab, 'page', $pageNode->getFont()); //Superpose mode $pageNode->setSuperposeMode($tab->{'page-superpose-mode'} ? "true": "false"); //Layout $this->unmarshallLayout($tab, $pageNode); foreach ($tab->{'panels'} as $panelData) $this->unmarshallPanel($panelData, $pageNode, $paramsNode); 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 ".$waitingResultFile." -rotate -90 ".$waitingResultFile; ++$requestIndex; } $this->paramsData->setBatchEnable(!(($fileFormat == RequestOutputPlotPageFormatEnum::PNG) && $this->isInteractiveRequest)); $this->paramsData->setPostCmd($postProcessCmd); return $this->paramsData; } protected function unmarshallLayout($tab, $pageNode) { switch ($tab->{'page-layout-type'}) { case 'vertical' : $pageNode->getLayout()->setType(RequestOutputPlotLayoutTypeEnum::VERTICAL); $pageNode->getLayout()->setPanelHeight($tab->{'page-layout-object'}->{'layout-panel-height'}); $pageNode->getLayout()->setPanelSpacing($tab->{'page-layout-object'}->{'layout-panel-spacing'}); $pageNode->getLayout()->setExpand($tab->{'page-layout-object'}->{'layout-expand'} ? "true" : "false"); //if ($tab->{'page-layout-object'}->{'layout-timeplot-width'} > 0) // $pageNode->setDefaultTimePlotWidth($tab->{'page-layout-object'}->{'layout-timeplot-width'}); if ($tab->{'page-layout-object'}->{'layout-timeplot-height'} > 0) $pageNode->setDefaultTimePlotHeight($tab->{'page-layout-object'}->{'layout-timeplot-height'}); if ($tab->{'page-layout-object'}->{'layout-xyplot-width'} > 0) $pageNode->setDefaultXYPlotWidth($tab->{'page-layout-object'}->{'layout-xyplot-width'}); if ($tab->{'page-layout-object'}->{'layout-xyplot-height'} > 0) $pageNode->setDefaultXYPlotHeight($tab->{'page-layout-object'}->{'layout-xyplot-height'}); break; case 'auto' : $pageNode->getLayout()->setType(RequestOutputPlotLayoutTypeEnum::AUTO); $pageNode->getLayout()->setPanelHeight($tab->{'page-layout-object'}->{'layout-panel-height'}); $pageNode->getLayout()->setPanelSpacing($tab->{'page-layout-object'}->{'layout-panel-spacing'}); $pageNode->getLayout()->setExpand($tab->{'page-layout-object'}->{'layout-expand'} ? "true" : "false"); break; case 'manual' : $pageNode->getLayout()->setType(RequestOutputPlotLayoutTypeEnum::MANUAL); $timePlotLeftMargin = $tab->{'page-layout-object'}->{'layout-timeplot-margin-left'} ? $tab->{'page-layout-object'}->{'layout-timeplot-margin-left'} : -1; $timePlotRightMargin = $tab->{'page-layout-object'}->{'layout-timeplot-margin-right'} ? $tab->{'page-layout-object'}->{'layout-timeplot-margin-right'} : -1; $pageNode->setDefaultTimePlotXMargin($timePlotLeftMargin, $timePlotRightMargin); $xyPlotLeftMargin = $tab->{'page-layout-object'}->{'layout-xyplot-margin-left'} ? $tab->{'page-layout-object'}->{'layout-xyplot-margin-left'} : -1; $xyPlotRightMargin = $tab->{'page-layout-object'}->{'layout-xyplot-margin-right'} ? $tab->{'page-layout-object'}->{'layout-xyplot-margin-right'} : -1; $pageNode->setDefaultXYPlotXMargin($xyPlotLeftMargin, $xyPlotRightMargin); break; default: throw new Exception('Layout type not implemented.'); } } protected function unmarshallPanel($panelData, $pageNode, $paramsNode) { $panelNode = $pageNode->addPanel(); switch ($pageNode->getLayout()->getType()) { case RequestOutputPlotLayoutTypeEnum::MANUAL : //Panel bounds $panelNode->getBounds()->setX($panelData->{'panel-bounds-x'}); $panelNode->getBounds()->setY($panelData->{'panel-bounds-y'}); $panelNode->getBounds()->setWidth($panelData->{'panel-bounds-width'}); $panelNode->getBounds()->setHeight($panelData->{'panel-bounds-height'}); //Panel margins $leftMargin = $panelData->{'panel-margin-left'} ? $panelData->{'panel-margin-left'} : -1; $rightMargin = $panelData->{'panel-margin-right'} ? $panelData->{'panel-margin-right'} : -1; $panelNode->setXMargin($leftMargin, $rightMargin); break; case RequestOutputPlotLayoutTypeEnum::VERTICAL : //Panel prefered dimensions if ($panelData->{'panel-prefered-width'} > 0) $panelNode->setPreferedWidth($panelData->{'panel-prefered-width'}); if ($panelData->{'panel-prefered-height'} > 0) $panelNode->setPreferedHeight($panelData->{'panel-prefered-height'}); break; default : //Nothing to do } //Panel background color if (($panelData->{'panel-background-color'} != 'none') && ($panelData->{'panel-background-color'} != '')) $panelNode->setBackgroundColor($this->hexColor2KernelColor($panelData->{'panel-background-color'})); //Panel font $this->unmarshallFont($panelData, 'panel', $panelNode->getFont()); //Panel title $this->unmarshallTitle($panelData, 'panel-title', $panelNode->getTitle()); //Plot type $plotNode = $this->unmarshallPlotType($panelData, $panelNode); //Tick plot $tickPlotNode = NULL; if ($plotNode->getName() == REQUESTOUTPUTPLOTELEMENTTIME_NAME) { if ($this->hasTickBar($panelData->{'params'})) { $tickPlotNode = $panelNode->addPlotElement(RequestOutputPlotElementTypeEnum::TICKPLOT,true); if ($panelData->{'panel-tick-format'} != '') $tickPlotNode->setFormat($panelData->{'panel-tick-format'}); } } //Status plot $statusPlotNode = NULL; if ($plotNode->getName() == REQUESTOUTPUTPLOTELEMENTTIME_NAME) { if ($this->hasStatusBar($panelData->{'params'})) { $statusPlotNode = $panelNode->addPlotElement(RequestOutputPlotElementTypeEnum::STATUSPLOT,true); switch ($panelData->{'panel-status-position'}) { case 'top' : $statusPlotNode->setPosition(RequestOutputPlotElementStatusPosition::TOP); break; case 'bottom' : $statusPlotNode->setPosition(RequestOutputPlotElementStatusPosition::BOTTOM); break; } $statusPlotNode->setColorMap($panelData->{'panel-status-colormap'}); } } //Axes foreach ($panelData->{'axes'} as $axisData) $this->unmarshallAxis($axisData, $plotNode); //Params $this->unmarshallParams($panelData->{'params'}, $paramsNode, $plotNode, $panelNode, $statusPlotNode, $tickPlotNode); return $panelNode; } protected function unmarshallPlotType($panelData, $panelNode) { switch ($panelData->{'panel-plot-type'}) { case 'timePlot' : $plotNode = $panelNode->addPlotElement(RequestOutputPlotElementTypeEnum::TIMEPLOT); break; case 'xyPlot' : $plotNode = $panelNode->addPlotElement(RequestOutputPlotElementTypeEnum::XYPLOT); $plotNode->setIsIsotropic($panelData->{'panel-scatter-isotropic'}); break; case 'statusPlot' : $plotNode = $panelNode->addPlotElement(RequestOutputPlotElementTypeEnum::STATUSPLOT); switch ($panelData->{'panel-status-position'}) { case 'top' : $plotNode->setPosition(RequestOutputPlotElementStatusPosition::TOP); break; case 'bottom' : $plotNode->setPosition(RequestOutputPlotElementStatusPosition::BOTTOM); break; } $plotNode->setColorMap($panelData->{'panel-status-colormap'}); break; case 'tickPlot' : $plotNode = $panelNode->addPlotElement(RequestOutputPlotElementTypeEnum::TICKPLOT); if ($panelData->{'panel-tick-format'} != '') $plotNode->setFormat($panelData->{'panel-tick-format'}); break; case 'epochPlot' : $plotNode = $panelNode->addPlotElement(RequestOutputPlotElementTypeEnum::EPOCHPLOT); if ($panelData->{'panel-epoch-centertimeid'} == '') throw new Exception('Center Time Id not defined for an Epoch Plot.'); $plotNode->setCenterTimeId($panelData->{'panel-epoch-centertimeid'}); break; case 'instantPlot' : $plotNode = $panelNode->addPlotElement(RequestOutputPlotElementTypeEnum::INSTANTPLOT); date_default_timezone_set('UTC'); $timeStamp = strtotime($panelData->{'panel-instant-time'}); $time = CommonClass::timeStampToDDTime($timeStamp); $plotNode->setTime($time); break; default: throw new Exception('Plot type not implemented.'); } return $plotNode; } protected function unmarshallAxis($axisData, $plotNode) { //axis type switch ($axisData->{'axis-type'}) { case 'time' : $axisNode = $plotNode->getTimeAxis(); $axisNode->setFormat($axisData->{'axis-time-format'}); break; case 'epoch' : $axisNode = $plotNode->getEpochAxis(); $axisNode->setNormalized($axisData->{'axis-epoch-normalized'} ? "true" : "false"); break; case 'x' : $axisNode = $plotNode->getXAxis(); break; case 'y-left' : $axisNode = $plotNode->addYAxis('y-left'); break; case 'y-right' : $axisNode = $plotNode->addYAxis('y-right'); $axisNode->setPosition(RequestOutputPlotAxisElementPosition::RIGHT); break; case 'color' : $axisNode = $plotNode->getZAxis(); $axisNode->setColorMapIndex($axisData->{'axis-color-map'}); if ($axisData->{'axis-color-minval'} != 'none') $axisNode->setMinValColor($this->hexColor2KernelColor($axisData->{'axis-color-minval'})); if ($axisData->{'axis-color-maxval'} != 'none') $axisNode->setMaxValColor($this->hexColor2KernelColor($axisData->{'axis-color-maxval'})); break; default: throw new Exception('Axis type not implemented.'); } //reverse axis $axisNode->setReverse($axisData->{'axis-reverse'} ? "true" : "false"); //axis scale switch ($axisData->{'axis-scale'}) { case 'logarithmic' : $axisNode->setScale(RequestOutputPlotAxisElementScale::LOGARITHMIC); break; default: $axisNode->setScale(RequestOutputPlotAxisElementScale::LINEAR); } //axis range if ($axisData->{'axis-range-min'} < $axisData->{'axis-range-max'}) $axisNode->getRange()->setMinMax($axisData->{'axis-range-min'}, $axisData->{'axis-range-max'}); $axisNode->getRange()->setExtend($axisData->{'axis-range-extend'} ? "true" : "false"); //axis color $axisNode->setColor($this->hexColor2KernelColor($axisData->{'axis-color'})); //axis thickness $axisNode->setThickness($axisData->{'axis-thickness'}); //axis ticks position switch ($axisData->{'axis-tick-position'}) { case 'inwards' : $axisNode->getTick()->setPosition(RequestOutputPlotAxisElementTickPosition::INWARDS); break; default : $axisNode->getTick()->setPosition(RequestOutputPlotAxisElementTickPosition::OUTWARDS); } //axis minor and major grid $axisNode->getTick()->setMinorGrid($axisData->{'axis-grid-minor'} ? "true" : "false"); $axisNode->getTick()->setMajorGrid($axisData->{'axis-grid-major'} ? "true" : "false"); //legend if ($axisData->{'axis-legend-text'} != '') $axisNode->getLegend()->setText($axisData->{'axis-legend-text'}); $axisNode->getLegend()->setColor($this->hexColor2KernelColor($axisData->{'axis-legend-color'})); $this->unmarshallLabel($axisData, "axis-legend", $axisNode->getLegend()); } protected function unmarshallParams($paramsData, $requestParamsNode, $plotNode, $panelNode, $statusPlotNode, $tickPlotNode) { //X parameters $isScatter = ($plotNode->getName() == REQUESTOUTPUTPLOTELEMENTXY_NAME); if ($isScatter) { foreach ($paramsData as $paramData) { if ($paramData->{'param-drawing-object'}->{'serie-xaxis-param'} == '') continue; $paramXInfo = $this->paramManager->addExistingParam($paramData->{'param-drawing-object'}->{'serie-xaxis-param'},$this->paramsData); if ($paramXInfo['id'] == '') throw new Exception('Cannot retrieve X parameter.'); $requestParamsNode->addParam($paramXInfo['id']); $xParamNode = $plotNode->getParams()->getParamById($paramXInfo['id']); switch ($paramData->{'param-drawing-type'}) { case 'serie' : //Unmarshall x serie if (count($paramXInfo['indexes']) == 0) $xParamNode->addXSerie(REQUESTOUTPUTPLOTELEMENTXY_XAXISID, -1); else if (count($paramXInfo['indexes']) == 1) $xParamNode->addXSerie(REQUESTOUTPUTPLOTELEMENTXY_XAXISID, $paramXInfo['indexes'][0]); else throw new Exception('X parameter for serie must be a component.'); break; default : throw new Exception('X parameter not allowed for this drawing type. '); } } } //Main drawing element parameter $drawingEltIndex = 0; foreach ($paramsData as $paramData) { //Param $paramInfo = $this->paramManager->addExistingParam($paramData->{'param-id'},$this->paramsData); $requestParamsNode->addParam($paramInfo['id']); $colorSerieId = -1; if ($paramData->{'param-drawing-object'}->{'serie-colored-param'} != '') $colorSerieId = $drawingEltIndex; switch ($paramData->{'param-drawing-type'}) { case 'serie' : $paramNode = $plotNode->getParams()->getParamById($paramInfo['id']); $this->unmarshallYSerie($paramData->{'param-drawing-object'}, $plotNode, $paramNode, $paramInfo['indexes'], $isScatter && ($paramData->{'param-drawing-object'}->{'serie-xaxis-param'} != ''), $colorSerieId); break; case 'spectro' : $paramNode = $plotNode->getParams()->getParamById($paramInfo['id']); $this->unmarshallSpectro($paramData->{'param-drawing-object'}, $plotNode, $paramNode, $paramInfo['indexes']); break; case 'status-bar' : if (($plotNode->getName() == REQUESTOUTPUTPLOTELEMENTSTATUS_NAME) && !isset($statusPlotNode)) $paramNode = $plotNode->getParams()->getParamById($paramInfo['id']); else $paramNode = $statusPlotNode->getParams()->getParamById($paramInfo['id']); $this->unmarshallStatusBar($paramData->{'param-drawing-object'}, $paramNode, $paramInfo['indexes']); break; case 'tick-bar' : if (($plotNode->getName() == REQUESTOUTPUTPLOTELEMENTTICK_NAME) && !isset($tickPlotNode)) $paramNode = $plotNode->getParams()->getParamById($paramInfo['id']); else $paramNode = $tickPlotNode->getParams()->getParamById($paramInfo['id']); $this->unmarshallTickBar($paramData->{'param-drawing-object'}, $paramNode, $paramInfo['indexes']); break; case 'iserie' : $paramNode = $plotNode->getParams()->getParamById($paramInfo['id']); $this->unmarshallInstantSerie($paramData->{'param-drawing-object'}, $plotNode, $paramNode); break; default : throw new Exception('Drawing type not implemented.'); } ++$drawingEltIndex; } //Colored parameter $drawingEltIndex = 0; foreach ($paramsData as $paramData) { if ($paramData->{'param-drawing-object'}->{'serie-colored-param'} == '') { ++$drawingEltIndex; continue; } $paramColoredInfo = $this->paramManager->addExistingParam($paramData->{'param-drawing-object'}->{'serie-colored-param'},$this->paramsData); if ($paramColoredInfo['id'] == '') throw new Exception('Cannot retrieve colored parameter.'); $requestParamsNode->addParam($paramColoredInfo['id']); $coloredParamNode = $plotNode->getParams()->getParamById($paramColoredInfo['id']); $colorSerieId = $drawingEltIndex; switch ($paramData->{'param-drawing-type'}) { case 'serie' : //Unmarshall colored serie if (count($paramColoredInfo['indexes']) == 0) $coloredParamNode->addColorSerie($colorSerieId, -1); else if (count($paramColoredInfo['indexes']) == 1) $coloredParamNode->addColorSerie($colorSerieId, $paramColoredInfo['indexes'][0]); else throw new Exception('Colored parameter for serie must be a component.'); break; default : throw new Exception('Colored parameter not allowed for this drawing type. '); } ++$drawingEltIndex; } } protected function unmarshallYSerie($paramDrawingData, $plotNode, $paramNode, $indexes, $useXAxis, $colorSerieId) { $serieNodes = array(); if (count($indexes) == 0) $serieNodes[] = $paramNode->addYSerie($paramDrawingData->{'serie-yaxis'}, -1, $useXAxis ? REQUESTOUTPUTPLOTELEMENTXY_XAXISID : '', $colorSerieId); foreach ($indexes as $index) $serieNodes[] = $paramNode->addYSerie($paramDrawingData->{'serie-yaxis'}, $index, $useXAxis ? REQUESTOUTPUTPLOTELEMENTXY_XAXISID : '', $colorSerieId); foreach ($serieNodes as $serieNode) { //Resampling if ($plotNode->getName() == REQUESTOUTPUTPLOTELEMENTXY_NAME) { switch ($paramDrawingData->{'serie-resampling-mode'}) { case 'yparam' : $serieNode->getResampling()->setType(RequestOutputPlotResamplingTypeEnum::YPARAM); break; case 'xparam' : default : $serieNode->getResampling()->setType(RequestOutputPlotResamplingTypeEnum::XPARAM); } } //Line $this->unmarshallLine($paramDrawingData, 'serie', $serieNode->getLine()); //Symbol $this->unmarshallSymbol($paramDrawingData, 'serie', $serieNode->getSymbol()); } } protected function unmarshallInstantSerie($paramDrawingData, $plotNode, $paramNode) { $iserieNode = $paramNode->addInstantSerie(REQUESTOUTPUTPLOTELEMENTXY_XAXISID, 'y-left'); //Table on X Axis $iserieNode->setTableOnXAxis($paramDrawingData->{'iserie-tableonx'} ? "true" : "false"); //Line $this->unmarshallLine($paramDrawingData, 'iserie', $iserieNode->getLine()); //Symbol $this->unmarshallSymbol($paramDrawingData, 'iserie', $iserieNode->getSymbol()); } protected function unmarshallSpectro($paramDrawingData, $plotNode, $paramNode, $indexes) { $spectroNode = $paramNode->addSpectro($paramDrawingData->{'spectro-yaxis'}); } protected function unmarshallStatusBar($paramDrawingData, $paramNode, $indexes) { if (count($indexes) == 0) $paramNode->addStatusBar(-1); foreach ($indexes as $index) $paramNode->addStatusBar($index); } protected function unmarshallTickBar($paramDrawingData, $paramNode, $indexes) { if (count($indexes) == 0) $paramNode->addTickBar(-1); foreach ($indexes as $index) $paramNode->addTickBar($index); } protected function hasStatusBar($paramsData) { foreach ($paramsData as $paramData) if ($paramData->{'param-drawing-type'} == 'status-bar') return true; return false; } protected function hasTickBar($paramsData) { foreach ($paramsData as $paramData) if ($paramData->{'param-drawing-type'} == 'tick-bar') return true; return false; } protected function unmarshallTitle($inputData, $keyPrefix, $titleNode) { if ($inputData->{$keyPrefix.'-text'} != '') { $titleNode->setText($inputData->{$keyPrefix.'-text'}); switch ($inputData->{$keyPrefix.'-position'}) { case 'top' : $titleNode->setPosition(RequestOutputPlotTitlePosition::TOP); break; case 'bottom' : $titleNode->setPosition(RequestOutputPlotTitlePosition::BOTTOM); break; } switch ($inputData->{$keyPrefix.'-alignment'}) { case 'center' : $titleNode->setAlign(RequestOutputPlotTitleAlign::CENTER); break; case 'left' : $titleNode->setAlign(RequestOutputPlotTitleAlign::LEFT); break; case 'right' : $titleNode->setAlign(RequestOutputPlotTitleAlign::RIGHT); break; } if ($inputData->{$keyPrefix.'-color'} != '') $titleNode->setColor($this->hexColor2KernelColor($inputData->{$keyPrefix.'-color'})); $this->unmarshallLabel($inputData, $keyPrefix, $titleNode); } } protected function unmarshallLabel($inputData, $keyPrefix, $labelNode) { if ($inputData->{$keyPrefix.'-font-activated'}) { $labelNode->setFontName($inputData->{$keyPrefix.'-font-name'}); $labelNode->setFontSize($inputData->{$keyPrefix.'-font-size'}); $style = ""; if ($inputData->{$keyPrefix.'-font-bold'}) { if ($style != "") $style .= ","; $style .= "bold"; } if ($inputData->{$keyPrefix.'-font-italic'}) { if ($style != "") $style .= ","; $style .= "italic"; } if ($style != "") $labelNode->setFontStyle($style); } } protected function unmarshallFont($inputData, $keyPrefix, $fontNode) { if ($inputData->{$keyPrefix.'-font-activated'}) { $fontNode->setFontName($inputData->{$keyPrefix.'-font-name'}); $fontNode->setSize($inputData->{$keyPrefix.'-font-size'}); if ($inputData->{$keyPrefix.'-font-italic'}) $fontNode->setStyle(RequestOutputPlotFontStyle::ITALIC); else $fontNode->setStyle(RequestOutputPlotFontStyle::UPRIGHT); if ($inputData->{$keyPrefix.'-font-bold'}) $fontNode->setWeight(RequestOutputPlotFontWeight::BOLD); else $fontNode->setWeight(RequestOutputPlotFontWeight::MEDIUM); } } protected function unmarshallCurve($inputData, $keyPrefix, $curveNode) { switch ($inputData->{$keyPrefix.'-style'}) { case 'plain' : $curveNode->setStyle(RequestOutputPlotCurveStyleEnum::PLAIN); break; case 'dot' : $curveNode->setStyle(RequestOutputPlotCurveStyleEnum::DOT); break; case 'long-spaced-dot' : $curveNode->setStyle(RequestOutputPlotCurveStyleEnum::LONGSPACEDDOT); break; case 'long-short-dot' : $curveNode->setStyle(RequestOutputPlotCurveStyleEnum::LONGSHORTDOT); break; default : throw new Exception('Curve style not implemented.'); } $curveNode->setWidth($inputData->{$keyPrefix.'-width'}); if ($inputData->{$keyPrefix.'-color'} != 'auto') $curveNode->setColor($this->hexColor2KernelColor($inputData->{$keyPrefix.'-color'})); } protected function unmarshallLine($inputData, $keyPrefix, $lineNode) { if (!$inputData->{$keyPrefix."-lines-activated"}) $lineNode->setType(RequestOutputPlotLineTypeEnum::NO); else { $lineNode->setType(RequestOutputPlotLineTypeEnum::LINE); $this->unmarshallCurve($inputData, $keyPrefix."-lines", $lineNode); } } protected function unmarshallSymbol($inputData, $keyPrefix, $symbolNode) { if (!$inputData->{$keyPrefix."-symbols-activated"}) { $symbolNode->setType(RequestOutputPlotSymbolTypeEnum::NO); return; } switch ($inputData->{$keyPrefix.'-symbols-type'}) { case 'dot' : $symbolNode->setType(RequestOutputPlotSymbolTypeEnum::DOT); break; case 'plus' : $symbolNode->setType(RequestOutputPlotSymbolTypeEnum::PLUS); break; case 'wildcard' : $symbolNode->setType(RequestOutputPlotSymbolTypeEnum::WILDCARD); break; case 'circle' : $symbolNode->setType(RequestOutputPlotSymbolTypeEnum::CIRCLE); break; case 'crux' : $symbolNode->setType(RequestOutputPlotSymbolTypeEnum::CRUX); break; case 'square' : $symbolNode->setType(RequestOutputPlotSymbolTypeEnum::SQUARE); break; case 'triangle' : $symbolNode->setType(RequestOutputPlotSymbolTypeEnum::TRIANGLE); break; case 'crux-in-circle' : $symbolNode->setType(RequestOutputPlotSymbolTypeEnum::CRUXINCIRCLE); break; case 'dot-in-circle' : $symbolNode->setType(RequestOutputPlotSymbolTypeEnum::DOTINCIRCLE); break; case 'diamond' : $symbolNode->setType(RequestOutputPlotSymbolTypeEnum::DIAMOND); break; case 'star' : $symbolNode->setType(RequestOutputPlotSymbolTypeEnum::STAR); break; case 'david-star' : $symbolNode->setType(RequestOutputPlotSymbolTypeEnum::DAVIDSTAR); break; case 'full-square' : $symbolNode->setType(RequestOutputPlotSymbolTypeEnum::FULLSQUARE); break; case 'full-circle' : $symbolNode->setType(RequestOutputPlotSymbolTypeEnum::FULLCIRCLE); break; case 'full-star' : $symbolNode->setType(RequestOutputPlotSymbolTypeEnum::FULLSTAR); break; default : throw new Exception('Symbol type not implemented.'); } $symbolNode->setSize($inputData->{$keyPrefix.'-symbols-size'}); if ($inputData->{$keyPrefix.'-symbols-color'} != 'auto') $symbolNode->setColor($this->hexColor2KernelColor($inputData->{$keyPrefix.'-symbols-color'})); } /* * @brief method to marshall the result of a download request */ protected function marshallResult($data) { if (!$this->isInteractiveRequest) { //add to job $commonRes = $this->commonMarshallResult($data,PLOT_RESULT_FILE_KEY."_0"); return $commonRes; } if (!$data->getSuccess()) return array( 'success' => false, 'message' => $data->getLastErrorMessage()); switch ($data->getStatus()) { case ProcessStatusEnumClass::DONE : $result = array(); foreach ($data->getWaitingResults() as $key => $waitingResult) { $contextResult = str_replace(".png","_context.xml",$waitingResult); $result[] = array( "id" => $key, "context" => IHMPlotContextFileClass::parse($this->getWorkingPath().$contextResult), "plot" => $waitingResult ); } return array( 'success' => true, 'id' => $data->getId(), 'folder' => $this->getWorkingDirName(), 'result' => $result ); case ProcessStatusEnumClass::KILLED : return array( 'success' => true, 'killed' => true); default : return array( 'success' => false, 'message' => 'Error to process the interractive request'); } } private function hexColor2KernelColor($hex) { $hex = str_replace("#", "", $hex); $r = hexdec(substr($hex,0,2)); $g = hexdec(substr($hex,2,2)); $b = hexdec(substr($hex,4,2)); return "[".$r.",".$g.",".$b."]"; } private function saveIHMRequest($input) { $path = $this->getWorkingPath()."ihm.request"; if (!is_dir($this->getWorkingPath())) mkdir($this->getWorkingPath(),0777); $file = fopen($path, 'w'); fwrite($file, json_encode($input)); fclose($file); } private function loadIHMRequest() { $path = $this->getWorkingPath()."ihm.request"; if (!file_exists($path)) return NULL; return json_decode(file_get_contents($path)); } } ?>