InfoParamNodeClass.php 8.33 KB
<?php

require_once("InfoParamTableDefBoundsNodeClass.php");
require_once("InfoParamTableDefCenterNodeClass.php");
require_once("InfoParamTableDefCenterWidthNodeClass.php");
require_once("InfoParamTableDefMinMaxNodeClass.php");

define ("INFOPARAM_TAGNAME", "info");
define ("INFOPARAM_NAME", "name");
define ("INFOPARAM_SHORTNAME", "short_name");
define ("INFOPARAM_COMPONENTS", "components");
define ("INFOPARAM_UNITS", "units");
define ("INFOPARAM_COORDSYS", "coordinates_system");
define ("INFOPARAM_TENSORORDER", "tensor_order");
define ("INFOPARAM_SICONV", "si_conversion");
define ("INFOPARAM_TABLE", "table");
define ("INFOPARAM_FILLVAL", "fill_value");
define ("INFOPARAM_UCD", "ucd");
define ("INFOPARAM_STATUSDEF", "status_def");
define ("INFOPARAM_STATUS", "status");
define ("INFOPARAM_STATUS_MINVAL", "minVal");
define ("INFOPARAM_STATUS_MAXVAL", "maxVal");
define ("INFOPARAM_STATUS_NAME", "name");
define ("INFOPARAM_STATUS_COLOR", "color");
define ("INFOPARAM_DATASETID", "dataset_id");

/**
 * 
 */
abstract class InfoParamTableTypeEnum
{
	const BOUNDS      = "Bounds";
	const MINMAX      = "MinMax";
	const CENTER      = "Center";
	const CENTERWIDTH = "CenterWidth";
}

/**
 * @class InfoParamNodeClass
 * @brief Definition of information about a parameter
 * @details
 */
class InfoParamNodeClass extends NodeClass
{
	public function __construct()
	{
		parent::__construct(INFOPARAM_TAGNAME);
		
		$this->getChildInstanceByName(INFOPARAM_NAME,true);
		$this->getChildInstanceByName(INFOPARAM_SHORTNAME,true);
		$this->getChildInstanceByName(INFOPARAM_COMPONENTS,true);
		$this->getChildInstanceByName(INFOPARAM_UNITS,true);
		$this->getChildInstanceByName(INFOPARAM_COORDSYS,true);
		$this->getChildInstanceByName(INFOPARAM_TENSORORDER,true);
		$this->getChildInstanceByName(INFOPARAM_SICONV,true);
		$this->getChildInstanceByName(INFOPARAM_TABLE,true);
		$this->getChildInstanceByName(INFOPARAM_FILLVAL,true);
		$this->getChildInstanceByName(INFOPARAM_UCD,true);
		$this->getChildInstanceByName(INFOPARAM_STATUSDEF,true);
		$this->getChildInstanceByName(INFOPARAM_DATASETID,true);
	}

	public function setName($name)
	{
		$node = $this->getChildInstanceByName(INFOPARAM_NAME,true);
		$node->setValue($name);
	}
	
	public function setShortName($short_name)
	{
		$node = $this->getChildInstanceByName(INFOPARAM_SHORTNAME,true);
		$node->setValue($short_name);
	}
	
	public function setComponents($components)
	{
		$node = $this->getChildInstanceByName(INFOPARAM_COMPONENTS,true);
		$node->setValue($components);
	}
	
	public function setUnits($units)
	{
		$node = $this->getChildInstanceByName(INFOPARAM_UNITS,true);
		$node->setValue($units);
	}
	
	public function setCoordSyst($coord_sys)
	{
		$node = $this->getChildInstanceByName(INFOPARAM_COORDSYS,true);
		$node->setValue($coord_sys);
	}
	
	public function setTensorOrder($tensor_order)
	{
		$node = $this->getChildInstanceByName(INFOPARAM_TENSORORDER,true);
		$node->setValue($tensor_order);
	}
	
	public function setSIConv($si_conv)
	{
		$node = $this->getChildInstanceByName(INFOPARAM_SICONV,true);
		$node->setValue($si_conv);
	}
	
	public function setFillVal($fill)
	{
		$node = $this->getChildInstanceByName(INFOPARAM_FILLVAL,true);
		$node->setValue($fill);
	}
	
	public function setUCD($ucd)
	{
		$node = $this->getChildInstanceByName(INFOPARAM_UCD,true);
		$node->setValue($ucd);
	}
	
	public function setDatasetID($dataset_id)
	{
		$node = $this->getChildInstanceByName(INFOPARAM_DATASETID,true);
		$node->setValue($dataset_id);
	}
	
	public function addTable($type, $name)
	{
		$node = $this->getTable();
		
		switch ($type)
		{
			case InfoParamTableTypeEnum::BOUNDS :
				$tableDef = new InfoParamTableDefBoundsNodeClass();
				break;
			case InfoParamTableTypeEnum::MINMAX :
				$tableDef = new InfoParamTableDefMinMaxNodeClass();
				break;
			case InfoParamTableTypeEnum::CENTER :
				$tableDef = new InfoParamTableDefCenterNodeClass();
				break;
			case InfoParamTableTypeEnum::CENTERWIDTH :
				$tableDef = new InfoParamTableDefCenterWidthNodeClass();
				break;
			default :
				//throw new Exception('Table definition node not implemented');
		}
		
		$tableDef->setTableName($name);
		
		$node->addChild($tableDef);
		
		return $tableDef;
	}
	
	public function getTable()
	{
		return $this->getChildInstanceByName(INFOPARAM_TABLE, true);
	}

	public function getStatusDef()
	{
		return $this->getChildInstanceByName(INFOPARAM_STATUSDEF, true);
	}

	public function addStatus($min, $max, $name, $color = "")
	{
		$node = $this->getStatusDef();

		$statusNode = new NodeClass(INFOPARAM_STATUS);
		$statusNode->setAttribute(INFOPARAM_STATUS_MINVAL, $min);
		$statusNode->setAttribute(INFOPARAM_STATUS_MAXVAL, $max);
		$statusNode->setAttribute(INFOPARAM_STATUS_NAME, $name);
		if (!empty($color)) {
			$statusNode->setAttribute(INFOPARAM_STATUS_COLOR, $color);
		}

		$node->addChild($statusNode);

		return $statusNode;
	}
	
	public function loadFromNode($xmlNode)
	{
		$nameXmlNode = $this->getXmlNodeChildByTagName($xmlNode, INFOPARAM_NAME);
		if (isset($nameXmlNode))
			$this->setName($this->getXmlNodeValue($nameXmlNode));
		
		$shortnameXmlNode = $this->getXmlNodeChildByTagName($xmlNode, INFOPARAM_SHORTNAME);
		if (isset($shortnameXmlNode))
			$this->setShortName($this->getXmlNodeValue($shortnameXmlNode));
		
		$componentsXmlNode = $this->getXmlNodeChildByTagName($xmlNode, INFOPARAM_COMPONENTS);
		if (isset($componentsXmlNode))
			$this->setComponents($this->getXmlNodeValue($componentsXmlNode));
		
		$unitsXmlNode = $this->getXmlNodeChildByTagName($xmlNode, INFOPARAM_UNITS);
		if (isset($unitsXmlNode))
			$this->setUnits($this->getXmlNodeValue($unitsXmlNode));
		
		$coordsysXmlNode = $this->getXmlNodeChildByTagName($xmlNode, INFOPARAM_COORDSYS);
		if (isset($coordsysXmlNode))
			$this->setCoordSyst($this->getXmlNodeValue($coordsysXmlNode));
		
		$tensororderXmlNode = $this->getXmlNodeChildByTagName($xmlNode, INFOPARAM_TENSORORDER);
		if (isset($tensororderXmlNode))
			$this->setTensorOrder($this->getXmlNodeValue($tensororderXmlNode));
		
		$siconvXmlNode = $this->getXmlNodeChildByTagName($xmlNode, INFOPARAM_SICONV);
		if (isset($siconvXmlNode))
			$this->setSIConv($this->getXmlNodeValue($siconvXmlNode));
		
		$tableXmlNode = $this->getXmlNodeChildByTagName($xmlNode, INFOPARAM_TABLE);
		if (isset($tableXmlNode)) {
			foreach ($this->getXmlNodeChildren($tableXmlNode) as $tableDefXmlNode) {
				switch ($this->getXmlNodeName($tableDefXmlNode)) {
					case INFOPARAMTABLEDEFBOUNDS_TAGNAME :
						$this->addTable(InfoParamTableTypeEnum::BOUNDS, "")->loadFromNode($tableDefXmlNode);
						break;
					case INFOPARAMTABLEDEFCENTER_TAGNAME :
						$this->addTable(InfoParamTableTypeEnum::CENTER, "")->loadFromNode($tableDefXmlNode);
						break;
					case INFOPARAMTABLEDEFCENTERWIDTH_TAGNAME :
						$this->addTable(InfoParamTableTypeEnum::CENTERWIDTH, "")->loadFromNode($tableDefXmlNode);
						break;
					case INFOPARAMTABLEDEFMINMAX_TAGNAME :
						$this->addTable(InfoParamTableTypeEnum::MINMAX, "")->loadFromNode($tableDefXmlNode);
						break;
					default :
						//throw new Exception('Table definition node not implemented');
				}
			}
		}
		
		$fillvalXmlNode = $this->getXmlNodeChildByTagName($xmlNode, INFOPARAM_FILLVAL);
		if (isset($fillvalXmlNode))
			$this->setFillVal($this->getXmlNodeValue($fillvalXmlNode));
		
		$ucdXmlNode = $this->getXmlNodeChildByTagName($xmlNode, INFOPARAM_UCD);
		if (isset($ucdXmlNode))
			$this->setUCD($this->getXmlNodeValue($ucdXmlNode));

		$statusDefXmlNode = $this->getXmlNodeChildByTagName($xmlNode, INFOPARAM_STATUSDEF);
		if (isset($statusDefXmlNode)) {
			foreach ($this->getXmlNodeChildren($statusDefXmlNode) as $statusNode) {
				$minVal = $this->getXmlNodeAttribute($statusNode, INFOPARAM_STATUS_MINVAL);
				$maxVal = $this->getXmlNodeAttribute($statusNode, INFOPARAM_STATUS_MAXVAL);
				$name = $this->getXmlNodeAttribute($statusNode, INFOPARAM_STATUS_NAME);
				$color = $this->getXmlNodeAttribute($statusNode, INFOPARAM_STATUS_COLOR);
				$this->addStatus($minVal, $maxVal, $name, $color);
			}
		}
		
		$datasetidXmlNode = $this->getXmlNodeChildByTagName($xmlNode, INFOPARAM_DATASETID);
		if (isset($datasetidXmlNode))
			$this->setDatasetID($this->getXmlNodeValue($datasetidXmlNode));
	}
}

?>