| | |
| | | return TRUE; |
| | | } |
| | | |
| | | void CPostProcess::SaveDefectData() |
| | | void CPostProcess::SaveMeasureData(CString strGlassID, CString strTime) |
| | | { |
| | | CString glass_id; |
| | | glass_id.Format(_T("%s"), g_pBase->m_strHPanelID); |
| | | if (!m_pGlassData) { |
| | | return; |
| | | } |
| | | |
| | | if (glass_id.IsEmpty() == TRUE) |
| | | glass_id.Format(_T("MANUAL_ID")); |
| | | double dTFTYOff = 0.0; |
| | | double dTFTXOff = 0.0; |
| | | |
| | | // 获取当前产品加载时间 |
| | | CTime tGlassLoading = m_pGlassData->GetLoadingTime(); |
| | | auto* pSideA = m_pGlassData->GetSideData(DIMENSION_A); |
| | | auto* pSideB = m_pGlassData->GetSideData(DIMENSION_B); |
| | | if (!pSideA || !pSideB) { |
| | | return; |
| | | } |
| | | |
| | | CString measure_data; |
| | | CString chip_data; |
| | | CString defect_data; |
| | | CString strTime = g_pBase->m_strLoadingTime; |
| | | double nPanelSizeCF_X = ((pSideB->m_nGlassEndLine - pSideB->m_nGlassStartLine) * pSideB->m_dPixelSizeY / 1000.0); |
| | | double nPanelSizeCF_Y = ((pSideA->m_nGlassEndLine - pSideA->m_nGlassStartLine) * pSideA->m_dPixelSizeY / 1000.0); |
| | | double nPanelSizeTFT_X = (((pSideB->m_nGlassEndLine - pSideB->m_nGlassStartLine) * pSideB->m_dPixelSizeY - dTFTXOff) / 1000.0); |
| | | double nPanelSizeTFT_Y = (((pSideA->m_nGlassEndLine - pSideA->m_nGlassStartLine) * pSideA->m_dPixelSizeY - dTFTYOff) / 1000.0); |
| | | |
| | | double dTFTYOff = 0; |
| | | //double dSumTFTYOff = 0; |
| | | //int nCountTFTYOff = 0; |
| | | //for (int nFrameIdx = 0; nFrameIdx < MAX_IMAGE_FRAME; nFrameIdx++) |
| | | //{ |
| | | // if (m_pGlassData->GetSideData(DIMENSION_B)->m_nSide_Electrode_Result_um[nFrameIdx] == -1) continue; |
| | | // dSumTFTYOff += m_pGlassData->GetSideData(DIMENSION_B)->m_nSide_Electrode_Result_um[nFrameIdx]; |
| | | // nCountTFTYOff++; |
| | | //} |
| | | //if (nCountTFTYOff > 0) |
| | | // dTFTYOff = dSumTFTYOff / nCountTFTYOff; |
| | | int unitNo = m_pTransData ? m_pTransData->m_nUnitNo : 0; |
| | | int eqpNo = m_pTransData ? m_pTransData->m_nEqpNo : 0; |
| | | int isGrind = m_pTransData ? m_pTransData->m_nisGrind : 0; |
| | | int roughPad = m_pTransData ? m_pTransData->m_nRoughPadLayer : 0; |
| | | |
| | | double dTFTXOff = 0; |
| | | //double dSumTFTXOff = 0; |
| | | //int nCountTFTXOff = 0; |
| | | //for (int nFrameIdx = 0; nFrameIdx < MAX_IMAGE_FRAME; nFrameIdx++) |
| | | //{ |
| | | // if (m_pGlassData->GetSideData(DIMENSION_A)->m_nSide_Electrode_Result_um[nFrameIdx] == -1) continue; |
| | | // dSumTFTXOff += m_pGlassData->GetSideData(DIMENSION_A)->m_nSide_Electrode_Result_um[nFrameIdx]; |
| | | // nCountTFTXOff++; |
| | | //} |
| | | //if (nCountTFTXOff > 0) |
| | | // dTFTXOff = dSumTFTXOff / nCountTFTXOff; |
| | | |
| | | double nPanelSizeCF_X = ((m_pGlassData->GetSideData(DIMENSION_B)->m_nGlassEndLine - m_pGlassData->GetSideData(DIMENSION_B)->m_nGlassStartLine) * m_pGlassData->GetSideData(DIMENSION_B)->m_dPixelSizeY / 1000.0); |
| | | double nPanelSizeCF_Y = ((m_pGlassData->GetSideData(DIMENSION_A)->m_nGlassEndLine - m_pGlassData->GetSideData(DIMENSION_A)->m_nGlassStartLine) * m_pGlassData->GetSideData(DIMENSION_A)->m_dPixelSizeY / 1000.0); |
| | | double nPanelSizeTFT_X = (((m_pGlassData->GetSideData(DIMENSION_B)->m_nGlassEndLine - m_pGlassData->GetSideData(DIMENSION_B)->m_nGlassStartLine) * m_pGlassData->GetSideData(DIMENSION_B)->m_dPixelSizeY - dTFTXOff) / 1000.0); |
| | | double nPanelSizeTFT_Y = (((m_pGlassData->GetSideData(DIMENSION_A)->m_nGlassEndLine - m_pGlassData->GetSideData(DIMENSION_A)->m_nGlassStartLine) * m_pGlassData->GetSideData(DIMENSION_A)->m_dPixelSizeY - dTFTYOff) / 1000.0); |
| | | |
| | | measure_data.AppendFormat(_T("%s,%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%f,%f,%f,%f,%d,%d,%d,%d,%d,%d,%d,%d"), |
| | | CString strBody; |
| | | strBody.AppendFormat(_T("%s,%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,") |
| | | _T("%f,%f,%f,%f,") |
| | | _T("%d,%d,%d,%d,%d,%d,%d,%d\r\n"), |
| | | strTime, |
| | | glass_id, |
| | | m_pTransData->m_nUnitNo, |
| | | m_pTransData->m_nEqpNo, |
| | | m_pTransData->m_nisGrind, |
| | | m_pTransData->m_nRoughPadLayer, |
| | | strGlassID, |
| | | unitNo, |
| | | eqpNo, |
| | | isGrind, |
| | | roughPad, |
| | | MeasrueCutLineResult(DIMENSION_A), |
| | | MeasrueCutLineResult(DIMENSION_B), |
| | | MeasrueCutLineResult(DIMENSION_C), |
| | |
| | | m_pGlassData->GetSideData(DIMENSION_C)->m_nBottomCornerWidth, |
| | | m_pGlassData->GetSideData(DIMENSION_C)->m_nBottomCornerHeight |
| | | ); |
| | | measure_data.Append(_T("\r\n")); |
| | | |
| | | CString measure_file_path; |
| | | if (m_pHardware->m_bSaveResultByHour) { |
| | | // 按小时保存结果 |
| | | measure_file_path.Format(_T("%s\\%s_%02d_MeasureData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, tGlassLoading.GetHour()); |
| | | } |
| | | else { |
| | | // 不按小时保存结果 |
| | | measure_file_path.Format(_T("%s\\%s_MeasureData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay); |
| | | const CString strPath = MakeResultCsvPath(_T("MeasureData")); |
| | | const CString strHeader = |
| | | _T("Time,Glass ID,Unit_No,Table_No,Slot_No,Panel_count,") |
| | | _T("AT_SizeAVG,BT_SizeAVG,CT_SizeAVG,DT_SizeAVG,") |
| | | _T("AB_SizeAVG,BB_SizeAVG,CB_SizeAVG,DB_SizeAVG,") |
| | | _T("CF_SizeX,CF_SizeY,TFT_SizeX,TFT_SizeY,") |
| | | _T("AT_CorX,AT_CorY,AB_CorX,AB_CorY,CT_CorX,CT_CorY,CB_CorX,CB_CorY\r\n"); |
| | | |
| | | AppendCsvWithHeader(strPath, strHeader, strBody); |
| | | } |
| | | |
| | | void CPostProcess::SaveChipData(CString strGlassID, CString strTime) |
| | | { |
| | | if (!m_pGlassData || !m_pRecipe) { |
| | | return; |
| | | } |
| | | |
| | | CheckDirectory(measure_file_path); |
| | | auto IsChip = [&](CDefect* d)->bool { |
| | | if (!d) return false; |
| | | const CString& t = g_strDefectType[d->m_DefectInfo.m_DefectLoc]; |
| | | return t == _T("Chip") || t == _T("In_Chip"); |
| | | }; |
| | | |
| | | CFile measure_module; |
| | | CFileException measure_exception; |
| | | auto PassMinSize = [&](CDefect* d)->bool { |
| | | const int nSide = d->m_DefectInfo.m_nSideIdx; |
| | | const int nLoc = (int)d->m_DefectInfo.m_DefectLoc; |
| | | const int nMinX = m_pRecipe->m_SideParam[nSide].m_InspectPrm[nLoc].m_nMinSize_Filter_X_um; |
| | | const int nMinY = m_pRecipe->m_SideParam[nSide].m_InspectPrm[nLoc].m_nMinSize_Filter_Y_um; |
| | | return (int)std::round(d->m_dSizeX_um) > nMinX && (int)std::round(d->m_dSizeY_um) > nMinY; |
| | | }; |
| | | |
| | | measure_module.Open(measure_file_path, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate | CFile::shareDenyWrite | CFile::shareDenyRead, &measure_exception); |
| | | auto NowStamp = []()->CString { |
| | | std::time_t now = std::time(nullptr); |
| | | std::tm tm{}; localtime_s(&tm, &now); |
| | | CString s; |
| | | s.Format(_T("%04d%02d%02d%02d%02d%02d"), tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); |
| | | return s; |
| | | }; |
| | | |
| | | if (measure_exception.m_cause == CFileException::none) |
| | | { |
| | | if (measure_module.SeekToEnd() == 0L) |
| | | { |
| | | CString defect_title; |
| | | defect_title.Format(_T("Time,Glass ID,Unit_No,Table_No,Slot_No,Panel_count,AT_SizeAVG,BT_SizeAVG,CT_SizeAVG,DT_SizeAVG,AB_SizeAVG,BB_SizeAVG,CB_SizeAVG,DB_SizeAVG,CF_SizeX,CF_SizeY,TFT_SizeX,TFT_SizeY,AT_CorX,AT_CorY,AB_CorX,AB_CorY,CT_CorX,CT_CorY,CB_CorX,CB_CorY\r\n")); |
| | | measure_module.Write(defect_title, defect_title.GetLength() * sizeof(TCHAR)); |
| | | } |
| | | measure_module.Write(measure_data, measure_data.GetLength() * sizeof(TCHAR)); |
| | | measure_module.Close(); |
| | | } |
| | | |
| | | { |
| | | MapDefectIt it; |
| | | MapDefect* pMapDefect = m_pGlassData->GetMapDefect_OK(); |
| | | |
| | | for (it = pMapDefect->begin(); it != pMapDefect->end(); it++) |
| | | { |
| | | CDefect* pDefect = static_cast<CDefect*>(it->second); |
| | | |
| | | if (pDefect == NULL) |
| | | continue; |
| | | |
| | | if (pDefect->m_bJudge_NG == TRUE) |
| | | continue; |
| | | |
| | | CString strDefectType = g_strDefectType[pDefect->m_DefectInfo.m_DefectLoc]; |
| | | if ((strDefectType.Compare(_T("Chip")) == 0 || strDefectType.Compare(_T("In_Chip")) == 0)) |
| | | { |
| | | // 获取当前时间 |
| | | std::time_t now = std::time(nullptr); |
| | | // 使用localtime_s代替localtime |
| | | std::tm nowTm; |
| | | localtime_s(&nowTm, &now); |
| | | |
| | | CString strDate; |
| | | strDate.Format(_T("%04d%02d%02d%02d%02d%02d"), |
| | | nowTm.tm_year + 1900, nowTm.tm_mon + 1, nowTm.tm_mday, nowTm.tm_hour, nowTm.tm_min, nowTm.tm_sec); |
| | | |
| | | CString strCLCS; |
| | | m_pGlassData->DecodeDefectPose(&(pDefect->m_DefectInfo), strCLCS); |
| | | |
| | | auto GetPosXY = [&](CDefect* d, int& x, int& y) { |
| | | #if HALCON_VISION_KEY |
| | | Point2I pos2I = BlVision_GetSoftVisionApp()->getPose(pDefect->m_DefectInfo.m_nSideIdx, pDefect->m_DefectInfo.m_ptDefectPos_pxl.x, pDefect->m_DefectInfo.m_ptDefectPos_pxl.y); |
| | | Point2I p = BlVision_GetSoftVisionApp()->getPose(d->m_DefectInfo.m_nSideIdx, d->m_DefectInfo.m_ptDefectPos_pxl.x, d->m_DefectInfo.m_ptDefectPos_pxl.y); |
| | | x = std::abs(p.x); y = std::abs(p.y); |
| | | #else |
| | | CPoint pos2I = m_pGlassData->TransformToGlobal((DimensionDir)pDefect->m_DefectInfo.m_nSideIdx, pDefect->m_DefectInfo.m_ptDefectPos_pxl); |
| | | #endif // HALCON_VISION_KEY |
| | | CPoint p = m_pGlassData->TransformToGlobal((DimensionDir)d->m_DefectInfo.m_nSideIdx, d->m_DefectInfo.m_ptDefectPos_pxl); |
| | | x = std::abs(p.x); y = std::abs(p.y); |
| | | #endif |
| | | }; |
| | | |
| | | int nMinSize_X = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[(int)pDefect->m_DefectInfo.m_DefectLoc].m_nMinSize_Filter_X_um; |
| | | int nMinSize_Y = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[(int)pDefect->m_DefectInfo.m_DefectLoc].m_nMinSize_Filter_Y_um;; |
| | | auto MakeRow = [&](CDefect* d, const CString& strGlassID)->CString { |
| | | CString strClcs; m_pGlassData->DecodeDefectPose(&d->m_DefectInfo, strClcs); |
| | | int px = 0, py = 0; GetPosXY(d, px, py); |
| | | CString row; |
| | | row.AppendFormat(_T("%s,%s,%s,%s,%s,%s,%s,%.1f,%.1f,%d,%d\r\n"), |
| | | NowStamp(), |
| | | strGlassID, |
| | | g_pBase->m_strRecipeName, |
| | | g_pBase->m_strSBKLine, |
| | | PANEL_SIDE[d->m_DefectInfo.m_nSideIdx], |
| | | strClcs, |
| | | (d->m_DefectInfo.m_nSideIdx >= 0 && d->m_DefectInfo.m_nSideIdx < 4) ? _T("CF") : _T("TFT"), |
| | | d->m_dSizeY_um, // Length |
| | | d->m_dSizeX_um, // Depth |
| | | px, py); |
| | | return row; |
| | | }; |
| | | |
| | | if (static_cast<int>(round(pDefect->m_dSizeX_um)) > nMinSize_X && static_cast<int>(round(pDefect->m_dSizeY_um)) > nMinSize_Y) |
| | | { |
| | | chip_data.AppendFormat(_T("%s,%s,%s,%s,%s,%s,%s,%f,%f,%d,%d"), |
| | | strDate, |
| | | glass_id, |
| | | g_pBase->m_strRecipeName, |
| | | g_pBase->m_strSBKLine, |
| | | PANEL_SIDE[pDefect->m_DefectInfo.m_nSideIdx], |
| | | strCLCS, |
| | | pDefect->m_DefectInfo.m_nSideIdx >= 0 && pDefect->m_DefectInfo.m_nSideIdx < 4 ? _T("CF") : _T("TFT"), |
| | | pDefect->m_dSizeY_um, |
| | | pDefect->m_dSizeX_um, |
| | | std::abs(pos2I.x), |
| | | std::abs(pos2I.y)); |
| | | chip_data.Append(_T("\r\n")); |
| | | } |
| | | } |
| | | struct Src { MapDefect* map; bool bRequireNG; bool bMinFilter; }; |
| | | Src sources[] = { |
| | | { m_pGlassData->GetMapDefect_OK(), false, true }, // OK:做最小尺寸过滤 |
| | | { m_pGlassData->GetMapDefect_NG(), true , false } // NG:不做最小尺寸过滤 |
| | | }; |
| | | |
| | | CString strBody; |
| | | for (const auto& s : sources) { |
| | | if (!s.map) continue; |
| | | for (auto it = s.map->begin(); it != s.map->end(); ++it) { |
| | | CDefect* d = static_cast<CDefect*>(it->second); |
| | | if (!d) continue; |
| | | if ((d->m_bJudge_NG ? true : false) != s.bRequireNG) continue; |
| | | if (!IsChip(d)) continue; |
| | | if (s.bMinFilter && !PassMinSize(d)) continue; |
| | | strBody += MakeRow(d, strGlassID); |
| | | } |
| | | } |
| | | |
| | | { |
| | | MapDefectIt it; |
| | | MapDefect* pMapDefect = m_pGlassData->GetMapDefect_NG(); |
| | | const CString strPath = MakeResultCsvPath(_T("ChipData")); |
| | | const CString strHeader = _T("Date,GlassID,Model,SBK Line,Side,C-L/C-S,TFT/CF,Length,Depth,PosX,PosY\r\n"); |
| | | AppendCsvWithHeader(strPath, strHeader, strBody); |
| | | } |
| | | |
| | | for (it = pMapDefect->begin(); it != pMapDefect->end(); it++) |
| | | { |
| | | void CPostProcess::SaveDefectListData(CString strGlassID, CString strTime) |
| | | { |
| | | if (!m_pGlassData) { |
| | | return; |
| | | } |
| | | |
| | | CString strBody; |
| | | MapDefect* pMapDefect = m_pGlassData->GetMapDefect_NG(); |
| | | if (pMapDefect) { |
| | | for (auto it = pMapDefect->begin(); it != pMapDefect->end(); ++it) { |
| | | CDefect* pDefect = static_cast<CDefect*>(it->second); |
| | | |
| | | if (pDefect == NULL) |
| | | if (!pDefect) { |
| | | continue; |
| | | } |
| | | |
| | | if (pDefect->m_bJudge_NG == FALSE) |
| | | if (!pDefect->m_bJudge_NG) { |
| | | continue; |
| | | |
| | | CString strDefectType = g_strDefectType[pDefect->m_DefectInfo.m_DefectLoc]; |
| | | } |
| | | |
| | | CString strEqip, strUnit; |
| | | |
| | | CTransfer_Data* pTrans = m_pTransData; |
| | | if (pTrans != NULL) |
| | | { |
| | | strEqip.Format(_T("%d"), pTrans->m_nEqpNo); |
| | | strUnit.Format(_T("%d"), pTrans->m_nUnitNo); |
| | | if (m_pTransData) { |
| | | strEqip.Format(_T("%d"), m_pTransData->m_nEqpNo); |
| | | strUnit.Format(_T("%d"), m_pTransData->m_nUnitNo); |
| | | } |
| | | else |
| | | { |
| | | strEqip.Format(_T("%d"), 0); |
| | | strUnit.Format(_T("%d"), 0); |
| | | else { |
| | | strEqip = _T("0"); strUnit = _T("0"); |
| | | } |
| | | |
| | | defect_data.AppendFormat(_T("%s,%s,%s,%s,%s,%s,%f,%f,%s"), |
| | | CString strSideName = PANEL_SIDE[pDefect->m_DefectInfo.m_nSideIdx]; |
| | | CString strDefectType = g_strDefectType[pDefect->m_DefectInfo.m_DefectLoc]; |
| | | |
| | | strBody.AppendFormat(_T("%s,%s,%s,%s,%s,%s,%f,%f,%s\r\n"), |
| | | strTime, |
| | | glass_id, |
| | | strGlassID, |
| | | strEqip, |
| | | strUnit, |
| | | PANEL_SIDE[pDefect->m_DefectInfo.m_nSideIdx], |
| | | strSideName, |
| | | strDefectType, |
| | | pDefect->m_dSizeX_um, |
| | | pDefect->m_dSizeY_um, |
| | | pDefect->m_strSaveImagePath); |
| | | defect_data.Append(_T("\r\n")); |
| | | } |
| | | } |
| | | |
| | | if ((strDefectType.Compare(_T("Chip")) == 0 || strDefectType.Compare(_T("In_Chip")) == 0)) |
| | | { |
| | | // 获取当前时间 |
| | | std::time_t now = std::time(nullptr); |
| | | // 使用localtime_s代替localtime |
| | | std::tm nowTm; |
| | | localtime_s(&nowTm, &now); |
| | | const CString strPath = MakeResultCsvPath(_T("DefectData")); |
| | | const CString strHeader = _T("TIME,ID,EQP NO,UNIT NO,SIDE,LOCATION,SIZE_X,SIZE_Y,IMAGE_PATH\r\n"); |
| | | AppendCsvWithHeader(strPath, strHeader, strBody); |
| | | } |
| | | |
| | | CString strDate; |
| | | strDate.Format(_T("%04d%02d%02d%02d%02d%02d"), |
| | | nowTm.tm_year + 1900, nowTm.tm_mon + 1, nowTm.tm_mday, nowTm.tm_hour, nowTm.tm_min, nowTm.tm_sec); |
| | | void CPostProcess::SaveRipSideInspect(CString strGlassID, CString strTime) |
| | | { |
| | | if (m_pHardware == nullptr || m_pGlassData == nullptr || m_pRecipe == nullptr) { |
| | | return; |
| | | } |
| | | |
| | | CString strCLCS; |
| | | m_pGlassData->DecodeDefectPose(&(pDefect->m_DefectInfo), strCLCS); |
| | | CPoint pos2I = m_pGlassData->TransformToGlobal((DimensionDir)pDefect->m_DefectInfo.m_nSideIdx, pDefect->m_DefectInfo.m_ptDefectPos_pxl); |
| | | int nSeq = 1; |
| | | CString strBody; |
| | | const DimensionDir RIP_SIDES[] = { DIMENSION_A_RIP, DIMENSION_B_RIP, DIMENSION_C_RIP, DIMENSION_D_RIP }; |
| | | |
| | | chip_data.AppendFormat(_T("%s,%s,%s,%s,%s,%s,%s,%f,%f,%d,%d"), |
| | | strDate, |
| | | glass_id, |
| | | g_pBase->m_strRecipeName, |
| | | g_pBase->m_strSBKLine, |
| | | PANEL_SIDE[pDefect->m_DefectInfo.m_nSideIdx], |
| | | strCLCS, |
| | | pDefect->m_DefectInfo.m_nSideIdx >= 0 && pDefect->m_DefectInfo.m_nSideIdx < 4 ? _T("CF") : _T("TFT"), |
| | | pDefect->m_dSizeY_um, |
| | | pDefect->m_dSizeX_um, |
| | | std::abs(pos2I.y), |
| | | std::abs(pos2I.x)); |
| | | chip_data.Append(_T("\r\n")); |
| | | for (DimensionDir eDim : RIP_SIDES) { |
| | | int nSide = (int)eDim; |
| | | CSide_Data* pSideData = m_pGlassData->GetSideData(eDim); |
| | | CSIDE_PARM* pSideParm = &m_pRecipe->m_SideParam[eDim]; |
| | | if (!pSideData || !pSideParm) { |
| | | continue; |
| | | } |
| | | |
| | | CRIP_THICKNESS_PARM& rip = pSideParm->m_RipThk; |
| | | if (rip.m_bUseInspect != TRUE) { |
| | | continue; |
| | | } |
| | | |
| | | int nMeasureCount = pSideParm->m_nSideDimensionCount; |
| | | for (int i = 0; i < nMeasureCount; ++i) { |
| | | if (i == MAX_SIDE_DIMENSION_MEASURE_COUNT || i == MAX_RIP_SAMPLE_COUNT) { |
| | | break; |
| | | } |
| | | |
| | | if (pSideParm->m_bSideDimension_Use[i] != TRUE) { |
| | | continue; |
| | | } |
| | | |
| | | bool bValid = pSideData->m_nSideRip_Left_Status[i] != 0 || pSideData->m_nSideRip_Right_Status[i] != 0 || pSideData->m_nSideRip_Glass_Status[i] != 0; |
| | | if (!bValid) { |
| | | continue; |
| | | } |
| | | |
| | | strBody.AppendFormat(_T("%d,%s,%s,%s,%.1f,%.1f,%.1f\r\n"), |
| | | nSeq++, strTime, strGlassID, g_SideName[nSide], |
| | | pSideData->m_dSideRip_Left_um[i], |
| | | pSideData->m_dSideRip_Right_um[i], |
| | | pSideData->m_dSideRip_Glass_um[i]); |
| | | } |
| | | } |
| | | |
| | | CString Chip_file_path; |
| | | if (m_pHardware->m_bSaveResultByHour) { |
| | | // 按小时保存结果 |
| | | Chip_file_path.Format(_T("%s\\%s_%02d_ChipData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, tGlassLoading.GetHour()); |
| | | if (strBody.IsEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | const CString strPath = MakeResultCsvPath(_T("RipSideInspect")); |
| | | const CString strHeader = _T("Seq,Time,ID,Side,Left Cut Depth (um),Right Cut Depth (um),Total Length (um)\r\n"); |
| | | AppendCsvWithHeader(strPath, strHeader, strBody); |
| | | } |
| | | |
| | | void CPostProcess::SaveDefectData() |
| | | { |
| | | CString strGlassID; |
| | | strGlassID.Format(_T("%s"), g_pBase->m_strHPanelID); |
| | | if (strGlassID.IsEmpty()) { |
| | | strGlassID.Format(_T("MANUAL_ID")); |
| | | } |
| | | |
| | | CString strTime; |
| | | strTime.Format(_T("%s"), g_pBase->m_strLoadingTime); |
| | | |
| | | SaveMeasureData(strGlassID, strTime); |
| | | SaveChipData(strGlassID, strTime); |
| | | SaveDefectListData(strGlassID, strTime); |
| | | SaveRipSideInspect(strGlassID, strTime); |
| | | } |
| | | |
| | | CString CPostProcess::MakeResultCsvPath(LPCTSTR stem) const |
| | | { |
| | | CString strPath; |
| | | if (m_pHardware && m_pHardware->m_bSaveResultByHour) { |
| | | CTime tLoad = m_pGlassData ? m_pGlassData->GetLoadingTime() : CTime::GetCurrentTime(); |
| | | strPath.Format(_T("%s\\%s_%02d_%s.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, tLoad.GetHour(), stem); |
| | | } |
| | | else { |
| | | // 不按小时保存结果 |
| | | Chip_file_path.Format(_T("%s\\%s_ChipData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay); |
| | | strPath.Format(_T("%s\\%s_%s.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, stem); |
| | | } |
| | | |
| | | CheckDirectory(Chip_file_path); |
| | | return strPath; |
| | | } |
| | | |
| | | CFile chip_module; |
| | | CFileException chip_exception; |
| | | |
| | | chip_module.Open(Chip_file_path, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate | CFile::shareDenyWrite | CFile::shareDenyRead, &chip_exception); |
| | | |
| | | if (chip_exception.m_cause == CFileException::none) |
| | | { |
| | | if (chip_module.SeekToEnd() == 0L) |
| | | { |
| | | CString defect_title; |
| | | defect_title.Format(_T("Date,GlassID,Model,SBK Line,Side,C-L/C-S,TFT/CF,Length,Depth,PosX,PosY\r\n")); |
| | | chip_module.Write(defect_title, defect_title.GetLength() * sizeof(TCHAR)); |
| | | } |
| | | chip_module.Write(chip_data, chip_data.GetLength() * sizeof(TCHAR)); |
| | | chip_module.Close(); |
| | | bool CPostProcess::AppendCsvWithHeader(const CString& strFilePath, const CString& strHeader, const CString& strBody) |
| | | { |
| | | if (strBody.IsEmpty()) { |
| | | return false; |
| | | } |
| | | |
| | | CString Defect_file_path; |
| | | if (m_pHardware->m_bSaveResultByHour) { |
| | | // 按小时保存结果 |
| | | Defect_file_path.Format(_T("%s\\%s_%02d_DefectData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, tGlassLoading.GetHour()); |
| | | } |
| | | else { |
| | | // 不按小时保存结果 |
| | | Defect_file_path.Format(_T("%s\\%s_DefectData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay); |
| | | CheckDirectory(strFilePath); |
| | | |
| | | CFile f; CFileException ex; |
| | | if (!f.Open(strFilePath, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate | CFile::shareDenyWrite | CFile::shareDenyRead, &ex)) { |
| | | return false; |
| | | } |
| | | |
| | | CheckDirectory(Defect_file_path); |
| | | |
| | | CFile defect_module; |
| | | CFileException defect_exception; |
| | | |
| | | defect_module.Open(Defect_file_path, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate | CFile::shareDenyWrite | CFile::shareDenyRead, &defect_exception); |
| | | |
| | | if (defect_exception.m_cause == CFileException::none) |
| | | { |
| | | if (defect_module.SeekToEnd() == 0L) |
| | | { |
| | | CString defect_title; |
| | | defect_title.Format(_T("TIME,ID,EQP NO,UNIT NO,SIDE,LOCATION,SIZE_X,SIZE_Y,IMAGE_PATH\r\n")); |
| | | defect_module.Write(defect_title, defect_title.GetLength()*sizeof(TCHAR)); |
| | | } |
| | | defect_module.Write(defect_data, defect_data.GetLength()*sizeof(TCHAR)); |
| | | defect_module.Close(); |
| | | if (f.SeekToEnd() == 0L) { |
| | | f.Write(strHeader, strHeader.GetLength() * sizeof(TCHAR)); |
| | | } |
| | | f.Write(strBody, strBody.GetLength() * sizeof(TCHAR)); |
| | | f.Close(); |
| | | return true; |
| | | } |
| | | |
| | | void CPostProcess::JudgementData() |
| | |
| | | void WriteSetupData(); |
| | | |
| | | protected: |
| | | CString MakeResultCsvPath(LPCTSTR stem) const; |
| | | bool AppendCsvWithHeader(const CString& strFilePath, const CString& strHeader, const CString& strBody); |
| | | void JudgementData(); |
| | | void SaveDefectImageNG(); |
| | | void SaveDefectImageOK(); |
| | | void SaveMeasureData(CString strGlassID, CString strTime); |
| | | void SaveChipData(CString strGlassID, CString strTime); |
| | | void SaveDefectListData(CString strGlassID, CString strTime); |
| | | void SaveRipSideInspect(CString strGlassID, CString strTime); |
| | | void SaveDefectData(); |
| | | void MergeDefect(); |
| | | void CalcGlassSize(); |
| | |
| | | void CDlgSideDimensionSetting::SetDlgRecipe(CGlassRecipe* pDlgRecipe) |
| | | { |
| | | m_pDlgRecipe = pDlgRecipe; |
| | | |
| | | UpdateRecipe(FALSE); |
| | | } |
| | | |
| | | void CDlgSideDimensionSetting::UpdateRecipe(BOOL bGetData) |
| | | { |
| | | // Title |
| | | if(m_pSelectSideIdx != NULL) |
| | | { |
| | | CString strTemp; |
| | | strTemp.Format(_T("[%s] Dim. Setting"), g_SideName[(int) *(m_pSelectSideIdx)]); |
| | | SetDlgItemText(IDC_STATIC_TITLE, strTemp); |
| | | |
| | | strTemp.Format(_T("Top Corner [%s] Dim. Setting"), g_SideName[(int) *(m_pSelectSideIdx)]); |
| | | SetDlgItemText(IDC_STATIC_TITLE_TOP_CORNER, strTemp); |
| | | |
| | | strTemp.Format(_T("Bot Corner [%s] Dim. Setting"), g_SideName[(int) *(m_pSelectSideIdx)]); |
| | | SetDlgItemText(IDC_STATIC_TITLE_BOT_CORNER, strTemp); |
| | | } |
| | | |
| | | if(bGetData == FALSE) |
| | | { |
| | | if(bGetData == FALSE) { |
| | | Fill_SideDimensionSetting(bGetData); |
| | | Fill_TopCornerDimensionSetting(bGetData); |
| | | Fill_BotCornerDimensionSetting(bGetData); |
| | | } |
| | | else |
| | | { |
| | | else { |
| | | Fill_SideDimensionSetting(bGetData); |
| | | Fill_TopCornerDimensionSetting(bGetData); |
| | | Fill_BotCornerDimensionSetting(bGetData); |
| | | } |
| | | } |
| | | |
| | | void CDlgSideDimensionSetting::RefreshSideUI(BOOL bReinitGrid /*=TRUE*/) |
| | | { |
| | | if (!m_pSelectSideIdx) { |
| | | return; |
| | | } |
| | | |
| | | const int nSideIdx = *m_pSelectSideIdx; |
| | | const DimensionDir eDim = (DimensionDir)nSideIdx; |
| | | m_bIsRipSide = (DIMENSION_A_RIP == eDim) || (DIMENSION_B_RIP == eDim) || (DIMENSION_C_RIP == eDim) || (DIMENSION_D_RIP == eDim); |
| | | |
| | | CString strTemp; |
| | | strTemp.Format(_T("[%s] Dim. Setting"), g_SideName[nSideIdx]); |
| | | SetDlgItemText(IDC_STATIC_TITLE, strTemp); |
| | | |
| | | strTemp.Format(_T("Top Corner [%s] Dim. Setting"), g_SideName[nSideIdx]); |
| | | SetDlgItemText(IDC_STATIC_TITLE_TOP_CORNER, strTemp); |
| | | |
| | | strTemp.Format(_T("Bot Corner [%s] Dim. Setting"), g_SideName[nSideIdx]); |
| | | SetDlgItemText(IDC_STATIC_TITLE_BOT_CORNER, strTemp); |
| | | |
| | | if (CWnd* p = GetDlgItem(IDC_BUTTON_CAL)) { |
| | | p->EnableWindow(!m_bIsRipSide); |
| | | } |
| | | |
| | | if (CWnd* p = GetDlgItem(IDC_BUTTON_GET_SIDE_RESULT)) { |
| | | p->EnableWindow(!m_bIsRipSide); |
| | | } |
| | | |
| | | if (bReinitGrid) { |
| | | Init_SideDimensionSetting(); |
| | | } |
| | | } |
| | | |
| | | void CDlgSideDimensionSetting::Init_SideDimensionSetting() |
| | | { |
| | | if (m_SideDimensionSetting.GetSafeHwnd() == NULL) |
| | | if (m_SideDimensionSetting.GetSafeHwnd() == NULL) { |
| | | return; |
| | | } |
| | | |
| | | int nRows = 1; |
| | | int nCols = 9 + 3; |
| | | if (m_pSelectSideIdx == nullptr) { |
| | | return; |
| | | } |
| | | |
| | | int nFixRows = 1; |
| | | int nFixCols = 0; |
| | | int nRowIdx = 0; |
| | | int nColIdx = 0; |
| | | auto ScaleX = [&](int px)->int { |
| | | HDC hdc = ::GetDC(m_hWnd); |
| | | const int dpi = GetDeviceCaps(hdc, LOGPIXELSX); |
| | | ::ReleaseDC(m_hWnd, hdc); |
| | | return MulDiv(px, dpi, 96); |
| | | }; |
| | | |
| | | struct ColDef { int w; LPCTSTR name; }; |
| | | static const ColDef kColsRip[] = { |
| | | { 90, _T("No.") }, |
| | | { 100, _T("Start Line To Y(um)") }, |
| | | { 100, _T("Use Dim.") }, |
| | | }; |
| | | static const ColDef kColsNormal[] = { |
| | | { 90, _T("No.") }, |
| | | { 70, _T("Top Mark To Y(um)") }, |
| | | { 70, _T("Use Dim.") }, |
| | | { 70, _T("Thres") }, |
| | | { 70, _T("Std(mm)") }, |
| | | { 70, _T("Min(mm)") }, |
| | | { 70, _T("Max(mm)") }, |
| | | { 70, _T("Off(mm)") }, |
| | | { 70, _T("Use Chamfer") }, |
| | | { 70, _T("Std(mm)") }, |
| | | { 70, _T("Min(mm)") }, |
| | | { 70, _T("Max(mm)") }, |
| | | }; |
| | | const ColDef* cols = m_bIsRipSide ? kColsRip : kColsNormal; |
| | | const int nCols = m_bIsRipSide ? (int)_countof(kColsRip) : (int)_countof(kColsNormal); |
| | | const int nRows = 1; |
| | | const int nFixRows = 1; |
| | | const int nFixCols = 0; |
| | | |
| | | m_SideDimensionSetting.DeleteAllItems(); |
| | | m_SideDimensionSetting.SetVirtualMode(FALSE); |
| | |
| | | m_SideDimensionSetting.SetFixedRowCount(nFixRows); |
| | | m_SideDimensionSetting.SetFixedColumnCount(nFixCols); |
| | | |
| | | CFont *pFont = m_SideDimensionSetting.GetFont(); |
| | | if (pFont) |
| | | { |
| | | LOGFONT lf; |
| | | pFont->GetLogFont(&lf); |
| | | if (CFont* pFont = m_SideDimensionSetting.GetFont()) { |
| | | LOGFONT lf{}; pFont->GetLogFont(&lf); |
| | | lf.lfItalic = 0; |
| | | lf.lfHeight = 14; |
| | | lf.lfWeight = FW_BOLD; |
| | | _tcscpy_s(lf.lfFaceName, _T("Arial")); |
| | | lf.lfHeight = 14; |
| | | |
| | | m_SideDimensionSetting.GetDefaultCell(FALSE, TRUE)->SetFont(&lf); |
| | | m_SideDimensionSetting.GetDefaultCell(TRUE, FALSE)->SetFont(&lf); |
| | |
| | | m_SideDimensionSetting.GetDefaultCell(TRUE, TRUE)->SetFont(&lf); |
| | | } |
| | | |
| | | // Col |
| | | m_SideDimensionSetting.SetColumnWidth(nColIdx, 90); |
| | | m_SideDimensionSetting.SetItemText(nRowIdx, nColIdx++, _T("No.")); |
| | | m_SideDimensionSetting.SetColumnWidth(nColIdx, 100); |
| | | m_SideDimensionSetting.SetItemText(nRowIdx, nColIdx++, _T("Top Mark To Y(um)")); |
| | | m_SideDimensionSetting.SetColumnWidth(nColIdx, 70); |
| | | m_SideDimensionSetting.SetItemText(nRowIdx, nColIdx++, _T("Use Dim.")); |
| | | m_SideDimensionSetting.SetColumnWidth(nColIdx, 70); |
| | | m_SideDimensionSetting.SetItemText(nRowIdx, nColIdx++, _T("Thres")); |
| | | m_SideDimensionSetting.SetColumnWidth(nColIdx, 70); |
| | | m_SideDimensionSetting.SetItemText(nRowIdx, nColIdx++, _T("Std(mm)")); |
| | | m_SideDimensionSetting.SetColumnWidth(nColIdx, 70); |
| | | m_SideDimensionSetting.SetItemText(nRowIdx, nColIdx++, _T("Min(mm)")); |
| | | m_SideDimensionSetting.SetColumnWidth(nColIdx, 70); |
| | | m_SideDimensionSetting.SetItemText(nRowIdx, nColIdx++, _T("Max(mm)")); |
| | | m_SideDimensionSetting.SetColumnWidth(nColIdx, 70); |
| | | m_SideDimensionSetting.SetItemText(nRowIdx, nColIdx++, _T("Off(mm)")); |
| | | m_SideDimensionSetting.SetColumnWidth(nColIdx, 70); |
| | | m_SideDimensionSetting.SetItemText(nRowIdx, nColIdx++, _T("Use Chamfer")); |
| | | m_SideDimensionSetting.SetColumnWidth(nColIdx, 70); |
| | | m_SideDimensionSetting.SetItemText(nRowIdx, nColIdx++, _T("Std(mm)")); |
| | | m_SideDimensionSetting.SetColumnWidth(nColIdx, 70); |
| | | m_SideDimensionSetting.SetItemText(nRowIdx, nColIdx++, _T("Min(mm)")); |
| | | m_SideDimensionSetting.SetColumnWidth(nColIdx, 70); |
| | | m_SideDimensionSetting.SetItemText(nRowIdx, nColIdx++, _T("Max(mm)")); |
| | | for (int c = 0; c < nCols; ++c) { |
| | | m_SideDimensionSetting.SetColumnWidth(c, ScaleX(cols[c].w)); |
| | | m_SideDimensionSetting.SetItemText(0, c, cols[c].name); |
| | | } |
| | | |
| | | m_SideDimensionSetting.SetFixedRowSelection(FALSE); |
| | | m_SideDimensionSetting.SetFixedColumnSelection(FALSE); |
| | |
| | | |
| | | void CDlgSideDimensionSetting::Fill_SideDimensionSetting(BOOL bGetData) |
| | | { |
| | | if(m_SideDimensionSetting.GetSafeHwnd() == NULL) |
| | | if (m_SideDimensionSetting.GetSafeHwnd() == NULL) { |
| | | return; |
| | | } |
| | | |
| | | if(m_pDlgRecipe == NULL || m_pSelectSideIdx == NULL) |
| | | if (m_pDlgRecipe == NULL || m_pSelectSideIdx == NULL) { |
| | | return; |
| | | } |
| | | |
| | | int nSideIdx = *(m_pSelectSideIdx); |
| | | |
| | | if(nSideIdx < 0 || eRcp_SideRD_End <= nSideIdx) |
| | | if (nSideIdx < 0 || nSideIdx >= eRcp_SideRD_End) { |
| | | return; |
| | | } |
| | | |
| | | int c = 0; |
| | | const int COL_NO = c++; |
| | | const int COL_TOPMARK_Y = c++; |
| | | const int COL_USE_DIM = c++; |
| | | |
| | | int COL_THRES = -1, COL_STD = -1, COL_MIN = -1, COL_MAX = -1, COL_OFF = -1; |
| | | int COL_CHAMFER_USE = -1, COL_CH_STD = -1, COL_CH_MIN = -1, COL_CH_MAX = -1; |
| | | |
| | | if (!m_bIsRipSide) { |
| | | COL_THRES = c++; |
| | | COL_STD = c++; |
| | | COL_MIN = c++; |
| | | COL_MAX = c++; |
| | | COL_OFF = c++; |
| | | COL_CHAMFER_USE = c++; |
| | | COL_CH_STD = c++; |
| | | COL_CH_MIN = c++; |
| | | COL_CH_MAX = c++; |
| | | } |
| | | |
| | | // 单元格读写封装 |
| | | auto SetCell = [&](int r, int col, LPCTSTR s) { m_SideDimensionSetting.SetItemText(r, col, s); }; |
| | | auto SetCellInt = [&](int r, int col, int v) { CString t; t.Format(_T("%d"), v); SetCell(r, col, t); }; |
| | | auto SetCellDouble = [&](int r, int col, double v, int prec = 3) { CString t; t.Format(_T("%.*f"), prec, v); SetCell(r, col, t); }; |
| | | auto SetCellBool = [&](int r, int col, BOOL b) { CString t; t.Format(_T("%d"), b ? 1 : 0); SetCell(r, col, t); }; |
| | | auto GetCellStr = [&](int r, int col)->CString { CString s = m_SideDimensionSetting.GetItemText(r, col); s.Trim(); return s; }; |
| | | auto GetCellInt = [&](int r, int col, int def = 0)->int { CString s = GetCellStr(r, col); return s.IsEmpty() ? def : _wtoi(s); }; |
| | | auto GetCellDouble = [&](int r, int col, double def = 0.0)->double { CString s = GetCellStr(r, col); return s.IsEmpty() ? def : _wtof(s); }; |
| | | auto GetCellBool = [&](int r, int col)->BOOL { return GetCellInt(r, col, 0) ? TRUE : FALSE; }; |
| | | |
| | | m_SideDimensionSetting.SetRedraw(FALSE); |
| | | CSIDE_PARM* pParam = &m_pDlgRecipe->m_SideParam[nSideIdx]; |
| | | |
| | | CString strTemp; |
| | | int nRow = 0; |
| | | int nCol = 0; |
| | | |
| | | if(bGetData == FALSE) |
| | | { |
| | | int nDimensionCount = pParam->m_nSideDimensionCount; |
| | | |
| | | if (!bGetData) { |
| | | const int nDimensionCount = max(0, min(pParam->m_nSideDimensionCount, MAX_SIDE_DIMENSION_MEASURE_COUNT)); |
| | | m_SideDimensionSetting.SetRowCount(nDimensionCount + 1); |
| | | |
| | | for(int i=0; i<nDimensionCount; i++) |
| | | { |
| | | nRow = i + 1; |
| | | nCol = 0; |
| | | for (int i = 0; i < nDimensionCount; ++i) { |
| | | const int r = i + 1; |
| | | |
| | | // 1. No. |
| | | strTemp.Format(_T("S_D/C_%d"), i + 1); |
| | | m_SideDimensionSetting.SetItemText(nRow, nCol++, strTemp); |
| | | // 1) No. |
| | | CString no; no.Format(_T("S_D/C_%d"), i + 1); |
| | | SetCell(r, COL_NO, no); |
| | | |
| | | // 2. Top Mark To Distance Y (um) |
| | | strTemp.Format(_T("%d"), pParam->m_nSideDimensionPos_TopMarkToDistance_um[i]); |
| | | m_SideDimensionSetting.SetItemText(nRow, nCol++, strTemp); |
| | | // 2) Top Mark To Distance Y (um) |
| | | SetCellInt(r, COL_TOPMARK_Y, pParam->m_nSideDimensionPos_TopMarkToDistance_um[i]); |
| | | |
| | | // 3. Use Dimension |
| | | strTemp.Format(_T("%d"), (int) pParam->m_bSideDimension_Use[i]); |
| | | m_SideDimensionSetting.SetItemText(nRow, nCol++, strTemp); |
| | | // 3) Use Dimension (0/1) |
| | | SetCellBool(r, COL_USE_DIM, pParam->m_bSideDimension_Use[i]); |
| | | |
| | | // 4. Thres |
| | | strTemp.Format(_T("%.d"), pParam->m_nSideDimensionSpec_Thres[i]); |
| | | m_SideDimensionSetting.SetItemText(nRow, nCol++, strTemp); |
| | | if (!m_bIsRipSide) { |
| | | // 4) Thres |
| | | SetCellInt(r, COL_THRES, pParam->m_nSideDimensionSpec_Thres[i]); |
| | | |
| | | // 5. Std |
| | | strTemp.Format(_T("%.3f"), pParam->m_dSideDimensionSpec_mm_Std[i]); |
| | | m_SideDimensionSetting.SetItemText(nRow, nCol++, strTemp); |
| | | // 5-7) Std/Min/Max |
| | | SetCellDouble(r, COL_STD, pParam->m_dSideDimensionSpec_mm_Std[i]); |
| | | SetCellDouble(r, COL_MIN, pParam->m_dSideDimensionSpec_mm_Min[i]); |
| | | SetCellDouble(r, COL_MAX, pParam->m_dSideDimensionSpec_mm_Max[i]); |
| | | |
| | | // 6. Min |
| | | strTemp.Format(_T("%.3f"), pParam->m_dSideDimensionSpec_mm_Min[i]); |
| | | m_SideDimensionSetting.SetItemText(nRow, nCol++, strTemp); |
| | | // 8) Offset |
| | | SetCellDouble(r, COL_OFF, pParam->m_dSideDimensionSpec_mm_Off[i]); |
| | | |
| | | // 7. Max |
| | | strTemp.Format(_T("%.3f"), pParam->m_dSideDimensionSpec_mm_Max[i]); |
| | | m_SideDimensionSetting.SetItemText(nRow, nCol++, strTemp); |
| | | // 9) Chamfer Use |
| | | SetCellBool(r, COL_CHAMFER_USE, pParam->m_bSideChamfer_Use[i]); |
| | | |
| | | // 8. Offset |
| | | strTemp.Format(_T("%.3f"), pParam->m_dSideDimensionSpec_mm_Off[i]); |
| | | m_SideDimensionSetting.SetItemText(nRow, nCol++, strTemp); |
| | | |
| | | // 9. Chamfer |
| | | strTemp.Format(_T("%d"), (int) pParam->m_bSideChamfer_Use[i]); |
| | | m_SideDimensionSetting.SetItemText(nRow, nCol++, strTemp); |
| | | |
| | | // 10. Std |
| | | strTemp.Format(_T("%.3f"), pParam->m_dSideChamfer_Spec_mm_Std[i]); |
| | | m_SideDimensionSetting.SetItemText(nRow, nCol++, strTemp); |
| | | |
| | | // 11. Min |
| | | strTemp.Format(_T("%.3f"), pParam->m_dSideChamfer_Spec_mm_Min[i]); |
| | | m_SideDimensionSetting.SetItemText(nRow, nCol++, strTemp); |
| | | |
| | | // 12. Max |
| | | strTemp.Format(_T("%.3f"), pParam->m_dSideChamfer_Spec_mm_Max[i]); |
| | | m_SideDimensionSetting.SetItemText(nRow, nCol++, strTemp); |
| | | // 10-12) Chamfer Std/Min/Max |
| | | SetCellDouble(r, COL_CH_STD, pParam->m_dSideChamfer_Spec_mm_Std[i]); |
| | | SetCellDouble(r, COL_CH_MIN, pParam->m_dSideChamfer_Spec_mm_Min[i]); |
| | | SetCellDouble(r, COL_CH_MAX, pParam->m_dSideChamfer_Spec_mm_Max[i]); |
| | | } |
| | | } |
| | | |
| | | m_SideDimensionSetting.Invalidate(); |
| | | } |
| | | else |
| | | { |
| | | int nDimensionCount = m_SideDimensionSetting.GetRowCount() - 1; |
| | | |
| | | else { |
| | | int nDimensionCount = max(0, m_SideDimensionSetting.GetRowCount() - 1); |
| | | nDimensionCount = min(nDimensionCount, MAX_SIDE_DIMENSION_MEASURE_COUNT); |
| | | pParam->m_nSideDimensionCount = nDimensionCount; |
| | | |
| | | for(int i=0; i<nDimensionCount; i++) |
| | | { |
| | | nRow = i + 1; |
| | | nCol = 1; |
| | | for (int i = 0; i < nDimensionCount; ++i) { |
| | | const int r = i + 1; |
| | | int col = COL_TOPMARK_Y; |
| | | |
| | | // 1. No. |
| | | // 2) Top Mark To Distance Y (um) |
| | | pParam->m_nSideDimensionPos_TopMarkToDistance_um[i] = GetCellInt(r, col++, pParam->m_nSideDimensionPos_TopMarkToDistance_um[i]); |
| | | |
| | | // 2. Top Mark To Distance Y (um) |
| | | strTemp = m_SideDimensionSetting.GetItemText(nRow, nCol++); |
| | | pParam->m_nSideDimensionPos_TopMarkToDistance_um[i] = _wtoi(strTemp); |
| | | // 3) Use Dimension |
| | | pParam->m_bSideDimension_Use[i] = GetCellBool(r, col++); |
| | | |
| | | // 3. Use Dimension |
| | | strTemp = m_SideDimensionSetting.GetItemText(nRow, nCol++); |
| | | pParam->m_bSideDimension_Use[i] = (_wtoi(strTemp) == 0) ? FALSE : TRUE; |
| | | if (!m_bIsRipSide) { |
| | | // 4) Thres |
| | | pParam->m_nSideDimensionSpec_Thres[i] = GetCellInt(r, col++, pParam->m_nSideDimensionSpec_Thres[i]); |
| | | |
| | | // 4. Thres |
| | | strTemp = m_SideDimensionSetting.GetItemText(nRow, nCol++); |
| | | pParam->m_nSideDimensionSpec_Thres[i] = _wtoi(strTemp); |
| | | // 5-7) Std/Min/Max |
| | | pParam->m_dSideDimensionSpec_mm_Std[i] = GetCellDouble(r, col++, pParam->m_dSideDimensionSpec_mm_Std[i]); |
| | | pParam->m_dSideDimensionSpec_mm_Min[i] = GetCellDouble(r, col++, pParam->m_dSideDimensionSpec_mm_Min[i]); |
| | | pParam->m_dSideDimensionSpec_mm_Max[i] = GetCellDouble(r, col++, pParam->m_dSideDimensionSpec_mm_Max[i]); |
| | | |
| | | // 5. Std |
| | | strTemp = m_SideDimensionSetting.GetItemText(nRow, nCol++); |
| | | pParam->m_dSideDimensionSpec_mm_Std[i] = _wtof(strTemp); |
| | | // 8) Offset |
| | | pParam->m_dSideDimensionSpec_mm_Off[i] = GetCellDouble(r, col++, pParam->m_dSideDimensionSpec_mm_Off[i]); |
| | | |
| | | // 6. Min |
| | | strTemp = m_SideDimensionSetting.GetItemText(nRow, nCol++); |
| | | pParam->m_dSideDimensionSpec_mm_Min[i] = _wtof(strTemp); |
| | | // 9) Chamfer Use |
| | | pParam->m_bSideChamfer_Use[i] = GetCellBool(r, col++); |
| | | |
| | | // 7. Max |
| | | strTemp = m_SideDimensionSetting.GetItemText(nRow, nCol++); |
| | | pParam->m_dSideDimensionSpec_mm_Max[i] = _wtof(strTemp); |
| | | // 10-12) Chamfer Std/Min/Max |
| | | pParam->m_dSideChamfer_Spec_mm_Std[i] = GetCellDouble(r, col++, pParam->m_dSideChamfer_Spec_mm_Std[i]); |
| | | pParam->m_dSideChamfer_Spec_mm_Min[i] = GetCellDouble(r, col++, pParam->m_dSideChamfer_Spec_mm_Min[i]); |
| | | pParam->m_dSideChamfer_Spec_mm_Max[i] = GetCellDouble(r, col++, pParam->m_dSideChamfer_Spec_mm_Max[i]); |
| | | } |
| | | } |
| | | |
| | | // 8. Offset |
| | | strTemp = m_SideDimensionSetting.GetItemText(nRow, nCol++); |
| | | pParam->m_dSideDimensionSpec_mm_Off[i] = _wtof(strTemp); |
| | | for (int k = nDimensionCount; k < MAX_SIDE_DIMENSION_MEASURE_COUNT; ++k) { |
| | | pParam->m_nSideDimensionPos_TopMarkToDistance_um[k] = 0; |
| | | pParam->m_bSideDimension_Use[k] = FALSE; |
| | | |
| | | // 9. Chamfer |
| | | strTemp = m_SideDimensionSetting.GetItemText(nRow, nCol++); |
| | | pParam->m_bSideChamfer_Use[i] = (_wtoi(strTemp) == 0) ? FALSE : TRUE; |
| | | pParam->m_nSideDimensionSpec_Thres[k] = 0; |
| | | pParam->m_dSideDimensionSpec_mm_Std[k] = 0.0; |
| | | pParam->m_dSideDimensionSpec_mm_Min[k] = 0.0; |
| | | pParam->m_dSideDimensionSpec_mm_Max[k] = 0.0; |
| | | pParam->m_dSideDimensionSpec_mm_Off[k] = 0.0; |
| | | |
| | | // 10. Std |
| | | strTemp = m_SideDimensionSetting.GetItemText(nRow, nCol++); |
| | | pParam->m_dSideChamfer_Spec_mm_Std[i] = _wtof(strTemp); |
| | | |
| | | // 11. Min |
| | | strTemp = m_SideDimensionSetting.GetItemText(nRow, nCol++); |
| | | pParam->m_dSideChamfer_Spec_mm_Min[i] = _wtof(strTemp); |
| | | |
| | | // 12. Max |
| | | strTemp = m_SideDimensionSetting.GetItemText(nRow, nCol++); |
| | | pParam->m_dSideChamfer_Spec_mm_Max[i] = _wtof(strTemp); |
| | | pParam->m_bSideChamfer_Use[k] = FALSE; |
| | | pParam->m_dSideChamfer_Spec_mm_Std[k] = 0.0; |
| | | pParam->m_dSideChamfer_Spec_mm_Min[k] = 0.0; |
| | | pParam->m_dSideChamfer_Spec_mm_Max[k] = 0.0; |
| | | } |
| | | } |
| | | } |
| | | |
| | | m_SideDimensionSetting.SetRedraw(TRUE); |
| | | m_SideDimensionSetting.Invalidate(FALSE); |
| | | } |
| | | |
| | | void CDlgSideDimensionSetting::Fill_SideDimensionSetting_CurrentResult() |
| | | { |
| | |
| | | |
| | | void CDlgSideDimensionSetting::ClickButtonAdd() |
| | | { |
| | | if(m_pDlgRecipe == NULL || m_pSelectSideIdx == NULL) |
| | | if (m_pDlgRecipe == NULL || m_pSelectSideIdx == NULL) { |
| | | return; |
| | | } |
| | | |
| | | int nSideIdx = *(m_pSelectSideIdx); |
| | | |
| | | if(nSideIdx < 0 || eRcp_SideRD_End <= nSideIdx) |
| | | if (nSideIdx < 0 || eRcp_SideRD_End <= nSideIdx) { |
| | | return; |
| | | } |
| | | |
| | | CSIDE_PARM* pParam = &m_pDlgRecipe->m_SideParam[nSideIdx]; |
| | | |
| | | int nAddIdx = pParam->m_nSideDimensionCount; |
| | | |
| | | if(nAddIdx < 0 || MAX_SIDE_DIMENSION_MEASURE_COUNT <= nAddIdx) |
| | | { |
| | | if(nAddIdx < 0 || MAX_SIDE_DIMENSION_MEASURE_COUNT <= nAddIdx) { |
| | | CString strMsg; |
| | | strMsg.Format(_T("Max Dimension Measure Count : %d ea"), MAX_SIDE_DIMENSION_MEASURE_COUNT); |
| | | AfxMessageBox(strMsg); |
| | | return; |
| | | } |
| | | |
| | | UpdateRecipe(TRUE); |
| | | |
| | | pParam->m_nSideDimensionPos_TopMarkToDistance_um[nAddIdx] = 0; |
| | | pParam->m_dSideDimensionSpec_mm_Min[nAddIdx] = 0; |
| | |
| | | |
| | | void CDlgSideDimensionSetting::ClickButtonDel() |
| | | { |
| | | if(m_pDlgRecipe == NULL || m_pSelectSideIdx == NULL) |
| | | if (m_pDlgRecipe == NULL || m_pSelectSideIdx == NULL) { |
| | | return; |
| | | } |
| | | |
| | | int nSideIdx = *(m_pSelectSideIdx); |
| | | |
| | | if(nSideIdx < 0 || eRcp_SideRD_End <= nSideIdx) |
| | | if (nSideIdx < 0 || eRcp_SideRD_End <= nSideIdx) { |
| | | return; |
| | | } |
| | | |
| | | CSIDE_PARM* pParam = &m_pDlgRecipe->m_SideParam[nSideIdx]; |
| | | |
| | |
| | | CCellID FocusedID = m_SideDimensionSetting.GetFocusCell(); |
| | | int nDelIdx = FocusedID.row - 1; |
| | | |
| | | if(nDelIdx < 0 || nSideDimensionCount <= nDelIdx) |
| | | { |
| | | if(nDelIdx < 0 || nSideDimensionCount <= nDelIdx) { |
| | | AfxMessageBox(_T("Select Error")); |
| | | return; |
| | | } |
| | | |
| | | UpdateRecipe(TRUE); |
| | | |
| | | int nPosIdx = 0; |
| | | for(int i=0; i<MAX_DIMENSION_COUNT; i++) |
| | | { |
| | | if(i == nDelIdx) |
| | | for(int i=0; i<MAX_DIMENSION_COUNT; i++) { |
| | | if (i == nDelIdx) { |
| | | continue; |
| | | } |
| | | |
| | | pParam->m_nSideDimensionPos_TopMarkToDistance_um[nPosIdx] = pParam->m_nSideDimensionPos_TopMarkToDistance_um[i]; |
| | | pParam->m_dSideDimensionSpec_mm_Min[nPosIdx] = pParam->m_dSideDimensionSpec_mm_Min[i]; |
| | |
| | | void SetDlgRecipe(CGlassRecipe* pDlgRecipe); |
| | | void SetGlassData(CGlass_Data* pGlassData) {m_pGlassData = pGlassData;} |
| | | void UpdateRecipe(BOOL bGetData); |
| | | |
| | | void RefreshSideUI(BOOL bReinitGrid = TRUE); |
| | | |
| | | void Init_SideDimensionSetting(); |
| | | void Fill_SideDimensionSetting(BOOL bGetData); |
| | |
| | | CGridCtrl m_SideDimensionSetting; |
| | | CGridCtrl m_TopCornerDimensionSetting; |
| | | CGridCtrl m_BotCornerDimensionSetting; |
| | | BOOL m_bIsRipSide; |
| | | public: |
| | | |
| | | DECLARE_EVENTSINK_MAP() |
| | |
| | | g_pLog->DisplayMessage(_T("[APP]Measure Side Edge Start, StartEdge = %d, EndEdge = %d, Width = %d"), nTopEdge, nBottomEdge, imgWidth); |
| | | |
| | | stFrameIndex stFrame = m_pGrabber->GetGrabFrame(); |
| | | CRIP_THICKNESS_PARM& rip = m_pRecipe->m_SideParam[eDim].m_RipThk; |
| | | CSIDE_PARM parm = m_pRecipe->m_SideParam[eDim]; |
| | | CRIP_THICKNESS_PARM& rip = parm.m_RipThk; |
| | | if (rip.m_bUseInspect != TRUE) { |
| | | return TRUE; |
| | | } |
| | | |
| | | int inspectNum = 36; |
| | | |
| | | //输入参数 |
| | | int topOffset = rip.m_nTopOffset; //T Offset |
| | |
| | | int leftEdge = rip.m_nRectLeft; //Rect L |
| | | int rightEdge = rip.m_nRectRight; //Rect R |
| | | int leftThres = rip.m_nLeftThres; //Left Thres |
| | | int rightThres = rip.m_nRightThres; //Right Thres |
| | | int rightThres = rip.m_nRightThres; //Right Thres |
| | | int gassThres = rip.m_nGlassThres; //Gas Thres |
| | | |
| | | int inspectNum = 36; |
| | | |
| | | int startY = nTopEdge + topOffset; |
| | | int endY = nBottomEdge - botOffset; |
| | | int step = (int)((endY - startY) / inspectNum); |
| | | g_pLog->DisplayMessage(_T("[APP]Measure Side Edge, (startY, endY, step) = (%d, %d, %d)"), startY, endY, step); |
| | | |
| | | int nStep = max(1, (endY - startY) / inspectNum); // 防 0 |
| | | auto SpecDiff = [](double v, double vMin, double vMax)->double { |
| | | if (v <= 0) return 0.0; // 无效值 |
| | | if (v < vMin) return v - vMin; // 负:低于下限 |
| | | if (v > vMax) return v - vMax; // 正:高于上限 |
| | | return 0.0; // 在规格内 |
| | | }; |
| | | auto judge = [](double v_um, double vMin, double vMax)->int { |
| | | if (v_um <= 0) return 0; |
| | | return (v_um < vMin || v_um > vMax) ? 2 : 1; |
| | | }; |
| | | auto MakeBaseInfo = [&](CPoint pt, CRect rt, DefectLocation loc)->CDefect_Info { |
| | | CDefect_Info info; |
| | | info.m_iFrameIdx = stFrame.nFrameIdx; |
| | | info.m_nCamID = m_iCamera; |
| | | info.m_nScanIdx = stFrame.nScanIdx; |
| | | info.m_nGlassStartLine = pSideData->m_nGlassStartLine; |
| | | info.m_nSideIdx = (int)eDim; |
| | | info.m_ptDefectPos_pxl = pt; |
| | | info.m_rtDefectPos_pxl = rt; |
| | | info.m_DefectLoc = loc; |
| | | return info; |
| | | }; |
| | | |
| | | #if 1 |
| | | int nMeasureCount = parm.m_nSideDimensionCount; |
| | | for (int nMeasurePointIdx = 0; nMeasurePointIdx < nMeasureCount; nMeasurePointIdx++) { |
| | | if (nMeasurePointIdx == MAX_SIDE_DIMENSION_MEASURE_COUNT || nMeasurePointIdx == MAX_RIP_SAMPLE_COUNT) { |
| | | break; |
| | | } |
| | | |
| | | if (parm.m_bSideDimension_Use[nMeasurePointIdx] != TRUE) { |
| | | continue; |
| | | } |
| | | |
| | | //这里做一个测试 |
| | | int inputY = (int)(parm.m_nSideDimensionPos_TopMarkToDistance_um[nMeasurePointIdx] * m_dPixelSizeY); //这个是输入参数,距离StartLine的距离, um |
| | | int targetY = (int)(inputY / m_dPixelSizeY); |
| | | int x1 = leftEdge; |
| | | int y1 = nTopEdge + targetY - 50; |
| | | int x2 = rightEdge; |
| | | int y2 = nTopEdge + targetY + 50; |
| | | |
| | | double dist_ret = 0.0f; //输出结果 |
| | | double left_dist_Gass = 0.0f; //输出结果 |
| | | double right_dist_Gass; //输出结果 |
| | | double xMinEdge_px = 0.0f; //输出结果 |
| | | double yMinEdge_px = 0.0f; //输出结果 |
| | | double xMaxEdge_px = 0.0f; //输出结果 |
| | | double yMaxEdge_px = 0.0f; //输出结果 |
| | | double xMinGas_px = 0.0f; //输出结果 |
| | | double yMinGas_px = 0.0f; //输出结果 |
| | | double xMaxGas_px = 0.0f; //输出结果 |
| | | double yMaxGas_px = 0.0f; //输出结果 |
| | | MeasureSideEdge_POS_1(eDim, x1, y1, x2, y2, leftThres, rightThres, gassThres, |
| | | xMinEdge_px, yMinEdge_px, xMaxEdge_px, yMaxEdge_px, |
| | | xMinGas_px, yMinGas_px, xMaxGas_px, yMaxGas_px, |
| | | dist_ret, left_dist_Gass, right_dist_Gass); |
| | | |
| | | g_pLog->DisplayMessage(_T("[APP]Measure Result: LeftEdge = (%.1f, %.1f), LeftGas = (%.1f, %.1f), rightGas = (%.1f, %.1f), RightEdge = (%.1f, %.1f), (Dist, LeftGass, RightGass) = (%.1f, %.1f, %.1f)"), |
| | | xMinEdge_px, yMinEdge_px, |
| | | xMinGas_px, yMinGas_px, |
| | | xMaxGas_px, yMaxGas_px, |
| | | xMaxEdge_px, yMaxEdge_px, |
| | | dist_ret, left_dist_Gass, right_dist_Gass); |
| | | |
| | | dist_ret *= m_dPixelSizeX; |
| | | left_dist_Gass *= m_dPixelSizeX; |
| | | right_dist_Gass *= m_dPixelSizeX; |
| | | |
| | | const int nGlassState = judge(dist_ret, rip.m_nGlassSizeMin_um, rip.m_nGlassSizeMax_um); |
| | | const int nLeftState = judge(left_dist_Gass, rip.m_nLeftRipSizeMin_um, rip.m_nLeftRipSizeMax_um); |
| | | const int nRightState = judge(right_dist_Gass, rip.m_nRightRipSizeMin_um, rip.m_nRightRipSizeMax_um); |
| | | |
| | | if (nMeasurePointIdx < MAX_RIP_SAMPLE_COUNT) { |
| | | // Glass 线段 |
| | | pSideData->m_ptSideRip_Glass_pxl[nMeasurePointIdx][0] = CPoint((int)xMinEdge_px, (int)yMinEdge_px); |
| | | pSideData->m_ptSideRip_Glass_pxl[nMeasurePointIdx][1] = CPoint((int)xMaxEdge_px, (int)yMaxEdge_px); |
| | | pSideData->m_dSideRip_Glass_um[nMeasurePointIdx] = dist_ret; |
| | | pSideData->m_nSideRip_Glass_Status[nMeasurePointIdx] = nGlassState; |
| | | |
| | | // Left 线段 |
| | | pSideData->m_ptSideRip_Left_pxl[nMeasurePointIdx][0] = CPoint((int)xMinEdge_px, (int)yMinEdge_px); |
| | | pSideData->m_ptSideRip_Left_pxl[nMeasurePointIdx][1] = CPoint((int)xMinGas_px, (int)yMinGas_px); |
| | | pSideData->m_dSideRip_Left_um[nMeasurePointIdx] = left_dist_Gass; |
| | | pSideData->m_nSideRip_Left_Status[nMeasurePointIdx] = nLeftState; |
| | | |
| | | // Right 线段 |
| | | pSideData->m_ptSideRip_Right_pxl[nMeasurePointIdx][0] = CPoint((int)xMaxGas_px, (int)yMaxGas_px); |
| | | pSideData->m_ptSideRip_Right_pxl[nMeasurePointIdx][1] = CPoint((int)xMaxEdge_px, (int)yMaxEdge_px); |
| | | pSideData->m_dSideRip_Right_um[nMeasurePointIdx] = right_dist_Gass; |
| | | pSideData->m_nSideRip_Right_Status[nMeasurePointIdx] = nRightState; |
| | | } |
| | | |
| | | // Glass NG |
| | | if (nGlassState == 2) { |
| | | CRect rt( |
| | | (int)min(min(xMinEdge_px, xMinGas_px), min(xMaxEdge_px, xMaxGas_px)), |
| | | (int)min(min(yMinEdge_px, yMinGas_px), min(yMaxEdge_px, yMaxGas_px)), |
| | | (int)max(max(xMinEdge_px, xMinGas_px), max(xMaxEdge_px, xMaxGas_px)), |
| | | (int)max(max(yMinEdge_px, yMinGas_px), max(yMaxEdge_px, yMaxGas_px)) |
| | | ); |
| | | CPoint pt((rt.left + rt.right) / 2, (rt.top + rt.bottom) / 2); |
| | | CDefect_Info defect = MakeBaseInfo(pt, rt, DefectLoc_Rip_Thickness_Glass); |
| | | double dDiff = SpecDiff(dist_ret, rip.m_nGlassSizeMin_um, rip.m_nGlassSizeMax_um); |
| | | m_pDefectControl->ExtractDefect_RipThickness(eDim, m_iCamera, stFrame.nScanIdx, defect, dist_ret, dDiff); |
| | | } |
| | | // Left NG |
| | | if (nLeftState == 2) { |
| | | CRect rt( |
| | | (int)min(xMinEdge_px, xMinGas_px), |
| | | (int)min(yMinEdge_px, yMinGas_px), |
| | | (int)max(xMinEdge_px, xMinGas_px), |
| | | (int)max(yMinEdge_px, yMinGas_px) |
| | | ); |
| | | CPoint pt((rt.left + rt.right) / 2, (rt.top + rt.bottom) / 2); |
| | | CDefect_Info defect = MakeBaseInfo(pt, rt, DefectLoc_Rip_Thickness_Left); |
| | | double dDiff = SpecDiff(left_dist_Gass, rip.m_nLeftRipSizeMin_um, rip.m_nLeftRipSizeMax_um); |
| | | m_pDefectControl->ExtractDefect_RipThickness(eDim, m_iCamera, stFrame.nScanIdx, defect, left_dist_Gass, dDiff); |
| | | } |
| | | // Right NG |
| | | if (nRightState == 2) { |
| | | CRect rt( |
| | | (int)min(xMaxEdge_px, xMaxGas_px), |
| | | (int)min(yMaxEdge_px, yMaxGas_px), |
| | | (int)max(xMaxEdge_px, xMaxGas_px), |
| | | (int)max(yMaxEdge_px, yMaxGas_px) |
| | | ); |
| | | CPoint pt((rt.left + rt.right) / 2, (rt.top + rt.bottom) / 2); |
| | | CDefect_Info defect = MakeBaseInfo(pt, rt, DefectLoc_Rip_Thickness_Right); |
| | | double dDiff = SpecDiff(right_dist_Gass, rip.m_nRightRipSizeMin_um, rip.m_nRightRipSizeMax_um); |
| | | m_pDefectControl->ExtractDefect_RipThickness(eDim, m_iCamera, stFrame.nScanIdx, defect, right_dist_Gass, dDiff); |
| | | } |
| | | } |
| | | #else |
| | | double dist_array[36]; //输出结果 |
| | | double left_dist_Gass_array[36]; //输出结果 |
| | | double right_dist_Gass_array[36]; //输出结果 |
| | |
| | | double xMaxGas_array_px[36]; //输出结果 |
| | | double yMaxGas_array_px[36]; //输出结果 |
| | | |
| | | int startY = nTopEdge + topOffset; |
| | | int endY = nBottomEdge - botOffset; |
| | | int step = (int)((endY - startY) / inspectNum); |
| | | g_pLog->DisplayMessage(_T("[APP]Measure Side Edge, (startY, endY, step) = (%d, %d, %d)"), startY, endY, step); |
| | | |
| | | for (int i = 0; i < inspectNum; i++) { |
| | | int x1 = leftEdge; |
| | | int y1 = startY + i * step; |
| | |
| | | x1, y1, x2, y2, |
| | | leftThres, rightThres, gassThres, |
| | | xMinEdge_array_px[i], yMinEdge_array_px[i], xMaxEdge_array_px[i], yMaxEdge_array_px[i], |
| | | xMinGas_array_px[i], yMinGas_array_px[i], xMaxGas_array_px[i], yMaxGas_array_px[i], |
| | | xMinGas_array_px[i], yMinGas_array_px[i], xMaxGas_array_px[i], yMaxGas_array_px[i], |
| | | szDist, leftGassDist, rightGassDist); |
| | | |
| | | dist_array[i] = m_dPixelSizeX * szDist; |
| | |
| | | right_dist_Gass_array[i] = m_dPixelSizeX * rightGassDist; |
| | | |
| | | g_pLog->DisplayMessage(_T("[APP]Measure Result %d: LeftEdge = (%.1f, %.1f), LeftGas = (%.1f, %.1f), rightGas = (%.1f, %.1f), RightEdge = (%.1f, %.1f), (Dist, LeftGass, RightGass) = (%.1f, %.1f, %.1f)"), |
| | | i + 1, |
| | | xMinEdge_array_px[i], yMinEdge_array_px[i], |
| | | xMinGas_array_px[i], yMinGas_array_px[i], |
| | | xMaxGas_array_px[i], yMaxGas_array_px[i], |
| | | xMaxEdge_array_px[i], yMaxEdge_array_px[i], |
| | | i + 1, |
| | | xMinEdge_array_px[i], yMinEdge_array_px[i], |
| | | xMinGas_array_px[i], yMinGas_array_px[i], |
| | | xMaxGas_array_px[i], yMaxGas_array_px[i], |
| | | xMaxEdge_array_px[i], yMaxEdge_array_px[i], |
| | | dist_array[i], left_dist_Gass_array[i], right_dist_Gass_array[i]); |
| | | |
| | | // 添加缺陷 |
| | |
| | | } |
| | | } |
| | | } |
| | | #endif |
| | | |
| | | return TRUE; |
| | | } |
| | | |
| | | void CInspectCamera::MeasureSideEdge_POS_1(DimensionDir eDim, |
| | | int x1, int y1, int x2, int y2, |
| | | int leftThres, int rightThres, int gassThres, |
| | | double& minEdgeX, double& minEdgeY, double& maxEdgeX, double& maxEdgeY, |
| | | double& minGasX, double& minGasY, double& maxGasX, double& maxGasY, |
| | | double& szDist, double& leftGassDist, double& rightGassDist) { |
| | | /* code */ |
| | | szDist = 0.0f; |
| | | leftGassDist = 0.0f; |
| | | rightGassDist = 0.0f; |
| | | int width = x2 - x1 + 1; |
| | | int height = y2 - y1 + 1; |
| | | uchar* imgData = new uchar[width * height]; |
| | | try { |
| | | CutImageROI(imgData, eDim, x1, y1, x2, y2); |
| | | |
| | | MeasurePoint dotResult1[100]; |
| | | MeasurePoint dotResult2[100]; |
| | | MeasurePoint dotResult3[100]; |
| | | int dotNum1 = 0; |
| | | int dotNum2 = 0; |
| | | int dotNum3 = 0; |
| | | CVisionMeasureClass doExec; |
| | | double sigma = 2.5f; //输入参数, 增加参数 |
| | | doExec.doMeasurePosB(imgData, width, height, sigma, |
| | | dotResult1, dotNum1, |
| | | dotResult2, dotNum2, |
| | | dotResult3, dotNum3); |
| | | for (int i = 0; i < dotNum1; i++) { |
| | | dotResult1[i].x += x1; |
| | | dotResult1[i].y += y1; |
| | | } |
| | | for (int i = 0; i < dotNum2; i++) { |
| | | dotResult2[i].x += x1; |
| | | dotResult2[i].y += y1; |
| | | } |
| | | for (int i = 0; i < dotNum3; i++) { |
| | | dotResult3[i].x += x1; |
| | | dotResult3[i].y += y1; |
| | | } |
| | | |
| | | int fzDist = 4.5; //输入参数, 增加参数 |
| | | |
| | | double xMinResult[3] = { -1 }; |
| | | double yMinResult[3] = { -1 }; |
| | | double xMaxResult[3] = { -1 }; |
| | | double yMaxResult[3] = { -1 }; |
| | | double xMinGassResult[3] = { -1 }; |
| | | double yMinGassResult[3] = { -1 }; |
| | | double xMaxGassResult[3] = { -1 }; |
| | | double yMaxGassResult[3] = { -1 }; |
| | | MeasureResultProc(dotResult1, dotNum1, leftThres, rightThres, gassThres, fzDist, |
| | | xMinResult[0], yMinResult[0], xMaxResult[0], yMaxResult[0], |
| | | xMinGassResult[0], yMinGassResult[0], xMaxGassResult[0], yMaxGassResult[0]); |
| | | MeasureResultProc(dotResult2, dotNum2, leftThres, rightThres, gassThres, fzDist, |
| | | xMinResult[1], yMinResult[1], xMaxResult[1], yMaxResult[1], |
| | | xMinGassResult[1], yMinGassResult[1], xMaxGassResult[1], yMaxGassResult[1]); |
| | | MeasureResultProc(dotResult3, dotNum3, leftThres, rightThres, gassThres, fzDist, |
| | | xMinResult[2], yMinResult[2], xMaxResult[2], yMaxResult[2], |
| | | xMinGassResult[2], yMinGassResult[2], xMaxGassResult[2], yMaxGassResult[2]); |
| | | |
| | | std::vector<double> vDist, vLeftGass, vRightGass; |
| | | for (int i = 0; i < 3; i++) { |
| | | if (xMinResult[i] > 0 && xMaxResult[i] > 0) { |
| | | double dx = xMaxResult[i] - xMinResult[i]; |
| | | double dy = yMaxResult[i] - yMinResult[i]; |
| | | double dist = sqrt(dx * dx + dy * dy); |
| | | vDist.push_back(dist); |
| | | } |
| | | if (xMinResult[i] > 0 && xMinGassResult[i] > 0) { |
| | | double dx = xMinGassResult[i] - xMinResult[i]; |
| | | double dy = yMinGassResult[i] - yMinResult[i]; |
| | | double dist = sqrt(dx * dx + dy * dy); |
| | | vLeftGass.push_back(dist); |
| | | } |
| | | if (xMaxResult[i] > 0 && xMaxGassResult[i] > 0) { |
| | | double dx = xMaxResult[i] - xMaxGassResult[i]; |
| | | double dy = yMaxResult[i] - yMaxGassResult[i]; |
| | | double dist = sqrt(dx * dx + dy * dy); |
| | | vRightGass.push_back(dist); |
| | | } |
| | | } |
| | | |
| | | double avgDist = 0.0f; |
| | | int sz = (int)(vDist.size()); |
| | | if (sz > 2) { |
| | | for (int i = 0; i < sz - 1; i++) { |
| | | for (int j = i + 1; j < sz; j++) { |
| | | if (vDist[i] > vDist[j]) { |
| | | double tmp = vDist[i]; |
| | | vDist[i] = vDist[j]; |
| | | vDist[j] = tmp; |
| | | } |
| | | } |
| | | } |
| | | double avg = 0.0f; |
| | | for (int i = 1; i < sz - 1; i++) { |
| | | avg += vDist[i]; |
| | | } |
| | | avgDist = avg / (sz - 2); |
| | | } |
| | | double avgLeftGass = 0.0f; |
| | | sz = (int)(vLeftGass.size()); |
| | | if (sz > 2) { |
| | | for (int i = 0; i < sz - 1; i++) { |
| | | for (int j = i + 1; j < sz; j++) { |
| | | if (vLeftGass[i] > vLeftGass[j]) { |
| | | double tmp = vLeftGass[i]; |
| | | vLeftGass[i] = vLeftGass[j]; |
| | | vLeftGass[j] = tmp; |
| | | } |
| | | } |
| | | } |
| | | double avg = 0.0f; |
| | | for (int i = 1; i < sz - 1; i++) { |
| | | avg += vLeftGass[i]; |
| | | } |
| | | avgLeftGass = avg / (sz - 2); |
| | | } |
| | | |
| | | double avgRightGass = 0.0f; |
| | | sz = (int)(vRightGass.size()); |
| | | if (sz > 2) { |
| | | for (int i = 0; i < sz - 1; i++) { |
| | | for (int j = i + 1; j < sz; j++) { |
| | | if (vRightGass[i] > vRightGass[j]) { |
| | | double tmp = vRightGass[i]; |
| | | vRightGass[i] = vRightGass[j]; |
| | | vRightGass[j] = tmp; |
| | | } |
| | | } |
| | | } |
| | | double avg = 0.0f; |
| | | for (int i = 1; i < sz - 1; i++) { |
| | | avg += vRightGass[i]; |
| | | } |
| | | avgRightGass = avg / (sz - 2); |
| | | } |
| | | |
| | | szDist = avgDist; |
| | | leftGassDist = avgLeftGass; |
| | | rightGassDist = avgRightGass; |
| | | |
| | | minEdgeX = xMinResult[1]; |
| | | minEdgeY = yMinResult[1]; |
| | | maxEdgeX = xMaxResult[1]; |
| | | maxEdgeY = yMaxResult[1]; |
| | | minGasX = minEdgeX + leftGassDist - 1; |
| | | minGasY = minEdgeY; |
| | | maxGasX = maxEdgeX - rightGassDist + 1; |
| | | maxGasY = maxEdgeY; |
| | | |
| | | delete[] imgData; |
| | | imgData = nullptr; |
| | | } |
| | | catch (...) { |
| | | delete[] imgData; |
| | | imgData = nullptr; |
| | | } |
| | | } |
| | | |
| | | void CInspectCamera::MeasureSideEdge_POS(DimensionDir eDim, |
| | | int x1, int y1, int x2, int y2, |
| | | int leftThres, int rightThres, int gassThres, |
| | |
| | | //14. 截图图像 |
| | | int CutImageROI(uchar* img, DimensionDir eDim, int x1, int y1, int x2, int y2); |
| | | BOOL MeasureSideEdge_EI(DimensionDir eDim); |
| | | |
| | | void MeasureSideEdge_POS_1(DimensionDir eDim, |
| | | int x1, int y1, int x2, int y2, |
| | | int leftThres, int rightThres, int gassThres, |
| | | double& minEdgeX, double& minEdgeY, double& maxEdgeX, double& maxEdgeY, |
| | | double& minGasX, double& minGasY, double& maxGasX, double& maxGasY, |
| | | double& szDist, double& leftGassDist, double& rightGassDist); |
| | | |
| | | void MeasureSideEdge_POS(DimensionDir eDim, |
| | | int x1, int y1, int x2, int y2, |
| | | int leftThres, int rightThres, int gassThres, |
| | |
| | | } |
| | | |
| | | DimensionDir eDim = (DimensionDir)m_nSideIdx; |
| | | bool bIsRipSide = (DIMENSION_A_RIP == m_nSideIdx) || (DIMENSION_B_RIP == eDim) || (DIMENSION_C_RIP == eDim) || (DIMENSION_D_RIP == eDim); |
| | | bool bIsRipSide = (DIMENSION_A_RIP == eDim) || (DIMENSION_B_RIP == eDim) || (DIMENSION_C_RIP == eDim) || (DIMENSION_D_RIP == eDim); |
| | | if (!bIsRipSide) { |
| | | return; |
| | | } |
| | |
| | | BOOL CViewMain_ScanImage::ManualThreadStart(int nCmd,int nIndex /*= -1*/) |
| | | { |
| | | if(m_pManualProcess) { |
| | | DWORD dwWait = ::WaitForSingleObject(m_pManualProcess->m_hThread, 3000); |
| | | DWORD dwWait = ::WaitForSingleObject(m_pManualProcess->m_hThread, 1000); |
| | | if (dwWait == WAIT_TIMEOUT) { |
| | | DWORD dwExitCode; |
| | | if ((::GetExitCodeThread(m_pManualProcess->m_hThread, &dwExitCode)) && (dwExitCode == STILL_ACTIVE)) { |
| | |
| | | |
| | | void CViewMain_Recipe::UpdateRecipe(BOOL bGetData, int type) |
| | | { |
| | | if(bGetData == FALSE) |
| | | { |
| | | // UpdateData(FALSE); // Parameter |
| | | |
| | | Fill_PanelInfo(bGetData); |
| | | Fill_SideInsInfo(bGetData); |
| | | Fill_JudgementInfo(bGetData); |
| | | |
| | | UpdateSideImage(); // Image |
| | | |
| | | UpdateMarkImage(); // Mark Image |
| | | |
| | | m_dScanTimeOut = m_pDlgRecipe->m_RecieParm.m_dOneScanTime_sec; |
| | | |
| | | if(m_pViewSideDimensionSetting != NULL) |
| | | m_pViewSideDimensionSetting->UpdateRecipe(bGetData); |
| | | |
| | | if(m_pViewSideNotchSetting != NULL) |
| | | m_pViewSideNotchSetting->UpdateRecipe(bGetData); |
| | | |
| | | if(m_pViewSideExceptionSetting != NULL) |
| | | m_pViewSideExceptionSetting->UpdateRecipe(bGetData); |
| | | |
| | | if(m_pViewSideUserDefectSetting != NULL) |
| | | m_pViewSideUserDefectSetting->UpdateRecipe(bGetData); |
| | | |
| | | UpdateData(FALSE); |
| | | } |
| | | else |
| | | { |
| | | UpdateData(TRUE); // Parameter |
| | | |
| | | Fill_PanelInfo(bGetData); |
| | | Fill_SideInsInfo(bGetData); |
| | | Fill_JudgementInfo(bGetData); |
| | | |
| | | if (bGetData) { |
| | | UpdateData(TRUE); |
| | | m_pDlgRecipe->m_RecieParm.m_dOneScanTime_sec = m_dScanTimeOut; |
| | | } |
| | | else { |
| | | m_dScanTimeOut = m_pDlgRecipe->m_RecieParm.m_dOneScanTime_sec; |
| | | } |
| | | |
| | | if (type == 1) |
| | | { |
| | | if (m_pViewSideDimensionSetting != NULL) |
| | | m_pViewSideDimensionSetting->UpdateRecipe(bGetData); |
| | | Fill_PanelInfo(bGetData); |
| | | Fill_SideInsInfo(bGetData); |
| | | Fill_JudgementInfo(bGetData); |
| | | |
| | | if (!bGetData) { |
| | | UpdateSideImage(); |
| | | UpdateMarkImage(); |
| | | } |
| | | |
| | | auto UpdateChild = [&](auto* pView) { |
| | | if (pView) { |
| | | pView->UpdateRecipe(bGetData); |
| | | } |
| | | }; |
| | | |
| | | if(m_pViewSideNotchSetting != NULL) |
| | | m_pViewSideNotchSetting->UpdateRecipe(bGetData); |
| | | const bool bNeedUpdateSideDim = (!bGetData) || (type == 1); |
| | | const bool bNeedRefreshSideUI = (!bGetData); |
| | | if (m_pViewSideDimensionSetting && bNeedUpdateSideDim) { |
| | | if (bNeedRefreshSideUI) { |
| | | m_pViewSideDimensionSetting->RefreshSideUI(TRUE); |
| | | } |
| | | m_pViewSideDimensionSetting->UpdateRecipe(bGetData); |
| | | } |
| | | |
| | | if(m_pViewSideExceptionSetting != NULL) |
| | | m_pViewSideExceptionSetting->UpdateRecipe(bGetData); |
| | | UpdateChild(m_pViewSideNotchSetting); |
| | | UpdateChild(m_pViewSideExceptionSetting); |
| | | UpdateChild(m_pViewSideUserDefectSetting); |
| | | |
| | | if(m_pViewSideUserDefectSetting != NULL) |
| | | m_pViewSideUserDefectSetting->UpdateRecipe(bGetData); |
| | | if (!bGetData) { |
| | | UpdateData(FALSE); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | void CViewMain_Recipe::ClickButtonOpenDimensionSettingView() |
| | | { |
| | | if(m_pViewSideDimensionSetting == NULL) |
| | | if (m_pViewSideDimensionSetting == NULL) { |
| | | return; |
| | | } |
| | | |
| | | m_pViewSideDimensionSetting->SetGlassData(m_pGlassData); |
| | | m_pViewSideDimensionSetting->ShowWindow(SW_SHOW); |
| | |
| | | MeasurePoint* measureResult6, int& outResult6, |
| | | MeasurePoint* measureResult7, int& outResult7); |
| | | |
| | | //4. 测量点 |
| | | int doMeasurePosB(unsigned char* img, int width, int height, double sigma, |
| | | MeasurePoint* measureResult1, int& outResult1, |
| | | MeasurePoint* measureResult2, int& outResult2, |
| | | MeasurePoint* measureResult3, int& outResult3); |
| | | |
| | | //1. 获取程序运行路径 |
| | | std::string GetAppPathA(void); |
| | | }; |
| | |
| | | HalconCpp::ZoomImageSize(hImage, &hZoomImage, width, szHeight, "constant"); |
| | | HalconCpp::MeanImage(hZoomImage, &hMeanImage, 1, 5); |
| | | |
| | | |
| | | double xOutResult[MEASURE_MAX_NUM] = { 0 }; |
| | | double yOutResult[MEASURE_MAX_NUM] = { 0 }; |
| | | double cyOutResult[MEASURE_MAX_NUM] = { 0 }; |
| | |
| | | return 1; |
| | | } |
| | | |
| | | int CVisionMeasureClass::doMeasurePosB(unsigned char* img, int width, int height, double sigma, |
| | | MeasurePoint* measureResult1, int& outResult1, |
| | | MeasurePoint* measureResult2, int& outResult2, |
| | | MeasurePoint* measureResult3, int& outResult3) { |
| | | /* code */ |
| | | if (nullptr == img) return -1; |
| | | |
| | | HalconCpp::HObject hImage, hZoomImage, hMeanImage; |
| | | HalconCpp::GenImage1(&hImage, "byte", width, height, (Hlong)img); |
| | | int szHeight = (int)(0.5 * height); |
| | | HalconCpp::ZoomImageSize(hImage, &hZoomImage, width, szHeight, "constant"); |
| | | HalconCpp::MeanImage(hZoomImage, &hMeanImage, 1, 5); |
| | | |
| | | double xOutResult[MEASURE_MAX_NUM] = { 0 }; |
| | | double yOutResult[MEASURE_MAX_NUM] = { 0 }; |
| | | double cyOutResult[MEASURE_MAX_NUM] = { 0 }; |
| | | double distOutResult[MEASURE_MAX_NUM] = { 0 }; |
| | | int outNum = 0; |
| | | |
| | | int topEdge = 15; |
| | | int botEdge = szHeight - 16; |
| | | int step = (int)((botEdge - topEdge) / 2); |
| | | int x1 = 5; |
| | | int x2 = width - 6; |
| | | for (int i = 0; i < 3; i++) { |
| | | int y1 = topEdge + i * step; |
| | | int y2 = y1; |
| | | int threshold = 10; |
| | | doMeasurePosApi(hMeanImage, x1, y1, x2, y2, 10, threshold, sigma, xOutResult, yOutResult, cyOutResult, distOutResult, outNum); |
| | | if (0 == i) { |
| | | outResult1 = outNum; |
| | | for (int i = 0; i < outNum; i++) { |
| | | measureResult1[i].x = xOutResult[i]; |
| | | measureResult1[i].y = 2 * yOutResult[i]; |
| | | measureResult1[i].cy = cyOutResult[i]; |
| | | } |
| | | } |
| | | else if (1 == i) { |
| | | outResult2 = outNum; |
| | | for (int i = 0; i < outNum; i++) { |
| | | measureResult2[i].x = xOutResult[i]; |
| | | measureResult2[i].y = 2 * yOutResult[i]; |
| | | measureResult2[i].cy = cyOutResult[i]; |
| | | } |
| | | } |
| | | else if (2 == i) { |
| | | outResult3 = outNum; |
| | | for (int i = 0; i < outNum; i++) { |
| | | measureResult3[i].x = xOutResult[i]; |
| | | measureResult3[i].y = 2 * yOutResult[i]; |
| | | measureResult3[i].cy = cyOutResult[i]; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | std::string CVisionMeasureClass::GetAppPathA(void) { |
| | | /* code */ |
| | | char szFilePath[MAX_PATH] = { 0 }, szDrive[MAX_PATH] = { 0 }, szDir[MAX_PATH] = { 0 }, szFileName[MAX_PATH] = { 0 }, szExt[MAX_PATH] = { 0 }; |
| | |
| | | MeasurePoint* measureResult6, int& outResult6, |
| | | MeasurePoint* measureResult7, int& outResult7); |
| | | |
| | | //4. 测量点 |
| | | int doMeasurePosB(unsigned char* img, int width, int height, double sigma, |
| | | MeasurePoint* measureResult1, int& outResult1, |
| | | MeasurePoint* measureResult2, int& outResult2, |
| | | MeasurePoint* measureResult3, int& outResult3); |
| | | |
| | | //1. 获取程序运行路径 |
| | | std::string GetAppPathA(void); |
| | | }; |