#pragma once #include "dxfmeta.h" class DXFCircle : public DXFMeta { public: explicit DXFCircle(UINT rCount,UINT seekBytes); ~DXFCircle(void); virtual string OutputFormat(); friend ostream& operator<<(ostream& os,const DXFCircle& metaCircle); //数据输出的友元函数 friend istream& operator>>(istream& is,DXFCircle& metaCircle); //数据输入的友元函数 virtual void Draw( HDC& dc ); private: Point center; double radius; };
#include "StdAfx.h" #include "DXFCircle.h" //************************************ // 定义圆在DXF中的输出格式 // Method: OutputFormat // FullName: DXFCircle::OutputFormat // Access: virtual public // Returns: std::string // Qualifier: // Author:zhengzhe 2011-11-22 //************************************ std::string DXFCircle::OutputFormat() { CString s; s.Format("10\r\n%f\r\n20\r\n%f\r\n30\r\n%f\r\n40\r\n%f\r\n0\r\n",center.x,center.y,center.z,radius); return s.GetString(); } //************************************ // 根据DXF行号和偏移的字节数来生成圆对象 // Method: DXFCircle // FullName: DXFCircle::DXFCircle // Access: public // Returns: // Qualifier: :DXFMeta(rCount,seekBytes) // Parameter: UINT rCount // Parameter: UINT seekBytes // Author:zhengzhe 2011-11-22 //************************************ DXFCircle::DXFCircle( UINT rCount,UINT seekBytes ):DXFMeta(rCount,seekBytes) { type=CIRCLE; center.x=center.y=center.z=0.0; radius = 1.0; } DXFCircle::~DXFCircle( void ) { } void DXFCircle::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: DXFCircle & metaCircle // Author:zhengzhe 2011-11-22 //************************************ istream& operator>>( istream& is,DXFCircle& metaCircle ) { char tmp[256]; //设定每行大小256 //跳到指定文件位置 is.seekg(metaCircle.m_memSeekStartPos,ios::beg); //开始读取数据 is.getline(tmp,256); metaCircle.IncrementCount(metaCircle, tmp); CString s(tmp); s = s.Trim(); while(s!="10") { is.getline(tmp,256); metaCircle.IncrementCount(metaCircle,tmp); s = tmp; s = s.Trim(); } while(s!="0") { if (s=="10") { is.getline(tmp,256); metaCircle.IncrementCount(metaCircle,tmp); metaCircle.center.x = atof(tmp); } if (s=="20") { is.getline(tmp,256); metaCircle.IncrementCount(metaCircle,tmp); metaCircle.center.y = atof(tmp); } if (s=="30") { is.getline(tmp,256); metaCircle.IncrementCount(metaCircle,tmp); metaCircle.center.z = atof(tmp); } if (s=="40") { is.getline(tmp,256); metaCircle.IncrementCount(metaCircle,tmp); metaCircle.radius = atof(tmp); } //在读取浮点数的时候,需要跳过后面的回车换行符 /*while(is.get()!='\n') continue;*/ is.getline(tmp,256); metaCircle.IncrementCount(metaCircle,tmp); s = tmp; s = s.Trim(); } //计算 metaCircle.CalCurByteSize(); metaCircle.m_orgByteSize = metaCircle.GetCurByteSize(); return is; } //************************************ // 输出显示圆信息 // Method: operator<< // FullName: operator<< // Access: public // Returns: ostream& // Qualifier: // Parameter: ostream & os // Parameter: const DXFCircle & metaCircle // Author:zhengzhe 2011-11-22 //************************************ ostream& operator<< (ostream& os,const DXFCircle& metaCircle ) { os <<(DXFMeta&)metaCircle <<endl; os<<"\nCenter[x=" <<metaCircle.center.x <<",y="<<metaCircle.center.y<<",z="<<metaCircle.center.z<<"]" <<"\nradius="<<metaCircle.radius<<"]"; return os; }