|
#include "stdafx.h"
|
#include "ViewUserDefectArea.h"
|
#include "afxdialogex.h"
|
#include "Glass_Data.h"
|
|
const int USERDEFECT_COLUMN_COUNT = 9;
|
const char* USERDEFECT_COLUMN_ITEM[USERDEFECT_COLUMN_COUNT] = {"No","POS X","POS Y","AREA WIDTH","AREA HEIGHT","DEFECT WIDTH","DEFECT HEIGHT","THRESHOLD","DILATION"};
|
const int USERDEFECT_COLUMN_WIDHT[USERDEFECT_COLUMN_COUNT] = {40,90,90,90,90,90,90,90,70};
|
|
#define GRID_FIX_COLOR RGB(144,200,246)
|
#define GRID_COLOR RGB(242,242,242)
|
#define GRID_TEXT_COLOR RGB(255,255,255)
|
#define GRID_LINE_COLOR GRID_FIX_COLOR
|
|
IMPLEMENT_DYNAMIC(CViewUserDefectArea, CDialogEx)
|
|
CViewUserDefectArea::CViewUserDefectArea(CWnd* pParent /*=NULL*/)
|
: CDialogEx(CViewUserDefectArea::IDD, pParent)
|
{
|
m_pGlassData = NULL;
|
m_pHardwareSetting = NULL;
|
m_pGlassRecipe = NULL;
|
m_pIU2P = NULL;
|
m_nSelectRow = -1;
|
}
|
|
CViewUserDefectArea::~CViewUserDefectArea()
|
{
|
|
}
|
|
void CViewUserDefectArea::DoDataExchange(CDataExchange* pDX)
|
{
|
CDialogEx::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_EDIT_USER_DEFECT_AREA_WIDTH, m_EditDefectAreaWidth);
|
DDX_Control(pDX, IDC_EDIT_USER_DEFECT_AREA_HEIGHT, m_EditDefectAreaHeight);
|
DDX_Control(pDX, IDC_EDIT_USER_DEFECT_AREA_THRESHOLD, m_EditDefectAreaThreshold);
|
DDX_Control(pDX, IDC_EDIT_USER_DEFECT_AREA_DILATION, m_EditDefectAreaDilation);
|
DDX_Control(pDX, IDC_USERDEFECT_LIST, m_GrdUserDefect);
|
|
DDX_Text(pDX, IDC_EDIT_USER_DEFECT_AREA_WIDTH, m_stUserDefectArea.defect_width);
|
DDX_Text(pDX, IDC_EDIT_USER_DEFECT_AREA_HEIGHT, m_stUserDefectArea.defect_height);
|
DDX_Text(pDX, IDC_EDIT_USER_DEFECT_AREA_THRESHOLD, m_stUserDefectArea.defect_threshold);
|
DDX_Text(pDX, IDC_EDIT_USER_DEFECT_AREA_DILATION, m_stUserDefectArea.defect_dilation);
|
}
|
|
|
BEGIN_MESSAGE_MAP(CViewUserDefectArea, CDialogEx)
|
ON_WM_SHOWWINDOW()
|
ON_BN_CLICKED(IDC_BUTTON_USER_DEFECT_AREA_DRAW, &CViewUserDefectArea::OnBnClickedButtonUserDefectAreaDraw)
|
ON_BN_CLICKED(IDC_BUTTON_USER_DEFECT_AREA_ADD, &CViewUserDefectArea::OnBnClickedButtonUserDefectAreaAdd)
|
ON_BN_CLICKED(IDC_BUTTO_USER_DEFECT_AREA_SAVE, &CViewUserDefectArea::OnBnClickedButtoUserDefectAreaSave)
|
ON_BN_CLICKED(IDC_BUTTON_USER_DEFECT_AREA_MODIFY, &CViewUserDefectArea::OnBnClickedButtonUserDefectAreaModify)
|
ON_BN_CLICKED(IDC_BUTTON_USER_DEFECT_AREA_DELETE, &CViewUserDefectArea::OnBnClickedButtonUserDefectAreaDelete)
|
ON_NOTIFY(NM_DBLCLK, IDC_USERDEFECT_LIST, OnGridDBClick)
|
END_MESSAGE_MAP()
|
|
void CViewUserDefectArea::OnShowWindow(BOOL bShow, UINT nStatus)
|
{
|
CDialogEx::OnShowWindow(bShow, nStatus);
|
|
if(bShow == TRUE)
|
{
|
UpdateData(FALSE);
|
FillUserDefectGrid(TRUE);
|
}
|
}
|
|
void CViewUserDefectArea::SetRecipe(CHardwareSettings *pHard,CGlassRecipe *pRecipe)
|
{
|
m_pHardwareSetting = pHard;
|
m_pGlassRecipe = pRecipe;
|
}
|
|
void CViewUserDefectArea::SetIndex(int index)
|
{
|
m_index = index;
|
FillUserDefectGrid(TRUE);
|
}
|
|
|
void CViewUserDefectArea::OnBnClickedButtonUserDefectAreaDraw()
|
{
|
if(m_pIU2P != NULL)
|
{
|
m_pIU2P->IU2P_DrawRect(TRUE);
|
}
|
}
|
|
void CViewUserDefectArea::OnBnClickedButtonUserDefectAreaAdd()
|
{
|
if(m_pGlassData == NULL || m_pGlassRecipe == NULL)
|
return;
|
|
if(m_pIU2P != NULL)
|
{
|
CRect rect = m_pIU2P->IU2P_GetCompareRect();
|
|
INS_EDGE_RESULT_INFO *pResInfo = m_pGlassData->GetEdgeResultInfo((DimensionDir)m_index);
|
if(pResInfo == NULL)
|
return;
|
|
//if(pResInfo->ptMark[0].x > 0 && pResInfo->ptMark[0].y > 0)
|
{
|
ST_USER_DEFECT_AREA stUserDefect;
|
|
stUserDefect.x = rect.left - static_cast<int>(pResInfo->ptMark[0].x);
|
stUserDefect.y = rect.top - static_cast<int>(pResInfo->ptMark[0].y);
|
stUserDefect.area_width = rect.Width();
|
stUserDefect.area_height = rect.Height();
|
|
USER_DEFECT_AREA_LIST *pList = m_pGlassRecipe->GetUserDefectList((DimensionDir)m_index);
|
if(pList == NULL)
|
return;
|
|
pList->push_back(stUserDefect);
|
|
FillUserDefectGrid(TRUE);
|
|
UpdateData(FALSE);
|
}
|
|
m_pIU2P->IU2P_DrawRect(FALSE);
|
}
|
}
|
|
|
BOOL CViewUserDefectArea::OnInitDialog()
|
{
|
CDialogEx::OnInitDialog();
|
|
FONT_STYLE.CreateFont(14, 0, 0, 0, 300 , FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
|
DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN, _T("Arial"));
|
|
m_EditDefectAreaWidth.SetFont(&FONT_STYLE);
|
m_EditDefectAreaHeight.SetFont(&FONT_STYLE);
|
m_EditDefectAreaThreshold.SetFont(&FONT_STYLE);
|
m_EditDefectAreaDilation.SetFont(&FONT_STYLE);
|
|
Init_UserDefectGrid();
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
}
|
|
|
void CViewUserDefectArea::OnBnClickedButtoUserDefectAreaSave()
|
{
|
if(m_pGlassRecipe != NULL)
|
{
|
m_pGlassRecipe->SaveUserDefectList();
|
if(m_pIU2P != NULL)
|
m_pIU2P->IU2P_DrawRefresh();
|
}
|
}
|
|
|
void CViewUserDefectArea::OnBnClickedButtonUserDefectAreaModify()
|
{
|
if(m_pGlassRecipe == NULL)
|
return;
|
|
if(m_nSelectRow < 0)
|
return;
|
|
USER_DEFECT_AREA_LIST *pList = m_pGlassRecipe->GetUserDefectList((DimensionDir)m_index);
|
if(pList == NULL)
|
return;
|
|
if((int)pList->size() < m_nSelectRow)
|
return;
|
|
itUSER_DEFECT_AREA_LIST it = pList->begin();
|
|
std::advance(it, m_nSelectRow-1);
|
|
UpdateData(TRUE);
|
|
it->defect_width = m_stUserDefectArea.defect_width;
|
it->defect_height = m_stUserDefectArea.defect_height;
|
it->defect_threshold = m_stUserDefectArea.defect_threshold;
|
it->defect_dilation = m_stUserDefectArea.defect_dilation;
|
|
m_pGlassRecipe->SaveUserDefectList();
|
FillUserDefectGrid(TRUE);
|
|
m_stUserDefectArea.defect_width = 0;
|
m_stUserDefectArea.defect_height = 0;
|
m_stUserDefectArea.defect_threshold = 0;
|
m_stUserDefectArea.defect_dilation = 0;
|
|
UpdateData(FALSE);
|
|
}
|
|
void CViewUserDefectArea::OnGridDBClick(NMHDR *pNotifyStruct, LRESULT* pResult)
|
{
|
NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNotifyStruct;
|
if (pItem->iRow < 0)
|
return;
|
|
m_nSelectRow = pItem->iRow;
|
|
if(m_pGlassRecipe == NULL)
|
return;
|
|
USER_DEFECT_AREA_LIST *pList = m_pGlassRecipe->GetUserDefectList((DimensionDir)m_index);
|
if(pList == NULL)
|
return;
|
|
if((int)pList->size() < m_nSelectRow)
|
return;
|
|
itUSER_DEFECT_AREA_LIST it = pList->begin();
|
|
std::advance(it, m_nSelectRow-1);
|
|
m_stUserDefectArea.defect_width = it->defect_width;
|
m_stUserDefectArea.defect_height = it->defect_height;
|
m_stUserDefectArea.defect_threshold = it->defect_threshold;
|
m_stUserDefectArea.defect_dilation = it->defect_dilation;
|
|
UpdateData(FALSE);
|
}
|
|
void CViewUserDefectArea::OnBnClickedButtonUserDefectAreaDelete()
|
{
|
if(m_pGlassRecipe == NULL)
|
return;
|
|
USER_DEFECT_AREA_LIST *pList = m_pGlassRecipe->GetUserDefectList((DimensionDir)m_index);
|
if(pList == NULL)
|
return;
|
|
if((int)pList->size() < m_nSelectRow)
|
return;
|
|
itUSER_DEFECT_AREA_LIST it = pList->begin();
|
|
std::advance(it, m_nSelectRow-1);
|
|
pList->erase(it);
|
|
FillUserDefectGrid(TRUE);
|
|
m_pGlassRecipe->SaveUserDefectList();
|
|
m_stUserDefectArea.defect_width = 0;
|
m_stUserDefectArea.defect_height = 0;
|
m_stUserDefectArea.defect_threshold = 0;
|
m_stUserDefectArea.defect_dilation = 0;
|
|
UpdateData(FALSE);
|
|
if(m_pIU2P != NULL)
|
{
|
m_pIU2P->IU2P_DrawRefresh();
|
}
|
}
|
|
|
void CViewUserDefectArea::Init_UserDefectGrid()
|
{
|
if(m_GrdUserDefect.GetSafeHwnd() == NULL)
|
return;
|
|
m_GrdUserDefect.GetDefaultCell(TRUE, FALSE)->SetBackClr(GRID_FIX_COLOR);
|
m_GrdUserDefect.GetDefaultCell(FALSE, TRUE)->SetBackClr(GRID_FIX_COLOR);
|
m_GrdUserDefect.GetDefaultCell(FALSE, FALSE)->SetBackClr(GRID_COLOR);
|
m_GrdUserDefect.SetFixedBkColor(GRID_FIX_COLOR);
|
m_GrdUserDefect.SetGridLines(GVL_BOTH);
|
|
m_GrdUserDefect.SetColumnCount(USERDEFECT_COLUMN_COUNT);
|
m_GrdUserDefect.SetRowCount(10);
|
m_GrdUserDefect.SetFixedRowCount(1);
|
m_GrdUserDefect.SetFixedColumnCount(0);
|
m_GrdUserDefect.ExpandColumnsToFit();
|
|
CFont *pFont = m_GrdUserDefect.GetFont();
|
if (!pFont)
|
return;
|
|
LOGFONT lf;
|
pFont->GetLogFont(&lf);
|
lf.lfItalic = 0;
|
lf.lfHeight = 14;
|
lf.lfWeight = FW_BOLD;
|
_tcscpy(lf.lfFaceName, _T("Arial"));
|
|
m_GrdUserDefect.GetDefaultCell(TRUE, FALSE)->SetFont(&lf);
|
m_GrdUserDefect.GetDefaultCell(FALSE, TRUE)->SetFont(&lf);
|
m_GrdUserDefect.GetDefaultCell(TRUE, TRUE)->SetFont(&lf);
|
m_GrdUserDefect.SetEditable(FALSE);
|
m_GrdUserDefect.SetSingleRowSelection(TRUE);
|
m_GrdUserDefect.EnableSelection(TRUE);
|
|
Init_UserDefectGridHeader();
|
}
|
|
void CViewUserDefectArea::Init_UserDefectGridHeader()
|
{
|
CString str;
|
GV_ITEM Item;
|
int nCol = 0;
|
int iLoop;
|
|
Item.mask = GVIF_TEXT;
|
Item.row = 0;
|
for(iLoop=0;iLoop<USERDEFECT_COLUMN_COUNT;iLoop++)
|
{
|
Item.col = nCol++;
|
Item.strText = USERDEFECT_COLUMN_ITEM[iLoop];
|
m_GrdUserDefect.SetItem(&Item);
|
m_GrdUserDefect.SetColumnWidth(Item.col,USERDEFECT_COLUMN_WIDHT[iLoop]);
|
}
|
|
m_GrdUserDefect.Invalidate();
|
}
|
|
void CViewUserDefectArea::FillUserDefectGrid(BOOL bWrite)
|
{
|
int iRow,iCol;
|
CString str;
|
|
if(m_pGlassRecipe == NULL)
|
return;
|
|
itUSER_DEFECT_AREA_LIST it;
|
USER_DEFECT_AREA_LIST *pList = m_pGlassRecipe->GetUserDefectList((DimensionDir)m_index);
|
ST_USER_DEFECT_AREA stUserDefect;
|
|
if(bWrite == TRUE)
|
{
|
m_GrdUserDefect.SetRowCount((int)pList->size()+1);
|
|
iRow = 1;
|
|
for(it=pList->begin();it!=pList->end();it++)
|
{
|
iCol = 0;
|
|
stUserDefect = *it;
|
|
str.Format(_T("%d"),iRow);
|
m_GrdUserDefect.SetItemText(iRow,iCol,str);
|
iCol++;
|
|
str.Format(_T("%d"),stUserDefect.x);
|
m_GrdUserDefect.SetItemText(iRow,iCol,str);
|
iCol++;
|
|
str.Format(_T("%d"),stUserDefect.y);
|
m_GrdUserDefect.SetItemText(iRow,iCol,str);
|
iCol++;
|
|
str.Format(_T("%d"),stUserDefect.area_width);
|
m_GrdUserDefect.SetItemText(iRow,iCol,str);
|
iCol++;
|
|
str.Format(_T("%d"),stUserDefect.area_height);
|
m_GrdUserDefect.SetItemText(iRow,iCol,str);
|
iCol++;
|
|
str.Format(_T("%d"),stUserDefect.defect_width);
|
m_GrdUserDefect.SetItemText(iRow,iCol,str);
|
iCol++;
|
|
str.Format(_T("%d"),stUserDefect.defect_height);
|
m_GrdUserDefect.SetItemText(iRow,iCol,str);
|
iCol++;
|
|
str.Format(_T("%d"),stUserDefect.defect_threshold);
|
m_GrdUserDefect.SetItemText(iRow,iCol,str);
|
iCol++;
|
|
str.Format(_T("%d"),stUserDefect.defect_dilation);
|
m_GrdUserDefect.SetItemText(iRow,iCol,str);
|
iCol++;
|
|
iRow++;
|
}
|
|
m_GrdUserDefect.Invalidate();
|
|
}
|
else
|
{
|
iRow = 1;
|
int nRow = m_GrdUserDefect.GetRowCount();
|
|
pList->clear();
|
|
if(iRow <= nRow)
|
return;
|
|
for(iRow=1;iRow<nRow;iRow++)
|
{
|
iCol = 1;
|
|
stUserDefect.clear();
|
|
str = m_GrdUserDefect.GetItemText(iRow,iCol);
|
stUserDefect.x = _ttoi(str);
|
iCol++;
|
|
str = m_GrdUserDefect.GetItemText(iRow,iCol);
|
stUserDefect.y = _ttoi(str);
|
iCol++;
|
|
str = m_GrdUserDefect.GetItemText(iRow,iCol);
|
stUserDefect.area_width = _ttoi(str);
|
iCol++;
|
|
str = m_GrdUserDefect.GetItemText(iRow,iCol);
|
stUserDefect.area_height = _ttoi(str);
|
iCol++;
|
|
str = m_GrdUserDefect.GetItemText(iRow,iCol);
|
stUserDefect.defect_width = _ttoi(str);
|
iCol++;
|
|
str = m_GrdUserDefect.GetItemText(iRow,iCol);
|
stUserDefect.defect_height = _ttoi(str);
|
iCol++;
|
|
str = m_GrdUserDefect.GetItemText(iRow,iCol);
|
stUserDefect.defect_threshold = _ttoi(str);
|
iCol++;
|
|
str = m_GrdUserDefect.GetItemText(iRow,iCol);
|
stUserDefect.defect_dilation = _ttoi(str);
|
|
pList->push_back(stUserDefect);
|
}
|
}
|
}
|