- UID
- 2172
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-29
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- [font=courier new]
- //*******************************************************************
- // 文件名称:Mydcl.cpp
- //*******************************************************************
- #include < stdio.h>
- #include "adslib.h"
- #include "rxdefs.h"
- #include "adsdlg.h"
- #include "string.h"
- #include < stdlib.h>
- #define ELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
- #define Cpoint(d, s) { d[X]=s[X]; d[Y]=s[Y]; d[Z]=s[Z];}
- #define Spoint(d, x,y,z) { d[X]=(x); d[Y]=(y); d[Z]=(z);}
- struct func_entry { char *func_name;
- int (*func) ();
- };
- int mydcl();
- void set_size0();
- void CALLB size_list_cb(ads_callback_packet *cpkt);
- void CALLB size_usr_cb(ads_callback_packet *cpkt);
- void CALLB size_usr_accept_cb(ads_callback_packet *cpkt);
- void CALLB size_accept_cb(ads_callback_packet *cpkt);
- int draw_size(ads_point, int, int, short, short,
- char, char, ads_real);
- int dofun();
- int funcload();
- static struct func_entry func_table[] = {
- {"c:MYDCL", mydcl},
- };
- ads_real scale; //比例值
- extern "C" AcRx::AppRetCode
- acrxEntryPoint(AcRx::AppMsgCode msg, void* ptr)
- {
- switch(msg) {
- case AcRx::kInitAppMsg:
- acrxUnlockApplication(ptr);
- break;
- case AcRx::kInvkSubrMsg:
- dofun();
- break;
- case AcRx::kLoadADSMsg:
- funcload();
- }
- return AcRx::kRetOK;
- }
- static int funcload()
- {
- int i;
- for (i = 0; i < ELEMENTS(func_table); i++) {
- if (!acedDefun(func_table[i].func_name, (short)i))
- return RTERROR;
- }
- return RTNORM;
- }
- static int dofun()
- {
- int val;
- if ((val = acedGetFunCode()) < 0 || val >= ELEMENTS(func_table))
- {
- acdbFail("收到不存在的函数代码.");
- return RTERROR;
- }
- val = (*func_table[val].func)();
- return val;
- }
- int mydcl()
- {
- set_size0();
- return RSRSLT;
- }
- //.................... 图7-2及图7-3的驱动程序 ....................
- static struct size_list { //图幅尺寸的数据结构
- char *name; //图幅名称
- int hor; //图纸水平长度
- int ver; //图纸纵向长度
- short a; //图框到图纸左边界距离
- short c; //图框到图纸上,下,右边界距离
- } size_list[] = {
- {"A0",1189,841,25,10}, //A0,A1,...幅面的尺寸
- {"A1",841,594,25,10},
- {"A2",594,420,25,10},
- {"A3",420,297,25,5},
- {"A4",210,297,25,5},
- {"A5",210,148,25,5},
- {"USR",1189,841,25,10}, //用户自定义幅面,在此借用A0,可动态修改
- };
- #define SIZE_L 7 //常用图幅的数目
- static int size=0; //A0到USR共7种图幅的序号
- static char style; //图纸布置方式,1=正常(水平);0=转置(竖置)
- static char head; //标题栏,1=格式A(标准格式);0=格式B
- ads_hdlg hdlg,hdlg1; //对话框handle,因需嵌套显示,故设为全局变量
- int dcl_id; //对话框文件标识字,理由同上
- int dlg_status,dlg_status1; //对话框显示状态标志,理由同上
- char tbuf[80]; //全局性的自由变量
- // *** 用于图幅及标题栏前置设定的主函数 ***
- void set_size0()
- {
- ads_point pt_temp1={0,0,0}; //绘制图幅外边界时,左下角点坐标
- int i;
- struct resbuf rb; //供存取AutoCAD系统变量之用
- if(ads_load_dialog("Mydcl.dcl", &dcl_id)!=RTNORM) {
- //将对话框文件Mydcl.dcl调入内存
- acedAlert("装入Mydcl.dcl文件出错.");
- return;
- }
- if(ads_new_dialog("set_size0",dcl_id,(CLIENTFUNC)0,&hdlg)!=RTNORM) {
- //显示对话框,图7-2
- acedAlert("显示set_size0对话框时出错.");
- ads_unload_dialog(dcl_id); //卸载对话框文件
- return;
- }
- ads_action_tile(hdlg, "list", (CLIENTFUNC)size_list_cb);
- //将对话框中"list栏"与回调函数size_list_cb()相关联
- ads_action_tile(hdlg, "accept", (CLIENTFUNC)size_accept_cb);
- //将对话框的"OK按钮"与回调函数size_accept_cb()相关联
- ads_action_tile(hdlg, "usr", (CLIENTFUNC)size_usr_cb);
- //"usr"与函数size_usr_cb()相关联,实现用户自定义USR图幅尺寸
- ads_start_list(hdlg, "list", LIST_NEW, 0);
- //初始化"list栏"中各项数据
- for (i=0;i< SIZE_L;++i) {
- sprintf(tbuf,"%s(%dX%d)",size_list[i].name,size_list[i].hor,
- size_list[i].ver);
- ads_add_list(tbuf); //向list栏加入表项
- }
- ads_end_list(); //表的初始化工作结束
- ads_set_tile(hdlg, "edit", size_list[size].name); //为"edit"赋初值
- sprintf(tbuf,"%d",size);
- ads_set_tile(hdlg,"list", tbuf); //为"list"赋初值
- ads_start_dialog(hdlg, &dlg_status); //与对话框进行交互
- ads_unload_dialog(dcl_id); //当对话框关闭后,清理内存
- acedGetVar("DIASTAT",&rb);
- if(rb.resval.rint==0) {
- acedRetVoid(); //直接返回AutoLISP,不回显nil
- return; //CANCEL结束对话框,返回
- }
- acedGetVar("userr1",&rb); //从系统变量userr1获取当前使用的比例值
- scale=rb.resval.rreal;
- if(scale==0.0) scale=1.0;
- acedCommand(RTSTR,"ERASE",RTSTR,"ALL",RTSTR,"",0);
- //清屏后,调draw_size()函数绘图框和标题栏等
- if(draw_size(pt_temp1,size_list[size].hor,size_list[size].ver,
- size_list[size].a,size_list[size].c,style,head,scale)!=RTERROR)
- acedCommand(RTSTR,"ZOOM",RTSTR,"ALL",0);
- acedRetVoid();
- return;
- }
- // *** 图幅对话框"list"列表栏所对应的回调函数size_list_cb() ***
- void CALLB size_list_cb(ads_callback_packet *cpkt)
- {
- if (cpkt->value == NULL || cpkt->value[0] == EOS)
- return ;
- ads_set_tile(cpkt->dialog,"edit",size_list[atoi(cpkt->value)].name);
- //用"list"中的比例值更新"edit"
- }
- // *** 图幅对话框"usr"所对应的回调函数size_usr_cb() ***
- void CALLB size_usr_cb(ads_callback_packet *cpkt)
- {
- short sht1,sht2; //对话框中幻灯片的尺寸
- ads_set_tile(cpkt->dialog, "edit", size_list[SIZE_L-1].name);
- //首先将主对话框中的"edit"一项用"USR"更新
- ads_new_dialog("set_size0_a", dcl_id, (CLIENTFUNC)0, &hdlg1);
- //显示子对话框,图7-3
- ads_action_tile(hdlg1, "accept", (CLIENTFUNC)size_usr_accept_cb);
- itoa(size_list[SIZE_L-1].hor,tbuf,10);
- ads_set_tile(hdlg1, "H", tbuf);
- itoa(size_list[SIZE_L-1].ver,tbuf,10);
- ads_set_tile(hdlg1, "V", tbuf);
- itoa(size_list[SIZE_L-1].a,tbuf,10);
- ads_set_tile(hdlg1, "a", tbuf);
- itoa(size_list[SIZE_L-1].c,tbuf,10);
- ads_set_tile(hdlg1, "c", tbuf);
- //上面几行是用USR图幅原值初始化对话框各项
- ads_dimensions_tile(hdlg1,"image",&sht1,&sht2); //显示幻灯片
- ads_start_image(hdlg1,"image");
- ads_slide_image(0,0,sht1,sht2,"set_size"); //幻灯片名为SET_SIZE.SLD
- ads_end_image();
- ads_start_dialog(hdlg1, &dlg_status1); //与对话框进行交互
- ads_start_list(hdlg, "list", LIST_CHANGE, SIZE_L-1);
- //改变主对话框"list栏"中USR图幅尺寸数字
- sprintf(tbuf,"%s(%dX%d)",size_list[SIZE_L-1].name,
- size_list[SIZE_L-1].hor,size_list[SIZE_L-1].ver);
- ads_add_list(tbuf);
- ads_end_list();
- sprintf(tbuf,"%d",SIZE_L-1);
- ads_set_tile(hdlg,"list", tbuf); //将主对话框的光标置于"list"的USR
- }
- // *** 自定义图幅对话框"OK按钮"所对应的回调函数size_accept_a_cb() ***
- void CALLB size_usr_accept_cb(ads_callback_packet *cpkt)
- {
- ads_get_tile(cpkt->dialog, "H", tbuf, MAX_TILE_STR);
- size_list[SIZE_L-1].hor=atoi(tbuf);
- ads_get_tile(cpkt->dialog, "V", tbuf, MAX_TILE_STR);
- size_list[SIZE_L-1].ver=atoi(tbuf);
- ads_get_tile(cpkt->dialog, "a", tbuf, MAX_TILE_STR);
- size_list[SIZE_L-1].a=atoi(tbuf);
- ads_get_tile(cpkt->dialog, "c", tbuf, MAX_TILE_STR);
- size_list[SIZE_L-1].c=atoi(tbuf);
- //获取各控件的值,送至结构变量size_list[]
- ads_done_dialog(cpkt->dialog,3); //关闭子对话框
- }
- // *** 图幅对话框"OK按钮"所对应的回调函数size_accept_cb() ***
- void CALLB size_accept_cb(ads_callback_packet *cpkt)
- {
- int i;
- ads_get_tile(cpkt->dialog, "edit", tbuf, MAX_TILE_STR);
- for(i=0;i< SIZE_L;i++) { //根据图幅名称,获取用户选定的图幅的序号
- if(stricmp(tbuf,size_list[i].name)==0) {
- size=i;
- break;
- }
- }
- if(i!=size) size=SIZE_L-1;
- if(size_list[size].hor< =25||size_list[size].ver< =10) {
- acedAlert("自定义尺寸有误.");
- return;
- }
- ads_get_tile(cpkt->dialog, "style", tbuf, MAX_TILE_STR);
- style=tbuf[0]; //图纸布置方式
- ads_get_tile(cpkt->dialog, "head_a", tbuf, MAX_TILE_STR);
- head=tbuf[0]; //标题栏格式
- ads_done_dialog(cpkt->dialog,1); //正常关闭对话框
- }
- // *** 绘制图幅外边界,图框,标题栏 ***
- int draw_size(ads_point pt_temp1, int hor, int ver, short a, short c,
- char style, char head, ads_real scale)
- { //传递参数依次为: 左下角点坐标,水平长度,纵向长度,至左边界距离,
- // 至其它三边的距离,图纸布置方式,标题栏格式,绘图比例
- ads_point pt0,pt1,pt2,pt3;
- int int1;
- char head_name[12]; //DWG格式标题栏图块名称
- ads_name ss,e0,e1; //选择集和实体名称
- if(style!='1') { //图纸转置90度
- int1=hor;
- hor=ver;
- ver=int1;
- }
- if(head=='1') strcpy(head_name,"head_a.dwg"); //标题栏格式A
- else strcpy(head_name,"head_b.dwg"); //标题栏格式B
- if(acedFindFile(head_name,tbuf)!=RTNORM) { //在盘上查找标题栏图块
- sprintf(tbuf,"file < %s> not existed.",head_name);
- acedAlert(tbuf);
- return RTERROR;
- }
-
- Cpoint(pt0,pt_temp1); //对图幅外边界四角点X,Y,Z坐标赋值
- Spoint(pt1,pt0[X]+hor,pt0[Y],0);
- Spoint(pt2,pt0[X]+hor,pt0[Y]+ver,0);
- Spoint(pt3,pt0[X],pt0[Y]+ver,0);
- acedCommand(RTSTR,"COLOR",RTSTR,"YELLOW",0);
- acedCommand(RTSTR,"LINE",RTPOINT,pt0,RTPOINT,pt1,0); //画外边界线
- acdbEntLast(e0); //为后续生成ss选择集而保存第一个实体的名称
- acedCommand(RTPOINT,pt2,RTPOINT,pt3,RTSTR,"C",0);
- Spoint(pt0,pt0[X]+a,pt0[Y]+c,0);
- Spoint(pt1,pt1[X]-c,pt1[Y]+c,0);
- Spoint(pt2,pt2[X]-c,pt2[Y]-c,0);
- Spoint(pt3,pt3[X]+a,pt3[Y]-c,0);
- acedCommand(RTSTR,"COLOR",RTSTR,"WHITE",0);
- acedCommand(RTSTR,"LINE",RTPOINT,pt0,RTPOINT,pt1,RTPOINT,pt2,
- RTPOINT,pt3,RTSTR,"C",0); //绘图框线
- acedCommand(RTSTR,"LINE",RTPOINT,pt3,RTSTR,"@40< 0",RTSTR,"@12< -90",
- RTSTR,"@40< -180",RTSTR,"@12< 90",RTSTR,"",0);//绘图号区
- acedCommand(RTSTR,"INSERT",RTSTR,head_name,RT3DPOINT,pt1,
- RTSTR,"",RTSTR,"",RTSTR,"",0); //插入标题栏图块
- acedCommand(RTSTR,"COLOR",RTSTR,"BYLAYER",0);
- acedSSAdd(NULL,NULL,ss); //构造空的选择集ss
- do { //生成包含所有新实体(图框,标题栏等)的选择集,送ss之中
- acedSSAdd(e0,ss,ss);
- acdbNameSet(e0,e1);
- } while(acdbEntNext(e1,e0)==RTNORM);
- acedCommand(RTSTR,"SCALE",RTPICKS,ss,RTSTR,"",RTPOINT,pt_temp1,
- RTREAL,1.0/scale,0); //对图框和标题栏等进行反比例缩放
- acedSSFree(ss); //释放选择集ss
- return RTNORM;
- }
- [/font]
|
|