RequestOutputPlotParamsNodeClass.php 10.7 KB
<?php

require_once("RequestOutputPlotYSerieNodeClass.php");
require_once "RequestOutputPlotOrbitSerieNodeClass.php";
require_once "RequestOutputPlotInstantSerieNodeClass.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 ("REQUESTOUTPUTPLOTXSERIE_ID", "id");
define ("REQUESTOUTPUTPLOTXSERIE_MIN", "min");
define ("REQUESTOUTPUTPLOTXSERIE_MAX", "max");

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

define ("REQUESTOUTPUTPLOTSPECTRO_NAME", "spectro");
define ("REQUESTOUTPUTPLOTSPECTRO_YAXIS", "yAxis");
define ("REQUESTOUTPUTPLOTSPECTRO_INDEX", "index");
define ("REQUESTOUTPUTPLOTSPECTRO_MIN", "min");
define ("REQUESTOUTPUTPLOTSPECTRO_MAX", "max");
define ("REQUESTOUTPUTPLOTSPECTRO_USELOG0ASMIN", "uselog0asmin");
define ("REQUESTOUTPUTPLOTSPECTRO_NORMALISATION", "normalization");
define ("REQUESTOUTPUTPLOTSPECTRO_RESOLUTION", "resolution");

define ("REQUESTOUTPUTPLOTINSTANTSPECTRO_NAME", "ispectro");
define ("REQUESTOUTPUTPLOTINSTANTSPECTRO_XAXIS", "xAxis");
define ("REQUESTOUTPUTPLOTINSTANTSPECTRO_DIMONXAXIS", "dimOnXAxis");

define ("REQUESTOUTPUTPLOTSTATUSBAR_NAME", "serie");
define ("REQUESTOUTPUTPLOTSTATUSBAR_INDEX", "index");

define ("REQUESTOUTPUTPLOTTICKBAR_NAME", "serie");
define ("REQUESTOUTPUTPLOTTICKBAR_INDEX", "index");

define ("REQUESTOUTPUTPLOTINTERVALS_NAME", "intervals");

/**
 * @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 setId($id)
	{
		$this->setAttribute(REQUESTOUTPUTPLOTPARAM_ID,$id);
	}

	public function addYSerie($yAxis, $index, $xId = -1, $colorSerieId = -1, $min = NULL, $max = NULL)
	{
		if ($xId != -1)
		{
			$ySerieNode = new RequestOutputPlotYSerieNodeClass(REQUESTOUTPUTPLOTYSERIE_XYPLOT_NAME);
			$ySerieNode->setXId($xId);
			$ySerieNode->setXAxisId(REQUESTOUTPUTPLOTELEMENTXY_XAXISID);
		}
		else
			$ySerieNode = new RequestOutputPlotYSerieNodeClass(REQUESTOUTPUTPLOTYSERIE_TIMEPLOT_NAME);
		$ySerieNode->setYAxisId($yAxis);
		if (isset($min))
			$ySerieNode->setMin($min);
		if (isset($max))
			$ySerieNode->setMax($max);
		if ($index >= 0)
			$ySerieNode->setIndex($index);
		if ($colorSerieId >= 0)
			$ySerieNode->setColorSerieId($colorSerieId);
		$this->addChild($ySerieNode);
		return $ySerieNode;
	}
	
	public function addOrbitSerie($yAxis, $colorSerieId = -1)
	{
		$orbitSerieNode = new RequestOutputPlotOrbitSerieNodeClass();
		$orbitSerieNode->setXAxisId(REQUESTOUTPUTPLOTELEMENTXY_XAXISID);
		$orbitSerieNode->setYAxisId($yAxis);
		if ($colorSerieId >= 0)
			$orbitSerieNode->setColorSerieId($colorSerieId);
		$this->addChild($orbitSerieNode);
		return $orbitSerieNode;
	}
	
	public function addInstantSerie($yAxis)
	{
		$iserieNode = new RequestOutputPlotInstantSerieNodeClass();
		$iserieNode->setXAxisId(REQUESTOUTPUTPLOTELEMENTXY_XAXISID);
		$iserieNode->setYAxisId($yAxis);
		$this->addChild($iserieNode);
		return $iserieNode;
	}
	
	public function addSpectro($yAxis = "", $resolution="", $index = NULL, $min = NULL, $max = NULL, $uselog0asmin = FALSE, $normalization = NULL)
	{
		$spectroNode = new NodeClass(REQUESTOUTPUTPLOTSPECTRO_NAME);
		$spectroNode->setAttribute(REQUESTOUTPUTPLOTSPECTRO_YAXIS, $yAxis);
		$spectroNode->setAttribute(REQUESTOUTPUTPLOTSPECTRO_USELOG0ASMIN, $uselog0asmin ? "true" : "false");
		if (isset($resolution))
			$spectroNode->setAttribute(REQUESTOUTPUTPLOTSPECTRO_RESOLUTION, $resolution);
		if (isset($normalization))
			$spectroNode->setAttribute(REQUESTOUTPUTPLOTSPECTRO_NORMALISATION, $normalization);
		if (isset($index))
			$spectroNode->setAttribute(REQUESTOUTPUTPLOTSPECTRO_INDEX, $index);
		if (isset($min))
			$spectroNode->setAttribute(REQUESTOUTPUTPLOTSPECTRO_MIN, $min);
		if (isset($max))
			$spectroNode->setAttribute(REQUESTOUTPUTPLOTSPECTRO_MAX, $max);
		$this->addChild($spectroNode);
		return $spectroNode;
	}
	
	public function addInstantSpectro($yAxis, $dimOnXAxis, $index = NULL, $min = NULL, $max = NULL)
	{
		$ispectroNode = new NodeClass(REQUESTOUTPUTPLOTINSTANTSPECTRO_NAME);
		$ispectroNode->setAttribute(REQUESTOUTPUTPLOTINSTANTSPECTRO_XAXIS, REQUESTOUTPUTPLOTELEMENTXY_XAXISID);
		$ispectroNode->setAttribute(REQUESTOUTPUTPLOTSPECTRO_YAXIS, $yAxis);
		$ispectroNode->setAttribute(REQUESTOUTPUTPLOTINSTANTSPECTRO_DIMONXAXIS, $dimOnXAxis);
		
		if (isset($min))
			$ispectroNode->setAttribute(REQUESTOUTPUTPLOTSPECTRO_MIN, $min);
		if (isset($max))
			$ispectroNode->setAttribute(REQUESTOUTPUTPLOTSPECTRO_MAX, $max);
		$this->addChild($ispectroNode);
		return $ispectroNode;
	}

	public function addXSerie($index = -1, $id = 0, $min = NULL, $max = NULL)
	{
		$xSerieNode = new NodeClass(REQUESTOUTPUTPLOTXSERIE_NAME);
		if ($index >= 0)
			$xSerieNode->setAttribute(REQUESTOUTPUTPLOTXSERIE_INDEX, $index);
		$xSerieNode->setAttribute(REQUESTOUTPUTPLOTXSERIE_ID, $id);
		if (isset($min))
			$xSerieNode->setAttribute(REQUESTOUTPUTPLOTXSERIE_MIN, $min);
		if (isset($max))
			$xSerieNode->setAttribute(REQUESTOUTPUTPLOTXSERIE_MAX, $max);
		$this->addChild($xSerieNode);
		return $xSerieNode;
	}
	
	public function addColorSerie($id = "", $index = -1)
	{
		$colorSerieNode = new NodeClass(REQUESTOUTPUTPLOTCOLORSERIE_NAME);
		$colorSerieNode->setAttribute(REQUESTOUTPUTPLOTCOLORSERIE_ID, $id);
		if ($index >= 0)
			$colorSerieNode->setAttribute(REQUESTOUTPUTPLOTCOLORSERIE_INDEX, $index);
		$this->addChild($colorSerieNode);
		return $colorSerieNode;
	}
	
	public function addStatusBar($index)
	{
		$statusBarNode = new NodeClass(REQUESTOUTPUTPLOTSTATUSBAR_NAME);
		if ($index >= 0)
			$statusBarNode->setAttribute(REQUESTOUTPUTPLOTSTATUSBAR_INDEX, $index);
		$this->addChild($statusBarNode);
		return $statusBarNode;
	}
	
	public function addTickBar($index)
	{
		$tickBarNode = new NodeClass(REQUESTOUTPUTPLOTTICKBAR_NAME);
		if ($index >= 0)
			$tickBarNode->setAttribute(REQUESTOUTPUTPLOTTICKBAR_INDEX, $index);
		$this->addChild($tickBarNode);
		return $tickBarNode;
	}

	public function addIntervals()
	{
		$intervalsNode = new NodeClass(REQUESTOUTPUTPLOTINTERVALS_NAME);
		$this->addChild($intervalsNode);
		return $intervalsNode;
	}
	
	public function loadFromNode($xmlNode)
	{
		$this->setId($this->getXmlNodeAttribute($xmlNode, REQUESTOUTPUTPLOTPARAM_ID));
		
		foreach ($this->getXmlNodeChildren($xmlNode) as $plottypeXmlNode) {
			$node = NULL;
			switch ($this->getXmlNodeName($plottypeXmlNode)) {
				case REQUESTOUTPUTPLOTYSERIE_XYPLOT_NAME :
					$node = new RequestOutputPlotYSerieNodeClass(REQUESTOUTPUTPLOTYSERIE_XYPLOT_NAME);
					break;
				case REQUESTOUTPUTPLOTYSERIE_TIMEPLOT_NAME :
					$node = new RequestOutputPlotYSerieNodeClass(REQUESTOUTPUTPLOTYSERIE_TIMEPLOT_NAME);
					break;
				case REQUESTOUTPUTPLOTORBITSERIE_NAME :
					$node = new RequestOutputPlotOrbitSerieNodeClass();
					break;
				case REQUESTOUTPUTPLOTINSTANTSERIE_NAME :
					$node = new RequestOutputPlotInstantSerieNodeClass();
					break;
				case REQUESTOUTPUTPLOTSPECTRO_NAME :
					$yAxis = $this->getXmlNodeAttribute($plottypeXmlNode, REQUESTOUTPUTPLOTSPECTRO_YAXIS);
					$index = $this->getXmlNodeAttribute($plottypeXmlNode, REQUESTOUTPUTPLOTSPECTRO_INDEX);
					$min = $this->getXmlNodeAttribute($plottypeXmlNode, REQUESTOUTPUTPLOTSPECTRO_MIN);
					$max = $this->getXmlNodeAttribute($plottypeXmlNode, REQUESTOUTPUTPLOTSPECTRO_MAX);
					$resolution = $this->getXmlNodeAttribute($plottypeXmlNode, REQUESTOUTPUTPLOTSPECTRO_RESOLUTION);
					$uselog0asmin = $this->getXmlNodeAttribute($plottypeXmlNode, REQUESTOUTPUTPLOTSPECTRO_USELOG0ASMIN) == "true";
					$node = $this->addSpectro($yAxis, $resolution, $index, $min, $max, $uselog0asmin);
					break;
				case REQUESTOUTPUTPLOTXSERIE_NAME :
					$xAxis = $this->getXmlNodeAttribute($plottypeXmlNode, REQUESTOUTPUTPLOTXSERIE_XAXIS);
					$index = $this->getXmlNodeAttribute($plottypeXmlNode, REQUESTOUTPUTPLOTXSERIE_INDEX);
					if (empty($index))
						$index = -1;
					$xId = $this->getXmlNodeAttribute($plottypeXmlNode, REQUESTOUTPUTPLOTXSERIE_XID);
					if (empty($xId))
						$xId = 0;
					$min = $this->getXmlNodeAttribute($plottypeXmlNode, REQUESTOUTPUTPLOTXSERIE_MIN);
					$max = $this->getXmlNodeAttribute($plottypeXmlNode, REQUESTOUTPUTPLOTXSERIE_MAX);
					$node = $this->addXSerie($index, $xId, $min, $max);
					break;
				case REQUESTOUTPUTPLOTCOLORSERIE_NAME :
					$id = $this->getXmlNodeAttribute($plottypeXmlNode, REQUESTOUTPUTPLOTCOLORSERIE_ID);
					$index = $this->getXmlNodeAttribute($plottypeXmlNode, REQUESTOUTPUTPLOTCOLORSERIE_INDEX);
					if (empty($index))
						$index = -1;
					$node = $this->addColorSerie($id, $index);
					break;
				case REQUESTOUTPUTPLOTSTATUSBAR_NAME :
					$index = $this->getXmlNodeAttribute($plottypeXmlNode, REQUESTOUTPUTPLOTSTATUSBAR_INDEX);
					if (empty($index))
						$index = -1;
					$node = $this->addStatusBar($index);
					break;
				case REQUESTOUTPUTPLOTTICKBAR_NAME :
					$index = $this->getXmlNodeAttribute($plottypeXmlNode, REQUESTOUTPUTPLOTTICKBAR_INDEX);
					if (empty($index))
						$index = -1;
					$node = $this->addTickBar($index);
					break;
				default:
					
			}
			
			if (isset($node)) {
				$node->loadFromNode($plottypeXmlNode);
				$this->addChild($node);
			}
		}
	}
}

/**
 * @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;
	}
	
	public function loadFromNode($xmlNode)
	{
		foreach ($this->getXmlNodeChildrenByTagName($xmlNode, REQUESTOUTPUTPLOTPARAM_NAME) as $paramXmlNode) {
			$this->getParamById()->loadFromNode($paramXmlNode);
		}
	}
}

?>