C 语言直接写 DWG 图形文件接口Word格式文档下载.docx
《C 语言直接写 DWG 图形文件接口Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《C 语言直接写 DWG 图形文件接口Word格式文档下载.docx(14页珍藏版)》请在冰豆网上搜索。
运行该程序后,程序读取数据文件DEMO.DAT文件,
经处理后,利用INT_DWG接口程序自动生成图形
文件DEMO.DWG。
DEMO.DAT实例用的原始数据文件
DEMO.DWG实例产生的DWG结果文件
CreateDate:
1993.3.29304
LastUpdate:
1994.1.16320
17Dpbgn/Dpvert/Dpend()352
26Dvtext()384
WrittedbyJYC.
-----------------------------------------------------------------------*/
#include
#defineDISTANCEdouble
#defineLENGTHdouble
#defineANGLEdouble
#defineHEIGHTdouble
#defineWIDTHdouble
#defineSCALEdouble
#defineRADIUSdouble
#defineNUMBERint
#defineMAXANGMAXFLOAT
#definediz(a,b,c,d)((a)*(d)-(b)*(c))
#definesqr(x)(x)*(x)
#definePolar(p,p1,a,l)(p).x=(p1).x+(l)*cos(a);
(p).y=(p1).y+(l)*sin(a)
#defineDistance(p,p2)sqrt(sqr((p2).x-(p).x)+sqr((p2).y-(p).y))
#defineMidpt(pt,pt1,pt2)pt-x=(pt1-x+pt2-x)/2;
pt-y=(pt1-y+pt2-y)/2
#defineSetLayer(x)D_Layer=x
#defineSetWidth(x)D_Width=x
#defineSetTexts(st,ht)D_Tstyle=st;
D_Theight=ht
#defineSetPoint(pt,u,v)pt.x=u;
pt.y=v
#defineSetQpt(pt,p1)memcpy(&
pt,&
p1,sizeof(pt))
#defineSetptxy(p,p1,x,y)(p).x=(p1).x+x;
(p).y=(p1).y+y
typedefstruct{doublex,y;
}
POINT;
typedefenum{FALSE,TRUE}
BOOL;
voidOpenDwg(char*dwgn);
voidCloseDwg(void);
voidSetPts(NUMBERptn,POINT*pts,...);
voidDline(POINTpt1,POINTpt2);
voidDpline(NUMBERptn,POINT*pts);
voidDppts(NUMBERptn,...);
voidDpbgn(BOOLclosed);
voidDpvert(POINTpt);
voidDpvertxy(doublex,doubley);
voidDpend(void);
voidDcircle(POINTpt1,DISTANCEr);
voidDarc(POINTpt1,RADIUSr,ANGLEsa,ANGLEse);
voidDtext(POINTpt1,ANGLEang,char*txt);
voidDvtext(POINTpt1,char*txt);
voidDinsert(NUMBERbn,POINTpt1,SCALEsx,SCALEsy,ANGLEang);
voidDprintf(POINTpt1,ANGLEang,char*format,...);
voidaxbyc(POINT*pt1,POINT*pt2,float*a,float*b,float*c);
BOOLintspt(POINT*pt,POINT*p11,POINT*p12,POINT*p21,POINT*p22);
ANGLEangle(POINT*pt1,POINT*pt2);
DISTANCEperdist(POINT*pt,POINT*p1,POINT*p2);
staticvoidfilcpy(longlen);
staticlongfilpcp(longdt);
staticvoidfilecp(void);
staticFILE*dwgh,*dwgf,*dwgt;
staticlongent_p,pln_p;
NUMBERD_Layer=0;
NUMBERD_Tstyle=0;
NUMBERD_Tjustify=0;
HEIGHTD_Theight=1.0;
WIDTHD_Width=0.0;
voidOpenDwg(char*dwgn)
{
charfn[20];
strcpy(fn,dwgn);
strcat(fn,"
.dwg"
);
dwgh=fopen("
dwg.hed"
"
rb"
dwgf=fopen(fn,"
wb"
dwgt=fopen("
dwg.tmp"
fseek(dwgh,0,SEEK_SET);
filcpy(0x14);
/*Head14h*/
ent_p=filpcp(0);
/*ent_p*/
}
voidCloseDwg(void)
longent_l,
tab_p,
blk_t_p,
lay_t_p,
sty_t_p,
ltp_t_p,
viw_t_p,
blk_p,
dwg_l;
FILE*tmpf;
fclose(dwgt);
ent_l=filelength(fileno(dwgt))-0x28;
fseek(dwgh,0x18,SEEK_SET);
filpcp(ent_l);
/*tab_p*/
/*blk_d_p*/
filpcp(0);
/*unknown*/
/*dwg_l*/
filcpy(6);
/*blk_t_p*/
/*lay_t_p*/
/*sty_t_p*/
/*ltp_t_p*/
/*vie_t_p*/
filcpy(0x4AE);
/*SystemVariable*/
tmpf=dwgh;
dwgh=dwgt;
filcpy(ent_l+0x28);
dwgh=tmpf;
fseek(dwgh,0x28,SEEK_CUR);
filecp();
fclose(dwgh);
fclose(tmpf);
fclose(dwgf);
/*unlink("
*/
voidDline(POINTpt1,POINTpt2)
charstr[8]={0x01,0x04,0x28,0,0,0,0,0};
str[4]=D_Layer;
fwrite(str,8,1,dwgt);
fwrite(&
pt1,16,1,dwgt);
pt2,16,1,dwgt);
voidDpline(NUMBERptn,POINT*pts)
charstr[8]={0x13,0x80,0x18,0,0,0,6,0},
stc[9]={0x13,0x80,0x19,0,0,0,7,0,1},
sti[8]={0x14,0x00,0x18,0,0,0,0,0},
stn[8]={0x11,0x00,0x0C,0,0,0,0,0};
NUMBERi;
stc[4]=D_Layer;
sti[4]=D_Layer;
stn[4]=D_Layer;
pln_p=ftell(dwgt)+ent_p;
if(ptn0)
else
fwrite(stc,9,1,dwgt);
D_Width,8,1,dwgt);
for(i=0;
i
/*------------------------------------------------------------------------
INT_DWG.H:
InterfaceToAutoCADDWGfileModule.
History:
1992.4.12FCGEOM
1992.11.3INT_DWG
1994.1.17Dpbgn/Dpvert/Dpend
1993.3.27ByJYCCo.
----------------------------------------------------------------------*/
#definedxy(x,y)(double)(x),(double)(y)
pt.y=v
#defineDistance(p1,p2)sqrt(sqr((p2).x-(p1).x)+sqr((p2).y-(p1).y))
#defineMidpt(p,p1,p2)p.x=(p1.x+p2.x)/2;
p.y=(p1.y+p2.y)/2
#defineAngle(p1,p2)angle(&
p1,&
p2)
#defineIntspt(p,s,q,u,v)intspt(&
p,&
s,&
q,&
u,&
v)
#definePerdist(p,p1,p2)perdist(&
externvoidOpenDwg(char*dwgn);
externvoidCloseDwg(void);
externvoidSetPts(NUMBERptn,POINT*pts,...);
externvoidDline(POINTpt1,POINTpt2);
externvoidDpline(NUMBERptn,POINT*pts);
externvoidDppts(NUMBERptn,...);
externvoidDpbgn(BOOLclosed);
externvoidDpvert(POINTpt);
externvoidDpvertxy(doublex,doubley);
externvoidDpend(void);
externvoidDcircle(POINTpt1,DISTANCEr);
externvoidDarc(POINTpt1,RADIUSr,ANGLEsa,ANGLEse);
externvoidDtext(POINTpt1,ANGLEang,char*txt);
externvoidDvtext(POINTpt1,char*txt);
externvoidDinsert(NUMBERbn,POINTpt1,SCALEsx,SCALEsy,ANGLEang);
externvoidDprintf(POINTpt1,ANGLEang,char*format,...);
externvoidintspt(POINT*p,POINT*p1,POINT*p2,POINT*p3,POINT*p4);
externvoidaxbyc(POINT*p1,POINT*p2,float*a,float*b,float*c);
externDISTANCEperdist(POINT*p,POINT*p1,POINT*p2);
externANGLEangle(POINT*p1,POINT*p2);
externNUMBERD_Layer;
externWIDTHD_Width;
externHEIGHTD_Theight;
externNUMBERD_Tstyle;
externNUMBERD_Tjustify;
--------------------------------------------------------------------------------
DEMO.C
MicroWaveApplication:
1994.1.25Copyfromdemo.c105
26MWhead/topo/build
Dborder/globe/dthtp/name/symbol
ah[3]={0,ah,ah2}paralleloperate
27LAY_BORD/TOPO/BUILD_0/1/2304
#defineparameters312proj314
WrittenbyJYC.
----------------------------------------------------------------------*/
#include"
int_dwg.h"
#definelnwid15.0
#definelmargin65.0
#definelspace5.0
#definermargin35.0
enum{LAY_BORD,LAY_TOPO_0,LAY_BUILD_0,
LAY_TOPO_1,LAY_BUILD_1,
LAY_TOPO_2,LAY_BUILD_2};
enum{BLK_ROAD,BLK_PIVOT};
voidMWhead(void);
voidMWtopo(void);
voidMWbuild(void);
voidMWend(void);
voidDborder(floatx,floaty);
voidDglobe(void);
voidDtopvt(DISTANCEdt,DISTANCEht);
voidDdthtp(floatdt,floatht,charsw);
voidDname(floatdt,char*txt);
voidDvilage(floatdt,floatht,floatvw,floatvh);
voidDsymbol(floatdt,floatht,intbn);
floatchord(floatAh,floatx);
charproj[80];
FILE*fi;
DISTANCEal,ah[3],bh,step;
SCALEsx,sy;
POINTmwbp;
voidmain(void)
clrscr();
OpenDwg("
demo"
MWhead();
MWtopo();
MWbuild();
MWend();
CloseDwg();
printf("
\nGoodLucky!
"
getch();
voidMWhead(void)
chartxt[80];
fi=fopen("
mwave.dat"
rt"
while(fscanf(fi,"
%s"
txt)){
if(*txt=='
*'
)
fgets(txt,80,fi);
break;
strcpy(proj,txt);
fscanf(fi,"
%lf%lf%lf%lf%lf%lf%lf\n\r"
&
al,&
bh,&
sx,&
sy,&
(ah[1]),&
(ah[2]),&
step);
ah[0]=0;
%s\n\r%lf,%lf,%lf,%lf,%lf,%lf,%lf\n\r"
proj,al,ah[1],ah[2],bh,sx,sy,step);
sx/=1000;
sy/=1000;
Dborder(0,0);
Dglobe();
voidMWtopo(void)
BOOLsta=FALSE;
DISTANCEdt,ht;
){
if(sta)break;
else{
if(!
sta)sta=TRUE;
sscanf(txt,"
%lf"
&
dt);
%lf\n\r"
ht);
(%8.2lf,%8.2lf)\n\r"
dt,ht);
Dtopvt(dt,ht);
voidMWbuild(void)
charsw,txt[80];
DISTANCEdt,ht,vw,vh;
sw=*txt;
%lf%lf"
dt,&
%c(%8.2lf,%8.2lf)"
sw,dt,ht);
Ddthtp(dt,ht,sw);
switch(sw){
case'
V'
:
%s%lf%lf\n\r"
txt,&
vw,&
vh);
(%8.2lf,%8.2lf)%s\n\r"
vw,vh,txt);
Dvilage(dt,ht,vw,vh);
Dname(dt,txt);
S'
E'
%s\n\r"
txt);
R'
\n\r"
Dsymbol(dt,ht,BLK_ROAD);
P'
Dsymbol(dt,ht,BLK_PIVOT);
defa