RequestOutputPlotCurveObjectNodeClass.php 3.73 KB
<?php

define ("REQUESTOUTPUTPLOTCURVEOBJECT_NAME", "curvePlot");
define ("REQUESTOUTPUTPLOTCURVEOBJECT_SERIEID", "serieId");

define ("REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_NAME", "function");
define ("REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_FUNCTIONNAME", "name");
define ("REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_ATTRIBUTES", "attributes");
define ("REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_ATTRIBUTE", "attribute");
define ("REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_ATTRIBUTENAME", "name");
define ("REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_ATTRIBUTEVALUE", "value");

/**
 * @class RequestOutputPlotCurveObjectFunctionNodeClass
 * @brief Definition of a function for a curve object element of a plot
 * @details
 */
class RequestOutputPlotCurveObjectFunctionNodeClass extends NodeClass
{
	public function __construct()
	{
		parent::__construct(REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_NAME);
	}
	
	public function setFunctionName($name)
	{
		$this->setAttribute(REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_FUNCTIONNAME, $name);
	}
	
	public function getFunctionName()
	{
		return $this->getAttribute(REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_FUNCTIONNAME);
	}
	
	public function getAttributes()
	{
		$node = $this->getFirstChildByName(REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_ATTRIBUTES);
	
		if (!isset($node))
		{
			$node = new NodeClass(REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_ATTRIBUTES);
			$this->addChild($node);
		}
	
		return $node;
	}
	
	public function addAttribute($name, $value)
	{
		$attributesNode = $this->getAttributes();
		
		$node = new NodeClass(REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_ATTRIBUTE);
		
		$node->setAttribute(REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_ATTRIBUTENAME, $name);
		$node->setAttribute(REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_ATTRIBUTEVALUE, $value);
		
		$attributesNode->addChild($node);
		return $node;
	}
	
	public function loadFromNode($xmlNode)
	{
		$this->setFunctionName($this->getXmlNodeAttribute($xmlNode, REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_FUNCTIONNAME));
		
		$attributesXmlNode = $this->getXmlNodeChildByTagName($xmlNode, REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_ATTRIBUTES);
		if (isset($attributesXmlNode)) {
			foreach ($this->getXmlNodeChildrenByTagName($attributesXmlNode, REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_ATTRIBUTE) as $attributeXmlNode) {
				$this->addAttribute($this->getXmlNodeAttribute($attributeXmlNode, REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_ATTRIBUTENAME),$this->getXmlNodeAttribute($attributeXmlNode, REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_ATTRIBUTEVALUE));
			}	
		}
	}
}

/**
 * @class RequestOutputPlotCurveObjectNodeClass
 * @brief Definition of a curve object element for a plot
 * @details
 */
class RequestOutputPlotCurveObjectNodeClass extends RequestOutputPlotCurveNodeClass
{
	public function __construct()
	{
		parent::__construct(REQUESTOUTPUTPLOTCURVEOBJECT_NAME);
	}
	
	public function setSerieId($serieId)
	{
		$this->setAttribute(REQUESTOUTPUTPLOTCURVEOBJECT_SERIEID, $serieId);
	}
	
	public function getSerieId()
	{
		return $this->getAttribute(REQUESTOUTPUTPLOTCURVEOBJECT_SERIEID);
	}
	
	public function isFunctionDefined()
	{
		$node = $this->getFirstChildByName(REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_NAME);
		return isset($node);
	}
	
	public function getFunction()
	{
		$node = $this->getFirstChildByName(REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_NAME);
	
		if (!isset($node))
		{
			$node = new RequestOutputPlotCurveObjectFunctionNodeClass();
			$this->addChild($node);
		}
	
		return $node;
	}
	
	public function loadFromNode($xmlNode)
	{
		$this->setSerieId($this->getXmlNodeAttribute($xmlNode, REQUESTOUTPUTPLOTCURVEOBJECT_SERIEID));
		
		$functionXmlNode = $this->getXmlNodeChildByTagName($xmlNode, REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_NAME);
		if (isset($functionXmlNode))
			$this->getFunction()->loadFromNode($functionXmlNode);
		parent::loadFromNode($xmlNode);
	}
}

?>