C# 读取DXF文件 (2)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
u s i n g S y s t e m;
using
using ponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using
using System.IO;
using System.Collections;
namespace DXF
{
public partial class Form1 : Form
{
private FileStream fs;
private StreamReader sr;
private ArrayList LayerList = new ArrayList();
private ArrayList LineList = new ArrayList();
private ArrayList ArcList=new ArrayList();
private ArrayList EllipseList = new ArrayList();
private ArrayList LwopolylineList = new ArrayList();
private ArrayList SplineList=new ArrayList();
private string[] str = new string[2];
private int count;
private double leftx;
private double lefty;
private double rightx;
private double righty;
public Form1()
{
InitializeComponent();
}
private string[] ReadPair()
{
string code = sr.ReadLine().Trim();
string codedata = sr.ReadLine().Trim();
count += 2;
string[] result = new string[2] { code, codedata };
return result;
}
private void Read()
{
while (sr.Peek() != -1)
{
str = ReadPair();
if (str[1] == "SECTION")
{
str = ReadPair();
switch (str[1])
{
case"HEADER": ReadHeader();
break;
case"TABLES": ReadTable();
break;
case"ENTITIES": ReadEntities();
break;
}
}
}
sr.Close();
fs.Close();
btDraw.Enabled = true;
label1.Text = count.ToString();
count = 0;
}
private void ReadTable()
{
while (str[1] != "ENDSEC")
{
while (str[0] != "2" || str[1] != "LAYER") {
str = ReadPair();
}
while (str[0] != "0" || str[1] != "LAYER") {
str = ReadPair();
}
while (str[0] == "0" && str[1] == "LAYER")
{
ReadLAYER();
}
while (str[1] != "ENDSEC")
{
str = ReadPair();
}
}
}
private void ReadLAYER()
{
LAYER newlayer = new LAYER();
while (str[1] != "ENDTAB")
{
str = ReadPair();
switch (str[0])
{
case"2": = str[1];
break;
case"62": newlayer.colornum = str[1];
break;
case"6": newlayer.lstyle = str[1];
break;
case"370": newlayer.lwidth = str[1];
break;
}
if (str[0] == "0" && str[1] == "LAYER") {
LayerList.Add(newlayer);
return;
}
}
LayerList.Add(newlayer);
}
private void ReadEntities()
{
while (str[1] != "ENDSEC")
{
switch (str[1])
{
case"LINE": ReadLine();
break;
case"ARC": ReadArc();
break;
case"CIRCLE": ReadArc();
break;
case"ELLIPSE": ReadEllipse();
break;
case"LWPOLYLINE": ReadLwpolyline();
break;
case"SPLINE": ReadSpline();
break;