Introduction
After 6 months of work, here is finally my first MFC program release. This program is a CAM simulator. I am not a software engineer, so please forgive me for errors. If you have questions please let me know. I am sure that you will find them. The lecture of data files was a big problem to me at the beginning, so here is the implementation. I needed to read *.txt files, what the CNC machine generate. Here is an example M X25 Y23 Z25 SPEED1500. This is a block of data, needed to setup the machines. This is a kind of language that the machine use to move on the coordinates over the work space. So in this implementation you can read a full document, splitting the block in the necessary X Y Z and SPEED values. This is my first upload, I have more things to say about this program I will try to improve soon, this short commentary.
void CProgramaDoc::OnFileOpen()
{
CString fichero="archivo de C�digo G",temp;
CFileDialog archivos(true,NULL,fichero,OFN_ALLOWMULTISELECT,
"Codigo G (*.tap)|*.tap|Codigo G (*.act)|*.act||",NULL);
if (archivos.DoModal() == FALSE) return;
fichero=archivos.GetPathName();
CFile cfFile (fichero, CFile::modeNoTruncate | CFile::modeRead);
CArchive ar (&cfFile, CArchive::load);
if(!ar.ReadString(temp)) return;
nl=0;
do
{
if(temp.GetLength() == 0) continue;
strcpy(linea[nl],temp);
nl++;
}while(ar.ReadString(temp));
int i,j,k,d,sp;
char aux[30];
for ( i=0; i<5000; i++)
{
x[i] = y[i] = z[i] = 0;
}
kn=0;
for (i=0;i<nl;i++)
{
if (linea[i][0]=='S');
{
Inicio=1;
}
if (linea[i][0]=='M');
{
sp = 0;
k = 0;
d = strlen(linea[i]);
for (j=0;j<d;j++)
{
if ((linea[i][j]=='-')|(isdigit(linea[i][j]))|
(linea[i][j]=='.'))
{
aux[k] = linea[i][j];
k++;
continue;
}
if (linea[i][j]==' ')
{
sp++;
if (sp==1) continue;
aux[k]=0;
if (sp==2)
if ((aux[0]=='-')|(isdigit(aux[0]))|(aux[0]=='.'))
x[kn] = atof(aux);
else
x[kn] = x[kn-1];
if (sp==3)
if ((aux[0]=='-')|(isdigit(aux[0]))|(aux[0]=='.'))
y[kn] = atof(aux);
else
y[kn] = y[kn-1];
if (sp==4)
if ((aux[0]=='-')|(isdigit(aux[0]))|(aux[0]=='.'))
z[kn] = atof(aux);
else
z[kn] = z[kn-1];
k = 0;
continue;
}
}
kn++;
j = d;
}
}
presentar = 1;
sumz = 0;
for (i=0; i<nl; i++)
{
sumz += abs(z[i]);
}
if (sumz == 0)
torno = 1;
else
fresa = 1;
UpdateAllViews(NULL);
}