#include "stdafx.h" #include "ViewRecipeList.h" #include "ViewRecipeNew.h" #include "ViewPPIDNew.h" const int LIST_COLUMN_COUNT = 3; const TCHAR* LIST_COLUMN_ITEM[LIST_COLUMN_COUNT] = {_T("No"),_T("Recipe"),_T("Comment")}; const int LIST_COLUMN_WIDHT[LIST_COLUMN_COUNT] = { 50,130,145 }; const int PPIDLIST_COLUMN_COUNT = 3; const TCHAR* PPIDLIST_COLUMN_ITEM[PPIDLIST_COLUMN_COUNT] = {_T("No"),_T("PLC Index"),_T("Recipe")}; const int PPIDLIST_COLUMN_WIDHT[PPIDLIST_COLUMN_COUNT] = {50,130,145}; // CViewRecipeList 措拳 惑磊涝聪促. IMPLEMENT_DYNAMIC(CViewRecipeList, CDialogEx) CViewRecipeList::CViewRecipeList(CWnd* pParent /*=NULL*/) : CDialogEx(CViewRecipeList::IDD, pParent) { m_strRecipeName.Empty(); m_strPPIDName.Empty(); m_strSelectRecipe.Empty(); m_VectorLinkList = NULL; m_pParent = pParent; } CViewRecipeList::~CViewRecipeList() { } void CViewRecipeList::DoDataExchange(CDataExchange* pDX) { DDX_Control(pDX,IDC_RECIPE_LIST,m_ListRecipe); DDX_Control(pDX,IDC_PPID_LIST,m_ListPPID); CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CViewRecipeList, CDialogEx) ON_WM_SHOWWINDOW() ON_BN_CLICKED(IDC_BUT_LIST_NEWRECIPE, &CViewRecipeList::OnBnClickedButListNewrecipe) ON_BN_CLICKED(IDC_BUT_LIST_SELECT, &CViewRecipeList::OnBnClickedButListSelect) ON_BN_CLICKED(IDC_BUT_LIST_EXIT, &CViewRecipeList::OnBnClickedButListExit) ON_NOTIFY(NM_CLICK, IDC_RECIPE_LIST, OnListRecipeClick) ON_NOTIFY(NM_CLICK, IDC_PPID_LIST, OnListPPIDClick) ON_WM_PAINT() ON_BN_CLICKED(IDC_BUT_LIST_NEWPPID, &CViewRecipeList::OnBnClickedButListNewppid) ON_BN_CLICKED(IDC_BUT_LIST_DELPPID, &CViewRecipeList::OnBnClickedButListDelppid) ON_BN_CLICKED(IDC_BUTTON_LINK, &CViewRecipeList::OnBnClickedButtonLink) ON_BN_CLICKED(IDC_BUT_LIST_DELRECIPE, &CViewRecipeList::OnBnClickedButListDelrecipe)//20141006 END_MESSAGE_MAP() BOOL CViewRecipeList::OnInitDialog() { SetControl(); Init_PPIDGrid(); return TRUE; } void CViewRecipeList::SetRecipeName(CString strPPID,CString strRecipe) { m_strPPIDName = strPPID; m_strRecipeName = strRecipe; } void CViewRecipeList::LoadRecipeList() { m_arrRecipeList.RemoveAll(); m_arrCommentList.RemoveAll(); m_arrRecipeFileList.RemoveAll(); CString strPath; CString strFileName,strFilePath; CFileFind finder; strPath.Format(_T("%s\\*.rcp"),RECIPE_PATH); BOOL bWorking = finder.FindFile(strPath); while (bWorking) { bWorking = finder.FindNextFile(); if (finder.IsDots()) continue; if (!finder.IsDirectory()) { strFilePath = finder.GetFilePath(); strFileName = finder.GetFileTitle(); CString strComment; CGlassRecipe GlassRecipe; CConfig recipeFile; GlassRecipe.Reset(); if (recipeFile.SetRegiConfig(NULL, NULL, (TCHAR*)(LPCTSTR)strFilePath, FileMap_Mode)) { GlassRecipe.ReadRecipe(&recipeFile); strComment.Format(_T("%s"), GlassRecipe.m_RecieParm.m_strComment); } m_arrRecipeList.Add(strFileName); m_arrCommentList.Add(strComment); m_arrRecipeFileList.Add(strFilePath); } } finder.Close(); } // CViewRecipeList 皋矫瘤 贸府扁涝聪促. void CViewRecipeList::OnShowWindow(BOOL bShow, UINT nStatus) { CDialogEx::OnShowWindow(bShow, nStatus); if(bShow == TRUE) { UpdateData(FALSE); Init_PPIDGrid(); LoadRecipeList(); FillRecipeList(); FillPPIDList(); } } void CViewRecipeList::SetControl() { m_FontControl.SetFont(this,IDC_BUT_LIST_NEWRECIPE,CFontControl::EN_ITEMFONT); m_FontControl.SetFont(this,IDC_BUT_LIST_NEWPPID,CFontControl::EN_ITEMFONT); m_FontControl.SetFont(this,IDC_BUT_LIST_DELPPID,CFontControl::EN_ITEMFONT); m_FontControl.SetFont(this,IDC_BUT_LIST_DELRECIPE,CFontControl::EN_ITEMFONT); m_FontControl.SetFont(this,IDC_BUT_LIST_SELECT,CFontControl::EN_ITEMFONT); m_FontControl.SetFont(this,IDC_BUT_LIST_EXIT,CFontControl::EN_ITEMFONT); HBITMAP BmpArrow= ::LoadBitmap(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDB_BITMAP_RECIPE_LINKARROW)); ((CButton*)GetDlgItem(IDC_BUTTON_LINK))->SetBitmap(BmpArrow); } void CViewRecipeList::FillPPIDList() { if(m_ListPPID.GetSafeHwnd() == NULL) return; if(m_VectorLinkList == NULL) { m_ListPPID.SetRowCount(1); return; } m_ListPPID.SetRowCount((int)m_VectorLinkList->size()+1); int nRowCnt = (int)m_VectorLinkList->size()+1; int iRow,iCol; CString str; iRow = 1; LinkList* pList = NULL; for (VectorLinkListIt it = m_VectorLinkList->begin(); it != m_VectorLinkList->end(); it++) { pList = *it; if(!pList) continue; iCol = 0; str.Format(_T("%d"),iRow); m_ListPPID.SetItemText(iRow,iCol,str); iCol++; str.Format(_T("%s"),pList->m_strUpperName); m_ListPPID.SetItemText(iRow,iCol,str); iCol++; str.Format(_T("%s"),pList->m_strInsName); m_ListPPID.SetItemText(iRow,iCol,str); iRow++; } m_ListPPID.Invalidate(); } void CViewRecipeList::FillRecipeList() { Init_Grid(); if(m_ListRecipe.GetSafeHwnd() == NULL) return; int nRowCnt = (int)m_arrRecipeList.GetSize()+1; int iRow,iCol; CString str; for(iRow=1;iRowSetBackClr(RGB(0xFF, 0xFF, 0xE0)); m_ListRecipe.SetGridLines(GVL_BOTH); m_ListRecipe.SetColumnCount(LIST_COLUMN_COUNT); m_ListRecipe.SetRowCount((int)m_arrRecipeList.GetSize()+1); m_ListRecipe.SetFixedRowCount(1); m_ListRecipe.SetFixedColumnCount(0); m_ListRecipe.ExpandColumnsToFit(); CFont *pFont = m_ListRecipe.GetFont(); if (!pFont) return; LOGFONT lf; pFont->GetLogFont(&lf); lf.lfItalic = 0; lf.lfHeight = 14; lf.lfWeight = FW_BOLD; _tcscpy_s(lf.lfFaceName, LF_FACESIZE, _T("Arial")); m_ListRecipe.GetDefaultCell(TRUE, FALSE)->SetFont(&lf); m_ListRecipe.GetDefaultCell(FALSE, TRUE)->SetFont(&lf); m_ListRecipe.GetDefaultCell(TRUE, TRUE)->SetFont(&lf); m_ListRecipe.SetEditable(FALSE); m_ListRecipe.EnableSelection(TRUE); Init_GridHeader(); } void CViewRecipeList::Init_GridHeader() { CString str; GV_ITEM Item; int nCol = 0; int iLoop; Item.mask = GVIF_TEXT; Item.row = 0; for(iLoop=0;iLoopSetBackClr(RGB(0xFF, 0xFF, 0xE0)); m_ListPPID.SetGridLines(GVL_BOTH); m_ListPPID.SetColumnCount(PPIDLIST_COLUMN_COUNT); m_ListPPID.SetRowCount(1); m_ListPPID.SetFixedRowCount(1); m_ListPPID.SetFixedColumnCount(0); m_ListPPID.ExpandColumnsToFit(); CFont *pFont = m_ListPPID.GetFont(); if (!pFont) return; LOGFONT lf; pFont->GetLogFont(&lf); lf.lfItalic = 0; lf.lfHeight = 14; lf.lfWeight = FW_BOLD; _tcscpy_s(lf.lfFaceName, LF_FACESIZE, _T("Arial")); m_ListPPID.GetDefaultCell(TRUE, FALSE)->SetFont(&lf); m_ListPPID.GetDefaultCell(FALSE, TRUE)->SetFont(&lf); m_ListPPID.GetDefaultCell(TRUE, TRUE)->SetFont(&lf); m_ListPPID.SetEditable(FALSE); m_ListPPID.EnableSelection(TRUE); Init_PPIDGridHeader(); } void CViewRecipeList::Init_PPIDGridHeader() { CString str; GV_ITEM Item; int nCol = 0; int iLoop; Item.mask = GVIF_TEXT; Item.row = 0; for(iLoop=0;iLoop [%s]?"),strCopyRecipe,strNewRecipe); if (IDNO == AfxMessageBox(str, MB_YESNO | MB_ICONQUESTION)) { str.Format(_T("Create New [%s]?"),strNewRecipe); if (IDNO == AfxMessageBox(str, MB_YESNO | MB_ICONQUESTION)) return; CGlassRecipe GlassRecipe; GlassRecipe.Reset(); GlassRecipe.MakeRecipeFileName(strNewRecipe); GlassRecipe.SaveRecipeConfigFile(strNewRecipe); GlassRecipe.m_RecieParm.m_strComment = strNewComment; if(GlassRecipe.WriteRecipeFile() == FALSE) AfxMessageBox(_T("Write New Recipe Fail!")); } else { CString strOrg,strTgt; strOrg.Format(_T("%s\\%s.rcp"),RECIPE_PATH,strCopyRecipe); strTgt.Format(_T("%s\\%s.rcp"),RECIPE_PATH,strNewRecipe); if(CopyFile(strOrg,strTgt,FALSE) == FALSE) AfxMessageBox(_T("Copy Recipe Fail!")); CConfig Config; if (Config.SetRegiConfig(NULL, NULL, (TCHAR*)(LPCTSTR)strTgt, FileMap_Mode)) { Config.SetItemValue(_T("COMMENT"), strNewComment); Config.WriteToFile(); } strOrg.Format(_T("%s\\%s.cfg"), RECIPE_PATH, strCopyRecipe); strTgt.Format(_T("%s\\%s.cfg"), RECIPE_PATH, strNewRecipe); //if (CopyFile(strOrg, strTgt, FALSE) == FALSE) // AfxMessageBox(_T("Copy Recipe Cofg Fail!")); // User Defect strOrg.Format(_T("C:\\EdgeInspector_App\\Recipe\\UserDefect\\%s_UserDefectArea.ini"),strCopyRecipe); strTgt.Format(_T("C:\\EdgeInspector_App\\Recipe\\UserDefect\\%s_UserDefectArea.ini"),strNewRecipe); CopyFile(strOrg,strTgt,FALSE); // Exp Area strOrg.Format(_T("C:\\EdgeInspector_App\\Recipe\\ExpArea\\%s_ExpArea.ins"),strCopyRecipe); strTgt.Format(_T("C:\\EdgeInspector_App\\Recipe\\ExpArea\\%s_ExpArea.ins"),strNewRecipe); CopyFile(strOrg,strTgt,FALSE); // Align strTgt.Format(_T("C:\\EdgeInspector_App\\Align\\%s"),strNewRecipe); CreateDirectory(strTgt,NULL); strOrg.Format(_T("C:\\EdgeInspector_App\\Align\\%s\\*.bmp"),strCopyRecipe); CFileFind pFinder; BOOL bWorking; CString szFile,szName; int nIndex; bWorking = pFinder.FindFile(strOrg); while (bWorking) { bWorking = pFinder.FindNextFile(); if(pFinder.IsDots()) continue; if(pFinder.IsDirectory()) continue; szFile = pFinder.GetFilePath(); nIndex = szFile.ReverseFind('\\'); if(nIndex < 0) continue; szName = szFile.Right(szFile.GetLength()-(nIndex+1)); if(szName.IsEmpty() == TRUE) continue; strTgt.Format(_T("C:\\EdgeInspector_App\\Align\\%s\\%s"),strNewRecipe,szName); CopyFile(szFile,strTgt,FALSE); } } } else { ///////20141006 CString str; str.Format(_T("Create new [%s]?"),strNewRecipe); if (IDNO == AfxMessageBox(str, MB_YESNO | MB_ICONQUESTION)) return; ///////20141006 CGlassRecipe GlassRecipe; GlassRecipe.Reset(); GlassRecipe.MakeRecipeFileName(strNewRecipe); GlassRecipe.SaveRecipeConfigFile(strNewRecipe); GlassRecipe.m_RecieParm.m_strComment = strNewComment; if(GlassRecipe.WriteRecipeFile() == FALSE) AfxMessageBox(_T("Write New Recipe Fail!")); } LoadRecipeList(); FillRecipeList(); } } void CViewRecipeList::OnBnClickedButListSelect() { m_pParent->PostMessage(UM_SELECT_RECIPE,NULL,NULL); OnOK(); } void CViewRecipeList::OnBnClickedButListExit() { OnCancel(); } void CViewRecipeList::OnPaint() { CPaintDC dc(this); // device context for painting CGeneralDraw pDraw; CUIPictureControl uiTitleRecipeName; CUIPictureControl uiTitlePPIDName; uiTitleRecipeName.SetItemDefault(this,IDC_LIST_RECIPE_NAME); uiTitleRecipeName.m_strData.Format(_T("%s"),m_strRecipeName); pDraw.DrawPitureControl(uiTitleRecipeName); uiTitlePPIDName.SetTitleDefault(this,IDC_LIST_PPID_NAME); uiTitlePPIDName.m_strData.Format(_T("%s"),m_strPPIDName); pDraw.DrawPitureControl(uiTitlePPIDName); } void CViewRecipeList::OnListPPIDClick(NMHDR *pNotifyStruct, LRESULT* pResult) { NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNotifyStruct; if(pItem->iRow <= 0 || m_VectorLinkList == NULL || pItem->iRow > (int)m_VectorLinkList->size()) return; VectorLinkListIt it; LinkList* pList = NULL; int nIndex = pItem->iRow-1; int nCount = 0; m_strRecipeName.Empty(); m_strPPIDName.Empty(); m_strSelectRecipe.Empty(); for (it = m_VectorLinkList->begin(); it != m_VectorLinkList->end(); it++,nCount++) { pList = *it; if(!pList) continue; if(nCount == nIndex) { m_strPPIDName = pList->m_strUpperName; break; } } if(m_strPPIDName.IsEmpty() == TRUE) return; for (it = m_VectorLinkList->begin(); it != m_VectorLinkList->end(); it++) { pList = *it; if(!pList) continue; if(pList->m_strUpperName.CompareNoCase(m_strPPIDName) == 0) { m_strRecipeName = pList->m_strInsName; } } Invalidate(FALSE); } void CViewRecipeList::OnListRecipeClick(NMHDR *pNotifyStruct, LRESULT* pResult) { NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNotifyStruct; m_strSelectRecipe.Empty(); if(pItem->iRow <= 0 || pItem->iRow > (int)m_arrRecipeList.GetSize()) return; int nIndex = pItem->iRow-1; m_strSelectRecipe = m_arrRecipeList.GetAt(nIndex); } void CViewRecipeList::OnBnClickedButListNewppid() { if(m_VectorLinkList == NULL) return; CViewPPIDNew dlgPPID; CString strNewPPID; if(dlgPPID.DoModal() == IDOK) { strNewPPID = dlgPPID.GetNewRecipeName(); if(strNewPPID.IsEmpty() == TRUE) { AfxMessageBox(_T("No PPID Name")); return; } LinkList* pList = NULL; for (VectorLinkListIt it = m_VectorLinkList->begin(); it != m_VectorLinkList->end(); it++) { pList = *it; if(!pList) continue; if(strNewPPID == pList->m_strUpperName) { AfxMessageBox(_T("Already existing Upper PPID")); return; } } strNewPPID.MakeUpper(); LinkList* pSetList = new LinkList; pSetList->m_strUpperName = strNewPPID; m_VectorLinkList->push_back(pSetList); m_strPPIDName = strNewPPID; FillPPIDList(); UpdateData(FALSE); } } void CViewRecipeList::OnBnClickedButListDelppid() { LinkList* pList = NULL; for (VectorLinkListIt it = m_VectorLinkList->begin(); it != m_VectorLinkList->end(); it++) { pList = *it; if (pList) { if(pList->m_strUpperName.CollateNoCase(m_strPPIDName) == 0) { if (IDNO == AfxMessageBox(_T("Are you sure you want to delete?"), MB_YESNO | MB_ICONQUESTION)) return; m_VectorLinkList->erase(it); delete pList; break; } } } FillPPIDList(); } void CViewRecipeList::OnBnClickedButtonLink() { if(m_strSelectRecipe.IsEmpty() == TRUE) { AfxMessageBox(_T("Please select Recipe.")); return; } CString str; str.Format(_T("Are you sure you want to connect PPID [%s] to Recipe [%s]?"),m_strPPIDName,m_strSelectRecipe); if (IDNO == AfxMessageBox(str, MB_YESNO | MB_ICONQUESTION)) return; m_strRecipeName = m_strSelectRecipe; LinkList* pList = NULL; for (VectorLinkListIt it = m_VectorLinkList->begin(); it != m_VectorLinkList->end(); it++) { pList = *it; if (pList) { if(pList->m_strUpperName.CollateNoCase(m_strPPIDName) == 0) { pList->m_strInsName = m_strRecipeName; break; } } } FillPPIDList(); Invalidate(FALSE); } void CViewRecipeList::OnBnClickedButListDelrecipe()//20141006 { if(m_strSelectRecipe.IsEmpty()) { AfxMessageBox(_T("Please select a recipe to delete.")); return; } CString str; str.Format(_T("Are you sure you want to delete the [%s]recipe?"),m_strSelectRecipe); if (IDNO == AfxMessageBox(str, MB_YESNO | MB_ICONQUESTION)) return; CString strPath; strPath.Format(_T("%s\\%s.rcp"), RECIPE_PATH, m_strSelectRecipe); DeleteFile(strPath); //strPath.Format(_T("%s\\%s.cfg"), RECIPE_PATH, m_strSelectRecipe); //DeleteFile(strPath); for (int i=0; i<4; i++) { strPath.Format(_T("C:\\EdgeInspector_App\\MasterImage\\%s_Dimension_[%d].bmp"),m_strSelectRecipe,i); DeleteFile(strPath); strPath.Format(_T("C:\\EdgeInspector_App\\Notch\\%s_[%d].notch"),m_strSelectRecipe,i); DeleteFile(strPath); strPath.Format(_T("C:\\EdgeInspector_App\\Notch\\%s_[%d]_notch.bmp"),m_strSelectRecipe,i); DeleteFile(strPath); strPath.Format(_T("C:\\EdgeInspector_App\\Notch\\%s_[%d]_Notch_org.bmp"),m_strSelectRecipe,i); DeleteFile(strPath); strPath.Format(_T("C:\\EdgeInspector_App\\Notch\\%s_Notch_Align_Mark_[%d].bmp"),m_strSelectRecipe,i); DeleteFile(strPath); } strPath.Format(_T("C:\\EdgeInspector_App\\Spline\\%s_CCut.bmp"),m_strSelectRecipe); DeleteFile(strPath); strPath.Format(_T("C:\\EdgeInspector_App\\Spline\\%s_CCut.ccut"),m_strSelectRecipe); DeleteFile(strPath); strPath.Format(_T("C:\\EdgeInspector_App\\Spline\\%s_CCut_org.bmp"),m_strSelectRecipe); DeleteFile(strPath); strPath.Format(_T("C:\\EdgeInspector_App\\Spline\\%s_RCut.bmp"),m_strSelectRecipe); DeleteFile(strPath); strPath.Format(_T("C:\\EdgeInspector_App\\Spline\\%s_RCut.ccut"),m_strSelectRecipe); DeleteFile(strPath); strPath.Format(_T("C:\\EdgeInspector_App\\Spline\\%s_RCut_org.bmp"),m_strSelectRecipe); DeleteFile(strPath); LoadRecipeList(); FillRecipeList(); }