210 lines
6.2 KiB
C#
210 lines
6.2 KiB
C#
using System;
|
|
using System.IO;
|
|
using PathLogic.Core;
|
|
using PathLogic.Models;
|
|
|
|
namespace PathLogic
|
|
{
|
|
/// <summary>
|
|
/// PathLogic 메인 프로그램
|
|
/// AGV 길찾기 알고리즘을 테스트하고 개발하기 위한 콘솔 애플리케이션
|
|
/// </summary>
|
|
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();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 시스템 초기화
|
|
/// </summary>
|
|
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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 메인 루프
|
|
/// </summary>
|
|
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();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 메뉴 표시
|
|
/// </summary>
|
|
private static void ShowMenu()
|
|
{
|
|
Console.WriteLine("===== 메뉴 =====");
|
|
Console.WriteLine("1. 맵 파일 로드 (load)");
|
|
Console.WriteLine("2. 맵 정보 표시 (info)");
|
|
Console.WriteLine("3. 노드 목록 표시 (nodes)");
|
|
Console.WriteLine("q. 종료 (quit)");
|
|
Console.Write("명령을 입력하세요: ");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 명령 처리
|
|
/// </summary>
|
|
/// <param name="command">사용자 입력 명령</param>
|
|
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}");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 맵 파일 로드 명령
|
|
/// </summary>
|
|
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("맵 파일 로드 실패!");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 맵 파일 로드
|
|
/// </summary>
|
|
/// <param name="filePath">맵 파일 경로</param>
|
|
/// <returns>로드 성공 여부</returns>
|
|
private static bool LoadMap(string filePath)
|
|
{
|
|
try
|
|
{
|
|
_mapData = _mapLoader.LoadFromFile(filePath);
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"맵 로드 오류: {ex.Message}");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 맵 정보 표시
|
|
/// </summary>
|
|
private static void ShowMapInfo()
|
|
{
|
|
if (_mapData == null)
|
|
{
|
|
Console.WriteLine("로드된 맵이 없습니다.");
|
|
return;
|
|
}
|
|
|
|
Console.WriteLine("===== 맵 정보 =====");
|
|
var stats = _mapData.GetStatistics();
|
|
Console.WriteLine(stats.ToString());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 노드 목록 표시
|
|
/// </summary>
|
|
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}개");
|
|
}
|
|
}
|
|
}
|
|
} |