DXF图元文件提取与显示(二)-Line

#pragma once
#include "dxfmeta.h"
class DXFLine :
	public DXFMeta
{
	
public:
	
	explicit DXFLine(UINT rCount,UINT seekBytes);
	virtual ~DXFLine(void);

	virtual string OutputFormat();
	
	void SetLine(Point& s,Point& e);

	friend	ostream& operator<<(ostream& os,const DXFLine& metaLine);		//数据输出的友元函数
	friend	istream& operator>>(istream& is,DXFLine& metaLine);				//数据输入的友元函数

	virtual void Draw( HDC& dc );

private:
	DXFMeta::Point start;		//开始点坐标
	DXFMeta::Point end;			//结束点坐标
};
#include "StdAfx.h"
#include "DXFLine.h"
#include <stdlib.h>


//************************************
// 根据DXF文件的读写的行号和偏移字符数,构建直线对象
// Method:    DXFLine
// FullName:  DXFLine::DXFLine
// Access:    public 
// Returns:   
// Qualifier: :DXFMeta(rCount,seekBytes)
// Parameter: UINT rCount
// Parameter: UINT seekBytes
// Author:zhengzhe 2011-11-21
//************************************
DXFLine::DXFLine(UINT rCount,UINT seekBytes):DXFMeta(rCount,seekBytes)
{
	type = LINE;
}


DXFLine::~DXFLine(void)
{
}




//************************************
// 直线的DXF输出格式
// Method:    OutputFormat
// FullName:  DXFLine::OutputFormat
// Access:    virtual public 
// Returns:   std::string
// Qualifier:
// Author:zhengzhe 2011-11-21
//************************************
std::string DXFLine::OutputFormat()
{
	CString s;
	s.Format("10\r\n%f\r\n20\r\n%f\r\n30\r\n%f\r\n11\r\n%f\r\n21\r\n%f\r\n31\r\n%f\r\n0\r\n",start.x,start.y,start.z,end.x,end.y,end.z);
	return s.GetString();
}



//************************************
// 设置线的起始点和终点
// Method:    SetLine
// FullName:  DXFLine::SetLine
// Access:    public 
// Returns:   void
// Qualifier:
// Parameter: Point & s
// Parameter: Point & e
// Author:zhengzhe 2011-11-21
//************************************
void DXFLine::SetLine( Point& s,Point& e )
{
	start = s;
	end = e;
	string output = OutputFormat();
	m_memSeekEndPos = m_memSeekStartPos+ output.length()*sizeof(char);
}

void DXFLine::Draw( HDC& dc )
{
	throw std::exception("The method or operation is not implemented.");
}


//************************************
// 在DXF文件中读入线的信息
// Method:    operator>>
// FullName:  operator>>
// Access:    public 
// Returns:   istream&
// Qualifier:
// Parameter: istream & is
// Parameter: DXFLine & metaLine
// Author:zhengzhe 2011-11-21
//************************************
istream& operator>>( istream& is,DXFLine& metaLine )
{
	char tmp[256];			//设定每行大小256
	
	//跳到指定文件位置
	is.seekg(metaLine.m_memSeekStartPos,ios::beg); 

	//开始读取数据
	is.getline(tmp,256);
	metaLine.IncrementCount(metaLine, tmp);

	CString s(tmp);
	s = s.Trim();
	while(s!="10")
	{
		is.getline(tmp,256);
		metaLine.IncrementCount(metaLine,tmp);
		s = tmp;
		s = s.Trim();
	}
	while(s!="0")
	{
		if (s=="10")
		{
			is.getline(tmp,256);
			metaLine.IncrementCount(metaLine,tmp);
			metaLine.start.x = atof(tmp);
		}
		if	(s=="20")
		{
			is.getline(tmp,256);
			metaLine.IncrementCount(metaLine,tmp);
			metaLine.start.y = atof(tmp);
		}
		if	(s=="30")
		{
			is.getline(tmp,256);
			metaLine.IncrementCount(metaLine,tmp);
			metaLine.start.z = atof(tmp);
		}
		if (s=="11")
		{
			is.getline(tmp,256);
			metaLine.IncrementCount(metaLine,tmp);
			metaLine.end.x = atof(tmp);
		}
		if(s=="21")
		{
			is.getline(tmp,256);
			metaLine.IncrementCount(metaLine,tmp);
			metaLine.end.y = atof(tmp);
		}
		if(s=="31")
		{
			is.getline(tmp,256);
			metaLine.IncrementCount(metaLine,tmp);
			metaLine.end.z = atof(tmp);
		}
		//在读取浮点数的时候,需要跳过后面的回车换行符
		/*while(is.get()!='\n')
			continue;*/
		is.getline(tmp,256);
		metaLine.IncrementCount(metaLine,tmp);
		s = tmp;
		s = s.Trim();
	}
	//计算
	metaLine.CalCurByteSize();
	metaLine.m_orgByteSize = metaLine.GetCurByteSize();
	return is;
}
//************************************
// Method:    operator<<
// FullName:  operator<<
// Access:    public 
// Returns:   friend	ostream&
// Qualifier:
// Parameter: ostream & os
// Parameter: const DXFLine & metaLine
// Author:	  zhengzhe 
// CreateDate: 2011-11-21
//************************************
ostream& operator<< (ostream& os,const DXFLine& metaLine )
{
	os <<(DXFMeta&)metaLine <<endl;
	os<<"\nStart Point[x=" <<metaLine.start.x <<",y="<<metaLine.start.y<<",z="<<metaLine.start.z<<"]"
	  <<"\nEnd Point[x=" <<metaLine.end.x <<",y="<<metaLine.end.y<<",z="<<metaLine.end.z<<"]";
	 
	return os;
}



你可能感兴趣的:(DXF图元文件提取与显示(二)-Line)