Click here to Skip to main content
15,897,704 members
Articles / Desktop Programming / MFC

Simple DXF Reader/Viewer with Spline Support

Rate me:
Please Sign up or sign in to vote.
5.00/5 (15 votes)
13 Sep 2013CPOL2 min read 80.2K   9K   27  
Simple DXF reader and viewer supporting the most common AutoCAD entities
// DXFNesterDoc.cpp : implementation of the CDXFNesterDoc class
//

#include "stdafx.h"
#include "DXFNester.h"

#include "DXFNesterDoc.h"
#include "dxf.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CDxf m_dxf;

/////////////////////////////////////////////////////////////////////////////
// CDXFNesterDoc

IMPLEMENT_DYNCREATE(CDXFNesterDoc, CDocument)

BEGIN_MESSAGE_MAP(CDXFNesterDoc, CDocument)
	//{{AFX_MSG_MAP(CDXFNesterDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDXFNesterDoc construction/destruction

CDXFNesterDoc::CDXFNesterDoc()
{
	// TODO: add one-time construction code here

}

CDXFNesterDoc::~CDXFNesterDoc()
{
}

BOOL CDXFNesterDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CDXFNesterDoc serialization

void CDXFNesterDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
		CString str = ar.m_strFileName;
	}
	else
	{
		// TODO: add loading code here
		CString str = ar.m_strFileName;

		if
		(
			str.GetAt(str.GetLength()-3) == 'd' &&
			str.GetAt(str.GetLength()-2) == 'x' &&
			str.GetAt(str.GetLength()-1) == 'f'
		)
		{
			//File type is DXF.
			m_dxf.Init();
			m_dxf.LoadFile(str);
			scale = 100;
			x_offset = 0;
			y_offset = 0;
			m_dxf.m_InitialDraw = FALSE;
		}
		else
		{
			//File type is not DXF.
			MessageBox(NULL,"This is not a DXF file!","File Type Error!",MB_ICONERROR);
		}
	}
}

/////////////////////////////////////////////////////////////////////////////
// CDXFNesterDoc diagnostics

#ifdef _DEBUG
void CDXFNesterDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CDXFNesterDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDXFNesterDoc commands

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Turkey Turkey
I am an electronics engineer who loves to code on embedded, desktop and web application development.

Comments and Discussions