#region DXF输入
private FileStream fs;
private StreamReader sr;
private string[] str = new string[2];
public List<PointD> pointList=new List<PointD> ();
public List<PointD[]> linePointList = new List<PointD[]>();
public void ReadDXF(string inputDXFPath)
{
fs = new FileStream(inputDXFPath, FileMode.Open, FileAccess.Read);
sr = new StreamReader(fs);
Read();
}
//读取编码与值
private string[] ReadPair()
{
string[] result = new string[2];
result[0] = sr.ReadLine().Trim();
result[1] = sr.ReadLine().Trim();
return result;
}
private void Read()
{
while (sr.Peek()!=-1)
{
str = ReadPair();
if (str[1]=="SECTION")
{
str = ReadPair();
switch (str[1])
{
case "ENTITIES": ReadEntities();
break;
default:
break;
}
}
}
sr.Close();
fs.Close();
}
//读取实体
private void ReadEntities()
{
while (str[1]!="ENDSEC")
{
switch (str[1])
{
case "LINE": ReadLINE();
break;
case "POINT": ReadPoint();
break;
default: str = ReadPair();
break;
}
}
}
//读取LINE
private void ReadLINE()
{
PointD[] line = new PointD[2];
line[0] = new PointD();
line[1] = new PointD();
str = ReadPair();
while (str[0]!="0")
{
str = ReadPair();
switch (str[0])
{
case "10": line[0].distance = Convert.ToDouble(str[1]);
break;
case "20": line[0].elev = Convert.ToDouble(str[1]);
break;
case "11": line[1].distance = Convert.ToDouble(str[1]);
break;
case "21": line[1].elev = Convert.ToDouble(str[1]);
break;
default:
break;
}
}
linePointList.Add(line);
}
//读取POINT
private void ReadPoint()
{
PointD point = new PointD();
str = ReadPair();
while (str[0] != "0")
{
str = ReadPair();
switch (str[0])
{
case "10": point.distance = Convert.ToDouble(str[1]);
break;
case "20": point.elev = Convert.ToDouble(str[1]);
break;
default:
break;
}
}
pointList.Add(point);
}
#endregion
}