#include "pch.h"
#include "MxHead.h"
#include "MxLineTypeData.h"

MxLineTypeData MxLineTypeData::s_instance;

MxLineTypeData::MxLineTypeData(void)
{
}

MxLineTypeData::~MxLineTypeData(void)
{
	// 释放内存。
	std::map<MxString,stuLineType*>::iterator iter 
		= m_mapLineTypeData.begin();

	for(;iter != m_mapLineTypeData.end();++iter)
	{
		delete iter->second;
	}
	m_mapLineTypeData.clear();


}

MxLineTypeData&		
MxLineTypeData::Instance()
{
	return s_instance;
}


McDbLinetypeTableRecord* 
MxLineTypeData::CreateLineTypeRecord(MxString sName) const
{
	if(sName.IsEmpty() )
		return NULL;

	sName.MakeUpper();

	std::map<MxString,stuLineType*>::const_iterator iter 
		= m_mapLineTypeData.find(sName);

	if(iter == m_mapLineTypeData.end())
		return NULL;

	stuLineType* pData = iter->second;

	McDbLinetypeTableRecord* pNew = new McDbLinetypeTableRecord;
	pNew->setName(sName);
	pNew->setComments(pData->sDescription);

	pNew->setNumDashes((int)pData->data.size() );

	for(UINT i = 0; i < pData->data.size();i++)
	{
		stuLineTypeData& lineData = (pData->data)[i];
		if(lineData.iType == 0)
		{
			pNew->setDashLengthAt(i,lineData.dDashLength);
		}
		else
		{
			// 暂不支持复杂线型。用空格-1.0代替。
			pNew->setDashLengthAt(i,-1.0);
		}
	}
	return pNew;
}

void MxLineTypeData::Init()
{
	// ACAD_ISO02W100
	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("ISO Dashed __ __ __ __ __ __ __ __ __ __ _");

		pLineType->AddDashLength(12.0);
		pLineType->AddDashLength(-3.0);

		m_mapLineTypeData.insert(std::make_pair(_T("ACAD_ISO02W100"),pLineType));
	}

	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("ISO Dashed with Distance __    __    __    _");

		pLineType->AddDashLength(12.0);
		pLineType->AddDashLength(-18.0);

		m_mapLineTypeData.insert(std::make_pair(_T("ACAD_ISO03W100"),pLineType));
	}


	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("ISO Long Dashed Dotted ____ . ____ . __");

		pLineType->AddDashLength(24.0);
		pLineType->AddDashLength(-3.0);

		pLineType->AddDashLength(0.0);
		pLineType->AddDashLength(-3.0);

		m_mapLineTypeData.insert(std::make_pair(_T("ACAD_ISO04W100"),pLineType));
	}

	 
	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("ISO Long Dashed Double Dotted ____ .. __");
		pLineType->AddDashLength(24.0);

		pLineType->AddDashLength(-3.0);

		pLineType->AddDashLength(0.0);

		pLineType->AddDashLength(-3.0);

		pLineType->AddDashLength(0.0);

		pLineType->AddDashLength(-3.0);
		m_mapLineTypeData.insert(std::make_pair(_T("ACAD_ISO05W100"),pLineType));
	}

	

	{

		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("Border __ __ . __ __ . __ __ . __ __ . __ __ .");

		pLineType->AddDashLength(12.7);

		pLineType->AddDashLength(-6.35);

		pLineType->AddDashLength(12.7);

		pLineType->AddDashLength(-6.35);

		pLineType->AddDashLength(0.0);

		pLineType->AddDashLength(-6.35);
	
		m_mapLineTypeData.insert(std::make_pair(_T("BORDER"),pLineType));
	}
	
	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("Border (.5x) __.__.__.__.__.__.__.__.__.__.__.");

		pLineType->AddDashLength(6.35);

		pLineType->AddDashLength(-3.175);

		pLineType->AddDashLength(6.35);

		pLineType->AddDashLength(-3.175);

		pLineType->AddDashLength(0.0);

		pLineType->AddDashLength(-3.175);

		m_mapLineTypeData.insert(std::make_pair(_T("BORDER2"),pLineType));
	}

	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("Border (2x) ____  ____  .  ____  ____  .  ___");

		pLineType->AddDashLength(25.4);

		pLineType->AddDashLength(-12.7);

		pLineType->AddDashLength(25.4);

		pLineType->AddDashLength(-12.7);

		pLineType->AddDashLength(0.0);

		pLineType->AddDashLength(-12.7);

		m_mapLineTypeData.insert(std::make_pair(_T("BORDERX2"),pLineType));
	} 

	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("Center ____ _ ____ _ ____ _ ____ _ ____ _ ____");

		pLineType->AddDashLength(31.75);

		pLineType->AddDashLength(-6.35);

		pLineType->AddDashLength(6.35);

		pLineType->AddDashLength(-6.35);

		m_mapLineTypeData.insert(std::make_pair(_T("CENTER"),pLineType));
	}

	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("Center (.5x) ___ _ ___ _ ___ _ ___ _ ___ _ ___");

		pLineType->AddDashLength(19.05);

		pLineType->AddDashLength(-3.175);

		pLineType->AddDashLength(3.175);

		pLineType->AddDashLength(-3.175);

		m_mapLineTypeData.insert(std::make_pair(_T("CENTER2"),pLineType));
	}

	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("Center (2x) ________  __  ________  __  _____");
		pLineType->AddDashLength(63.5);

		pLineType->AddDashLength(-12.7);

		pLineType->AddDashLength(12.7);

		pLineType->AddDashLength(-12.7);

		m_mapLineTypeData.insert(std::make_pair(_T("CENTERX2"),pLineType));
	}


	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("Dash dot __ . __ . __ . __ . __ . __ . __ . __");
		//
		pLineType->AddDashLength(12.7);

		pLineType->AddDashLength(-6.35);

		pLineType->AddDashLength(0.0);

		pLineType->AddDashLength(-6.35);

		m_mapLineTypeData.insert(std::make_pair(_T("DASHDOT"),pLineType));
	}

	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("Dash dot (.5x) _._._._._._._._._._._._._._._.");		
		pLineType->AddDashLength(6.35);

		pLineType->AddDashLength(-3.175);

		pLineType->AddDashLength(0.0);

		pLineType->AddDashLength(-3.175);
		m_mapLineTypeData.insert(std::make_pair(_T("DASHDOT2"),pLineType));
	}

	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("Dash dot (2x) ____  .  ____  .  ____  .  ___");

		pLineType->AddDashLength(25.4);

		pLineType->AddDashLength(-12.7);

		pLineType->AddDashLength(0.0);

		pLineType->AddDashLength(-12.7);

		m_mapLineTypeData.insert(std::make_pair(_T("DASHDOTX2"),pLineType));
	}


	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("Dashed __ __ __ __ __ __ __ __ __ __ __ __ __ _");

		pLineType->AddDashLength(12.7);

		pLineType->AddDashLength(-6.35);

		m_mapLineTypeData.insert(std::make_pair(_T("DASHED"),pLineType));
	}


	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("Dashed (.5x) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _");

		//		
		pLineType->AddDashLength(6.35);

		pLineType->AddDashLength(-3.175);

		m_mapLineTypeData.insert(std::make_pair(_T("DASHED2"),pLineType));
	}


	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("Dashed (2x) ____  ____  ____  ____  ____  ___");

		pLineType->AddDashLength(25.4);

		pLineType->AddDashLength(-12.7);

		m_mapLineTypeData.insert(std::make_pair(_T("DASHEDX2"),pLineType));
	}

	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("Divide ____ . . ____ . . ____ . . ____ . . ____");
		//
		pLineType->AddDashLength(12.7);

		pLineType->AddDashLength(-6.35);

		pLineType->AddDashLength(0.0);

		pLineType->AddDashLength(-6.35);

		pLineType->AddDashLength(0.0);

		pLineType->AddDashLength(-6.35);

		m_mapLineTypeData.insert(std::make_pair(_T("DIVIDE"),pLineType));
	}

	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("Divide (.5x) __..__..__..__..__..__..__..__.._");

		//
		pLineType->AddDashLength(6.35);


		pLineType->AddDashLength(-3.175);


		pLineType->AddDashLength(0.0);


		pLineType->AddDashLength(-3.175);


		pLineType->AddDashLength(0.0);


		pLineType->AddDashLength(-3.175);

		m_mapLineTypeData.insert(std::make_pair(_T("DIVIDE2"),pLineType));
	}


	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("Divide (2x) ________  .  .  ________  .  .  _");
		//
		pLineType->AddDashLength(25.4);

		pLineType->AddDashLength(-12.7);

		pLineType->AddDashLength(0.0);

		pLineType->AddDashLength(-12.7);

		pLineType->AddDashLength(0.0);

		pLineType->AddDashLength(-12.7);

		m_mapLineTypeData.insert(std::make_pair(_T("DIVIDEX2"),pLineType));
	}

	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("Dot . . . . . . . . . . . . . . . . . . . . . .");

		//
		pLineType->AddDashLength(0.0);

		pLineType->AddDashLength(-6.35);

		m_mapLineTypeData.insert(std::make_pair(_T("DOT"),pLineType));
	}

	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("Dot (.5x) .....................................");

		pLineType->AddDashLength(0.0);
			 
		pLineType->AddDashLength(-3.175);

		m_mapLineTypeData.insert(std::make_pair(_T("DOT2"),pLineType));
	}

	{
		stuLineType* pLineType = new stuLineType;
		pLineType->sDescription = _T("Dot (2x) .  .  .  .  .  .  .  .  .  .  .  .  .");

		//
		pLineType->AddDashLength(0.0);

		pLineType->AddDashLength(-12.7);

		m_mapLineTypeData.insert(std::make_pair(_T("DOTX2"),pLineType));
	}
}