#include "xmlmodel.h"

// ----------------------------------------------------------------------------
CXmlModel::CXmlModel(CXmlUi* pXmlUi, CXmlLayout* pParent)
	: CXmlFrame(pXmlUi, pParent)
{
	m_type				= eXmlUiType_Model;

	m_file.clear();
	m_scale				= 1.0f;
	m_fogNear			= 0.0f;
	m_fogFar			= 1.0f;
}

// ----------------------------------------------------------------------------
CXmlModel::~CXmlModel()
{
}

// ----------------------------------------------------------------------------
void CXmlModel::LoadNodeAttribute(const DOMNamedNodeMap* nodeMap)
{
	CXmlFrame::LoadNodeAttribute(nodeMap);

	const XMLCh* nodeValue;
	if ( (nodeValue = GetNodeAttribute(nodeMap, "file")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_file = tmpStr;
		XMLString::release(&tmpStr);
	}
	if ( (nodeValue = GetNodeAttribute(nodeMap, "scale")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_scale = (float)atof(tmpStr);
		XMLString::release(&tmpStr);
	}
	if ( (nodeValue = GetNodeAttribute(nodeMap, "fogNear")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_fogNear = (float)atof(tmpStr);
		XMLString::release(&tmpStr);
	}
	if ( (nodeValue = GetNodeAttribute(nodeMap, "fogFar")) != NULL )
	{
		char* tmpStr = XMLString::transcode(nodeValue);
		m_fogFar = (float)atof(tmpStr);
		XMLString::release(&tmpStr);
	}
}

// ----------------------------------------------------------------------------
void CXmlModel::LoadNodeElement(const DOMNode* node, const char* nodeName)
{
	CXmlFrame::LoadNodeElement(node, nodeName);

	// FontString
	if ( XMLString::compareString(nodeName, "FogColor") == 0 )
	{
		m_fogColor.LoadFromDOMNode(node);
	}
}

// ----------------------------------------------------------------------------
void CXmlModel::Inherit(CXmlLayout* pXmlLayout)
{
	CXmlFrame::Inherit(pXmlLayout);
	CXmlModel* pXmlModel = dynamic_cast<CXmlModel*>(pXmlLayout);
	if (pXmlModel)
	{
		m_file		= pXmlModel->m_file;
		m_fogColor	= pXmlModel->m_fogColor;
		m_scale		= pXmlModel->m_scale;
		m_fogNear	= pXmlModel->m_fogNear;
		m_fogFar	= pXmlModel->m_fogFar;
	}
}