From 34a804e53872deb9cacc036616162e2bad91f040 Mon Sep 17 00:00:00 2001 From: backuppc Date: Thu, 30 Oct 2025 09:43:04 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=85=B8=EB=93=9C=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20=EC=8B=9C=20=EA=B3=A0=EC=95=84=20=EC=97=B0=EA=B2=B0=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 주요 변경사항: - CleanupOrphanConnections() 함수 추가 - 저장 시 고아 연결 자동 정리 - 로드 시 고아 연결 자동 제거 - 경로 예측에서 삭제된 노드 연결 사용 방지 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../AGVNavigationCore/Models/MapLoader.cs | 35 +++++++++++++++++++ Cs_HMI/Data/NewMap.agvmap | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Cs_HMI/AGVLogic/AGVNavigationCore/Models/MapLoader.cs b/Cs_HMI/AGVLogic/AGVNavigationCore/Models/MapLoader.cs index d2176ec..fd9f912 100644 --- a/Cs_HMI/AGVLogic/AGVNavigationCore/Models/MapLoader.cs +++ b/Cs_HMI/AGVLogic/AGVNavigationCore/Models/MapLoader.cs @@ -78,6 +78,9 @@ namespace AGVNavigationCore.Models // 중복된 NodeId 정리 FixDuplicateNodeIds(result.Nodes); + // 존재하지 않는 노드에 대한 연결 정리 (고아 연결 제거) + CleanupOrphanConnections(result.Nodes); + // 양방향 연결 자동 설정 (A→B가 있으면 B→A도 설정) // 주의: CleanupDuplicateConnections()는 제거됨 - 양방향 연결을 단방향으로 변환하는 버그가 있었음 EnsureBidirectionalConnections(result.Nodes); @@ -113,6 +116,9 @@ namespace AGVNavigationCore.Models { try { + // 저장 전 고아 연결 정리 (삭제된 노드에 대한 연결 제거) + CleanupOrphanConnections(nodes); + var mapData = new MapFileData { Nodes = nodes, @@ -298,6 +304,35 @@ namespace AGVNavigationCore.Models } } + /// + /// 존재하지 않는 노드에 대한 연결을 정리합니다 (고아 연결 제거). + /// 노드 삭제 후 저장된 맵 파일에서 삭제된 노드 ID가 ConnectedNodes에 남아있는 경우를 처리합니다. + /// + /// 맵 노드 목록 + private static void CleanupOrphanConnections(List mapNodes) + { + if (mapNodes == null || mapNodes.Count == 0) return; + + // 존재하는 모든 노드 ID 집합 생성 + var validNodeIds = new HashSet(mapNodes.Select(n => n.NodeId)); + + // 각 노드의 연결을 검증하고 존재하지 않는 노드 ID 제거 + foreach (var node in mapNodes) + { + if (node.ConnectedNodes == null || node.ConnectedNodes.Count == 0) + continue; + + var orphanConnections = node.ConnectedNodes + .Where(connectedId => !validNodeIds.Contains(connectedId)) + .ToList(); + + foreach (var orphanId in orphanConnections) + { + node.RemoveConnection(orphanId); + } + } + } + /// /// [사용 중지됨] 중복 연결을 정리합니다. 양방향 중복 연결을 단일 연결로 통합합니다. /// 주의: 이 함수는 버그가 있어 사용 중지됨 - 양방향 연결을 단방향으로 변환하여 경로 탐색 실패 발생 diff --git a/Cs_HMI/Data/NewMap.agvmap b/Cs_HMI/Data/NewMap.agvmap index 6806987..1ca0c86 100644 --- a/Cs_HMI/Data/NewMap.agvmap +++ b/Cs_HMI/Data/NewMap.agvmap @@ -1082,6 +1082,6 @@ "DisplayText": "N031 - [030]" } ], - "CreatedDate": "2025-10-30T09:30:01.9333244+09:00", + "CreatedDate": "2025-10-30T09:37:03.9172219+09:00", "Version": "1.0" } \ No newline at end of file