// ViewRecipeSetting.cpp : 备泅 颇老涝聪促.
|
//
|
|
#include "stdafx.h"
|
#include "ENRIT.h"
|
#include "ViewRecipeSetting.h"
|
#include "afxdialogex.h"
|
#include "ViewRecipeList.h"
|
#include "ViewUserDefectArea.h"
|
#include "ViewException.h"
|
#include "ViewLampControl.h"
|
#include "DlgLogin.h"
|
// CViewRecipeSetting 措拳 惑磊涝聪促.
|
|
IMPLEMENT_DYNAMIC(CViewRecipeSetting, CDialogEx)
|
|
static CViewRecipeSetting *m_pThis = NULL;
|
CViewRecipeSetting::CViewRecipeSetting(CWnd* pParent /*=NULL*/)
|
: CDialogEx(CViewRecipeSetting::IDD, pParent)
|
{
|
m_pDlgRecipe = new CGlassRecipe;
|
m_IV2M = NULL;
|
m_pGlassData = NULL;
|
m_pViewRecipeList = NULL;
|
m_pViewUserDefect = NULL;
|
m_pViewExpArea = NULL;
|
m_pviewLightControl = NULL;
|
m_pHardware = NULL;
|
m_pViewRecipeInspection = NULL;
|
m_pViewRecipeProfile = NULL;
|
m_pViewRecipeChamfer = NULL;
|
m_nCndRDSide = 0;
|
m_nCndSelect = 0;
|
|
m_pVisionSetDlg = NULL;
|
m_pThis = this;
|
}
|
|
CViewRecipeSetting::~CViewRecipeSetting()
|
{
|
DeleteVectorList();
|
|
delete m_pDlgRecipe;
|
m_pDlgRecipe = NULL;
|
|
if(m_pViewRecipeList != NULL)
|
{
|
delete m_pViewRecipeList;
|
m_pViewRecipeList = NULL;
|
}
|
if(m_pViewUserDefect != NULL)
|
{
|
delete m_pViewUserDefect;
|
m_pViewUserDefect = NULL;
|
}
|
if(m_pViewExpArea != NULL)
|
{
|
delete m_pViewExpArea;
|
m_pViewExpArea = NULL;
|
}
|
if(m_pviewLightControl != NULL)
|
{
|
delete m_pviewLightControl;
|
m_pviewLightControl = NULL;
|
}
|
if(m_pViewRecipeInspection != NULL)
|
{
|
delete m_pViewRecipeInspection;
|
m_pViewRecipeInspection = NULL;
|
}
|
if(m_pViewRecipeProfile != NULL)
|
{
|
delete m_pViewRecipeProfile;
|
m_pViewRecipeProfile = NULL;
|
}
|
if(m_pViewRecipeChamfer != NULL)
|
{
|
delete m_pViewRecipeChamfer;
|
m_pViewRecipeChamfer = NULL;
|
}
|
|
if (NULL != m_pVisionSetDlg) {
|
if (0 == BlVision_GetSoftVisionApp()->ReleaseWindow(m_pVisionSetDlg)) {
|
m_pVisionSetDlg = NULL;
|
}
|
}
|
}
|
|
void CViewRecipeSetting::DoDataExchange(CDataExchange* pDX)
|
{
|
DDX_Control(pDX, IDC_STATIC_RECIPE_NAME, m_ctrlRecipeName);
|
DDX_Control(pDX, IDC_STATIC_RECIPE_COMMENT, m_ctrlRecipeComment);
|
DDX_Control(pDX, IDC_BUTTON_RECIPE_LIST, m_ctrlRecipList);
|
|
DDX_Control(pDX, IDC_SLIDER_ZOOM2 , m_sliderZoom);
|
DDX_Control(pDX, IDC_SCROLLBAR_V , m_ctrlScrollV);
|
DDX_Control(pDX, IDC_SCROLLBAR_H , m_ctrlScrollH);
|
DDX_Text(pDX, IDC_BRUSH_GRAY , m_frameImg.m_nBrushGray);
|
|
UINT nIDCmdSelect[] = { IDC_RDO_RCP_INSPECT_SETTING,IDC_RDO_RCP_PROFILE_SETTING,IDC_RDO_RCP_CHAMFER_SETTING};
|
for (int i = 0; i < eRcp_End; i++) {
|
DDX_Control(pDX, nIDCmdSelect[i], m_ctrlCmdSelect[i]);
|
}
|
|
CDialogEx::DoDataExchange(pDX);
|
}
|
|
|
BEGIN_MESSAGE_MAP(CViewRecipeSetting, CDialogEx)
|
ON_WM_SHOWWINDOW()
|
ON_WM_HSCROLL()
|
ON_WM_VSCROLL()
|
ON_WM_MOUSEWHEEL()
|
ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER_ZOOM2, &CViewRecipeSetting::OnNMCustomdrawSliderZoom2)
|
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER_ZOOM2, &CViewRecipeSetting::OnNMReleasedcaptureSliderZoom2)
|
ON_MESSAGE(WM_POCESS_STATUS , &CViewRecipeSetting::OnProcessStatus)
|
ON_MESSAGE(UM_SELECT_RECIPE, &CViewRecipeSetting::OnSelectRecipe)
|
ON_MESSAGE(WM_AREA_ITEM_MODIFY ,&CViewRecipeSetting::OnAreaModify)
|
ON_MESSAGE(WM_AREA_ITEM_SELECT_CHANGE ,&CViewRecipeSetting::OnAreaChange)
|
ON_MESSAGE(UM_LIGHT_APPLY_RECIPE ,&CViewRecipeSetting::OnLightApplyRecipe)
|
END_MESSAGE_MAP()
|
|
|
// CViewRecipeSetting 皋矫瘤 贸府扁涝聪促.
|
BEGIN_EVENTSINK_MAP(CViewRecipeSetting, CDialogEx)
|
ON_EVENT(CViewRecipeSetting, IDC_BTN_IMG_LOAD, DISPID_CLICK, CViewRecipeSetting::ClickImgLoadButton, VTS_NONE)
|
ON_EVENT(CViewRecipeSetting, IDC_BTN_IMG_SAVE, DISPID_CLICK, CViewRecipeSetting::ClickImgSaveButton, VTS_NONE)
|
ON_EVENT(CViewRecipeSetting, IDC_BTN_IMG_INIT, DISPID_CLICK, CViewRecipeSetting::ClickInitProcessButton, VTS_NONE)
|
ON_EVENT(CViewRecipeSetting, IDC_BTN_IMG_PROCESS, DISPID_CLICK, CViewRecipeSetting::ClickInspectProcessButton, VTS_NONE)
|
ON_EVENT(CViewRecipeSetting, IDC_BTN_RECIPE_SAVE, DISPID_CLICK, CViewRecipeSetting::ClickRecipeSaveButton, VTS_NONE)
|
ON_EVENT(CViewRecipeSetting, IDC_BUTTON_RECIPE_LIST, DISPID_CLICK, CViewRecipeSetting::ClickRecipeListButton, VTS_NONE)
|
ON_EVENT(CViewRecipeSetting, IDC_BUTTON_OPEN_USER_DEFECT_VIEW, DISPID_CLICK, CViewRecipeSetting::OnBnClickedBtnUserDefect, VTS_NONE)
|
ON_EVENT(CViewRecipeSetting, IDC_BTN_FILTER_LIST1, DISPID_CLICK, CViewRecipeSetting::OnBnClickedBtnExpRegion, VTS_NONE)
|
ON_EVENT(CViewRecipeSetting, IDC_BUTTON_LIGHT_CONTROL, DISPID_CLICK, CViewRecipeSetting::OnBnClickedBtnLightControl, VTS_NONE)
|
ON_EVENT(CViewRecipeSetting, IDC_RDO_RCP_INSPECT_SETTING, DISPID_CLICK, CViewRecipeSetting::ClickChkSelectlButton, VTS_NONE)
|
ON_EVENT(CViewRecipeSetting, IDC_RDO_RCP_PROFILE_SETTING, DISPID_CLICK, CViewRecipeSetting::ClickChkSelectlButton, VTS_NONE)
|
ON_EVENT(CViewRecipeSetting, IDC_RDO_RCP_CHAMFER_SETTING, DISPID_CLICK, CViewRecipeSetting::ClickChkSelectlButton, VTS_NONE)
|
ON_EVENT(CViewRecipeSetting, IDC_BUTTON_LANG_ENGLISH, DISPID_CLICK, CViewRecipeSetting::OnClickButtonLang, VTS_NONE)
|
ON_EVENT(CViewRecipeSetting, IDC_BUTTON_LANG_KOREAN, DISPID_CLICK, CViewRecipeSetting::OnClickButtonLang, VTS_NONE)
|
ON_EVENT(CViewRecipeSetting, IDC_BUTTON_LANG_CHINESE, DISPID_CLICK, CViewRecipeSetting::OnClickButtonLang, VTS_NONE)
|
ON_EVENT(CViewRecipeSetting, IDC_BUTTON_VISION_SET, DISPID_CLICK, CViewRecipeSetting::ClickButtonVisionSet, VTS_NONE)
|
END_EVENTSINK_MAP()
|
|
BOOL CViewRecipeSetting::PreTranslateMessage(MSG* pMsg)
|
{
|
if( pMsg->message == WM_KEYDOWN )
|
{
|
if(pMsg->wParam == VK_RETURN
|
|| pMsg->wParam == VK_ESCAPE )
|
{
|
::TranslateMessage(pMsg);
|
::DispatchMessage(pMsg);
|
return TRUE; // DO NOT process further
|
}
|
}
|
|
return CDialog::PreTranslateMessage(pMsg);
|
}
|
|
BOOL CViewRecipeSetting::OnInitDialog()
|
{
|
UpdateData(FALSE);
|
|
m_pViewRecipeList = new CViewRecipeList;
|
m_pViewRecipeList->Create(CViewRecipeList::IDD,this);
|
m_pViewRecipeList->SetParent(this);
|
m_pViewRecipeList->ShowWindow(SW_HIDE);
|
|
m_pViewUserDefect = new CViewUserDefectArea;
|
m_pViewUserDefect->Create(CViewUserDefectArea::IDD,this);
|
m_pViewUserDefect->SetIU2P(static_cast<IUserDefectInterface2Parent*>(this));
|
m_pViewUserDefect->ShowWindow(SW_HIDE);
|
|
m_pViewExpArea = new CViewException;
|
m_pViewExpArea->Create(CViewException::IDD,this);
|
m_pViewExpArea->SetIU2P(static_cast<IUserDefectInterface2Parent*>(this));
|
m_pViewExpArea->ShowWindow(SW_HIDE);
|
|
m_pviewLightControl = new CViewLampControl;
|
m_pviewLightControl->Create(CViewLampControl::IDD,this);
|
m_pviewLightControl->ShowWindow(SW_HIDE);
|
m_pviewLightControl->SetParent(this);
|
|
m_pViewRecipeInspection = new CViewRecipeInspectionView;
|
m_pViewRecipeInspection->Create(CViewRecipeInspectionView::IDD,this);
|
m_pViewRecipeInspection->SetI2M((IInspectRecipeView2Parent*)this);
|
m_pViewRecipeInspection->SetH2M((IHoleRecipeView2Parent*)this);
|
|
CRect rect,cRect;
|
|
((CWnd*)GetDlgItem(IDC_STATIC_RECIPE_BASE_BAR))->GetWindowRect(rect);
|
ScreenToClient(&rect);
|
m_pViewRecipeInspection->GetClientRect(cRect);
|
cRect.OffsetRect(rect.left,rect.bottom + 5);
|
m_pViewRecipeInspection->MoveWindow(cRect);
|
m_pViewRecipeInspection->ShowWindow(SW_HIDE);
|
|
m_pViewRecipeProfile = new CViewRecipeProfileView;
|
m_pViewRecipeProfile->Create(CViewRecipeProfileView::IDD,this);
|
m_pViewRecipeProfile->MoveWindow(cRect);
|
m_pViewRecipeProfile->ShowWindow(SW_HIDE);
|
|
m_pViewRecipeChamfer = new CViewRecipeChamferView;
|
m_pViewRecipeChamfer->Create(CViewRecipeChamferView::IDD,this);
|
m_pViewRecipeChamfer->MoveWindow(cRect);
|
m_pViewRecipeChamfer->ShowWindow(SW_HIDE);
|
|
m_sliderZoom.SetRange(0,8);
|
m_sliderZoom.SetPos(4);
|
|
m_frameImg.InitBitMap();
|
m_frameImg.SetSide(0);
|
|
GetDlgItem(IDC_STATIC_SELECT_IMG)->GetWindowRect(m_rcFrameImg);
|
GetDlgItem(IDC_STATIC_SELECT_IMG)->DestroyWindow();
|
|
ScreenToClient(m_rcFrameImg);
|
m_frameImg.Create(NULL,NULL,WS_VISIBLE | WS_CHILD,m_rcFrameImg,this,0);
|
|
InitScrollInfo();
|
|
LoadLinkFile(LINK_FILE_NAME);
|
|
m_pVisionEvent = new IVisionEvent(onMsgVisionEvent, onMsgLogEvent);
|
BlVision_GetSoftVisionApp()->setImageEventSignal(m_pVisionEvent);
|
|
return TRUE;
|
}
|
|
void CViewRecipeSetting::onMsgVisionEvent(int code, int eDir) {
|
/* code */
|
if (1 == code) { //获取区域数据
|
m_pThis->SetFrameRegion();
|
}
|
else if (2 == code) { //获取效果
|
m_pThis->DispAllResult();
|
}
|
}
|
|
void CViewRecipeSetting::onMsgLogEvent(int level, std::string strText) {
|
/* code */
|
CString str = CA2T(strText.c_str());
|
g_pLog->DisplayMessage(str);
|
}
|
|
void CViewRecipeSetting::SetFrameRegion(void) {
|
/* code */
|
if (!m_frameImg.GetMode(MODE_MARK_REG)) return;
|
|
IVisionRecipe *pInstance = BlVision_GetVisionRecipe();
|
if (NULL == pInstance) return;
|
|
CRect rtMeasureRect = m_frameImg.GetMartRect();
|
pInstance->setFrame(rtMeasureRect.left, rtMeasureRect.top, rtMeasureRect.right, rtMeasureRect.bottom);
|
}
|
|
void CViewRecipeSetting::DispAllResult(void) {
|
/* code */
|
m_frameImg.UpdataVisionResult();
|
}
|
|
void CViewRecipeSetting::ClickChkSelectlButton()
|
{
|
UINT nID = GetFocus()->GetDlgCtrlID();
|
|
UpdateData(TRUE);
|
|
ChangeRcpView(nID);
|
}
|
|
void CViewRecipeSetting::SetButtonSelectEnableAll(const BOOL& bEnable)
|
{
|
int i;
|
for (i = 0; i < eRcp_End; i++)
|
{
|
if (m_ctrlCmdSelect[i].GetEnabled() != bEnable) {
|
m_ctrlCmdSelect[i].SetEnabled(bEnable);
|
}
|
}
|
}
|
|
void CViewRecipeSetting::SetButtonSelectSel(eViewSelect eSelView, BOOL bEnable)
|
{
|
if(eSelView >= eRcp_End) return;
|
if(m_ctrlCmdSelect[eSelView].GetEnabled() != bEnable){
|
m_ctrlCmdSelect[eSelView].SetEnabled(bEnable);
|
}
|
}
|
|
void CViewRecipeSetting::ChangeRcpView(UINT nID)
|
{
|
SetButtonSelectEnableAll(TRUE);
|
|
eViewSelect eSelView;
|
UINT nViewID;
|
switch(nID)
|
{
|
case IDC_RDO_RCP_INSPECT_SETTING:
|
m_nCndSelect = 0;
|
eSelView = eRcp_Inspection;
|
nViewID = CViewRecipeInspectionView::IDD;
|
break;
|
case IDC_RDO_RCP_PROFILE_SETTING:
|
m_nCndSelect = 1;
|
eSelView = eRcp_Profile;
|
nViewID = CViewRecipeProfileView::IDD;
|
break;
|
case IDC_RDO_RCP_CHAMFER_SETTING:
|
m_nCndSelect = 2;
|
eSelView = eRcp_Chamfer;
|
nViewID = CViewRecipeChamferView::IDD;
|
break;
|
default:
|
return;
|
}
|
|
SetButtonSelectSel(eSelView,FALSE);
|
|
ChangeSelectView(nViewID);
|
}
|
|
void CViewRecipeSetting::ChangeSelectView(UINT nViewID)
|
{
|
UINT nShow;
|
|
UINT eFrameView[] = {CViewRecipeInspectionView::IDD,CViewRecipeProfileView::IDD,CViewRecipeChamferView::IDD};
|
|
for(int i=0; i<eRcp_End; i++)
|
{
|
if(eFrameView[i] == nViewID)
|
nShow = SW_SHOW;
|
else
|
nShow = SW_HIDE;
|
|
switch(i)
|
{
|
case eRcp_Inspection: m_pViewRecipeInspection->ShowWindow(nShow); break;
|
case eRcp_Profile: m_pViewRecipeProfile->ShowWindow(nShow); break;
|
case eRcp_Chamfer: m_pViewRecipeChamfer->ShowWindow(nShow); break;
|
}
|
}
|
}
|
|
void CViewRecipeSetting::ClickImgLoadButton()
|
{
|
if(m_IV2M == NULL)
|
return;
|
|
m_IV2M->IV2M_LoadImageFullFile(m_nCndRDSide,m_pGlassData);
|
|
m_frameImg.Invalidate(FALSE);
|
InitScrollInfo();
|
}
|
|
void CViewRecipeSetting::ClickImgSaveButton()
|
{
|
CPoint ptStart;
|
int nLength;
|
const int nOneFrameSize = 50000;
|
CString strPath,strLog;
|
int iSide = m_nCndRDSide;
|
int nTotalLength = 0;
|
int nFrame = 0;
|
|
if(m_pGlassData == NULL || m_IV2M == NULL || m_pHardware == NULL)
|
return;
|
|
int iCam = m_pHardware->GetCameraIndexToDimension((DimensionDir)iSide);
|
int iScan = m_pHardware->GetScanToDimension((DimensionDir)iSide);
|
|
CCameraSettings *pCamera = m_pHardware->GetCameraSettings(iCam,iScan);
|
if(pCamera == NULL)
|
return;
|
|
CGlassRecipe *pGlassRcp = m_pGlassData->GetGlassRecipe();
|
CString strRcpName = pGlassRcp->GetRecipeName();
|
|
nTotalLength = pCamera->m_nGrabFrameCount*pCamera->m_FrameSize.cy;
|
nFrame = nTotalLength/nOneFrameSize;
|
|
ptStart.x = 0;
|
ptStart.y = max(0,0);
|
|
INS_EDGE_RESULT_INFO *pEdgeInfo = m_pGlassData->GetEdgeResultInfo((DimensionDir)iSide);
|
if(pEdgeInfo != NULL)
|
{
|
ptStart.y = max(0,pEdgeInfo->nGlassStartLine-1000);
|
|
nTotalLength = min((pEdgeInfo->nGlassEndLine + 1000) - ptStart.y,pCamera->m_nGrabFrameCount*pCamera->m_FrameSize.cy);
|
}
|
|
CString strGlassID = g_pBase->m_strHPanelID;
|
if(strGlassID.IsEmpty() == TRUE)
|
{
|
strGlassID = _T("Manual_ID");
|
}
|
|
if(strRcpName.IsEmpty() == TRUE)
|
{
|
strRcpName = _T("TestRcp");
|
}
|
|
strGlassID.Trim(_T(' '));
|
|
CTime time = CTime::GetCurrentTime();
|
|
CString strDate,strTime;
|
|
strDate.Format(_T("%04d%02d%02d"),time.GetYear(),time.GetMonth(),time.GetDay());
|
strTime.Format(_T("%02d%02d%02d"),time.GetHour(),time.GetMinute(),time.GetSecond());
|
|
for(int i = 0; i < nFrame ; i++)
|
{
|
nLength = nOneFrameSize;
|
|
strPath.Format(_T("%sDebugFullImage\\%s\\%s\\%s\\%s\\%s__%s_%d"),PATH_INSPECTION_DATA,strDate,strRcpName,strGlassID,strTime,strGlassID,PANEL_SIDE[iSide],i);
|
|
m_IV2M->IV2M_SaveFullImage(strPath,iSide,ptStart,nLength);
|
ptStart.y += nLength;
|
}
|
|
nLength = nTotalLength%nOneFrameSize;
|
if(nLength)
|
{
|
strPath.Format(_T("%sDebugFullImage\\%s\\%s\\%s\\%s\\%s__%s_%d"),PATH_INSPECTION_DATA,strDate,strRcpName,strGlassID,strTime,strGlassID,PANEL_SIDE[iSide],nFrame);
|
|
m_IV2M->IV2M_SaveFullImage(strPath,iSide,ptStart,nLength);
|
}
|
|
//AfxMessageBox(_T("Save Completed"));
|
}
|
|
void CViewRecipeSetting::ClickInitProcessButton()
|
{
|
InitView();
|
|
if(m_IV2M != NULL)
|
{
|
m_IV2M->IV2M_InitView(VIEW_RECIPE);
|
}
|
}
|
|
void CViewRecipeSetting::ClickInspectProcessButton()
|
{
|
DimensionDir eDim = (DimensionDir)m_nCndRDSide;
|
|
m_IV2M->IV2M_InspectionProcess(eDim);
|
}
|
|
void CViewRecipeSetting::OnShowWindow(BOOL bShow, UINT nStatus)
|
{
|
if(bShow == TRUE)
|
{
|
UpdateData(FALSE);
|
|
m_frameImg.SetRecipe(m_pHardware,m_pDlgRecipe);
|
m_frameImg.SetGlassData(m_pGlassData);
|
m_frameImg.SetSide(m_nCndRDSide);
|
|
InitScrollInfo();
|
|
UINT eViewID[] = {IDC_RDO_RCP_INSPECT_SETTING,IDC_RDO_RCP_PROFILE_SETTING};
|
|
ChangeRcpView(eViewID[m_nCndSelect]);
|
}
|
}
|
|
void CViewRecipeSetting::SetGlassData(CGlass_Data *pGlass)
|
{
|
m_pGlassData = pGlass;
|
}
|
|
void CViewRecipeSetting::ViewRefresh(PROG_MSG ProcMsg)
|
{
|
SendMessage(WM_POCESS_STATUS,(WPARAM)&ProcMsg, ProcMsg.nSide);
|
}
|
|
void CViewRecipeSetting::SetV2M(IViewInterface2Parent* pV2M)
|
{
|
m_IV2M = pV2M;
|
if(m_pviewLightControl != NULL)
|
m_pviewLightControl->SetIV2P(static_cast<IViewInterface2Parent*>(m_IV2M));
|
m_frameImg.SetMainInterface(m_IV2M);
|
}
|
|
void CViewRecipeSetting::InitView()
|
{
|
m_pGlassData= NULL;
|
|
if(m_IV2M != NULL)
|
{
|
LPBYTE plpBuf = NULL;
|
if(m_IV2M != NULL)
|
plpBuf = m_IV2M->IV2M_GetGrabBufferByDimension((DimensionDir)m_nCndRDSide,0);
|
m_frameImg.SetImage(plpBuf);
|
}
|
|
m_frameImg.SetGlassData(m_pGlassData);
|
m_frameImg.SetRecipe(m_pHardware,m_pDlgRecipe);
|
m_frameImg.SetSide(m_nCndRDSide);
|
|
InitScrollInfo(TRUE);
|
}
|
|
void CViewRecipeSetting::SetRecipe(CHardwareSettings *pHW,CGlassRecipe *pRecipe)
|
{
|
m_pHardware = pHW;
|
m_pRecipe = pRecipe;
|
|
if(pRecipe != NULL)
|
{
|
*m_pDlgRecipe = *pRecipe;
|
}
|
|
if(m_IV2M != NULL)
|
{
|
LPBYTE plpBuf = NULL;
|
if(m_IV2M != NULL)
|
plpBuf = m_IV2M->IV2M_GetGrabBufferByDimension((DimensionDir)m_nCndRDSide,0);
|
m_frameImg.SetImage(plpBuf);
|
}
|
|
m_frameImg.SetGlassData(m_pGlassData);
|
m_frameImg.SetRecipe(m_pHardware,m_pDlgRecipe);
|
m_frameImg.SetSide(m_nCndRDSide);
|
|
InitScrollInfo();
|
|
m_strRecipeName = m_pDlgRecipe->GetRecipeName();
|
m_ctrlRecipeName.SetCaption(m_strRecipeName);
|
m_ctrlRecipeComment.SetCaption(m_pDlgRecipe->m_GlassParm.m_strDisp);
|
|
if(m_pViewRecipeInspection)
|
m_pViewRecipeInspection->SetRecipe(m_pHardware,m_pDlgRecipe);
|
if(m_pViewRecipeProfile)
|
m_pViewRecipeProfile->SetRecipe(m_pHardware,m_pDlgRecipe);
|
if(m_pViewRecipeChamfer)
|
m_pViewRecipeChamfer->SetRecipe(m_pHardware,m_pDlgRecipe);
|
|
std::string strVisionName = BlVision_GetVisionRecipe()->getVisionName();
|
CW2A pszConvertedAnsiString(m_strRecipeName);
|
if (strVisionName.compare(pszConvertedAnsiString) != 0)
|
{
|
auto startTime = std::chrono::high_resolution_clock::now();
|
BlVision_GetVisionRecipe()->setVisionName(pszConvertedAnsiString);
|
BlVision_GetVisionRecipe()->open();
|
auto endTime = std::chrono::high_resolution_clock::now();
|
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);
|
g_pLog->DisplayMessage(_T("Read VisionRecipe %s %lld milliseconds"), m_strRecipeName, duration.count());
|
}
|
|
int nGlassSizeX = m_pDlgRecipe->m_GlassParm.m_nGlassSizeX;
|
int nGlassSizeY = m_pDlgRecipe->m_GlassParm.m_nGlassSizeY;
|
BlVision_GetVisionRecipe()->setGlassSize(nGlassSizeX, nGlassSizeY);
|
}
|
|
void CViewRecipeSetting::InitScrollInfo(BOOL bInitPos /*= FALSE*/)
|
{
|
int i =0;
|
|
SCROLLINFO scrollInfoV;
|
SCROLLINFO scrollInfoH;
|
|
int nPos_V = m_ctrlScrollV.GetScrollPos();
|
int nPos_H = m_ctrlScrollH.GetScrollPos();
|
|
if(bInitPos)
|
{
|
nPos_V = 0;
|
nPos_H = 0;
|
}
|
|
scrollInfoV.cbSize = sizeof(SCROLLINFO);
|
scrollInfoV.fMask = SIF_ALL;
|
scrollInfoV.nMin = 1;
|
if(scrollInfoV.nMin < 1)
|
scrollInfoV.nMin = 1;
|
scrollInfoV.nPos = 1;
|
scrollInfoV.nTrackPos = 400;
|
scrollInfoV.nMax = INT_MAX;
|
|
scrollInfoH.cbSize = sizeof(SCROLLINFO);
|
scrollInfoH.fMask = SIF_ALL;
|
scrollInfoH.nMin = 1;
|
scrollInfoH.nPos = 1;
|
scrollInfoH.nTrackPos = 64;
|
|
double dZoom = m_frameImg.GetZoomData();
|
|
scrollInfoV.nPage = m_rcFrameImg.Height();
|
scrollInfoH.nPage = int(m_rcFrameImg.Width() / dZoom);
|
scrollInfoH.nMax = IMAGE_WIDTH;
|
|
if(m_pGlassData != NULL)
|
{
|
INS_EDGE_RESULT_INFO *pEdgeInfo = m_pGlassData->GetEdgeResultInfo((DimensionDir)m_nCndRDSide);
|
if(pEdgeInfo != NULL)
|
{
|
int nEndLIne = pEdgeInfo->nGlassEndLine;
|
if(nEndLIne <= 0)
|
nEndLIne = pEdgeInfo->nPreGlassEndLine;
|
|
scrollInfoV.nMax = nEndLIne - pEdgeInfo->nGlassStartLine + (int)(m_rcFrameImg.Height() * dZoom);
|
}
|
}
|
else
|
{
|
if(m_nCndRDSide%2)
|
scrollInfoV.nMax = MAX_IMAGE_LINE_SHORT - int(m_rcFrameImg.Height() / dZoom);
|
else
|
scrollInfoV.nMax = MAX_IMAGE_LINE_LONG - int(m_rcFrameImg.Height() / dZoom);
|
}
|
|
if(m_pHardware == NULL)
|
{
|
if(m_nCndRDSide%2)
|
scrollInfoV.nMax = min(MAX_IMAGE_LINE_SHORT - int(m_rcFrameImg.Height() / dZoom),scrollInfoV.nMax);
|
else
|
scrollInfoV.nMax = min(MAX_IMAGE_LINE_LONG - int(m_rcFrameImg.Height() / dZoom),scrollInfoV.nMax);
|
}
|
else
|
{
|
int iCam = m_pHardware->GetCameraIndexToDimension((DimensionDir)m_nCndRDSide);
|
int nMaxLine = g_pBase->m_pMemFrameNo[iCam]*g_pBase->m_pFrameHeight[iCam];
|
|
scrollInfoV.nMax = min(nMaxLine - int(m_rcFrameImg.Height() / dZoom),scrollInfoV.nMax);
|
}
|
|
m_ctrlScrollV.SetScrollInfo(&scrollInfoV);
|
m_ctrlScrollV.SetScrollPos(nPos_V);
|
|
m_ctrlScrollH.SetScrollInfo(&scrollInfoH);
|
m_ctrlScrollH.SetScrollPos(nPos_H);
|
}
|
|
void CViewRecipeSetting::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
|
{
|
if(pScrollBar->m_hWnd == m_ctrlScrollH.m_hWnd)
|
{
|
SCROLLINFO si;
|
si.fMask=SIF_ALL;
|
m_ctrlScrollH.GetScrollInfo(&si,SIF_ALL);
|
|
switch(nSBCode)
|
{
|
case SB_LINEUP:
|
si.nPos--;
|
break;
|
case SB_LINEDOWN:
|
si.nPos++;
|
break;
|
case SB_PAGEUP:
|
si.nPos-=si.nPage;
|
break;
|
case SB_PAGEDOWN:
|
si.nPos+=si.nPage;
|
break;
|
case SB_THUMBTRACK:
|
si.nPos=nPos;
|
break;
|
}
|
|
if(si.nPos>(int)(si.nMax-si.nMin-si.nPage+1)) si.nPos=si.nMax-si.nMin-si.nPage+1;
|
if(si.nPos<si.nMin) si.nPos=si.nMin;
|
si.fMask=SIF_POS;
|
|
m_ctrlScrollH.SetScrollInfo(&si);
|
m_frameImg.m_ptOrg.x = si.nPos;
|
m_frameImg.ViewUpdate();
|
}
|
CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
|
}
|
|
void CViewRecipeSetting::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
|
{
|
if(!pScrollBar->m_hWnd)
|
{
|
CDialogEx::OnVScroll(nSBCode, nPos, pScrollBar);
|
return;
|
}
|
|
|
if(pScrollBar->m_hWnd == m_ctrlScrollV.m_hWnd)
|
{
|
int pos;
|
SCROLLINFO si;
|
si.fMask=SIF_ALL;
|
|
m_ctrlScrollV.GetScrollInfo(&si,SIF_ALL);
|
|
switch(nSBCode)
|
{
|
|
case SB_LINEUP:
|
si.nPos = si.nPos -1;
|
break;
|
case SB_LINEDOWN:
|
si.nPos = si.nPos +1;
|
break;
|
case SB_PAGEUP:
|
si.nPos-=si.nPage;
|
break;
|
case SB_PAGEDOWN:
|
si.nPos+=si.nPage;
|
break;
|
case SB_THUMBTRACK:
|
si.nPos = si.nTrackPos;
|
break;
|
|
}
|
|
if(si.nPos>(int)(si.nMax-si.nMin -si.nPage+1))
|
si.nPos=si.nMax-si.nMin-si.nPage+1;
|
|
if(si.nPos<si.nMin)
|
si.nPos=si.nMin;
|
|
si.fMask=SIF_POS;
|
pos = si.nPos - 1;
|
pos += 0;//g_GrabInfo[m_nCndRDSide].nStartLine;
|
|
m_ctrlScrollV.SetScrollInfo(&si);
|
|
LPBYTE plpBuf = NULL;
|
|
|
if(m_pGlassData != NULL)
|
{
|
INS_EDGE_RESULT_INFO *pEdgeInfo = m_pGlassData->GetEdgeResultInfo((DimensionDir)m_nCndRDSide);
|
if(pEdgeInfo != NULL)
|
m_frameImg.m_ptOrg.y = max(0,pos + pEdgeInfo->nGlassStartLine - m_frameImg.m_WndRect.Height()/2);
|
}
|
else
|
m_frameImg.m_ptOrg.y = max(0,pos - m_frameImg.m_WndRect.Height()/2);
|
|
if(m_IV2M != NULL)
|
{
|
if(m_IV2M != NULL)
|
plpBuf = m_IV2M->IV2M_GetGrabBufferByDimension((DimensionDir)m_nCndRDSide,m_frameImg.m_ptOrg.y);
|
}
|
|
m_frameImg.SetImage(plpBuf);
|
m_frameImg.SetGlassData(m_pGlassData);
|
m_frameImg.ViewUpdate();
|
}
|
|
CDialogEx::OnVScroll(nSBCode, nPos, pScrollBar);
|
}
|
|
void CViewRecipeSetting::UpdateZoom()
|
{
|
m_frameImg.SetZommMode(m_dZoom);
|
InitScrollInfo();
|
m_frameImg.Invalidate(FALSE);
|
}
|
|
void CViewRecipeSetting::OnNMCustomdrawSliderZoom2(NMHDR *pNMHDR, LRESULT *pResult)
|
{
|
LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
|
|
CString strTmp;
|
int nPos = m_sliderZoom.GetPos();
|
|
|
if(nPos > 4)
|
m_dZoom = 1 + (nPos - 4) * 0.25;
|
else if(nPos < 4)
|
m_dZoom = 1 /double(5-nPos);
|
else
|
m_dZoom = 1;
|
|
|
strTmp.Format(_T("X %.2f"),m_dZoom);
|
GetDlgItem(IDC_ST_ZOOM2)->SetWindowText(strTmp);
|
|
*pResult = 0;
|
}
|
|
void CViewRecipeSetting::OnNMReleasedcaptureSliderZoom2(NMHDR *pNMHDR, LRESULT *pResult)
|
{
|
// TODO: Add your control notification handler code here
|
this->SetFocus();
|
UpdateZoom();
|
*pResult = 0;
|
}
|
|
BOOL CViewRecipeSetting::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
|
{
|
// TODO: Add your message handler code here and/or call default
|
|
int nPos = m_sliderZoom.GetPos();
|
if(zDelta > 0)
|
m_sliderZoom.SetPos(nPos+1);
|
else
|
m_sliderZoom.SetPos(nPos-1);
|
|
UpdateZoom();
|
|
return CDialogEx::OnMouseWheel(nFlags, zDelta, pt);
|
}
|
|
LRESULT CViewRecipeSetting::OnLightApplyRecipe(WPARAM wParam, LPARAM lParam)
|
{
|
return 0;
|
}
|
|
LRESULT CViewRecipeSetting::OnProcessStatus(WPARAM wParam, LPARAM lParam)
|
{
|
PROG_MSG MsgJob = *((PROG_MSG*)wParam);
|
|
if(MsgJob.nSide != m_nCndRDSide)
|
return 0;
|
|
if(MsgJob.nState == 2)
|
{
|
InitScrollInfo();
|
|
double dZoom = m_frameImg.GetZoomData();
|
|
if(m_pGlassData != NULL)
|
{
|
INS_EDGE_RESULT_INFO *pEdgeInfo = m_pGlassData->GetEdgeResultInfo((DimensionDir)MsgJob.nSide);
|
if(pEdgeInfo != NULL)
|
m_frameImg.m_ptOrg.y = CHKMAX(0,pEdgeInfo->nGlassStartLine - (int)((m_frameImg.m_WndRect.Height()/2)/ dZoom));
|
}
|
m_frameImg.SetGlassData(m_pGlassData);
|
|
if(m_IV2M != NULL)
|
{
|
LPBYTE plpBuf = NULL;
|
if(m_IV2M != NULL)
|
plpBuf = m_IV2M->IV2M_GetGrabBufferByDimension((DimensionDir)MsgJob.nSide,m_frameImg.m_ptOrg.y);
|
m_frameImg.SetImage(plpBuf);
|
}
|
}
|
else
|
{
|
InitScrollInfo();
|
|
m_frameImg.m_ptOrg.y = MsgJob.nDispLine;
|
if(m_IV2M != NULL)
|
{
|
LPBYTE plpBuf = NULL;
|
if(m_IV2M != NULL)
|
plpBuf = m_IV2M->IV2M_GetGrabBufferByDimension((DimensionDir)MsgJob.nSide,m_frameImg.m_ptOrg.y);
|
m_frameImg.SetImage(plpBuf);
|
}
|
|
m_frameImg.SetGlassData(m_pGlassData);
|
|
}
|
|
m_frameImg.ViewUpdate();
|
|
return 1;
|
}
|
|
void CViewRecipeSetting::ClickRecipeListButton()
|
{
|
if(m_pViewRecipeList != NULL)
|
{
|
m_pViewRecipeList->SetRecipeName(m_strPPIDName,m_strRecipeName);
|
m_pViewRecipeList->SetLinkList(&m_VectorLinkList);
|
m_pViewRecipeList->ShowWindow(SW_SHOW);
|
}
|
}
|
|
void CViewRecipeSetting::ClickRecipeSaveButton()
|
{
|
if(m_pDlgRecipe == NULL)
|
return;
|
|
CDlgLogin login;
|
|
login.DoModal();
|
if (login.m_bLoginOK == FALSE)
|
{
|
//AfxMessageBox(_T("Login failed! Please try again."));
|
return;
|
}
|
|
//if(IDYES == AfxMessageBox(_T("Save Parameter?"), MB_YESNO | MB_ICONQUESTION))
|
{
|
if(m_pViewRecipeInspection != NULL)
|
m_pViewRecipeInspection->UpdateData(TRUE);
|
|
UpdateData(TRUE);
|
|
if(m_strRecipeName.IsEmpty() == TRUE)
|
{
|
AfxMessageBox(_T("No Select Recipe"), MB_OK | MB_ICONERROR);
|
return;
|
}
|
|
// 急琶等 Recipe 荐沥.
|
if (m_pDlgRecipe->WriteRecipeFile() == FALSE)
|
{
|
AfxMessageBox(_T("Save Fail"), MB_OK | MB_ICONERROR);
|
return;
|
}
|
|
m_pDlgRecipe->MakeRecipeFileNameBackUp(m_strRecipeName);
|
m_pDlgRecipe->WriteRecipeFileBackUp();
|
|
if(m_IV2M != NULL)
|
m_IV2M->IV2M_RecipeChange(m_strRecipeName);
|
|
BlVision_GetVisionRecipe()->save();
|
}
|
}
|
|
BOOL CViewRecipeSetting::LoadLinkFile(CString strFilePath)
|
{
|
CConfig cfg;
|
if(!cfg.SetRegiConfig(NULL, NULL, (TCHAR*)(LPCTSTR)strFilePath, FileMap_Mode))
|
{
|
CStdioFile File;
|
CFileException ex;
|
|
if (File.Open(strFilePath, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite|CFile::shareDenyWrite, &ex) == FALSE)
|
return FALSE;
|
|
File.Close();
|
|
if(!cfg.SetRegiConfig(NULL, NULL, (TCHAR*)(LPCTSTR)strFilePath, FileMap_Mode))
|
return FALSE;
|
}
|
|
int nCount;
|
|
cfg.GetItemValue(_T("UPPER_NUMBER"), nCount, 0);
|
|
if(nCount <= 0 || nCount >= 1000)
|
return FALSE;
|
|
DeleteVectorList();
|
|
int i;
|
CString strValue = _T("");
|
|
for(i = 0; i < nCount; i++)
|
{
|
LinkList* pList = new LinkList();
|
cfg.GetItemValue(i, _T("UPPER_NAME"), strValue, _T("NoName"));
|
strValue.MakeUpper();
|
pList->m_strUpperName=strValue;
|
|
cfg.GetItemValue(i, _T("STEP_NAME"), strValue, _T("NoName"));
|
strValue.MakeUpper();
|
pList->m_strStepName=strValue;
|
|
cfg.GetItemValue(i, _T("INS_NAME"), strValue, _T("NoName"));
|
strValue.MakeUpper();
|
pList->m_strInsName=strValue;
|
|
m_VectorLinkList.push_back(pList);
|
}
|
return TRUE;
|
}
|
|
void CViewRecipeSetting::DeleteVectorList()
|
{
|
// Vector 昏力
|
LinkList* pList = NULL;
|
for (VectorLinkListIt it = m_VectorLinkList.begin(); it != m_VectorLinkList.end(); it++)
|
{
|
pList = *it;
|
if (pList)
|
delete pList;
|
}
|
m_VectorLinkList.clear();
|
}
|
|
BOOL CViewRecipeSetting::WriteLinkFile(CString strFilePath)
|
{
|
CConfig cfg;
|
if(!cfg.SetRegiConfig(NULL, NULL, (TCHAR*)(LPCTSTR)strFilePath, FileMap_Mode))
|
{
|
CStdioFile File;
|
CFileException ex;
|
|
if (File.Open(strFilePath, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite|CFile::shareDenyWrite, &ex) == FALSE)
|
return FALSE;
|
|
File.Close();
|
|
if(!cfg.SetRegiConfig(NULL, NULL, (TCHAR*)(LPCTSTR)strFilePath, FileMap_Mode))
|
return FALSE;
|
}
|
|
int nCount = (int)m_VectorLinkList.size();
|
|
cfg.SetItemValue(_T("UPPER_NUMBER"), nCount);
|
|
if(nCount <= 0 || nCount >= 1000)
|
return FALSE;
|
|
int i = 0;
|
CString strValue = _T("");
|
|
LinkList* pList;
|
for(VectorLinkListIt it = m_VectorLinkList.begin(); it != m_VectorLinkList.end(); it++)
|
{
|
pList = *it;
|
if(pList == NULL)
|
continue;
|
|
cfg.SetItemValue(i, _T("UPPER_NAME"), (TCHAR*)(LPCTSTR)pList->m_strUpperName);
|
cfg.SetItemValue(i, _T("STEP_NAME"), (TCHAR*)(LPCTSTR)pList->m_strStepName);
|
cfg.SetItemValue(i, _T("INS_NAME"), (TCHAR*)(LPCTSTR)pList->m_strInsName);
|
|
i++;
|
}
|
cfg.WriteToFile();
|
|
return TRUE;
|
}
|
|
LRESULT CViewRecipeSetting::OnSelectRecipe(WPARAM wParam, LPARAM lParam)
|
{
|
if(m_pViewRecipeList != NULL)
|
{
|
m_strPPIDName = m_pViewRecipeList->GetPPIDName();
|
m_strRecipeName = m_pViewRecipeList->GetRecipeName();
|
ChangeRecipe();
|
WriteLinkFile(LINK_FILE_NAME);
|
}
|
|
return 0;
|
}
|
|
POINT CViewRecipeSetting::IE2P_GetFrameViewBasepoint()
|
{
|
return m_frameImg.m_ptOrg;
|
}
|
|
void CViewRecipeSetting::IE2P_SetExpAreaTrackerReset()
|
{
|
m_frameImg.SetAcitveTracker(NULL);
|
}
|
|
void CViewRecipeSetting::IE2P_SetExpArea(int iSide)
|
{
|
if(m_pViewExpArea == NULL || m_pGlassData == NULL)
|
return;
|
|
CPoint ptOrg;
|
|
EXECPTION_AREA *pExpArea = m_pViewExpArea->GetExpArea();
|
INS_EDGE_RESULT_INFO *pResInfo = m_pGlassData->GetEdgeResultInfo((DimensionDir)iSide);
|
if(pResInfo == NULL)
|
return;
|
|
m_frameImg.SetAcitveTracker(pExpArea);
|
ptOrg.x = CHKMAX(0,(int)(pExpArea->rc.left + pResInfo->ptMark[0].x));
|
ptOrg.y = CHKMAX(0,(int)(pExpArea->rc.top + pResInfo->ptMark[0].y - m_frameImg.m_WndRect.Height()/2));
|
|
m_frameImg.m_ptOrg.y = ptOrg.y;
|
|
LPBYTE plpBuf = NULL;
|
if(m_IV2M != NULL)
|
plpBuf = m_IV2M->IV2M_GetGrabBufferByDimension((DimensionDir)iSide,ptOrg.y);
|
m_frameImg.SetImage(plpBuf);
|
|
SCROLLINFO si;
|
si.fMask=SIF_ALL;
|
m_ctrlScrollV.GetScrollInfo(&si,SIF_ALL);
|
si.nPos = CHKMAX(pResInfo->nGlassStartLine - m_frameImg.m_WndRect.Height()/2 +1,ptOrg.y - pResInfo->nGlassStartLine - m_frameImg.m_WndRect.Height()/2 +1);
|
m_ctrlScrollV.SetScrollInfo(&si);
|
m_frameImg.ViewUpdate();
|
}
|
|
void CViewRecipeSetting::IU2P_DrawRefresh()
|
{
|
m_frameImg.Invalidate(FALSE);
|
}
|
|
void CViewRecipeSetting::IU2P_DrawRect(BOOL bSet)
|
{
|
if(m_pGlassData == NULL)
|
return;
|
|
INS_EDGE_RESULT_INFO *pResInfo = m_pGlassData->GetEdgeResultInfo((DimensionDir)m_nCndRDSide);
|
if(pResInfo == NULL)
|
return;
|
|
if(bSet == TRUE)
|
{
|
//if(pResInfo->ptMark[0].x > 0 && pResInfo->ptMark[0].y > 0)
|
{
|
m_frameImg.SetMode(MODE_USER_DEFECT_AREA);
|
m_frameImg.Invalidate(FALSE);
|
}
|
}
|
else
|
{
|
m_frameImg.ResetMode(MODE_USER_DEFECT_AREA);
|
m_frameImg.Invalidate(FALSE);
|
}
|
}
|
|
CRect CViewRecipeSetting::IU2P_GetCompareRect()
|
{
|
CRect rect = CRect(0,0,0,0);
|
|
if(m_pGlassData == NULL)
|
return rect;
|
|
INS_EDGE_RESULT_INFO *pResInfo = m_pGlassData->GetEdgeResultInfo((DimensionDir)m_nCndRDSide);
|
if(pResInfo == NULL)
|
return rect;
|
|
//if(pResInfo->ptMark[0].x > 0 && pResInfo->ptMark[0].y > 0)
|
{
|
rect = m_frameImg.GetCompareRect();
|
}
|
|
return rect;
|
}
|
|
void CViewRecipeSetting::ChangeRecipe()
|
{
|
m_pDlgRecipe->Reset();
|
|
ReadRecipe(m_strRecipeName);
|
|
m_strRecipeName = m_pDlgRecipe->GetRecipeName();
|
m_ctrlRecipeName.SetCaption(m_strRecipeName);
|
m_ctrlRecipeComment.SetCaption(m_pDlgRecipe->m_GlassParm.m_strDisp);
|
|
if(m_pViewRecipeInspection != NULL)
|
{
|
m_pViewRecipeInspection->SetRecipe(m_pHardware,m_pDlgRecipe);
|
m_pViewRecipeInspection->DrawMarkImage();
|
m_pViewRecipeInspection->Refresh();
|
}
|
|
std::string strVisionName = BlVision_GetVisionRecipe()->getVisionName();
|
CW2A pszConvertedAnsiString(m_strRecipeName);
|
if (strVisionName.compare(pszConvertedAnsiString) != 0)
|
{
|
auto startTime = std::chrono::high_resolution_clock::now();
|
BlVision_GetVisionRecipe()->setVisionName(pszConvertedAnsiString);
|
BlVision_GetVisionRecipe()->open();
|
auto endTime = std::chrono::high_resolution_clock::now();
|
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);
|
g_pLog->DisplayMessage(_T("Read VisionRecipe %s %lld milliseconds"), m_strRecipeName, duration.count());
|
}
|
|
int nGlassSizeX = m_pDlgRecipe->m_GlassParm.m_nGlassSizeX;
|
int nGlassSizeY = m_pDlgRecipe->m_GlassParm.m_nGlassSizeY;
|
BlVision_GetVisionRecipe()->setGlassSize(nGlassSizeX, nGlassSizeY);
|
|
UpdateData(FALSE);
|
}
|
|
BOOL CViewRecipeSetting::ReadRecipe(CString strRecipe)
|
{
|
if(strRecipe.IsEmpty() == TRUE)
|
{
|
//AfxMessageBox("Recipe Name捞 绝嚼聪促.");
|
return FALSE;
|
}
|
|
m_pDlgRecipe->Reset();
|
|
if(m_pDlgRecipe->MakeRecipeFileName(strRecipe) == FALSE)
|
return FALSE;
|
|
return m_pDlgRecipe->ReadRecipeFile();
|
}
|
|
void CViewRecipeSetting::IInspectRecipe2RecipeView_ChangeSide(int iSide)
|
{
|
m_nCndRDSide = iSide;
|
|
InitScrollInfo();
|
|
m_frameImg.SetSide(m_nCndRDSide);
|
|
if(m_IV2M != NULL)
|
{
|
LPBYTE plpBuf = NULL;
|
if(m_IV2M != NULL)
|
plpBuf = m_IV2M->IV2M_GetGrabBufferByDimension((DimensionDir)m_nCndRDSide,m_frameImg.m_ptOrg.y);
|
m_frameImg.SetImage(plpBuf);
|
}
|
|
m_frameImg.SetRecipe(m_pHardware,m_pDlgRecipe);
|
m_frameImg.SetGlassData(m_pGlassData);
|
m_frameImg.ViewUpdate();
|
|
if (NULL != m_pVisionSetDlg) {
|
ISoftVisionApp *pApp = BlVision_GetSoftVisionApp();
|
int nDir = (DimensionDir)(iSide);
|
pApp->ChangeDimension(m_pVisionSetDlg, nDir);
|
}
|
}
|
|
BOOL CViewRecipeSetting::IInspectRecipe2RecipeView_SetMarker(int nPos,int nMarkPos)
|
{
|
if(!m_frameImg.GetMode(MODE_MARK_REG))
|
return FALSE;
|
if(m_IV2M == NULL || m_pDlgRecipe == NULL)
|
return FALSE;
|
|
CALIGNMARK_PARM *pAlignPrm = m_pDlgRecipe->GetAlignMarkPrm((DimensionDir)m_nCndRDSide);
|
if(pAlignPrm == NULL)
|
return FALSE;
|
|
CRect rc(m_frameImg.GetMartRect());
|
CvRect roi;
|
|
LPBYTE lpImg = m_IV2M->IV2M_GetGrabBufferByDimension((DimensionDir)m_nCndRDSide,rc.top);
|
IplImage *IpScr = cvCreateImageHeader(cvSize(IMAGE_WIDTH,IMAGE_HEIGHT),8,1);
|
cvSetData(IpScr,lpImg ,IMAGE_WIDTH);
|
|
roi.x = rc.left;
|
roi.y = 0;
|
roi.width = rc.Width();
|
roi.height = rc.Height();
|
|
|
if(pAlignPrm->m_nMarkType[0] == 0 || pAlignPrm->m_nMarkType[0] == 1)
|
{
|
CvRect rcMark = Get_MaxPattern(IpScr,roi,pAlignPrm->m_nMarkType[0]);
|
|
if(rcMark.width > 10 && rcMark.height > 10)
|
{
|
roi.x = max(0,rcMark.x - 10);
|
roi.y = max(0,rcMark.y - 10);
|
roi.width = min(IMAGE_WIDTH - roi.x,rcMark.width +20);
|
roi.height = min(IMAGE_HEIGHT - roi.y,rcMark.height +20);
|
|
CvPoint2D32f ptCenter = Get_MarkCenter(IpScr,roi,pAlignPrm->m_nMarkType[0]);
|
|
roi.x = int(ptCenter.x - rcMark.width/2.0 + 0.5);
|
roi.y = int(ptCenter.y - rcMark.height/2.0 + 0.5);
|
|
roi.width = rcMark.width;
|
roi.height = rcMark.height;
|
}
|
}
|
|
|
if(roi.x >= 0 && roi.y >= 0)
|
{
|
if(pAlignPrm->IpMarkImg[nPos][nMarkPos])
|
cvReleaseImage(&pAlignPrm->IpMarkImg[nPos][nMarkPos]);
|
|
//cvSetImageROI(IpScr,roi);
|
|
pAlignPrm->IpMarkImg[nPos][nMarkPos] = cvCreateImage(cvSize(roi.width,roi.height),8,1);
|
|
BYTE *pOrg,*pTgt;
|
int iPos = 0;
|
for(int i=roi.y;i<roi.y+roi.height;i++,iPos++)
|
{
|
pOrg = (BYTE *)(IpScr->imageData+i*IpScr->widthStep+roi.x);
|
pTgt = (BYTE *)(pAlignPrm->IpMarkImg[nPos][nMarkPos]->imageData+iPos*pAlignPrm->IpMarkImg[nPos][nMarkPos]->widthStep);
|
CopyMemory(pTgt, pOrg, roi.width);
|
}
|
}
|
|
cvReleaseImageHeader(&IpScr);
|
|
return TRUE;
|
}
|
|
void CViewRecipeSetting::IInspectRecipe2RecipeView_SetMarkerPos(int nOff_X,int nOff_Y)
|
{
|
CRect rc;
|
rc = m_frameImg.GetMartRect();
|
rc.OffsetRect(nOff_X,nOff_Y);
|
m_frameImg.SetMarkRect(rc);
|
m_frameImg.ViewUpdate();
|
}
|
|
void CViewRecipeSetting::IInspectRecipe2RecipeView_ModifyMarker(BOOL bModify)
|
{
|
if(bModify == TRUE)
|
{
|
m_frameImg.SetMode(MODE_MARK_REG);
|
}
|
else
|
{
|
m_frameImg.ResetMode(MODE_MARK_REG);
|
}
|
m_frameImg.Invalidate(FALSE);
|
}
|
|
CvRect CViewRecipeSetting::Get_MaxPattern(IplImage *IpScr,CvRect roi,int nMode,int nOffSet)
|
{
|
cvSetImageROI(IpScr,roi);
|
|
IplImage *Bin = cvCreateImage(cvSize(roi.width,roi.height),8,1);
|
|
double dMean = cvAvg(IpScr).val[0];
|
|
if(nMode == 0)
|
cvThreshold(IpScr,Bin,dMean + nOffSet,255,CV_THRESH_BINARY);
|
else
|
cvThreshold(IpScr,Bin,dMean - nOffSet,255,CV_THRESH_BINARY_INV);
|
|
CvMemStorage* storage = cvCreateMemStorage(0);
|
CvSeq *contours = 0;
|
cvFindContours(Bin,storage,&contours,sizeof(CvContour),CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
|
|
|
CvRect rect;
|
CvRect rect_max = cvRect(0,0,0,0);
|
|
for(;contours!=0;contours=contours->h_next)
|
{
|
rect = cvBoundingRect(contours);
|
|
if(rect.width * rect.height > rect_max.width * rect_max.height)
|
{
|
rect_max = rect;
|
}
|
}
|
cvResetImageROI(IpScr);
|
cvSetImageROI(IpScr,rect_max);
|
|
rect_max.x += roi.x;
|
rect_max.y += roi.y;
|
cvResetImageROI(IpScr);
|
cvReleaseMemStorage(&storage);
|
cvReleaseImage(&Bin);
|
return rect_max;
|
}
|
|
CvPoint2D32f CViewRecipeSetting::Get_MarkCenter(IplImage *IpScr,CvRect roi,int nMode,int nOffSet)
|
{
|
cvSetImageROI(IpScr,roi);
|
IplImage *Bin = cvCreateImage(cvSize(roi.width,roi.height),8,1);
|
|
double dMean = cvAvg(IpScr).val[0];
|
|
switch(nMode)
|
{
|
case 0:
|
cvThreshold(IpScr,Bin,dMean + nOffSet,255,CV_THRESH_BINARY);
|
break;
|
|
case 1:
|
cvThreshold(IpScr,Bin,dMean - nOffSet,255,CV_THRESH_BINARY_INV);
|
break;
|
|
case 2:
|
cvCanny(IpScr,Bin,100,50,3);
|
break;
|
}
|
|
cvResetImageROI(IpScr);
|
|
//cvSaveImage(Data,Bin)
|
int i,j,nPos1,nPos2,nCnt1,nCnt2;
|
|
float *ptCenter_X = new float[roi.height];
|
|
float *ptCenter_Y = new float[roi.width];
|
|
BYTE *pData;
|
|
nCnt1 = nCnt2 = 0;
|
for(i = 0; i < roi.height; i++)
|
{
|
nPos1 = nPos2 = 0;
|
|
pData = (BYTE *)(&Bin->imageData[i * Bin->widthStep]);
|
for(j = 1; j < roi.width ; j++)
|
{
|
if(pData[j])
|
{
|
nPos1 = j;
|
break;
|
}
|
}
|
|
for(j = roi.width -1 ; j > 1 ; j--)
|
{
|
if(pData[j])
|
{
|
nPos2 = j;
|
break;
|
}
|
}
|
|
if(nPos1 && nPos2)
|
ptCenter_X[nCnt1++] = (float)((nPos1 + nPos2)/2.0);
|
}
|
|
|
for(j = 1 ; j< roi.width; j++)
|
{
|
nPos1 = nPos2 = 0;
|
for(i = 1; i < roi.height ; i++)
|
{
|
pData = (BYTE *)(&Bin->imageData[i * Bin->widthStep + j]);
|
|
if(*pData)
|
{
|
nPos1 = i;
|
break;
|
}
|
}
|
|
for(i = roi.height -1; i > 1 ; i--)
|
{
|
pData = (BYTE *)(&Bin->imageData[i * Bin->widthStep + j]);
|
|
if(*pData)
|
{
|
nPos2 = i;
|
break;
|
}
|
}
|
|
if(nPos1 && nPos2)
|
ptCenter_Y[nCnt2++] = (float)((nPos1 + nPos2)/2.0);
|
}
|
|
if(nCnt1)
|
sort(ptCenter_X,&ptCenter_X[nCnt1]);
|
if(nCnt2)
|
sort(ptCenter_Y,&ptCenter_Y[nCnt2]);
|
|
|
CvPoint2D32f ptCenter;
|
|
ptCenter.x = ptCenter.y = 0;
|
|
if(nCnt1 > 10 && nCnt2 > 10)
|
{
|
|
for(i = nCnt1/2 - 5; i < nCnt1/2 + 5; i++)
|
ptCenter.x += ptCenter_X[i];
|
|
for(i = nCnt2/2 - 5; i < nCnt2/2 + 5; i++)
|
ptCenter.y += ptCenter_Y[i];
|
|
ptCenter.x = (float)(ptCenter.x / 10.0 + roi.x);
|
ptCenter.y = (float)(ptCenter.y / 10.0 + roi.y);
|
}
|
else
|
{
|
|
ptCenter.x = (float)(ptCenter_X[nCnt1/2]/2.0 + roi.x);
|
ptCenter.y = (float)(ptCenter_Y[nCnt2/2]/2.0 + roi.y);
|
}
|
|
delete [] ptCenter_X;
|
delete [] ptCenter_Y;
|
|
|
cvReleaseImage(&Bin);
|
|
return ptCenter;
|
}
|
|
void CViewRecipeSetting::OnBnClickedBtnUserDefect()
|
{
|
if(m_pViewUserDefect != NULL)
|
{
|
m_pViewUserDefect->SetIndex(m_nCndRDSide);
|
m_pViewUserDefect->SetRecipe(m_pHardware,m_pDlgRecipe);
|
m_pViewUserDefect->SetGlassData(m_pGlassData);
|
m_pViewUserDefect->ShowWindow(SW_SHOW);
|
}
|
}
|
|
void CViewRecipeSetting::IE2P_SetExpAreaDlgClose()
|
{
|
m_bShowExpArea = FALSE;
|
m_frameImg.SetTrackerModify(FALSE);
|
m_frameImg.ResetMode(MODE_MARK_REG);
|
m_frameImg.Invalidate(FALSE);
|
}
|
|
void CViewRecipeSetting::OnBnClickedBtnExpRegion()
|
{
|
if(m_pViewExpArea != NULL)
|
{
|
m_frameImg.SetTrackerModify(TRUE);
|
m_frameImg.SetMode(MODE_MARK_REG);
|
m_frameImg.SetEventWnd(GetSafeHwnd());
|
|
m_pViewExpArea->SetRecipe(m_pHardware,m_pDlgRecipe);
|
m_pViewExpArea->SetGlassData(m_pGlassData);
|
m_pViewExpArea->SetIndex(m_nCndRDSide);
|
m_pViewExpArea->ShowWindow(SW_SHOW);
|
m_bShowExpArea = TRUE;
|
}
|
}
|
|
LRESULT CViewRecipeSetting::OnAreaModify(WPARAM wParam, LPARAM lParam)
|
{
|
if(m_bShowExpArea == FALSE)
|
return 1;
|
|
if(m_pViewExpArea != NULL)
|
{
|
m_pViewExpArea->SetAreaModify(m_frameImg.m_pTracker);
|
}
|
|
return 1;
|
}
|
|
LRESULT CViewRecipeSetting::OnAreaChange(WPARAM wParam, LPARAM lParam)
|
{
|
if(m_bShowExpArea == FALSE)
|
return 1;
|
|
if(m_pViewExpArea != NULL)
|
{
|
m_pViewExpArea->SetAreaChange(m_frameImg.m_pTracker);
|
}
|
return 1;
|
}
|
|
BOOL CViewRecipeSetting::IHoleRecipe2RecipeView_AddHoleArea(int& nSideIdx, CRect& rtArea)
|
{
|
if(m_pGlassData == NULL)
|
return FALSE;
|
|
INS_EDGE_RESULT_INFO *pResInfo = m_pGlassData->GetEdgeResultInfo((DimensionDir)m_nCndRDSide);
|
if(pResInfo == NULL)
|
return FALSE;
|
|
if(pResInfo->ptMark[0].x < 1 || pResInfo->ptMark[0].y < 1)
|
{
|
AfxMessageBox(_T("Not Measure Image... This Function use after Measure"));
|
return FALSE;
|
}
|
|
nSideIdx = m_nCndRDSide;
|
rtArea.left = (int)(m_frameImg.m_ptOrg.x - pResInfo->ptMark[0].x + 50);
|
rtArea.top = (int)(m_frameImg.m_ptOrg.y - pResInfo->ptMark[0].y + 50);
|
rtArea.right = rtArea.left + 150;
|
rtArea.bottom = rtArea.top + 150;
|
|
return TRUE;
|
}
|
|
BOOL CViewRecipeSetting::IHoleRecipe2RecipeView_GetHoleAreaImage(int nHoleIdx, IplImage** pImageBuffer)
|
{
|
if(m_IV2M == NULL || pImageBuffer == NULL || m_pDlgRecipe == NULL)
|
return FALSE;
|
|
if(m_pDlgRecipe->m_HoleInspectParm.m_vecHoleInsParam[nHoleIdx].m_nSideIdx != m_nCndRDSide)
|
return FALSE;
|
|
INS_EDGE_RESULT_INFO *pResInfo = m_pGlassData->GetEdgeResultInfo((DimensionDir)m_nCndRDSide);
|
if(pResInfo == NULL)
|
return FALSE;
|
|
if(pResInfo->ptMark[0].x < 1 || pResInfo->ptMark[0].y < 1)
|
{
|
AfxMessageBox(_T("Not Measure Image... This Function use after Measure"));
|
return FALSE;
|
}
|
|
if(*(pImageBuffer) != NULL)
|
cvReleaseImage(pImageBuffer);
|
|
(*pImageBuffer) = cvCreateImage(cvSize(m_pDlgRecipe->m_HoleInspectParm.m_vecHoleInsParam[nHoleIdx].m_rtArea.Width(), m_pDlgRecipe->m_HoleInspectParm.m_vecHoleInsParam[nHoleIdx].m_rtArea.Height()), 8, 1);
|
cvZero((*pImageBuffer));
|
|
int nStartX = (int)(pResInfo->ptMark[0].x + m_pDlgRecipe->m_HoleInspectParm.m_vecHoleInsParam[nHoleIdx].m_rtArea.left);
|
int nStartY = (int)(pResInfo->ptMark[0].y + m_pDlgRecipe->m_HoleInspectParm.m_vecHoleInsParam[nHoleIdx].m_rtArea.top);
|
|
BYTE* pGrabBuffer = NULL;
|
|
for(int i=0; i< (*pImageBuffer)->height; i++)
|
{
|
pGrabBuffer = m_IV2M->IV2M_GetGrabBufferByDimension((GLOBAL_DEFINE::DimensionDir) m_pDlgRecipe->m_HoleInspectParm.m_vecHoleInsParam[nHoleIdx].m_nSideIdx, nStartY + i);
|
|
if(pGrabBuffer == NULL)
|
continue;
|
|
memcpy(&(*pImageBuffer)->imageData[(*pImageBuffer)->widthStep*i], pGrabBuffer+nStartX, sizeof(BYTE)*(*pImageBuffer)->width);
|
}
|
|
return TRUE;
|
}
|
|
void CViewRecipeSetting::IHoleRecipe2RecipeView_UpdateFrameView()
|
{
|
m_frameImg.SetRecipe(m_pHardware, m_pDlgRecipe);
|
m_frameImg.ViewUpdate();
|
}
|
|
void CViewRecipeSetting::IHoleRecipe2RecipeView_SaveRecipe()
|
{
|
ClickRecipeSaveButton();
|
}
|
|
void CViewRecipeSetting::OnBnClickedBtnLightControl()
|
{
|
if(m_pviewLightControl != NULL)
|
{
|
m_pviewLightControl->SetData(m_pDlgRecipe,m_pHardware);
|
m_pviewLightControl->SetParent(this);
|
m_pviewLightControl->ShowWindow(SW_SHOW);
|
}
|
}
|
|
BOOL CViewRecipeSetting::IHoleRecipe2RecipeVIew_HoleInspectProcess(int nHoleIdx, IplImage** pImageBuffer)
|
{
|
if(m_pDlgRecipe == NULL || pImageBuffer == NULL)
|
return FALSE;
|
|
INS_EDGE_RESULT_INFO *pResInfo = m_pGlassData->GetEdgeResultInfo((DimensionDir)m_nCndRDSide);
|
if(pResInfo == NULL)
|
return FALSE;
|
|
|
if(pResInfo->ptMark[0].x < 1 || pResInfo->ptMark[0].y < 1)
|
{
|
AfxMessageBox(_T("Not Measure Image... This Function use after Measure"));
|
return FALSE;
|
}
|
|
if(nHoleIdx < 0 || m_pDlgRecipe->m_HoleInspectParm.m_vecHoleInsParam.size() <= nHoleIdx)
|
return FALSE;
|
|
if(m_pDlgRecipe->m_HoleInspectParm.m_vecHoleInsParam[nHoleIdx].m_nSideIdx != m_nCndRDSide)
|
return FALSE;
|
|
IplImage* pTargetImage = cvCreateImage(cvSize(m_pDlgRecipe->m_HoleInspectParm.m_vecHoleInsParam[nHoleIdx].m_rtArea.Width(), m_pDlgRecipe->m_HoleInspectParm.m_vecHoleInsParam[nHoleIdx].m_rtArea.Height()), 8, 1);
|
cvZero(pTargetImage);
|
|
int nStartX = (int)(pResInfo->ptMark[0].x + m_pDlgRecipe->m_HoleInspectParm.m_vecHoleInsParam[nHoleIdx].m_rtArea.left);
|
int nStartY = (int)(pResInfo->ptMark[0].y + m_pDlgRecipe->m_HoleInspectParm.m_vecHoleInsParam[nHoleIdx].m_rtArea.top);
|
|
BYTE* pGrabBuffer = NULL;
|
|
for(int i=0; i< m_pDlgRecipe->m_HoleInspectParm.m_vecHoleInsParam[nHoleIdx].m_rtArea.Height(); i++)
|
{
|
pGrabBuffer = m_IV2M->IV2M_GetGrabBufferByDimension((GLOBAL_DEFINE::DimensionDir) m_pDlgRecipe->m_HoleInspectParm.m_vecHoleInsParam[nHoleIdx].m_nSideIdx, nStartY + i);
|
|
if(pGrabBuffer == NULL)
|
continue;
|
|
memcpy(&pTargetImage->imageData[pTargetImage->widthStep*i], pGrabBuffer+nStartX, sizeof(BYTE)*pTargetImage->width);
|
}
|
|
CHoleInspector holeInspector;
|
std::vector<CRect> vecDefectList;
|
|
CPoint ptMatchingPos;
|
|
holeInspector.HoleInspect_TemplateMatching(&m_pDlgRecipe->m_HoleInspectParm.m_vecHoleInsParam[nHoleIdx], pTargetImage, vecDefectList, ptMatchingPos, pImageBuffer);
|
|
cvReleaseImage(&pTargetImage);
|
|
return TRUE;
|
}
|
|
int CViewRecipeSetting::IHoleRecipe2RecipeView_GetCurrentSetSide()
|
{
|
return m_nCndRDSide;
|
}
|
|
void CViewRecipeSetting::OnClickButtonLang()
|
{
|
UINT nID = GetFocus()->GetDlgCtrlID();
|
|
int nRet = -1;
|
switch (g_pLang->m_eSelectLangType)
|
{
|
case emLanguageType::emLanguageType_EN:
|
nRet = MessageBox(_T("After changing the language, restart the software."), _T("Hint"), MB_OKCANCEL | MB_ICONINFORMATION);
|
break;
|
case emLanguageType::emLanguageType_KR:
|
nRet = MessageBox(_T("언어를 변경한 후 소프트웨어를 다시 시작하십시오."), _T("제시"), MB_OKCANCEL | MB_ICONINFORMATION);
|
break;
|
case emLanguageType::emLanguageType_CH:
|
nRet = MessageBox(_T("切换语言后,请重启软件。"), _T("提示"), MB_OKCANCEL | MB_ICONINFORMATION);
|
break;
|
default:
|
return;
|
}
|
|
if (IDOK == nRet)
|
{
|
emLanguageType eSelLang;
|
switch (nID)
|
{
|
case IDC_BUTTON_LANG_ENGLISH:
|
eSelLang = emLanguageType::emLanguageType_EN;
|
break;
|
case IDC_BUTTON_LANG_KOREAN:
|
eSelLang = emLanguageType::emLanguageType_KR;
|
break;
|
case IDC_BUTTON_LANG_CHINESE:
|
eSelLang = emLanguageType::emLanguageType_CH;
|
break;
|
default:
|
return;
|
}
|
|
CString strPath;
|
strPath.Format(_T("%s\\LanguageType.ini"), LANGUAGE_DIR_PATH);
|
CT2CA pszConvertedAnsiString(strPath, CP_UTF8);
|
g_pLang->SaveLanguageSetting(std::string(pszConvertedAnsiString), eSelLang);
|
}
|
}
|
|
void CViewRecipeSetting::ClickButtonVisionSet()
|
{
|
// TODO: 在此处添加消息处理程序代码
|
IVisionRecipe *pInstance = BlVision_GetVisionRecipe();
|
CW2A pszHPanelID(g_pBase->m_strHPanelID);
|
pInstance->setProductNo(pszHPanelID);
|
if (NULL == pInstance) return;
|
if (!pInstance->getVisionUse()) {
|
BlVision_GetSoftVisionApp()->OpenKeySetWindow();
|
return;
|
}
|
|
ISoftVisionApp *pApp = BlVision_GetSoftVisionApp();
|
if (NULL == m_pVisionSetDlg) {
|
m_pVisionSetDlg = pApp->CreateVisionWindow();
|
}
|
|
|
m_pVisionSetDlg->ShowWindow(SW_SHOW);
|
int nDir = (DimensionDir)(m_nCndRDSide);
|
pApp->SetVisionOpen(TRUE);
|
pApp->ChangeDimension(m_pVisionSetDlg, nDir);
|
|
// BlVision_GetSoftVisionApp()->OpenVisionWindow();
|
}
|