C 读取DXF文件Word格式.docx
《C 读取DXF文件Word格式.docx》由会员分享,可在线阅读,更多相关《C 读取DXF文件Word格式.docx(14页珍藏版)》请在冰豆网上搜索。
privatedoublelefty;
privatedoublerightx;
privatedoublerighty;
publicForm1()
InitializeComponent();
}
privatestring[]ReadPair()
stringcode=sr.ReadLine().Trim();
stringcodedata=sr.ReadLine().Trim();
count+=2;
string[]result=newstring[2]{code,codedata};
returnresult;
privatevoidRead()
while(sr.Peek()!
=-1)
str=ReadPair();
if(str[1]=="
SECTION"
)
switch(str[1])
case"
HEADER"
:
ReadHeader();
break;
TABLES"
ReadTable();
ENTITIES"
ReadEntities();
sr.Close();
fs.Close();
btDraw.Enabled=true;
label1.Text=count.ToString();
count=0;
privatevoidReadTable()
while(str[1]!
="
ENDSEC"
while(str[0]!
2"
||str[1]!
LAYER"
0"
while(str[0]=="
&
&
str[1]=="
ReadLAYER();
privatevoidReadLAYER()
LAYERnewlayer=newLAYER();
ENDTAB"
switch(str[0])
newlayer.name=str[1];
62"
newlayer.colornum=str[1];
6"
newlayer.lstyle=str[1];
370"
newlayer.lwidth=str[1];
if(str[0]=="
LayerList.Add(newlayer);
return;
privatevoidReadEntities()
LINE"
ReadLine();
ARC"
ReadArc();
CIRCLE"
ELLIPSE"
ReadEllipse();
LWPOLYLINE"
ReadLwpolyline();
SPLINE"
ReadSpline();
default:
privatevoidReadArc()
ARCnewarc=newARC();
8"
newarc.LName=str[1];
10"
newarc.CenterX=Double.Parse(str[1]);
20"
newarc.CenterY=Double.Parse(str[1]);
40"
newarc.Radiu=Double.Parse(str[1]);
50"
newarc.SAngle=Double.Parse(str[1]);
51"
newarc.EAngle=Double.Parse(str[1]);
newarc.lwidth=str[1];
ArcList.Add(newarc);
privatevoidReadLine()
LINEnewline=newLINE();
newline.LName=str[1];
newline.StartX=Double.Parse(str[1]);
newline.StartY=Double.Parse(str[1]);
11"
newline.EndX=Double.Parse(str[1]);
21"
newline.EndY=Double.Parse(str[1]);
newline.colornum=str[1];
newline.lwidth=str[1];
LineList.Add(newline);
privatevoidReadEllipse()
ELLIPSEnewellipse=newELLIPSE();
newellipse.LName=str[1];
newellipse.CenterX=Double.Parse(str[1]);
newellipse.CenterY=Double.Parse(str[1]);
newellipse.DeltaX=Double.Parse(str[1]);
newellipse.DeltaY=Double.Parse(str[1]);
newellipse.Radio=Double.Parse(str[1]);
41"
newellipse.PSAngle=Double.Parse(str[1]);
42"
newellipse.PEAngle=Double.Parse(str[1]);
newellipse.lwidth=str[1];
EllipseList.Add(newellipse);
privatevoidReadLwpolyline()
LWPOLYLINEnewlw=newLWPOLYLINE();
newlw.LName=str[1];
newlw.lwidth=str[1];
newlw.colornum=str[1];
90"
newlw.PointCount=Int32.Parse(str[1]);
70"
newlw.Flag=Int32.Parse(str[1]);
newlw.pointx=newdouble[newlw.PointCount];
newlw.pointy=newdouble[newlw.PointCount];
//if(newlw.Flag==1)
newlw.converxity=newdouble[newlw.PointCount];
//else
//newlw.converxity=newdouble[newlw.PointCount-1];
newlw.pointx[0]=Double.Parse(str[1]);
str=ReadPair();
newlw.pointy[0]=Double.Parse(str[1]);
for(inti=1;
i<
newlw.PointCount;
i++)
stringtemp=sr.ReadLine().Trim();
if(temp=="
newlw.converxity[i-1]=Double.Parse(sr.ReadLine().Trim());
i--;
elseif(temp=="
stringr=sr.ReadLine().Trim();
newlw.pointy[i]=Double.Parse(r);
else
newlw.pointx[i]=Double.Parse(r);
strings=sr.ReadLine().Trim();
if(s=="
newlw.converxity[newlw.PointCount-1]=Double.Parse(sr.ReadLine().Trim());
elseif(s=="
sr.ReadLine();
LwopolylineList.Add(newlw);
elsesr.ReadLine();
publicvoidReadSpline()
SPLINEnewspline=newSPLINE();
newspline.LName=str[1];
newspline.lwidth=str[1];
newspline.colornum=str[1];
newspline.Flag=Int32.Parse(str[1]);
74"
newspline.Count=Int32.Parse(str[1]);
newspline.throughpx=newdouble[Int32.Parse(str[1])];
newspline.throughpy=newdouble[Int32.Parse(str[1])];
12"
newspline.SVertorX=Double.Parse(str[1]);
22"
newspline.SVertorY=Double.Parse(str[1]);
13"
newspline.EVertorX=Double.Parse(str[1]);
23"
newspline.EVertorY=Double.Parse(str[1]);
newspline.throughpx[0]=Double.Parse(str[1]);
newspline.throughpy[0]=Double.Parse(str[1]);
for(inti=1;
i<
newspline.throughpx.Length;
i++)
if(str[0]=="
newspline.throughpx[i]=Double.Parse(str[1]);
elseif(str[0]=="
newspline.throughpy[i]=Double.Parse(str[1]);
if(newspline.Flag==11)
for(inti=0;
3;
SplineList.Add(newspline);
publicvoidReadHeader()
$EXTMIN"
leftx=Double.Parse(str[1]);
lefty=Double.Parse(str[1]);
$EXTMAX"
rightx=Double.Parse(str[1]);
righty=Double.Parse(str[1]);
//打开DXF文件
privatevoidbtOpen_Click(objectsender,EventArgse)
btDraw.Enabled=false;
LayerList.Clear();
LineList.Clear();
ArcList.Clear();
EllipseList.Clear();
LwopolylineList.Clear();
SplineList.Clear();
this.openFileDialog1.ShowDialog();
if(this.openFileDialog1.FileName.Trim()!
"
stringpath=this.openFileDialog1.FileName;
fs=newFileStream(path,FileMode.Open,FileAccess.Read);
sr=newStreamReader(fs);
Read();
privatevoidbtDraw_Click(objectsender,EventArgse)
doublewidth=Math.Ceiling(rightx)-Math.Ceiling(leftx)+40;
doubleheight=Math.Ceiling(righty)-Math.Ceiling(lefty)+40;
Bitmapbmp=newBitmap((int)width,(int)height);
Graphicsgx=Graphics.FromImage(bmp);
doublepw=width/(double)460;
doubleph=height/(double)384;
for(inti=0;
LineList.Count;
LINEtemp=(LINE)LineList[i];
temp.Move(leftx,lefty,righty-lefty+39);
temp.Draw(gx);
ArcList.Count;
ARCtemp=(ARC)ArcList[i];
EllipseList.Count;
ELLIPSEtemp=(ELLIPSE)EllipseList[i];
temp.Move(leftx+1,lefty+1);
temp.Draw(gx,height-1,pw,ph);
LwopolylineList.Count;
LWPOLYLINEtemp=(LWPOLYLINE)LwopolylineList[i];
temp.Draw(gx,leftx,lefty,righty-lefty+39);
SplineList.Count;
SPLINEtemp=(SPLINE)SplineList[i];
temp.Draw(gx,leftx-10,lefty,righty-lefty+39);
this.pictureBox1.Image=bmp;
}