first commit -push

This commit is contained in:
dungtt
2025-10-15 15:15:53 +07:00
parent 674ae395be
commit a9577c5756
885 changed files with 74595 additions and 0 deletions

View File

@@ -0,0 +1,131 @@
using RobotNet.MapShares.Dtos;
using RobotNet.MapShares.Enums;
using System.Text.Json;
namespace RobotNet.WebApp.Maps.Models;
public class EdgeModel : IDisposable
{
public Guid Id => Data.Id;
public Guid MapId => Data.MapId;
public double X1 => StartNode.X;
public double Y1 => StartNode.Y;
public double X2 => EndNode.X;
public double Y2 => EndNode.Y;
public DirectionAllowed DirectionAllowed => Data.DirectionAllowed;
public TrajectoryDegree TrajectoryDegree => Data.TrajectoryDegree;
public double ControlPoint1X => Data.ControlPoint1X;
public double ControlPoint1Y => Data.ControlPoint1Y;
public double ControlPoint2X => Data.ControlPoint2X;
public double ControlPoint2Y => Data.ControlPoint2Y;
public double MaxSpeed => Data.MaxSpeed;
public double MaxHeight => Data.MaxHeight;
public double MinHeight => Data.MinHeight;
public bool RotationAllowed => Data.RotationAllowed;
public double MaxRotationSpeed => Data.MaxRotationSpeed;
public string Actions => Data.Actions;
public double AllowedDeviationXy => Data.AllowedDeviationXy;
public double AllowedDeviationTheta => Data.AllowedDeviationTheta;
public bool ActivedControlPoint1 { get; set; }
public bool ActivedControlPoint2 { get; set; }
public NodeModel StartNode { get; private set; }
public NodeModel EndNode { get; private set; }
public event Func<Task>? StartNodePositionChanged;
public event Func<Task>? EndNodePositionChanged;
public event Func<Task>? ControlPoint1PositionChanged;
public event Func<Task>? ControlPoint2PositionChanged;
public event Func<Task>? DirectionChanged;
public event Action<bool>? ActiveChanged;
public event Action<EdgeModel>? SelectedChanged;
public event Action<bool>? ErrorChanged;
private readonly EdgeDto Data;
public EdgeModel(EdgeDto data, NodeModel startNode, NodeModel endNode)
{
Data = data;
StartNode = startNode;
EndNode = endNode;
StartNode.PositionChanged += StartNode_PositionChanged;
EndNode.PositionChanged += EndNode_PositionChanged;
}
private void EndNode_PositionChanged() => EndNodePositionChanged?.Invoke();
private void StartNode_PositionChanged() => StartNodePositionChanged?.Invoke();
public void Active() => ActiveChanged?.Invoke(true);
public void UnActive() => ActiveChanged?.Invoke(false);
public void Selected() => SelectedChanged?.Invoke(this);
public void UpdateNode(Guid id, NodeModel node)
{
if (StartNode.Id == id)
{
StartNode.PositionChanged -= StartNode_PositionChanged;
StartNode = node;
StartNode.PositionChanged += StartNode_PositionChanged;
StartNodePositionChanged?.Invoke();
}
else if (EndNode.Id == id)
{
EndNode.PositionChanged -= EndNode_PositionChanged;
EndNode = node;
EndNode.PositionChanged += EndNode_PositionChanged;
EndNodePositionChanged?.Invoke();
}
}
public void UpdateData(EdgeUpdateModel model)
{
if(Data.ControlPoint1X != model.ControlPoint1X || Data.ControlPoint1Y != model.ControlPoint1Y)
{
Data.ControlPoint1X = model.ControlPoint1X;
Data.ControlPoint1Y = model.ControlPoint1Y;
ControlPoint1PositionChanged?.Invoke();
}
if (Data.ControlPoint2X != model.ControlPoint2X || Data.ControlPoint2Y != model.ControlPoint2Y)
{
Data.ControlPoint2X = model.ControlPoint2X;
Data.ControlPoint2Y = model.ControlPoint2Y;
ControlPoint2PositionChanged?.Invoke();
}
Data.RotationAllowed = model.RotationAllowed;
Data.MaxSpeed = model.MaxSpeed;
Data.MaxRotationSpeed = model.MaxRotationSpeed;
Data.MaxHeight = model.MaxHeight;
Data.MinHeight = model.MinHeight;
Data.Actions = JsonSerializer.Serialize(model.Actions);
if (Data.DirectionAllowed != model.DirectionAllowed)
{
Data.DirectionAllowed = model.DirectionAllowed;
DirectionChanged?.Invoke();
}
}
public void UpdateControlPoint1(double x, double y)
{
Data.ControlPoint1X = x;
Data.ControlPoint1Y = y;
ControlPoint1PositionChanged?.Invoke();
}
public void UpdateControlPoint2(double x, double y)
{
Data.ControlPoint2X = x;
Data.ControlPoint2Y = y;
ControlPoint2PositionChanged?.Invoke();
}
public void SetError(bool state) => ErrorChanged?.Invoke(state);
public void Dispose()
{
StartNode.PositionChanged -= StartNode_PositionChanged;
EndNode.PositionChanged -= EndNode_PositionChanged;
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,60 @@
using RobotNet.MapShares.Dtos;
namespace RobotNet.WebApp.Maps.Models;
#nullable disable
public class ElementModel : IDisposable
{
public Guid Id => Element.Id;
public Guid ModelId => Element.ModelId;
public Guid NodeId => Element.NodeId;
public Guid MapId => Element.MapId;
public string Name => Element.Name;
public double X => Node.X;
public double Y => Node.Y;
public double Theta => Node.Theta;
public double OffsetX => Element.OffsetX;
public double OffsetY => Element.OffsetY;
public bool IsOpen => Element.IsOpen;
public string Content => Element.Content;
public event Func<Task> PositionChanged;
public event Func<Task> OffsetChanged;
public ElementDto Element { get; private set; }
public NodeModel Node { get; private set; }
public ElementModel(ElementDto element, NodeModel node)
{
Element = element;
Node = node;
Node.PositionChanged += Node_PositionChanged;
}
public void Node_PositionChanged() => PositionChanged?.Invoke();
public void UpdateOffset(double offsetX, double offsetY)
{
if (Element.OffsetX == offsetX && Element.OffsetY == offsetY) return;
Element.OffsetX = offsetX;
Element.OffsetY = offsetY;
OffsetChanged?.Invoke();
}
public void UpdateElement(ElementDto model)
{
Element.Name = model.Name;
Element.IsOpen = model.IsOpen;
Element.Content = model.Content;
UpdateOffset(model.OffsetX, model.OffsetY);
}
public void Dispose()
{
Node.PositionChanged -= Node_PositionChanged;
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,123 @@
using RobotNet.MapShares.Dtos;
using RobotNet.MapShares.Enums;
namespace RobotNet.WebApp.Maps.Models;
public class MapEdgeModel : IEnumerable<EdgeModel>
{
private readonly Dictionary<Guid, EdgeModel> dicEdges = [];
public EdgeModel this[int i] => dicEdges.Values.ElementAt(i);
public EdgeModel this[Guid id] => dicEdges[id];
public IEnumerator<EdgeModel> GetEnumerator() => dicEdges.Values.GetEnumerator();
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();
public bool TryGetValue(Guid id, out EdgeModel? value) => dicEdges.TryGetValue(id, out value);
public bool ContainsKey(Guid key) => dicEdges.ContainsKey(key);
public List<EdgeModel> ActivedEdges { get; private set; } = [];
public event Action? Changed;
public event Action<EdgeModel?>? EdgeSelectedChanged;
private (double X, double Y) StartMovePosition;
public void Add(EdgeDto edge, NodeModel start, NodeModel end)
{
if (dicEdges.ContainsKey(edge.Id)) return;
var model = new EdgeModel(edge, start, end);
dicEdges.Add(model.Id, model);
model.SelectedChanged += EdgeSelectedChange;
Changed?.Invoke();
}
public void ReplaceAll(IEnumerable<EdgeModel> edges)
{
foreach (var edge in dicEdges.Values)
{
if (ActivedEdges.Any(e => e.Id == edge.Id))
{
edge.SelectedChanged -= EdgeSelectedChange;
edge.UnActive();
ActivedEdges.Remove(edge);
}
edge.Dispose();
}
dicEdges.Clear();
foreach (var edge in edges)
{
dicEdges.Add(edge.Id, edge);
edge.SelectedChanged += EdgeSelectedChange;
}
Changed?.Invoke();
}
public void Remove(EdgeModel edge)
{
if (!dicEdges.ContainsKey(edge.Id)) return;
edge.SelectedChanged -= EdgeSelectedChange;
if (ActivedEdges.Any(e => e.Id == edge.Id))
{
ActivedEdges.Remove(edge);
}
edge.Dispose();
dicEdges.Remove(edge.Id);
Changed?.Invoke();
}
private void EdgeSelectedChange(EdgeModel edge)
{
EdgeSelectedChanged?.Invoke(edge);
}
public void UnActivedEdge(EdgeModel? exceptedModel = null)
{
foreach (var edge in ActivedEdges)
{
if (exceptedModel is not null && edge.Id == exceptedModel.Id) continue;
var edgeInDic = dicEdges.Values.FirstOrDefault(e => e.Id.Equals(edge.Id));
edgeInDic?.UnActive();
}
ActivedEdges.Clear();
if (exceptedModel is not null) ActivedEdges.Add(exceptedModel);
}
public void ActivedEdge(IEnumerable<EdgeModel> edges)
{
UnActivedEdge();
foreach (var edge in edges)
{
var edgeInDic = dicEdges[edge.Id];
edgeInDic?.Active();
ActivedEdges.Add(edge);
}
}
public void SetStartMovePosition(double x, double y)
{
StartMovePosition.X = x;
StartMovePosition.Y = y;
}
public void UpdateMoveEdge(double x, double y)
{
double deltaX = x - StartMovePosition.X;
double deltaY = y - StartMovePosition.Y;
List<Guid> NodeUpdated = [];
foreach (var edge in ActivedEdges)
{
if (!NodeUpdated.Any(n => n == edge.StartNode.Id)) edge.StartNode.UpdatePosition(edge.StartNode.X + deltaX, edge.StartNode.Y + deltaY);
if (!NodeUpdated.Any(n => n == edge.EndNode.Id)) edge.EndNode.UpdatePosition(edge.EndNode.X + deltaX, edge.EndNode.Y + deltaY);
if (edge.TrajectoryDegree == TrajectoryDegree.Two) edge.UpdateControlPoint1(edge.ControlPoint1X + deltaX, edge.ControlPoint1Y + deltaY);
if (edge.TrajectoryDegree == TrajectoryDegree.Three)
{
edge.UpdateControlPoint1(edge.ControlPoint1X + deltaX, edge.ControlPoint1Y + deltaY);
edge.UpdateControlPoint2(edge.ControlPoint2X + deltaX, edge.ControlPoint2Y + deltaY);
}
NodeUpdated.Add(edge.StartNode.Id);
NodeUpdated.Add(edge.EndNode.Id);
}
StartMovePosition.X = x;
StartMovePosition.Y = y;
}
}

View File

@@ -0,0 +1,45 @@
using System.Collections;
namespace RobotNet.WebApp.Maps.Models;
public class MapElementModel : IEnumerable<ElementModel>
{
private readonly Dictionary<Guid, ElementModel> dicElements = [];
public IEnumerator<ElementModel> GetEnumerator() => dicElements.Values.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
public bool TryGetValue(Guid id, out ElementModel? value) => dicElements.TryGetValue(id, out value);
public bool ContainsKey(Guid key) => dicElements.ContainsKey(key);
public event Action? Changed;
public void Add(ElementModel element)
{
if (dicElements.ContainsKey(element.Id)) return;
dicElements.Add(element.Id, element);
Changed?.Invoke();
}
public void ReplaceAll(IEnumerable<ElementModel> elements)
{
foreach (var robot in dicElements.Values)
{
robot.Dispose();
}
dicElements.Clear();
foreach (var element in elements)
{
dicElements.Add(element.Id, element);
}
Changed?.Invoke();
}
public void Remove(ElementModel element)
{
if (!dicElements.ContainsKey(element.Id)) return;
element.Dispose();
dicElements.Remove(element.Id);
Changed?.Invoke();
}
}

View File

@@ -0,0 +1,86 @@
using RobotNet.MapShares.Dtos;
namespace RobotNet.WebApp.Maps.Models;
public class MapNodeModel : IEnumerable<NodeModel>
{
private readonly Dictionary<Guid, NodeModel> dicNodes = [];
public NodeModel this[int i] => dicNodes.Values.ElementAt(i);
public NodeModel this[Guid id] => dicNodes[id];
public IEnumerator<NodeModel> GetEnumerator() => dicNodes.Values.GetEnumerator();
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();
public bool ContainsKey(Guid key) => dicNodes.ContainsKey(key);
public bool TryGetValue(Guid id, out NodeModel? value) => dicNodes.TryGetValue(id, out value);
public NodeModel? SelectedNode { get; set; }
public List<NodeModel> ActivedNodes { get; private set; } = [];
public event Action? Changed;
private (double X, double Y) StartMovePosition;
public void Add(NodeDto node)
{
if (dicNodes.ContainsKey(node.Id)) return;
var model = new NodeModel(node);
dicNodes.Add(model.Id, model);
Changed?.Invoke();
}
public void ReplaceAll(IEnumerable<NodeDto> nodes)
{
dicNodes.Clear();
foreach (var node in nodes)
{
var model = new NodeModel(node);
dicNodes.Add(model.Id, model);
}
Changed?.Invoke();
}
public void Remove(NodeModel node)
{
if (!dicNodes.ContainsKey(node.Id)) return;
node.Dispose();
dicNodes.Remove(node.Id);
Changed?.Invoke();
}
public void ActivedNode(IEnumerable<NodeModel> nodes)
{
UnActivedNode();
foreach (var node in nodes)
{
var nodeInDic = dicNodes.Values.FirstOrDefault(e => e.Id.Equals(node.Id));
nodeInDic?.Active();
ActivedNodes.Add(node);
}
}
public void UnActivedNode()
{
foreach (var node in ActivedNodes)
{
var nodeInDic = dicNodes.Values.FirstOrDefault(e => e.Id.Equals(node.Id));
nodeInDic?.UnActive();
}
ActivedNodes.Clear();
}
public void SetStartMovePosition(double x, double y)
{
StartMovePosition.X = x;
StartMovePosition.Y = y;
}
public void UpdateMoveNode(double x, double y)
{
double deltaX = x - StartMovePosition.X;
double deltaY = y - StartMovePosition.Y;
ActivedNodes.ForEach(n => n.UpdatePosition(n.X + deltaX, n.Y + deltaY));
StartMovePosition.X = x;
StartMovePosition.Y = y;
}
}

View File

@@ -0,0 +1,73 @@
using RobotNet.MapShares.Dtos;
namespace RobotNet.WebApp.Maps.Models;
public class MapZoneModel : IEnumerable<ZoneModel>
{
private readonly Dictionary<Guid, ZoneModel> dicZones = [];
public ZoneModel this[int i] => dicZones.Values.ElementAt(i);
public ZoneModel this[Guid id] => dicZones[id];
public IEnumerator<ZoneModel> GetEnumerator() => dicZones.Values.GetEnumerator();
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();
public bool TryGetValue(Guid id, out ZoneModel? value) => dicZones.TryGetValue(id, out value);
public ZoneModel? ZoneActived { get; private set; }
public event Action? Changed;
public event Action<ZoneModel, bool>? ActivedZoneChanged;
public void ReplaceAll(IEnumerable<ZoneDto> zones)
{
foreach (var zone in dicZones.Values)
{
zone.ActiveChanged -= Zone_ActiveChanged;
zone.Dispose();
if (ZoneActived is not null && ZoneActived == zone) ZoneActived = null;
}
dicZones.Clear();
foreach (var zone in zones)
{
var model = new ZoneModel(zone);
model.ActiveChanged += Zone_ActiveChanged;
dicZones.Add(zone.Id, model);
}
Changed?.Invoke();
}
public void Add(ZoneDto zone)
{
if (dicZones.ContainsKey(zone.Id)) return;
var model = new ZoneModel(zone);
dicZones.Add(model.Id, model);
model.ActiveChanged += Zone_ActiveChanged;
Changed?.Invoke();
}
public void Remove(ZoneModel zone)
{
if (!dicZones.ContainsKey(zone.Id)) return;
zone.UnActive();
zone.ActiveChanged -= Zone_ActiveChanged;
if (ZoneActived is not null && zone.Id == ZoneActived.Id) ZoneActived = null;
zone.Dispose();
dicZones.Remove(zone.Id);
Changed?.Invoke();
}
private void Zone_ActiveChanged(ZoneModel zone, bool state)
{
if (state)
{
if (ZoneActived is not null && ZoneActived != zone || ZoneActived is null)
{
ZoneActived?.UnActive();
ZoneActived = zone;
}
}
ActivedZoneChanged?.Invoke(zone, state);
}
public void UnActivedZone() => ZoneActived?.UnActive();
}

View File

@@ -0,0 +1,59 @@
using RobotNet.MapShares.Dtos;
using System.Text.Json;
namespace RobotNet.WebApp.Maps.Models;
public class NodeModel(NodeDto Data) : IDisposable
{
public Guid Id => Data.Id;
public Guid MapId => Data.MapId;
public string Name => Data.Name;
public double X => Data.X;
public double Y => Data.Y;
public double Theta => Data.Theta;
public string Actions => Data.Actions;
public double AllowedDeviationXy => Data.AllowedDeviationXy;
public double AllowedDeviationTheta => Data.AllowedDeviationTheta;
public event Action? PositionChanged;
public event Action<bool>? ActivedChanged;
public event Action<bool>? ErrorChanged;
public int NumberOfEdgeReference => PositionChanged?.GetInvocationList().Length ?? 0;
public void UpdatePosition(double x, double y)
{
if (Data.X == x && Data.Y == y) return;
Data.X = x;
Data.Y = y;
PositionChanged?.Invoke();
}
public void UpdatePosition(double x, double y, double theta)
{
if (Data.X == x && Data.Y == y && Data.Theta == theta) return;
Data.X = x;
Data.Y = y;
Data.Theta = theta;
PositionChanged?.Invoke();
}
public void UpdateData(NodeUpdateModel model)
{
Data.Name = model.Name;
Data.AllowedDeviationXy = model.AllowedDeviationXy;
Data.AllowedDeviationTheta = model.AllowedDeviationTheta;
Data.Actions = JsonSerializer.Serialize(model.Actions);
UpdatePosition(model.X, model.Y, model.Theta);
}
public void Active() => ActivedChanged?.Invoke(true);
public void UnActive() => ActivedChanged?.Invoke(false);
public void SetError(bool state) => ErrorChanged?.Invoke(state);
public void Dispose()
{
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,121 @@
using RobotNet.MapShares;
using RobotNet.MapShares.Dtos;
using RobotNet.MapShares.Enums;
namespace RobotNet.WebApp.Maps.Models;
public class ZoneModel(ZoneDto Data) : IDisposable
{
public Guid Id => Data.Id;
public Guid MapId => Data.MapId;
public ZoneType Type => Data.Type;
public string Name => Data.Name;
public double X1 => Data.X1;
public double Y1 => Data.Y1;
public double X2 => Data.X2;
public double Y2 => Data.Y2;
public double X3 => Data.X3;
public double Y3 => Data.Y3;
public double X4 => Data.X4;
public double Y4 => Data.Y4;
public string Fill => Data.Type switch
{
ZoneType.Confined => "#c29ffa", // Vùng hoạt động hạn chế
ZoneType.Forbidden => "#ea868f", // Vùng cấm di chuyển
ZoneType.Operating => "#79dfc1", // Vùng hoạt động bình thường
ZoneType.OperatingHazard => "#ffda6a", // Vùng hoạt động nguy hiểm
ZoneType.Restricted => "#fd9843", // Vùng hoạt động giới hạn
ZoneType.LoadTransfer => "#e685b5", // Vùng chuyển hàng
_ => "none",
};
public int ActiveNode = -1;
public event Action<ZoneModel, bool>? ActiveChanged;
public event Func<Task>? ControlNodePosittionChanged;
public event Action? TypeChanged;
private (double X, double Y) StartMovePosition;
public void Active()
{
if (ActiveNode == -1) ActiveNode = 5;
ActiveChanged?.Invoke(this, true);
}
public void UnActive() => ActiveChanged?.Invoke(this, false);
public void UpdateControlNode(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
{
Data.X1 = x1;
Data.Y1 = y1;
Data.X2 = x2;
Data.Y2 = y2;
Data.X3 = x3;
Data.Y3 = y3;
Data.X4 = x4;
Data.Y4 = y4;
ControlNodePosittionChanged?.Invoke();
}
public void UpdateData(ZoneUpdateModel data)
{
if (data.Type != Data.Type)
{
Data.Type = data.Type;
TypeChanged?.Invoke();
}
if (data.Name != Data.Name) Data.Name = data.Name;
UpdateControlNode(data.X1, data.Y1, data.X2, data.Y2, data.X3, data.Y3, data.X4, data.Y4);
}
public void SetStartMovePosition(double x, double y)
{
StartMovePosition.X = x;
StartMovePosition.Y = y;
}
public void UpdateControlNode(int node, double x, double y)
{
double deltaX = x - StartMovePosition.X;
double deltaY = y - StartMovePosition.Y;
switch (node)
{
case 1:
Data.X1 = x;
Data.Y1 = y;
break;
case 2:
Data.X2 = x;
Data.Y2 = y;
break;
case 3:
Data.X3 = x;
Data.Y3 = y;
break;
case 4:
Data.X4 = x;
Data.Y4 = y;
break;
case 5:
if (!MapEditorHelper.IsPointInside(StartMovePosition.X, StartMovePosition.Y, Data)) return;
Data.X1 += deltaX;
Data.Y1 += deltaY;
Data.X2 += deltaX;
Data.Y2 += deltaY;
Data.X3 += deltaX;
Data.Y3 += deltaY;
Data.X4 += deltaX;
Data.Y4 += deltaY;
break;
}
StartMovePosition.X = x;
StartMovePosition.Y = y;
ControlNodePosittionChanged?.Invoke();
}
public void Dispose()
{
GC.SuppressFinalize(this);
}
}