C读取DXF文件.docx
- 文档编号:12915116
- 上传时间:2023-06-09
- 格式:DOCX
- 页数:16
- 大小:15.86KB
C读取DXF文件.docx
《C读取DXF文件.docx》由会员分享,可在线阅读,更多相关《C读取DXF文件.docx(16页珍藏版)》请在冰点文库上搜索。
C读取DXF文件
usingSystem;
using
using;
using;
using;
using;
using
using;
using;
namespaceDXF
{
publicpartialclassForm1:
Form
{
privateFileStreamfs;
privateStreamReadersr;
privateArrayListLayerList=newArrayList();
privateArrayListLineList=newArrayList();
privateArrayListArcList=newArrayList();
privateArrayListEllipseList=newArrayList();
privateArrayListLwopolylineList=newArrayList();
privateArrayListSplineList=newArrayList();
privatestring[]str=newstring[2];
privateintcount;
privatedoubleleftx;
privatedoublelefty;
privatedoublerightx;
privatedoublerighty;
publicForm1()
{
InitializeComponent();
}
privatestring[]ReadPair()
{
stringcode=().Trim();
stringcodedata=().Trim();
count+=2;
string[]result=newstring[2]{code,codedata};
returnresult;
}
privatevoidRead()
{
while()!
=-1)
{
str=ReadPair();
if(str[1]=="SECTION")
{
str=ReadPair();
switch(str[1])
{
case"HEADER":
ReadHeader();
break;
case"TABLES":
ReadTable();
break;
case"ENTITIES":
ReadEntities();
break;
}
}
}
();
();
=true;
=();
count=0;
}
privatevoidReadTable()
{
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();
}
}
}
privatevoidReadLAYER()
{
LAYERnewlayer=newLAYER();
while(str[1]!
="ENDTAB")
{
str=ReadPair();
switch(str[0])
{
case"2":
=str[1];
break;
case"62":
=str[1];
break;
case"6":
=str[1];
break;
case"370":
=str[1];
break;
}
if(str[0]=="0"&&str[1]=="LAYER")
{
(newlayer);
return;
}
}
(newlayer);
}
privatevoidReadEntities()
{
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;
default:
str=ReadPair();
break;
}
}
}
privatevoidReadArc()
{
ARCnewarc=newARC();
while(str[1]!
="ENDSEC")
{
str=ReadPair();
switch(str[0])
{
case"8":
=str[1];
break;
case"10":
=(str[1]);
break;
case"20":
=(str[1]);
break;
case"40":
=(str[1]);
break;
case"50":
=(str[1]);
break;
case"51":
=(str[1]);
break;
case"370":
=str[1];
break;
case"0":
(newarc);
return;
}
}
}
privatevoidReadLine()
{
LINEnewline=newLINE();
while(str[1]!
="ENDSEC")
{
str=ReadPair();
switch(str[0])
{
case"8":
=str[1];
break;
case"10":
=(str[1]);
break;
case"20":
=(str[1]);
break;
case"11":
=(str[1]);
break;
case"21":
=(str[1]);
break;
case"62":
=str[1];
break;
case"370":
=str[1];
break;
case"0":
(newline);
return;
}
}
}
privatevoidReadEllipse()
{
ELLIPSEnewellipse=newELLIPSE();
while(str[1]!
="ENDSEC")
{
str=ReadPair();
switch(str[0])
{
case"8":
=str[1];
break;
case"10":
=(str[1]);
break;
case"20":
=(str[1]);
break;
case"11":
=(str[1]);
break;
case"21":
=(str[1]);
break;
case"40":
=(str[1]);
break;
case"41":
=(str[1]);
break;
case"42":
=(str[1]);
break;
case"370":
=str[1];
break;
case"0":
(newellipse);
return;
}
}
}
privatevoidReadLwpolyline()
{
LWPOLYLINEnewlw=newLWPOLYLINE();
while(str[1]!
="ENDSEC")
{
str=ReadPair();
switch(str[0])
{
case"8":
=str[1];
break;
case"370":
=str[1];
break;
case"62":
=str[1];
break;
case"90":
=(str[1]);
break;
case"70":
=(str[1]);
break;
case"10":
=newdouble[];
=newdouble[];
rim();
if(temp=="42")
{
[i-1]=().Trim());
i--;
}
elseif(temp=="20")
{
stringr=().Trim();
[i]=(r);
}
else
{
stringr=().Trim();
[i]=(r);
i--;
}
}
strings=().Trim();
if(s=="42")
[-1]=().Trim());
elseif(s=="0")
{
();
(newlw);
return;
}
else();
break;
case"0":
(newlw);
return;
}
}
}
publicvoidReadSpline()
{
SPLINEnewspline=newSPLINE();
while(str[1]!
="ENDSEC")
{
str=ReadPair();
switch(str[0])
{
case"8":
=str[1];
break;
case"370":
=str[1];
break;
case"62":
=str[1];
break;
case"70":
=(str[1]);
break;
case"74":
=(str[1]);
=newdouble[(str[1])];
=newdouble[(str[1])];
break;
case"12":
=(str[1]);
break;
case"22":
=(str[1]);
break;
case"13":
=(str[1]);
break;
case"23":
=(str[1]);
break;
case"11":
[0]=(str[1]);
str=ReadPair();
[0]=(str[1]);
str=ReadPair();
for(int
{
str=ReadPair();
if(str[0]=="11")
{
[i]=(str[1]);
i--;
}
elseif(str[0]=="21")
{
[i]=(str[1]);
i--;
}
}
if==11)
{
for(inti=0;i<3;i++)
{
str=ReadPair();
}
}
break;
case"0":
(newspline);
return;
}
}
}
publicvoidReadHeader()
{
while(str[1]!
="ENDSEC")
{
str=ReadPair();
switch(str[1])
{
case"$EXTMIN":
str=ReadPair();
leftx=(str[1]);
str=ReadPair();
lefty=(str[1]);
break;
case"$EXTMAX":
str=ReadPair();
rightx=(str[1]);
str=ReadPair();
righty=(str[1]);
break;
}
}
}
//打开DXF文件
privatevoidbtOpen_Click(objectsender,EventArgse)
{
=false;
();
();
();
();
();
();
if(this"")
{
stringpath=fs=newFileStream(path,,;
sr=newStreamReader(fs);
Read();
}
}
privatevoidbtDraw_Click(objectsender,EventArgse)
{
doublewidth=(rightx)-(leftx)+40;
doubleheight=(righty)-(lefty)+40;
Bitmapbmp=newBitmap((int)width,(int)height);
Graphicsgx=(bmp);
doublepw=width/(double)460;
doubleph=height/(double)384;
for(inti=0;i<;i++)
{
LINEtemp=(LINE)LineList[i];
(leftx,lefty,righty-lefty+39);
(gx);
}
for(inti=0;i<;i++)
{
ARCtemp=(ARC)ArcList[i];
(leftx,lefty,righty-lefty+39);
(gx);
}
for(inti=0;i<;i++)
{
ELLIPSEtemp=(ELLIPSE)EllipseList[i];
(leftx+1,lefty+1);
(gx,height-1,pw,ph);
}
for(inti=0;i<;i++)
{
LWPOLYLINEtemp=(LWPOLYLINE)LwopolylineList[i];
(gx,leftx,lefty,righty-lefty+39);
}
for(inti=0;i<;i++)
{
SPLINEtemp=(SPLINE)SplineList[i];
(gx,leftx-10,lefty,righty-lefty+39);
}
=bmp;
}
}
}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 读取 DXF 文件