/*
 * $Id: LODnode.h 672 2009-01-16 08:34:17Z misek $
 *
 * Description  : One line description of file.
 * Author       : Antonin Misek <antonin.misek@skoda-auto.cz>
 *
 * Purpose      :
 *     Long description of what the file is for.
 */


#ifndef __LODNODE__H__
#define __LODNODE__H__

#include "scenenode.h"
//#include "moddefs.h"

namespace VRUT
{
	///\c SceneNode of type Level Of Detail
	class LODNode : public SceneNode
	{
	private:
		///Hash map for storing distances
		WX_DECLARE_HASH_MAP( NODE_ID, float, wxIntegerHash, wxIntegerEqual, LODToDistance);
	protected:
		///distances (used for switching)
		LODToDistance distances;

	public:
		static const SCENENODE_TYPE ClassType = LOD;

		///Class constructor, \c LOD type by default
		LODNode(const wxString & _name) : SceneNode(_name, ClassType)
		{
		}

		///Copy constructor
		LODNode(const LODNode & lod) : SceneNode(lod)
		{
			for (LODToDistance::const_iterator it=lod.distances.begin(); it!=lod.distances.end(); it++)
				distances.insert(*it);
		}

		///Class destructor
		virtual ~LODNode()
		{
		}

		///Set distance for given LOD
		void SetDistance(NODE_ID LODId, float distance)
		{
			if (LODId != NODE_ID_NONE)
				//distances.insert(LODToDistance::value_type(LODId, distance));
				distances[LODId]=distance;
		}

		///Get LOD distance
		float GetDistance(NODE_ID LODId) const
		{
			LODToDistance::const_iterator mapIt = distances.find(LODId);
			return ( mapIt == distances.end() ? 0 : mapIt->second );
		}

		///Remove LOD distance
		void RemoveDistance(NODE_ID LODId)
		{
			distances.erase(LODId);
		}

		///Get string with node's properties - \c SceneNode overload
		virtual wxString ToString() const
		{
			wxString dists, separator;
			for (auto &distance : distances)
			{
				dists+=separator+TextWriter::WriteToWxString(distance.second);
				separator=wxT(", ");
			}
			return SceneNode::ToString()+wxString::Format(wxT("\nLOD distances count: %lu ("), (unsigned long)distances.size())+dists+wxT(")\n");
		}

		///Get copy of instance - \c SceneNode overload
		virtual SceneNode * Clone() const
		{
			return new LODNode(*this);
		}

		friend class Scene;
	};
}

#endif
