You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

428 lines
12 KiB
C++

#include "StdAfx.h"
#include "WorkFileMgr.h"
#include "GlobalDefine.h"
#include "TemplateMgr.h"
#include "WorkFileLable.h"
#include "LogMgr.h"
#include "ModuleDeviceMgr.h"
#include "ModuleDrawMgr.h"
#include "ObjComponentMgr.h"
#include "MsgBox.h"
#include "GlobalFunction.h"
#include "MarkAreaMgr.h"
#include "FileMgr.h"
#include "Laser.h"
#include "CommonFlowMgr.h"
#include "Propertie.h"
#include "PropertieMgr.h"
#include "AuthorityMgr.h"
#include "WorkTime.h"
#include "PenParMgr.h"
#include "ProgramLaserTuiHuo.h"
#include "WaferRecipeDataMgr.h"
#include "PropertieMgr.h"
#include "EncryptionMgr.h"
#define SAVE_PAR_FILE_PATH _T("\\SaveDevPar\\")
#define CHECK_WAFER_PT_RADIUS 160 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>ķ<EFBFBD>Χ
#define MAP_HISTORY_DATA_PATH _T("\\MapHistory\\")
#define RECIPE_FILE_PATH _T("\\RecipePar\\")
CString CWorkFileMgr::m_CurOpenFile;
CWorkFileMgr *gWorkFileMgr = new CWorkFileMgr;
CWorkFileMgr::CWorkFileMgr(void)
{
}
CWorkFileMgr::~CWorkFileMgr(void)
{
}
void CWorkFileMgr:: OnAppInitialize()
{
}
#if 1
//<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
bool CWorkFileMgr::IsOpenFile()
{
if(m_CurOpenFile == "")
{
CMsgBox MsgBox;
MsgBox.Show("δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>!");
return false;
}
return true;
}
void CWorkFileMgr::OnOpenFile()
{
TCHAR szFilters[]=("MAK <20>ļ<EFBFBD>(*.mak)|*.mak");
CFileDialog dlg(TRUE,("mak"),("MarkFile"),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilters);
if(dlg.DoModal()==IDOK)
{
OnOpenFileExt(dlg.GetPathName());
}
}
void CWorkFileMgr::OnOpenFileExt(CString Path)
{
ReadWorkFile(Path);
//<2F><>¼<EFBFBD><C2BC>ǰ<EFBFBD>򿪵<EFBFBD><F2BFAAB5>ļ<EFBFBD><C4BC><EFBFBD>------------------------------------------
SaveFileName(Path);
CLayer &layer = gLayer;
layer.NotSelAllObj();//ȫ<><C8AB>ѡ
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>бʵ<D0B1>ѡ<EFBFBD><D1A1>״̬
gPenParMgr->ResetAllSelState();
#ifdef __DLG_PANE_PEN_PAR__
GetFrame()->m_CDlgPenPar.UpdatePar();
#endif
}
//<2F><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CWorkFileMgr::SaveFileName(CString FileName)
{
m_CurOpenFile = FileName;
GetCurDocPtr()->SetTitle(m_CurOpenFile);
}
//<2F><><EFBFBD>浱ǰ<E6B5B1>򿪵<EFBFBD><F2BFAAB5>ĵ<EFBFBD>
void CWorkFileMgr::OnSaveFile()
{
int len = m_CurOpenFile.GetLength();
CString FileSuffix;//<2F>ļ<EFBFBD><C4BC><EFBFBD>׺
if(len>4)
FileSuffix = m_CurOpenFile.Right(3);
if(m_CurOpenFile == "" || (FileSuffix != "" && (FileSuffix != "mak")))//<2F>µ<EFBFBD><C2B5>ļ<EFBFBD>
{
//<2F><><EFBFBD><EFBFBD>Ϊ
OnSaveFileAs();
}
else//<2F><><EFBFBD>浱ǰ<E6B5B1>򿪵<EFBFBD><F2BFAAB5>ļ<EFBFBD>
{
SaveFile(m_CurOpenFile);
CMsgBox MsgBox;
MsgBox.Show(m_CurOpenFile+" <20><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>!");
}
}
//<2F><><EFBFBD><EFBFBD>Ϊ
void CWorkFileMgr::OnSaveFileAs()
{
}
void CWorkFileMgr::SaveFile(CString FileName)
{
SaveWorkFile(FileName);
SaveFileName(FileName);
}
#endif
#if 1
void CWorkFileMgr::SaveWorkFile(CString FilePath)
{
//<2F><EFBFBD><E6B4A2><EFBFBD>б<EFBFBD>ǩ<EFBFBD><C7A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
vector<CLab> LabVec;
//<2F><>ȡģ<C8A1><C4A3><EFBFBD>ı<EFBFBD>ǩ
//gModuleDeviceMgr.SaveWorkFile(LabVec);
gPenParMgr->SaveWorkFile(LabVec);
gWaferRecipeDataMgr->SaveWorkFile(LabVec);
//<2F><>ǩд<C7A9><EFBFBD>ļ<EFBFBD>
SaveWorkFileExt(FilePath,LabVec);
}
//<2F><><EFBFBD>б<EFBFBD>ǩд<C7A9><D0B4><EFBFBD>ļ<EFBFBD>
void CWorkFileMgr::SaveWorkFileExt(CString FilePath,vector<CLab> &LabVec)
{
CFile file(FilePath,CFile::modeReadWrite|CFile::modeCreate);
CArchive ar(&file,CArchive::store);
size_t LabCnt = LabVec.size();
ar<<LabCnt;//<2F><>ǩ<EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD>
vector<CLab>::iterator iter = LabVec.begin();
vector<CLab>::iterator iter_end = LabVec.end();
for(;iter!=iter_end;iter++)
{
(*iter).Serialize(ar);
}
}
#endif
#if 1
void CWorkFileMgr::ReadWorkFile(CString FilePath)
{
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>----------------------------------------------------------
vector<CLab> LabVec;
ReadWorkFileExt(FilePath,LabVec);
if(LabVec.empty())
return;
//<2F><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF>ģ<EFBFBD><C4A3>------------------------------------------------------------
CLabVecRang LabVecRang(LabVec,0,LabVec.size()-1);
vector<CLabVecRang> LabVecRangVec;
SeparateStrVec(LabVecRang,LabVecRangVec,LAB_MODULE_START,LAB_MODULE_END);
//<2F><><EFBFBD>δ<EFBFBD><CEB4><EFBFBD>ÿ<EFBFBD><C3BF>ģ<EFBFBD><C4A3>---------------------------------------------------
vector<CLabVecRang>::iterator iter = LabVecRangVec.begin();
vector<CLabVecRang>::iterator iter_end = LabVecRangVec.end();
for(;iter!=iter_end;iter++)
{
if(gModuleDrawMgr.ReadWorkFile(*iter))
continue;//<2F><><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>ȡ
gModuleDeviceMgr.ReadWorkFile(*iter);
}
}
void CWorkFileMgr::ReadWorkFileExt(CString FilePath,vector<CLab> &LabVec)
{
CFile file;
if(file.Open(FilePath,CFile::modeRead))
{
CArchive ar(&file,CArchive::load);
size_t LabCnt;
ar>>LabCnt;//<2F>ȶ<EFBFBD>ȡ<EFBFBD><C8A1>ǩ<EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD>
for(size_t i=0;i<LabCnt;i++)
{
CLab Lab;
Lab.Serialize(ar);
LabVec.push_back(Lab);
}
file.Close();
}
else
{
gLogMgr->WriteDebugLog("File Read Error", _LOG_ERROR);
}
}
//<2F><>LabVecRang <20>и<EFBFBD><D0B8><EFBFBD>StrLabStart <20><>StrLabEnd <20><>ǩ<EFBFBD><C7A9>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>str <20><><EFBFBD>浽LabVecRangVec
void CWorkFileMgr::SeparateStrVec(CLabVecRang &LabVecRang,vector<CLabVecRang> &LabVecRangVec,LAB_TYPE StrLabStart,LAB_TYPE StrLabEnd)
{
size_t StartCnt = 0;//<2F><><EFBFBD><EFBFBD>Ƕ<EFBFBD>׵<EFBFBD><D7B5><EFBFBD><EFBFBD><EFBFBD>
size_t StartIdx = 0;
size_t EndIdx = 0;
size_t Start = LabVecRang.GetStart();
size_t End = LabVecRang.GetEnd()+1;
for(size_t i=Start;i<End;i++)
{
if(LabVecRang.GetLabType(i)==StrLabStart)
{
if(StartCnt==0)//ֻ<>е<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ż<EFBFBD>¼
{
StartIdx = i+1;//<2F><>¼<EFBFBD><C2BC><EFBFBD>ʼλ<CABC><CEBB>
}
StartCnt++;
}
if(LabVecRang.GetLabType(i)==StrLabEnd)
{
if(StartCnt==1)
{
EndIdx = i-1;//Ŀ<><C4BF><EFBFBD><EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD>жϵ<D0B6><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǩ
//if(EndIdx>StartIdx)//<2F><>Ҫ<EFBFBD>Ѽ<EFBFBD><D1BC>յķ<D5B5>Χ
{
CLabVecRang Rang(LabVecRang.GetVec(),StartIdx,EndIdx);
LabVecRangVec.push_back(Rang);
}
}
StartCnt--;
}
}
}
void CWorkFileMgr::SeparateLabVecRangVec(vector<CLab> &LabVec,vector<CLabVecRang>&LabVecRangVec,CString Path,LAB_TYPE StrLabStart,LAB_TYPE StrLabEnd)
{
CFileMgr FileMgr;
if(!FileMgr.IsFileExist(Path))
return;
ReadWorkFileExt(Path,LabVec);
if(LabVec.empty())
return;
//<2F><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD>¼------------------------------------------------------------
CLabVecRang LabVecRang(LabVec,0,LabVec.size()-1);
SeparateStrVec(LabVecRang,LabVecRangVec,StrLabStart,StrLabEnd);
}
//<2F><>StrVec <20><><EFBFBD>Һͱ<D2BA>ǩLabStr ƥ<><C6A5><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ǩ<EFBFBD><C7A9>ֵ,û<><C3BB>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>""
CLab CWorkFileMgr::FindLab(CLabVecRang &LabVecRang,LAB_TYPE LabStr)
{
CLab ret;
size_t Start = LabVecRang.GetStart();
size_t End = LabVecRang.GetEnd()+1;
for(size_t i=Start;i<End;i++)
{
if(LabVecRang.GetLabType(i)==LabStr)
{
ret = LabVecRang.GetLab(i);
break;
}
}
return ret;
}
#endif
#if 1
//<2F><><EFBFBD><EFBFBD>obj <20>ļ<EFBFBD>
void CWorkFileMgr::OpenObjFile()
{
TCHAR szFilters[]=("OBJ <20>ļ<EFBFBD>(*.obj)|*.obj");
CFileDialog dlg(TRUE,("obj"),("ObjFile"),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilters);
//Ĭ<><C4AC>·<EFBFBD><C2B7>
CString Path = gProgramLaserTuiHuo->GetScanAreaFilePath();
dlg.m_ofn.lpstrInitialDir = Path;
if(dlg.DoModal()==IDOK)
{
ReadObjTemplateFile(dlg.GetPathName());
m_pView->RefreshView();
}
}
//<2F><><EFBFBD><EFBFBD>obj <20>ļ<EFBFBD>
void CWorkFileMgr::SaveObjFile()
{
CObjContainer &LayerObjContainer = gLayer.GetObjContainer();
if(!LayerObjContainer.CheckPtRadius(CHECK_WAFER_PT_RADIUS)&&!gEncryptionMgr->IsbRunAtNoteBook())
{
CString s;
s.Format("<EFBFBD><EFBFBD><EFBFBD>ݵ㲻<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD>Χ֮<EFBFBD>ڣ<EFBFBD>ֱ<EFBFBD><EFBFBD>= %d",(CHECK_WAFER_PT_RADIUS*2));
CMsgBox MsgBox;
MsgBox.Show(s);
return;
}
TCHAR szFilters[]=("OBJ <20>ļ<EFBFBD>(*.obj)|*.obj");
CFileDialog dlg(FALSE,("obj"),("ObjFile"),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilters);
//Ĭ<><C4AC>·<EFBFBD><C2B7>
dlg.m_ofn.lpstrInitialDir = gProgramLaserTuiHuo->GetScanAreaFilePath();
if(dlg.DoModal()==IDOK)
{
SaveObjTemplateFile(dlg.GetPathName());
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰMap <20><>¼<EFBFBD><C2BC>·<EFBFBD><C2B7>
CString CWorkFileMgr::CreatMapHistoryPath()
{
CString MonitoringDataPath = gProgramLaserTuiHuo->GetLaipuLaserDataDir(MAP_HISTORY_DATA_PATH);
CString Path = MonitoringDataPath;
CFileMgr FileMgr;
CWorkTime WorkTime;
Path += WorkTime.GetCurYear();
Path += "\\"+WorkTime.GetCurMonth();
Path += "\\"+WorkTime.GetCurDay();
Path += "\\";
if(!FileMgr.IsDirectoryExists(Path))
{
FileMgr.CreatDir(Path);
}
return Path;
}
#endif
#if 1
//<2F><>Txt <20>ļ<EFBFBD><C4BC>е<EFBFBD><D0B5><EFBFBD>obj
void CWorkFileMgr::OpenObjTxtFile()
{
TCHAR szFilters[]=("TXT <20>ļ<EFBFBD>(*.txt)|*.txt");
CFileDialog dlg(TRUE,("txt"),("TxtFile"),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilters);
//Ĭ<><C4AC>·<EFBFBD><C2B7>
CString Path = gProgramLaserTuiHuo->GetObjTxtFilePath();
dlg.m_ofn.lpstrInitialDir = Path;
if(dlg.DoModal()==IDOK)
{
gLayer.DelAllObj();
CObjContainer &LayerObjContainer = gLayer.GetObjContainer();
LayerObjContainer.ReadObjFromTxt(dlg.GetPathName());
m_pView->RefreshView();
}
}
//<2F><><EFBFBD><EFBFBD>obj <20><>txt <20>ļ<EFBFBD>
void CWorkFileMgr::SaveObjTxtFile()
{
TCHAR szFilters[]=("TXT <20>ļ<EFBFBD>(*.txt)|*.txt");
CFileDialog dlg(FALSE,("txt"),("TxtFile"),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilters);
//Ĭ<><C4AC>·<EFBFBD><C2B7>
dlg.m_ofn.lpstrInitialDir = gProgramLaserTuiHuo->GetObjTxtFilePath();
if(dlg.DoModal()==IDOK)
{
CObjContainer &LayerObjContainer = gLayer.GetObjContainer();
LayerObjContainer.SaveObjToTxt(dlg.GetPathName());
}
}
#endif
#if 1
void CWorkFileMgr::ExtParToTxtFile()
{
TCHAR szFilters[]=("TXT <20>ļ<EFBFBD>(*.txt)|*.txt");
CString FileName;//Ĭ<><C4AC><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
FileName += gWorkTime.GetDateTime("_","_");
FileName = "DevicePar_"+FileName;
CFileDialog dlg(FALSE,("txt"),FileName,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilters);
//Ĭ<><C4AC>·<EFBFBD><C2B7>
if(dlg.DoModal()==IDOK)
{
gDevicePropertieMgr.SaveAllPropertieToTxtFile(dlg.GetPathName());
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>򿪵<EFBFBD>ʱ<EFBFBD>򵼳<EFBFBD><F2B5BCB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
void CWorkFileMgr::ExtParToTxtFileOnAppOpen()
{
CString DirPath = gProgramLaserTuiHuo->GetLaipuLaserDataDir(SAVE_PAR_FILE_PATH);
CFileMgr FileMgr;
if(!FileMgr.IsDirectoryExists(DirPath))
FileMgr.CreatDir(DirPath);
CString FileName;//Ĭ<><C4AC><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
FileName += gWorkTime.GetDateTime("_","_");
FileName = "DevicePar_"+FileName;
FileName += ".bin";
CString FilePath = DirPath + FileName;
gDevicePropertieMgr.SaveAllPropertieToTxtFile(FilePath);
CString Log;
Log = "ExtPar-->";
Log += FileName;
gLogMgr->WriteDebugLog(Log);
}
//ͨ<><CDA8><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>obj <20>ļ<EFBFBD>(<28><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>)
void CWorkFileMgr::ReadObjFileByName(CString FileName)
{
CFileMgr FileMgr;
CString FilePath;//<2F><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
FileMgr.GetFullFilePath(FilePath,FileName);
ReadObjTemplateFile(FilePath);
}
//ͨ<><CDA8><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>obj <20>ļ<EFBFBD>(<28><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>)
void CWorkFileMgr::ReadObjTemplateFile(CString FilePath)
{
ReadWorkFile(FilePath);
}
//ֻ<><D6BB><EFBFBD><EFBFBD>obj ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CWorkFileMgr::SaveObjTemplateFile(CString FilePath)
{
CString MapHistoryPath = CreatMapHistoryPath();
CFileMgr FileMgr;
bool bFileExist = FileMgr.IsFileExist(FilePath);
CString FileName = FileMgr.GetFileNameFromPath(FilePath,true);
CString s = "[";
CWorkTime WorkTime;
s += WorkTime.GetCurTime("_");
s += "_";
s += gAuthorityMgr->GetCurUserName();
s += "]";
FileName = s +FileName;
FileName += ".obj";
MapHistoryPath += FileName;
if(bFileExist)//<2F><><EFBFBD><EFBFBD>obj <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CDB4><EFBFBD>,<2C><><EFBFBD>Ƶ<EFBFBD>history
{
FileMgr.CopyFolder(FilePath,MapHistoryPath);
}
vector<CLab> LabVec;//<2F><EFBFBD><E6B4A2><EFBFBD>б<EFBFBD>ǩ<EFBFBD><C7A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F>Ѽ<EFBFBD><D1BC><EFBFBD><EFBFBD>б<EFBFBD>ǩ
gTemplateMgr->SaveWorkFile(LabVec);
//<2F><><EFBFBD>б<EFBFBD>ǩд<C7A9><D0B4><EFBFBD>ļ<EFBFBD>
SaveWorkFileExt(FilePath,LabVec);
if(!bFileExist)//<2F><><EFBFBD><EFBFBD>obj <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD>Ƶ<EFBFBD>history (<28><>ʾ<EFBFBD>½<EFBFBD>obj)
{
FileMgr.CopyFolder(FilePath,MapHistoryPath);
}
}
#endif