- UID
- 82688
- 积分
- 380
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-9-27
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
如何去生成等高线,可能很多朋友不太清楚,我现有一生成等高线的程序,主要代码如下,具体见附件!!!
int _map_draw()
{
struct resbuf rb; /*供存取AutoCAD系统变量之用*/
char str[20],map_dat[320];
int i,pos,c,error_flag=0,uds,re_num;
ads_real equal_val,ang;
struct resbuf *result;
char *token;
pt_temp0[Z]=pt_temp1[Z]=0.0;
if(tbl_check("STYLE","MAP_TXT")==RTERROR) {
acedCommand(RTSTR,"STYLE",RTSTR,"MAP_TXT",RTSTR,"TIMES.TTF",
RTSTR,"0",RTSTR,"1.0",RTSTR,"",RTSTR,"",RTSTR,"",0);
sprintf(tbuf,"字体样式MAP_TXT被创建.");
acedAlert(tbuf);
}
if(tbl_check("LAYER","MAP_OUTLINE")==RTERROR) {
layer_do("M","MAP_OUTLINE");
}
if(tbl_check("LAYER","MAP_TEXT")==RTERROR) {
layer_do("M","MAP_TEXT");
layer_edit("C","RED","MAP_TEXT");
}
if((result=acutNewRb(RTSTR))==NULL) {
acdbFail("\nUnable to allocate buffer.");
return RTERROR;
}
if((result->resval.rstring=(char *)malloc(80))==NULL) {
acdbFail("\nUnable to allocate string.");
return RTERROR;
}
if(acedGetFileD("选择已有的地形图数据文件",NULL,"MAP",2,result)
!=RTNORM) {
acutRelRb(result);
return RTERROR;
}
strcpy(map_name,result->resval.rstring);
acutRelRb(result);
acedGetVar("userr1",&rb); /*从系统变量userr1获取当前使用的比例值*/
scale=rb.resval.rreal;
if(scale==0.0) strcpy(tbuf,"1:1");
else {
if(scale<1.0) sprintf(tbuf,"1:%g",1.0/scale);
else sprintf(tbuf,"%g:1",scale);
}
sprintf(tbuf1,"\n请输入比例值<%s>:",tbuf);
if(acedGetString(1,tbuf1,str)==RTCAN) return RTERROR;
if(str[0]==EOS) strcpy(str,tbuf);
scale=atof(str); /*获取scale值*/
token=strchr(str,(int)':');
if(token==NULL) {
acutPrintf("\n比例输入有误.");
return RTERROR;
}
*token++;
if(atof(token)==0) {
acutPrintf("\n比例输入有误.");
return RTERROR;
}
scale/=atof(token); /*获取用户输入值,送scale变量*/
acutPrintf("\n ");
acutPrintf("\n是否要对所生成的等高线进行光顺?");
acutPrintf("\n0=不进行光顺处理; 1=进行光顺处理<%d>:",pedit_flag);
Int_input2(4,NULL,&pedit_flag,pedit_flag<2);
layer_do("S","MAP_OUTLINE");
if((fp=fopen(map_name,"rb"))==NULL) {
sprintf(tbuf,"文件 %s 不能打开!",map_name);
acedAlert(tbuf);
return RTERROR;
}
map_dat[0]=EOS;
error_flag=0;
while((c=getc(fp))!=EOF) {
if(c==13) {
if((map_dat[0]>='0'&&map_dat[0]<='9')
||map_dat[0]=='+'||map_dat[0]=='-') {
equal_val=atof(map_dat); /*获取scale值*/
token=strchr(map_dat,(int)',');
if(token==NULL) {
acutPrintf("\n数据文件格式有误.");
error_flag=1;
break;
}
*token++;
pos=atoi(token); /*获取用户输入值,送scale变量*/
token=strchr(token,(int)':');
if(token==NULL) {
acutPrintf("\n数据文件格式有误.");
error_flag=1;
break;
}
*token++;
i=0;
acedCommand(RTSTR,"PLINE",RTNONE);
for(;;) {
if(i>0&&i<abs(pos)) {
Cpoint(pt_temp0,pt_temp1);
}
pt_temp1[X]=(atof(token))*scale;
token=strchr(token,(int)',');
if(token==NULL) {
acutPrintf("\n数据文件格式有误.");
error_flag=1;
break;
}
*token++;
pt_temp1[Y]=(atof(token))*scale;
token=strchr(token,(int)';');
i++;
if(i==abs(pos)) {
pt_temp0[X]=(pt_temp0[X]+pt_temp1[X])/2;
pt_temp0[Y]=(pt_temp0[Y]+pt_temp1[Y])/2;
ang=acutAngle(pt_temp0,pt_temp1);
if(pos<0) ang+=PI;
}
acedCommand(RTPOINT,pt_temp1,RTNONE);
if(token==NULL) break;
*token++;
}
acedCommand(0);
if(error_flag==0&&pedit_flag==1) {
acedCommand (RTSTR,"PEDIT",RTSTR,"L",RTSTR,"F",RTSTR,"",0);
}
if(error_flag==1) break;
layer_do("S","MAP_TEXT");
sprintf(tbuf,"%g",equal_val);
acedCommand(RTSTR,"TEXT",RTSTR,"BC",RTPOINT,pt_temp0,
RTREAL,3.2*scale,RTREAL,ang*180/PI,RTSTR,tbuf,0);
layer_do("S","MAP_OUTLINE");
}
map_dat[0]=EOS;
}
else {
if(c!=10) sprintf(map_dat,"%s%c",map_dat,c);
}
}
fclose(fp);
acedCommand(RTSTR,"ZOOM",RTSTR,"ALL",0);
rb.restype=RTREAL;
rb.resval.rreal=scale;
acedSetVar("userr1",&rb); /*将新的比例值送userr1系统变量保存*/
return RTNORM;
} |
|