📄 maindlg.cpp
字号:
for (i=0;i<end_arr;i++){
if (xarr[i] != NULL)
free(xarr[i]);
if (yarr[i] != NULL)
free(yarr[i]);
}
return 1;
}
int cut(int n)
{
int k;
if (cutted[n] == 1)
return 1;
if (end_con[n] == 0){
order[n] = cur_order;
cur_order ++;
cutted[n] = 1;
return 1;
}
for (k=0;k<end_con[n];k++)
cut(con[n][k]);
order[n] = cur_order;
cur_order ++;
cutted[n] = 1;
return 1;
}
trans_g_to_23_code()
{
FILE *fp;
int i,times,ch;
fp = fopen("c:\\jgs\\setup1.fil","rb");
if (fp == NULL){
return -1;
}
load_mac_para(fp);
xmaxv1 = xmaxv; // Max Speed units(G CODE) per danwei
ymaxv1 = ymaxv;
x_once_max_a_pulses = xmaxa*xsteps*interval/1000.0;
y_once_max_a_pulses = ymaxa*ysteps*interval/1000.0;
x_once_max_a_pulses /= (1000/interval);
y_once_max_a_pulses /= (1000/interval);
x_once_max_v_pulses = xmaxv*xsteps*interval/1000.0;
y_once_max_v_pulses = ymaxv*ysteps*interval/1000.0;
if (danwei == MINUTES){
x_once_max_a_pulses /= 60.0;
y_once_max_a_pulses /= 60.0;
x_once_max_v_pulses /= 60.0;
y_once_max_v_pulses /= 60.0;
}
x_times = x_once_max_v_pulses/x_once_max_a_pulses;
if (x_times > 1)
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 > 1)
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;
}
fclose(fp);
return trans_g_to_23();
// printf("If You Want To Send, Press Enter!\n");
// ch = getch();
// if (ch == 13)
// send_file();
}
trans_gfile_to_23_code()
{
FILE *fp;
int i,times,ch;
b_x = b_y = e_x = e_y = o_x = o_y = 0;
x_count=0;
y_count=0;
x_count1=0;
y_count1=0;
end_wait=0;
end_output=0;
x_adj=0;
y_adj=0;
mode=0;
oldxx=0;
oldyy=0;
fp = fopen("c:\\jgs\\setup1.fil","rb");
if (fp == NULL){
return -1;
}
load_mac_para(fp);
xmaxv1 = xmaxv; // Max Speed units(G CODE) per danwei
ymaxv1 = ymaxv;
x_once_max_a_pulses = xmaxa*xsteps*interval/1000.0;
y_once_max_a_pulses = ymaxa*ysteps*interval/1000.0;
x_once_max_a_pulses /= (1000/interval);
y_once_max_a_pulses /= (1000/interval);
x_once_max_v_pulses = xmaxv*xsteps*interval/1000.0;
y_once_max_v_pulses = ymaxv*ysteps*interval/1000.0;
if (danwei == MINUTES){
x_once_max_a_pulses /= 60.0;
y_once_max_a_pulses /= 60.0;
x_once_max_v_pulses /= 60.0;
y_once_max_v_pulses /= 60.0;
}
x_times = x_once_max_v_pulses/x_once_max_a_pulses;
if (x_times > 1)
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 > 1)
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;
}
fclose(fp);
return trans_gfile_to_23();
}
/*
get_a_line(FILE *fpe)
{
int i,ch;
ch = fgetc(fpe);
if (ch == EOF)
return -1;
i = 0;
while ((ch != 13)&&(ch != 10)&&(ch != EOF)){
buf[i++] = ch;
ch = fgetc(fpe);
}
buf[i] = 0;
if (ch == EOF)
return -1;
fgetc(fpe);
return 0;
}
*/
load_mac_para(FILE *fpe)
{
int ret,order,value,i;
int step,len;
ret = 0;
step = 0;
while (ret == 0){
ret = get_a_line(fpe);
if ((buf[0] == 'I')&&(step == 0)){
get_a_line(fpe);
board_no = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'P')&&(step == 1)){
test_dog();
get_a_line(fpe);
pulse_rate = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'U')&&(step == 2)){
get_a_line(fpe);
interval = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'X')&&(buf[1] == 'S')&&(step == 3)){
get_a_line(fpe);
xsteps = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'Y')&&(buf[1] == 'S')&&(step == 4)){
get_a_line(fpe);
ysteps = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'Z')&&(buf[1] == 'S')&&(step == 5)){
get_a_line(fpe);
zsteps = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'm')||(buf[0] == 's')&&(step == 6)){
if (buf[0] == 'm')
danwei = MINUTES;
else
danwei = SECONDS;
step ++;
}
else if ((buf[0] == 'X')&&(buf[1] == 'M')&&(step == 7)){
get_a_line(fpe);
xmaxv2 = xmaxv = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'Y')&&(buf[1] == 'M')&&(step == 8)){
get_a_line(fpe);
ymaxv2 = ymaxv = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'Z')&&(buf[1] == 'M')&&(step == 9)){
get_a_line(fpe);
zmaxv2 = zmaxv = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'X')&&(buf[1] == 'M')&&(step == 10)){
get_a_line(fpe);
xmaxa2 = xmaxa = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'Y')&&(buf[1] == 'M')&&(step == 11)){
get_a_line(fpe);
ymaxa2 = ymaxa = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'Z')&&(buf[1] == 'M')&&(step == 12)){
get_a_line(fpe);
zmaxa2 = zmaxa = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'X')&&(step == 13)){
get_a_line(fpe);
xydspeed = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'Z')&&(step == 14)){
get_a_line(fpe);
zdspeed = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'M')&&(step == 15)){
get_a_line(fpe);
max_accu_arc = atof(&(buf[0]));
}
else if ((buf[0] == 'W')&&(step == 16)){
get_a_line(fpe);
order = atol(&(buf[0]));
get_a_line(fpe);
for (i=0;i<strlen(buf);i++)
if (buf[i] == 'X')
buf[i] = '0';
for (i=0;i<strlen(buf);i++)
buf[i] -= '0';
value = buf[0] * 32 + buf[1] * 16 + buf[2] * 8 + buf[3] * 4 +
buf[4] * 2 + buf[5];
wait[end_wait].order = order;
wait[end_wait++].value = value;
}
else if ((buf[0] == 'S')&&(step == 15)){
get_a_line(fpe);
order = atol(&(buf[0]));
get_a_line(fpe);
for (i=0;i<strlen(buf);i++)
if (buf[i] == 'X')
buf[i] = '0';
len = strlen(buf);
for (i=0;i<len;i++)
buf[i] -= '0';
value = buf[0] * 32 + buf[1] * 16 + buf[2] * 8 + buf[3] * 4 +
buf[4] * 2 + buf[5];
output[end_output].order = order;
output[end_output++].value = value;
}
else if ((buf[0] == 'X')&&(buf[1] == 'H')&&(step == 15)){
get_a_line(fpe);
xhl = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'X')&&(buf[1] == 'L')&&(step == 16)){
get_a_line(fpe);
xll = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'Y')&&(buf[1] == 'H')&&(step == 17)){
get_a_line(fpe);
yhl = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'Y')&&(buf[1] == 'L')&&(step == 18)){
get_a_line(fpe);
yll = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'Z')&&(buf[1] == 'H')&&(step == 19)){
get_a_line(fpe);
zhl = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'Z')&&(buf[1] == 'L')&&(step == 20)){
get_a_line(fpe);
zll = atol(&(buf[0]));
step ++;
}
else if ((buf[0] == 'G')&&(buf[1] == 'o')&&(step == 21)){
get_a_line(fpe);
strcpy(go_home_str,buf);
step ++;
strcpy(command_str,"");
}
else if ((buf[0] == 'I')&&(buf[1] == 'n')&&(step == 22)){
get_a_line(fpe);
strcat(command_str," ");
strcat(command_str,buf);
}
}
}
trans_g_to_23()
{
FILE *fr_file;
strcpy(filename,"c:\\jgs\\test.g");
if (filename[strlen(filename)-2] != '.')
strcat(filename,".G");
fr_file = fopen(filename,"rb");
if (fr_file == NULL){
return -1;
}
filename[strlen(filename)-2] = 0;
// strcat(filename,".23");
// to_file = fopen(filename,"w");
to_file = fopen("c:\\jgs\\test.23","w");
if (to_file == NULL){
fclose(fr_file);
return -1;
}
put_a_line(to_file,"V1");
put_a_line(to_file,"I768");
put_a_line(to_file,"U20");
put_a_line(to_file,"N2");
strcpy(buf,"=");
strcat(buf,command_str);
put_a_line(to_file,buf);
trans_file(fr_file,to_file);
fclose(fr_file);
fclose(to_file);
return 1;
}
trans_gfile_to_23()
{
FILE *fr_file,*to_file;
FILE *wfpe;
int ch,oc;
if (filename[strlen(filename)-2] != '.')
strcat(filename,".G");
fr_file = fopen(filename,"rb");
if (fr_file == NULL){
return -1;
}
wfpe = fopen("c:\\jgs\\t.tmp","wb");
ch = fgetc(fr_file);
oc = ch;
while (ch != EOF){
if (ch == 'N'){
if ((oc != 10)&&(oc != 13)){
fputc(13,wfpe);
fputc(10,wfpe);
}
}
fputc(ch,wfpe);
oc = ch;
ch = fgetc(fr_file);
}
fclose(fr_file);
fclose(wfpe);
fr_file = fopen(filename,"wb");
wfpe = fopen("c:\\jgs\\t.tmp","rb");
ch = fgetc(wfpe);
while (ch != EOF){
fputc(ch,fr_file);
ch = fgetc(wfpe);
}
fclose(fr_file);
fclose(wfpe);
fr_file = fopen(filename,"rb");
if (fr_file == NULL){
return -1;
}
filename[strlen(filename)-2] = 0;
strcat(filename,".23");
// to_file = fopen(filename,"w");
to_file = fopen("c:\\jgs\\test.23","w");
if (to_file == NULL){
fclose(fr_file);
return -1;
}
put_a_line(to_file,"V1");
put_a_line(to_file,"I768");
put_a_line(to_file,"U20");
put_a_line(to_file,"N2");
strcpy(buf,"=");
strcat(buf,command_str);
put_a_line(to_file,buf);
trans_file(fr_file,to_file);
fclose(fr_file);
fclose(to_file);
return 1;
}
float count_angle(float x0, float y0, float x1, float y1)
{
float a;
if ((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0) < 1e-8)
return 0;
a = acos((x1-x0)/sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)));
if (y1 < y0)
a = 2*PI - a;
return a;
}
recover_data()
{
int i;
xmaxv = xmaxv3;
ymaxv = ymaxv3;
test_dog();
zmaxv = zmaxv3;
xmaxa = xmaxa3;
ymaxa = ymaxa3;
zmaxa = zmaxa3;
xmaxv1 = xmaxv; // Max Speed units(G CODE) per danwei
ymaxv1 = ymaxv;
x_once_max_v_pulses = xmaxv*xsteps*interval/(1000.0);
y_once_max_v_pulses = ymaxv*ysteps*interval/(1000.0);
if (danwei == MINUTES){
x_once_max_v_pulses /= 60.0;
y_once_max_v_pulses /= 60.0;
}
x_times = x_once_max_v_pulses/x_once_max_a_pulses;
if (x_times > 1)
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 > 1)
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;
}
}
set_data()
{
int i;
xmaxv3 = xmaxv;
ymaxv3 = ymaxv;
zmaxv3 = zmaxv;
xmaxa3 = xmaxa;
ymaxa3 = ymaxa;
zmaxa3 = zmaxa;
xmaxv = xmaxv2;
ymaxv = ymaxv2;
zmaxv = zmaxv2;
xmaxa = xmaxa2;
ymaxa = ymaxa2;
zmaxa = zmaxa2;
xmaxv1 = xmaxv; // Max Speed units(G CODE) per danwei
ymaxv1 = ymaxv;
x_once_max_v_pulses = xmaxv*xsteps*interval/(1000.0);
y_once_max_v_pulses = ymaxv*ysteps*interval/(1000.0);
if (danwei == MINUTES){
x_once_max_v_pulses /= 60.0;
y_once_max_v_pulses /= 60.0;
}
x_times = x_once_max_v_pulses/x_once_max_a_pulses;
if (x_times > 1)
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 > 1)
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;
}
}
void maindlg::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
// flag = 0;
}
get_a_line(FILE *fpe)
{
int i,ch,j;
long l;
ch = fgetc(fpe);
if (ch == EOF)
return -1;
i = 0;
while ((ch == 13)||(ch == 10))
ch = fgetc(fpe);
while ((ch != 13)&&(ch != 10)&&(ch != EOF)){
buf[i++] = ch;
ch = fgetc(fpe);
}
buf[i] = 0;
if (ch == EOF)
return -1;
ch = fgetc(fpe);
if (ch == EOF)
return -1;
strcpy(nbuf,"");
if ((ch == 13)||(ch == 10)){
ch = fgetc(fpe);
if (ch == EOF){
return 0;
}
}
j = 1;
i = 0;
while ((ch != 13)&&(ch != 10)&&(ch != EOF)){
nbuf[i++] = ch;
ch = fgetc(fpe);
j ++;
}
nbuf[i] = 0;
if (ch == EOF){
strcpy(nbuf,"");
j --;
}
l = -j;
fseek(fpe,l,SEEK_CUR);
return 0;
}
put_a_line(FILE *fpe,char *buf)
{
int i,xx,yy;
for (i=0;i<strlen(buf);i++)
fputc(buf[i],fpe);
if (buf[0] == 'P'){
xx = atoi(&(buf[1]));
i = 0;
while (buf[i] != ' ')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -