📄 maindlg.cpp
字号:
i ++;
yy = atoi(&(buf[i]));
x_count1 += xx;
y_count1 += yy;
}
if (fabs(yy) > 100)
i = 0;
fputc('\n',fpe);
if (fpe == tar_fpe)
line_n ++;
}
put_a_line_to_tar_fpe(char *buf)
{
int i,xx,yy;
for (i=0;i<strlen(buf);i++)
fputc(buf[i],tar_fpe);
if ((buf[0] == 'P')||(buf[0] == 'B')){
xx = atoi(&(buf[1]));
i = 0;
while (buf[i] != ' ')
i ++;
yy = atoi(&(buf[i]));
x_count1 += xx;
y_count1 += yy;
}
if (fabs(yy) > 100)
i = 0;
fputc('\n',tar_fpe);
line_n ++;
}
//main proc
trans_file(FILE *fr_file,FILE *to_file)
{
int ret,b_pos,b_p,i,flag,order,order1;
char buf1[100],buf2[20],bufl[100],bufbak[100];
float ff;
FILE *t_fpe;
int b_flagl,flagl,rr;
long ll;
float bx,by,mx,my,ex,ey,a1,a2;
long countl;
line_n = 0;
b_flagl = 0;
countl = 0;
sub_flag = add_flag = 1;
t_fpe = fopen("c:\\jgs\\temp.g","w");
ret = 0;
first_flag = 1;
while (ret == 0){
ret = get_a_line(fr_file);
if (ret == -1)
break;
b_pos = 0;
if (buf[0] == 'N'){
i = 1;
while (((buf[i] >= '0')&&(buf[i] <= '9'))||(buf[i] == ' '))
i ++;
b_pos = i;
}
if ((buf[b_pos] == 'G')&&(buf[b_pos+1] == '9')&&(buf[b_pos+2] == '2')){
b_p = b_pos;
while ((buf[b_p] != 'X')&&(buf[b_p] != 'x'))
b_p ++;
o_x = atof(&(buf[b_p+1]));
while ((buf[b_p] != 'Y')&&(buf[b_p] != 'y'))
b_p ++;
o_y = atof(&(buf[b_p+1]));
fprintf(t_fpe,"%s\n",buf);
}
else if (buf[b_pos] == 'G'){
i = b_pos + 1;
while (((buf[i] >= '0')&&(buf[i] <= '9'))||(buf[i] == ' '))
i ++;
b_p = i;
flag = atoi(&(buf[b_pos+1]));
line_flag = flag;
switch (flag){
case 0:
trans_line(b_p,t_fpe);
break;
case 1:
trans_line(b_p,t_fpe);
break;
case 2:
trans_circ(b_p,t_fpe,2);
break;
case 3:
trans_circ(b_p,t_fpe,3);
break;
}
}
else if ((buf[b_pos] == 'X')||(buf[b_pos] == 'Y')){
b_p = b_pos;
switch (flag){
case 0:
trans_line(b_p,t_fpe);
break;
case 1:
trans_line(b_p,t_fpe);
break;
case 2:
trans_circ(b_p,t_fpe,2);
break;
case 3:
trans_circ(b_p,t_fpe,3);
break;
}
}
else
fprintf(t_fpe,"%s\n",buf);
}
fclose(t_fpe);
fclose(fr_file);
tar_fpe = to_file;
fr_file = fopen("c:\\jgs\\temp.g","rb");
ret = 0;
begin_flag = 1;
cur_speed = xydspeed;
order1 = 1;
while (ret == 0){
order1 ++;
ret = get_a_line(fr_file);
if (fabs(x_count1-e_x*100) > 2)
ret = ret;
if (ret == -1)
strcpy(buf,"");
b_pos = 0;
if (buf[0] == 'N'){
i = 1;
while (((buf[i] >= '0')&&(buf[i] <= '9'))||(buf[i] == ' '))
i ++;
b_pos = i;
}
if (buf[b_pos] == 'F'){
cur_speed = atof(&(buf[b_pos+1]));
cur_speed /= 60;
if (cur_speed < xmaxv1){
xmaxv = cur_speed*60;
ymaxv = cur_speed*60;
x_once_max_v_pulses = xmaxv*xsteps*interval/(1000.0);
y_once_max_v_pulses = ymaxv*ysteps*interval/(1000.0);
x_once_max_v_pulses /= 60;
y_once_max_v_pulses /= 60;
x_times = x_once_max_v_pulses/x_once_max_a_pulses;
if (x_times > 0)
x_once_max_v_pulses = x_once_max_a_pulses*x_times;
x_len_to_acc = 0;
for (i=0;i<x_times;i++){
x_len_to_acc += (i+1)*x_once_max_a_pulses;
}
y_times = y_once_max_v_pulses/y_once_max_a_pulses;
if (y_times > 0)
y_once_max_v_pulses = y_once_max_a_pulses*y_times;
y_len_to_acc = 0;
for (i=0;i<y_times;i++){
y_len_to_acc += (i+1)*y_once_max_a_pulses;
}
}
}
else if (buf[b_pos] == 'M'){
order = atoi(&(buf[b_pos+1]));
for (i=0;i<end_output;i++)
if (order == output[i].order){
if (mode == 1){
// put_a_line(to_file,"P0 0");
put_a_line(to_file,"A2");
put_a_line(to_file,"=2Q0 1Q0");
}
strcpy(buf1,"O ");
itoa(output[i].value,buf2,10);
strcat(buf1,buf2);
itoa(63,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
begin_flag = 1;
}
// if (order == 2){
// put_a_line(to_file,"A2");
// put_a_line(to_file,"S2");
// put_a_line(to_file,"E");
// }
}
else if ((buf[b_pos] == 'G')&&(buf[b_pos+1] == '9')&&(buf[b_pos+2] == '2')){
b_p = b_pos;
while ((buf[b_p] != 'X')&&(buf[b_p] != 'x'))
b_p ++;
o_x = atof(&(buf[b_p+1]));
while ((buf[b_p] != 'Y')&&(buf[b_p] != 'y'))
b_p ++;
o_y = atof(&(buf[b_p+1]));
}
else if (buf[b_pos] == 'G'){
i = b_pos + 1;
while (((buf[i] >= '0')&&(buf[i] <= '9'))||(buf[i] == ' '))
i ++;
b_p = i;
flag = atoi(&(buf[b_pos+1]));
if ((flag >= 0)&&(flag <= 3)){
if (begin_flag == 1){
strcpy(buf1,"=1Q2 2Q2 1TD");
itoa(interval,buf2,10);
strcat(buf1,buf2);
strcat(buf1," 2TD");
strcat(buf1,buf2);
strcat(buf1," MSL11X MSS");
put_a_line(to_file,buf1);
begin_flag = 0;
mode = 1;
}
}
switch (flag){
break;
case 0:
case 1:
if ((flag == 0)&&(!dk_flag))
set_data();
ll = ftell(fr_file);
if (b_flagl == 1){
flagl = 0;
strcpy(bufl,buf);
strcpy(bufbak,buf);
while (flagl == 0){
rr = get_a_line(fr_file);
if (rr == -1)
break ;
i = 0;
while ((i < strlen(buf))&&(buf[i] != 'G'))
i ++;
if (buf[i] == 'G'){
if ((buf[i+1] == '1')||((buf[i+1] == '0')&&(buf[i+2] == '1'))){
flagl = 1;
}
if (((buf[i+1] == '0')&&((buf[i+2] < '0')||(buf[i+2] > '9')))||((buf[i+1] == '0')&&(buf[i+2] == '0'))){
flagl = 1;
}
}
}
if (flagl == 1){
bx = x_ps/xsteps;
by = y_ps/ysteps;
i = 0;
while (bufl[i] != 'X')
i ++;
mx = atof(&(bufl[i+1]));
i = 0;
while (bufl[i] != 'Y')
i ++;
my = atof(&(bufl[i+1]));
//石少林 2002/4/22 将0.2改为0.0002
if (fabs(mx-bx)+fabs(my-by) < 0.0002){
goto a;
}
i = 0;
while (buf[i] != 'X')
i ++;
ex = atof(&(buf[i+1]));
i = 0;
while (buf[i] != 'Y')
i ++;
ey = atof(&(buf[i+1]));
a1 = asin((my-by)/sqrt((mx-bx)*(mx-bx)+(my-by)*(my-by)))*180/3.14159;
a2 = asin((ey-my)/sqrt((ex-mx)*(ex-mx)+(ey-my)*(ey-my)))*180/3.14159;
if (sub_flag == 1)
add_flag = 1;
else
add_flag = 0;
if (fabs(a1-a2) > 30){
countl ++;
sub_flag = 1;
}
else{
sub_flag = 0;
}
}
strcpy(buf,bufbak);
if ((dk_flag == 1)&&(fabs(mx-bx) < 0.011)&&(fabs(ex-bx) < 0.011))
sub_flag = 0;
if ((dk_flag == 1)&&(fabs(my-by) < 0.001)&&(fabs(ex-mx) < 0.011)){
add_flag = 1;
sub_flag = 1;
}
}
fseek(fr_file,ll,SEEK_SET);
proc_line(b_p,to_file);
a:
b_flagl = 1;
fseek(fr_file,ll,SEEK_SET);
old_mode = 1;
if ((flag == 0)&&(!dk_flag)){
recover_data();
}
break;
case 2:
proc_circ(b_p,to_file,2);
old_mode = 2;
break;
case 3:
proc_circ(b_p,to_file,3);
old_mode = 3;
break;
case 4:
strcpy(buf1,"W");
i = 0;
while (buf[i] != 'P')
i ++;
strcat(buf1,&(buf[i+1]));
put_a_line(to_file,buf1);
break;
}
}
else if ((buf[b_pos] == 'X')||(buf[b_pos] == 'Y')){
flag = old_mode;
if ((flag >= 0)&&(flag <= 3)){
if (begin_flag == 1){
strcpy(buf1,"=1Q2 2Q2 1TD");
itoa(interval,buf2,10);
strcat(buf1,buf2);
strcat(buf1," 2TD");
strcat(buf1,buf2);
strcat(buf1," MSL11X MSS");
put_a_line(to_file,buf1);
begin_flag = 0;
mode = 1;
}
}
b_p = b_pos;
switch (flag){
case 0:
set_data();
proc_line(b_p,to_file);
recover_data();
old_mode = 1;
break;
case 1:
proc_line(b_p,to_file);
old_mode = 1;
break;
case 2:
proc_circ(b_p,to_file,2);
old_mode = 2;
break;
case 3:
proc_circ(b_p,to_file,3);
old_mode = 3;
break;
}
}
}
}
proc_circ(int b_p,FILE *to_file,int type)
{
}
trans_circ(int b_p,FILE *t_fpe,int type)
{
float I,J,cx,cy,r;
float ba,ea,an,len;
int i,j,num;
char chbak;
float step_len,step_an,n_an;
float n_x,n_y;
b_x = oldx;
b_y = oldy;
I = oldi;
J = oldj;
if (buf[b_p] == 'X'){
i = b_p + 1;
while ((buf[i] != 'Y')&&(buf[i] != 'I')&&(buf[i] != 'J')&&(buf[i] != 0))
i ++;
if (buf[i] != 0){
chbak = buf[i];
buf[i] = 0;
}
e_x = atof(&(buf[b_p+1]));
e_x -= o_x;
buf[i] = chbak;
i = b_p + 1;
while ((buf[i] != 'Y')&&(buf[i] != 0))
i ++;
if (buf[i] == 'Y'){
j = b_p + 1;
while ((buf[j] != 'I')&&(buf[j] != 'J')&&(buf[i] != 0))
j ++;
if (buf[j] != 0){
chbak = buf[j];
buf[j] = 0;
}
e_y = atof(&(buf[i+1]));
e_y -= o_y;
buf[j] = chbak;
}
else{
e_y = b_y;
}
}
else{
e_x = b_x;
e_y = atof(&(buf[b_p+1]));
e_y -= o_y;
}
i = b_p + 1;
while ((buf[i] != 'I')&&(buf[i] != 0))
i ++;
if (buf[i] == 'I'){
j = b_p + 1;
while ((buf[j] != 'J')&&(buf[i] != 0))
j ++;
if (buf[j] != 0){
chbak = buf[j];
buf[j] = 0;
}
I = atof(&(buf[i+1]));
buf[j] = chbak;
}
else
I = oldi;
i = b_p + 1;
while ((buf[i] != 'J')&&(buf[i] != 0))
i ++;
if (buf[i] == 'J'){
J = atof(&(buf[i+1]));
}
else
J = oldj;
cx = I + b_x;
cy = J + b_y;
r = sqrt((b_x-cx)*(b_x-cx)+(b_y-cy)*(b_y-cy));
ba = count_angle(cx,cy,b_x,b_y);
ea = count_angle(cx,cy,e_x,e_y);
an = ba;
if (ba > ea){
len = r*(ba-ea);
}
else{
len = r*(ba + 2*PI - ea);
}
if (type == 3) // 2 clock wise
len = r*2*PI - len; // 3 anti clock wise
if ((fabs(ba-ea) < 0.0001) || (fabs(fabs(ba-ea)-2*PI) < 0.0001))
len = r*2*PI;
num = len;
if (num > 0){
for (i=0;i<num;i++){
step_len = len/num;
step_an = step_len / r;
if (type == 3){ // anti clock wise
n_an = ba + (i+1)*step_an;
}
else{
n_an = ba - (i+1)*step_an;
}
n_x = cx + r*cos(n_an);
n_y = cy + r*sin(n_an);
fprintf(t_fpe,"G01X%fY%f\n",n_x,n_y);
}
}
else{
fprintf(t_fpe,"G01X%fY%f\n",e_x,e_y);
}
oldx = e_x;
oldy = e_y;
}
trans_line(int b_p,FILE *to_file)
{
int i;
char outs[5];
b[0] = oldx;
b[1] = oldy;
if (buf[b_p] == 'X'){
e[0] = atof(&(buf[b_p+1]));
e[0] -= o_x;
i = b_p + 1;
while ((buf[i] != 'Y')&&(buf[i] != 0))
i ++;
if (buf[i] == 'Y'){
e[1] = atof(&(buf[i+1]));
e[1] -= o_y;
}
else{
e[1] = b[1];
}
}
else{
e[0] = b[0];
e[1] = atof(&(buf[b_p+1]));
e[1] -= o_y;
}
oldx = e[0];
oldy = e[1];
itoa(line_flag,outs,10);
// if (trans_g_file_flag == 1){
// if (first_flag == 1){
// first_flag = 0;
// fprintf(to_file,"G92X%fY%f\n",e[0],e[1]);
// }
// }
fprintf(to_file,"G0%sX%fY%f\n",outs,e[0],e[1]);
}
proc_line(int b_p,FILE *to_file)
{
int i,j,flag;
int a_times,times[2];
int s,v,a_s_ps,max_times;
int a,num,p,half_ps,k,m;
long run_ps,all_ps,ll;
float ps[2];
int left,aver_add,left_add,type;
float l1,l2,l3,an;
double df;
float b_x,e_x,b_y,e_y,n_x,n_y;
float old_x_ps,old_y_ps;
pulses_per_unit[0] = xsteps;
pulses_per_unit[1] = ysteps;
xyrate = pulses_per_unit[0]/pulses_per_unit[1];
vmax = x_once_max_v_pulses;
b[0] = x_ps/pulses_per_unit[0];
b[1] = y_ps/pulses_per_unit[1];
bb_x = x_ps;
bb_y = y_ps;
if (buf[b_p] == 'X'){
e[0] = atof(&(buf[b_p+1]));
e[0] -= o_x;
i = b_p + 1;
while ((buf[i] != 'Y')&&(buf[i] != 0))
i ++;
if (buf[i] == 'Y'){
e[1] = atof(&(buf[i+1]));
e[1] -= o_y;
}
else{
e[1] = b[1];
}
}
else{
e[0] = b[0];
e[1] = atof(&(buf[b_p+1]));
e[1] -= o_y;
}
if (fabs(e[0]-b[0]) + fabs(e[1]-b[1]) < 0.0001)
return -1;
if (fabs(e[0]) + fabs(e[1]) < 0.0001)
i = 0;
oldx = b[0];
oldy = b[1];
b_x = b[0]; b_y = b[1]; e_x = e[0]; e_y = e[1];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -