| | |
| | | #include "CPageGraph1.h" |
| | | #include "afxdialogex.h" |
| | | #include "Common.h" |
| | | #include "CEquipment.h" |
| | | #include "CGlass.h" |
| | | #include "CServoUtilsTool.h" |
| | | |
| | | namespace { |
| | | const UINT kSlotTableId = 60001; |
| | | |
| | | bool ParseHexColor(const char* psz, COLORREF& outColor) |
| | | { |
| | | if (psz == nullptr || *psz == '\0') return false; |
| | | while (*psz == ' ' || *psz == '\t') ++psz; |
| | | if (*psz == '#') ++psz; |
| | | if (psz[0] == '0' && (psz[1] == 'x' || psz[1] == 'X')) psz += 2; |
| | | char* endPtr = nullptr; |
| | | unsigned long value = strtoul(psz, &endPtr, 16); |
| | | if (endPtr == psz) return false; |
| | | BYTE r = (BYTE)((value >> 16) & 0xFF); |
| | | BYTE g = (BYTE)((value >> 8) & 0xFF); |
| | | BYTE b = (BYTE)(value & 0xFF); |
| | | outColor = RGB(r, g, b); |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | const std::map<SERVO::ROBOT_POSITION, RobotPositionMapping> g_positionMap = { |
| | | { SERVO::ROBOT_POSITION::Port1, { SERVO::ROBOT_POSITION::Port1, 1.00f, 0.00f } }, |
| | | { SERVO::ROBOT_POSITION::Port2, { SERVO::ROBOT_POSITION::Port2, 0.90f, 0.00f } }, |
| | | { SERVO::ROBOT_POSITION::Port3, { SERVO::ROBOT_POSITION::Port3, 0.75f, 0.00f } }, |
| | | { SERVO::ROBOT_POSITION::Port4, { SERVO::ROBOT_POSITION::Port4, 0.60f, 0.00f } }, |
| | | { SERVO::ROBOT_POSITION::Aligner, { SERVO::ROBOT_POSITION::Aligner, 0.40f, 0.00f } }, |
| | | { SERVO::ROBOT_POSITION::Fliper, { SERVO::ROBOT_POSITION::Fliper, 0.25f, 0.00f } }, |
| | | { SERVO::ROBOT_POSITION::Bonder1, { SERVO::ROBOT_POSITION::Bonder1, 0.00f, 0.00f } }, |
| | | { SERVO::ROBOT_POSITION::Bonder2, { SERVO::ROBOT_POSITION::Bonder2, 0.00f, 180.00f } }, |
| | | { SERVO::ROBOT_POSITION::Bake, { SERVO::ROBOT_POSITION::Bake, 0.35f, 180.00f } }, |
| | | { SERVO::ROBOT_POSITION::Cooling, { SERVO::ROBOT_POSITION::Cooling, 0.65f, 180.00f } }, |
| | | { SERVO::ROBOT_POSITION::Measurement,{SERVO::ROBOT_POSITION::Measurement,1.00f, 180.00f } }, |
| | | }; |
| | | |
| | | // Image |
| | | #define IMAGE_ROBOT 2 |
| | | #define IMAGE_LEGEND 3 |
| | | |
| | | #define INDICATE_BONDER1 1 |
| | | #define INDICATE_BONDER2 2 |
| | |
| | | #define INDICATE_BAKE_COOLING 12 |
| | | #define INDICATE_MEASUREMENT 13 |
| | | |
| | | // 定时器 |
| | | #define TIMER_ID_DEVICE_STATUS 1 // 用于初始化设备状态 |
| | | #define TIMER_ID_ROBOT_STATUS 2 // 用于周期刷新机器人位置/臂状态 |
| | | #define TIMER_ID_ROBOT_ANIMATION 3 // |
| | | |
| | | // CPageGraph1 对话框 |
| | | |
| | | IMPLEMENT_DYNAMIC(CPageGraph1, CDialogEx) |
| | |
| | | CPageGraph1::CPageGraph1(CWnd* pParent /*=nullptr*/) |
| | | : CDialogEx(IDD_PAGE_GRAPH1, pParent) |
| | | { |
| | | m_pGraph = nullptr; |
| | | m_pObserver = nullptr; |
| | | m_bIsRobotMoving = FALSE; |
| | | m_crBkgnd = PAGE_GRPAH1_BACKGROUND_COLOR; |
| | | m_hbrBkgnd = nullptr; |
| | | // ===== 图形界面相关成员变量初始化 ===== |
| | | m_pGraph = nullptr; // 图形绘图对象 |
| | | m_pObserver = nullptr; // 观察者对象(可能是事件观察者) |
| | | m_crBkgnd = PAGE_GRPAH1_BACKGROUND_COLOR; // 背景颜色 |
| | | m_hbrBkgnd = nullptr; // 背景刷句柄 |
| | | m_slotBarTestMode = 0; // 0=off,1=has,2=processing |
| | | m_pSelectedEquipment = nullptr; |
| | | m_slotTableRowCount = 1; |
| | | m_slotTableRowHeight = 20; |
| | | m_slotTablePadding = 8; |
| | | m_slotTableHeaderHeight = 22; |
| | | m_slotTableTitleHeight = 20; |
| | | |
| | | // ===== 机器人动画状态初始化 ===== |
| | | m_bIsRobotMoving = FALSE; // 当前是否正在动画移动 |
| | | m_nRobotMoveStartX = 0; // 动画起始 X 坐标 |
| | | m_nRobotMoveEndX = 0; // 动画目标 X 坐标 |
| | | m_nRobotMoveSteps = 30; // 动画总步数(动画速度控制) |
| | | m_nRobotMoveCurrentStep = 0; // 当前动画步数 |
| | | m_nRobotMoveStartAngle = 0.0f; // 动画起始角度 |
| | | m_nRobotMoveEndAngle = 0.0f; // 动画目标角度 |
| | | |
| | | // ===== 机器人上一次状态初始化 ===== |
| | | m_lastRobotPosition = SERVO::ROBOT_POSITION::Port1; // 上次机器人位置(默认 Port1) |
| | | m_lastArmState[0] = FALSE; // 上次机械臂1 状态(未占用) |
| | | m_lastArmState[1] = FALSE; // 上次机械臂2 状态(未占用) |
| | | |
| | | // ===== 机械臂相对偏移量初始化(从配置中加载) ===== |
| | | m_arm1Offset = LoadArmOffset("ARM1"); // 加载机械臂1偏移 |
| | | m_arm2Offset = LoadArmOffset("ARM2"); // 加载机械臂2偏移 |
| | | |
| | | //m_arm1Offset = { -30, -45 }; // ARM1 从中心向左47, 向上33 |
| | | //m_arm2Offset = { 27, -45 }; // ARM2 从中心向右10, 向上33 |
| | | } |
| | | |
| | | CPageGraph1::~CPageGraph1() |
| | |
| | | |
| | | // CPageGraph1 消息处理程序 |
| | | |
| | | std::string CPageGraph1::GetConfigPath() |
| | | { |
| | | char path[MAX_PATH]; |
| | | GetModuleFileNameA(NULL, path, MAX_PATH); |
| | | std::string exePath(path); |
| | | std::string configDir = exePath.substr(0, exePath.find_last_of("\\/")) + "\\Config"; |
| | | CreateDirectoryA(configDir.c_str(), NULL); |
| | | return configDir + "\\robot_offset.ini"; |
| | | } |
| | | |
| | | void CPageGraph1::UpdateLegendPosition() |
| | | { |
| | | if (!m_pGraph) return; |
| | | auto* pImage = m_pGraph->GetImage(IMAGE_LEGEND); |
| | | if (!pImage) return; |
| | | |
| | | RECT rc = { 0 }; |
| | | ::GetClientRect(m_pGraph->GetSafeWnd(), &rc); |
| | | std::string iniPath = GetConfigPath(); |
| | | int cfgX = GetPrivateProfileIntA("Graph1", "LegendX", -1, iniPath.c_str()); |
| | | int cfgY = GetPrivateProfileIntA("Graph1", "LegendY", -1, iniPath.c_str()); |
| | | |
| | | int x = (cfgX >= 0) ? cfgX : (rc.right - pImage->bmWidth - 8); |
| | | int y = (cfgY >= 0) ? cfgY : 6; |
| | | if (x < 0) x = 0; |
| | | if (y < 0) y = 0; |
| | | if (x > rc.right - pImage->bmWidth) x = rc.right - pImage->bmWidth; |
| | | if (y > rc.bottom - pImage->bmHeight) y = rc.bottom - pImage->bmHeight; |
| | | m_pGraph->UpdateImageCoordinates(IMAGE_LEGEND, x, y); |
| | | m_pGraph->Invalidata(); |
| | | } |
| | | |
| | | void CPageGraph1::LayoutSlotTable() |
| | | { |
| | | if (GetSafeHwnd() == nullptr) return; |
| | | |
| | | std::string iniPath = GetConfigPath(); |
| | | m_slotTableRowHeight = GetPrivateProfileIntA("Graph1", "SlotTableRowHeight", 20, iniPath.c_str()); |
| | | m_slotTablePadding = GetPrivateProfileIntA("Graph1", "SlotTablePadding", 8, iniPath.c_str()); |
| | | m_slotTableHeaderHeight = GetPrivateProfileIntA("Graph1", "SlotTableHeaderHeight", 22, iniPath.c_str()); |
| | | m_slotTableTitleHeight = GetPrivateProfileIntA("Graph1", "SlotTableTitleHeight", 20, iniPath.c_str()); |
| | | char colorBuf[32] = { 0 }; |
| | | COLORREF lineColor = RGB(230, 230, 230); |
| | | COLORREF headerBgColor = RGB(245, 245, 245); |
| | | GetPrivateProfileStringA("Graph1", "SlotTableLineColor", "", colorBuf, sizeof(colorBuf), iniPath.c_str()); |
| | | if (!ParseHexColor(colorBuf, lineColor)) { |
| | | lineColor = RGB(230, 230, 230); |
| | | } |
| | | GetPrivateProfileStringA("Graph1", "SlotTableHeaderBgColor", "", colorBuf, sizeof(colorBuf), iniPath.c_str()); |
| | | if (!ParseHexColor(colorBuf, headerBgColor)) { |
| | | headerBgColor = RGB(245, 245, 245); |
| | | } |
| | | if (m_slotTableRowHeight < 14) m_slotTableRowHeight = 14; |
| | | if (m_slotTableRowHeight > 40) m_slotTableRowHeight = 40; |
| | | if (m_slotTablePadding < 2) m_slotTablePadding = 2; |
| | | if (m_slotTablePadding > 16) m_slotTablePadding = 16; |
| | | if (m_slotTableHeaderHeight < 16) m_slotTableHeaderHeight = 16; |
| | | if (m_slotTableHeaderHeight > 40) m_slotTableHeaderHeight = 40; |
| | | if (m_slotTableTitleHeight < 16) m_slotTableTitleHeight = 16; |
| | | if (m_slotTableTitleHeight > 40) m_slotTableTitleHeight = 40; |
| | | int cfgX = GetPrivateProfileIntA("Graph1", "SlotTableX", -1, iniPath.c_str()); |
| | | int cfgY = GetPrivateProfileIntA("Graph1", "SlotTableY", -1, iniPath.c_str()); |
| | | |
| | | CRect rcClient; |
| | | GetClientRect(&rcClient); |
| | | |
| | | int cfgW = max(160, rcClient.Width() / 3); |
| | | if (cfgW > 280) cfgW = 280; |
| | | |
| | | const int titleHeight = m_slotTableTitleHeight; |
| | | const int headerHeight = m_slotTableHeaderHeight; |
| | | const int rowHeight = m_slotTableRowHeight; |
| | | int rows = m_slotTableRowCount; |
| | | if (rows < 1) rows = 1; |
| | | if (rows > 8) rows = 8; |
| | | int cfgH = titleHeight + headerHeight + rowHeight * rows + 6; |
| | | |
| | | if (cfgW > rcClient.Width() - 6) cfgW = max(160, rcClient.Width() - 6); |
| | | if (cfgH > rcClient.Height() - 6) cfgH = max(80, rcClient.Height() - 6); |
| | | |
| | | int x = (cfgX >= 0) ? cfgX : (rcClient.right - cfgW - 6); |
| | | int y = (cfgY >= 0) ? cfgY : 12; |
| | | |
| | | if (x < 0) x = 0; |
| | | if (y < 0) y = 0; |
| | | // if (x + cfgW > rcClient.right) x = max(0, rcClient.right - cfgW); |
| | | // if (y + cfgH > rcClient.bottom) y = max(0, rcClient.bottom - cfgH); |
| | | |
| | | CRect rcTable(x, y, x + cfgW, y + cfgH); |
| | | if (m_slotTable.GetSafeHwnd() == nullptr) { |
| | | BOOL created = m_slotTable.Create(this, rcTable, kSlotTableId); |
| | | m_slotTable.SetTitle(_T("Slot Info")); |
| | | m_slotTable.SetRowHeight(m_slotTableRowHeight); |
| | | m_slotTable.SetPadding(m_slotTablePadding); |
| | | m_slotTable.SetHeaderHeight(m_slotTableHeaderHeight); |
| | | m_slotTable.SetTitleHeight(m_slotTableTitleHeight); |
| | | m_slotTable.SetLineColor(lineColor); |
| | | m_slotTable.SetHeaderBgColor(headerBgColor); |
| | | (void)created; |
| | | } |
| | | else { |
| | | m_slotTable.MoveWindow(&rcTable); |
| | | m_slotTable.SetRowHeight(m_slotTableRowHeight); |
| | | m_slotTable.SetPadding(m_slotTablePadding); |
| | | m_slotTable.SetHeaderHeight(m_slotTableHeaderHeight); |
| | | m_slotTable.SetTitleHeight(m_slotTableTitleHeight); |
| | | m_slotTable.SetLineColor(lineColor); |
| | | m_slotTable.SetHeaderBgColor(headerBgColor); |
| | | } |
| | | |
| | | // 如果超出可视区域,强制移到左上角作为兜底 |
| | | CRect rcWnd; |
| | | m_slotTable.GetWindowRect(&rcWnd); |
| | | ScreenToClient(&rcWnd); |
| | | if (rcWnd.right <= 0 || rcWnd.bottom <= 0 || |
| | | rcWnd.left >= rcClient.right || rcWnd.top >= rcClient.bottom) { |
| | | CRect rcFallback(10, 10, 10 + cfgW, 10 + cfgH); |
| | | m_slotTable.MoveWindow(&rcFallback); |
| | | } |
| | | m_slotTable.SetWindowPos(&CWnd::wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); |
| | | |
| | | if (auto* pGraphWnd = GetDlgItem(IDC_SERVO_GRAPH1)) { |
| | | pGraphWnd->SetWindowPos(&CWnd::wndBottom, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); |
| | | } |
| | | m_slotTable.BringWindowToTop(); |
| | | } |
| | | |
| | | void CPageGraph1::UpdateSlotTable(SERVO::CEquipment* pEquipment) |
| | | { |
| | | if (m_slotTable.GetSafeHwnd() == nullptr) return; |
| | | |
| | | std::vector<CSlotTableCtrl::Row> rows; |
| | | if (pEquipment != nullptr) { |
| | | for (int i = 0; i < SLOT_MAX && rows.size() < 8; ++i) { |
| | | SERVO::CSlot* pSlot = pEquipment->getSlot(i); |
| | | if (pSlot == nullptr || !pSlot->isEnable()) continue; |
| | | |
| | | CSlotTableCtrl::Row row; |
| | | row.slot.Format(_T("%d"), pSlot->getNo()); |
| | | |
| | | CContext* pCtx = pSlot->getContext(); |
| | | if (pCtx == nullptr) { |
| | | pCtx = pSlot->getTempContext(); |
| | | } |
| | | SERVO::CGlass* pGlass = dynamic_cast<SERVO::CGlass*>(pCtx); |
| | | if (pGlass != nullptr) { |
| | | row.glassId = pGlass->getID().c_str(); |
| | | row.type = SERVO::CServoUtilsTool::getMaterialsTypeText(pGlass->getType()).c_str(); |
| | | } |
| | | |
| | | rows.push_back(row); |
| | | } |
| | | } |
| | | |
| | | m_slotTableRowCount = static_cast<int>(rows.size()); |
| | | if (m_slotTableRowCount < 1) m_slotTableRowCount = 1; |
| | | if (m_slotTableRowCount > 8) m_slotTableRowCount = 8; |
| | | LayoutSlotTable(); |
| | | |
| | | if (pEquipment != nullptr) { |
| | | m_slotTable.SetTitle(CString(pEquipment->getName().c_str())); |
| | | } |
| | | else { |
| | | m_slotTable.SetTitle(_T("Slot Info")); |
| | | } |
| | | m_slotTable.SetRows(rows); |
| | | } |
| | | |
| | | void CPageGraph1::InitRxWindows() |
| | | { |
| | |
| | | BOOL bAlive = pEquipment->isAlive(); |
| | | if (EQ_ID_EFEM == nID) { |
| | | DeviceStatus status = bAlive ? DeviceStatus::ONLINE : DeviceStatus::OFFLINE; |
| | | UpdateDeviceStatus(INDICATE_FLIPER, status); |
| | | UpdateDeviceStatus(INDICATE_ALIGNER, status); |
| | | UpdateDeviceStatus(INDICATE_LPORT1, status); |
| | | UpdateDeviceStatus(INDICATE_LPORT2, status); |
| | | UpdateDeviceStatus(INDICATE_LPORT3, status); |
| | | UpdateDeviceStatus(INDICATE_LPORT4, status); |
| | | UpdateDeviceStatus(INDICATE_ROBOT_ARM1, status); |
| | | UpdateDeviceStatus(INDICATE_ROBOT_ARM2, status); |
| | | } |
| | |
| | | DeviceStatus status = bAlive ? DeviceStatus::ONLINE : DeviceStatus::OFFLINE; |
| | | UpdateDeviceStatus(INDICATE_BONDER2, status); |
| | | } |
| | | else if (EQ_ID_VACUUMBAKE == nID) { |
| | | DeviceStatus status = bAlive ? DeviceStatus::ONLINE : DeviceStatus::OFFLINE; |
| | | UpdateDeviceStatus(INDICATE_VACUUM_BAKE, status); |
| | | } |
| | | else if (EQ_ID_BAKE_COOLING == nID) { |
| | | DeviceStatus status = bAlive ? DeviceStatus::ONLINE : DeviceStatus::OFFLINE; |
| | | UpdateDeviceStatus(INDICATE_BAKE_COOLING, status); |
| | | } |
| | | else if (EQ_ID_MEASUREMENT == nID) { |
| | | DeviceStatus status = bAlive ? DeviceStatus::ONLINE : DeviceStatus::OFFLINE; |
| | | UpdateDeviceStatus(INDICATE_MEASUREMENT, status); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else if (RX_CODE_EQ_DATA_CHANGED == code |
| | | || RX_CODE_LOADPORT_STATUS_CHANGED == code) { |
| | | // 设备数据变化时,及时刷新格子与右侧Slot表,避免只在点击时更新一次 |
| | | UpdateSlotBars(); |
| | | if (m_pSelectedEquipment != nullptr) { |
| | | UpdateSlotTable(m_pSelectedEquipment); |
| | | } |
| | | } |
| | | |
| | |
| | | BOOL CPageGraph1::OnInitDialog() |
| | | { |
| | | CDialogEx::OnInitDialog(); |
| | | SetTimer(1, 3000, nullptr); |
| | | |
| | | ModifyStyle(0, WS_CLIPCHILDREN | WS_CLIPSIBLINGS); |
| | | InitRxWindows(); |
| | | SetTimer(TIMER_ID_DEVICE_STATUS, 800, nullptr); |
| | | SetTimer(TIMER_ID_ROBOT_STATUS, 1000, nullptr); // 每 1000ms 更新一次状态 |
| | | |
| | | // 图示 |
| | | m_pGraph = CServoGraph::Hook(GetDlgItem(IDC_SERVO_GRAPH1)->GetSafeHwnd()); |
| | | if (auto* pGraphWnd = GetDlgItem(IDC_SERVO_GRAPH1)) { |
| | | pGraphWnd->ModifyStyle(0, WS_CLIPSIBLINGS); |
| | | } |
| | | std::string iniPath = GetConfigPath(); |
| | | CString strPath; |
| | | strPath.Format(_T("%s\\res\\Servo001.bmp"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir); |
| | | auto resolveGraphImagePath = [&](const char* iniKey, const char* defaultName) -> CString { |
| | | char value[MAX_PATH] = { 0 }; |
| | | GetPrivateProfileStringA("Graph1", iniKey, defaultName, value, (DWORD)sizeof(value), iniPath.c_str()); |
| | | std::string file = value; |
| | | auto trim = [](std::string& s) { |
| | | while (!s.empty() && (s.front() == ' ' || s.front() == '\t' || s.front() == '\r' || s.front() == '\n')) s.erase(s.begin()); |
| | | while (!s.empty() && (s.back() == ' ' || s.back() == '\t' || s.back() == '\r' || s.back() == '\n')) s.pop_back(); |
| | | }; |
| | | trim(file); |
| | | if (file.empty()) file = defaultName; |
| | | |
| | | CString path; |
| | | const bool isAbs = (file.size() > 1 && file[1] == ':') || (!file.empty() && (file[0] == '\\' || file[0] == '/')); |
| | | if (isAbs) { |
| | | path = file.c_str(); |
| | | } |
| | | else if (file.rfind("res\\", 0) == 0 || file.rfind("res/", 0) == 0) { |
| | | path.Format(_T("%s\\%s"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir, CString(file.c_str())); |
| | | } |
| | | else { |
| | | path.Format(_T("%s\\res\\%s"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir, CString(file.c_str())); |
| | | } |
| | | |
| | | DWORD attr = GetFileAttributes(path); |
| | | if (attr == INVALID_FILE_ATTRIBUTES || (attr & FILE_ATTRIBUTE_DIRECTORY)) { |
| | | path.Format(_T("%s\\res\\%s"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir, CString(defaultName)); |
| | | } |
| | | return path; |
| | | }; |
| | | |
| | | strPath = resolveGraphImagePath("BackgroundBmp", "Servo001.bmp"); |
| | | m_pGraph->AddImage(1, (LPTSTR)(LPCTSTR)strPath, 0, 0); |
| | | |
| | | strPath.Format(_T("%s\\res\\Robot001.bmp"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir); |
| | | m_pGraph->AddImage(IMAGE_ROBOT, (LPTSTR)(LPCTSTR)strPath, 170, 270); |
| | | |
| | | // Legend |
| | | strPath.Format(_T("%s\\res\\GraphLegend.bmp"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir); |
| | | m_pGraph->AddImage(IMAGE_LEGEND, (LPTSTR)(LPCTSTR)strPath, 0, 0); |
| | | UpdateLegendPosition(); |
| | | LayoutSlotTable(); |
| | | m_slotTable.ShowWindow(SW_SHOW); |
| | | |
| | | // 添加指示器 |
| | | // Bonder |
| | | m_pGraph->AddIndicateBox(INDICATE_BONDER1, 220, 172, 48, RGB(22, 22, 22), |
| | | // size config |
| | | int boxSize = GetPrivateProfileIntA("Graph1", "BoxSize", 56, iniPath.c_str()); |
| | | if (boxSize < 40) boxSize = 40; |
| | | if (boxSize > 80) boxSize = 80; |
| | | int slotSizeDefault = GetPrivateProfileIntA("Graph1", "SlotSize", 6, iniPath.c_str()); |
| | | int slotSize8 = GetPrivateProfileIntA("Graph1", "SlotSize8", slotSizeDefault, iniPath.c_str()); |
| | | int slotSizeOther = GetPrivateProfileIntA("Graph1", "SlotSizeOther", slotSizeDefault, iniPath.c_str()); |
| | | if (slotSize8 < 2) slotSize8 = 2; |
| | | if (slotSize8 > 12) slotSize8 = 12; |
| | | if (slotSizeOther < 2) slotSizeOther = 2; |
| | | if (slotSizeOther > 12) slotSizeOther = 12; |
| | | m_pGraph->SetSlotBarSizeByCount(slotSize8, slotSizeOther); |
| | | int armBoxSize = GetPrivateProfileIntA("Graph1", "ArmBoxSize", boxSize, iniPath.c_str()); |
| | | if (armBoxSize < 30) armBoxSize = 30; |
| | | if (armBoxSize > 80) armBoxSize = 80; |
| | | |
| | | // ArmSpacing = edge-to-edge gap between the two robot arm boxes. |
| | | int armGap = GetPrivateProfileIntA("Graph1", "ArmSpacing", 6, iniPath.c_str()); |
| | | if (armGap < 0) armGap = 0; |
| | | if (armGap > 100) armGap = 100; |
| | | |
| | | int arm1X = 190; |
| | | int arm2X = 243; |
| | | int armY = 294; |
| | | int minArmSpacing = armBoxSize + armGap; |
| | | if (minArmSpacing > 0) { |
| | | int mid = (m_arm1Offset.x + m_arm2Offset.x) / 2; |
| | | int half = minArmSpacing / 2; |
| | | if (m_arm1Offset.x <= m_arm2Offset.x) { |
| | | m_arm1Offset.x = mid - half; |
| | | m_arm2Offset.x = mid + half; |
| | | } else { |
| | | m_arm2Offset.x = mid - half; |
| | | m_arm1Offset.x = mid + half; |
| | | } |
| | | } |
| | | { |
| | | int baseMid = (arm1X + arm2X) / 2; |
| | | int half = minArmSpacing / 2; |
| | | arm1X = baseMid - half; |
| | | arm2X = baseMid + half; |
| | | } |
| | | |
| | | auto readGraphPoint = [&](const char* keyPrefix, int defaultX, int defaultY) -> POINT { |
| | | std::string keyX = std::string(keyPrefix) + "_X"; |
| | | std::string keyY = std::string(keyPrefix) + "_Y"; |
| | | POINT pt = { 0 }; |
| | | pt.x = GetPrivateProfileIntA("Graph1", keyX.c_str(), defaultX, iniPath.c_str()); |
| | | pt.y = GetPrivateProfileIntA("Graph1", keyY.c_str(), defaultY, iniPath.c_str()); |
| | | return pt; |
| | | }; |
| | | |
| | | const POINT ptBonder1 = readGraphPoint("Bonder1", 220, 172); |
| | | const POINT ptBonder2 = readGraphPoint("Bonder2", 220, 516); |
| | | const POINT ptFliper = readGraphPoint("Fliper", 338, 172); |
| | | const POINT ptAligner = readGraphPoint("Aligner", 428, 172); |
| | | const POINT ptLoadPort4 = readGraphPoint("LoadPort4", 518, 172); |
| | | const POINT ptLoadPort3 = readGraphPoint("LoadPort3", 606, 172); |
| | | const POINT ptLoadPort2 = readGraphPoint("LoadPort2", 690, 172); |
| | | const POINT ptLoadPort1 = readGraphPoint("LoadPort1", 774, 172); |
| | | const POINT ptRobotArm1 = readGraphPoint("RobotArm1", arm1X, armY); |
| | | const POINT ptRobotArm2 = readGraphPoint("RobotArm2", arm2X, armY); |
| | | const POINT ptVacuumBake = readGraphPoint("VacuumBake", 396, 516); |
| | | const POINT ptBakeCooling = readGraphPoint("BakeCooling", 566, 516); |
| | | const POINT ptMeasurement = readGraphPoint("Measurement", 737, 516); |
| | | |
| | | m_pGraph->AddIndicateBox(INDICATE_BONDER1, ptBonder1.x, ptBonder1.y, boxSize, RGB(22, 22, 22), |
| | | RGB(255, 127, 39), EQ_BOX_OFFLINE); |
| | | m_pGraph->SetBoxText(INDICATE_BONDER1, "10", "Bonder 1"); |
| | | m_pGraph->AddIndicateBox(INDICATE_BONDER2, 220, 516, 48, RGB(22, 22, 22), |
| | | m_pGraph->SetBoxText(INDICATE_BONDER1, "", "Bonder 1"); |
| | | m_pGraph->AddIndicateBox(INDICATE_BONDER2, ptBonder2.x, ptBonder2.y, boxSize, RGB(22, 22, 22), |
| | | RGB(255, 127, 39), EQ_BOX_OFFLINE); |
| | | m_pGraph->SetBoxText(INDICATE_BONDER2, "11", "Bonder 2"); |
| | | m_pGraph->SetBoxText(INDICATE_BONDER2, "", "Bonder 2"); |
| | | |
| | | |
| | | // 翻转 |
| | | m_pGraph->AddIndicateBox(INDICATE_FLIPER, 338, 172, 48, RGB(22, 22, 22), |
| | | m_pGraph->AddIndicateBox(INDICATE_FLIPER, ptFliper.x, ptFliper.y, boxSize, RGB(22, 22, 22), |
| | | RGB(255, 127, 39), EQ_BOX_OFFLINE); |
| | | m_pGraph->SetBoxText(INDICATE_FLIPER, "8", "Fliper"); |
| | | m_pGraph->SetBoxText(INDICATE_FLIPER, "", "Fliper"); |
| | | |
| | | |
| | | // 对位 |
| | | m_pGraph->AddIndicateBox(INDICATE_ALIGNER, 428, 172, 48, RGB(22, 22, 22), |
| | | m_pGraph->AddIndicateBox(INDICATE_ALIGNER, ptAligner.x, ptAligner.y, boxSize, RGB(22, 22, 22), |
| | | RGB(255, 127, 39), EQ_BOX_OFFLINE); |
| | | m_pGraph->SetBoxText(INDICATE_ALIGNER, "7", "Aligner"); |
| | | m_pGraph->SetBoxText(INDICATE_ALIGNER, "", "Aligner"); |
| | | |
| | | |
| | | // Load port 4 |
| | | m_pGraph->AddIndicateBox(INDICATE_LPORT4, 518, 172, 48, RGB(22, 22, 22), |
| | | m_pGraph->AddIndicateBox(INDICATE_LPORT4, ptLoadPort4.x, ptLoadPort4.y, boxSize, RGB(22, 22, 22), |
| | | RGB(255, 127, 39), EQ_BOX_OFFLINE); |
| | | m_pGraph->SetBoxText(INDICATE_LPORT4, "4", "LPort4"); |
| | | m_pGraph->SetBoxText(INDICATE_LPORT4, "", "LPort4"); |
| | | |
| | | |
| | | // Load port 3 |
| | | m_pGraph->AddIndicateBox(INDICATE_LPORT3, 606, 172, 48, RGB(22, 22, 22), |
| | | m_pGraph->AddIndicateBox(INDICATE_LPORT3, ptLoadPort3.x, ptLoadPort3.y, boxSize, RGB(22, 22, 22), |
| | | RGB(255, 127, 39), EQ_BOX_OFFLINE); |
| | | m_pGraph->SetBoxText(INDICATE_LPORT3, "3", "LPort3"); |
| | | m_pGraph->SetBoxText(INDICATE_LPORT3, "", "LPort3"); |
| | | |
| | | |
| | | // Load port 2 |
| | | m_pGraph->AddIndicateBox(INDICATE_LPORT2, 690, 172, 48, RGB(22, 22, 22), |
| | | m_pGraph->AddIndicateBox(INDICATE_LPORT2, ptLoadPort2.x, ptLoadPort2.y, boxSize, RGB(22, 22, 22), |
| | | RGB(255, 127, 39), EQ_BOX_OFFLINE); |
| | | m_pGraph->SetBoxText(INDICATE_LPORT2, "2", "LPort2"); |
| | | m_pGraph->SetBoxText(INDICATE_LPORT2, "", "LPort2"); |
| | | |
| | | |
| | | // Load port 1 |
| | | m_pGraph->AddIndicateBox(INDICATE_LPORT1, 774, 172, 48, RGB(22, 22, 22), |
| | | m_pGraph->AddIndicateBox(INDICATE_LPORT1, ptLoadPort1.x, ptLoadPort1.y, boxSize, RGB(22, 22, 22), |
| | | RGB(255, 127, 39), EQ_BOX_OFFLINE); |
| | | m_pGraph->SetBoxText(INDICATE_LPORT1, "1", "LPort1"); |
| | | m_pGraph->SetBoxText(INDICATE_LPORT1, "", "LPort1"); |
| | | |
| | | |
| | | // Robot |
| | | m_pGraph->AddIndicateBox(INDICATE_ROBOT_ARM1, 190, 294, 48, RGB(22, 22, 22), |
| | | m_pGraph->AddIndicateBox(INDICATE_ROBOT_ARM1, ptRobotArm1.x, ptRobotArm1.y, armBoxSize, RGB(22, 22, 22), |
| | | RGB(255, 127, 39), EQ_BOX_OFFLINE); |
| | | m_pGraph->SetBoxText(INDICATE_ROBOT_ARM1, "5", "Robot"); |
| | | m_pGraph->AddIndicateBox(INDICATE_ROBOT_ARM2, 243, 294, 48, RGB(22, 22, 22), |
| | | m_pGraph->SetBoxText(INDICATE_ROBOT_ARM1, "", "Robot"); |
| | | m_pGraph->AddIndicateBox(INDICATE_ROBOT_ARM2, ptRobotArm2.x, ptRobotArm2.y, armBoxSize, RGB(22, 22, 22), |
| | | RGB(255, 127, 39), EQ_BOX_OFFLINE); |
| | | m_pGraph->SetBoxText(INDICATE_ROBOT_ARM2, "6", "Robot"); |
| | | m_pGraph->SetBoxText(INDICATE_ROBOT_ARM2, "", "Robot"); |
| | | |
| | | |
| | | // Vacuum bake |
| | | m_pGraph->AddIndicateBox(INDICATE_VACUUM_BAKE, 396, 516, 48, RGB(22, 22, 22), |
| | | m_pGraph->AddIndicateBox(INDICATE_VACUUM_BAKE, ptVacuumBake.x, ptVacuumBake.y, boxSize, RGB(22, 22, 22), |
| | | RGB(255, 127, 39), EQ_BOX_OFFLINE); |
| | | m_pGraph->SetBoxText(INDICATE_VACUUM_BAKE, "9", "Vacuum bake"); |
| | | m_pGraph->SetBoxText(INDICATE_VACUUM_BAKE, "", "Vacuum bake"); |
| | | |
| | | |
| | | // Bake cooling |
| | | m_pGraph->AddIndicateBox(INDICATE_BAKE_COOLING, 566, 516, 48, RGB(22, 22, 22), |
| | | m_pGraph->AddIndicateBox(INDICATE_BAKE_COOLING, ptBakeCooling.x, ptBakeCooling.y, boxSize, RGB(22, 22, 22), |
| | | RGB(255, 127, 39), EQ_BOX_OFFLINE); |
| | | m_pGraph->SetBoxText(INDICATE_BAKE_COOLING, "12", "Bake cooling"); |
| | | m_pGraph->SetBoxText(INDICATE_BAKE_COOLING, "", "Bake cooling"); |
| | | |
| | | |
| | | // 精度检 |
| | | m_pGraph->AddIndicateBox(INDICATE_MEASUREMENT, 737, 516, 48, RGB(22, 22, 22), |
| | | m_pGraph->AddIndicateBox(INDICATE_MEASUREMENT, ptMeasurement.x, ptMeasurement.y, boxSize, RGB(22, 22, 22), |
| | | RGB(255, 127, 39), EQ_BOX_OFFLINE); |
| | | m_pGraph->SetBoxText(INDICATE_MEASUREMENT, "13", "Measurement"); |
| | | m_pGraph->SetBoxText(INDICATE_MEASUREMENT, "", "Measurement"); |
| | | |
| | | // slot bar positions (top row / bottom row) |
| | | m_pGraph->SetIndicateBoxSlotBarPosition(INDICATE_BONDER1, SlotBarPos::Top); |
| | | m_pGraph->SetIndicateBoxSlotBarPosition(INDICATE_FLIPER, SlotBarPos::Top); |
| | | m_pGraph->SetIndicateBoxSlotBarPosition(INDICATE_ALIGNER, SlotBarPos::Top); |
| | | m_pGraph->SetIndicateBoxSlotBarPosition(INDICATE_LPORT4, SlotBarPos::Top); |
| | | m_pGraph->SetIndicateBoxSlotBarPosition(INDICATE_LPORT3, SlotBarPos::Top); |
| | | m_pGraph->SetIndicateBoxSlotBarPosition(INDICATE_LPORT2, SlotBarPos::Top); |
| | | m_pGraph->SetIndicateBoxSlotBarPosition(INDICATE_LPORT1, SlotBarPos::Top); |
| | | |
| | | // 绑定数据 |
| | | { |
| | | SERVO::CEquipment* pEquipment = theApp.m_model.m_master.getEquipment(EQ_ID_EFEM); |
| | | m_pGraph->SetIndicateBoxData(INDICATE_ROBOT_ARM1, pEquipment); |
| | | } |
| | | m_pGraph->SetIndicateBoxSlotBarPosition(INDICATE_BONDER2, SlotBarPos::Bottom); |
| | | m_pGraph->SetIndicateBoxSlotBarPosition(INDICATE_VACUUM_BAKE, SlotBarPos::Bottom); |
| | | m_pGraph->SetIndicateBoxSlotBarPosition(INDICATE_BAKE_COOLING, SlotBarPos::Bottom); |
| | | m_pGraph->SetIndicateBoxSlotBarPosition(INDICATE_MEASUREMENT, SlotBarPos::Bottom); |
| | | |
| | | UpdateSlotBars(); |
| | | |
| | | return TRUE; // return TRUE unless you set the focus to a control |
| | | // 异常: OCX 属性页应返回 FALSE |
| | |
| | | newFrameColor2 = EQ_BOX_FRAME2; |
| | | break; |
| | | case OFFLINE: |
| | | newBackgroundColor = RGB(222, 222, 222); |
| | | newBackgroundColor = EQ_BOX_OFFLINE; |
| | | newFrameColor1 = EQ_BOX_FRAME1; |
| | | newFrameColor2 = EQ_BOX_FRAME2; |
| | | break; |
| | | case OCCUPIED: |
| | | newBackgroundColor = EQ_BOX_OCCUPIED; |
| | | newFrameColor1 = EQ_BOX_FRAME1; |
| | | newFrameColor2 = EQ_BOX_FRAME2; |
| | | break; |
| | |
| | | { |
| | | CDialogEx::OnDestroy(); |
| | | |
| | | KillTimer(TIMER_ID_ROBOT_STATUS); |
| | | |
| | | if (m_hbrBkgnd != nullptr) { |
| | | ::DeleteObject(m_hbrBkgnd); |
| | | } |
| | | |
| | | if (m_pObserver != nullptr) { |
| | | m_pObserver->unsubscribe(); |
| | | m_pObserver = NULL; |
| | | } |
| | | |
| | | SaveArmOffset("ARM1", m_arm1Offset); |
| | | SaveArmOffset("ARM2", m_arm2Offset); |
| | | } |
| | | |
| | | void CPageGraph1::OnSize(UINT nType, int cx, int cy) |
| | |
| | | CRect rcClient; |
| | | GetClientRect(&rcClient); |
| | | GetDlgItem(IDC_SERVO_GRAPH1)->MoveWindow(0, 0, rcClient.Width(), rcClient.Height()); |
| | | UpdateLegendPosition(); |
| | | LayoutSlotTable(); |
| | | m_slotTable.ShowWindow(SW_SHOW); |
| | | } |
| | | |
| | | void CPageGraph1::UpdateRobotPosition(float percentage) |
| | | { |
| | | // 限制百分比范围在 [0, 1] 之间 |
| | | if (percentage < 0.0f) percentage = 0.0f; |
| | | if (percentage > 1.0f) percentage = 1.0f; |
| | | |
| | | // 根据百分比计算目标 X 坐标 |
| | | int startX = m_pGraph->GetImage(IMAGE_ROBOT)->x; |
| | | auto* pImage = m_pGraph->GetImage(IMAGE_ROBOT); |
| | | if (!pImage) return; |
| | | |
| | | // 获取当前角度(已通过 RotateRobot 设置) |
| | | float angleDegrees = pImage->angle; |
| | | float radians = angleDegrees * 3.1415926f / 180.0f; |
| | | |
| | | int startX = pImage->x; |
| | | int endX = static_cast<int>(170 + percentage * (700 - 170)); |
| | | int y = 270; |
| | | int cy = y + pImage->bmHeight / 2; |
| | | |
| | | int arm1Offset = 20; // 从图片到ARM1的偏移 |
| | | int arm2Offset = 73; // 从图片到ARM2的偏移 |
| | | |
| | | // 计算移动所需的时间 |
| | | // 动画时间 |
| | | int distance = abs(endX - startX); |
| | | int duration = static_cast<int>((distance / 100.0) * 1000); |
| | | |
| | | int duration = static_cast<int>((distance / 100.0f) * 1000); |
| | | auto startTime = std::chrono::steady_clock::now(); |
| | | auto endTime = startTime + std::chrono::milliseconds(duration); |
| | | |
| | | // 开始移动,设置标记 |
| | | m_bIsRobotMoving = TRUE; |
| | | |
| | | // 开始平滑移动 |
| | | while (std::chrono::steady_clock::now() < endTime) { |
| | | auto currentTime = std::chrono::steady_clock::now(); |
| | | float progress = std::chrono::duration<float, std::milli>(currentTime - startTime).count() / duration; |
| | | progress = min(progress, 1.0f); |
| | | |
| | | // 根据进度计算当前位置 |
| | | int currentX = static_cast<int>(startX + progress * (endX - startX)); |
| | | m_pGraph->UpdateImageCoordinates(IMAGE_ROBOT, currentX, 270); |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM1, currentX + arm1Offset, 294); |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM2, currentX + arm2Offset, 294); |
| | | int cx = currentX + pImage->bmWidth / 2; |
| | | |
| | | // 刷新界面 |
| | | // 旋转后的偏移 |
| | | int rotatedX1 = static_cast<int>(cos(radians) * m_arm1Offset.x - sin(radians) * m_arm1Offset.y); |
| | | int rotatedY1 = static_cast<int>(sin(radians) * m_arm1Offset.x + cos(radians) * m_arm1Offset.y); |
| | | int rotatedX2 = static_cast<int>(cos(radians) * m_arm2Offset.x - sin(radians) * m_arm2Offset.y); |
| | | int rotatedY2 = static_cast<int>(sin(radians) * m_arm2Offset.x + cos(radians) * m_arm2Offset.y); |
| | | |
| | | // 应用所有元素的新坐标 |
| | | m_pGraph->UpdateImageCoordinates(IMAGE_ROBOT, currentX, y); |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM1, cx + rotatedX1, cy + rotatedY1); |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM2, cx + rotatedX2, cy + rotatedY2); |
| | | |
| | | Invalidate(); |
| | | UpdateWindow(); |
| | | |
| | | // 控制帧率约为 60 FPS |
| | | std::this_thread::sleep_for(std::chrono::milliseconds(16)); |
| | | } |
| | | |
| | | // 确保最后位置精确到目标位置 |
| | | m_pGraph->UpdateImageCoordinates(IMAGE_ROBOT, endX, 270); |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM1, endX + arm1Offset, 294); |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM2, endX + arm2Offset, 294); |
| | | // 最终位置校正 |
| | | int cx = endX + pImage->bmWidth / 2; |
| | | int rotatedX1 = static_cast<int>(cos(radians) * m_arm1Offset.x - sin(radians) * m_arm1Offset.y); |
| | | int rotatedY1 = static_cast<int>(sin(radians) * m_arm1Offset.x + cos(radians) * m_arm1Offset.y); |
| | | int rotatedX2 = static_cast<int>(cos(radians) * m_arm2Offset.x - sin(radians) * m_arm2Offset.y); |
| | | int rotatedY2 = static_cast<int>(sin(radians) * m_arm2Offset.x + cos(radians) * m_arm2Offset.y); |
| | | |
| | | // 界面重绘 |
| | | m_pGraph->UpdateImageCoordinates(IMAGE_ROBOT, endX, y); |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM1, cx + rotatedX1, cy + rotatedY1); |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM2, cx + rotatedX2, cy + rotatedY2); |
| | | |
| | | Invalidate(); |
| | | |
| | | // 动画结束,设置标记 |
| | | m_bIsRobotMoving = FALSE; |
| | | } |
| | | |
| | | void CPageGraph1::RotateRobot(float angleInDegrees) |
| | | { |
| | | // 将角度转换为弧度 |
| | | float angleInRadians = static_cast<float>(std::acos(-1)) / 180.0f * angleInDegrees; |
| | | |
| | | // 获取机器人图片的当前坐标和中心 |
| | | // 获取机器人图片 |
| | | auto* pImage = m_pGraph->GetImage(IMAGE_ROBOT); |
| | | if (!pImage) return; |
| | | |
| | | // 更新 Rotate 图片的角度,确保角度保持在 [0, 360) 范围内 |
| | | m_pGraph->UpdateImageAngle(IMAGE_ROBOT, static_cast<float>(fmod(pImage->angle + angleInDegrees + 360, 360))); |
| | | // 修正角度为 0~360 |
| | | float finalAngle = fmod(angleInDegrees + 360.0f, 360.0f); |
| | | m_pGraph->UpdateImageAngle(IMAGE_ROBOT, finalAngle); |
| | | |
| | | int cx = pImage->x + pImage->bmWidth / 2; // 图片中心 X |
| | | int cy = pImage->y + pImage->bmHeight / 2; // 图片中心 Y |
| | | // 计算中心点 |
| | | int cx = pImage->x + pImage->bmWidth / 2; |
| | | int cy = pImage->y + pImage->bmHeight / 2; |
| | | |
| | | // 旋转指示框的坐标 |
| | | auto* pRobot1 = m_pGraph->GetIndicateBox(INDICATE_ROBOT_ARM1); |
| | | auto* pRobot2 = m_pGraph->GetIndicateBox(INDICATE_ROBOT_ARM2); |
| | | // 转换角度为弧度 |
| | | float radians = angleInDegrees * 3.1415926f / 180.0f; |
| | | |
| | | if (pRobot1 && pRobot2) { |
| | | int newArmX1 = pImage->x + 20; |
| | | int newArmY1 = 294; |
| | | // 旋转 offset1 |
| | | int rotatedX1 = static_cast<int>(cos(radians) * m_arm1Offset.x - sin(radians) * m_arm1Offset.y); |
| | | int rotatedY1 = static_cast<int>(sin(radians) * m_arm1Offset.x + cos(radians) * m_arm1Offset.y); |
| | | |
| | | int newArmX2 = pImage->x + 73; |
| | | int newArmY2 = 294; |
| | | // 旋转 offset2 |
| | | int rotatedX2 = static_cast<int>(cos(radians) * m_arm2Offset.x - sin(radians) * m_arm2Offset.y); |
| | | int rotatedY2 = static_cast<int>(sin(radians) * m_arm2Offset.x + cos(radians) * m_arm2Offset.y); |
| | | |
| | | if (angleInDegrees != 0.0f) { |
| | | // 计算指示框1的新坐标 |
| | | newArmX1 = static_cast<int>(cx + (pRobot1->x - cx) * cos(angleInRadians) - (pRobot1->y - cy) * sin(angleInRadians)); |
| | | newArmY1 = static_cast<int>(cy + (pRobot1->x - cx) * sin(angleInRadians) + (pRobot1->y - cy) * cos(angleInRadians)); |
| | | // 更新指示框 |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM1, cx + rotatedX1, cy + rotatedY1); |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM2, cx + rotatedX2, cy + rotatedY2); |
| | | |
| | | // 计算指示框2的新坐标 |
| | | newArmX2 = static_cast<int>(cx + (pRobot2->x - cx) * cos(angleInRadians) - (pRobot2->y - cy) * sin(angleInRadians)); |
| | | newArmY2 = static_cast<int>(cy + (pRobot2->x - cx) * sin(angleInRadians) + (pRobot2->y - cy) * cos(angleInRadians)); |
| | | } |
| | | Invalidate(); |
| | | } |
| | | |
| | | // 更新指示框的位置 |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM1, newArmX1, newArmY1); |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM2, newArmX2, newArmY2); |
| | | void CPageGraph1::BindEquipmentToGraph() |
| | | { |
| | | struct EquipmentBindInfo |
| | | { |
| | | int nEquipmentID; |
| | | int nIndicateID; |
| | | }; |
| | | |
| | | static const EquipmentBindInfo EQUIPMENT_BIND_LIST[] = { |
| | | { EQ_ID_ARM_TRAY1, INDICATE_ROBOT_ARM1 }, |
| | | { EQ_ID_ARM_TRAY2, INDICATE_ROBOT_ARM2 }, |
| | | { EQ_ID_Bonder1, INDICATE_BONDER1 }, |
| | | { EQ_ID_Bonder2, INDICATE_BONDER2 }, |
| | | { EQ_ID_LOADPORT1, INDICATE_LPORT1 }, |
| | | { EQ_ID_LOADPORT2, INDICATE_LPORT2 }, |
| | | { EQ_ID_LOADPORT3, INDICATE_LPORT3 }, |
| | | { EQ_ID_LOADPORT4, INDICATE_LPORT4 }, |
| | | { EQ_ID_FLIPER, INDICATE_FLIPER }, |
| | | { EQ_ID_VACUUMBAKE, INDICATE_VACUUM_BAKE }, |
| | | { EQ_ID_ALIGNER, INDICATE_ALIGNER }, |
| | | { EQ_ID_BAKE_COOLING, INDICATE_BAKE_COOLING }, |
| | | { EQ_ID_MEASUREMENT, INDICATE_MEASUREMENT } |
| | | }; |
| | | |
| | | for (const auto& stBindInfo : EQUIPMENT_BIND_LIST) |
| | | { |
| | | SERVO::CEquipment* pEquipment = theApp.m_model.m_master.getEquipment(stBindInfo.nEquipmentID); |
| | | m_pGraph->SetIndicateBoxData(stBindInfo.nIndicateID, pEquipment); |
| | | } |
| | | } |
| | | |
| | | void CPageGraph1::MoveRobotToPosition(SERVO::ROBOT_POSITION position) |
| | | { |
| | | auto it = g_positionMap.find(position); |
| | | if (it == g_positionMap.end()) { |
| | | TRACE("Invalid robot position: %d\n", static_cast<int>(position)); |
| | | return; |
| | | } |
| | | |
| | | // 强制重绘界面 |
| | | Invalidate(); |
| | | const RobotPositionMapping& mapping = it->second; |
| | | |
| | | // 平台移动 |
| | | UpdateRobotPosition(mapping.percentage); |
| | | |
| | | // 旋转方向 |
| | | RotateRobot(mapping.angle); |
| | | |
| | | m_lastRobotPosition = position; |
| | | } |
| | | |
| | | void CPageGraph1::StartRobotMoveToPosition(SERVO::ROBOT_POSITION position) |
| | | { |
| | | auto it = g_positionMap.find(position); |
| | | if (it == g_positionMap.end()) { |
| | | TRACE("Invalid robot position: %d\n", static_cast<int>(position)); |
| | | return; |
| | | } |
| | | |
| | | const RobotPositionMapping& mapping = it->second; |
| | | |
| | | auto* pImage = m_pGraph->GetImage(IMAGE_ROBOT); |
| | | if (!pImage) return; |
| | | |
| | | m_nRobotMoveStartX = pImage->x; |
| | | m_nRobotMoveEndX = static_cast<int>(170 + mapping.percentage * (700 - 170)); |
| | | |
| | | m_nRobotMoveStartAngle = pImage->angle; // 起始角度(当前角度) |
| | | m_nRobotMoveEndAngle = mapping.angle; // 目标角度 |
| | | |
| | | m_nRobotMoveCurrentStep = 0; |
| | | m_targetRobotPosition = position; |
| | | m_bIsRobotMoving = TRUE; |
| | | |
| | | SetTimer(TIMER_ID_ROBOT_ANIMATION, 16, nullptr); |
| | | } |
| | | |
| | | POINT CPageGraph1::LoadArmOffset(const std::string& armName) |
| | | { |
| | | std::string iniPath = GetConfigPath(); |
| | | POINT pt; |
| | | pt.x = GetPrivateProfileIntA("Offsets", (armName + "_X").c_str(), 0, iniPath.c_str()); |
| | | pt.y = GetPrivateProfileIntA("Offsets", (armName + "_Y").c_str(), 0, iniPath.c_str()); |
| | | return pt; |
| | | } |
| | | |
| | | |
| | | void CPageGraph1::UpdateSlotBars() |
| | | { |
| | | if (m_pGraph == nullptr) return; |
| | | |
| | | if (m_slotBarTestMode != 0) { |
| | | ApplySlotBarTestPattern(m_slotBarTestMode); |
| | | return; |
| | | } |
| | | |
| | | struct SlotBarBind { |
| | | int eqId; |
| | | int indicateId; |
| | | }; |
| | | static const SlotBarBind kSlotBars[] = { |
| | | { EQ_ID_Bonder1, INDICATE_BONDER1 }, |
| | | { EQ_ID_FLIPER, INDICATE_FLIPER }, |
| | | { EQ_ID_ALIGNER, INDICATE_ALIGNER }, |
| | | { EQ_ID_LOADPORT4, INDICATE_LPORT4 }, |
| | | { EQ_ID_LOADPORT3, INDICATE_LPORT3 }, |
| | | { EQ_ID_LOADPORT2, INDICATE_LPORT2 }, |
| | | { EQ_ID_LOADPORT1, INDICATE_LPORT1 }, |
| | | { EQ_ID_Bonder2, INDICATE_BONDER2 }, |
| | | { EQ_ID_VACUUMBAKE, INDICATE_VACUUM_BAKE }, |
| | | { EQ_ID_BAKE_COOLING, INDICATE_BAKE_COOLING }, |
| | | { EQ_ID_MEASUREMENT, INDICATE_MEASUREMENT }, |
| | | }; |
| | | |
| | | for (const auto& item : kSlotBars) { |
| | | SERVO::CEquipment* pEq = theApp.m_model.m_master.getEquipment(item.eqId); |
| | | std::vector<COLORREF> colors; |
| | | BuildSlotColors(pEq, colors); |
| | | m_pGraph->SetIndicateBoxSlotColors(item.indicateId, colors); |
| | | } |
| | | } |
| | | |
| | | void CPageGraph1::BuildSlotColors(SERVO::CEquipment* pEq, std::vector<COLORREF>& colors) |
| | | { |
| | | colors.clear(); |
| | | if (pEq == nullptr) return; |
| | | |
| | | for (int i = 0; i < SLOT_MAX; ++i) { |
| | | SERVO::CSlot* pSlot = pEq->getSlot(i); |
| | | if (pSlot == nullptr || !pSlot->isEnable()) continue; |
| | | SERVO::CGlass* pGlass = (SERVO::CGlass*)pSlot->getContext(); |
| | | BOOL isProcessing = FALSE; |
| | | if (pGlass != nullptr) { |
| | | const auto st = pEq->getProcessState(i + 1); |
| | | isProcessing = (st == SERVO::PROCESS_STATE::Processing); |
| | | } |
| | | colors.push_back(GetSlotColor(pGlass, isProcessing)); |
| | | } |
| | | } |
| | | |
| | | COLORREF CPageGraph1::GetSlotColor(SERVO::CGlass* pGlass, BOOL isProcessing) |
| | | { |
| | | if (pGlass == nullptr) { |
| | | return EQ_SLOT_EMPTY; |
| | | } |
| | | const auto type = pGlass->getType(); |
| | | const bool isG2 = (type == SERVO::MaterialsType::G2 || type == SERVO::MaterialsType::G1G2); |
| | | if (isProcessing) { |
| | | return isG2 ? EQ_SLOT_PROC_G2 : EQ_SLOT_PROC_G1; |
| | | } |
| | | return isG2 ? EQ_SLOT_G2 : EQ_SLOT_G1; |
| | | } |
| | | |
| | | void CPageGraph1::ApplySlotBarTestPattern(int mode) |
| | | { |
| | | if (m_pGraph == nullptr) return; |
| | | |
| | | std::vector<COLORREF> colors; |
| | | colors.reserve(SLOT_MAX); |
| | | for (int i = 0; i < SLOT_MAX; ++i) { |
| | | if (mode == 2) { |
| | | colors.push_back((i % 2 == 0) ? EQ_SLOT_PROC_G1 : EQ_SLOT_PROC_G2); |
| | | } else if (mode == 1) { |
| | | colors.push_back((i % 2 == 0) ? EQ_SLOT_G1 : EQ_SLOT_G2); |
| | | } else { |
| | | colors.push_back(EQ_SLOT_EMPTY); |
| | | } |
| | | } |
| | | |
| | | struct SlotBarBind { |
| | | int indicateId; |
| | | }; |
| | | static const SlotBarBind kSlotBars[] = { |
| | | { INDICATE_BONDER1 }, |
| | | { INDICATE_FLIPER }, |
| | | { INDICATE_ALIGNER }, |
| | | { INDICATE_LPORT4 }, |
| | | { INDICATE_LPORT3 }, |
| | | { INDICATE_LPORT2 }, |
| | | { INDICATE_LPORT1 }, |
| | | { INDICATE_BONDER2 }, |
| | | { INDICATE_VACUUM_BAKE }, |
| | | { INDICATE_BAKE_COOLING }, |
| | | { INDICATE_MEASUREMENT }, |
| | | }; |
| | | |
| | | for (const auto& item : kSlotBars) { |
| | | m_pGraph->SetIndicateBoxSlotColors(item.indicateId, colors); |
| | | } |
| | | } |
| | | |
| | | void CPageGraph1::SaveArmOffset(const std::string& armName, const POINT& pt) |
| | | { |
| | | std::string iniPath = GetConfigPath(); |
| | | char buf[16]; |
| | | |
| | | sprintf_s(buf, "%d", pt.x); |
| | | WritePrivateProfileStringA("Offsets", (armName + "_X").c_str(), buf, iniPath.c_str()); |
| | | |
| | | sprintf_s(buf, "%d", pt.y); |
| | | WritePrivateProfileStringA("Offsets", (armName + "_Y").c_str(), buf, iniPath.c_str()); |
| | | } |
| | | |
| | | void CPageGraph1::OnGraphItemClicked(NMHDR* pNMHDR, LRESULT* pResult) |
| | | { |
| | | BYSERVOGRAPH_NMHDR* pGraphNmhdr = reinterpret_cast<BYSERVOGRAPH_NMHDR*>(pNMHDR); |
| | | CString s; s.Format(_T("OnGraphItemClicked %d"), pGraphNmhdr->dwData); |
| | | SERVO::CEquipment* pEquipment = (SERVO::CEquipment*)m_pGraph->GetIndicateBoxData(pGraphNmhdr->dwData); |
| | | if (pEquipment != nullptr) { |
| | | AfxMessageBox(pEquipment->getName().c_str()); |
| | | |
| | | if (GetKeyState(VK_SHIFT) & 0x8000) { |
| | | // m_slotBarTestMode = (m_slotBarTestMode + 1) % 3; |
| | | UpdateSlotBars(); |
| | | *pResult = 0; |
| | | return; |
| | | } |
| | | |
| | | // 移动到指定位置 (测试使用) |
| | | if (pGraphNmhdr->dwData == INDICATE_LPORT1) { |
| | | |
| | | } |
| | | |
| | | if (m_pGraph != nullptr) { |
| | | LayoutSlotTable(); |
| | | LOGI("[Graph1] item clicked id=%u", (unsigned)pGraphNmhdr->dwData); |
| | | auto* pEq = (SERVO::CEquipment*)m_pGraph->GetIndicateBoxData((int)pGraphNmhdr->dwData); |
| | | m_pSelectedEquipment = pEq; |
| | | UpdateSlotTable(pEq); |
| | | } |
| | | m_slotTable.ShowWindow(SW_SHOW); |
| | | m_slotTable.BringWindowToTop(); |
| | | |
| | | *pResult = 0; |
| | | } |
| | | |
| | | void CPageGraph1::OnTimer(UINT_PTR nIDEvent) |
| | | { |
| | | if (1 == nIDEvent) { |
| | | KillTimer(1); |
| | | InitRxWindows(); |
| | | UpdateLegendPosition(); |
| | | |
| | | if (TIMER_ID_DEVICE_STATUS == nIDEvent) { |
| | | KillTimer(TIMER_ID_DEVICE_STATUS); |
| | | |
| | | // 更新状态 |
| | | { |
| | | SERVO::CEquipment* pEquipment = (SERVO::CEFEM*)theApp.m_model.m_master.getEquipment(EQ_ID_EFEM); |
| | | ASSERT(pEquipment); |
| | | DeviceStatus status = pEquipment->isAlive() ? DeviceStatus::ONLINE : DeviceStatus::OFFLINE; |
| | | UpdateDeviceStatus(INDICATE_FLIPER, status); |
| | | UpdateDeviceStatus(INDICATE_ALIGNER, status); |
| | | UpdateDeviceStatus(INDICATE_LPORT1, status); |
| | | UpdateDeviceStatus(INDICATE_LPORT2, status); |
| | | UpdateDeviceStatus(INDICATE_LPORT3, status); |
| | | UpdateDeviceStatus(INDICATE_LPORT4, status); |
| | | UpdateDeviceStatus(INDICATE_ROBOT_ARM1, status); |
| | | UpdateDeviceStatus(INDICATE_ROBOT_ARM2, status); |
| | | } |
| | |
| | | DeviceStatus status = pEquipment->isAlive() ? DeviceStatus::ONLINE : DeviceStatus::OFFLINE; |
| | | UpdateDeviceStatus(INDICATE_BONDER2, status); |
| | | } |
| | | |
| | | { |
| | | SERVO::CEquipment* pEquipment = theApp.m_model.m_master.getEquipment(EQ_ID_VACUUMBAKE); |
| | | ASSERT(pEquipment); |
| | | DeviceStatus status = pEquipment->isAlive() ? DeviceStatus::ONLINE : DeviceStatus::OFFLINE; |
| | | UpdateDeviceStatus(INDICATE_VACUUM_BAKE, status); |
| | | } |
| | | |
| | | { |
| | | SERVO::CEquipment* pEquipment = theApp.m_model.m_master.getEquipment(EQ_ID_BAKE_COOLING); |
| | | ASSERT(pEquipment); |
| | | DeviceStatus status = pEquipment->isAlive() ? DeviceStatus::ONLINE : DeviceStatus::OFFLINE; |
| | | UpdateDeviceStatus(INDICATE_BAKE_COOLING, status); |
| | | } |
| | | |
| | | { |
| | | SERVO::CEquipment* pEquipment = theApp.m_model.m_master.getEquipment(EQ_ID_MEASUREMENT); |
| | | ASSERT(pEquipment); |
| | | DeviceStatus status = pEquipment->isAlive() ? DeviceStatus::ONLINE : DeviceStatus::OFFLINE; |
| | | UpdateDeviceStatus(INDICATE_MEASUREMENT, status); |
| | | } |
| | | } |
| | | else if (nIDEvent == TIMER_ID_ROBOT_STATUS) { |
| | | SERVO::CEFEM* pEFEM = (SERVO::CEFEM*)theApp.m_model.m_master.getEquipment(EQ_ID_EFEM); |
| | | if (!pEFEM || !pEFEM->isAlive()) { |
| | | UpdateSlotBars(); |
| | | if (m_pSelectedEquipment != nullptr) { |
| | | UpdateSlotTable(m_pSelectedEquipment); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | // 如果设备在线,那么更新 ARM 状态 |
| | | SERVO::RMDATA& robotData = pEFEM->getRobotMonitoringData(); |
| | | if (m_lastArmState[0] != robotData.armState[0]) { |
| | | m_lastArmState[0] = robotData.armState[0]; |
| | | DeviceStatus arm1Status; |
| | | arm1Status = robotData.armState[0] ? DeviceStatus::OCCUPIED : DeviceStatus::ONLINE; |
| | | UpdateDeviceStatus(INDICATE_ROBOT_ARM1, arm1Status); |
| | | } |
| | | |
| | | if (m_lastArmState[1] != robotData.armState[1]) { |
| | | m_lastArmState[1] = robotData.armState[1]; |
| | | DeviceStatus arm2Status; |
| | | arm2Status = robotData.armState[1] ? DeviceStatus::OCCUPIED : DeviceStatus::ONLINE; |
| | | UpdateDeviceStatus(INDICATE_ROBOT_ARM2, arm2Status); |
| | | } |
| | | |
| | | // 位置信息状态显示 |
| | | if (robotData.position != m_lastRobotPosition) { |
| | | StartRobotMoveToPosition(robotData.position); |
| | | } |
| | | |
| | | UpdateSlotBars(); |
| | | if (m_pSelectedEquipment != nullptr) { |
| | | // 定时兜底:即使漏掉事件通知,也确保右侧Slot表持续刷新 |
| | | UpdateSlotTable(m_pSelectedEquipment); |
| | | } |
| | | } |
| | | else if (nIDEvent == TIMER_ID_ROBOT_ANIMATION) { |
| | | if (!m_bIsRobotMoving) { |
| | | KillTimer(TIMER_ID_ROBOT_ANIMATION); |
| | | return; |
| | | } |
| | | |
| | | m_nRobotMoveCurrentStep++; |
| | | |
| | | float progress = static_cast<float>(m_nRobotMoveCurrentStep) / m_nRobotMoveSteps; |
| | | if (progress >= 1.0f) { |
| | | progress = 1.0f; |
| | | m_bIsRobotMoving = FALSE; |
| | | KillTimer(TIMER_ID_ROBOT_ANIMATION); |
| | | m_lastRobotPosition = m_targetRobotPosition; |
| | | } |
| | | |
| | | // 平滑计算位置 |
| | | int currentX = static_cast<int>(m_nRobotMoveStartX + progress * (m_nRobotMoveEndX - m_nRobotMoveStartX)); |
| | | auto* pImage = m_pGraph->GetImage(IMAGE_ROBOT); |
| | | if (!pImage) return; |
| | | |
| | | int cx = currentX + pImage->bmWidth / 2; |
| | | int y = 270; |
| | | int cy = y + pImage->bmHeight / 2; |
| | | |
| | | // 平滑计算角度 |
| | | float currentAngle = m_nRobotMoveStartAngle + progress * (m_nRobotMoveEndAngle - m_nRobotMoveStartAngle); |
| | | float radians = currentAngle * 3.1415926f / 180.0f; |
| | | |
| | | int rotatedX1 = static_cast<int>(cos(radians) * m_arm1Offset.x - sin(radians) * m_arm1Offset.y); |
| | | int rotatedY1 = static_cast<int>(sin(radians) * m_arm1Offset.x + cos(radians) * m_arm1Offset.y); |
| | | int rotatedX2 = static_cast<int>(cos(radians) * m_arm2Offset.x - sin(radians) * m_arm2Offset.y); |
| | | int rotatedY2 = static_cast<int>(sin(radians) * m_arm2Offset.x + cos(radians) * m_arm2Offset.y); |
| | | |
| | | m_pGraph->UpdateImageCoordinates(IMAGE_ROBOT, currentX, y); |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM1, cx + rotatedX1, cy + rotatedY1); |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM2, cx + rotatedX2, cy + rotatedY2); |
| | | m_pGraph->UpdateImageAngle(IMAGE_ROBOT, currentAngle); |
| | | |
| | | Invalidate(); |
| | | } |
| | | |
| | | CDialogEx::OnTimer(nIDEvent); |