2024年4月25日发(作者:)

C 语言直接写 DWG 图形文件接口

作者:yaozheng

专家分:10570

发表时间:2003-5-5 10:13:00 [回复]

高质高效舒适地编程:使用 Visual Unit

楼主

会员信息

发短消

所属BLOG

/* ---------------------------------------------------------------

-----------

INTerface to AutoCAD DWG drawing format.

Environment: PC, DOS, Turbo C, AutoCAD 10~

Contain Files:

INT_DWG.C DWG 文件访问函数库的源码。

INT_DWG.H DWG 文件访问函数库的头文件,

由外部 DEMO.C 文件引用。

INT_ DWG 文件访问函数库的连接用目标码,

INT_DWG.C 编译而成。

DWG 文件的头文件。

用户可根据自己的需要生成自己的"样板图",改名

*.DWG为 作为头文件。

DEMO.C 调用实例源码。该例为计算微波在两地间的通过能力。

运行该程序后,程序读取数据文件 文件,

经处理后,利用 INT_DWG 接口程序自动生成图形

文件 。

实例用的原始数据文件

实例产生的 DWG 结果文件

Create Date: 1993.3.29 304

Last Update: 1994.1.16 320

Last Update: 17 Dpbgn/Dpvert/Dpend() 352

26 Dvtext() 384

Writted by JYC.

------------------------------------------------------------------

----- */

#include

#include

#include

#include

#include

#define DISTANCE double

#define LENGTH double

#define ANGLE double

#define HEIGHT double

#define WIDTH double

#define SCALE double

#define RADIUS double

#define NUMBER int

#define MAXANG MAXFLOAT

#define diz(a,b,c,d) ((a)*(d)-(b)*(c))

#define sqr(x) (x)*(x)

#define Polar(p,p1,a,l) (p).x=(p1).x+(l)*cos(a);(p).y=(p1).y+(l)*s

in(a)

#define Distance(p,p2) sqrt(sqr((p2).x-(p).x)+sqr((p2).y-(p).y))

#define Midpt(pt,pt1,pt2) pt-x=(pt1-x+pt2-x)/2; pt-y=(pt1-y+pt2-y)

/2

#define SetLayer(x) D_Layer=x

#define SetWidth(x) D_Width=x

#define SetTexts(st,ht) D_Tstyle=st; D_Theight=ht

#define SetPoint(pt,u,v) pt.x=u;pt.y=v

#define SetQpt(pt,p1) memcpy(&pt,&p1,sizeof(pt))

#define Setptxy(p,p1,x,y) (p).x=(p1).x+x; (p).y=(p1).y+y

typedef struct { double x,y; }

POINT;

typedef enum {FALSE,TRUE}

BOOL;

void OpenDwg (char *dwgn);

void CloseDwg (void);

void SetPts (NUMBER ptn, POINT *pts, ...);

void Dline (POINT pt1,POINT pt2);

void Dpline (NUMBER ptn,POINT *pts);

void Dppts (NUMBER ptn, ...);

void Dpbgn (BOOL closed);

void Dpvert (POINT pt);

void Dpvertxy (double x,double y);

void Dpend (void);

void Dcircle (POINT pt1,DISTANCE r);

void Darc (POINT pt1,RADIUS r,ANGLE sa,ANGLE se);

void Dtext (POINT pt1,ANGLE ang,char *txt);