This commit is contained in:
backuppc
2025-11-10 14:43:47 +09:00
parent 68745f23bb
commit 6e54633c08
57 changed files with 4432 additions and 1018 deletions

View File

@@ -10,12 +10,13 @@ using System.Windows.Forms;
using Project.StateMachine;
using COMM;
using AR;
using AGVNavigationCore.Models;
namespace Project.ViewForm
{
public partial class fAuto : Form
{
public fAuto()
{
InitializeComponent();
@@ -26,46 +27,143 @@ namespace Project.ViewForm
this.ctlAuto1.Scean = CtlAuto.eScean.Progress;
else
this.ctlAuto1.Scean = CtlAuto.eScean.Normal;
PUB.mapctl = new AGVControl.MapControl();
PUB.mapctl.Dock = DockStyle.Fill;
PUB.mapctl.Visible = true;
PUB.mapctl.Font = this.panel1.Font;
PUB.mapctl.BackColor = Color.FromArgb(32, 32, 32);
this.panel1.Controls.Add(PUB.mapctl);
InitializeMapCanvas();
//PUB.mapctl = new AGVControl.MapControl();
//PUB.mapctl.Dock = DockStyle.Fill;
//PUB.mapctl.Visible = true;
//PUB.mapctl.Font = this.panel1.Font;
//PUB.mapctl.BackColor = Color.FromArgb(32, 32, 32);
//this.panel1.Controls.Add(PUB.mapctl);
}
private void InitializeMapCanvas()
{
PUB._mapCanvas = new AGVNavigationCore.Controls.UnifiedAGVCanvas();
PUB._mapCanvas.Dock = DockStyle.Fill;
PUB._mapCanvas.ShowGrid = false;
PUB._mapCanvas.BackColor = Color.FromArgb(32,32,32);
PUB._mapCanvas.ForeColor = Color.White;
// RfidMappings 제거 - MapNode에 통합됨
// 이벤트 연결
//PUB._mapCanvas.NodeAdded += OnNodeAdded;
//PUB._mapCanvas.NodeSelected += OnNodeSelected;
//PUB._mapCanvas.NodeMoved += OnNodeMoved;
//PUB._mapCanvas.NodeDeleted += OnNodeDeleted;
//PUB._mapCanvas.ConnectionDeleted += OnConnectionDeleted;
//PUB._mapCanvas.ImageNodeDoubleClicked += OnImageNodeDoubleClicked;
//PUB._mapCanvas.MapChanged += OnMapChanged;
// 스플리터 패널에 맵 캔버스 추가
panel1.Controls.Add(PUB._mapCanvas);
// 툴바 버튼 이벤트 연결
//WireToolbarButtonEvents();
}
private void fAuto_Load(object sender, EventArgs e)
{
ctlAuto1.dev_agv = PUB.AGV;
// ctlAuto1.dev_plc = PUB.PLC;
ctlAuto1.dev_bms = PUB.BMS;
ctlAuto1.dev_xbe = PUB.XBE;
PUB.AGV.DataReceive += AGV_DataReceive;
//auto load
var path = new System.IO.DirectoryInfo("route");
if (path.Exists == false) path.Create();
var files = path.GetFiles("*.route");
var fn = string.Empty;
if (files.Any() == false)
//맵파일로딩
var filePath = new System.IO.FileInfo(@".\route\NewMap.agvmap");
if (filePath.Exists)
{
fn = AR.UTIL.MakePath("sample.route");
}
else if (files.Count() == 1)
{
fn = files.First().FullName;
}
if(fn.isEmpty()==false)
{
var fi = new System.IO.FileInfo(AR.UTIL.CurrentPath + "\\sample.route");
if (fi.Exists)
var result = MapLoader.LoadMapFromFile(filePath.FullName);
if (result.Success)
{
PUB.log.Add($"autoload : {fi.FullName}");
var rlt = PUB.mapctl.LoadFromFile(fi.FullName,out string errmsg);
if (rlt == false) AR.UTIL.MsgE(errmsg);
if (PUB._mapNodes == null) PUB._mapNodes = new List<MapNode>();
else PUB._mapNodes.Clear();
PUB._mapNodes.AddRange(result.Nodes);
// 맵 캔버스에 데이터 설정
PUB._mapCanvas.Nodes = PUB._mapNodes;
// 🔥 맵 설정 적용 (배경색, 그리드 표시)
if (result.Settings != null)
{
PUB._mapCanvas.BackColor = System.Drawing.Color.FromArgb(result.Settings.BackgroundColorArgb);
PUB._mapCanvas.ShowGrid = result.Settings.ShowGrid;
}
// 🔥 가상 AGV 초기화 (첫 노드 위치에 생성)
if (PUB._virtualAGV == null && PUB._mapNodes.Count > 0)
{
var startNode = PUB._mapNodes.FirstOrDefault(n => n.IsNavigationNode());
if (startNode != null)
{
PUB._virtualAGV = new VirtualAGV("AGV-01", startNode.Position, AgvDirection.Forward);
PUB._virtualAGV.SetPosition(startNode, AgvDirection.Forward);
// 캔버스에 AGV 리스트 설정
var agvList = new System.Collections.Generic.List<AGVNavigationCore.Controls.IAGV> { PUB._virtualAGV };
PUB._mapCanvas.AGVList = agvList;
PUB.log.Add($"가상 AGV 생성: {startNode.NodeId} 위치");
}
}
else if (PUB._virtualAGV != null)
{
// 기존 AGV가 있으면 캔버스에 다시 연결
var agvList = new System.Collections.Generic.List<AGVNavigationCore.Controls.IAGV> { PUB._virtualAGV };
PUB._mapCanvas.AGVList = agvList;
}
// 맵 로드 후 자동으로 맵에 맞춤
PUB._mapCanvas.FitToNodes();
PUB.log.Add($"맵 파일 로드 완료: {filePath.Name}, 노드 수: {result.Nodes.Count}");
}
else
{
PUB.log.Add($"맵 파일 로딩 실패: {result.ErrorMessage}");
MessageBox.Show($"맵 파일 로딩 실패: {result.ErrorMessage}", "오류",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
PUB.log.Add($"맵 파일을 찾을 수 없습니다: {filePath.FullName}");
}
//var fn = string.Empty;
//if (files.Any() == false)
//{
// fn = AR.UTIL.MakePath("sample.route");
//}
//else if (files.Count() == 1)
//{
// fn = files.First().FullName;
//}
//if (fn.isEmpty() == false)
//{
// var fi = new System.IO.FileInfo(AR.UTIL.CurrentPath + "\\sample.route");
// if (fi.Exists)
// {
// PUB.log.Add($"autoload : {fi.FullName}");
// var rlt = PUB.mapctl.LoadFromFile(fi.FullName, out string errmsg);
// if (rlt == false) AR.UTIL.MsgE(errmsg);
// }
//}
this.timer1.Start();
}
@@ -107,7 +205,7 @@ namespace Project.ViewForm
}
bool tmrun = false;
private void fAuto_VisibleChanged(object sender, EventArgs e)
{
this.timer1.Enabled = this.Visible;