?? mshowdoc.cpp
字號:
if (GSim[CodeNum].sflag == 1)
{
sprintf(bf,"Line %d S error",CodeLine+1);
return 1;
}
GSim[CodeNum].sflag = 1;
GCodeNow.sflag = 1;
if ((GSen[i+1]<'0') || (GSen[i+1] >'9') )
{
sprintf(bf,"Line %d S error",CodeLine+1);
return 1;
}
fd = atoi(&GSen[i+1]);
if (fd>S_MAX)
{
sprintf(bf,"Line %d S error",CodeLine+1);
return 1;
}
GSim[CodeNum].s = fd;
GCodeNow.s = fd;
break;
case 'f':
case 'F':
if (GSim[CodeNum].fflag == 1)
{
sprintf(bf,"Line %d F error",CodeLine+1);
return 1;
}
GSim[CodeNum].fflag = 1;
GCodeNow.fflag = 1;
if ((GSen[i+1]<'0') || (GSen[i+1] >'9') )
{
sprintf(bf,"Line %d F error",CodeLine+1);
return 1;
}
fd = atoi(&GSen[i+1]);
if (fd>F_MAX)
{
sprintf(bf,"Line %d F error",CodeLine+1);
return 1;
}
GSim[CodeNum].f = fd;
GCodeNow.f = fd;
break;
case 'm':
case 'M':
if (fd<0||fd>99)
{
sprintf(bf,"Line %d M error",CodeLine+1);
return 1;
}
GSim[CodeNum].mflag = 1;
GCodeNow.mflag = 1;
fd = atoi(&GSen[i+1]);
GSim[CodeNum].m = fd;
GCodeNow.m = fd;
break;
case ' ': /*Space*/
break;
case '\n':
break;
case EOF:
break; /*End Of File*/
default:
break;
}
}
return 0;
}
int CMshowDoc::CheckSen(char * GSen)
{
if ( ( nflag == 1)&& (NNow <= NOld) ) // Check N number inc
return 1;
if ((G92flag == 0)&& (xflag || yflag || zflag)&& (GSim[CodeNum].gflag == 0) )
if (G00Sign == 0xff)
return 1;
else
{
GSim[CodeNum].g = G00Sign;
GSim[CodeNum].gflag = 1;
GCodeNow.g = G00Sign;
GCodeNow.gflag = 1;
}
if ((tflag == 1) && (G40Sign == 2) )
{
Tr = - Tr;
tflag = 0;
}
NOld = NNow;
CodeLine++;
nflag = xflag = yflag = zflag = iflag = jflag = kflag = 0;
G92flag = 0;
return 0;
}
int CMshowDoc::CompTypeGet()
{
int i;
i = VectYNow * VectXOld - VectYOld * VectXNow;
/*
if ( ((G40Sign == 1)&&(GCodeNow.y * GCodeOld.x - GCodeNow.x * GCodeOld.y > 0) )
||((G40Sign == 2)&&(GCodeNow.y * GCodeOld.x - GCodeNow.x * GCodeOld.y < 0))
)*/
if ((G40Sign == 1) || (G40Sign == 3) || (G40Sign == 5) )
return i;
else
return (-i);
}
void CMshowDoc::VectGet()
{
if ((GCodeOld.g == 0) || (GCodeOld.g == 1) ) //直線
{
VectXOld = GCodeOld.x;
VectYOld = GCodeOld.y;
}
else if (GCodeOld.g == 2) //順圓
{
VectXOld = GCodeOld.y - GCodeOld.j;
VectYOld = GCodeOld.i - GCodeOld.x;
}
else if (GCodeOld.g == 3) //逆圓
{
VectXOld = -(GCodeOld.y - GCodeOld.j);
VectYOld = -(GCodeOld.i - GCodeOld.x);
}
if ((GCodeNow.g == 0) || (GCodeNow.g == 1) )
{
VectXNow = GCodeNow.x;
VectYNow = GCodeNow.y;
}
else if (GCodeNow.g == 2)
{
VectXNow = -GCodeNow.j;
VectYNow = GCodeNow.i;
// CenXNow = xOld + GCodeNow.i; //圓弧絕對坐標
// CenYNow = yOld + GCodeNow.j;
}
else if (GCodeNow.g == 3)
{
VectXNow = GCodeNow.j;
VectYNow = -GCodeNow.i;
}
DistOld = (double)sqrt((double)(VectXOld * VectXOld + VectYOld * VectYOld));
DistNow = (double)sqrt((double)(VectXNow * VectXNow + VectYNow * VectYNow));
}
void CMshowDoc::CutCompCalcu()
{
if (CutCompType > 0 )
{
xs =xOld - (int) (Tr * (VectYOld * DistNow + VectYNow * DistOld ) / ( DistOld * DistNow + VectXOld * VectXNow + VectYOld * VectYNow));
ys =yOld + (int) (Tr * (VectXOld * DistNow + VectXNow * DistOld ) / ( DistOld * DistNow + VectXOld * VectXNow + VectYOld * VectYNow));
if ((GCodeOld.g == 2) || (GCodeOld.g == 3) ) //前段為圓弧時,修正圓心
{
GCodeOld.i += xOld - GCodeOld.x - xLast;
GCodeOld.j += yOld - GCodeOld.y - yLast;
}
}
else if (CutCompType < 0)
{
xs = xOld - (int)(Tr * VectYOld / DistOld);
ys = yOld + (int)(Tr * VectXOld / DistOld);
if ((GCodeOld.g == 2) || (GCodeOld.g == 3) ) //前段為圓弧時,修正圓心
{
GCodeOld.i += xOld - GCodeOld.x - xLast;
GCodeOld.j += yOld - GCodeOld.y - yLast;
}
GCodeOld.x = xs - xLast;
GCodeOld.y = ys - yLast;
xLast = xs;
yLast = ys;
memcpy(&GCode[GCodeNum],&GCodeOld,sizeof(GCODE));
GCodeNum++;
xs = xOld - (int)(Tr * VectYNow / DistNow);
ys = yOld + (int)(Tr * VectXNow / DistNow);
GCodeOld.x = xs - xLast;
GCodeOld.y = ys - yLast;
GCodeOld.i = xOld - xLast; //圓弧過渡
GCodeOld.j = yOld - yLast;
if (G40Sign == 3)
GCodeOld.g = 2;
else
GCodeOld.g = 3;
}
else
{
xs = xOld - (int)(Tr * VectYOld / DistOld);
ys = yOld + (int)(Tr * VectXOld / DistOld);
if ((GCodeOld.g == 2) || (GCodeOld.g == 3) ) //前段為圓弧時,修正圓心
{
GCodeOld.i += xOld - GCodeOld.x - xLast;
GCodeOld.j += yOld - GCodeOld.y - yLast;
}
}
GCodeOld.x = xs - xLast;
GCodeOld.y = ys - yLast;
xLast = xs;
yLast = ys;
memcpy(&GCode[GCodeNum],&GCodeOld,sizeof(GCODE));
memcpy(&GCodeOld,&GCodeNow,sizeof(GCODE));
memset(&GCodeNow,0,sizeof(GCODE));
xOld = xNow;
yOld = yNow;
GCodeNum++;
}
int CMshowDoc::CutComp()
{
if (G40Sign == 0 )
{
memcpy(&GCode[GCodeNum],&GCodeNow,sizeof(GCODE));
memset(&GCodeNow,0,sizeof(GCODE));
GCodeNum++;
}
else if ( (G40Sign == 1)|| (G40Sign == 2) )
{
if(G40Beg == 0)
{
if (GCodeNow.gflag != 1)
{
sprintf(bf,"Line %d Cut Com Build error",CodeLine+1);
return 1;
}
if ((GCodeNow.g == 0) || (GCodeNow.g == 1))
{
memcpy(&GCodeOld,&GCodeNow,sizeof(GCODE));
xOld = xNow;
yOld = yNow;
memset(&GCodeNow,0,sizeof(GCODE));
G40Beg = 1;
}
else
{
sprintf(bf,"刀補建立必須在直線段上");
return 1;
}
}
else
{
if ((GCodeNow.gflag == 0) && (GCodeNow.mflag == 0) && (GCodeNow.sflag == 0) && (GCodeNow.fflag == 0) )
return 0;
VectGet();
CutCompType = CompTypeGet();
if((GCodeNow.g == 0)||(GCodeNow.g == 1))
if ((GCodeNow.x == 0) && (GCodeNow.y == 0) ) //沒有進給
{
sprintf(bf,"Line %d error",CodeLine+1);
return 1;
}
else
{ //缺少判誤 判斷接圓弧
}
if ( CutCompType > 0 ) //縮短型 直線接直線(或圓弧) 刀補建立
{
xs = xOld - (int)(Tr * VectYNow / DistNow) ;
ys = yOld + (int)(Tr * VectXNow / DistNow);
GCodeOld.x = xs - DUIDAOX;
GCodeOld.y = ys - DUIDAOY;
xLast = xs;
yLast = ys;
memcpy(&GCode[GCodeNum],&GCodeOld,sizeof(GCODE));
memcpy(&GCodeOld,&GCodeNow,sizeof(GCODE));
memset(&GCodeNow,0,sizeof(GCODE));
xOld = xNow;
yOld = yNow;
GCodeNum++;
}
else
{
sprintf(bf,"刀補建立不是縮短型");
return 1;
}
G40Beg = 0;
if (G40Sign == 1)
G40Sign = 3;
else
G40Sign = 4;
}
}
else if ((G40Sign == 3)|| (G40Sign == 4) ) //刀補進行
{
if ((GCodeNow.gflag == 0) && (GCodeNow.mflag == 0) && (GCodeNow.sflag == 0) && (GCodeNow.fflag == 0) )
return 0;
VectGet();
CutCompType = CompTypeGet();
CutCompCalcu();
}
else //刀補撤銷
{
VectGet();
CutCompType = CompTypeGet();
if((GCodeNow.g == 0)||(GCodeNow.g ==1))
if ((GCodeNow.x == 0) && (GCodeNow.y == 0) ) //沒有進給
{
sprintf(bf,"Line %d error",CodeLine+1);
return 1;
}
else
{ //缺少判誤 判斷接圓弧
}
if ( CutCompType > 0 ) //縮短型 直線(或圓弧)接直線 刀補撤銷
{
xs = xOld - (int)(Tr * VectYOld / DistOld);
ys = yOld + (int)(Tr * VectXOld / DistOld);
if ((GCodeOld.g == 2) || (GCodeOld.g == 3))
{
GCodeOld.i += xOld - GCodeOld.x;
GCodeOld.j += yOld - GCodeOld.y;
}
GCodeOld.x = xs - xLast;
GCodeOld.y = ys - yLast;
memcpy(&GCode[GCodeNum],&GCodeOld,sizeof(GCODE));
GCodeNum++;
GCodeOld.x = xNow - xs;
GCodeOld.y = yNow - ys;
xLast = xNow;
yLast = yNow;
memcpy(&GCode[GCodeNum],&GCodeOld,sizeof(GCODE));
memset(&GCodeNow,0,sizeof(GCODE));
GCodeNum++;
}
else
{
sprintf(bf,"刀補撤銷不是縮短型");
return 1;
}
// G40End = 1;
G40Sign = 0;
// }
/*
else
{
memcpy(&GCode[GCodeNum],&GCodeOld,sizeof(GCODE));
GCodeNum++;
if ((GCodeNow.gflag == 0) && (GCodeNow.mflag == 0) && (GCodeNow.sflag == 0) && (GCodeNow.fflag == 0) )
return 0;
else
{
memcpy(&GCode[GCodeNum],&GCodeNow,sizeof(GCODE));
GCodeNum++;
}
G40Sign = 0;
G40End = 0;
}*/
}
return 0;
}
void CMshowDoc::Init()
{
for (int i=0;i<50;i++)
{
memset(&GSim[i],0,sizeof(GCODE));
memset(&GCode[i],0,sizeof(GCODE));
}
memset(&GCodeNow,0,sizeof(GCODE));
memset(&GCodeOld,0,sizeof(GCODE));
GCodeNum = 0;
G91Sign = 0;
G92flag = 0;
nflag = xflag = yflag = zflag = iflag = jflag = kflag = tflag = 0;
CodeLine = 0;
NOld = -1;
NNow = 0;
G00Sign = 0xff;
G40Sign = 0; //默認 無刀補
// memset( &GDataOld, 0, sizeof(GDATA));
// memset( &GDataNew, 0, sizeof(GDATA));
G40Beg = 0;
// G40End = 0;
datumx = DUIDAOX;datumy = DUIDAOY; datumz = DUIDAOZ;
tx = ty = tz = 0;
mchx = datumx + tx;
mchy = datumy + ty;
mchz = datumz + tz;
G31x = G31y =G31z = 0;
G53x = 400;
G53y = 0;
G53z = 0;
xNow = mchx;
yNow = mchy;
zNow = mchz;
xOld = xNow;
yOld = yNow;
xLast = xNow;
yLast = yNow;
}
void CMshowDoc::List()
{
CStdioFile myinputfile;
BOOL isend=TRUE;
myinputfile.Open(FileName,CFile::modeRead| CFile::typeText );
CString mystring[100];
int number=0;
while (isend)
{
isend = myinputfile.ReadString(mystring[number]);
if (isend)
{
number++;
}
else
number--;
}
myinputfile.Close();
CMshowView *pMshowview = (CMshowView*)((CMainFrame*)AfxGetMainWnd())->GetActiveView();
((CListBox *)(((CMainFrame*)AfxGetMainWnd())->m_wndDialogBar.GetDlgItem(IDC_LIST)))->ResetContent();
for(int i=0;i<=number;i++)
{
((CListBox *)(((CMainFrame*)AfxGetMainWnd())->m_wndDialogBar.GetDlgItem(IDC_LIST)))->InsertString(i,mystring[i]);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -