From 415ad67bb66ca2d99fb21a8eeb32f942ad2cd7b0 Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期一, 09 二月 2026 13:32:42 +0800
Subject: [PATCH] 1.修改为tab页的展示形式

---
 SourceCode/Bond/Servo/CPageGlassList.cpp |  705 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 615 insertions(+), 90 deletions(-)

diff --git a/SourceCode/Bond/Servo/CPageGlassList.cpp b/SourceCode/Bond/Servo/CPageGlassList.cpp
index 0d0d5c1..3fbf607 100644
--- a/SourceCode/Bond/Servo/CPageGlassList.cpp
+++ b/SourceCode/Bond/Servo/CPageGlassList.cpp
@@ -13,6 +13,7 @@
 #include <unordered_map>
 #include <vector>
 #include <string>
+#include <algorithm>
 #include "CProcessDataListDlg.h"
 
 #define PAGE_SIZE                       50
@@ -22,6 +23,86 @@
 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 璁板綍涓嬫潵
@@ -99,6 +180,9 @@
 
 // ====== 寮�鍏筹細1=鍚敤鍋囨暟鎹紙鍙浛鎹� DB 鏌ヨ锛夛紱0=鐢ㄧ湡瀹� DB ======
 #define USE_FAKE_DB_DEMO 0
+
+// ====== 寮�鍏筹細1=鍚敤妯℃嫙浼犳劅鍣ㄦ暟鎹敓鎴愶紱0=浣跨敤鐪熷疄鏁版嵁 ======
+#define USE_MOCK_SENSOR_DATA 0
 
 #if USE_FAKE_DB_DEMO
 #include <ctime>
@@ -475,6 +559,7 @@
     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()
 
@@ -1084,9 +1169,10 @@
 {
     CDialogEx::OnInitDialog();
 
-    // 瀹氭椂鍣細1=鍒濆鍖栬闃咃紝2=鍛ㄦ湡鍒锋柊锛堝彧澧為噺锛�
+    // 瀹氭椂鍣細1=鍒濆鍖栬闃咃紝2=鍛ㄦ湡鍒锋柊锛堝彧澧為噺锛夛紝3=寤惰繜鍔犺浇棣栧睆鏁版嵁
     SetTimer(1, 3000, nullptr);
     SetTimer(2, 2000, nullptr);
+    SetTimer(3, 10, nullptr);
 
     // 涓嬫媺妗嗘帶浠�
     InitStatusCombo();
@@ -1136,7 +1222,6 @@
     m_listCtrl.SetPopupFullTextColumns({ 11, 12 });
 
     Resize();
-    OnBnClickedButtonSearch(); // 瑙﹀彂涓�娆℃煡璇笌棣栧睆濉厖
 
     return TRUE;  // return TRUE unless you set the focus to a control
 }
@@ -1196,6 +1281,10 @@
     else if (nIDEvent == 2) {
         UpdateWipData();  // 鍙仛澧為噺锛屼笉閲嶅缓
     }
+    else if (nIDEvent == 3) {
+        KillTimer(3);
+        OnBnClickedButtonSearch(); // 寤惰繜棣栧睆鏌ヨ锛岄伩鍏嶅崱浣� OnInitDialog
+    }
 
     CDialogEx::OnTimer(nIDEvent);
 }
@@ -1225,6 +1314,8 @@
 
 void CPageGlassList::OnBnClickedButtonSearch()
 {
+    CWaitCursor wait; // 鏄剧ず绛夊緟鍏夋爣锛屾彁绀烘鍦ㄥ姞杞�
+
     // 鑾峰彇鍏抽敭瀛楄緭鍏ユ鍐呭
     CString strKeyword;
     GetDlgItemText(IDC_EDIT_KEYWORD, strKeyword);
@@ -1334,12 +1425,12 @@
     strSanitizedGlassId.Remove('>');
     strSanitizedGlassId.Remove('|');
 
-    strDefaultFileName.Format(_T("Glass_%s.json"), strSanitizedGlassId);
+    strDefaultFileName.Format(_T("Glass_%s.csv"), strSanitizedGlassId);
 
     // 鏂囦欢淇濆瓨瀵硅瘽妗嗭紝璁剧疆榛樿鏂囦欢鍚�
-    CFileDialog fileDialog(FALSE, _T("json"), strDefaultFileName,
+    CFileDialog fileDialog(FALSE, _T("csv"), strDefaultFileName,
         OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
-        _T("JSON Files (*.json)|*.json|CSV Files (*.csv)|*.csv||"));
+        _T("CSV Files (*.csv)|*.csv|JSON Files (*.json)|*.json||"));
 
     if (fileDialog.DoModal() != IDOK) return;
 
@@ -1347,98 +1438,204 @@
     CString fileExt = fileDialog.GetFileExt();
 
     if (fileExt.CompareNoCase(_T("json")) == 0) {
-        // 淇濆瓨涓� JSON
-        if (!row->pretty.empty()) {
-            CFile file;
-            if (file.Open(filePath, CFile::modeCreate | CFile::modeWrite)) {
-                file.Write(row->pretty.c_str(), row->pretty.length());
-                file.Close();
-
-                CString strSuccess;
-                strSuccess.Format(_T("璁板綍宸蹭繚瀛樹负JSON鏂囦欢锛歕n%s"), filePath);
-                AfxMessageBox(strSuccess);
-            }
-            else {
-                AfxMessageBox(_T("淇濆瓨鏂囦欢澶辫触"));
-            }
-        }
-        else {
-            AfxMessageBox(_T("璇ヨ褰曟病鏈塉SON鏁版嵁"));
-        }
+        ExportToJson(*row, filePath);
     }
     else {
-        // 淇濆瓨涓� CSV 鏍煎紡 - 鍒嗘寮�
-        CString csvContent;
+        ExportToCsv(*row, filePath);
+    }
+}
 
-        // === 绗竴閮ㄥ垎锛氬熀纭�淇℃伅 ===
-        csvContent += _T("=== 鍩虹淇℃伅 ===\n");
-        csvContent += _T("ID,Cassette搴忓垪鍙�,Job搴忓垪鍙�,Glass ID,鐗╂枡绫诲瀷,鐘舵��,寮�濮嬫椂闂�,缁撴潫鏃堕棿,缁戝畾Glass ID,AOI缁撴灉,璺緞\n");
+void CPageGlassList::ExportToJson(const GlassLogDb::Row& row, const CString& filePath)
+{
+    // 淇濆瓨涓� JSON
+    if (!row.pretty.empty()) {
+        CFile file;
+        if (file.Open(filePath, CFile::modeCreate | CFile::modeWrite)) {
+            file.Write(row.pretty.c_str(), (UINT)row.pretty.length());
+            file.Close();
 
-        CString baseInfoRow;
-        baseInfoRow.Format(_T("%lld,%d,%d,%s,%d,%d,%s,%s,%s,%d,%s\n"),
-            row->id, row->cassetteSeqNo, row->jobSeqNo,
-            CString(row->classId.c_str()), row->materialType, row->state,
-            CString(row->tStart.c_str()), CString(row->tEnd.c_str()),
-            CString(row->buddyId.c_str()), row->aoiResult,
-            CString(row->path.c_str()));
-        csvContent += baseInfoRow;
-
-        // === 绗簩閮ㄥ垎锛氬伐鑹哄弬鏁� ===
-        csvContent += _T("\n=== 宸ヨ壓鍙傛暟 ===\n");
-
-        // 濡傛灉鏈� pretty 瀛楁锛岃В鏋愬伐鑹哄弬鏁�
-        if (!row->pretty.empty()) {
-            SERVO::CGlass tempGlass;
-            if (GlassJson::FromString(row->pretty, tempGlass)) {
-                auto& params = tempGlass.getParams();
-                if (!params.empty()) {
-                    // 宸ヨ壓鍙傛暟琛ㄥご - 璋冩暣鍚庣殑鍒�
-                    csvContent += _T("鍙傛暟鍚嶇О,鍙傛暟ID,鏁板��,鏈哄櫒鍗曞厓\n");
-
-                    // 宸ヨ壓鍙傛暟鏁版嵁 - 璋冩暣鍚庣殑鏍煎紡
-                    for (auto& param : params) {
-                        CString paramRow;
-                        CString valueStr;
-
-                        // 鏍规嵁鍙傛暟绫诲瀷鏍煎紡鍖栨暟鍊�
-                        if (param.getValueType() == PVT_INT) {
-                            valueStr.Format(_T("%d"), param.getIntValue());
-                        }
-                        else {
-                            valueStr.Format(_T("%.3f"), param.getDoubleValue());
-                        }
-
-                        // 璋冩暣鍚庣殑鏍煎紡锛氬幓鎺夋暟鍊肩被鍨嬪垪
-                        paramRow.Format(_T("%s,%s,%s,%s\n"),
-                            CString(param.getName().c_str()),
-                            CString(param.getId().c_str()),
-                            valueStr,
-                            CString(param.getUnit().c_str())); // 杩欓噷鏄剧ず鏈哄櫒鍗曞厓
-
-                        csvContent += paramRow;
-                    }
-                }
-                else {
-                    csvContent += _T("鏃犲伐鑹哄弬鏁版暟鎹甛n");
-                }
-            }
-            else {
-                csvContent += _T("鏃犳硶瑙f瀽宸ヨ壓鍙傛暟\n");
-            }
-        }
-        else {
-            csvContent += _T("鏃犲伐鑹哄弬鏁版暟鎹甛n");
-        }
-
-        // 浣跨敤杈呭姪鍑芥暟淇濆瓨涓� UTF-8 缂栫爜
-        if (WriteAnsiStringAsUtf8ToFile(csvContent, filePath)) {
             CString strSuccess;
-            strSuccess.Format(_T("璁板綍宸蹭繚瀛樹负CSV鏂囦欢锛歕n%s"), filePath);
+            strSuccess.Format(_T("璁板綍宸蹭繚瀛樹负JSON鏂囦欢锛歕n%s"), filePath);
             AfxMessageBox(strSuccess);
         }
         else {
             AfxMessageBox(_T("淇濆瓨鏂囦欢澶辫触"));
         }
+    }
+    else {
+        AfxMessageBox(_T("璇ヨ褰曟病鏈塉SON鏁版嵁"));
+    }
+}
+
+void CPageGlassList::ExportToCsv(const GlassLogDb::Row& row, const CString& filePath)
+{
+    CString csvContent;
+
+    // === 绗竴閮ㄥ垎锛氬熀纭�淇℃伅 ===
+    ExportBasicInfo(csvContent, row);
+
+    // === 绗簩閮ㄥ垎锛氬伐鑹哄弬鏁� ===
+    ExportProcessParams(csvContent, row);
+
+    // === 绗笁閮ㄥ垎锛氫紶鎰熷櫒鏁版嵁璇︽儏 ===
+    ExportSensorData(csvContent, row);
+
+    // 浣跨敤杈呭姪鍑芥暟淇濆瓨涓� UTF-8 缂栫爜
+    if (WriteAnsiStringAsUtf8ToFile(csvContent, filePath)) {
+        CString strSuccess;
+        strSuccess.Format(_T("璁板綍宸蹭繚瀛樹负CSV鏂囦欢锛歕n%s"), filePath);
+        AfxMessageBox(strSuccess);
+    }
+    else {
+        AfxMessageBox(_T("淇濆瓨鏂囦欢澶辫触"));
+    }
+}
+
+void CPageGlassList::ExportBasicInfo(CString& csvContent, const GlassLogDb::Row& row)
+{
+    csvContent += _T("=== 鍩虹淇℃伅 ===\n");
+    csvContent += _T("ID,Cassette搴忓垪鍙�,Job搴忓垪鍙�,Glass ID,鐗╂枡绫诲瀷,鐘舵��,寮�濮嬫椂闂�,缁撴潫鏃堕棿,缁戝畾Glass ID,AOI缁撴灉,璺緞\n");
+
+    CString baseInfoRow;
+    baseInfoRow.Format(_T("%lld,%d,%d,%s,%d,%d,%s,%s,%s,%d,%s\n"),
+        row.id, row.cassetteSeqNo, row.jobSeqNo,
+        CString(row.classId.c_str()), row.materialType, row.state,
+        CString(row.tStart.c_str()), CString(row.tEnd.c_str()),
+        CString(row.buddyId.c_str()), row.aoiResult,
+        CString(row.path.c_str()));
+    csvContent += baseInfoRow;
+}
+
+void CPageGlassList::ExportProcessParams(CString& csvContent, const GlassLogDb::Row& row)
+{
+    csvContent += _T("\n=== 宸ヨ壓鍙傛暟 ===\n");
+
+    // 濡傛灉鏈� pretty 瀛楁锛岃В鏋愬伐鑹哄弬鏁�
+    if (!row.pretty.empty()) {
+        SERVO::CGlass tempGlass;
+        if (GlassJson::FromString(row.pretty, tempGlass)) {
+            auto& params = tempGlass.getParams();
+            if (!params.empty()) {
+                // 宸ヨ壓鍙傛暟琛ㄥご
+                csvContent += _T("鍙傛暟鍚嶇О,鍙傛暟ID,鏁板��,鏈哄櫒鍗曞厓\n");
+
+                // 宸ヨ壓鍙傛暟鏁版嵁
+                for (auto& param : params) {
+                    CString paramRow;
+                    CString valueStr;
+
+                    // 鏍规嵁鍙傛暟绫诲瀷鏍煎紡鍖栨暟鍊�
+                    if (param.getValueType() == PVT_INT) {
+                        valueStr.Format(_T("%d"), param.getIntValue());
+                    }
+                    else {
+                        valueStr.Format(_T("%.3f"), param.getDoubleValue());
+                    }
+
+                    paramRow.Format(_T("%s,%s,%s,%s\n"),
+                        CString(param.getName().c_str()),
+                        CString(param.getId().c_str()),
+                        valueStr,
+                        CString(param.getUnit().c_str()));
+
+                    csvContent += paramRow;
+                }
+            }
+            else {
+                csvContent += _T("鏃犲伐鑹哄弬鏁版暟鎹甛n");
+            }
+        }
+        else {
+            csvContent += _T("鏃犳硶瑙f瀽宸ヨ壓鍙傛暟\n");
+        }
+    }
+    else {
+        csvContent += _T("鏃犲伐鑹哄弬鏁版暟鎹甛n");
+    }
+}
+
+void CPageGlassList::ExportSensorData(CString& csvContent, const GlassLogDb::Row& row)
+{
+    csvContent += _T("\n=== 浼犳劅鍣ㄦ暟鎹鎯� ===\n");
+
+    // 濡傛灉鏈� pretty 瀛楁锛岃В鏋愪紶鎰熷櫒鏁版嵁
+    if (!row.pretty.empty()) {
+        SERVO::CGlass tempGlass;
+        if (GlassJson::FromString(row.pretty, tempGlass)) {
+#if USE_MOCK_SENSOR_DATA
+            // 鐢熸垚妯℃嫙鐨凷VData鐢ㄤ簬娴嬭瘯
+            GenerateMockSVData(tempGlass);
+#endif
+            // 瀵规瘡涓満鍣ㄧ敓鎴愯〃鏍�
+            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");
+
+                if (dataByType.empty()) {
+                    csvContent += _T("No sensor data\n");
+                    continue;
+                }
+
+                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 += _T("\n");
+                csvContent += header;
+
+                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 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 = 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");
+                        }
+                    }
+                    row += _T("\n");
+                    csvContent += row;
+                }
+            }
+        }
+        else {
+            csvContent += _T("鏃犳硶瑙f瀽浼犳劅鍣ㄦ暟鎹甛n");
+        }
+    }
+    else {
+        csvContent += _T("鏃犱紶鎰熷櫒鏁版嵁\n");
     }
 }
 
@@ -1462,9 +1659,190 @@
 {
     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锛學IP涓虹┖
+    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锛學IP涓虹┖
+    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;
@@ -1797,4 +2175,151 @@
     }
 
     return CDialogEx::PreTranslateMessage(pMsg);
-}
\ No newline at end of file
+}
+
+// 鑾峰彇鏈哄櫒棰勫畾涔夌殑鍒楅『搴�
+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);
+
+    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;
+}
+
+// 鏃堕棿鎴宠浆鎹负瀛楃涓�
+std::string CPageGlassList::timePointToString(const std::chrono::system_clock::time_point& tp) 
+{
+    auto time_t = std::chrono::system_clock::to_time_t(tp);
+    std::tm tm;
+    localtime_s(&tm, &time_t);
+    char buffer[20];
+    std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &tm);
+    return buffer;
+}
+
+// 鏃堕棿鎴宠浆鎹负姣
+int64_t CPageGlassList::timePointToMs(const std::chrono::system_clock::time_point& tp)
+{
+    return std::chrono::duration_cast<std::chrono::milliseconds>(tp.time_since_epoch()).count();
+}
+
+// 鐢熸垚妯℃嫙鐨凷VData鐢ㄤ簬娴嬭瘯
+void CPageGlassList::GenerateMockSVData(SERVO::CGlass& glass)
+{
+    // 鑾峰彇璁惧鏁版嵁绫诲瀷閰嶇疆
+    auto& dataTypes = SERVO::CServoUtilsTool::getEqDataTypes();
+    
+    // 涓烘瘡涓澶囩敓鎴愭ā鎷熸暟鎹�
+    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 : typeList) {
+            std::vector<SERVO::SVDataItem> mockData;
+            
+            // 鐢熸垚600涓暟鎹偣锛�10鍒嗛挓 * 60涓偣/鍒嗛挓锛�
+            for (int i = 0; i < 600; ++i) {
+                auto timestamp = startTime + std::chrono::seconds(i * 1);
+                
+                // 鏍规嵁璁惧绫诲瀷鍜屾暟鎹被鍨嬬敓鎴愪笉鍚岀殑妯℃嫙鍊�
+                double value = GenerateMockValue(machineId, dataType, i);
+                
+                mockData.emplace_back(timestamp, value);
+            }
+            
+            // 灏嗘ā鎷熸暟鎹坊鍔犲埌glass瀵硅薄涓�
+            glass.addSVData(machineId, dataType, mockData);
+        }
+    }
+}
+
+// 鏍规嵁璁惧绫诲瀷鍜屾暟鎹被鍨嬬敓鎴愭ā鎷熸暟鍊�
+double CPageGlassList::GenerateMockValue(int machineId, const std::string& dataType, int index)
+{
+    // 鍩虹鍊艰寖鍥�
+    double baseValue = 0.0;
+    double variation = 0.0;
+    
+    // 鏍规嵁璁惧绫诲瀷璁剧疆鍩虹鍊�
+    switch (machineId) {
+        case EQ_ID_Bonder1:
+        case EQ_ID_Bonder2:
+            if (dataType.find("鍘嬪姏") != std::string::npos) {
+                baseValue = 50.0;  // 鍘嬪姏鍩虹鍊�
+                variation = 10.0;  // 鍘嬪姏鍙樺寲鑼冨洿
+            } else if (dataType.find("娓╁害") != std::string::npos) {
+                baseValue = 180.0; // 娓╁害鍩虹鍊�
+                variation = 5.0;   // 娓╁害鍙樺寲鑼冨洿
+            } else if (dataType.find("鎵╁睍鍊�") != std::string::npos) {
+                baseValue = 100.0; // 鎵╁睍鍊煎熀纭�鍊�
+                variation = 15.0;  // 鎵╁睍鍊煎彉鍖栬寖鍥�
+            }
+            break;
+            
+        case EQ_ID_VACUUMBAKE:
+            if (dataType.find("鎵╁睍鍊�") != std::string::npos) {
+                baseValue = 80.0;
+                variation = 12.0;
+            } else if (dataType.find("娓╁害") != std::string::npos) {
+                baseValue = 200.0;
+                variation = 8.0;
+            }
+            break;
+            
+        case EQ_ID_BAKE_COOLING:
+            if (dataType.find("娓╁害") != std::string::npos) {
+                baseValue = 25.0;  // 鍐峰嵈娓╁害
+                variation = 3.0;
+            }
+            break;
+            
+        default:
+            baseValue = 50.0;
+            variation = 5.0;
+            break;
+    }
+    
+    // 娣诲姞鏃堕棿鐩稿叧鐨勮秼鍔垮拰闅忔満鍙樺寲
+    double timeTrend = sin(index * 0.1) * 2.0;  // 姝e鸡娉㈣秼鍔�
+    double randomNoise = (rand() % 100 - 50) / 100.0 * variation * 0.3;  // 闅忔満鍣0
+    
+    return baseValue + timeTrend + randomNoise;
+}

--
Gitblit v1.9.3