增加CNC的文件保存和打开。

This commit is contained in:
TAO Cheng
2013-08-08 09:33:19 +08:00
parent 5a8e27e70d
commit a7ccbac4d6
11 changed files with 303 additions and 46 deletions
@@ -1,4 +1,6 @@
#pragma once
#define MAX_BUFF_SIZE 0x200
enum EEntityType
{
etUnknow = 0,
@@ -19,9 +19,9 @@ public:
virtual int get_type() = 0;
virtual void SaveCmd(CString _filename,int _savetype=0) = 0;
virtual void SaveCmd(FILE* _filestream,int _savetype=0) = 0;
virtual void ReadCmd(CString _filename,int _savetype=0) = 0;
virtual void ReadCmd(FILE* _filestream,int _savetype=0) = 0;
virtual void GetPoint(int type_of_point,
int theo_or_meas,
@@ -89,14 +89,86 @@ void CSo7_CNC_Point::PutPoint(int type_of_point,int theo_or_meas,int coord_sys,C
}
//===================================================
void CSo7_CNC_Point::SaveCmd(CString _filename,int _savetype)
void CSo7_CNC_Point::SaveCmd(FILE* _filestream,int _savetype)
{
UNREFERENCED_PARAMETER(_filename);
m_TotalLines=8;
UNREFERENCED_PARAMETER(_savetype);
fprintf(_filestream,"[etPoint]\n");
fprintf(_filestream,"ENTITYTYPE=%d\n", etPoint);
fprintf(_filestream,"TOTALLINES=%d\n", m_TotalLines);
fprintf(_filestream,"ID=%d\n", m_ID);
fprintf(_filestream,"POSX=%9.6f\n",m_Pos.x);
fprintf(_filestream,"POSY=%9.6f\n",m_Pos.y);
fprintf(_filestream,"POSZ=%9.6f\n",m_Pos.z);
fprintf(_filestream,";\n");
}
//===================================================
void CSo7_CNC_Point::ReadCmd(CString _filename,int _savetype)
void CSo7_CNC_Point::ReadCmd(FILE* _filestream,int _savetype)
{
UNREFERENCED_PARAMETER(_filename);
UNREFERENCED_PARAMETER(_savetype);
char szLine[MAX_BUFF_SIZE];
char *token = NULL;
char seps[] = " =,\t\n";
char cTemp[20]={0};
m_TotalLines=0;
fgets(szLine,MAX_BUFF_SIZE,_filestream);//read a line
if((szLine[0]!=';')&&(strlen(szLine)>2))
{
token = strtok(szLine,seps);
if(!_stricmp(token,"TOTALLINES"))
{
token = strtok( NULL, seps);
if (token)
{
strcpy(cTemp,token);
m_TotalLines=atoi(cTemp);
}
}
}
for (int i=0;i<(m_TotalLines-2);i++)
{
fgets(szLine,MAX_BUFF_SIZE,_filestream);//read a line
if((szLine[0]!=';')&&(strlen(szLine)>2))
{
token = strtok(szLine,seps);
if(!_stricmp(token, "ID"))
{
token = strtok( NULL, seps);
if (token)
{
strcpy(cTemp,token);
m_ID=atoi(cTemp);
}
}
else if(!_stricmp(token, "POSX"))
{
token = strtok( NULL, seps);
if (token)
{
strcpy(cTemp,token);
m_Pos.x=atof(cTemp);
}
}
else if(!_stricmp(token, "POSY"))
{
token = strtok( NULL, seps);
if (token)
{
strcpy(cTemp,token);
m_Pos.y=atof(cTemp);
}
}
else if(!_stricmp(token, "POSZ"))
{
token = strtok( NULL, seps);
if (token)
{
strcpy(cTemp,token);
m_Pos.z=atof(cTemp);
}
}
}
}
}
@@ -9,14 +9,15 @@ public:
CSo7_CNC_Point& operator=(const CSo7_CNC_Point& _CNC_Point);
protected:
int m_TotalLines;
void Init();
public:
CPoint3 m_Pos;
CSO7_CMD* Copy();
int get_id();
int get_type();
void SaveCmd(CString _filename,int _savetype=0);
void ReadCmd(CString _filename,int _savetype=0);
void SaveCmd(FILE* _filestream,int _savetype=0);
void ReadCmd(FILE* _filestream,int _savetype=0);
void GetPoint(int type_of_point,
int theo_or_meas,
@@ -1,6 +1,7 @@
#include "StdAfx.h"
#include "CSO7_CMD.h"
#include "So7_CNC_Point.h"
#include "So7_CNC_Program.h"
//=====================================
@@ -73,14 +74,71 @@ BOOL CSo7_CNC_Program::IsEmpty()
};
//================================================================================================
void CSo7_CNC_Program::Load(CString _csProgFile)
void CSo7_CNC_Program::open()
{
UNREFERENCED_PARAMETER(_csProgFile);
FILE* m_pLoadFile=NULL;
char szLine[MAX_BUFF_SIZE];
char *token = NULL;
char seps[] = " =,\t\n";
char cTemp[20]={0};
int EntityType=0;
_wfopen_s(&m_pLoadFile,m_CncProgFileName,_T("rt"));
if(m_pLoadFile)
{
while (!feof(m_pLoadFile))
{
fgets(szLine,MAX_BUFF_SIZE,m_pLoadFile);//read a line
if((szLine[0]!=';')&&(strlen(szLine)>2))
{
token = strtok(szLine,seps);
if(!_stricmp(token,"ENTITYTYPE"))
{
token = strtok( NULL, seps);
if (token)
{
strcpy(cTemp,token);
EntityType=atoi(cTemp);
Load(m_pLoadFile,EntityType);
}
}
}
}
}
};
//================================================================================================
void CSo7_CNC_Program::Load(FILE* _pLoadFile,int _EntityType)
{
switch(_EntityType)
{
case etPoint:
{
CPoint3 Pos;
CSO7_CMD* pEntity=new CSo7_CNC_Point(Pos);
pEntity->ReadCmd(_pLoadFile);
m_CNC_element.push_back(pEntity);
m_Program_Number++;
}
break;
default:
break;
}
};
//================================================================================================
void CSo7_CNC_Program::Save()
{
FILE* m_pOutFile=NULL;
_wfopen_s(&m_pOutFile, m_CncProgFileName, _T("wt"));
if (m_pOutFile)
{
for(int i=0;i<m_Program_Number;i++)
m_CNC_element[i]->SaveCmd(m_pOutFile);
fclose(m_pOutFile);
}
};
@@ -98,3 +156,20 @@ void CSo7_CNC_Program::Initialize(void)
{
InitNew();
};
//================================================================================================
CString CSo7_CNC_Program::GetEntityName(int _EntityType)
{
CString rCStr("");
switch(_EntityType)
{
case etPoint:
{
rCStr=_T("CNC Point");
}
break;
default:
break;
}
return rCStr;
}
@@ -5,7 +5,8 @@ public:
CSo7_CNC_Program(void);
~CSo7_CNC_Program(void);
void Initialize();
void Load(CString _csProgName);
void Load(FILE* _pLoadFile,int _EntityType);
void open();
void Save();
void Close();
void AddCncStep(CSO7_CMD* pProgStep);
@@ -13,6 +14,7 @@ public:
int InitNew();
void RemoveAll();
BOOL IsEmpty();
CString GetEntityName(int _EntityType);
std::vector<CSO7_CMD*> m_CNC_element;
CSO7_CMD* _pCurrCncStep;
int m_Program_Number;