| | |
| | | #include <unordered_map> |
| | | #include <vector> |
| | | #include <string> |
| | | #include <algorithm> |
| | | #include "CProcessDataListDlg.h" |
| | | |
| | | #define PAGE_SIZE 50 |
| | |
| | | static const COLORREF kWipText = RGB(0, 0, 0); |
| | | static const COLORREF kWipParentBk = RGB(201, 228, 180); // 基础绿 |
| | | static const COLORREF kWipChildBk = RGB(221, 241, 208); // 更浅一点 |
| | | |
| | | namespace { |
| | | CString FormatPathTime(ULONGLONG ts) |
| | | { |
| | | if (ts == 0) return _T(""); |
| | | return CString(CToolUnits::timeToString2(ts).c_str()); |
| | | } |
| | | |
| | | void BuildPathRowsFromGlass(SERVO::CGlass& glass, std::vector<CProcessDataListDlg::PathRow>& rows) |
| | | { |
| | | rows.clear(); |
| | | SERVO::CPath* pHead = glass.getPath(); |
| | | if (pHead == nullptr) return; |
| | | |
| | | SERVO::CPath* p = pHead->getHeadPath(); |
| | | int step = 1; |
| | | while (p != nullptr) { |
| | | CProcessDataListDlg::PathRow r; |
| | | r.step.Format(_T("%d"), step++); |
| | | std::string eqName = SERVO::CServoUtilsTool::getEqUnitName( |
| | | (int)p->getEqID(), (int)p->getUnit(), (int)p->getSlot()); |
| | | if (eqName.empty()) { |
| | | CString tmp; |
| | | tmp.Format(_T("Eq:%u Unit:%u Slot:%u"), p->getEqID(), p->getUnit(), p->getSlot()); |
| | | r.chamber = tmp; |
| | | } |
| | | else { |
| | | r.chamber = eqName.c_str(); |
| | | } |
| | | r.enterTime = FormatPathTime(p->getInTime()); |
| | | r.leaveTime = FormatPathTime(p->getOutTime()); |
| | | r.isArmStep = (p->getEqID() == EQ_ID_ARM |
| | | || p->getEqID() == EQ_ID_ARM_TRAY1 |
| | | || p->getEqID() == EQ_ID_ARM_TRAY2); |
| | | rows.push_back(r); |
| | | p = p->getNext(); |
| | | } |
| | | } |
| | | |
| | | void ParseNameValuePairs(const CString& text, std::vector<std::pair<CString, CString>>& outRows) |
| | | { |
| | | outRows.clear(); |
| | | int idx = 0; |
| | | CString token; |
| | | while (AfxExtractSubString(token, text, idx, ',')) { |
| | | ++idx; |
| | | const int pos = token.Find(_T(':')); |
| | | if (pos < 0) continue; |
| | | CString name = token.Left(pos); |
| | | CString value = token.Mid(pos + 1); |
| | | name.Trim(); |
| | | value.Trim(); |
| | | if (!name.IsEmpty()) { |
| | | outRows.emplace_back(name, value); |
| | | } |
| | | } |
| | | } |
| | | |
| | | void BuildBasicRowsFromList(CListCtrl& list, int row, std::vector<std::pair<CString, CString>>& rows) |
| | | { |
| | | rows.clear(); |
| | | CHeaderCtrl* pHdr = list.GetHeaderCtrl(); |
| | | const int colCount = pHdr ? pHdr->GetItemCount() : 0; |
| | | for (int col = 1; col < colCount; ++col) { |
| | | if (col == 11 || col == 12) continue; // 这两列单独作为其他页 |
| | | TCHAR buf[256] = { 0 }; |
| | | LVCOLUMN lvc = {}; |
| | | lvc.mask = LVCF_TEXT; |
| | | lvc.pszText = buf; |
| | | lvc.cchTextMax = _countof(buf); |
| | | CString header; |
| | | if (list.GetColumn(col, &lvc)) header = lvc.pszText; |
| | | header.Trim(); |
| | | if (header.IsEmpty()) continue; |
| | | |
| | | CString val = list.GetItemText(row, col); |
| | | rows.emplace_back(header, val); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // ===== 放在 CPageGlassList.cpp 顶部的匿名工具(文件内静态) ===== |
| | | // 把当前“已展开”的父行,用它们的 classId(第4列文本)做 key 记录下来 |
| | |
| | | ON_BN_CLICKED(IDC_BUTTON_PREV_PAGE, &CPageGlassList::OnBnClickedButtonPrevPage) |
| | | ON_BN_CLICKED(IDC_BUTTON_NEXT_PAGE, &CPageGlassList::OnBnClickedButtonNextPage) |
| | | ON_NOTIFY(ELCN_SHOWFULLTEXT, IDC_LIST_ALARM, &CPageGlassList::OnShowFullText) |
| | | ON_NOTIFY(NM_DBLCLK, IDC_LIST_ALARM, &CPageGlassList::OnNMDblclkListAlarm) |
| | | ON_BN_CLICKED(IDC_BUTTON_EXPORT_ROW, &CPageGlassList::OnBnClickedButtonExportRow) |
| | | END_MESSAGE_MAP() |
| | | |
| | |
| | | { |
| | | CDialogEx::OnInitDialog(); |
| | | |
| | | // 定时器:1=初始化订阅,2=周期刷新(只增量) |
| | | // 定时器:1=初始化订阅,2=周期刷新(只增量),3=延迟加载首屏数据 |
| | | SetTimer(1, 3000, nullptr); |
| | | SetTimer(2, 2000, nullptr); |
| | | SetTimer(3, 10, nullptr); |
| | | |
| | | // 下拉框控件 |
| | | InitStatusCombo(); |
| | |
| | | m_listCtrl.SetPopupFullTextColumns({ 11, 12 }); |
| | | |
| | | Resize(); |
| | | OnBnClickedButtonSearch(); // 触发一次查询与首屏填充 |
| | | |
| | | return TRUE; // return TRUE unless you set the focus to a control |
| | | } |
| | |
| | | else if (nIDEvent == 2) { |
| | | UpdateWipData(); // 只做增量,不重建 |
| | | } |
| | | else if (nIDEvent == 3) { |
| | | KillTimer(3); |
| | | OnBnClickedButtonSearch(); // 延迟首屏查询,避免卡住 OnInitDialog |
| | | } |
| | | |
| | | CDialogEx::OnTimer(nIDEvent); |
| | | } |
| | |
| | | |
| | | void CPageGlassList::OnBnClickedButtonSearch() |
| | | { |
| | | CWaitCursor wait; // 显示等待光标,提示正在加载 |
| | | |
| | | // 获取关键字输入框内容 |
| | | CString strKeyword; |
| | | GetDlgItemText(IDC_EDIT_KEYWORD, strKeyword); |
| | |
| | | if (!row.pretty.empty()) { |
| | | CFile file; |
| | | if (file.Open(filePath, CFile::modeCreate | CFile::modeWrite)) { |
| | | file.Write(row.pretty.c_str(), row.pretty.length()); |
| | | file.Write(row.pretty.c_str(), (UINT)row.pretty.length()); |
| | | file.Close(); |
| | | |
| | | CString strSuccess; |
| | |
| | | // 对每个机器生成表格 |
| | | for (const auto& machinePair : tempGlass.getAllSVData()) { |
| | | int machineId = machinePair.first; |
| | | const auto& dataByType = machinePair.second; |
| | | CString machineName = CString(SERVO::CServoUtilsTool::getEqName(machineId).c_str()); |
| | | |
| | | csvContent += _T("\n[") + machineName + _T("]\n"); |
| | | |
| | | // 获取该机器的预定义列顺序 |
| | | auto columnOrder = getMachineColumnOrder(machineId); |
| | | |
| | | if (columnOrder.empty()) { |
| | | csvContent += _T("无预定义列配置\n"); |
| | | if (dataByType.empty()) { |
| | | csvContent += _T("No sensor data\n"); |
| | | continue; |
| | | } |
| | | |
| | | // 构建表头 - 直接使用中文列名 |
| | | CString header = _T("时间戳(ms),本地时间"); |
| | | auto columnOrder = getMachineColumnOrder(machineId, &dataByType); |
| | | if (columnOrder.empty()) { |
| | | csvContent += _T("No exportable columns\n"); |
| | | continue; |
| | | } |
| | | |
| | | CString header = _T("Timestamp(ms),LocalTime"); |
| | | for (const auto& dataType : columnOrder) { |
| | | header += _T(","); |
| | | header += CString(dataType.c_str()); // 直接使用中文列名 |
| | | header += CString(dataType.c_str()); |
| | | } |
| | | header += _T("\n"); |
| | | csvContent += header; |
| | | |
| | | // 检查是否有数据 |
| | | if (machinePair.second.empty()) { |
| | | csvContent += _T("无传感器数据\n"); |
| | | auto baselineIt = std::find_if(columnOrder.begin(), columnOrder.end(), |
| | | [&](const std::string& type) { |
| | | auto dataIt = dataByType.find(type); |
| | | return dataIt != dataByType.end() && !dataIt->second.empty(); |
| | | }); |
| | | if (baselineIt == columnOrder.end()) { |
| | | csvContent += _T("No usable time series\n"); |
| | | continue; |
| | | } |
| | | |
| | | // 使用第一个数据类型的时间序列作为基准 |
| | | const std::string& firstDataType = columnOrder[0]; |
| | | auto firstDataTypeIt = machinePair.second.find(firstDataType); |
| | | if (firstDataTypeIt == machinePair.second.end() || firstDataTypeIt->second.empty()) { |
| | | csvContent += _T("无基准数据类型数据\n"); |
| | | continue; |
| | | } |
| | | |
| | | const auto& timeSeries = firstDataTypeIt->second; |
| | | |
| | | // 对于每个时间点,输出一行数据 |
| | | for (size_t i = 0; i < timeSeries.size(); i++) { |
| | | const auto& timeSeries = dataByType.at(*baselineIt); |
| | | for (size_t i = 0; i < timeSeries.size(); ++i) { |
| | | auto timestamp = timeSeries[i].timestamp; |
| | | |
| | | // 时间戳(毫秒) |
| | | auto ms = timePointToMs(timestamp); |
| | | CString row; |
| | | row.Format(_T("%lld,"), ms); |
| | | |
| | | // 本地时间字符串 |
| | | CString localTime = CString(timePointToString(timestamp).c_str()); |
| | | row += localTime; |
| | | |
| | | // 按照预定义的列顺序输出数据 |
| | | for (const auto& dataType : columnOrder) { |
| | | row += _T(","); |
| | | |
| | | auto dataTypeIt = machinePair.second.find(dataType); |
| | | if (dataTypeIt != machinePair.second.end() && i < dataTypeIt->second.size()) { |
| | | // 直接按索引获取数据 |
| | | auto dataTypeIt = dataByType.find(dataType); |
| | | if (dataTypeIt != dataByType.end() && i < dataTypeIt->second.size()) { |
| | | CString valueStr; |
| | | valueStr.Format(_T("%.3f"), dataTypeIt->second[i].value); |
| | | row += valueStr; |
| | | } |
| | | else { |
| | | // 理论上不应该发生,因为您说没有空值 |
| | | row += _T("N/A"); |
| | | } |
| | | } |
| | |
| | | { |
| | | auto* p = reinterpret_cast<NMC_ELC_SHOWFULLTEXT*>(pNMHDR); |
| | | |
| | | // 对话框显示工艺参数 |
| | | if (p->iSubItem != 11 && p->iSubItem != 12) { |
| | | AfxMessageBox(p->text); |
| | | *pResult = 0; |
| | | return; |
| | | } |
| | | |
| | | const int row = p->iItem; |
| | | std::vector<std::pair<CString, CString>> basicRows; |
| | | std::vector<std::pair<CString, CString>> processRows; |
| | | std::vector<CProcessDataListDlg::PathRow> pathRows; |
| | | bool pathOk = false; |
| | | |
| | | BuildBasicRowsFromList(m_listCtrl, row, basicRows); |
| | | |
| | | CString paramsText = m_listCtrl.GetItemText(row, 12); |
| | | ParseNameValuePairs(paramsText, processRows); |
| | | |
| | | CString strId = m_listCtrl.GetItemText(row, 1); // DB id,WIP为空 |
| | | if (!strId.IsEmpty()) { |
| | | try { |
| | | auto rec = GlassLogDb::Instance().queryById(_ttoi64(strId)); |
| | | if (rec.has_value() && !rec->pretty.empty()) { |
| | | SERVO::CGlass tempGlass; |
| | | if (GlassJson::FromString(rec->pretty, tempGlass)) { |
| | | BuildPathRowsFromGlass(tempGlass, pathRows); |
| | | pathOk = !pathRows.empty(); |
| | | } |
| | | } |
| | | } |
| | | catch (...) { |
| | | pathOk = false; |
| | | } |
| | | } |
| | | |
| | | if (!pathOk) { |
| | | CString cls = m_listCtrl.GetItemText(row, 4); // Class ID |
| | | #ifdef _UNICODE |
| | | std::string classId = CT2A(cls); |
| | | #else |
| | | std::string classId = cls.GetString(); |
| | | #endif |
| | | if (!classId.empty()) { |
| | | std::vector<SERVO::CGlass*> wipGlasses; |
| | | theApp.m_model.m_master.getWipGlasses(wipGlasses); |
| | | std::vector<SERVO::CGlass*> tempRetain = wipGlasses; |
| | | SERVO::CGlass* found = nullptr; |
| | | for (auto* g : wipGlasses) { |
| | | if (g == nullptr) continue; |
| | | if (g->getID() == classId) { found = g; break; } |
| | | SERVO::CGlass* b = g->getBuddy(); |
| | | if (b != nullptr && b->getID() == classId) { found = b; break; } |
| | | } |
| | | if (found != nullptr) { |
| | | BuildPathRowsFromGlass(*found, pathRows); |
| | | pathOk = !pathRows.empty(); |
| | | } |
| | | for (auto* item : tempRetain) { |
| | | if (item != nullptr) item->release(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!pathOk) { |
| | | CString pathText = m_listCtrl.GetItemText(row, 11); |
| | | if (!pathText.IsEmpty()) { |
| | | int cur = 0; |
| | | CString token = pathText.Tokenize(_T("->"), cur); |
| | | int step = 1; |
| | | while (!token.IsEmpty()) { |
| | | token.Trim(); |
| | | if (!token.IsEmpty()) { |
| | | CProcessDataListDlg::PathRow r; |
| | | r.step.Format(_T("%d"), step++); |
| | | r.chamber = token; |
| | | r.enterTime = _T(""); |
| | | r.leaveTime = _T(""); |
| | | CString upper = token; |
| | | upper.MakeUpper(); |
| | | r.isArmStep = (upper.Find(_T("ARM")) >= 0 || upper.Find(_T("TRAY")) >= 0); |
| | | pathRows.push_back(r); |
| | | } |
| | | token = pathText.Tokenize(_T("->"), cur); |
| | | } |
| | | } |
| | | } |
| | | |
| | | CProcessDataListDlg dlg; |
| | | dlg.setRawText(p->text); |
| | | dlg.setUnifiedData(basicRows, pathRows, processRows); |
| | | dlg.setInitialTab((p->iSubItem == 11) ? 1 : 2); |
| | | dlg.DoModal(); |
| | | |
| | | *pResult = 0; |
| | | } |
| | | |
| | | void CPageGlassList::OnNMDblclkListAlarm(NMHDR* pNMHDR, LRESULT* pResult) |
| | | { |
| | | LPNMITEMACTIVATE pItem = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR); |
| | | if (pItem == nullptr || pItem->iItem < 0) { |
| | | *pResult = 0; |
| | | return; |
| | | } |
| | | |
| | | const int row = pItem->iItem; |
| | | std::vector<std::pair<CString, CString>> basicRows; |
| | | std::vector<std::pair<CString, CString>> processRows; |
| | | std::vector<CProcessDataListDlg::PathRow> pathRows; |
| | | bool pathOk = false; |
| | | |
| | | BuildBasicRowsFromList(m_listCtrl, row, basicRows); |
| | | |
| | | CString paramsText = m_listCtrl.GetItemText(row, 12); |
| | | ParseNameValuePairs(paramsText, processRows); |
| | | |
| | | CString strId = m_listCtrl.GetItemText(row, 1); // DB id,WIP为空 |
| | | if (!strId.IsEmpty()) { |
| | | try { |
| | | auto rec = GlassLogDb::Instance().queryById(_ttoi64(strId)); |
| | | if (rec.has_value() && !rec->pretty.empty()) { |
| | | SERVO::CGlass tempGlass; |
| | | if (GlassJson::FromString(rec->pretty, tempGlass)) { |
| | | BuildPathRowsFromGlass(tempGlass, pathRows); |
| | | pathOk = !pathRows.empty(); |
| | | } |
| | | } |
| | | } |
| | | catch (...) { |
| | | pathOk = false; |
| | | } |
| | | } |
| | | |
| | | if (!pathOk) { |
| | | CString cls = m_listCtrl.GetItemText(row, 4); // Class ID |
| | | #ifdef _UNICODE |
| | | std::string classId = CT2A(cls); |
| | | #else |
| | | std::string classId = cls.GetString(); |
| | | #endif |
| | | if (!classId.empty()) { |
| | | std::vector<SERVO::CGlass*> wipGlasses; |
| | | theApp.m_model.m_master.getWipGlasses(wipGlasses); |
| | | std::vector<SERVO::CGlass*> tempRetain = wipGlasses; |
| | | SERVO::CGlass* found = nullptr; |
| | | for (auto* g : wipGlasses) { |
| | | if (g == nullptr) continue; |
| | | if (g->getID() == classId) { found = g; break; } |
| | | SERVO::CGlass* b = g->getBuddy(); |
| | | if (b != nullptr && b->getID() == classId) { found = b; break; } |
| | | } |
| | | if (found != nullptr) { |
| | | BuildPathRowsFromGlass(*found, pathRows); |
| | | pathOk = !pathRows.empty(); |
| | | } |
| | | for (auto* item : tempRetain) { |
| | | if (item != nullptr) item->release(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!pathOk) { |
| | | CString pathText = m_listCtrl.GetItemText(row, 11); |
| | | if (!pathText.IsEmpty()) { |
| | | int cur = 0; |
| | | CString token = pathText.Tokenize(_T("->"), cur); |
| | | int step = 1; |
| | | while (!token.IsEmpty()) { |
| | | token.Trim(); |
| | | if (!token.IsEmpty()) { |
| | | CProcessDataListDlg::PathRow r; |
| | | r.step.Format(_T("%d"), step++); |
| | | r.chamber = token; |
| | | r.enterTime = _T(""); |
| | | r.leaveTime = _T(""); |
| | | CString upper = token; |
| | | upper.MakeUpper(); |
| | | r.isArmStep = (upper.Find(_T("ARM")) >= 0 || upper.Find(_T("TRAY")) >= 0); |
| | | pathRows.push_back(r); |
| | | } |
| | | token = pathText.Tokenize(_T("->"), cur); |
| | | } |
| | | } |
| | | } |
| | | |
| | | CProcessDataListDlg dlg; |
| | | dlg.setUnifiedData(basicRows, pathRows, processRows); |
| | | dlg.DoModal(); |
| | | |
| | | *pResult = 0; |
| | |
| | | } |
| | | |
| | | // 获取机器预定义的列顺序 |
| | | std::vector<std::string> CPageGlassList::getMachineColumnOrder(int machineId) |
| | | std::vector<std::string> CPageGlassList::getMachineColumnOrder(int machineId, |
| | | const std::unordered_map<std::string, std::vector<SERVO::SVDataItem>>* actualData) |
| | | { |
| | | std::vector<std::string> columnOrder; |
| | | auto dataTypes = SERVO::CServoUtilsTool::getEqDataTypes(); |
| | | auto it = dataTypes.find(machineId); |
| | | return it != dataTypes.end() ? it->second : std::vector<std::string>(); |
| | | |
| | | if (actualData != nullptr) { |
| | | if (it != dataTypes.end()) { |
| | | for (const auto& name : it->second) { |
| | | if (actualData->find(name) != actualData->end()) { |
| | | columnOrder.push_back(name); |
| | | } |
| | | } |
| | | } |
| | | for (const auto& kv : *actualData) { |
| | | if (std::find(columnOrder.begin(), columnOrder.end(), kv.first) == columnOrder.end()) { |
| | | columnOrder.push_back(kv.first); |
| | | } |
| | | } |
| | | return columnOrder; |
| | | } |
| | | |
| | | if (it != dataTypes.end()) { |
| | | columnOrder = it->second; |
| | | } |
| | | return columnOrder; |
| | | } |
| | | |
| | | // 时间戳转换为字符串 |
| | |
| | | for (const auto& machinePair : dataTypes) { |
| | | int machineId = machinePair.first; |
| | | const auto& dataTypeList = machinePair.second; |
| | | std::vector<std::string> filteredTypes; |
| | | |
| | | if (machineId == EQ_ID_VACUUMBAKE || machineId == EQ_ID_BAKE_COOLING) { |
| | | const char activePrefix = 'A'; |
| | | for (const auto& dataType : dataTypeList) { |
| | | if (!dataType.empty() && dataType[0] == activePrefix) { |
| | | filteredTypes.push_back(dataType); |
| | | } |
| | | } |
| | | } |
| | | |
| | | const auto& typeList = filteredTypes.empty() ? dataTypeList : filteredTypes; |
| | | |
| | | // 生成时间序列:从当前时间往前推10分钟,每1秒一个数据点 |
| | | auto now = std::chrono::system_clock::now(); |
| | | auto startTime = now - std::chrono::minutes(10); |
| | | |
| | | // 为每个数据类型生成模拟数据 |
| | | for (const auto& dataType : dataTypeList) { |
| | | for (const auto& dataType : typeList) { |
| | | std::vector<SERVO::SVDataItem> mockData; |
| | | |
| | | // 生成600个数据点(10分钟 * 60个点/分钟) |
| | |
| | | double randomNoise = (rand() % 100 - 50) / 100.0 * variation * 0.3; // 随机噪声 |
| | | |
| | | return baseValue + timeTrend + randomNoise; |
| | | } |
| | | } |