interactiveRequestRealIndexes = array(); $fullResetZoom = false; if (isset($input->{'action'})) { $input = $this->unmarshallActionRequest($input); $forceTimeZoomReset = isset($input->{'force-time-zoom-reset'}) ? $input->{'force-time-zoom-reset'} : false; } else { $resetZoom = true; //save request $this->saveIHMRequest($input); } //Get active tab $activeTab = NULL; foreach ($input->tabs as $tab) { if ($tab->{'id'} == $input->{'last-plotted-tab'}) { $activeTab = $tab; } } //Request $requestIndexInParamData = 0; $tabRequestIndex = 0; $this->isInteractiveRequest = ($input->{'file-output'} == 'INTERACTIVE'); $this->isFromWS = ($input->{'file-output'} == 'WS'); $postProcessCmd = ""; foreach ($input->tabs as $tab) { if (isset($activeTab)) { if ($this->isInteractiveRequest) { if ($activeTab->{'multi-plot-linked'} && !$tab->{'multi-plot-linked'}) { ++$tabRequestIndex; //Tab is not linked to the Multi Plot Mode continue; } else if (!$activeTab->{'multi-plot-linked'} && ($tab->{'id'} != $activeTab->{'id'})) { ++$tabRequestIndex; //Plot only current active tab continue; } else if (isset($input->{'force-single-replot'}) && $input->{'force-single-replot'} && ($tab->{'id'} != $activeTab->{'id'})) { ++$tabRequestIndex; //Plot only current active tab when 'force-single-replot' is active continue; } //Reset zoom list if needed if ($fullResetZoom || $forceTimeZoomReset) $this->resetZoomListForTab($tab->{'id'}, $forceTimeZoomReset && !$fullResetZoom); } else { if ($tab->{'id'} != $activeTab->{'id'}) { ++$tabRequestIndex; //In no interactive request, plot only active tab continue; } //Reset zoom list if needed if ($fullResetZoom || $forceTimeZoomReset) $this->resetZoomListForTab($tab->{'id'}, $forceTimeZoomReset && !$fullResetZoom); } } $requestNode = $this->paramsData->addRequestNode(); $requestNode->setRealIndex($tabRequestIndex); $outputsNode = $requestNode->getOutputsNode(); $paramsNode = $requestNode->getParamsNode(); //unmarshall time definition if ($tab->{'multi-plot-linked'}) { $isIntervalRequest = ($input->timesrc == 'Interval'); $ttFileIndex = -1; $ttIntIndex = -1; if ($this->isInteractiveRequest && !$isIntervalRequest && !$tab->{'page-superpose-mode'}) { $ttFileIndex = !isset($input->{'ttFileIndex'}) ? 0 : $input->{'ttFileIndex'}; $ttIntIndex = !isset($input->{'intIndex'}) ? 0 : $input->{'intIndex'}; } $this->unmarshallTimeDefinition($input, $requestIndexInParamData, $ttFileIndex, $ttIntIndex); } else { $isIntervalRequest = ($tab->timesrc == 'Interval'); $ttFileIndex = -1; $ttIntIndex = -1; if ($this->isInteractiveRequest && !$isIntervalRequest && !$tab->{'page-superpose-mode'}) { $ttFileIndex = !isset($activeTab->{'ttFileIndex'}) ? 0 : $activeTab->{'ttFileIndex'}; $ttIntIndex = !isset($activeTab->{'intIndex'}) ? 0 : $activeTab->{'intIndex'}; } $this->unmarshallTimeDefinition($tab, $requestIndexInParamData, $ttFileIndex, $ttIntIndex); } $this->interactiveCrtTTFileIndex = $ttFileIndex; $plotOutputNode = $outputsNode->addNewOutput(RequestOutputTypeEnum::PLOT); $plotOutputNode->setWriteContextFile($this->isInteractiveRequest ? "true" : "false"); $compression = ""; if (!$this->isInteractiveRequest && !$this->isFromWS) { 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 .= $tab->{'id'}; $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 'grayscale' : $pageNode->setMode(RequestOutputPlotPageModeEnum::GRAYSCALE); break; case 'color' : default: $pageNode->setMode(RequestOutputPlotPageModeEnum::COLOR); break; } 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-font', $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 || $this->isFromWS) { $resultFile = $filePrefix."_*".$extension; $waitingResultFile = $filePrefix.$extension; } else { $resultFile = $filePrefix."_*".$compression; $waitingResultFile = $filePrefix.$compression; } if ($this->isInteractiveRequest) { $this->interactiveRequestRealIndexes[PLOT_RESULT_FILE_KEY."_".$tab->{'id'}] = $tabRequestIndex; $this->interactiveMultiPlotState[PLOT_RESULT_FILE_KEY."_".$tab->{'id'}] = $tab->{'multi-plot-linked'}; $this->interactiveTimeSelectionState[PLOT_RESULT_FILE_KEY."_".$tab->{'id'}] = $isIntervalRequest; $this->interactivePreview = isset($input->{'interactive-preview'}) && ($input->{'interactive-preview'}); $this->paramsData->addWaitingResult(PLOT_RESULT_FILE_KEY."_".$tab->{'id'}, $waitingResultFile); } else $this->paramsData->addWaitingResult(PLOT_RESULT_FILE_KEY, $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; else if ($this->isFromWS) { if ($isPortrait) $postProcessCmd .= " | convert ".$waitingResultFile." -rotate -90 ".$input->{"ws-result-file"}; else $postProcessCmd .= " | mv ".$waitingResultFile." ".$input->{"ws-result-file"}; } ++$tabRequestIndex; ++$requestIndexInParamData; } $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 id if (isset($panelData->{'id'})) $panelNode->setId($panelData->{'id'}); if (isset($panelData->{'panel-index'})) $panelNode->setIndex($panelData->{'panel-index'}); //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-font', $panelNode->getFont()); //Panel title $this->unmarshallTitle($panelData, 'panel-title', $panelNode->getTitle()); //Plot type $plotNode = $this->unmarshallPlotType($panelData, $panelNode); $isTimePlot = ($plotNode->getName() == REQUESTOUTPUTPLOTELEMENTTIME_NAME); //Tick plot $tickPlotNode = NULL; if ($isTimePlot) { 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 ($isTimePlot) { 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, $panelData->{'constants'}, $plotNode); //Params $this->unmarshallParams($panelData->{'params'}, $paramsNode, $plotNode, $panelNode, $statusPlotNode, $tickPlotNode); //Additional objects if ($plotNode->getAdditionalObjects() != NULL) $this->unmarshallAdditionalObjects($panelData, $plotNode->getAdditionalObjects(), $isTimePlot); //Fills if ($plotNode->getFills() != NULL) $this->unmarshallFills($panelData, $plotNode->getFills()); 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'} != '') $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.'); } //Params Legend if (isset($panelData->{'panel-series-legend'}) && $panelData->{'panel-series-legend'}->{'legend-series-activated'}) $this->unmarshallParamsLegend($panelData->{'panel-series-legend'}, $plotNode->getLegends()->getParamsLegend()); //Text Legends foreach ($panelData->{'text-legends'} as $textLegendData) $this->unmarshallTextLegend($textLegendData, $plotNode->getLegends()); return $plotNode; } protected function unmarshallAxis($axisData, $constantsData, $plotNode) { //axis type $constantAxisId = ''; switch ($axisData->{'axis-type'}) { case 'time' : $axisNode = $plotNode->getTimeAxis(); $axisNode->setFormat($axisData->{'axis-time-format'}); $constantAxisId = 'x'; break; case 'epoch' : $axisNode = $plotNode->getEpochAxis(); $axisNode->setNormalized($axisData->{'axis-epoch-normalized'} ? "true" : "false"); $constantAxisId = 'x'; break; case 'x' : $axisNode = $plotNode->getXAxis(); $constantAxisId = 'x'; break; case 'y-left' : $axisNode = $plotNode->addYAxis('y-left'); $constantAxisId = 'y-left'; break; case 'y-right' : $axisNode = $plotNode->addYAxis('y-right'); $axisNode->setPosition(RequestOutputPlotAxisElementPosition::RIGHT); $constantAxisId = 'y-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 if (isset($axisData->{'axis-reverse'})) $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'}); if (isset($axisData->{'axis-range-extend'})) $axisNode->getRange()->setExtend($axisData->{'axis-range-extend'} ? "true" : "false"); //axis color if (isset($axisData->{'axis-color'})) $axisNode->setColor($this->hexColor2KernelColor($axisData->{'axis-color'})); //axis thickness if (isset($axisData->{'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 if (isset($axisData->{'axis-grid-minor'})) $axisNode->getTick()->setMinorGrid($axisData->{'axis-grid-minor'} ? "true" : "false"); if (isset($axisData->{'axis-grid-major'})) $axisNode->getTick()->setMajorGrid($axisData->{'axis-grid-major'} ? "true" : "false"); //legend if (isset($axisData->{'axis-legend-text'}) && $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()); } //Show legend if (isset($axisData->{'axis-legend-activated'})) $axisNode->setShowLegend($axisData->{'axis-legend-activated'} ? "true" : "false"); //Show tick marks if (isset($axisData->{'axis-tick-showmarks'})) $axisNode->setShowTickMarks($axisData->{'axis-tick-showmarks'} ? "true" : "false"); //Add constants if ($constantAxisId != '') { foreach ($constantsData as $constantData) if ($constantData->{'constant-axis-id'} == $constantAxisId) $this->unmarshallConstant($constantData,$axisNode); } } 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, $paramData->{'param-drawing-object'}->{'serie-xvalue-min'}, $paramData->{'param-drawing-object'}->{'serie-xvalue-max'}); else if (count($paramXInfo['indexes']) == 1) $xParamNode->addXSerie(REQUESTOUTPUTPLOTELEMENTXY_XAXISID, $paramXInfo['indexes'][0], $paramData->{'param-drawing-object'}->{'serie-xvalue-min'}, $paramData->{'param-drawing-object'}->{'serie-xvalue-max'}); 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->{'paramid'}, $this->paramsData, $paramData->{'template_args'}); $paramInfo['indexes'] = array(); $dim1_index = '*'; if (!$paramData->{'dim1-is-range'}) { if ($paramData->{'dim1-index'} != '') $dim1_index = $paramData->{'dim1-index'}; } $dim2_index = '*'; if (!$paramData->{'dim2-is-range'}) { if ($paramData->{'dim2-index'} != '') $dim2_index = $paramData->{'dim2-index'}; } switch ($paramData->{'type'}) { case 0: //scalar - nothing to do break; case 1: //Tab1D if ($paramData->{'dim1-is-range'}) { $template_args = array( 'paramid' => $paramInfo['id'], 'min' => $paramData->{'dim1-min-range'}, 'max' => $paramData->{'dim1-max-range'}, 'relateddim' => 0 ); $paramInfo = $this->paramManager->addExistingParam('sum_into_table_range', $this->paramsData, $template_args); } else if ($paramData->{'dim2-is-range'}) { $template_args = array( 'paramid' => $paramInfo['id'], 'min' => $paramData->{'dim2-min-range'}, 'max' => $paramData->{'dim2-max-range'}, 'relateddim' => 1 ); $paramInfo = $this->paramManager->addExistingParam('sum_into_table_range', $this->paramsData, $template_args); } else if (isset($dim1_index) && ($dim1_index != '*')) { $paramInfo['indexes'][] = $dim1_index; } else if (isset($dim2_index) && ($dim2_index != '*')) { $paramInfo['indexes'][] = $dim2_index; } break; case 2: if (($dim1_index != '*') || ($dim2_index != '*')) { $paramInfo['indexes'][] = "[".$dim1_index.",".$dim2_index."]"; } break; } $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->unmarshallSerie($paramData, $requestParamsNode, $plotNode, $paramNode, $paramInfo['indexes'], $isScatter && ($paramData->{'param-drawing-object'}->{'serie-xaxis-param'} != ''), $colorSerieId, false); break; case 'orbit-serie' : $paramNode = $plotNode->getParams()->getParamById($paramInfo['id']); $this->unmarshallSerie($paramData, $requestParamsNode, $plotNode, $paramNode, -1, false, $colorSerieId, true); 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; case 'ispectro' : $paramNode = $plotNode->getParams()->getParamById($paramInfo['id']); $this->unmarshallInstantSpectro($paramData->{'param-drawing-object'}, $plotNode, $paramNode, $paramInfo['indexes']); 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' : case 'orbit-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 unmarshallSerie($paramData, $requestParamsNode, $plotNode, $paramNode, $indexes, $useXAxis, $colorSerieId, $isOrbitSerie) { $serieNodes = array(); if (!$isOrbitSerie) { if (count($indexes) == 0) { $serieNode = $paramNode->addYSerie($paramData->{'param-drawing-object'}->{'serie-yaxis'}, -1, $useXAxis ? REQUESTOUTPUTPLOTELEMENTXY_XAXISID : '', $colorSerieId, $paramData->{'param-drawing-object'}->{'serie-value-min'}, $paramData->{'param-drawing-object'}->{'serie-value-max'}); $serieNode->setId($paramData->{'id'}); $serieNodes[] = $serieNode; } foreach ($indexes as $index) { $serieNode = $paramNode->addYSerie($paramData->{'param-drawing-object'}->{'serie-yaxis'}, $index, $useXAxis ? REQUESTOUTPUTPLOTELEMENTXY_XAXISID : '', $colorSerieId, $paramData->{'param-drawing-object'}->{'serie-value-min'}, $paramData->{'param-drawing-object'}->{'serie-value-max'}); if (count($indexes) == 1) $serieNode->setId($paramData->{'id'}); $serieNodes[] = $serieNode; } } else { $orbitSerie = $paramNode->addOrbitSerie($paramData->{'param-drawing-object'}->{'serie-yaxis'}, REQUESTOUTPUTPLOTELEMENTXY_XAXISID, $colorSerieId); $orbitSerie->setId($paramData->{'id'}); $serieNodes[] = $orbitSerie; } foreach ($serieNodes as $serieNode) { if (!$isOrbitSerie) { //Resampling if ($plotNode->getName() == REQUESTOUTPUTPLOTELEMENTXY_NAME) { switch ($paramData->{'param-drawing-object'}->{'serie-resampling-mode'}) { case 'yparam' : $serieNode->getResampling()->setType(RequestOutputPlotResamplingTypeEnum::YPARAM); break; case 'xparam' : default : $serieNode->getResampling()->setType(RequestOutputPlotResamplingTypeEnum::XPARAM); } } } else { //Projection switch ($paramData->{'param-drawing-object'}->{'serie-projection'}) { case 'XY' : $serieNode->setProjection(RequestOutputPlotOrbitSerieProjectionEnum::XY); break; case 'XZ' : $serieNode->setProjection(RequestOutputPlotOrbitSerieProjectionEnum::XZ); break; case 'YZ' : $serieNode->setProjection(RequestOutputPlotOrbitSerieProjectionEnum::YZ); break; case 'XR' : $serieNode->setProjection(RequestOutputPlotOrbitSerieProjectionEnum::XR); break; case 'YR' : $serieNode->setProjection(RequestOutputPlotOrbitSerieProjectionEnum::YR); break; case 'ZR' : $serieNode->setProjection(RequestOutputPlotOrbitSerieProjectionEnum::ZR); break; default : throw new Exception('Projection not allowed for the orbit serie'); } } //Line $this->unmarshallLine($paramData->{'param-drawing-object'}, 'serie', $serieNode->getLine(), $paramData->{'param-drawing-object'}->{"serie-lines-activated"} ? RequestOutputPlotLineTypeEnum::LINE : RequestOutputPlotLineTypeEnum::NO); //Symbol if (!$paramData->{'param-drawing-object'}->{"serie-symbols-activated"}) $serieNode->getSymbol()->setType(RequestOutputPlotSymbolTypeEnum::NO); else $this->unmarshallSymbol($paramData->{'param-drawing-object'}, 'serie-symbols', $serieNode->getSymbol()); //Time tick if ($paramData->{'param-drawing-object'}->{'serie-timetick-activated'}) $this->unmarshallTimeTick($paramData->{'param-drawing-object'}, $serieNode->getTimeTicks()); //Interval tick if ($paramData->{'param-drawing-object'}->{'serie-intervaltick-activated'}) $this->unmarshallIntervalTick($paramData->{'param-drawing-object'}, $serieNode->getIntervalTicks()); if (!$isOrbitSerie) { //Error bar if ($paramData->{'param-drawing-object'}->{'serie-errorbar-activated'}) $this->unmarshallErrorBar($paramData->{'param-drawing-object'}, $requestParamsNode, $serieNode->getErrorBar()); } } } protected function unmarshallTimeTick($serieData, $timeTickNode) { //Font if ($serieData->{'serie-timetick-font-activated'}) $this->unmarshallFont($serieData, 'serie-timetick-font', $timeTickNode->getFont()); //First Symbol if ($serieData->{'serie-timetick-firstsymbols-activated'}) $this->unmarshallSymbol($serieData, 'serie-timetick-firstsymbols', $timeTickNode->getFirstSymbol()); //Symbol $this->unmarshallSymbol($serieData, 'serie-timetick-symbols', $timeTickNode->getSymbol()); //Set options by type switch ($serieData->{'serie-timetick-type'}) { case 'time-step' : $timeTickNode->setStep(CommonClass::timeStampToDDTime($serieData->{'serie-timetick-step'})); $timeTickNode->setNumber(0); break; case 'nb-major' : $timeTickNode->setStep(0); $timeTickNode->setNumber($serieData->{'serie-timetick-nbmajor'}); break; case 'auto' : default : $timeTickNode->setStep('auto'); $timeTickNode->setNumber(0); } //Minor $timeTickNode->setMinor($serieData->{'serie-timetick-nbminor'}); //Color $timeTickNode->setColor($this->hexColor2KernelColor($serieData->{'serie-timetick-color'})); } protected function unmarshallIntervalTick($serieData, $intervalTickNode) { //Mode switch ($serieData->{'serie-intervaltick-mode'}) { case 'symbol-only': $intervalTickNode->setMode(RequestOutputPlotSerieIntervalTicksModeEnum::SYMBOLONLY); break; case 'interval-index': $intervalTickNode->setMode(RequestOutputPlotSerieIntervalTicksModeEnum::INTERVALINDEX); break; case 'start-stop-time': $intervalTickNode->setMode(RequestOutputPlotSerieIntervalTicksModeEnum::STARTSTOPTIME); break; case 'start-time': default : $intervalTickNode->setMode(RequestOutputPlotSerieIntervalTicksModeEnum::STARTTIME); } //Color $intervalTickNode->setColor($this->hexColor2KernelColor($serieData->{'serie-intervaltick-color'})); //Symbol $this->unmarshallSymbol($serieData, 'serie-intervaltick-symbols', $intervalTickNode->getSymbol()); //Font if ($serieData->{'serie-intervaltick-font-activated'}) $this->unmarshallFont($serieData, 'serie-intervaltick-font', $intervalTickNode->getFont()); } protected function unmarshallErrorBar($serieData, $requestParamsNode, $errorBarNode) { //Type switch ($serieData->{'serie-errorbar-type'}) { case 'min-max': $errorBarTypeNode = $errorBarNode->getBarByType(RequestOutputPlotYSerieErrorBarTypeEnum::MINMAX); $minParamInfo = $this->paramManager->addExistingParam($serieData->{'serie-errorbar-minparam'}, $this->paramsData); if ($minParamInfo['id'] == '') throw new Exception('Cannot retrieve min. error parameter.'); $requestParamsNode->addParam($minParamInfo['id']); if (count($minParamInfo['indexes']) == 0) $errorBarTypeNode->setMinParam($minParamInfo['id'], -1); else if (count($minParamInfo['indexes']) == 1) $errorBarTypeNode->setMinParam($minParamInfo['id'], $minParamInfo['indexes'][0]); else throw new Exception('Min parameter for error bar must be a component.'); $maxParamInfo = $this->paramManager->addExistingParam($serieData->{'serie-errorbar-maxparam'}, $this->paramsData); if ($maxParamInfo['id'] == '') throw new Exception('Cannot retrieve max. error parameter.'); $requestParamsNode->addParam($maxParamInfo['id']); if (count($maxParamInfo['indexes']) == 0) $errorBarTypeNode->setMaxParam($maxParamInfo['id'], -1); else if (count($maxParamInfo['indexes']) == 1) $errorBarTypeNode->setMaxParam($maxParamInfo['id'], $maxParamInfo['indexes'][0]); else throw new Exception('Max parameter for error bar must be a component.'); break; case 'delta': $errorBarTypeNode = $errorBarNode->getBarByType(RequestOutputPlotYSerieErrorBarTypeEnum::DELTA); $deltaParamInfo = $this->paramManager->addExistingParam($serieData->{'serie-errorbar-deltaparam'}, $this->paramsData); if ($deltaParamInfo['id'] == '') throw new Exception('Cannot retrieve delta error parameter.'); $requestParamsNode->addParam($deltaParamInfo['id']); if (count($deltaParamInfo['indexes']) == 0) $errorBarTypeNode->setDeltaParam($deltaParamInfo['id'], -1); else if (count($deltaParamInfo['indexes']) == 1) $errorBarTypeNode->setDeltaParam($deltaParamInfo['id'], $deltaParamInfo['indexes'][0]); else throw new Exception('Delta parameter for error bar must be a component.'); break; default : throw new Exception('Unknown error bar type.'); } //Line $this->unmarshallLine($serieData, 'serie-errorbar', $errorBarNode->getLine(), RequestOutputPlotLineTypeEnum::LINE); } 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(), $paramDrawingData->{"iserie-lines-activated"} ? RequestOutputPlotLineTypeEnum::LINE : RequestOutputPlotLineTypeEnum::NO); //Symbol if (!$paramDrawingData->{"iserie-symbols-activated"}) $iserieNode->getSymbol()->setType(RequestOutputPlotSymbolTypeEnum::NO); else $this->unmarshallSymbol($paramDrawingData, 'iserie-symbols', $iserieNode->getSymbol()); } protected function unmarshallSpectro($paramDrawingData, $plotNode, $paramNode, $indexes) { $spectroNode = $paramNode->addSpectro($paramDrawingData->{'spectro-yaxis'}, count($indexes) > 0 ? $indexes[0] : NULL, $paramDrawingData->{'spectro-value-min'}, $paramDrawingData->{'spectro-value-max'}); } protected function unmarshallInstantSpectro($paramDrawingData, $plotNode, $paramNode, $indexes) { //TBD how to process inexes if they are defined ? $spectroNode = $paramNode->addInstantSpectro(REQUESTOUTPUTPLOTELEMENTXY_XAXISID, 'y-left', $paramDrawingData->{'ispectro-dimonxaxis'}); } 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 unmarshallParamsLegend($paramsLegendData, $paramsLegendNode) { //Legend type switch ($paramsLegendData->{'legend-series-type'}) { case 'text-line-symbol' : $paramsLegendNode->setType(RequestOutputPlotParamsLegendTypeEnum::TEXTLINESYMBOL); break; case 'text-only' : default : $paramsLegendNode->setType(RequestOutputPlotParamsLegendTypeEnum::TEXTONLY); } //Show param legend $paramsLegendNode->setShowParamInfo($paramsLegendData->{'legend-series-showparaminfo'} ? "true" : "false"); //Show interval legend $paramsLegendNode->setShowIntervalInfo($paramsLegendData->{'legend-series-intervalinfo-activated'} ? "true" : "false"); //Interval info type switch ($paramsLegendData->{'legend-series-intervalinfo-type'}) { case 'start-stop' : $paramsLegendNode->setIntervalInfoType(RequestOutputPlotParamsLegendIntervalInfoTypeEnum::STARTSTOP); break; case 'index' : default : $paramsLegendNode->setIntervalInfoType(RequestOutputPlotParamsLegendIntervalInfoTypeEnum::INDEX); } //Position switch ($paramsLegendData->{'legend-series-position'}) { case 'inside' : $paramsLegendNode->setPosition(RequestOutputPlotParamsLegendPositionEnum::INSIDE); break; case 'outside' : default : $paramsLegendNode->setPosition(RequestOutputPlotParamsLegendPositionEnum::OUTSIDE); } //Default text color $paramsLegendNode->setDefaultTextColor($this->hexColor2KernelColor($paramsLegendData->{'legend-series-defaulttextcolor'})); //Border visible $paramsLegendNode->setBorderVisible($paramsLegendData->{'legend-series-border-activated'} ? "true" : "false"); //Border color $paramsLegendNode->setBorderColor($this->hexColor2KernelColor($paramsLegendData->{'legend-series-border-color'})); //Font if ($paramsLegendData->{'legend-series-font-activated'}) $this->unmarshallFont($paramsLegendData, 'legend-series-font', $paramsLegendNode->getFont()); } protected function unmarshallTextLegend($textLegendData, $legendsNode) { $legendNode = $legendsNode->addTextLegend(); //Legend text $legendNode->setText($textLegendData->{'legend-text-value'}); //Legend position switch ($textLegendData->{'legend-text-position'}) { case 'top' : $legendNode->setPosition(RequestOutputPlotTextLegendPositionEnum::TOP); break; case 'bottom' : $legendNode->setPosition(RequestOutputPlotTextLegendPositionEnum::BOTTOM); break; case 'left' : $legendNode->setPosition(RequestOutputPlotTextLegendPositionEnum::LEFT); break; case 'right' : default : $legendNode->setPosition(RequestOutputPlotTextLegendPositionEnum::RIGHT); } //Legend text color $legendNode->setColor($this->hexColor2KernelColor($textLegendData->{'legend-text-color'})); //Font if ($textLegendData->{'legend-text-font-activated'}) $this->unmarshallFont($textLegendData, 'legend-text-font', $legendNode->getFont()); } protected function unmarshallConstant($constantData,$axisNode) { $constantNode = $axisNode->addConstant(); $constantNode->setId($constantData->{'id'}); //Constant value switch ($axisNode->getName()) { case REQUESTOUTPUTPLOTTIMEAXIS_NAME : date_default_timezone_set('UTC'); $timeStamp = strtotime($constantData->{'constant-time-value'}); $time = CommonClass::timeStampToDDTime($timeStamp); $constantNode->setConstantValue($time); break; default : $constantNode->setConstantValue($constantData->{'constant-float-value'}); } //Curve options $this->unmarshallCurve($constantData, "constant-line", $constantNode); } protected function unmarshallAdditionalObjects($panelData, $addObjectsNode, $isTimePlot) { foreach ($panelData->{'textObjs'} as $textData) $this->unmarshallTextObject($textData, $addObjectsNode, $isTimePlot); foreach ($panelData->{'curves'} as $curveData) $this->unmarshallCurveObject($curveData, $addObjectsNode); } protected function unmarshallTextObject($textData, $addObjectsNode, $isTimePlot) { $textNode = $addObjectsNode->addTextObject(); $textNode->setText($textData->{'text-value'}); switch ($textData->{'text-y-axis'}) { case 'y-right' : $textNode->setYAxis('y-right'); break; case 'y-left' : $textNode->setYAxis('y-left'); break; } if ($isTimePlot && !$textData->{'text-x-relative'}) { date_default_timezone_set('UTC'); $timeStamp = strtotime($textData->{'text-x-timevalue'}); $time = CommonClass::timeStampToDDTime($timeStamp); $textNode->setX($time); } else if ($textData->{'text-x-relative'}) $textNode->setX(($textData->{'text-x-floatvalue'}*100)."%"); else $textNode->setX($textData->{'text-x-floatvalue'}); if ($textData->{'text-y-relative'}) $textNode->setY(($textData->{'text-y-value'}*100)."%"); else $textNode->setY($textData->{'text-y-value'}); $textNode->setAngle($textData->{'text-angle'}); $textNode->setColor($this->hexColor2KernelColor($textData->{'text-color'})); switch ($textData->{'text-align'}) { case 'center' : $textNode->setAlign(RequestOutputPlotTextAlign::CENTER); break; case 'right' : $textNode->setAlign(RequestOutputPlotTextAlign::RIGHT); break; case 'left' : default: $textNode->setAlign(RequestOutputPlotTextAlign::LEFT); } //Font if ($textData->{'text-font-activated'}) $this->unmarshallFont($textData, 'text-font', $textNode->getFont()); } protected function unmarshallCurveObject($curveData, $addObjectsNode) { if (($curveData->{'curve-name'} == '') || !isset($curveData->{'curve-serie-id'})) return; $curveNode = $addObjectsNode->addCurveObject(); $curveNode->setSerieId($curveData->{'curve-serie-id'}); $curveNode->getFunction()->setFunctionName($curveData->{'curve-name'}); foreach ($curveData->{'params'} as $paramData) $curveNode->getFunction()->addAttribute($paramData->{'curve-param-name'}, $paramData->{'curve-param-value'}); //Curve options $this->unmarshallCurve($curveData, "curve-line", $curveNode); } protected function unmarshallFills($panelData, $fillsNode) { foreach ($panelData->{'fills'} as $fillData) { //Serie / Constant if ($fillData->{'fill-type'} == 'serie-constant') { $fillNode = $fillsNode->addFill(RequestOutputPlotFillTypeEnum::SERIECONSTANT); $fillNode->setSerieId($fillData->{'fill-firstserie-id'}); $fillNode->setConstantId($fillData->{'fill-constant-id'}); if ($fillData->{'fill-greater-color'} != 'none') $fillNode->setGreaterColor($this->hexColor2KernelColor($fillData->{'fill-greater-color'})); if ($fillData->{'fill-less-color'} != 'none') $fillNode->setLessColor($this->hexColor2KernelColor($fillData->{'fill-less-color'})); } } foreach ($panelData->{'fills'} as $fillData) { //Serie / Serie if ($fillData->{'fill-type'} == 'serie-serie') { $fillNode = $fillsNode->addFill(RequestOutputPlotFillTypeEnum::SERIESERIE); $fillNode->setFirstSerieId($fillData->{'fill-firstserie-id'}); $fillNode->setSecondSerieId($fillData->{'fill-secondserie-id'}); if ($fillData->{'fill-greater-color'} != 'none') $fillNode->setGreaterColor($this->hexColor2KernelColor($fillData->{'fill-greater-color'})); if ($fillData->{'fill-less-color'} != 'none') $fillNode->setLessColor($this->hexColor2KernelColor($fillData->{'fill-less-color'})); } } } 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.'-activated'}) { $fontNode->setFontName($inputData->{$keyPrefix.'-name'}); $fontNode->setSize($inputData->{$keyPrefix.'-size'}); if ($inputData->{$keyPrefix.'-italic'}) $fontNode->setStyle(RequestOutputPlotFontStyle::ITALIC); else $fontNode->setStyle(RequestOutputPlotFontStyle::UPRIGHT); if ($inputData->{$keyPrefix.'-bold'}) $fontNode->setWeight(RequestOutputPlotFontWeight::BOLD); else $fontNode->setWeight(RequestOutputPlotFontWeight::MEDIUM); } } protected function unmarshallCurve($inputData, $keyPrefix, $curveNode) { switch ($inputData->{$keyPrefix.'-style'}) { 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; case 'plain' : default : $curveNode->setStyle(RequestOutputPlotCurveStyleEnum::PLAIN); break; } if (isset($inputData->{$keyPrefix.'-width'})) $curveNode->setWidth($inputData->{$keyPrefix.'-width'}); if (isset($inputData->{$keyPrefix.'-color'}) && ($inputData->{$keyPrefix.'-color'} != 'auto')) $curveNode->setColor($this->hexColor2KernelColor($inputData->{$keyPrefix.'-color'})); } protected function unmarshallLine($inputData, $keyPrefix, $lineNode, $lineType) { $lineNode->setType($lineType); $this->unmarshallCurve($inputData, $keyPrefix."-lines", $lineNode); } protected function unmarshallSymbol($inputData, $keyPrefix, $symbolNode) { switch ($inputData->{$keyPrefix.'-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.'-size'}); if ($inputData->{$keyPrefix.'-color'} != 'auto') $symbolNode->setColor($this->hexColor2KernelColor($inputData->{$keyPrefix.'-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); return $commonRes; } //Interactive request 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, "index" => $this->interactiveRequestRealIndexes[$key], "multiplot" => $this->interactiveMultiPlotState[$key], "preview" => $this->interactivePreview, "isInterval" => $this->interactiveTimeSelectionState[$key], "ttFileIndex" => $this->interactiveCrtTTFileIndex, "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)); } private function unmarshallActionRequest($input) { $actionInput = $input->{'action'}; $multiPlotState = $input->{'multiPlotState'}; $plotInput = $this->loadIHMRequest(); if (!isset($plotInput)) throw new Exception('Cannot retrieve request input for inetractive action.'); //Set interactive Multi Plot state foreach ($multiPlotState as $key => $value) { foreach ($plotInput->{'tabs'} as $tab) { if (PLOT_RESULT_FILE_KEY."_".$tab->{'id'} == $key) $tab->{'multi-plot-linked'} = $value; } } switch ($actionInput->{'action'}) { case 'zoom' : return $this->unmarshallZoom($actionInput, $plotInput); case 'forward' : case 'halfforward' : case 'backward' : case 'halfbackward' : case 'extend' : case 'shift' : return $this->unmarshallNavigation($actionInput, $plotInput); case 'goto' : return $this->unmarshallTTGoto($actionInput, $plotInput); case 'synchronize' : return $this->unmarshallSynchronize($actionInput, $plotInput); case 'instant' : return $this->unmarshallInstant($actionInput, $plotInput); case 'undozoom' : return $this->unmarshallUndoZoom($actionInput, $plotInput); default : throw new Exception('Interactive action not implemented.'); } } private function addZoomInList($input, $isInterval, $minOrFileIndex, $maxOrIntervalIndex) { //if $isInterval == true, $minOrFileIndex is the min and $maxOrInetrvalIndex is the max //if $isInterval == false, $minOrFileIndex is the fileIndex and $maxOrInetrvalIndex is the intervalIndex $zoomList = $this->loadZoomList(); if (!isset($zoomList->tabs)) { //Init zoom list $zoomList = (Object)array( 'tabs' => (Object)array() ); } if (!isset($zoomList->tabs->{$input->{'tabId'}})) { $zoomList->tabs->{$input->{'tabId'}} = (Object)array( 'times' => array(), 'panels' => (Object)array() ); } if ($input->{'axeId'} == 'timeAxis') { if ($isInterval) array_push ($zoomList->tabs->{$input->{'tabId'}}->times, (Object)array( 'isInterval' => true, 'min' => $minOrFileIndex, 'max' => $maxOrIntervalIndex )); else array_push ($zoomList->tabs->{$input->{'tabId'}}->times, (Object)array( 'isInterval' => false, 'ttFileIndex' => $minOrFileIndex, 'intIndex' => $maxOrIntervalIndex )); } else { if (!isset($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}})) { $zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}} = (Object) array( 'axes' => (Object)array() ); } if (!isset($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}})) { $zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}} = array(); } array_push ($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}}, (Object)array( 'min' => $minOrFileIndex, 'max' => $maxOrIntervalIndex )); } //save zoom list $path = $this->getWorkingPath()."zoom.list"; if (!is_dir($this->getWorkingPath())) mkdir($this->getWorkingPath(),0777); $file = fopen($path, 'w'); fwrite($file, json_encode($zoomList)); fclose($file); } private function loadZoomList() { $path = $this->getWorkingPath()."zoom.list"; if (!file_exists($path)) return NULL; return json_decode(file_get_contents($path)); } private function resetZoomListForTab($tabId, $resetOnlyTimeZoom = false) { $zoomList = $this->loadZoomList(); if (isset($zoomList->tabs) && isset($zoomList->tabs->{PLOT_RESULT_FILE_KEY."_".$tabId})) { if (!$resetOnlyTimeZoom) unset($zoomList->tabs->{PLOT_RESULT_FILE_KEY."_".$tabId}); else $zoomList->tabs->{PLOT_RESULT_FILE_KEY."_".$tabId}->times = array(); } $path = $this->getWorkingPath()."zoom.list"; if (!is_dir($this->getWorkingPath())) mkdir($this->getWorkingPath(),0777); $file = fopen($path, 'w'); fwrite($file, json_encode($zoomList)); fclose($file); } private function undoZoomInList($input) { $zoomList = $this->loadZoomList(); $result = NULL; if (isset($zoomList->tabs) && isset($zoomList->tabs->{$input->{'tabId'}})) { if ($input->{'axeId'} == 'timeAxis') { if (count($zoomList->tabs->{$input->{'tabId'}}->times) <= 0) return NULL; $result = array_pop($zoomList->tabs->{$input->{'tabId'}}->times); } else { if (!isset($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}})) return NULL; if (!isset($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}})) return NULL; $result = array_pop($zoomList->tabs->{$input->{'tabId'}}->panels->{$input->{'panelId'}}->axes->{$input->{'axeId'}}); } } else return NULL; $path = $this->getWorkingPath()."zoom.list"; if (!is_dir($this->getWorkingPath())) mkdir($this->getWorkingPath(),0777); $file = fopen($path, 'w'); fwrite($file, json_encode($zoomList)); fclose($file); return $result; } private function unmarshallZoom($input, $plotInput, $isUndo = false) { //Find current tab $crtTab = NULL; foreach ($plotInput->{'tabs'} as $tab) { if ($input->{'tabId'} == PLOT_RESULT_FILE_KEY."_".$tab->{'id'}) { $crtTab = $tab; break; } } if (!$crtTab) throw new Exception('Cannot retrieve plot tab for navigation action.'); if ($input->{'axeId'} == 'timeAxis') { //Zoom on Time Axis if ($crtTab->{'multi-plot-linked'}) { //Update multi plot time definition if ($plotInput->{'timesrc'} != 'Interval') { $plotInput->{'timesrc'} = 'Interval'; if (!$isUndo) $this->addZoomInList($input,false, isset($plotInput->{'ttFileIndex'}) ? $plotInput->{'ttFileIndex'}: 0, isset($plotInput->{'intIndex'}) ? $plotInput->{'intIndex'}: 0); } else { if (!$isUndo) $this->addZoomInList($input,true,$plotInput->{'startDate'},$plotInput->{'stopDate'}); } $plotInput->{'startDate'} = $input->{'min'}; $plotInput->{'stopDate'} = $input->{'max'}; } else { if ($crtTab->{'timesrc'} != 'Interval') { $crtTab->{'timesrc'} = 'Interval'; if (!$isUndo) $this->addZoomInList($input,false, isset($crtTab->{'ttFileIndex'}) ? $crtTab->{'ttFileIndex'} : 0, isset($crtTab->{'intIndex'}) ? $crtTab->{'intIndex'} : 0); } else { if (!$isUndo) $this->addZoomInList($input,true,$crtTab->{'startDate'},$crtTab->{'stopDate'}); } $crtTab->{'startDate'} = $input->{'min'}; $crtTab->{'stopDate'} = $input->{'max'}; } $plotInput->{'last-plotted-tab'} = $crtTab->{'id'}; $plotInput->{'force-time-zoom-reset'} = false; $this->saveIHMRequest($plotInput); return $plotInput; } //Digital axis zoom foreach ($crtTab->{'panels'} as $panel) { if ($input->{'panelId'} == $panel->{'id'}) { foreach ($panel->{'axes'} as $axis) { if ($input->{'axeId'} == $axis->{'id'}) { $axis->{'axis-range-extend'} = false; $oldMin = $axis->{'axis-range-min'}; $oldMax = $axis->{'axis-range-max'}; $axis->{'axis-range-min'} = $input->{'min'}; $axis->{'axis-range-max'} = $input->{'max'}; $plotInput->{'last-plotted-tab'} = $crtTab->{'id'}; $this->saveIHMRequest($plotInput); //Do not save 'force-single-replot' in request file! $plotInput->{'force-single-replot'} = true; $plotInput->{'force-time-zoom-reset'} = false; if (!$isUndo) $this->addZoomInList($input,true,$oldMin,$oldMax); return $plotInput; } } throw new Exception('Cannot retrieve axis for zoom action.'); } } throw new Exception('Cannot retrieve plot panel for zoom action.'); } private function unmarshallUndoZoom($input, $plotInput) { $result = $this->undoZoomInList($input); if ($result != NULL) { if (isset($result->isInterval)) { if (!$result->isInterval) { $input->ttFileIndex = $result->ttFileIndex; $input->intIndex = $result->intIndex; return $this->unmarshallTTGoto($input, $plotInput); } } $input->min = $result->min; $input->max = $result->max; return $this->unmarshallZoom($input, $plotInput, true); } throw new Exception('No undo zoom to apply.'); } private function unmarshallNavigation($input, $plotInput) { //Find current tab $crtTab = NULL; foreach ($plotInput->{'tabs'} as $tab) { if ($input->{'tabId'} == PLOT_RESULT_FILE_KEY."_".$tab->{'id'}) { $crtTab = $tab; break; } } if (!$crtTab) throw new Exception('Cannot retrieve plot tab for navigation action.'); if ($crtTab->{'multi-plot-linked'}) { $startTime = $plotInput->{'startDate'}; $stopTime = $plotInput->{'stopDate'}; } else { $startTime = $crtTab->{'startDate'}; $stopTime = $crtTab->{'stopDate'}; } //Compute new start / stop time date_default_timezone_set('UTC'); $startTimeStamp = strtotime($startTime); $stopTimeStamp = strtotime($stopTime); $duration = $stopTimeStamp - $startTimeStamp; switch ($input->{'action'}) { case 'forward' : $startTimeStamp += $duration; $stopTimeStamp += $duration; break; case 'halfforward' : $startTimeStamp += ($duration/2); $stopTimeStamp += ($duration/2); break; case 'backward' : $startTimeStamp -= $duration; $stopTimeStamp -= $duration; break; case 'halfbackward' : $startTimeStamp -= ($duration/2); $stopTimeStamp -= ($duration/2); break; case 'extend' : $startTimeStamp -= $input->{'duration'}; $stopTimeStamp += $input->{'duration'}; break; case 'shift' : $startTimeStamp += $input->{'duration'}; $stopTimeStamp += $input->{'duration'}; break; } if ($stopTimeStamp - $startTimeStamp <= 0) throw new Exception('New duration is lower than 0.'); $startTime = date("Y-m-d\TH:i:s",$startTimeStamp); $stopTime = date("Y-m-d\TH:i:s",$stopTimeStamp); //Update request if ($crtTab->{'multi-plot-linked'}) { $plotInput->{'startDate'} = $startTime; $plotInput->{'stopDate'} = $stopTime; } else { $crtTab->{'startDate'} = $startTime; $crtTab->{'stopDate'} = $stopTime; } $plotInput->{'last-plotted-tab'} = $crtTab->{'id'}; $plotInput->{'force-time-zoom-reset'} = true; $this->saveIHMRequest($plotInput); return $plotInput; } private function unmarshallTTGoto($input, $plotInput) { //Find current tab $crtTab = NULL; foreach ($plotInput->{'tabs'} as $tab) { if ($input->{'tabId'} == PLOT_RESULT_FILE_KEY."_".$tab->{'id'}) { $crtTab = $tab; break; } } if (!$crtTab) throw new Exception('Cannot retrieve plot tab for navigation action.'); $plotInput->{'last-plotted-tab'} = $crtTab->{'id'}; if ($crtTab->{'multi-plot-linked'}) { $plotInput->{'timesrc'} = 'TimeTable'; $plotInput->{'ttFileIndex'} = $input->{'ttFileIndex'}; $plotInput->{'intIndex'} = $input->{'intIndex'}; } else { $crtTab->{'timesrc'} = 'TimeTable'; $crtTab->{'ttFileIndex'} = $input->{'ttFileIndex'}; $crtTab->{'intIndex'} = $input->{'intIndex'}; } $plotInput->{'force-time-zoom-reset'} = true; $this->saveIHMRequest($plotInput); return $plotInput; } private function unmarshallSynchronize($input, $plotInput) { //Find current tab $crtTab = NULL; foreach ($plotInput->{'tabs'} as $tab) { if ($input->{'tabId'} == PLOT_RESULT_FILE_KEY."_".$tab->{'id'}) { $crtTab = $tab; break; } } if (!$crtTab) throw new Exception('Cannot retrieve plot tab for synchronize action.'); if ($crtTab->{'multi-plot-linked'}) { } else { $plotInput->{'last-plotted-tab'} = $crtTab->{'id'}; $crtTab->{'ttFileIndex'} = $plotInput->{'ttFileIndex'}; $crtTab->{'intIndex'} = $plotInput->{'intIndex'}; $crtTab->{'timesrc'} = $plotInput->{'timesrc'}; $crtTab->{'timeTables'} = $plotInput->{'timeTables'}; $crtTab->{'startDate'} = $plotInput->{'startDate'}; $crtTab->{'stopDate'} = $plotInput->{'stopDate'}; } $plotInput->{'force-time-zoom-reset'} = true; $this->saveIHMRequest($plotInput); return $plotInput; } private function unmarshallInstant($input, $plotInput) { //Find current tab $crtTab = NULL; foreach ($plotInput->{'tabs'} as $tab) { if ($input->{'tabId'} == PLOT_RESULT_FILE_KEY."_".$tab->{'id'}) { $crtTab = $tab; break; } } if (!$crtTab) throw new Exception('Cannot retrieve plot tab for instant plot.'); //Find current panel $crtPanel = NULL; foreach ($crtTab->{'panels'} as $panel) { if ($input->{'panelId'} == $panel->{'id'}) { $crtPanel = $panel; break; } } if (!$crtPanel) throw new Exception('Cannot retrieve plot panel for instant plot.'); if ($crtPanel->{'panel-plot-type'} != 'timePlot') throw new Exception('Instant plot action only available for Time plot.'); //Find spectra parameter $crtParam = NULL; foreach ($crtPanel->{'params'} as $param) { if ($param->{'param-drawing-type'} == 'spectro') { $crtParam = $param; break; } } if (!$crtParam) throw new Exception('Cannot retrieve plot param for instant plot.'); //Find table Y-axis $crtYAxis = NULL; foreach ($crtPanel->{'axes'} as $axis) { if ($crtParam->{'param-drawing-object'}->{'spectro-yaxis'} == $axis->{'id'}) { $crtYAxis = $axis; break; } } if (!$crtYAxis) throw new Exception('Cannot retrieve plot y Axis for instant plot.'); //Find color Z-axis $crtColorAxis = NULL; foreach ($crtPanel->{'axes'} as $axis) { if ($axis->{'id'} == 'color') { $crtColorAxis = $axis; break; } } if (!$crtColorAxis) throw new Exception('Cannot retrieve plot color Axis for instant plot.'); date_default_timezone_set('UTC'); $timeStamp = strtotime($input->time); $instantPlotInput = (Object)array( "interactive-preview" => true, "file-format" => "PNG", "file-output" => "INTERACTIVE", "file-prefix" => "instant", "last-plotted-tab"=> 1, "timesrc" => "Interval", "startDate" => date("Y-m-dTH:i:s", $timeStamp - 3600), "stopDate" => date("Y-m-dTH:i:s", $timeStamp + 3600), "tabs" => array() ); $instantTab = (Object)array( "id" => 1, "multi-plot-linked" => true, "page-margins-activated" => $crtTab->{"page-margins-activated"}, "page-margin-x" => $crtTab->{"page-margin-x"}, "page-margin-y" => $crtTab->{"page-margin-y"}, "page-orientation" => $crtTab->{"page-orientation"}, "page-dimension" => $crtTab->{"page-dimension"}, "page-layout-type" => "vertical", "page-layout-object" => (Object)array( "layout-expand" => true, "layout-panel-height" => 0.5, "layout-panel-spacing" => 0.05 ), "panels" => array() ); $instantPanel = (Object)array( "id" => "1", "panel-plot-type" => "instantPlot", "panel-instant-time" => $input->time, "axes" => array(), "params" => array() ); $instantXAxis = (Object)array( "id" => "xaxis_id", "axis-type" => "x", "axis-scale" => $crtYAxis->{"axis-scale"}, "axis-thickness" => 1 ); $instantYAxis = (Object)array( "id" => "y-left", "axis-type" => "y-left", "axis-scale" => $crtColorAxis->{"axis-scale"}, "axis-thickness" => 1 ); $instantPanel->{"axes"}[] = $instantXAxis; $instantPanel->{"axes"}[] = $instantYAxis; $instantParam = (Object)array( "id" => 1, "paramid" => $crtParam->{'paramid'}, "param-drawing-type" => "iserie", "param-drawing-object" => (Object)array( "iserie-tableonx" => true, "iserie-lines-activated" => true, "iserie-lines-style" => "plain", "iserie-lines-width" => 1, "iserie-lines-color" => "auto" ) ); $instantPanel->{"params"}[] = $instantParam; $instantTab->{"panels"}[] = $instantPanel; $instantPlotInput->{"tabs"}[] = $instantTab; return $instantPlotInput; } } ?>