#include "pch.h"
#include "MxHead.h"
#include "MxOptLineTypeTable.h"
#include "MxWriteContext.h"
#include "DxfLib\dl_writer_ascii.h"
#include "DxfLib\dl_entities.h"
#include "DxfLib\dl_dxf.h"
#include "Tool.h"

MxOptLineTypeTable::MxOptLineTypeTable(MxWriteContext*  pContext)
	: m_pWriteContext(pContext)
{

}

MxOptLineTypeTable::~MxOptLineTypeTable(void)
{
}

bool MxOptLineTypeTable::Mx2Dxf(DL_WriterA* dw)
{

	if(m_pWriteContext == NULL)
	{
		ASSERT(0);
		return false;
	}

	int iNum = 1;
	McDbLinetypeTablePointer spMxTab(m_pWriteContext->GetDatabase(),McDb::kForRead);
	ASSERT(spMxTab.openStatus() == Mcad::eOk);

	McDbLinetypeTableIterator* pIter = NULL;
	spMxTab->newIterator(pIter);
	std::auto_ptr<McDbLinetypeTableIterator> spIter(pIter);
	ASSERT(pIter != NULL);

	for(iNum = 0;!pIter->done();pIter->step(),iNum++ );

	dw->tableLineTypes(iNum);
	
	
	pIter->start();
	for (; !pIter->done(); pIter->step()) 
	{
		McDbObjectId mxRecId;
		pIter->getRecordId(mxRecId);

		McDbObjectPointer<McDbLinetypeTableRecord> spMxRec(mxRecId,McDb::kForRead);
		ASSERT(spMxRec.openStatus() == Mcad::eOk);

		LPCTSTR pszName = NULL;
		spMxRec->getName(pszName);

		m_pWriteContext->GetDxf()->writeLineType(
			*dw,
			DL_LineTypeData(MXDXF_W2A(pszName), 0));
	}
	dw->tableEnd();

	return true;
}