RequestOutputPlotParamsNodeClass.php 3.16 KB
<?php

require_once("RequestOutputPlotYSerieNodeClass.php");

define ("REQUESTOUTPUTPLOTPARAMS_NAME", "params");

define ("REQUESTOUTPUTPLOTPARAM_NAME", "param");
define ("REQUESTOUTPUTPLOTPARAM_ID", "id");

define ("REQUESTOUTPUTPLOTXSERIE_NAME", "xserie");
define ("REQUESTOUTPUTPLOTXSERIE_XAXIS", "xAxis");
define ("REQUESTOUTPUTPLOTXSERIE_INDEX", "index");

define ("REQUESTOUTPUTPLOTCOLORSERIE_NAME", "colorserie");
define ("REQUESTOUTPUTPLOTCOLORSERIE_ID", "id");
define ("REQUESTOUTPUTPLOTCOLORSERIE_INDEX", "index");

define ("REQUESTOUTPUTPLOTSPECTRO_NAME", "spectro");
define ("REQUESTOUTPUTPLOTSPECTRO_YAXIS", "yAxis");

/**
 * @class RequestOutputPlotParamNodeClass
 * @brief Definition of a param for a plot of a plot request
 * @details
*/
class RequestOutputPlotParamNodeClass extends NodeClass
{
	public function __construct($id)
	{
		parent::__construct(REQUESTOUTPUTPLOTPARAM_NAME);
		$this->setAttribute(REQUESTOUTPUTPLOTPARAM_ID, $id);
	}

	public function getId()
	{
		return $this->getAttribute(REQUESTOUTPUTPLOTPARAM_ID);
	}

	public function addYSerie($yAxis, $index, $xAxis = "", $colorSerieId = -1)
	{
		if ($xAxis != "")
		{
			$ySerieNode = new RequestOutputPlotYSerieNodeClass(REQUESTOUTPUTPLOTYSERIE_XYPLOT_NAME);
			$ySerieNode->setXAxisId($xAxis);
		}
		else
			$ySerieNode = new RequestOutputPlotYSerieNodeClass(REQUESTOUTPUTPLOTYSERIE_TIMEPLOT_NAME);
		$ySerieNode->setYAxisId($yAxis);
		if ($index >= 0)
			$ySerieNode->setIndex($index);
		if ($colorSerieId >= 0)
			$ySerieNode->setColorSerieId($colorSerieId);
		$this->addChild($ySerieNode);
		return $ySerieNode;
	}

	public function addSpectro($yAxis)
	{
		$spectroNode = new NodeClass(REQUESTOUTPUTPLOTSPECTRO_NAME);
		$spectroNode->setAttribute(REQUESTOUTPUTPLOTSPECTRO_YAXIS, $yAxis);
		$this->addChild($spectroNode);
		return $spectroNode;
	}

	public function addXSerie($xAxis, $index)
	{
		$xSerieNode = new NodeClass(REQUESTOUTPUTPLOTXSERIE_NAME);
		$xSerieNode->setAttribute(REQUESTOUTPUTPLOTXSERIE_XAXIS, $xAxis);
		if ($index >= 0)
			$xSerieNode->setAttribute(REQUESTOUTPUTPLOTXSERIE_INDEX, $index);
		$this->addChild($xSerieNode);
		return $xSerieNode;
	}
	
	public function addColorSerie($id, $index)
	{
		$colorSerieNode = new NodeClass(REQUESTOUTPUTPLOTCOLORSERIE_NAME);
		$colorSerieNode->setAttribute(REQUESTOUTPUTPLOTCOLORSERIE_ID, $id);
		if ($index >= 0)
			$colorSerieNode->setAttribute(REQUESTOUTPUTPLOTCOLORSERIE_INDEX, $index);
		$this->addChild($colorSerieNode);
		return $colorSerieNode;
	}
}

/**
 * @class RequestOutputPlotParamsNodeClass
 * @brief Definition of a params for a plot of a plot request
 * @details
 */
class RequestOutputPlotParamsNodeClass extends NodeClass
{
	public function __construct()
	{
		parent::__construct(REQUESTOUTPUTPLOTPARAMS_NAME);
	}

	public function getParamById($id)
	{
		$paramNodes = $this->getChildrenByName(REQUESTOUTPUTPLOTPARAM_NAME);
		foreach ($paramNodes as $paramNode)
		if ($paramNode->getId() == $id)
			return $paramNode;
		//create new param
		$paramNode = new RequestOutputPlotParamNodeClass($id);
		$this->addChild($paramNode);
		return $paramNode;
	}
}

?>