《C# 读取DXF文件》由会员分享,可在线阅读,更多相关《C# 读取DXF文件(17页珍藏版)》请在金锄头文库上搜索。
1、using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.IO;using System.Collections;namespace DXF public partial class Form1 : Form private FileStream fs; private StreamReader sr; priva
2、te 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 =
3、new string2; 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
4、2 code, codedata ; return result; private void Read() while (sr.Peek() != -1) str = ReadPair(); if (str1 = SECTION) str = ReadPair(); switch (str1) case HEADER: ReadHeader(); break; case TABLES: ReadTable(); break; case ENTITIES: ReadEntities(); break; sr.Close(); fs.Close(); btDraw.Enabled = true;
5、label1.Text = count.ToString(); count = 0; private void ReadTable() while (str1 != ENDSEC) while (str0 != 2 | str1 != LAYER) str = ReadPair(); while (str0 != 0 | str1 != LAYER) str = ReadPair(); while (str0 = 0 & str1 = LAYER) ReadLAYER(); while (str1 != ENDSEC) str = ReadPair(); private void ReadLA
6、YER() LAYER newlayer = new LAYER(); while (str1 != ENDTAB) str = ReadPair(); switch (str0) case 2: newlayer.name = str1; break; case 62: newlayer.colornum = str1; break; case 6: newlayer.lstyle = str1; break; case 370: newlayer.lwidth = str1; break; if (str0 = 0 & str1 = LAYER) LayerList.Add(newlaye
7、r); return; LayerList.Add(newlayer); private void ReadEntities() while (str1 != ENDSEC) switch (str1) case LINE: ReadLine(); break; case ARC: ReadArc(); break; case CIRCLE: ReadArc(); break; case ELLIPSE: ReadEllipse(); break; case LWPOLYLINE: ReadLwpolyline(); break; case SPLINE: ReadSpline(); brea
8、k; default: str = ReadPair(); break; private void ReadArc() ARC newarc = new ARC(); while (str1 != ENDSEC) str = ReadPair(); switch (str0) case 8: newarc.LName = str1; break; case 10: newarc.CenterX = Double.Parse(str1); break; case 20: newarc.CenterY = Double.Parse(str1); break; case 40: newarc.Radiu = Double.Parse(str1); break; case 50: newarc.SAngle = Double.Parse