save
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using RobotApp.VDA5050.InstantAction;
|
||||
using RobotApp.VDA5050.Order;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace RobotApp.Client.Services;
|
||||
@@ -7,13 +8,37 @@ namespace RobotApp.Client.Services;
|
||||
// ======================================================
|
||||
// EDGE UI
|
||||
// ======================================================
|
||||
public class UiEdge : VDA5050.Order.Edge
|
||||
public class UiEdge
|
||||
{
|
||||
public double Radius { get; set; } = 0.0;
|
||||
public Quadrant Quadrant { get; set; } = Quadrant.I;
|
||||
public string EdgeId { get; set; } = "";
|
||||
public int SequenceId { get; set; }
|
||||
public bool Released { get; set; } = true;
|
||||
|
||||
// Đánh dấu đã expand chưa
|
||||
public bool Expanded { get; set; } = false;
|
||||
public string StartNodeId { get; set; } = "";
|
||||
public string EndNodeId { get; set; } = "";
|
||||
|
||||
// ===== CURVE (EDITOR GENERATED) =====
|
||||
public double Radius { get; set; } = 0;
|
||||
public Quadrant Quadrant { get; set; }
|
||||
|
||||
// ===== IMPORTED TRAJECTORY =====
|
||||
public bool HasTrajectory { get; set; } = false;
|
||||
public UiTrajectory? Trajectory { get; set; }
|
||||
|
||||
// ===== UI STATE =====
|
||||
public bool Expanded { get; private set; } = false;
|
||||
|
||||
public void MarkExpanded()
|
||||
{
|
||||
Expanded = true;
|
||||
}
|
||||
}
|
||||
|
||||
public class UiTrajectory
|
||||
{
|
||||
public int Degree { get; set; }
|
||||
public double[] KnotVector { get; set; } = Array.Empty<double>();
|
||||
public List<Point> ControlPoints { get; set; } = new();
|
||||
}
|
||||
|
||||
public enum Quadrant
|
||||
@@ -138,7 +163,111 @@ public class OrderMessage
|
||||
}
|
||||
};
|
||||
}
|
||||
public static OrderMessage FromSchemaObject(JsonElement root)
|
||||
{
|
||||
var order = new OrderMessage
|
||||
{
|
||||
HeaderId = root.GetProperty("headerId").GetInt32(),
|
||||
Timestamp = root.GetProperty("timestamp").GetString(),
|
||||
Version = root.GetProperty("version").GetString(),
|
||||
Manufacturer = root.GetProperty("manufacturer").GetString(),
|
||||
SerialNumber = root.GetProperty("serialNumber").GetString(),
|
||||
OrderId = root.GetProperty("orderId").GetString(),
|
||||
OrderUpdateId = root.GetProperty("orderUpdateId").GetInt32()
|
||||
};
|
||||
|
||||
// ================= NODES =================
|
||||
foreach (var n in root.GetProperty("nodes").EnumerateArray())
|
||||
{
|
||||
var node = new Node
|
||||
{
|
||||
NodeId = n.GetProperty("nodeId").GetString()!,
|
||||
SequenceId = n.GetProperty("sequenceId").GetInt32(),
|
||||
Released = n.GetProperty("released").GetBoolean(),
|
||||
|
||||
NodePosition = new NodePosition
|
||||
{
|
||||
X = n.GetProperty("nodePosition").GetProperty("x").GetDouble(),
|
||||
Y = n.GetProperty("nodePosition").GetProperty("y").GetDouble(),
|
||||
Theta = n.GetProperty("nodePosition").GetProperty("theta").GetDouble(),
|
||||
AllowedDeviationXY = n.GetProperty("nodePosition").GetProperty("allowedDeviationXY").GetDouble(),
|
||||
AllowedDeviationTheta = n.GetProperty("nodePosition").GetProperty("allowedDeviationTheta").GetDouble(),
|
||||
MapId = n.GetProperty("nodePosition").GetProperty("mapId").GetString()
|
||||
},
|
||||
|
||||
Actions = ParseActions(n)
|
||||
};
|
||||
|
||||
order.Nodes.Add(node);
|
||||
}
|
||||
|
||||
foreach (var e in root.GetProperty("edges").EnumerateArray())
|
||||
{
|
||||
var edge = new UiEdge
|
||||
{
|
||||
EdgeId = e.GetProperty("edgeId").GetString()!,
|
||||
SequenceId = e.GetProperty("sequenceId").GetInt32(),
|
||||
Released = e.GetProperty("released").GetBoolean(),
|
||||
StartNodeId = e.GetProperty("startNodeId").GetString()!,
|
||||
EndNodeId = e.GetProperty("endNodeId").GetString()!,
|
||||
};
|
||||
|
||||
// ===== IMPORT TRAJECTORY =====
|
||||
if (e.TryGetProperty("trajectory", out var traj))
|
||||
{
|
||||
edge.HasTrajectory = true;
|
||||
edge.Trajectory = new UiTrajectory
|
||||
{
|
||||
Degree = traj.GetProperty("degree").GetInt32(),
|
||||
KnotVector = traj.GetProperty("knotVector")
|
||||
.EnumerateArray()
|
||||
.Select(x => x.GetDouble())
|
||||
.ToArray(),
|
||||
|
||||
ControlPoints = traj.GetProperty("controlPoints")
|
||||
.EnumerateArray()
|
||||
.Select(p => new Point(
|
||||
p.GetProperty("x").GetDouble(),
|
||||
p.GetProperty("y").GetDouble()
|
||||
))
|
||||
.ToList()
|
||||
};
|
||||
|
||||
// 🔥 IMPORTED CURVE → LOCK APPLY
|
||||
edge.MarkExpanded();
|
||||
}
|
||||
|
||||
order.Edges.Add(edge);
|
||||
}
|
||||
|
||||
return order;
|
||||
}
|
||||
|
||||
// ================= ACTION PARSER =================
|
||||
private static VDA5050.InstantAction.Action[] ParseActions(JsonElement parent)
|
||||
{
|
||||
if (!parent.TryGetProperty("actions", out var acts))
|
||||
return Array.Empty<VDA5050.InstantAction.Action>();
|
||||
|
||||
return acts.EnumerateArray().Select(a =>
|
||||
new VDA5050.InstantAction.Action
|
||||
{
|
||||
ActionId = a.GetProperty("actionId").GetString(),
|
||||
ActionType = a.GetProperty("actionType").GetString(),
|
||||
BlockingType = a.GetProperty("blockingType").GetString(),
|
||||
|
||||
ActionParameters = a.TryGetProperty("actionParameters", out var ps)
|
||||
? ps.EnumerateArray()
|
||||
.Select(p => new ActionParameter
|
||||
{
|
||||
Key = p.GetProperty("key").GetString(),
|
||||
Value = p.GetProperty("value").GetString()
|
||||
})
|
||||
.ToArray()
|
||||
: Array.Empty<ActionParameter>()
|
||||
}
|
||||
).ToArray();
|
||||
}
|
||||
public object ToSchemaObject()
|
||||
{
|
||||
int seq = 0;
|
||||
@@ -199,7 +328,36 @@ public class OrderMessage
|
||||
// ================= EDGES =================
|
||||
edges = Edges.Select<UiEdge, object>(e =>
|
||||
{
|
||||
// ---------- ĐƯỜNG THẲNG ----------
|
||||
// =================================================
|
||||
// 1️⃣ IMPORTED TRAJECTORY (ƯU TIÊN CAO NHẤT)
|
||||
// =================================================
|
||||
if (e.HasTrajectory && e.Trajectory != null)
|
||||
{
|
||||
return new
|
||||
{
|
||||
edgeId = e.EdgeId,
|
||||
sequenceId = seq++,
|
||||
released = true,
|
||||
|
||||
startNodeId = e.StartNodeId,
|
||||
endNodeId = e.EndNodeId,
|
||||
|
||||
trajectory = new
|
||||
{
|
||||
degree = e.Trajectory.Degree,
|
||||
knotVector = e.Trajectory.KnotVector,
|
||||
controlPoints = e.Trajectory.ControlPoints
|
||||
.Select(p => new { x = p.X, y = p.Y })
|
||||
.ToArray()
|
||||
},
|
||||
|
||||
actions = Array.Empty<object>()
|
||||
};
|
||||
}
|
||||
|
||||
// =================================================
|
||||
// 2️⃣ STRAIGHT EDGE (KHÔNG CÓ CURVE)
|
||||
// =================================================
|
||||
if (e.Radius <= 0)
|
||||
{
|
||||
return new
|
||||
@@ -207,14 +365,19 @@ public class OrderMessage
|
||||
edgeId = e.EdgeId,
|
||||
sequenceId = seq++,
|
||||
released = true,
|
||||
|
||||
startNodeId = e.StartNodeId,
|
||||
endNodeId = e.EndNodeId,
|
||||
|
||||
actions = Array.Empty<object>()
|
||||
};
|
||||
}
|
||||
|
||||
// ---------- ĐƯỜNG CONG 1/4 ----------
|
||||
// =================================================
|
||||
// 3️⃣ EDITOR GENERATED CURVE (RADIUS + QUADRANT)
|
||||
// =================================================
|
||||
var startNode = Nodes.First(n => n.NodeId == e.StartNodeId);
|
||||
|
||||
var A = new Point(
|
||||
startNode.NodePosition.X,
|
||||
startNode.NodePosition.Y
|
||||
|
||||
Reference in New Issue
Block a user