using System; using System.IO; using PathLogic.Core; using PathLogic.Models; namespace PathLogic { /// /// PathLogic 메인 프로그램 /// AGV 길찾기 알고리즘을 테스트하고 개발하기 위한 콘솔 애플리케이션 /// class Program { private static MapLoader _mapLoader; private static MapData _mapData; static void Main(string[] args) { Console.WriteLine("===== AGV PathLogic 개발 도구 ====="); Console.WriteLine("AGV 길찾기 알고리즘 개발을 위한 기본 프로젝트"); Console.WriteLine(); try { InitializeSystem(); RunMainLoop(); } catch (Exception ex) { Console.WriteLine($"오류 발생: {ex.Message}"); Console.WriteLine("아무 키나 눌러 종료하세요."); Console.ReadKey(); } } /// /// 시스템 초기화 /// private static void InitializeSystem() { Console.WriteLine("시스템 초기화 중..."); _mapLoader = new MapLoader(); // 기본 맵 파일 로드 string defaultMapPath = @"C:\Data\Source\(5613#) ENIG AGV\Source\Cs_HMI\Data\NewMap.agvmap"; if (File.Exists(defaultMapPath)) { LoadMap(defaultMapPath); Console.WriteLine("기본 맵 파일 로드 완료."); } else { Console.WriteLine("기본 맵 파일을 찾을 수 없습니다."); Console.WriteLine($"경로: {defaultMapPath}"); } Console.WriteLine("초기화 완료."); Console.WriteLine(); } /// /// 메인 루프 /// private static void RunMainLoop() { while (true) { ShowMenu(); string input = Console.ReadLine(); if (string.IsNullOrEmpty(input)) continue; if (input.ToLower() == "q" || input.ToLower() == "quit" || input.ToLower() == "exit") { Console.WriteLine("프로그램을 종료합니다."); break; } ProcessCommand(input); Console.WriteLine(); } } /// /// 메뉴 표시 /// private static void ShowMenu() { Console.WriteLine("===== 메뉴 ====="); Console.WriteLine("1. 맵 파일 로드 (load)"); Console.WriteLine("2. 맵 정보 표시 (info)"); Console.WriteLine("3. 노드 목록 표시 (nodes)"); Console.WriteLine("q. 종료 (quit)"); Console.Write("명령을 입력하세요: "); } /// /// 명령 처리 /// /// 사용자 입력 명령 private static void ProcessCommand(string command) { try { switch (command.ToLower().Trim()) { case "1": case "load": LoadMapCommand(); break; case "2": case "info": ShowMapInfo(); break; case "3": case "nodes": ShowNodes(); break; default: Console.WriteLine("알 수 없는 명령입니다."); break; } } catch (Exception ex) { Console.WriteLine($"명령 처리 중 오류: {ex.Message}"); } } /// /// 맵 파일 로드 명령 /// private static void LoadMapCommand() { Console.Write("맵 파일 경로를 입력하세요 (엔터: 기본 경로): "); string path = Console.ReadLine(); if (string.IsNullOrEmpty(path)) { path = @"C:\Data\Source\(5613#) ENIG AGV\Source\Cs_HMI\Data\NewMap.agvmap"; } if (LoadMap(path)) { Console.WriteLine("맵 파일 로드 성공!"); } else { Console.WriteLine("맵 파일 로드 실패!"); } } /// /// 맵 파일 로드 /// /// 맵 파일 경로 /// 로드 성공 여부 private static bool LoadMap(string filePath) { try { _mapData = _mapLoader.LoadFromFile(filePath); return true; } catch (Exception ex) { Console.WriteLine($"맵 로드 오류: {ex.Message}"); return false; } } /// /// 맵 정보 표시 /// private static void ShowMapInfo() { if (_mapData == null) { Console.WriteLine("로드된 맵이 없습니다."); return; } Console.WriteLine("===== 맵 정보 ====="); var stats = _mapData.GetStatistics(); Console.WriteLine(stats.ToString()); } /// /// 노드 목록 표시 /// private static void ShowNodes() { if (_mapData == null) { Console.WriteLine("로드된 맵이 없습니다."); return; } Console.WriteLine("===== 노드 목록 ====="); foreach (var node in _mapData.GetNavigationNodes()) { Console.WriteLine($"{node.NodeId} ({node.RfidId}) - {node.Name} [{node.Type}] - 연결: {node.ConnectedNodes.Count}개"); } } } }