refactor: Consolidate RFID mapping and add bidirectional pathfinding
Major improvements to AGV navigation system: • Consolidated RFID management into MapNode, removing duplicate RfidMapping class • Enhanced MapNode with RFID metadata fields (RfidStatus, RfidDescription) • Added automatic bidirectional connection generation in pathfinding algorithms • Updated all components to use unified MapNode-based RFID system • Added command line argument support for AGVMapEditor auto-loading files • Fixed pathfinding failures by ensuring proper node connectivity Technical changes: - Removed RfidMapping class and dependencies across all projects - Updated AStarPathfinder with EnsureBidirectionalConnections() method - Modified MapLoader to use AssignAutoRfidIds() for RFID automation - Enhanced UnifiedAGVCanvas, SimulatorForm, and MainForm for MapNode integration - Improved data consistency and reduced memory footprint 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
41
Cs_HMI/AGVNavigationCore/Controls/UnifiedAGVCanvas.Designer.cs
generated
Normal file
41
Cs_HMI/AGVNavigationCore/Controls/UnifiedAGVCanvas.Designer.cs
generated
Normal file
@@ -0,0 +1,41 @@
|
||||
namespace AGVNavigationCore.Controls
|
||||
{
|
||||
partial class UnifiedAGVCanvas
|
||||
{
|
||||
/// <summary>
|
||||
/// 필수 디자이너 변수입니다.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
|
||||
#region 구성 요소 디자이너에서 생성한 코드
|
||||
|
||||
/// <summary>
|
||||
/// 디자이너 지원에 필요한 메서드입니다.
|
||||
/// 이 메서드의 내용을 코드 편집기로 수정하지 마세요.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// UnifiedAGVCanvas
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.Color.White;
|
||||
this.Name = "UnifiedAGVCanvas";
|
||||
this.Size = new System.Drawing.Size(800, 600);
|
||||
this.Paint += new System.Windows.Forms.PaintEventHandler(this.UnifiedAGVCanvas_Paint);
|
||||
this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.UnifiedAGVCanvas_MouseClick);
|
||||
this.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.UnifiedAGVCanvas_MouseDoubleClick);
|
||||
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.UnifiedAGVCanvas_MouseDown);
|
||||
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.UnifiedAGVCanvas_MouseMove);
|
||||
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.UnifiedAGVCanvas_MouseUp);
|
||||
this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.UnifiedAGVCanvas_MouseWheel);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
801
Cs_HMI/AGVNavigationCore/Controls/UnifiedAGVCanvas.Events.cs
Normal file
801
Cs_HMI/AGVNavigationCore/Controls/UnifiedAGVCanvas.Events.cs
Normal file
@@ -0,0 +1,801 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using AGVNavigationCore.Models;
|
||||
using AGVNavigationCore.PathFinding;
|
||||
|
||||
namespace AGVNavigationCore.Controls
|
||||
{
|
||||
public partial class UnifiedAGVCanvas
|
||||
{
|
||||
#region Paint Events
|
||||
|
||||
private void UnifiedAGVCanvas_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
var g = e.Graphics;
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
g.InterpolationMode = InterpolationMode.High;
|
||||
|
||||
// 변환 행렬 설정 (줌 및 팬)
|
||||
var transform = new Matrix();
|
||||
transform.Scale(_zoomFactor, _zoomFactor);
|
||||
transform.Translate(_panOffset.X, _panOffset.Y);
|
||||
g.Transform = transform;
|
||||
|
||||
try
|
||||
{
|
||||
// 그리드 그리기
|
||||
if (_showGrid)
|
||||
{
|
||||
DrawGrid(g);
|
||||
}
|
||||
|
||||
// 노드 연결선 그리기
|
||||
DrawConnections(g);
|
||||
|
||||
// 경로 그리기
|
||||
DrawPaths(g);
|
||||
|
||||
// 노드 그리기
|
||||
DrawNodes(g);
|
||||
|
||||
// AGV 그리기
|
||||
DrawAGVs(g);
|
||||
|
||||
// 임시 연결선 그리기 (편집 모드)
|
||||
if (_canvasMode == CanvasMode.Edit && _isConnectionMode)
|
||||
{
|
||||
DrawTemporaryConnection(g);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
g.Transform = new Matrix(); // 변환 행렬 리셋
|
||||
}
|
||||
|
||||
// UI 정보 그리기 (변환 없이)
|
||||
DrawUIInfo(g);
|
||||
}
|
||||
|
||||
private void DrawGrid(Graphics g)
|
||||
{
|
||||
if (!_showGrid) return;
|
||||
|
||||
var bounds = GetVisibleBounds();
|
||||
var gridSize = (int)(GRID_SIZE * _zoomFactor);
|
||||
|
||||
if (gridSize < 5) return; // 너무 작으면 그리지 않음
|
||||
|
||||
for (int x = bounds.Left; x < bounds.Right; x += GRID_SIZE)
|
||||
{
|
||||
if (x % (GRID_SIZE * 5) == 0)
|
||||
g.DrawLine(new Pen(Color.Gray, 1), x, bounds.Top, x, bounds.Bottom);
|
||||
else
|
||||
g.DrawLine(_gridPen, x, bounds.Top, x, bounds.Bottom);
|
||||
}
|
||||
|
||||
for (int y = bounds.Top; y < bounds.Bottom; y += GRID_SIZE)
|
||||
{
|
||||
if (y % (GRID_SIZE * 5) == 0)
|
||||
g.DrawLine(new Pen(Color.Gray, 1), bounds.Left, y, bounds.Right, y);
|
||||
else
|
||||
g.DrawLine(_gridPen, bounds.Left, y, bounds.Right, y);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawConnections(Graphics g)
|
||||
{
|
||||
if (_nodes == null) return;
|
||||
|
||||
foreach (var node in _nodes)
|
||||
{
|
||||
if (node.ConnectedNodes == null) continue;
|
||||
|
||||
foreach (var connectedNodeId in node.ConnectedNodes)
|
||||
{
|
||||
var targetNode = _nodes.FirstOrDefault(n => n.NodeId == connectedNodeId);
|
||||
if (targetNode == null) continue;
|
||||
|
||||
DrawConnection(g, node, targetNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawConnection(Graphics g, MapNode fromNode, MapNode toNode)
|
||||
{
|
||||
var startPoint = fromNode.Position;
|
||||
var endPoint = toNode.Position;
|
||||
|
||||
// 연결선만 그리기 (단순한 도로 연결, 방향성 없음)
|
||||
g.DrawLine(_connectionPen, startPoint, endPoint);
|
||||
}
|
||||
|
||||
private void DrawDirectionArrow(Graphics g, Point point, double angle, AgvDirection direction)
|
||||
{
|
||||
var arrowSize = CONNECTION_ARROW_SIZE;
|
||||
var arrowAngle = Math.PI / 6; // 30도
|
||||
|
||||
var cos = Math.Cos(angle);
|
||||
var sin = Math.Sin(angle);
|
||||
|
||||
var arrowPoint1 = new Point(
|
||||
(int)(point.X - arrowSize * Math.Cos(angle - arrowAngle)),
|
||||
(int)(point.Y - arrowSize * Math.Sin(angle - arrowAngle))
|
||||
);
|
||||
|
||||
var arrowPoint2 = new Point(
|
||||
(int)(point.X - arrowSize * Math.Cos(angle + arrowAngle)),
|
||||
(int)(point.Y - arrowSize * Math.Sin(angle + arrowAngle))
|
||||
);
|
||||
|
||||
var arrowColor = direction == AgvDirection.Forward ? Color.Blue : Color.Red;
|
||||
var arrowPen = new Pen(arrowColor, 2);
|
||||
|
||||
g.DrawLine(arrowPen, point, arrowPoint1);
|
||||
g.DrawLine(arrowPen, point, arrowPoint2);
|
||||
|
||||
arrowPen.Dispose();
|
||||
}
|
||||
|
||||
private void DrawPaths(Graphics g)
|
||||
{
|
||||
// 모든 경로 그리기
|
||||
if (_allPaths != null)
|
||||
{
|
||||
foreach (var path in _allPaths)
|
||||
{
|
||||
DrawPath(g, path, Color.LightBlue);
|
||||
}
|
||||
}
|
||||
|
||||
// 현재 선택된 경로 그리기
|
||||
if (_currentPath != null)
|
||||
{
|
||||
DrawPath(g, _currentPath, Color.Purple);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawPath(Graphics g, PathResult path, Color color)
|
||||
{
|
||||
if (path?.Path == null || path.Path.Count < 2) return;
|
||||
|
||||
var pathPen = new Pen(color, 4) { DashStyle = DashStyle.Dash };
|
||||
|
||||
for (int i = 0; i < path.Path.Count - 1; i++)
|
||||
{
|
||||
var currentNodeId = path.Path[i];
|
||||
var nextNodeId = path.Path[i + 1];
|
||||
|
||||
var currentNode = _nodes?.FirstOrDefault(n => n.NodeId == currentNodeId);
|
||||
var nextNode = _nodes?.FirstOrDefault(n => n.NodeId == nextNodeId);
|
||||
|
||||
if (currentNode != null && nextNode != null)
|
||||
{
|
||||
// 경로 선 그리기
|
||||
g.DrawLine(pathPen, currentNode.Position, nextNode.Position);
|
||||
|
||||
// 경로 방향 표시 (계산된 경로의 경우에만 방향 화살표 표시)
|
||||
var midPoint = new Point(
|
||||
(currentNode.Position.X + nextNode.Position.X) / 2,
|
||||
(currentNode.Position.Y + nextNode.Position.Y) / 2
|
||||
);
|
||||
|
||||
var angle = Math.Atan2(nextNode.Position.Y - currentNode.Position.Y,
|
||||
nextNode.Position.X - currentNode.Position.X);
|
||||
DrawDirectionArrow(g, midPoint, angle, AgvDirection.Forward);
|
||||
}
|
||||
}
|
||||
|
||||
pathPen.Dispose();
|
||||
}
|
||||
|
||||
private void DrawNodes(Graphics g)
|
||||
{
|
||||
if (_nodes == null) return;
|
||||
|
||||
foreach (var node in _nodes)
|
||||
{
|
||||
DrawNode(g, node);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawNode(Graphics g, MapNode node)
|
||||
{
|
||||
switch (node.Type)
|
||||
{
|
||||
case NodeType.Label:
|
||||
DrawLabelNode(g, node);
|
||||
break;
|
||||
case NodeType.Image:
|
||||
DrawImageNode(g, node);
|
||||
break;
|
||||
default:
|
||||
DrawCircularNode(g, node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawCircularNode(Graphics g, MapNode node)
|
||||
{
|
||||
var brush = GetNodeBrush(node);
|
||||
|
||||
switch (node.Type)
|
||||
{
|
||||
case NodeType.Docking:
|
||||
DrawPentagonNode(g, node, brush);
|
||||
break;
|
||||
case NodeType.Charging:
|
||||
DrawTriangleNode(g, node, brush);
|
||||
break;
|
||||
default:
|
||||
DrawCircleNode(g, node, brush);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawCircleNode(Graphics g, MapNode node, Brush brush)
|
||||
{
|
||||
var rect = new Rectangle(
|
||||
node.Position.X - NODE_RADIUS,
|
||||
node.Position.Y - NODE_RADIUS,
|
||||
NODE_SIZE,
|
||||
NODE_SIZE
|
||||
);
|
||||
|
||||
// 노드 그리기
|
||||
g.FillEllipse(brush, rect);
|
||||
g.DrawEllipse(Pens.Black, rect);
|
||||
|
||||
// 선택된 노드 강조
|
||||
if (node == _selectedNode)
|
||||
{
|
||||
g.DrawEllipse(_selectedNodePen, rect);
|
||||
}
|
||||
|
||||
// 호버된 노드 강조
|
||||
if (node == _hoveredNode)
|
||||
{
|
||||
var hoverRect = new Rectangle(rect.X - 2, rect.Y - 2, rect.Width + 4, rect.Height + 4);
|
||||
g.DrawEllipse(new Pen(Color.Orange, 2), hoverRect);
|
||||
}
|
||||
|
||||
DrawNodeLabel(g, node);
|
||||
}
|
||||
|
||||
private void DrawPentagonNode(Graphics g, MapNode node, Brush brush)
|
||||
{
|
||||
var radius = NODE_RADIUS;
|
||||
var center = node.Position;
|
||||
|
||||
// 5각형 꼭짓점 계산 (위쪽부터 시계방향)
|
||||
var points = new Point[5];
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var angle = (Math.PI * 2 * i / 5) - Math.PI / 2; // -90도부터 시작 (위쪽)
|
||||
points[i] = new Point(
|
||||
(int)(center.X + radius * Math.Cos(angle)),
|
||||
(int)(center.Y + radius * Math.Sin(angle))
|
||||
);
|
||||
}
|
||||
|
||||
// 5각형 그리기
|
||||
g.FillPolygon(brush, points);
|
||||
g.DrawPolygon(Pens.Black, points);
|
||||
|
||||
// 선택된 노드 강조
|
||||
if (node == _selectedNode)
|
||||
{
|
||||
g.DrawPolygon(_selectedNodePen, points);
|
||||
}
|
||||
|
||||
// 호버된 노드 강조
|
||||
if (node == _hoveredNode)
|
||||
{
|
||||
// 확장된 5각형 계산
|
||||
var hoverPoints = new Point[5];
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var angle = (Math.PI * 2 * i / 5) - Math.PI / 2;
|
||||
hoverPoints[i] = new Point(
|
||||
(int)(center.X + (radius + 3) * Math.Cos(angle)),
|
||||
(int)(center.Y + (radius + 3) * Math.Sin(angle))
|
||||
);
|
||||
}
|
||||
g.DrawPolygon(new Pen(Color.Orange, 2), hoverPoints);
|
||||
}
|
||||
|
||||
DrawNodeLabel(g, node);
|
||||
}
|
||||
|
||||
private void DrawTriangleNode(Graphics g, MapNode node, Brush brush)
|
||||
{
|
||||
var radius = NODE_RADIUS;
|
||||
var center = node.Position;
|
||||
|
||||
// 삼각형 꼭짓점 계산 (위쪽 꼭짓점부터 시계방향)
|
||||
var points = new Point[3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
var angle = (Math.PI * 2 * i / 3) - Math.PI / 2; // -90도부터 시작 (위쪽)
|
||||
points[i] = new Point(
|
||||
(int)(center.X + radius * Math.Cos(angle)),
|
||||
(int)(center.Y + radius * Math.Sin(angle))
|
||||
);
|
||||
}
|
||||
|
||||
// 삼각형 그리기
|
||||
g.FillPolygon(brush, points);
|
||||
g.DrawPolygon(Pens.Black, points);
|
||||
|
||||
// 선택된 노드 강조
|
||||
if (node == _selectedNode)
|
||||
{
|
||||
g.DrawPolygon(_selectedNodePen, points);
|
||||
}
|
||||
|
||||
// 호버된 노드 강조
|
||||
if (node == _hoveredNode)
|
||||
{
|
||||
// 확장된 삼각형 계산
|
||||
var hoverPoints = new Point[3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
var angle = (Math.PI * 2 * i / 3) - Math.PI / 2;
|
||||
hoverPoints[i] = new Point(
|
||||
(int)(center.X + (radius + 3) * Math.Cos(angle)),
|
||||
(int)(center.Y + (radius + 3) * Math.Sin(angle))
|
||||
);
|
||||
}
|
||||
g.DrawPolygon(new Pen(Color.Orange, 2), hoverPoints);
|
||||
}
|
||||
|
||||
DrawNodeLabel(g, node);
|
||||
}
|
||||
|
||||
private void DrawNodeLabel(Graphics g, MapNode node)
|
||||
{
|
||||
string displayText;
|
||||
Color textColor;
|
||||
string descriptionText;
|
||||
|
||||
// 위쪽에 표시할 설명 (노드의 Description 속성)
|
||||
descriptionText = string.IsNullOrEmpty(node.Description) ? "" : node.Description;
|
||||
|
||||
// 아래쪽에 표시할 값 (RFID 우선, 없으면 노드ID)
|
||||
if (node.HasRfid())
|
||||
{
|
||||
// RFID가 있는 경우: 순수 RFID 값만 표시 (진한 색상)
|
||||
displayText = node.RfidId;
|
||||
textColor = Color.Black;
|
||||
}
|
||||
else
|
||||
{
|
||||
// RFID가 없는 경우: 노드 ID 표시 (연한 색상)
|
||||
displayText = node.NodeId;
|
||||
textColor = Color.Gray;
|
||||
}
|
||||
|
||||
var font = new Font("Arial", 8, FontStyle.Bold);
|
||||
var descFont = new Font("Arial", 6, FontStyle.Regular);
|
||||
|
||||
// 메인 텍스트 크기 측정
|
||||
var textSize = g.MeasureString(displayText, font);
|
||||
var descSize = g.MeasureString(descriptionText, descFont);
|
||||
|
||||
// 설명 텍스트 위치 (노드 위쪽)
|
||||
var descPoint = new Point(
|
||||
(int)(node.Position.X - descSize.Width / 2),
|
||||
(int)(node.Position.Y - NODE_RADIUS - descSize.Height - 2)
|
||||
);
|
||||
|
||||
// 메인 텍스트 위치 (노드 아래쪽)
|
||||
var textPoint = new Point(
|
||||
(int)(node.Position.X - textSize.Width / 2),
|
||||
(int)(node.Position.Y + NODE_RADIUS + 2)
|
||||
);
|
||||
|
||||
// 설명 텍스트 그리기 (설명이 있는 경우에만)
|
||||
if (!string.IsNullOrEmpty(descriptionText))
|
||||
{
|
||||
using (var descBrush = new SolidBrush(Color.FromArgb(120, Color.Black)))
|
||||
{
|
||||
g.DrawString(descriptionText, descFont, descBrush, descPoint);
|
||||
}
|
||||
}
|
||||
|
||||
// 메인 텍스트 그리기
|
||||
using (var textBrush = new SolidBrush(textColor))
|
||||
{
|
||||
g.DrawString(displayText, font, textBrush, textPoint);
|
||||
}
|
||||
|
||||
font.Dispose();
|
||||
descFont.Dispose();
|
||||
}
|
||||
|
||||
private void DrawLabelNode(Graphics g, MapNode node)
|
||||
{
|
||||
var text = string.IsNullOrEmpty(node.LabelText) ? node.NodeId : node.LabelText;
|
||||
|
||||
// 폰트 설정
|
||||
var font = new Font(node.FontFamily, node.FontSize, node.FontStyle);
|
||||
var textBrush = new SolidBrush(node.ForeColor);
|
||||
|
||||
// 텍스트 크기 측정
|
||||
var textSize = g.MeasureString(text, font);
|
||||
var textPoint = new Point(
|
||||
(int)(node.Position.X - textSize.Width / 2),
|
||||
(int)(node.Position.Y - textSize.Height / 2)
|
||||
);
|
||||
|
||||
// 배경 그리기 (설정된 경우)
|
||||
if (node.ShowBackground)
|
||||
{
|
||||
var backgroundBrush = new SolidBrush(node.BackColor);
|
||||
var backgroundRect = new Rectangle(
|
||||
textPoint.X - 2,
|
||||
textPoint.Y - 2,
|
||||
(int)textSize.Width + 4,
|
||||
(int)textSize.Height + 4
|
||||
);
|
||||
g.FillRectangle(backgroundBrush, backgroundRect);
|
||||
g.DrawRectangle(Pens.Black, backgroundRect);
|
||||
backgroundBrush.Dispose();
|
||||
}
|
||||
|
||||
// 텍스트 그리기
|
||||
g.DrawString(text, font, textBrush, textPoint);
|
||||
|
||||
// 선택된 노드 강조
|
||||
if (node == _selectedNode)
|
||||
{
|
||||
var selectionRect = new Rectangle(
|
||||
textPoint.X - 4,
|
||||
textPoint.Y - 4,
|
||||
(int)textSize.Width + 8,
|
||||
(int)textSize.Height + 8
|
||||
);
|
||||
g.DrawRectangle(_selectedNodePen, selectionRect);
|
||||
}
|
||||
|
||||
// 호버된 노드 강조
|
||||
if (node == _hoveredNode)
|
||||
{
|
||||
var hoverRect = new Rectangle(
|
||||
textPoint.X - 6,
|
||||
textPoint.Y - 6,
|
||||
(int)textSize.Width + 12,
|
||||
(int)textSize.Height + 12
|
||||
);
|
||||
g.DrawRectangle(new Pen(Color.Orange, 2), hoverRect);
|
||||
}
|
||||
|
||||
font.Dispose();
|
||||
textBrush.Dispose();
|
||||
}
|
||||
|
||||
private void DrawImageNode(Graphics g, MapNode node)
|
||||
{
|
||||
// 이미지 로드 (필요시)
|
||||
if (node.LoadedImage == null && !string.IsNullOrEmpty(node.ImagePath))
|
||||
{
|
||||
node.LoadImage();
|
||||
}
|
||||
|
||||
if (node.LoadedImage != null)
|
||||
{
|
||||
// 실제 표시 크기 계산
|
||||
var displaySize = node.GetDisplaySize();
|
||||
if (displaySize.IsEmpty)
|
||||
displaySize = new Size(50, 50); // 기본 크기
|
||||
|
||||
var imageRect = new Rectangle(
|
||||
node.Position.X - displaySize.Width / 2,
|
||||
node.Position.Y - displaySize.Height / 2,
|
||||
displaySize.Width,
|
||||
displaySize.Height
|
||||
);
|
||||
|
||||
// 회전이 있는 경우
|
||||
if (node.Rotation != 0)
|
||||
{
|
||||
var oldTransform = g.Transform;
|
||||
g.TranslateTransform(node.Position.X, node.Position.Y);
|
||||
g.RotateTransform(node.Rotation);
|
||||
g.TranslateTransform(-node.Position.X, -node.Position.Y);
|
||||
|
||||
// 투명도 적용하여 이미지 그리기
|
||||
if (node.Opacity < 1.0f)
|
||||
{
|
||||
var imageAttributes = new System.Drawing.Imaging.ImageAttributes();
|
||||
var colorMatrix = new System.Drawing.Imaging.ColorMatrix();
|
||||
colorMatrix.Matrix33 = node.Opacity;
|
||||
imageAttributes.SetColorMatrix(colorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default,
|
||||
System.Drawing.Imaging.ColorAdjustType.Bitmap);
|
||||
g.DrawImage(node.LoadedImage, imageRect, 0, 0, node.LoadedImage.Width, node.LoadedImage.Height,
|
||||
GraphicsUnit.Pixel, imageAttributes);
|
||||
imageAttributes.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
g.DrawImage(node.LoadedImage, imageRect);
|
||||
}
|
||||
|
||||
g.Transform = oldTransform;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 투명도 적용하여 이미지 그리기
|
||||
if (node.Opacity < 1.0f)
|
||||
{
|
||||
var imageAttributes = new System.Drawing.Imaging.ImageAttributes();
|
||||
var colorMatrix = new System.Drawing.Imaging.ColorMatrix();
|
||||
colorMatrix.Matrix33 = node.Opacity;
|
||||
imageAttributes.SetColorMatrix(colorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default,
|
||||
System.Drawing.Imaging.ColorAdjustType.Bitmap);
|
||||
g.DrawImage(node.LoadedImage, imageRect, 0, 0, node.LoadedImage.Width, node.LoadedImage.Height,
|
||||
GraphicsUnit.Pixel, imageAttributes);
|
||||
imageAttributes.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
g.DrawImage(node.LoadedImage, imageRect);
|
||||
}
|
||||
}
|
||||
|
||||
// 선택된 노드 강조
|
||||
if (node == _selectedNode)
|
||||
{
|
||||
g.DrawRectangle(_selectedNodePen, imageRect);
|
||||
}
|
||||
|
||||
// 호버된 노드 강조
|
||||
if (node == _hoveredNode)
|
||||
{
|
||||
var hoverRect = new Rectangle(imageRect.X - 2, imageRect.Y - 2, imageRect.Width + 4, imageRect.Height + 4);
|
||||
g.DrawRectangle(new Pen(Color.Orange, 2), hoverRect);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// 이미지가 없는 경우 기본 사각형으로 표시
|
||||
var rect = new Rectangle(
|
||||
node.Position.X - 25,
|
||||
node.Position.Y - 25,
|
||||
50,
|
||||
50
|
||||
);
|
||||
|
||||
g.FillRectangle(Brushes.LightGray, rect);
|
||||
g.DrawRectangle(Pens.Black, rect);
|
||||
|
||||
// "이미지 없음" 텍스트
|
||||
var font = new Font("Arial", 8);
|
||||
var text = "No Image";
|
||||
var textSize = g.MeasureString(text, font);
|
||||
var textPoint = new Point(
|
||||
(int)(node.Position.X - textSize.Width / 2),
|
||||
(int)(node.Position.Y - textSize.Height / 2)
|
||||
);
|
||||
g.DrawString(text, font, Brushes.Black, textPoint);
|
||||
font.Dispose();
|
||||
|
||||
// 선택된 노드 강조
|
||||
if (node == _selectedNode)
|
||||
{
|
||||
g.DrawRectangle(_selectedNodePen, rect);
|
||||
}
|
||||
|
||||
// 호버된 노드 강조
|
||||
if (node == _hoveredNode)
|
||||
{
|
||||
var hoverRect = new Rectangle(rect.X - 2, rect.Y - 2, rect.Width + 4, rect.Height + 4);
|
||||
g.DrawRectangle(new Pen(Color.Orange, 2), hoverRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Brush GetNodeBrush(MapNode node)
|
||||
{
|
||||
switch (node.Type)
|
||||
{
|
||||
case NodeType.Normal:
|
||||
return _normalNodeBrush;
|
||||
case NodeType.Rotation:
|
||||
return _rotationNodeBrush;
|
||||
case NodeType.Docking:
|
||||
return _dockingNodeBrush;
|
||||
case NodeType.Charging:
|
||||
return _chargingNodeBrush;
|
||||
case NodeType.Label:
|
||||
return new SolidBrush(Color.Purple);
|
||||
case NodeType.Image:
|
||||
return new SolidBrush(Color.Brown);
|
||||
default:
|
||||
return _normalNodeBrush;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawAGVs(Graphics g)
|
||||
{
|
||||
if (_agvList == null) return;
|
||||
|
||||
foreach (var agv in _agvList)
|
||||
{
|
||||
if (_agvPositions.ContainsKey(agv.AgvId))
|
||||
{
|
||||
DrawAGV(g, agv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawAGV(Graphics g, IAGV agv)
|
||||
{
|
||||
if (!_agvPositions.ContainsKey(agv.AgvId)) return;
|
||||
|
||||
var position = _agvPositions[agv.AgvId];
|
||||
var direction = _agvDirections.ContainsKey(agv.AgvId) ? _agvDirections[agv.AgvId] : AgvDirection.Forward;
|
||||
var state = _agvStates.ContainsKey(agv.AgvId) ? _agvStates[agv.AgvId] : AGVState.Idle;
|
||||
|
||||
// AGV 색상 결정
|
||||
var brush = GetAGVBrush(state);
|
||||
|
||||
// AGV 사각형 그리기
|
||||
var rect = new Rectangle(
|
||||
position.X - AGV_SIZE / 2,
|
||||
position.Y - AGV_SIZE / 2,
|
||||
AGV_SIZE,
|
||||
AGV_SIZE
|
||||
);
|
||||
|
||||
g.FillRectangle(brush, rect);
|
||||
g.DrawRectangle(_agvPen, rect);
|
||||
|
||||
// 방향 표시 (화살표)
|
||||
DrawAGVDirection(g, position, direction);
|
||||
|
||||
// AGV ID 표시
|
||||
var font = new Font("Arial", 10, FontStyle.Bold);
|
||||
var textSize = g.MeasureString(agv.AgvId, font);
|
||||
var textPoint = new Point(
|
||||
(int)(position.X - textSize.Width / 2),
|
||||
(int)(position.Y - AGV_SIZE / 2 - textSize.Height - 2)
|
||||
);
|
||||
|
||||
g.DrawString(agv.AgvId, font, Brushes.Black, textPoint);
|
||||
|
||||
// 배터리 레벨 표시
|
||||
var batteryText = $"{agv.BatteryLevel:F0}%";
|
||||
var batterySize = g.MeasureString(batteryText, font);
|
||||
var batteryPoint = new Point(
|
||||
(int)(position.X - batterySize.Width / 2),
|
||||
(int)(position.Y + AGV_SIZE / 2 + 2)
|
||||
);
|
||||
|
||||
g.DrawString(batteryText, font, Brushes.Black, batteryPoint);
|
||||
font.Dispose();
|
||||
}
|
||||
|
||||
private Brush GetAGVBrush(AGVState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case AGVState.Idle:
|
||||
return Brushes.LightGray;
|
||||
case AGVState.Moving:
|
||||
return Brushes.LightGreen;
|
||||
case AGVState.Rotating:
|
||||
return Brushes.Yellow;
|
||||
case AGVState.Docking:
|
||||
return Brushes.Orange;
|
||||
case AGVState.Charging:
|
||||
return Brushes.Blue;
|
||||
case AGVState.Error:
|
||||
return Brushes.Red;
|
||||
default:
|
||||
return Brushes.LightGray;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawAGVDirection(Graphics g, Point position, AgvDirection direction)
|
||||
{
|
||||
var arrowSize = 10;
|
||||
Point[] arrowPoints = null;
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case AgvDirection.Forward:
|
||||
arrowPoints = new Point[]
|
||||
{
|
||||
new Point(position.X + arrowSize, position.Y),
|
||||
new Point(position.X - arrowSize/2, position.Y - arrowSize/2),
|
||||
new Point(position.X - arrowSize/2, position.Y + arrowSize/2)
|
||||
};
|
||||
break;
|
||||
case AgvDirection.Backward:
|
||||
arrowPoints = new Point[]
|
||||
{
|
||||
new Point(position.X - arrowSize, position.Y),
|
||||
new Point(position.X + arrowSize/2, position.Y - arrowSize/2),
|
||||
new Point(position.X + arrowSize/2, position.Y + arrowSize/2)
|
||||
};
|
||||
break;
|
||||
}
|
||||
|
||||
if (arrowPoints != null)
|
||||
{
|
||||
g.FillPolygon(Brushes.White, arrowPoints);
|
||||
g.DrawPolygon(Pens.Black, arrowPoints);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawTemporaryConnection(Graphics g)
|
||||
{
|
||||
if (_connectionStartNode != null && _connectionEndPoint != Point.Empty)
|
||||
{
|
||||
g.DrawLine(_tempConnectionPen, _connectionStartNode.Position, _connectionEndPoint);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawUIInfo(Graphics g)
|
||||
{
|
||||
// 회사 로고
|
||||
if (_companyLogo != null)
|
||||
{
|
||||
var logoRect = new Rectangle(10, 10, 100, 50);
|
||||
g.DrawImage(_companyLogo, logoRect);
|
||||
}
|
||||
|
||||
// 측정 정보
|
||||
if (!string.IsNullOrEmpty(_measurementInfo))
|
||||
{
|
||||
var font = new Font("Arial", 9);
|
||||
var textBrush = new SolidBrush(Color.Black);
|
||||
var backgroundBrush = new SolidBrush(Color.FromArgb(200, Color.White));
|
||||
|
||||
var textSize = g.MeasureString(_measurementInfo, font);
|
||||
var textRect = new Rectangle(
|
||||
Width - (int)textSize.Width - 20,
|
||||
Height - (int)textSize.Height - 20,
|
||||
(int)textSize.Width + 10,
|
||||
(int)textSize.Height + 10
|
||||
);
|
||||
|
||||
g.FillRectangle(backgroundBrush, textRect);
|
||||
g.DrawRectangle(Pens.Gray, textRect);
|
||||
g.DrawString(_measurementInfo, font, textBrush, textRect.X + 5, textRect.Y + 5);
|
||||
|
||||
font.Dispose();
|
||||
textBrush.Dispose();
|
||||
backgroundBrush.Dispose();
|
||||
}
|
||||
|
||||
// 줌 정보
|
||||
var zoomText = $"Zoom: {_zoomFactor:P0}";
|
||||
var zoomFont = new Font("Arial", 10, FontStyle.Bold);
|
||||
var zoomSize = g.MeasureString(zoomText, zoomFont);
|
||||
var zoomPoint = new Point(10, Height - (int)zoomSize.Height - 10);
|
||||
|
||||
g.FillRectangle(new SolidBrush(Color.FromArgb(200, Color.White)),
|
||||
zoomPoint.X - 5, zoomPoint.Y - 5,
|
||||
zoomSize.Width + 10, zoomSize.Height + 10);
|
||||
g.DrawString(zoomText, zoomFont, Brushes.Black, zoomPoint);
|
||||
zoomFont.Dispose();
|
||||
}
|
||||
|
||||
private Rectangle GetVisibleBounds()
|
||||
{
|
||||
var left = (int)(-_panOffset.X / _zoomFactor);
|
||||
var top = (int)(-_panOffset.Y / _zoomFactor);
|
||||
var right = (int)((Width - _panOffset.X) / _zoomFactor);
|
||||
var bottom = (int)((Height - _panOffset.Y) / _zoomFactor);
|
||||
|
||||
return new Rectangle(left, top, right - left, bottom - top);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
605
Cs_HMI/AGVNavigationCore/Controls/UnifiedAGVCanvas.Mouse.cs
Normal file
605
Cs_HMI/AGVNavigationCore/Controls/UnifiedAGVCanvas.Mouse.cs
Normal file
@@ -0,0 +1,605 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using AGVNavigationCore.Models;
|
||||
|
||||
namespace AGVNavigationCore.Controls
|
||||
{
|
||||
public partial class UnifiedAGVCanvas
|
||||
{
|
||||
#region Mouse Events
|
||||
|
||||
private void UnifiedAGVCanvas_MouseClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
Focus(); // 포커스 설정
|
||||
|
||||
if (_canvasMode == CanvasMode.ViewOnly) return;
|
||||
|
||||
var worldPoint = ScreenToWorld(e.Location);
|
||||
var hitNode = GetNodeAt(worldPoint);
|
||||
|
||||
switch (_editMode)
|
||||
{
|
||||
case EditMode.Select:
|
||||
HandleSelectClick(hitNode);
|
||||
break;
|
||||
|
||||
case EditMode.AddNode:
|
||||
HandleAddNodeClick(worldPoint);
|
||||
break;
|
||||
|
||||
case EditMode.Connect:
|
||||
HandleConnectClick(hitNode);
|
||||
break;
|
||||
|
||||
case EditMode.Delete:
|
||||
HandleDeleteClick(hitNode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void UnifiedAGVCanvas_MouseDoubleClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (_canvasMode == CanvasMode.ViewOnly) return;
|
||||
|
||||
var worldPoint = ScreenToWorld(e.Location);
|
||||
var hitNode = GetNodeAt(worldPoint);
|
||||
|
||||
if (hitNode != null)
|
||||
{
|
||||
// 노드 속성 편집 (이벤트 발생)
|
||||
NodeSelected?.Invoke(this, hitNode);
|
||||
}
|
||||
}
|
||||
|
||||
private void UnifiedAGVCanvas_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
var worldPoint = ScreenToWorld(e.Location);
|
||||
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
if (_canvasMode == CanvasMode.Edit && _editMode == EditMode.Move)
|
||||
{
|
||||
var hitNode = GetNodeAt(worldPoint);
|
||||
if (hitNode != null)
|
||||
{
|
||||
_isDragging = true;
|
||||
_selectedNode = hitNode;
|
||||
_dragOffset = new Point(
|
||||
worldPoint.X - hitNode.Position.X,
|
||||
worldPoint.Y - hitNode.Position.Y
|
||||
);
|
||||
Cursor = Cursors.SizeAll;
|
||||
Invalidate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 팬 시작 (우클릭 또는 중간버튼)
|
||||
_isPanning = true;
|
||||
_lastMousePosition = e.Location;
|
||||
Cursor = Cursors.SizeAll;
|
||||
}
|
||||
else if (e.Button == MouseButtons.Right)
|
||||
{
|
||||
// 컨텍스트 메뉴 (편집 모드에서만)
|
||||
if (_canvasMode == CanvasMode.Edit)
|
||||
{
|
||||
var hitNode = GetNodeAt(worldPoint);
|
||||
ShowContextMenu(e.Location, hitNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UnifiedAGVCanvas_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
var worldPoint = ScreenToWorld(e.Location);
|
||||
|
||||
// 호버 노드 업데이트
|
||||
var newHoveredNode = GetNodeAt(worldPoint);
|
||||
if (newHoveredNode != _hoveredNode)
|
||||
{
|
||||
_hoveredNode = newHoveredNode;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
if (_isPanning)
|
||||
{
|
||||
// 팬 처리
|
||||
var deltaX = e.X - _lastMousePosition.X;
|
||||
var deltaY = e.Y - _lastMousePosition.Y;
|
||||
|
||||
_panOffset.X += deltaX;
|
||||
_panOffset.Y += deltaY;
|
||||
|
||||
_lastMousePosition = e.Location;
|
||||
Invalidate();
|
||||
}
|
||||
else if (_isDragging && _canvasMode == CanvasMode.Edit)
|
||||
{
|
||||
// 노드 드래그
|
||||
if (_selectedNode != null)
|
||||
{
|
||||
var newPosition = new Point(
|
||||
worldPoint.X - _dragOffset.X,
|
||||
worldPoint.Y - _dragOffset.Y
|
||||
);
|
||||
|
||||
// 그리드 스냅
|
||||
if (ModifierKeys.HasFlag(Keys.Control))
|
||||
{
|
||||
newPosition.X = (newPosition.X / GRID_SIZE) * GRID_SIZE;
|
||||
newPosition.Y = (newPosition.Y / GRID_SIZE) * GRID_SIZE;
|
||||
}
|
||||
|
||||
_selectedNode.Position = newPosition;
|
||||
NodeMoved?.Invoke(this, _selectedNode);
|
||||
MapChanged?.Invoke(this, EventArgs.Empty);
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
else if (_isConnectionMode && _canvasMode == CanvasMode.Edit)
|
||||
{
|
||||
// 임시 연결선 업데이트
|
||||
_connectionEndPoint = worldPoint;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
// 툴팁 표시 (호버된 노드/AGV 정보)
|
||||
UpdateTooltip(worldPoint);
|
||||
}
|
||||
|
||||
private void UnifiedAGVCanvas_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
if (_isDragging && _canvasMode == CanvasMode.Edit)
|
||||
{
|
||||
_isDragging = false;
|
||||
Cursor = GetCursorForMode(_editMode);
|
||||
}
|
||||
|
||||
if (_isPanning)
|
||||
{
|
||||
_isPanning = false;
|
||||
Cursor = Cursors.Default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UnifiedAGVCanvas_MouseWheel(object sender, MouseEventArgs e)
|
||||
{
|
||||
// 줌 처리
|
||||
var mouseWorldPoint = ScreenToWorld(e.Location);
|
||||
var oldZoom = _zoomFactor;
|
||||
|
||||
if (e.Delta > 0)
|
||||
_zoomFactor = Math.Min(_zoomFactor * 1.2f, 5.0f);
|
||||
else
|
||||
_zoomFactor = Math.Max(_zoomFactor / 1.2f, 0.1f);
|
||||
|
||||
// 마우스 위치를 중심으로 줌
|
||||
var zoomRatio = _zoomFactor / oldZoom;
|
||||
_panOffset.X = (int)(e.X - (e.X - _panOffset.X) * zoomRatio);
|
||||
_panOffset.Y = (int)(e.Y - (e.Y - _panOffset.Y) * zoomRatio);
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Mouse Helper Methods
|
||||
|
||||
private Point ScreenToWorld(Point screenPoint)
|
||||
{
|
||||
return new Point(
|
||||
(int)((screenPoint.X - _panOffset.X) / _zoomFactor),
|
||||
(int)((screenPoint.Y - _panOffset.Y) / _zoomFactor)
|
||||
);
|
||||
}
|
||||
|
||||
private Point WorldToScreen(Point worldPoint)
|
||||
{
|
||||
return new Point(
|
||||
(int)(worldPoint.X * _zoomFactor + _panOffset.X),
|
||||
(int)(worldPoint.Y * _zoomFactor + _panOffset.Y)
|
||||
);
|
||||
}
|
||||
|
||||
private MapNode GetNodeAt(Point worldPoint)
|
||||
{
|
||||
if (_nodes == null) return null;
|
||||
|
||||
// 역순으로 검사하여 위에 그려진 노드부터 확인
|
||||
for (int i = _nodes.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var node = _nodes[i];
|
||||
if (IsPointInNode(worldPoint, node))
|
||||
return node;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool IsPointInNode(Point point, MapNode node)
|
||||
{
|
||||
switch (node.Type)
|
||||
{
|
||||
case NodeType.Label:
|
||||
return IsPointInLabelNode(point, node);
|
||||
case NodeType.Image:
|
||||
return IsPointInImageNode(point, node);
|
||||
default:
|
||||
return IsPointInCircularNode(point, node);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsPointInCircularNode(Point point, MapNode node)
|
||||
{
|
||||
switch (node.Type)
|
||||
{
|
||||
case NodeType.Docking:
|
||||
return IsPointInPentagon(point, node);
|
||||
case NodeType.Charging:
|
||||
return IsPointInTriangle(point, node);
|
||||
default:
|
||||
return IsPointInCircle(point, node);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsPointInCircle(Point point, MapNode node)
|
||||
{
|
||||
var hitRadius = Math.Max(NODE_RADIUS, 10 / _zoomFactor);
|
||||
var distance = Math.Sqrt(
|
||||
Math.Pow(node.Position.X - point.X, 2) +
|
||||
Math.Pow(node.Position.Y - point.Y, 2)
|
||||
);
|
||||
return distance <= hitRadius;
|
||||
}
|
||||
|
||||
private bool IsPointInPentagon(Point point, MapNode node)
|
||||
{
|
||||
var radius = NODE_RADIUS;
|
||||
var center = node.Position;
|
||||
|
||||
// 5각형 꼭짓점 계산
|
||||
var points = new Point[5];
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var angle = (Math.PI * 2 * i / 5) - Math.PI / 2;
|
||||
points[i] = new Point(
|
||||
(int)(center.X + radius * Math.Cos(angle)),
|
||||
(int)(center.Y + radius * Math.Sin(angle))
|
||||
);
|
||||
}
|
||||
|
||||
return IsPointInPolygon(point, points);
|
||||
}
|
||||
|
||||
private bool IsPointInTriangle(Point point, MapNode node)
|
||||
{
|
||||
var radius = NODE_RADIUS;
|
||||
var center = node.Position;
|
||||
|
||||
// 삼각형 꼭짓점 계산
|
||||
var points = new Point[3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
var angle = (Math.PI * 2 * i / 3) - Math.PI / 2;
|
||||
points[i] = new Point(
|
||||
(int)(center.X + radius * Math.Cos(angle)),
|
||||
(int)(center.Y + radius * Math.Sin(angle))
|
||||
);
|
||||
}
|
||||
|
||||
return IsPointInPolygon(point, points);
|
||||
}
|
||||
|
||||
private bool IsPointInPolygon(Point point, Point[] polygon)
|
||||
{
|
||||
// Ray casting 알고리즘 사용
|
||||
bool inside = false;
|
||||
int j = polygon.Length - 1;
|
||||
|
||||
for (int i = 0; i < polygon.Length; i++)
|
||||
{
|
||||
var xi = polygon[i].X;
|
||||
var yi = polygon[i].Y;
|
||||
var xj = polygon[j].X;
|
||||
var yj = polygon[j].Y;
|
||||
|
||||
if (((yi > point.Y) != (yj > point.Y)) &&
|
||||
(point.X < (xj - xi) * (point.Y - yi) / (yj - yi) + xi))
|
||||
{
|
||||
inside = !inside;
|
||||
}
|
||||
j = i;
|
||||
}
|
||||
|
||||
return inside;
|
||||
}
|
||||
|
||||
private bool IsPointInLabelNode(Point point, MapNode node)
|
||||
{
|
||||
var text = string.IsNullOrEmpty(node.LabelText) ? node.NodeId : node.LabelText;
|
||||
|
||||
// 임시 Graphics로 텍스트 크기 측정
|
||||
using (var tempBitmap = new Bitmap(1, 1))
|
||||
using (var tempGraphics = Graphics.FromImage(tempBitmap))
|
||||
{
|
||||
var font = new Font(node.FontFamily, node.FontSize, node.FontStyle);
|
||||
var textSize = tempGraphics.MeasureString(text, font);
|
||||
|
||||
var textRect = new Rectangle(
|
||||
(int)(node.Position.X - textSize.Width / 2),
|
||||
(int)(node.Position.Y - textSize.Height / 2),
|
||||
(int)textSize.Width,
|
||||
(int)textSize.Height
|
||||
);
|
||||
|
||||
font.Dispose();
|
||||
return textRect.Contains(point);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsPointInImageNode(Point point, MapNode node)
|
||||
{
|
||||
var displaySize = node.GetDisplaySize();
|
||||
if (displaySize.IsEmpty)
|
||||
displaySize = new Size(50, 50); // 기본 크기
|
||||
|
||||
var imageRect = new Rectangle(
|
||||
node.Position.X - displaySize.Width / 2,
|
||||
node.Position.Y - displaySize.Height / 2,
|
||||
displaySize.Width,
|
||||
displaySize.Height
|
||||
);
|
||||
|
||||
return imageRect.Contains(point);
|
||||
}
|
||||
|
||||
private IAGV GetAGVAt(Point worldPoint)
|
||||
{
|
||||
if (_agvList == null) return null;
|
||||
|
||||
var hitRadius = Math.Max(AGV_SIZE / 2, 15 / _zoomFactor);
|
||||
|
||||
return _agvList.FirstOrDefault(agv =>
|
||||
{
|
||||
if (!_agvPositions.ContainsKey(agv.AgvId)) return false;
|
||||
|
||||
var agvPos = _agvPositions[agv.AgvId];
|
||||
var distance = Math.Sqrt(
|
||||
Math.Pow(agvPos.X - worldPoint.X, 2) +
|
||||
Math.Pow(agvPos.Y - worldPoint.Y, 2)
|
||||
);
|
||||
return distance <= hitRadius;
|
||||
});
|
||||
}
|
||||
|
||||
private void HandleSelectClick(MapNode hitNode)
|
||||
{
|
||||
if (hitNode != _selectedNode)
|
||||
{
|
||||
_selectedNode = hitNode;
|
||||
NodeSelected?.Invoke(this, hitNode);
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleAddNodeClick(Point worldPoint)
|
||||
{
|
||||
// 그리드 스냅
|
||||
if (ModifierKeys.HasFlag(Keys.Control))
|
||||
{
|
||||
worldPoint.X = (worldPoint.X / GRID_SIZE) * GRID_SIZE;
|
||||
worldPoint.Y = (worldPoint.Y / GRID_SIZE) * GRID_SIZE;
|
||||
}
|
||||
|
||||
var newNode = new MapNode
|
||||
{
|
||||
NodeId = $"N{_nodeCounter:D3}",
|
||||
Position = worldPoint,
|
||||
Type = NodeType.Normal
|
||||
};
|
||||
|
||||
_nodeCounter++;
|
||||
_nodes.Add(newNode);
|
||||
|
||||
NodeAdded?.Invoke(this, newNode);
|
||||
MapChanged?.Invoke(this, EventArgs.Empty);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
private void HandleConnectClick(MapNode hitNode)
|
||||
{
|
||||
if (hitNode == null) return;
|
||||
|
||||
if (!_isConnectionMode)
|
||||
{
|
||||
// 연결 시작
|
||||
_isConnectionMode = true;
|
||||
_connectionStartNode = hitNode;
|
||||
_selectedNode = hitNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 연결 완료
|
||||
if (_connectionStartNode != null && _connectionStartNode != hitNode)
|
||||
{
|
||||
CreateConnection(_connectionStartNode, hitNode);
|
||||
}
|
||||
CancelConnection();
|
||||
}
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
private void HandleDeleteClick(MapNode hitNode)
|
||||
{
|
||||
if (hitNode == null) return;
|
||||
|
||||
// 연결된 모든 연결선도 제거
|
||||
foreach (var node in _nodes)
|
||||
{
|
||||
node.RemoveConnection(hitNode.NodeId);
|
||||
}
|
||||
|
||||
_nodes.Remove(hitNode);
|
||||
|
||||
if (_selectedNode == hitNode)
|
||||
_selectedNode = null;
|
||||
|
||||
NodeDeleted?.Invoke(this, hitNode);
|
||||
MapChanged?.Invoke(this, EventArgs.Empty);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
private void CreateConnection(MapNode fromNode, MapNode toNode)
|
||||
{
|
||||
// 중복 연결 체크
|
||||
if (fromNode.ConnectedNodes.Contains(toNode.NodeId))
|
||||
return;
|
||||
|
||||
fromNode.AddConnection(toNode.NodeId);
|
||||
MapChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private float CalculateDistance(Point from, Point to)
|
||||
{
|
||||
var dx = to.X - from.X;
|
||||
var dy = to.Y - from.Y;
|
||||
return (float)Math.Sqrt(dx * dx + dy * dy);
|
||||
}
|
||||
|
||||
private void ShowContextMenu(Point location, MapNode hitNode)
|
||||
{
|
||||
_contextMenu.Items.Clear();
|
||||
|
||||
if (hitNode != null)
|
||||
{
|
||||
_contextMenu.Items.Add("노드 속성...", null, (s, e) => NodeSelected?.Invoke(this, hitNode));
|
||||
_contextMenu.Items.Add("노드 삭제", null, (s, e) => HandleDeleteClick(hitNode));
|
||||
_contextMenu.Items.Add("-");
|
||||
}
|
||||
|
||||
_contextMenu.Items.Add("노드 추가", null, (s, e) =>
|
||||
{
|
||||
var worldPoint = ScreenToWorld(location);
|
||||
HandleAddNodeClick(worldPoint);
|
||||
});
|
||||
|
||||
_contextMenu.Items.Add("전체 맞춤", null, (s, e) => FitToNodes());
|
||||
_contextMenu.Items.Add("줌 리셋", null, (s, e) => ResetZoom());
|
||||
|
||||
_contextMenu.Show(this, location);
|
||||
}
|
||||
|
||||
private void UpdateTooltip(Point worldPoint)
|
||||
{
|
||||
string tooltipText = "";
|
||||
|
||||
// 노드 툴팁
|
||||
var hitNode = GetNodeAt(worldPoint);
|
||||
if (hitNode != null)
|
||||
{
|
||||
tooltipText = $"노드: {hitNode.NodeId}\n타입: {hitNode.Type}\n위치: ({hitNode.Position.X}, {hitNode.Position.Y})";
|
||||
}
|
||||
else
|
||||
{
|
||||
// AGV 툴팁
|
||||
var hitAGV = GetAGVAt(worldPoint);
|
||||
if (hitAGV != null)
|
||||
{
|
||||
var state = _agvStates.ContainsKey(hitAGV.AgvId) ? _agvStates[hitAGV.AgvId] : AGVState.Idle;
|
||||
tooltipText = $"AGV: {hitAGV.AgvId}\n상태: {state}\n배터리: {hitAGV.BatteryLevel:F1}%\n위치: ({hitAGV.CurrentPosition.X}, {hitAGV.CurrentPosition.Y})";
|
||||
}
|
||||
}
|
||||
|
||||
// 툴팁 업데이트 (기존 ToolTip 컨트롤 사용)
|
||||
if (!string.IsNullOrEmpty(tooltipText))
|
||||
{
|
||||
// ToolTip 설정 (필요시 추가 구현)
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region View Control Methods
|
||||
|
||||
/// <summary>
|
||||
/// 모든 노드가 보이도록 뷰 조정
|
||||
/// </summary>
|
||||
public void FitToNodes()
|
||||
{
|
||||
if (_nodes == null || _nodes.Count == 0) return;
|
||||
|
||||
var minX = _nodes.Min(n => n.Position.X);
|
||||
var maxX = _nodes.Max(n => n.Position.X);
|
||||
var minY = _nodes.Min(n => n.Position.Y);
|
||||
var maxY = _nodes.Max(n => n.Position.Y);
|
||||
|
||||
var margin = 50;
|
||||
var contentWidth = maxX - minX + margin * 2;
|
||||
var contentHeight = maxY - minY + margin * 2;
|
||||
|
||||
var zoomX = (float)Width / contentWidth;
|
||||
var zoomY = (float)Height / contentHeight;
|
||||
_zoomFactor = Math.Min(zoomX, zoomY) * 0.9f;
|
||||
|
||||
var centerX = (minX + maxX) / 2;
|
||||
var centerY = (minY + maxY) / 2;
|
||||
|
||||
_panOffset.X = (int)(Width / 2 - centerX * _zoomFactor);
|
||||
_panOffset.Y = (int)(Height / 2 - centerY * _zoomFactor);
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 줌 리셋
|
||||
/// </summary>
|
||||
public void ResetZoom()
|
||||
{
|
||||
_zoomFactor = 1.0f;
|
||||
_panOffset = Point.Empty;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 특정 위치로 이동
|
||||
/// </summary>
|
||||
public void PanTo(Point worldPoint)
|
||||
{
|
||||
_panOffset.X = (int)(Width / 2 - worldPoint.X * _zoomFactor);
|
||||
_panOffset.Y = (int)(Height / 2 - worldPoint.Y * _zoomFactor);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 특정 노드로 이동
|
||||
/// </summary>
|
||||
public void PanToNode(string nodeId)
|
||||
{
|
||||
var node = _nodes?.FirstOrDefault(n => n.NodeId == nodeId);
|
||||
if (node != null)
|
||||
{
|
||||
PanTo(node.Position);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 특정 AGV로 이동
|
||||
/// </summary>
|
||||
public void PanToAGV(string agvId)
|
||||
{
|
||||
if (_agvPositions.ContainsKey(agvId))
|
||||
{
|
||||
PanTo(_agvPositions[agvId]);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
536
Cs_HMI/AGVNavigationCore/Controls/UnifiedAGVCanvas.cs
Normal file
536
Cs_HMI/AGVNavigationCore/Controls/UnifiedAGVCanvas.cs
Normal file
@@ -0,0 +1,536 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using AGVNavigationCore.Models;
|
||||
using AGVNavigationCore.PathFinding;
|
||||
|
||||
namespace AGVNavigationCore.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// 통합 AGV 캔버스 컨트롤
|
||||
/// 맵 편집, AGV 시뮬레이션, 실시간 모니터링을 모두 지원
|
||||
/// </summary>
|
||||
public partial class UnifiedAGVCanvas : UserControl
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private const int NODE_SIZE = 24;
|
||||
private const int NODE_RADIUS = NODE_SIZE / 2;
|
||||
private const int GRID_SIZE = 20;
|
||||
private const float CONNECTION_WIDTH = 2.0f;
|
||||
private const int SNAP_DISTANCE = 10;
|
||||
private const int AGV_SIZE = 30;
|
||||
private const int CONNECTION_ARROW_SIZE = 8;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Enums
|
||||
|
||||
/// <summary>
|
||||
/// 캔버스 모드
|
||||
/// </summary>
|
||||
public enum CanvasMode
|
||||
{
|
||||
ViewOnly, // 읽기 전용 (시뮬레이터, 모니터링)
|
||||
Edit // 편집 가능 (맵 에디터)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 편집 모드 (CanvasMode.Edit일 때만 적용)
|
||||
/// </summary>
|
||||
public enum EditMode
|
||||
{
|
||||
Select, // 선택 모드
|
||||
Move, // 이동 모드
|
||||
AddNode, // 노드 추가 모드
|
||||
Connect, // 연결 모드
|
||||
Delete, // 삭제 모드
|
||||
AddLabel, // 라벨 추가 모드
|
||||
AddImage // 이미지 추가 모드
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
// 캔버스 모드
|
||||
private CanvasMode _canvasMode = CanvasMode.ViewOnly;
|
||||
private EditMode _editMode = EditMode.Select;
|
||||
|
||||
// 맵 데이터
|
||||
private List<MapNode> _nodes;
|
||||
private MapNode _selectedNode;
|
||||
private MapNode _hoveredNode;
|
||||
|
||||
// AGV 관련
|
||||
private List<IAGV> _agvList;
|
||||
private Dictionary<string, Point> _agvPositions;
|
||||
private Dictionary<string, AgvDirection> _agvDirections;
|
||||
private Dictionary<string, AGVState> _agvStates;
|
||||
|
||||
// 경로 관련
|
||||
private PathResult _currentPath;
|
||||
private List<PathResult> _allPaths;
|
||||
|
||||
// UI 요소들
|
||||
private Image _companyLogo;
|
||||
private string _companyLogoPath = string.Empty;
|
||||
private string _measurementInfo = "스케일: 1:100\n면적: 1000㎡\n최종 수정: " + DateTime.Now.ToString("yyyy-MM-dd");
|
||||
|
||||
// 편집 관련 (EditMode에서만 사용)
|
||||
private bool _isDragging;
|
||||
private Point _dragOffset;
|
||||
private Point _lastMousePosition;
|
||||
private bool _isConnectionMode;
|
||||
private MapNode _connectionStartNode;
|
||||
private Point _connectionEndPoint;
|
||||
|
||||
// 그리드 및 줌 관련
|
||||
private bool _showGrid = true;
|
||||
private float _zoomFactor = 1.0f;
|
||||
private Point _panOffset = Point.Empty;
|
||||
private bool _isPanning;
|
||||
|
||||
// 자동 증가 카운터
|
||||
private int _nodeCounter = 1;
|
||||
|
||||
|
||||
// 브러쉬 및 펜
|
||||
private Brush _normalNodeBrush;
|
||||
private Brush _rotationNodeBrush;
|
||||
private Brush _dockingNodeBrush;
|
||||
private Brush _chargingNodeBrush;
|
||||
private Brush _selectedNodeBrush;
|
||||
private Brush _hoveredNodeBrush;
|
||||
private Brush _gridBrush;
|
||||
private Brush _agvBrush;
|
||||
private Brush _pathBrush;
|
||||
|
||||
private Pen _connectionPen;
|
||||
private Pen _gridPen;
|
||||
private Pen _tempConnectionPen;
|
||||
private Pen _selectedNodePen;
|
||||
private Pen _pathPen;
|
||||
private Pen _agvPen;
|
||||
|
||||
// 컨텍스트 메뉴
|
||||
private ContextMenuStrip _contextMenu;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
// 맵 편집 이벤트
|
||||
public event EventHandler<MapNode> NodeAdded;
|
||||
public event EventHandler<MapNode> NodeSelected;
|
||||
public event EventHandler<MapNode> NodeDeleted;
|
||||
public event EventHandler<MapNode> NodeMoved;
|
||||
public event EventHandler MapChanged;
|
||||
|
||||
// AGV 이벤트
|
||||
public event EventHandler<IAGV> AGVSelected;
|
||||
public event EventHandler<IAGV> AGVStateChanged;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// 캔버스 모드
|
||||
/// </summary>
|
||||
public CanvasMode Mode
|
||||
{
|
||||
get => _canvasMode;
|
||||
set
|
||||
{
|
||||
_canvasMode = value;
|
||||
UpdateModeUI();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 편집 모드 (CanvasMode.Edit일 때만 적용)
|
||||
/// </summary>
|
||||
public EditMode CurrentEditMode
|
||||
{
|
||||
get => _editMode;
|
||||
set
|
||||
{
|
||||
if (_canvasMode != CanvasMode.Edit) return;
|
||||
|
||||
_editMode = value;
|
||||
if (_editMode != EditMode.Connect)
|
||||
{
|
||||
CancelConnection();
|
||||
}
|
||||
Cursor = GetCursorForMode(_editMode);
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 그리드 표시 여부
|
||||
/// </summary>
|
||||
public bool ShowGrid
|
||||
{
|
||||
get => _showGrid;
|
||||
set
|
||||
{
|
||||
_showGrid = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 줌 팩터
|
||||
/// </summary>
|
||||
public float ZoomFactor
|
||||
{
|
||||
get => _zoomFactor;
|
||||
set
|
||||
{
|
||||
_zoomFactor = Math.Max(0.1f, Math.Min(5.0f, value));
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 선택된 노드
|
||||
/// </summary>
|
||||
public MapNode SelectedNode => _selectedNode;
|
||||
|
||||
/// <summary>
|
||||
/// 노드 목록
|
||||
/// </summary>
|
||||
public List<MapNode> Nodes
|
||||
{
|
||||
get => _nodes ?? new List<MapNode>();
|
||||
set
|
||||
{
|
||||
_nodes = value ?? new List<MapNode>();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AGV 목록
|
||||
/// </summary>
|
||||
public List<IAGV> AGVList
|
||||
{
|
||||
get => _agvList ?? new List<IAGV>();
|
||||
set
|
||||
{
|
||||
_agvList = value ?? new List<IAGV>();
|
||||
UpdateAGVData();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 현재 표시할 경로
|
||||
/// </summary>
|
||||
public PathResult CurrentPath
|
||||
{
|
||||
get => _currentPath;
|
||||
set
|
||||
{
|
||||
_currentPath = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 모든 경로 목록 (다중 AGV 경로 표시용)
|
||||
/// </summary>
|
||||
public List<PathResult> AllPaths
|
||||
{
|
||||
get => _allPaths ?? new List<PathResult>();
|
||||
set
|
||||
{
|
||||
_allPaths = value ?? new List<PathResult>();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 회사 로고 이미지
|
||||
/// </summary>
|
||||
public Image CompanyLogo
|
||||
{
|
||||
get => _companyLogo;
|
||||
set
|
||||
{
|
||||
_companyLogo = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 측정 정보 텍스트
|
||||
/// </summary>
|
||||
public string MeasurementInfo
|
||||
{
|
||||
get => _measurementInfo;
|
||||
set
|
||||
{
|
||||
_measurementInfo = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
public UnifiedAGVCanvas()
|
||||
{
|
||||
InitializeComponent();
|
||||
InitializeCanvas();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Initialization
|
||||
|
||||
private void InitializeCanvas()
|
||||
{
|
||||
SetStyle(ControlStyles.AllPaintingInWmPaint |
|
||||
ControlStyles.UserPaint |
|
||||
ControlStyles.DoubleBuffer |
|
||||
ControlStyles.ResizeRedraw, true);
|
||||
|
||||
_nodes = new List<MapNode>();
|
||||
_agvList = new List<IAGV>();
|
||||
_agvPositions = new Dictionary<string, Point>();
|
||||
_agvDirections = new Dictionary<string, AgvDirection>();
|
||||
_agvStates = new Dictionary<string, AGVState>();
|
||||
_allPaths = new List<PathResult>();
|
||||
|
||||
InitializeBrushesAndPens();
|
||||
CreateContextMenu();
|
||||
}
|
||||
|
||||
private void InitializeBrushesAndPens()
|
||||
{
|
||||
// 노드 브러쉬
|
||||
_normalNodeBrush = new SolidBrush(Color.LightBlue);
|
||||
_rotationNodeBrush = new SolidBrush(Color.Yellow);
|
||||
_dockingNodeBrush = new SolidBrush(Color.Orange);
|
||||
_chargingNodeBrush = new SolidBrush(Color.Green);
|
||||
_selectedNodeBrush = new SolidBrush(Color.Red);
|
||||
_hoveredNodeBrush = new SolidBrush(Color.LightCyan);
|
||||
|
||||
// AGV 및 경로 브러쉬
|
||||
_agvBrush = new SolidBrush(Color.Red);
|
||||
_pathBrush = new SolidBrush(Color.Purple);
|
||||
|
||||
// 그리드 브러쉬
|
||||
_gridBrush = new SolidBrush(Color.LightGray);
|
||||
|
||||
// 펜
|
||||
_connectionPen = new Pen(Color.DarkBlue, CONNECTION_WIDTH);
|
||||
_connectionPen.EndCap = LineCap.ArrowAnchor;
|
||||
|
||||
_gridPen = new Pen(Color.LightGray, 1);
|
||||
_tempConnectionPen = new Pen(Color.Orange, 2) { DashStyle = DashStyle.Dash };
|
||||
_selectedNodePen = new Pen(Color.Red, 3);
|
||||
_pathPen = new Pen(Color.Purple, 3);
|
||||
_agvPen = new Pen(Color.Red, 3);
|
||||
}
|
||||
|
||||
private void CreateContextMenu()
|
||||
{
|
||||
_contextMenu = new ContextMenuStrip();
|
||||
// 컨텍스트 메뉴는 EditMode에서만 사용
|
||||
}
|
||||
|
||||
private void UpdateModeUI()
|
||||
{
|
||||
// 모드에 따른 UI 업데이트
|
||||
if (_canvasMode == CanvasMode.ViewOnly)
|
||||
{
|
||||
Cursor = Cursors.Default;
|
||||
_contextMenu.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_contextMenu.Enabled = true;
|
||||
Cursor = GetCursorForMode(_editMode);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region AGV Management
|
||||
|
||||
/// <summary>
|
||||
/// AGV 위치 업데이트
|
||||
/// </summary>
|
||||
public void UpdateAGVPosition(string agvId, Point position)
|
||||
{
|
||||
if (_agvPositions.ContainsKey(agvId))
|
||||
_agvPositions[agvId] = position;
|
||||
else
|
||||
_agvPositions.Add(agvId, position);
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AGV 방향 업데이트
|
||||
/// </summary>
|
||||
public void UpdateAGVDirection(string agvId, AgvDirection direction)
|
||||
{
|
||||
if (_agvDirections.ContainsKey(agvId))
|
||||
_agvDirections[agvId] = direction;
|
||||
else
|
||||
_agvDirections.Add(agvId, direction);
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AGV 상태 업데이트
|
||||
/// </summary>
|
||||
public void UpdateAGVState(string agvId, AGVState state)
|
||||
{
|
||||
if (_agvStates.ContainsKey(agvId))
|
||||
_agvStates[agvId] = state;
|
||||
else
|
||||
_agvStates.Add(agvId, state);
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AGV 위치 설정 (시뮬레이터용)
|
||||
/// </summary>
|
||||
/// <param name="agvId">AGV ID</param>
|
||||
/// <param name="position">새로운 위치</param>
|
||||
public void SetAGVPosition(string agvId, Point position)
|
||||
{
|
||||
UpdateAGVPosition(agvId, position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AGV 데이터 동기화
|
||||
/// </summary>
|
||||
private void UpdateAGVData()
|
||||
{
|
||||
if (_agvList == null) return;
|
||||
|
||||
foreach (var agv in _agvList)
|
||||
{
|
||||
UpdateAGVPosition(agv.AgvId, agv.CurrentPosition);
|
||||
UpdateAGVDirection(agv.AgvId, agv.CurrentDirection);
|
||||
UpdateAGVState(agv.AgvId, agv.CurrentState);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helper Methods
|
||||
|
||||
private Cursor GetCursorForMode(EditMode mode)
|
||||
{
|
||||
if (_canvasMode != CanvasMode.Edit)
|
||||
return Cursors.Default;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case EditMode.AddNode:
|
||||
return Cursors.Cross;
|
||||
case EditMode.Move:
|
||||
return Cursors.SizeAll;
|
||||
case EditMode.Connect:
|
||||
return Cursors.Hand;
|
||||
case EditMode.Delete:
|
||||
return Cursors.No;
|
||||
default:
|
||||
return Cursors.Default;
|
||||
}
|
||||
}
|
||||
|
||||
private void CancelConnection()
|
||||
{
|
||||
_isConnectionMode = false;
|
||||
_connectionStartNode = null;
|
||||
_connectionEndPoint = Point.Empty;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cleanup
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
|
||||
// 브러쉬 정리
|
||||
_normalNodeBrush?.Dispose();
|
||||
_rotationNodeBrush?.Dispose();
|
||||
_dockingNodeBrush?.Dispose();
|
||||
_chargingNodeBrush?.Dispose();
|
||||
_selectedNodeBrush?.Dispose();
|
||||
_hoveredNodeBrush?.Dispose();
|
||||
_gridBrush?.Dispose();
|
||||
_agvBrush?.Dispose();
|
||||
_pathBrush?.Dispose();
|
||||
|
||||
// 펜 정리
|
||||
_connectionPen?.Dispose();
|
||||
_gridPen?.Dispose();
|
||||
_tempConnectionPen?.Dispose();
|
||||
_selectedNodePen?.Dispose();
|
||||
_pathPen?.Dispose();
|
||||
_agvPen?.Dispose();
|
||||
|
||||
// 컨텍스트 메뉴 정리
|
||||
_contextMenu?.Dispose();
|
||||
|
||||
// 이미지 정리
|
||||
_companyLogo?.Dispose();
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region Interfaces
|
||||
|
||||
/// <summary>
|
||||
/// AGV 인터페이스 (가상/실제 AGV 통합)
|
||||
/// </summary>
|
||||
public interface IAGV
|
||||
{
|
||||
string AgvId { get; }
|
||||
Point CurrentPosition { get; }
|
||||
AgvDirection CurrentDirection { get; }
|
||||
AGVState CurrentState { get; }
|
||||
float BatteryLevel { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AGV 상태 열거형
|
||||
/// </summary>
|
||||
public enum AGVState
|
||||
{
|
||||
Idle, // 대기
|
||||
Moving, // 이동 중
|
||||
Rotating, // 회전 중
|
||||
Docking, // 도킹 중
|
||||
Charging, // 충전 중
|
||||
Error // 오류
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user