RequestOutputPlotParamsNodeClass.php 8.53 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_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 ("REQUESTOUTPUTPLOTSTATUSBAR_NAME", "serie");
define ("REQUESTOUTPUTPLOTSTATUSBAR_INDEX", "index");

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

/**
 * @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, $xAxis = "", $colorSerieId = -1, $min = NULL, $max = NULL)
	{
		if ($xAxis != "")
		{
			$ySerieNode = new RequestOutputPlotYSerieNodeClass(REQUESTOUTPUTPLOTYSERIE_XYPLOT_NAME);
			$ySerieNode->setXAxisId($xAxis);
		}
		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, $xAxis, $colorSerieId = -1)
	{
		$orbitSerieNode = new RequestOutputPlotOrbitSerieNodeClass();
		$orbitSerieNode->setYAxisId($yAxis);
		$orbitSerieNode->setXAxisId($xAxis);
		if ($colorSerieId >= 0)
			$orbitSerieNode->setColorSerieId($colorSerieId);
		$this->addChild($orbitSerieNode);
		return $orbitSerieNode;
	}
	
	public function addInstantSerie($xAxis, $yAxis)
	{
		$iserieNode = new RequestOutputPlotInstantSerieNodeClass();
		$iserieNode->setXAxisId($xAxis);
		$iserieNode->setYAxisId($yAxis);
		$this->addChild($iserieNode);
		return $iserieNode;
	}
	
	public function addSpectro($yAxis = "", $index = NULL, $min = NULL, $max = NULL)
	{
		$spectroNode = new NodeClass(REQUESTOUTPUTPLOTSPECTRO_NAME);
		$spectroNode->setAttribute(REQUESTOUTPUTPLOTSPECTRO_YAXIS, $yAxis);
		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 addXSerie($xAxis = "", $index = -1, $min = NULL, $max = NULL)
	{
		$xSerieNode = new NodeClass(REQUESTOUTPUTPLOTXSERIE_NAME);
		$xSerieNode->setAttribute(REQUESTOUTPUTPLOTXSERIE_XAXIS, $xAxis);
		if ($index >= 0)
			$xSerieNode->setAttribute(REQUESTOUTPUTPLOTXSERIE_INDEX, $index);
		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 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);
					$node = $this->addSpectro($yAxis, $index, $min, $max);
					break;
				case REQUESTOUTPUTPLOTXSERIE_NAME :
					$xAxis = $this->getXmlNodeAttribute($plottypeXmlNode, REQUESTOUTPUTPLOTXSERIE_XAXIS);
					$index = $this->getXmlNodeAttribute($plottypeXmlNode, REQUESTOUTPUTPLOTXSERIE_INDEX);
					if (empty($index))
						$index = -1;
					$min = $this->getXmlNodeAttribute($plottypeXmlNode, REQUESTOUTPUTPLOTXSERIE_MIN);
					$max = $this->getXmlNodeAttribute($plottypeXmlNode, REQUESTOUTPUTPLOTXSERIE_MAX);
					$node = $this->addXSerie($xAxis, $index, $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);
		}
	}
}

?>