first commit -push
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
@inject IJSRuntime JSRuntime
|
||||
@implements IDisposable
|
||||
|
||||
<path @ref="Ref" />
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public EdgeModel Model { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<EdgeModel> DoubleClick { get; set; }
|
||||
|
||||
[CascadingParameter]
|
||||
protected bool MapIsActive { get; set; }
|
||||
|
||||
private ElementReference Ref;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
await UpdatePathData();
|
||||
}
|
||||
|
||||
private async Task UpdatePathData()
|
||||
{
|
||||
var data = $"M {Model.X1} {Model.Y1}";
|
||||
|
||||
if (Model.TrajectoryDegree == TrajectoryDegree.One)
|
||||
{
|
||||
data = $"{data} L {(Model.X1 + Model.X2) / 2} {(Model.Y1 + Model.Y2) / 2} L {Model.X2} {Model.Y2}";
|
||||
}
|
||||
else if (Model.TrajectoryDegree == TrajectoryDegree.Two)
|
||||
{
|
||||
data = $"{data} Q {Model.ControlPoint1X} {Model.ControlPoint1Y} {Model.X2} {Model.Y2}";
|
||||
}
|
||||
else if (Model.TrajectoryDegree == TrajectoryDegree.Three)
|
||||
{
|
||||
data = $"{data} C {Model.ControlPoint1X} {Model.ControlPoint1Y}, {Model.ControlPoint2X} {Model.ControlPoint2Y}, {Model.X2} {Model.Y2}";
|
||||
}
|
||||
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "d", data);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using RobotNet.MapShares.Dtos;
|
||||
using RobotNet.MapShares.Enums;
|
||||
|
||||
namespace RobotNet.WebApp.Robots.Components.Monitoring.Element;
|
||||
|
||||
public class EdgeModel(EdgeDto data, NodeModel startNode, NodeModel endNode) : 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 NodeModel StartNode { get; private set; } = startNode;
|
||||
public NodeModel EndNode { get; private set; } = endNode;
|
||||
|
||||
|
||||
private readonly EdgeDto Data = data;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
path {
|
||||
cursor: default;
|
||||
stroke: #22B3FF;
|
||||
stroke-width: var(--edge-stroke-width);
|
||||
fill: none;
|
||||
}
|
||||
|
||||
path.setting:hover {
|
||||
stroke: #1E9DDF;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
path.setting:active {
|
||||
stroke: #227CFF;
|
||||
}
|
||||
|
||||
path.setting.active:hover {
|
||||
stroke: #227CFF;
|
||||
}
|
||||
|
||||
path.active {
|
||||
stroke: #227CFF;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
@implements IDisposable
|
||||
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<polyline @ref="Ref" />
|
||||
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public EdgeModel Model { get; set; } = null!;
|
||||
|
||||
private ElementReference Ref;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
await UpdatePathData();
|
||||
await UpdateMaker();
|
||||
}
|
||||
|
||||
private async Task UpdatePathData()
|
||||
{
|
||||
string data = string.Empty;
|
||||
double sx = 0, sy = 0, mx = 0, my = 0, ex = 0, ey = 0;
|
||||
double sTime = 0.49, eTime = 0.5;
|
||||
|
||||
|
||||
if (Model.TrajectoryDegree == TrajectoryDegree.One)
|
||||
{
|
||||
sx = Model.X1;
|
||||
sy = Model.Y1;
|
||||
ex = Model.X2;
|
||||
ey = Model.Y2;
|
||||
}
|
||||
else if (Model.TrajectoryDegree == TrajectoryDegree.Two)
|
||||
{
|
||||
sx = (Model.X1 + Model.ControlPoint1X) / 2;
|
||||
sy = (Model.Y1 + Model.ControlPoint1Y) / 2;
|
||||
ex = (Model.X2 + Model.ControlPoint1X) / 2;
|
||||
ey = (Model.Y2 + Model.ControlPoint1Y) / 2;
|
||||
}
|
||||
else if (Model.TrajectoryDegree == TrajectoryDegree.Three)
|
||||
{
|
||||
sx = Math.Pow(1 - sTime, 3) * Model.X1 + 3 * Math.Pow(1 - sTime, 2) * sTime * Model.ControlPoint1X + 3 * Math.Pow(sTime, 2) * (1 - sTime) * Model.ControlPoint2X + Math.Pow(sTime, 3) * Model.X2;
|
||||
sy = Math.Pow(1 - sTime, 3) * Model.Y1 + 3 * Math.Pow(1 - sTime, 2) * sTime * Model.ControlPoint1Y + 3 * Math.Pow(sTime, 2) * (1 - sTime) * Model.ControlPoint2Y + Math.Pow(sTime, 3) * Model.Y2;
|
||||
|
||||
ex = Math.Pow(1 - eTime, 3) * Model.X1 + 3 * Math.Pow(1 - eTime, 2) * eTime * Model.ControlPoint1X + 3 * Math.Pow(eTime, 2) * (1 - eTime) * Model.ControlPoint2X + Math.Pow(eTime, 3) * Model.X2;
|
||||
ey = Math.Pow(1 - eTime, 3) * Model.Y1 + 3 * Math.Pow(1 - eTime, 2) * eTime * Model.ControlPoint1Y + 3 * Math.Pow(eTime, 2) * (1 - eTime) * Model.ControlPoint2Y + Math.Pow(eTime, 3) * Model.Y2;
|
||||
}
|
||||
|
||||
mx = (sx + ex) / 2;
|
||||
my = (sy + ey) / 2;
|
||||
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "points", $"{sx},{sy} {mx},{my} {ex},{ey}");
|
||||
}
|
||||
|
||||
private async Task UpdateMaker()
|
||||
{
|
||||
if (Model == null) return;
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "marker-mid", MapSvgDefs.GetMakerMid(Model.DirectionAllowed));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
polyline {
|
||||
stroke-width: var(--edge-direction-stroke-width);
|
||||
stroke: none;
|
||||
fill: none;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
@implements IDisposable
|
||||
|
||||
@inject IHttpClientFactory HttpFactory
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<g class="element" visibility="@(Show ? "visible" : "hidden")" @ondblclick="@(async () => await DoubleClick.InvokeAsync(Model))">
|
||||
<image @ref="@ImageRef" />
|
||||
<text @ref="textRef" visibility="@(Show && ShowName ? "visible" : "hidden")">@Model?.Name</text>
|
||||
</g>
|
||||
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public bool Show { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool ShowName { get; set; }
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public ElementModel Model { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<ElementModel> DoubleClick { get; set; }
|
||||
|
||||
private ElementReference ImageRef;
|
||||
private ElementReference textRef;
|
||||
private ElementModelDto ElementModel = new();
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
using var Http = HttpFactory.CreateClient("MapManagerAPI");
|
||||
var model = await Http.GetFromJsonAsync<MessageResult<ElementModelDto?>>($"api/ElementModels/{Model.ModelId}");
|
||||
if (model is not null && model.Data is not null)
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("SetImageAttribute", ImageRef, model.Data.Width, model.Data.Height, -model.Data.Width / 2, -model.Data.Height / 2, $"{Http.BaseAddress}api/images/elementModel/{model.Data.Id}?IsOpen={Model.IsOpen}");
|
||||
ElementModel = model.Data;
|
||||
}
|
||||
if (Model is not null)
|
||||
{
|
||||
Model.UpdateChanged += Model_UpdateChanged;
|
||||
await UpdatePosition(Model.X, Model.Y, Model.Theta);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Model_UpdateChanged()
|
||||
{
|
||||
await SetElementImage(Model.IsOpen);
|
||||
await UpdatePosition(Model.OffsetX, Model.OffsetY);
|
||||
}
|
||||
|
||||
public override async Task SetParametersAsync(ParameterView parameters)
|
||||
{
|
||||
bool updateRobot = false;
|
||||
if (parameters.TryGetValue(nameof(Model), out ElementModel? model) && ((Model?.Id ?? Guid.Empty) != (model?.Id ?? Guid.Empty)))
|
||||
{
|
||||
if (Model != null) Model.UpdateChanged -= Model_UpdateChanged;
|
||||
if (model != null)
|
||||
{
|
||||
updateRobot = true;
|
||||
model.UpdateChanged -= Model_UpdateChanged;
|
||||
}
|
||||
}
|
||||
await base.SetParametersAsync(parameters);
|
||||
if (updateRobot && model != null)
|
||||
{
|
||||
await SetElementImage(model.IsOpen);
|
||||
await UpdatePosition(model.X, model.Y, model.Theta);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SetElementImage(bool isOpen)
|
||||
{
|
||||
if (ElementModel.Id != Guid.Empty)
|
||||
{
|
||||
using var Http = HttpFactory.CreateClient("MapManagerAPI");
|
||||
await JSRuntime.InvokeVoidAsync("SetImageAttribute", ImageRef, ElementModel.Width, ElementModel.Height, (-ElementModel.Width / 2), (-ElementModel.Height / 2), $"{Http.BaseAddress}api/images/elementModel/{ElementModel.Id}?IsOpen={isOpen}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdatePosition(double x, double y, double theta)
|
||||
=> await JSRuntime.InvokeVoidAsync("SetRobotPosition", ImageRef, textRef, x + Model.OffsetX, y + Model.OffsetY, theta, -ElementModel.Width / 2, -ElementModel.Height / 2);
|
||||
|
||||
public async Task UpdatePosition(double offsetX, double offsetY)
|
||||
=> await JSRuntime.InvokeVoidAsync("SetRobotPosition", ImageRef, textRef, Model.X + offsetX, Model.Y + offsetY, Model.Theta, -ElementModel.Width / 2, -ElementModel.Height / 2);
|
||||
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Model != null) Model.UpdateChanged -= Model_UpdateChanged;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using RobotNet.MapShares.Dtos;
|
||||
|
||||
namespace RobotNet.WebApp.Robots.Components.Monitoring.Element;
|
||||
|
||||
public class ElementModel(ElementDto element, NodeModel node) : 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 ElementDto Element { get; private set; } = element;
|
||||
public NodeModel Node { get; private set; } = node;
|
||||
|
||||
public event Func<Task>? UpdateChanged;
|
||||
|
||||
public void Update(ElementDto element)
|
||||
{
|
||||
Element.IsOpen = element.IsOpen;
|
||||
Element.OffsetX = element.OffsetX;
|
||||
Element.OffsetY = element.OffsetY;
|
||||
Element.Content = element.Content;
|
||||
UpdateChanged?.Invoke();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
text {
|
||||
dominant-baseline: middle;
|
||||
text-anchor: middle;
|
||||
fill: red;
|
||||
transform: scale(1, -1);
|
||||
font-size: 0.01em;
|
||||
user-select: none;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.element {
|
||||
transform-origin: center;
|
||||
transform-box: fill-box;
|
||||
}
|
||||
|
||||
.element:hover {
|
||||
cursor: pointer;
|
||||
transform: scale(1.2);
|
||||
filter: drop-shadow(0 0 5px rgba(0, 0, 0, 0.5));
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
@using Microsoft.JSInterop
|
||||
|
||||
@implements IDisposable
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<circle @ref="circleErrorRef" style="fill: red; opacity: 0.6; r: 0.3px;"/>
|
||||
<circle @ref="circleRef"/>
|
||||
<text @ref="textRef" visibility="@(ShowName ? "visible" : "hidden")">@Model?.Name</text>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public NodeModel Model { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<NodeModel> DoubleClick { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<NodeModel?> OnClick { get; set; }
|
||||
|
||||
[CascadingParameter]
|
||||
protected bool MapIsActive { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool ShowName { get; set; }
|
||||
|
||||
private ElementReference circleRef;
|
||||
private ElementReference textRef;
|
||||
private ElementReference circleErrorRef;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
await UpdatePosition(Model.X, Model.Y);
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", circleErrorRef, "visibility", "hidden");
|
||||
}
|
||||
|
||||
private async Task UpdatePosition(double x, double y)
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("SetNodePosition", circleRef, textRef, x, y);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using RobotNet.MapShares.Dtos;
|
||||
|
||||
namespace RobotNet.WebApp.Robots.Components.Monitoring.Element;
|
||||
|
||||
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 void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
circle {
|
||||
cursor: default;
|
||||
fill: #FFBD33;
|
||||
stroke: #FF5733;
|
||||
stroke-width: 0;
|
||||
r: var(--node-r);
|
||||
}
|
||||
|
||||
circle.setting:hover {
|
||||
stroke-width: 0.02px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
circle.setting:active {
|
||||
stroke-width: 0.02px;
|
||||
stroke: green;
|
||||
}
|
||||
|
||||
circle.active {
|
||||
stroke-width: 0.02px;
|
||||
stroke: green;
|
||||
}
|
||||
|
||||
circle:hover + text.setting {
|
||||
transition-delay: 0.1s;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
circle + text {
|
||||
transition-delay: 0.3s;
|
||||
font-size: 0.01em;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
text {
|
||||
dominant-baseline: middle;
|
||||
text-anchor: middle;
|
||||
fill: red;
|
||||
transform: scale(1, -1);
|
||||
user-select: none;
|
||||
}
|
||||
111
RobotNet.WebApp/Robots/Components/Monitoring/Element/Robot.razor
Normal file
111
RobotNet.WebApp/Robots/Components/Monitoring/Element/Robot.razor
Normal file
@@ -0,0 +1,111 @@
|
||||
@implements IDisposable
|
||||
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject IHttpClientFactory HttpFactory
|
||||
|
||||
<image @ref="@RobotRef" />
|
||||
<image @ref="@ElementRef" visibility="@(isCarrying ? "visible" : "hidden")" />
|
||||
<text @ref="textRef" visibility="@(ShowName ? "visible" : "hidden")">@Model?.RobotName</text>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public RobotVisualizationModel Model { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public bool ShowName { get; set; }
|
||||
|
||||
private ElementReference ElementRef;
|
||||
private ElementReference RobotRef;
|
||||
private ElementReference textRef;
|
||||
private RobotModelDto RobotModel = new();
|
||||
|
||||
private bool isCarrying = false;
|
||||
private ElementModelDto ElementModel = new();
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
using var Http = HttpFactory.CreateClient("RobotManagerAPI");
|
||||
var model = await Http.GetFromJsonAsync<MessageResult<RobotModelDto?>>($"api/Robots/Model/{Model.RobotId}");
|
||||
if (model is not null && model.Data is not null)
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("SetImageAttribute", RobotRef, model.Data.Length, model.Data.Width, model.Data.OriginX, model.Data.OriginY, $"{Http.BaseAddress}api/RobotModels/image/{model.Data.Id}");
|
||||
RobotModel = model.Data;
|
||||
}
|
||||
if (Model is not null)
|
||||
{
|
||||
Model.PositionChanged += Model_PositionChanged;
|
||||
Model.LoadsChanged += Model_LoadChanged;
|
||||
await UpdatePosition(Model.X, Model.Y, Model.Theta);
|
||||
if(Model.Loads.Length > 0 && Guid.TryParse(Model.Loads[0].LoadId, out Guid loadId))
|
||||
{
|
||||
await Model_LoadChanged(loadId);
|
||||
await UpdateLoadPosition(Model.X, Model.Y, Model.Theta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task SetParametersAsync(ParameterView parameters)
|
||||
{
|
||||
bool updateRobot = false;
|
||||
if (parameters.TryGetValue(nameof(Model), out RobotVisualizationModel? model) && ((Model?.RobotId ?? string.Empty) != (model?.RobotId ?? string.Empty)))
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.PositionChanged -= Model_PositionChanged;
|
||||
Model.LoadsChanged -= Model_LoadChanged;
|
||||
}
|
||||
|
||||
if (model != null)
|
||||
{
|
||||
updateRobot = true;
|
||||
model.PositionChanged += Model_PositionChanged;
|
||||
model.LoadsChanged += Model_LoadChanged;
|
||||
}
|
||||
}
|
||||
await base.SetParametersAsync(parameters);
|
||||
if (updateRobot && model != null)
|
||||
{
|
||||
await UpdatePosition(model.X, model.Y, model.Theta);
|
||||
if (model.Loads.Length > 0) await UpdateLoadPosition(model.X, model.Y, model.Theta);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Model_PositionChanged()
|
||||
{
|
||||
await UpdatePosition(Model.X, Model.Y, Model.Theta);
|
||||
await UpdateLoadPosition(Model.X, Model.Y, Model.Theta);
|
||||
}
|
||||
|
||||
public async Task UpdatePosition(double x, double y, double theta)
|
||||
=> await JSRuntime.InvokeVoidAsync("SetRobotPosition", RobotRef, textRef, x, y, theta, RobotModel.OriginX, RobotModel.OriginY);
|
||||
|
||||
private async Task UpdateLoadPosition(double x, double y, double theta)
|
||||
=> await JSRuntime.InvokeVoidAsync("SetRobotPosition", ElementRef, null, x, y, theta, -ElementModel.Width / 2, -ElementModel.Height / 2);
|
||||
|
||||
private async Task Model_LoadChanged(Guid elementModelId)
|
||||
{
|
||||
if (elementModelId != Guid.Empty)
|
||||
{
|
||||
using var Http = HttpFactory.CreateClient("MapManagerAPI");
|
||||
var model = await Http.GetFromJsonAsync<MessageResult<ElementModelDto?>>($"api/ElementModels/{elementModelId}");
|
||||
if (model is not null && model.Data is not null)
|
||||
{
|
||||
isCarrying = true;;
|
||||
await JSRuntime.InvokeVoidAsync("SetImageAttribute", ElementRef, model.Data.Width, model.Data.Height, -model.Data.Width / 2, -model.Data.Height / 2, $"{Http.BaseAddress}api/images/elementModel/{model.Data.Id}?IsOpen=true");
|
||||
await UpdateLoadPosition(Model.X, Model.Y, Model.Theta);
|
||||
ElementModel = model.Data;
|
||||
}
|
||||
}
|
||||
else isCarrying = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Model != null) Model.PositionChanged -= Model_PositionChanged;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using RobotNet.RobotShares.VDA5050.State;
|
||||
|
||||
namespace RobotNet.WebApp.Robots.Components.Monitoring.Element;
|
||||
|
||||
#nullable disable
|
||||
|
||||
public class RobotVisualizationModel : IDisposable
|
||||
{
|
||||
public string RobotId { get; set; }
|
||||
public string RobotName { get; set; }
|
||||
public double X { get; set; }
|
||||
public double Y { get; set; }
|
||||
public double Theta { get; set; }
|
||||
public Load[] Loads { get; set; } = [];
|
||||
public event Func<Task> PositionChanged;
|
||||
public event Func<Guid, Task> LoadsChanged;
|
||||
public void Update(double x, double y, double theta, Load[] loads)
|
||||
{
|
||||
if (X != x || Y != y || Theta != theta)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Theta = theta;
|
||||
PositionChanged?.Invoke();
|
||||
}
|
||||
|
||||
if (loads.Length > 0 && (Loads.Length == 0 || Loads[0].LoadId != loads[0].LoadId))
|
||||
{
|
||||
if (Guid.TryParse(loads[0].LoadId, out Guid elementModelId)) LoadsChanged?.Invoke(elementModelId);
|
||||
else LoadsChanged?.Invoke(Guid.Empty);
|
||||
Loads = loads;
|
||||
}
|
||||
else if (Loads.Length != 0 && loads.Length == 0)
|
||||
{
|
||||
LoadsChanged?.Invoke(Guid.Empty);
|
||||
Loads = loads;
|
||||
}
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
text {
|
||||
dominant-baseline: middle;
|
||||
text-anchor: middle;
|
||||
fill: red;
|
||||
transform: scale(1, -1);
|
||||
font-size: 0.01em;
|
||||
user-select: none;
|
||||
font-weight: normal;
|
||||
}
|
||||
/*
|
||||
image {
|
||||
transform: scale(1, -1);
|
||||
}*/
|
||||
@@ -0,0 +1,40 @@
|
||||
@inject IJSRuntime JSRuntime
|
||||
@implements IDisposable
|
||||
|
||||
<polygon @ref="Ref" fill="@Model.Fill" style="visibility: @(IsShow ? "visible" : "hidden")" />
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public ZoneModel Model { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<ZoneModel> DoubleClick { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool IsShow { get; set; }
|
||||
|
||||
[CascadingParameter]
|
||||
protected bool MapIsActive { get; set; }
|
||||
|
||||
private ElementReference Ref;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
await UpdateData();
|
||||
}
|
||||
|
||||
private async Task UpdateData()
|
||||
{
|
||||
string data = $"{Model.X1},{Model.Y1} {Model.X2},{Model.Y2} {Model.X3},{Model.Y3} {Model.X4},{Model.Y4}";
|
||||
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "points", data);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using RobotNet.MapShares.Dtos;
|
||||
using RobotNet.MapShares.Enums;
|
||||
|
||||
namespace RobotNet.WebApp.Robots.Components.Monitoring.Element;
|
||||
|
||||
public class ZoneModel(ZoneDto Data) : IDisposable
|
||||
{
|
||||
public Guid Id => Data.Id;
|
||||
public Guid MapId => Data.MapId;
|
||||
public ZoneType Type => Data.Type;
|
||||
|
||||
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 void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
polygon {
|
||||
stroke: none;
|
||||
fill-opacity: 0.5;
|
||||
stroke-linejoin: round;
|
||||
stroke-linecap: butt;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
polygon.setting:hover {
|
||||
stroke-width: 0.02px;
|
||||
stroke: red;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
polygon.setting:active {
|
||||
fill-opacity: 0.7;
|
||||
stroke-width: 0.02px;
|
||||
stroke: green;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
polygon.setting.active {
|
||||
fill-opacity: 0.7;
|
||||
stroke-width: 0.02px;
|
||||
stroke: green;
|
||||
cursor: pointer;
|
||||
z-index: 2;
|
||||
}
|
||||
37
RobotNet.WebApp/Robots/Components/Monitoring/MapGrid.razor
Normal file
37
RobotNet.WebApp/Robots/Components/Monitoring/MapGrid.razor
Normal file
@@ -0,0 +1,37 @@
|
||||
<g visibility="@(Show ? "visible" : "hidden")">
|
||||
@for (int x = startX; x <= endX; x += 1)
|
||||
{
|
||||
<line x1="@x" y1="@originY" x2="@x" y2="@(height + originY)" />
|
||||
}
|
||||
@for (int y = startY; y <= endY; y += 1)
|
||||
{
|
||||
<line x1="@originX" y1="@y" x2="@(width + originX)" y2="@y" />
|
||||
}
|
||||
</g>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public bool Show { get; set; }
|
||||
|
||||
private double originX;
|
||||
private double originY;
|
||||
private int startX;
|
||||
private int startY;
|
||||
private int endX;
|
||||
private int endY;
|
||||
private double width;
|
||||
private double height;
|
||||
|
||||
public void Resize(double mapOriginX, double mapOriginY, double mapheight, double mapwidth)
|
||||
{
|
||||
width = mapwidth;
|
||||
height = mapheight;
|
||||
originX = mapOriginX;
|
||||
originY = -height - mapOriginY;
|
||||
startX = (int)Math.Ceiling(originX);
|
||||
startY = (int)Math.Ceiling(originY);
|
||||
endX = (int)Math.Floor(width + mapOriginX);
|
||||
endY = (int)Math.Floor(-mapOriginY);
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
line {
|
||||
stroke: gray;
|
||||
stroke-width: 0.04px;
|
||||
stroke-opacity: 1;
|
||||
stroke-dasharray: 0.05 0.1;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<div class="map-editor-info">
|
||||
<div class="px-1 pt-1">
|
||||
@X
|
||||
</div>
|
||||
<div class ="px-1 pb-1">
|
||||
@Y
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private double X;
|
||||
private double Y;
|
||||
|
||||
public void Update(double x, double y)
|
||||
{
|
||||
X = Math.Round(x, 3);
|
||||
Y = Math.Round(y, 3);
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
div {
|
||||
width:fit-content;
|
||||
height: fit-content;
|
||||
}
|
||||
.map-editor-info {
|
||||
color: #00cc66;
|
||||
font-size: 15px;
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
left: 5px;
|
||||
font-weight: bold;
|
||||
background-color:white;
|
||||
border-radius:4px
|
||||
}
|
||||
30
RobotNet.WebApp/Robots/Components/Monitoring/MapRobot.razor
Normal file
30
RobotNet.WebApp/Robots/Components/Monitoring/MapRobot.razor
Normal file
@@ -0,0 +1,30 @@
|
||||
@implements IDisposable
|
||||
|
||||
@using RobotNet.WebApp.Robots.Components.Monitoring.Element
|
||||
|
||||
@foreach (var robot in Models)
|
||||
{
|
||||
<Robot Model="@robot" ShowName="@ShowName" />
|
||||
}
|
||||
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public MapRobotModel Models { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public bool ShowName { get; set; }
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
Models.Changed += StateHasChanged;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Models.Changed -= StateHasChanged;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using RobotNet.WebApp.Robots.Components.Monitoring.Element;
|
||||
using System.Collections;
|
||||
|
||||
namespace RobotNet.WebApp.Robots.Components.Monitoring;
|
||||
|
||||
public class MapRobotModel : IEnumerable<RobotVisualizationModel>
|
||||
{
|
||||
private readonly Dictionary<string, RobotVisualizationModel> dicRobots = [];
|
||||
public IEnumerator<RobotVisualizationModel> GetEnumerator() => dicRobots.Values.GetEnumerator();
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
public event Action? Changed;
|
||||
|
||||
public void Add(RobotVisualizationModel robot)
|
||||
{
|
||||
if (dicRobots.ContainsKey(robot.RobotId)) return;
|
||||
|
||||
dicRobots.Add(robot.RobotId, robot);
|
||||
Changed?.Invoke();
|
||||
}
|
||||
|
||||
public bool ContainsKey(string key) => dicRobots.ContainsKey(key);
|
||||
|
||||
public void ReplaceAll(IEnumerable<RobotVisualizationModel> robots)
|
||||
{
|
||||
foreach (var robot in dicRobots.Values)
|
||||
{
|
||||
robot.Dispose();
|
||||
}
|
||||
dicRobots.Clear();
|
||||
|
||||
foreach (var robot in robots)
|
||||
{
|
||||
robot.Update(robot.X, robot.Y, robot.Theta, robot.Loads);
|
||||
dicRobots.Add(robot.RobotId, robot);
|
||||
}
|
||||
Changed?.Invoke();
|
||||
}
|
||||
|
||||
public void Remove(RobotVisualizationModel robot)
|
||||
{
|
||||
if (!dicRobots.ContainsKey(robot.RobotId)) return;
|
||||
robot.Dispose();
|
||||
dicRobots.Remove(robot.RobotId);
|
||||
Changed?.Invoke();
|
||||
}
|
||||
|
||||
public bool TryGetValue(string id, out RobotVisualizationModel? value) => dicRobots.TryGetValue(id, out value);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<defs>
|
||||
<marker id="edge-two-way" markerWidth="2" markerHeight="1" refX="1" refY="0.5" orient="auto">
|
||||
<polyline points="0.8,0.3 0.6,0.5 0.8,0.7"/>
|
||||
<polyline points="1.2,0.3 1.4,0.5 1.2,0.7"/>
|
||||
<polyline points="0.6,0.5 1.4,0.5" />
|
||||
</marker>
|
||||
<marker id="edge-forward" markerWidth="2" markerHeight="1" refX="1" refY="0.5" orient="auto">
|
||||
<polyline points="1.2,0.3 1.4,0.5 1.2,0.7"/>
|
||||
<polyline points="0.6,0.5 1.4,0.5"/>
|
||||
</marker>
|
||||
<marker id="edge-backward" markerWidth="2" markerHeight="1" refX="1" refY="0.5" orient="auto">
|
||||
<polyline points="0.8,0.3 0.6,0.5 0.8,0.7"/>
|
||||
<polyline points="0.6,0.5 1.4,0.5"/>
|
||||
</marker>
|
||||
<marker id="edge-none" markerWidth="2" markerHeight="1" refX="1" refY="0.5" orient="auto">
|
||||
<polyline points="0.6,0.5 1.4,0.5"/>
|
||||
</marker>
|
||||
</defs>
|
||||
|
||||
@code {
|
||||
public static string GetMakerMid(DirectionAllowed direction)
|
||||
{
|
||||
return direction switch
|
||||
{
|
||||
DirectionAllowed.Both => $"url(#edge-two-way)",
|
||||
DirectionAllowed.Forward => $"url(#edge-forward)",
|
||||
DirectionAllowed.Backward => $"url(#edge-backward)",
|
||||
DirectionAllowed.None => $"url(#edge-none)",
|
||||
_ => "",
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
polyline {
|
||||
stroke: #DD22FF;
|
||||
stroke-width: 0.05px;
|
||||
fill: none;
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
@using RobotNet.RobotShares.VDA5050.State
|
||||
|
||||
<div class="d-flex h-100 d-flex flex-column overflow-x-hidden overflow-y-auto p-2" style="width: 250px" hidden="@(!IsExpand)">
|
||||
<MudExpansionPanels Elevation="0" Style="border: 1px solid silver">
|
||||
<MudExpansionPanel Expanded="true">
|
||||
<TitleContent>
|
||||
<MudText>Visualization</MudText>
|
||||
</TitleContent>
|
||||
<ChildContent>
|
||||
<MudTextField Class="mb-2" Label="X" Value="RobotStateSelected.AgvPosition.X" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
<MudTextField Class="my-2" Label="Y" Value="RobotStateSelected.AgvPosition.Y" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
<MudTextField Class="my-2" Label="Theta" Value="RobotStateSelected.AgvPosition.Theta" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
<MudTextField Class="my-2" Label="Velocity X" Value="RobotStateSelected.AgvVelocity.Vx" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
<MudTextField Class="mt-2" Label="Velocity Y" Value="RobotStateSelected.AgvVelocity.Vy" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
<MudTextField Class="mt-2" Label="Angular Velocity" Value="RobotStateSelected.AgvVelocity.Omega" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</ChildContent>
|
||||
</MudExpansionPanel>
|
||||
</MudExpansionPanels>
|
||||
|
||||
<MudExpansionPanels Elevation="0" Class="mt-2" Style="border: 1px solid silver">
|
||||
<MudExpansionPanel Expanded="true">
|
||||
<TitleContent>
|
||||
<MudText>Localization</MudText>
|
||||
</TitleContent>
|
||||
<ChildContent>
|
||||
<MudText Class="ms-2">Initialized: @RobotStateSelected.AgvPosition.PositionInitialized</MudText>
|
||||
<MudText Class="ms-2">Quality: @RobotStateSelected.AgvPosition.LocalizationScore</MudText>
|
||||
<MudText Class="ms-2">DeviationRange: @RobotStateSelected.AgvPosition.DeviationRange</MudText>
|
||||
</ChildContent>
|
||||
</MudExpansionPanel>
|
||||
</MudExpansionPanels>
|
||||
|
||||
<MudExpansionPanels Elevation="0" Class="mt-2" Style="border: 1px solid silver">
|
||||
<MudExpansionPanel Expanded="true">
|
||||
<TitleContent>
|
||||
<MudText>Battery</MudText>
|
||||
</TitleContent>
|
||||
<ChildContent>
|
||||
<MudProgressLinear Class="m-2" Color="@(RobotStateSelected.Battery.BatteryHealth < 10 ? Color.Error : RobotStateSelected.Battery.BatteryHealth > 20 ? Color.Success : Color.Warning)" Rounded Striped Size="Size.Large" Value="@RobotStateSelected.Battery.BatteryHealth" />
|
||||
<MudText Class="ms-2">@($"Health: {Math.Round(RobotStateSelected.Battery.BatteryHealth, 1)}%")</MudText>
|
||||
<MudText Class="ms-2">@($"Voltage: {Math.Round(RobotStateSelected.Battery.BatteryVoltage, 1)}V")</MudText>
|
||||
<MudText Class="ms-2">@($"State: {Math.Round(RobotStateSelected.Battery.BatteryCharge, 1)}")</MudText>
|
||||
<MudText Class="ms-2">@($"Charging: {RobotStateSelected.Battery.Charging}")</MudText>
|
||||
</ChildContent>
|
||||
</MudExpansionPanel>
|
||||
</MudExpansionPanels>
|
||||
|
||||
<MudExpansionPanels Elevation="0" Class="mt-2" Style="border: 1px solid silver">
|
||||
<MudExpansionPanel>
|
||||
<TitleContent>
|
||||
<div class="d-flex">
|
||||
<MudText>Errors</MudText>
|
||||
<MudBadge Content="RobotStateSelected.Errors.Length" Color="Color.Info" Overlap="true" Class="d-flex ml-auto">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Info" Color="Color.Secondary" />
|
||||
</MudBadge>
|
||||
</div>
|
||||
</TitleContent>
|
||||
<ChildContent>
|
||||
@foreach (var error in RobotStateSelected.Errors)
|
||||
{
|
||||
<MudTooltip Text="@error.ErrorDescription" Placement="Placement.Top" Color="Color.Info">
|
||||
<MudButton Class="m-2" Color="@(error.ErrorLevel == ErrorLevel.FATAL.ToString() ? Color.Error : Color.Warning)" Variant="Variant.Filled" Size="Size.Small" Style="text-transform:none">@error.ErrorType</MudButton>
|
||||
</MudTooltip>
|
||||
}
|
||||
</ChildContent>
|
||||
</MudExpansionPanel>
|
||||
</MudExpansionPanels>
|
||||
|
||||
<MudExpansionPanels Elevation="0" Class="mt-2" Style="border: 1px solid silver">
|
||||
<MudExpansionPanel>
|
||||
<TitleContent>
|
||||
<div class="d-flex">
|
||||
<MudText>Notification</MudText>
|
||||
<MudBadge Content="RobotStateSelected.Infomations.Length" Color="Color.Info" Overlap="true" Class="d-flex ml-auto">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Notifications" Color="Color.Warning" />
|
||||
</MudBadge>
|
||||
</div>
|
||||
</TitleContent>
|
||||
<ChildContent>
|
||||
<div class="d-flex flex-column">
|
||||
@foreach (var info in RobotStateSelected.Infomations)
|
||||
{
|
||||
<MudTooltip Text="@info.InfoDescription" Placement="Placement.Top" Color="Color.Info">
|
||||
<MudButton Class="m-2" Color="@(info.InfoLevel == InfoLevel.INFO.ToString() ? Color.Info : Color.Default)" Variant="Variant.Filled" Size="Size.Small" Style="text-transform:none">@info.InfoType</MudButton>
|
||||
</MudTooltip>
|
||||
}
|
||||
</div>
|
||||
</ChildContent>
|
||||
</MudExpansionPanel>
|
||||
</MudExpansionPanels>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private RobotInfomationDto RobotStateSelected = new();
|
||||
private bool IsExpand = true;
|
||||
|
||||
public void ExpandedClick(bool value)
|
||||
{
|
||||
IsExpand = value;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public void UpdateState(RobotInfomationDto data)
|
||||
{
|
||||
RobotStateSelected.Battery.BatteryVoltage = data.Battery.BatteryVoltage;
|
||||
RobotStateSelected.Battery.BatteryHealth = data.Battery.BatteryHealth;
|
||||
RobotStateSelected.Battery.BatteryCharge = data.Battery.BatteryCharge;
|
||||
RobotStateSelected.Battery.Charging = data.Battery.Charging;
|
||||
|
||||
RobotStateSelected.AgvPosition.LocalizationScore = data.AgvPosition.LocalizationScore;
|
||||
RobotStateSelected.AgvPosition.PositionInitialized = data.AgvPosition.PositionInitialized;
|
||||
RobotStateSelected.AgvPosition.DeviationRange = data.AgvPosition.DeviationRange;
|
||||
|
||||
RobotStateSelected.AgvPosition.X = data.AgvPosition.X;
|
||||
RobotStateSelected.AgvPosition.Y = data.AgvPosition.Y;
|
||||
RobotStateSelected.AgvPosition.Theta = data.AgvPosition.Theta;
|
||||
RobotStateSelected.AgvVelocity.Vx = data.AgvVelocity.Vx;
|
||||
RobotStateSelected.AgvVelocity.Vy = data.AgvVelocity.Vy;
|
||||
RobotStateSelected.AgvVelocity.Omega = data.AgvVelocity.Omega;
|
||||
|
||||
RobotStateSelected.Errors = [.. data.Errors];
|
||||
RobotStateSelected.Infomations = [.. data.Infomations];
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
501
RobotNet.WebApp/Robots/Components/Monitoring/MonitorMap.razor
Normal file
501
RobotNet.WebApp/Robots/Components/Monitoring/MonitorMap.razor
Normal file
@@ -0,0 +1,501 @@
|
||||
@using RobotNet.WebApp.Robots.Components.Monitoring.Element
|
||||
@using System.Text.Json
|
||||
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService DialogService
|
||||
@inject IHttpClientFactory HttpFactory
|
||||
|
||||
<div class="monitor-map" @ref="ViewContainerRef">
|
||||
<div @ref="ViewMovementRef">
|
||||
<svg @ref="MapContainerRef" class="monitor-map-view" letter-spacing="normal">
|
||||
<MapSvgDefs />
|
||||
<image @ref="MapImageRef" class="monitor-map-image" />
|
||||
<OriginVector />
|
||||
<MapGrid @ref="@MapGridRef" Show="@ShowGrid" />
|
||||
|
||||
@foreach (var zone in zones)
|
||||
{
|
||||
<Zone Model="zone" IsShow="true" />
|
||||
}
|
||||
@foreach (var edge in edges)
|
||||
{
|
||||
<Edge Model="edge" />
|
||||
}
|
||||
@foreach (var edge in edges)
|
||||
{
|
||||
<EdgeDirection Model="edge" />
|
||||
}
|
||||
@foreach (var node in nodes)
|
||||
{
|
||||
<Node Model="node" ShowName="@ShowName" />
|
||||
}
|
||||
@foreach (var element in elements)
|
||||
{
|
||||
<Element Model="element" ShowName="@ShowName" Show="@ShowElement" DoubleClick="ElementDoubleClick" />
|
||||
}
|
||||
<RobotCurrentPath @ref="@RobotCurrentPathRef" Show="@ShowPath" />
|
||||
<RobotPath @ref="@RobotPathRef" Show="@ShowPath" />
|
||||
<MapRobot Models="robots" ShowName="@ShowName" />
|
||||
<RobotLaserScaner @ref="RobotLaserScanerRef" ShowLaser="ShowLaser" />
|
||||
</svg>
|
||||
</div>
|
||||
<MapMousePosition @ref="MapInfoRef" />
|
||||
</div>
|
||||
|
||||
<MudDialog @bind-Visible="updateElementVisble">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">
|
||||
Update Element @ElementUpdateModel.Name
|
||||
</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<div class="d-flex flex-row" style="max-height: 700px; overflow-y: auto; width: 600px">
|
||||
<div class="d-flex flex-column h-100 me-2" style="width: 47%">
|
||||
<MudTextField T="string" Label="Name" @bind-value="ElementUpdateModel.Name" Variant="Variant.Outlined"
|
||||
Required="true" RequiredError="Name is required!" ReadOnly
|
||||
Validation="@(new Func<string, IEnumerable<string>>(MapEditorHelper.NameValidation))" />
|
||||
<MudNumericField T="double" Label="Offset X" @bind-value="ElementUpdateModel.OffsetX" Variant="Variant.Outlined" Step="0.1" ReadOnly />
|
||||
<MudNumericField T="double" Label="Offset Y" @bind-value="ElementUpdateModel.OffsetY" Variant="Variant.Outlined" Step="0.1" ReadOnly />
|
||||
<MudCheckBox Size="Size.Small" T="bool" LabelPlacement="Placement.Start" Label="IsOpen" @bind-value="ElementUpdateModel.IsOpen" Color="Color.Success"
|
||||
UncheckedColor="Color.Default" />
|
||||
</div>
|
||||
<div class="paper-property-container">
|
||||
<div class="paper-property ms-2">
|
||||
@foreach (var property in ElementProperties)
|
||||
{
|
||||
@if (property.Type == typeof(int).ToString())
|
||||
{
|
||||
if (int.TryParse(property.DefaultValue, out int value))
|
||||
{
|
||||
<MudNumericField T="int" Margin="Margin.Dense" Label="@property.Name" Value="value" Variant="Variant.Outlined" ReadOnly="@(property.ReadOnly)"
|
||||
ValueChanged="((data) => DefaultIntValueChanged(property.Id, data))" />
|
||||
}
|
||||
}
|
||||
else if (property.Type == typeof(double).ToString())
|
||||
{
|
||||
if (double.TryParse(property.DefaultValue, out double value))
|
||||
{
|
||||
<MudNumericField T="double" Margin="Margin.Dense" Label="@property.Name" Value="value" Variant="Variant.Outlined" Step="0.1" ReadOnly="@(property.ReadOnly)"
|
||||
ValueChanged="((data) => DefaultDoubleValueChanged(property.Id, data))" />
|
||||
}
|
||||
}
|
||||
else if (property.Type == typeof(bool).ToString())
|
||||
{
|
||||
if (bool.TryParse(property.DefaultValue, out bool value))
|
||||
{
|
||||
<MudCheckBox Class="m-0" Size="Size.Small" T="bool" LabelPlacement="Placement.Start" Label="@property.Name" Value="value" Color="Color.Success"
|
||||
UncheckedColor="Color.Default" ReadOnly="@(property.ReadOnly)" ValueChanged="((data) => DefaultBooleanValueChanged(property.Id, data))" />
|
||||
}
|
||||
}
|
||||
else if (property.Type == typeof(string).ToString())
|
||||
{
|
||||
<MudTextField T="string" Label="@property.Name" Value="@property.DefaultValue" Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly="@(property.ReadOnly)"
|
||||
ValueChanged="((data) => property.DefaultValue = data)" />
|
||||
}
|
||||
}
|
||||
</div>
|
||||
<span class="paper-title">Properties</span>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="(() => updateElementVisble = false)" Class="px-10" Variant="Variant.Filled">Cancel</MudButton>
|
||||
<MudButton OnClick="UpdateElement" Variant="Variant.Filled" Color="Color.Primary" Class="px-10 me-4">Update</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
|
||||
[Parameter]
|
||||
public bool ShowGrid { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool ShowName { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool ShowPath { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool ShowLaser { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool ShowElement { get; set; }
|
||||
|
||||
private MapMousePosition MapInfoRef = null!;
|
||||
private RobotPath RobotPathRef = null!;
|
||||
private RobotCurrentPath RobotCurrentPathRef = null!;
|
||||
private MapGrid MapGridRef = null!;
|
||||
private RobotLaserScaner RobotLaserScanerRef = null!;
|
||||
|
||||
private DotNetObjectReference<MonitorMap> DotNetObj = null!;
|
||||
private ElementReference ViewContainerRef;
|
||||
private ElementReference ViewMovementRef;
|
||||
private ElementReference MapContainerRef;
|
||||
private ElementReference MapImageRef;
|
||||
|
||||
private double ViewContainerRectX;
|
||||
private double ViewContainerRectY;
|
||||
private double ViewContainerRectWidth;
|
||||
private double ViewContainerRectHeight;
|
||||
private double ViewContainerRectTop;
|
||||
private double ViewContainerRectRight;
|
||||
private double ViewContainerRectBottom;
|
||||
private double ViewContainerRectLeft;
|
||||
|
||||
private double CursorX;
|
||||
private double CursorY;
|
||||
private double ClientOriginX;
|
||||
private double ClientOriginY;
|
||||
|
||||
private double Resolution = 1;
|
||||
private double OriginX;
|
||||
private double OriginY;
|
||||
private double ImageOriginY;
|
||||
private double ImageWidth;
|
||||
private double ImageHeight;
|
||||
private double Scale = 1;
|
||||
private double Left;
|
||||
private double Top;
|
||||
private double FitScale = 1;
|
||||
private double OldOriginY;
|
||||
|
||||
private List<EdgeModel> edges = new();
|
||||
private List<NodeModel> nodes = new();
|
||||
private List<ZoneModel> zones = new();
|
||||
private List<ElementModel> elements = new();
|
||||
private MapRobotModel robots = new();
|
||||
|
||||
private bool IsFocusRobot = false;
|
||||
private string RobotSelectedId = "";
|
||||
|
||||
private bool updateElementVisble;
|
||||
private ElementUpdateModel ElementUpdateModel = new();
|
||||
private List<MapShares.Property.ElementProperty> ElementProperties = [];
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
DotNetObj = DotNetObjectReference.Create(this);
|
||||
|
||||
await JSRuntime.InvokeVoidAsync("DOMCssLoaded");
|
||||
|
||||
await JSRuntime.InvokeVoidAsync("UpdateViewContainerRect", DotNetObj, ViewContainerRef, nameof(ViewContainerResize));
|
||||
await JSRuntime.InvokeVoidAsync("ResizeObserverRegister", DotNetObj, ViewContainerRef, nameof(ViewContainerResize));
|
||||
await JSRuntime.InvokeVoidAsync("AddEventListener", DotNetObj, ViewContainerRef, "click", nameof(ViewContainerClick));
|
||||
await JSRuntime.InvokeVoidAsync("AddMouseMoveEventListener", DotNetObj, ViewContainerRef, nameof(MouseMoveOnMapContainer));
|
||||
|
||||
await JSRuntime.InvokeVoidAsync("AddMouseWheelEventListener", DotNetObj, MapContainerRef, nameof(MouseWheelOnMapContainer));
|
||||
await JSRuntime.InvokeVoidAsync("AddTouchMoveEventListener", DotNetObj, ViewContainerRef, nameof(TouchMoveOnMapContainer));
|
||||
}
|
||||
|
||||
public async Task LoadMap(MapDataDto? mapData)
|
||||
{
|
||||
if (mapData == null)
|
||||
{
|
||||
nodes.Clear();
|
||||
edges.Clear();
|
||||
zones.Clear();
|
||||
elements.Clear();
|
||||
robots.ReplaceAll([]);
|
||||
RobotCurrentPathRef.UpdatePath([]);
|
||||
RobotPathRef.UpdatePath([]);
|
||||
Resolution = 1.0;
|
||||
OriginY = 0;
|
||||
OriginX = 0;
|
||||
OldOriginY = 0;
|
||||
ImageOriginY = 0;
|
||||
ImageHeight = 0;
|
||||
ImageWidth = 0;
|
||||
MapGridRef.Resize(OriginX, OriginY, ImageHeight, ImageWidth);
|
||||
await JSRuntime.InvokeVoidAsync("SetMapSvgConfig", MapContainerRef, ImageWidth, ImageHeight, OriginX, 1.0);
|
||||
await JSRuntime.InvokeVoidAsync("SetImageAttribute", MapImageRef, ImageWidth, ImageHeight, OriginX, OriginY, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
nodes = [.. mapData.Nodes.Select(node => new NodeModel(node))];
|
||||
edges = [.. mapData.Edges.Select(edge => new EdgeModel(edge, nodes.First(n => n.Id == edge.StartNodeId), nodes.First(n => n.Id == edge.EndNodeId)))];
|
||||
zones = [.. mapData.Zones.Select(zone => new ZoneModel(zone))];
|
||||
elements = [.. mapData.Elements.Select(element => new ElementModel(element, nodes.First(n => n.Id == element.NodeId)))];
|
||||
Resolution = mapData.Resolution;
|
||||
OldOriginY = mapData.OriginY;
|
||||
OriginY = -mapData.ImageHeight * Resolution - mapData.OriginY;
|
||||
OriginX = mapData.OriginX;
|
||||
ImageOriginY = mapData.OriginY;
|
||||
ImageHeight = mapData.ImageHeight * Resolution;
|
||||
ImageWidth = mapData.ImageWidth * Resolution;
|
||||
MapGridRef.Resize(OriginX, OriginY, ImageHeight, ImageWidth);
|
||||
|
||||
using var Http = HttpFactory.CreateClient("MapManagerAPI");
|
||||
|
||||
await JSRuntime.InvokeVoidAsync("SetMapSvgConfig", MapContainerRef, ImageWidth, ImageHeight, OriginX, mapData.OriginY);
|
||||
await JSRuntime.InvokeVoidAsync("SetImageAttribute", MapImageRef, ImageWidth, ImageHeight, OriginX, OriginY, $"{Http.BaseAddress}api/images/map/{mapData.Id}");
|
||||
await JSRuntime.InvokeVoidAsync("UpdateViewContainerRect", DotNetObj, ViewContainerRef, nameof(ViewContainerResize));
|
||||
await ScaleFitContentAsync();
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public async Task ScaleFitContentAsync()
|
||||
{
|
||||
Scale = FitScale;
|
||||
await SetViewMovement((ViewContainerRectWidth - ImageWidth * Scale) / 2, (ViewContainerRectHeight - ImageHeight * Scale) / 2);
|
||||
await JSRuntime.InvokeVoidAsync("SetMapSvgRect", MapContainerRef, ImageWidth * Scale, ImageHeight * Scale);
|
||||
}
|
||||
|
||||
private async Task SetViewMovement(double left, double top)
|
||||
{
|
||||
Top = top;
|
||||
Left = left;
|
||||
|
||||
ClientOriginX = ViewContainerRectLeft + Left - OriginX * Scale;
|
||||
ClientOriginY = ViewContainerRectTop + Top - OriginY * Scale;
|
||||
await JSRuntime.InvokeVoidAsync("SetMapMovement", ViewMovementRef, Top, Left);
|
||||
}
|
||||
|
||||
public async Task ScaleZoom(double deltaY)
|
||||
{
|
||||
if (deltaY > 0)
|
||||
{
|
||||
if (Scale >= FitScale * 20) return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Scale <= FitScale / 2) return;
|
||||
}
|
||||
double oldScale = Scale;
|
||||
Scale += deltaY;
|
||||
|
||||
double centerXBefore = ((ViewContainerRectLeft + ViewContainerRectWidth / 2) - ClientOriginX) / oldScale - OriginX;
|
||||
double centerYBefore = (ClientOriginY - (ViewContainerRectHeight / 2 + ViewContainerRectTop)) / oldScale - OldOriginY;
|
||||
|
||||
await SetViewMovement(Left - centerXBefore * deltaY, Top - (ImageHeight - centerYBefore) * deltaY);
|
||||
await JSRuntime.InvokeVoidAsync("SetMapSvgRect", MapContainerRef, ImageWidth * Scale, ImageHeight * Scale);
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public void ViewContainerResize(double x, double y, double width, double height, double top, double right, double bottom, double left)
|
||||
{
|
||||
ViewContainerRectX = x;
|
||||
ViewContainerRectY = y;
|
||||
ViewContainerRectWidth = width;
|
||||
ViewContainerRectHeight = height;
|
||||
ViewContainerRectTop = top;
|
||||
ViewContainerRectRight = right;
|
||||
ViewContainerRectBottom = bottom;
|
||||
ViewContainerRectLeft = left;
|
||||
|
||||
ClientOriginX = ViewContainerRectLeft + Left - OriginX * Scale;
|
||||
ClientOriginY = ViewContainerRectTop + Top - OriginY * Scale;
|
||||
|
||||
FitScale = Math.Min(ViewContainerRectWidth / ImageWidth, ViewContainerRectHeight / ImageHeight);
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public async Task TouchMoveOnMapContainer(double clientX, double clientY, int touchCount, double movementX, double movementY)
|
||||
{
|
||||
CursorX = (clientX - ClientOriginX) / Scale;
|
||||
CursorY = (ClientOriginY - clientY) / Scale;
|
||||
MapInfoRef.Update(CursorX, CursorY);
|
||||
|
||||
if (touchCount == 1) await SetViewMovement(Left + movementX, Top + movementY);
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public async Task MouseWheelOnMapContainer(double deltaY, double offsetX, double offsetY)
|
||||
{
|
||||
double scaleChange;
|
||||
if (deltaY > 0)
|
||||
{
|
||||
if (Scale <= FitScale / 2) return;
|
||||
scaleChange = Scale > FitScale ? -(Scale / FitScale) : -0.1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Scale >= FitScale * 100) return;
|
||||
scaleChange = Scale < FitScale ? 0.5 : (Scale / FitScale);
|
||||
}
|
||||
|
||||
double oldScale = Scale;
|
||||
|
||||
Scale += scaleChange;
|
||||
await JSRuntime.InvokeVoidAsync("SetMapSvgRect", MapContainerRef, ImageWidth * Scale, ImageHeight * Scale);
|
||||
|
||||
double mouseX = CursorX - OriginX;
|
||||
double mouseY = CursorY - OldOriginY;
|
||||
await SetViewMovement(Left - mouseX * scaleChange, Top - (ImageHeight - mouseY) * scaleChange);
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public async Task ViewContainerClick() => await ViewContainerRef.FocusAsync();
|
||||
|
||||
[JSInvokable]
|
||||
public async Task MouseMoveOnMapContainer(double clientX, double clientY, long buttons, bool ctrlKey, double movementX, double movementY)
|
||||
{
|
||||
CursorX = (clientX - ClientOriginX) / Scale;
|
||||
CursorY = (ClientOriginY - clientY) / Scale;
|
||||
MapInfoRef.Update(CursorX, CursorY);
|
||||
|
||||
if (IsFocusRobot) return;
|
||||
switch (buttons)
|
||||
{
|
||||
case 4:
|
||||
await SetViewMovement(Left + movementX, Top + movementY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadRobots(IEnumerable<RobotInfomationDto> robotDtos)
|
||||
{
|
||||
if (robotDtos.Any())
|
||||
{
|
||||
var robotModel = robotDtos.Select(robot => new RobotVisualizationModel()
|
||||
{
|
||||
RobotId = robot.RobotId,
|
||||
RobotName = robot.Name,
|
||||
X = robot.AgvPosition.X,
|
||||
Y = robot.AgvPosition.Y,
|
||||
Theta = robot.AgvPosition.Theta,
|
||||
}).ToArray();
|
||||
robots.ReplaceAll(robotModel);
|
||||
}
|
||||
else robots.ReplaceAll([]);
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public void RobotSelectedChange(string robotId)
|
||||
{
|
||||
if (robotId != RobotSelectedId) RobotSelectedId = robotId;
|
||||
}
|
||||
|
||||
public void FocusRobot(bool value) => IsFocusRobot = value;
|
||||
|
||||
public async Task FocusRobotAsync()
|
||||
{
|
||||
var robot = robots.FirstOrDefault(r => r.RobotId == RobotSelectedId);
|
||||
if (robot is null) return;
|
||||
double mapX = (ViewContainerRectWidth - ImageWidth * Scale) / 2 + ((ImageWidth / 2 + OriginX) * Scale) - robot.X * Scale;
|
||||
double mapY = (ViewContainerRectHeight - ImageHeight * Scale) / 2 + ((ImageHeight / 2 + OriginY) * Scale) + robot.Y * Scale;
|
||||
await SetViewMovement(mapX, mapY);
|
||||
}
|
||||
|
||||
public async Task SetRobotPosition(List<RobotInfomationDto> robotStates)
|
||||
{
|
||||
foreach (var robot in robotStates)
|
||||
{
|
||||
var robotModel = robots.FirstOrDefault(rm => rm.RobotId == robot.RobotId);
|
||||
if (robotModel is not null)
|
||||
{
|
||||
robotModel.Update(robot.AgvPosition.X, robot.AgvPosition.Y, robot.AgvPosition.Theta, robot.Loads);
|
||||
if (IsFocusRobot && robot.RobotId == RobotSelectedId) await FocusRobotAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
robots.Add(new()
|
||||
{
|
||||
RobotId = robot.RobotId,
|
||||
RobotName = robot.Name,
|
||||
X = robot.AgvPosition.X,
|
||||
Y = robot.AgvPosition.Y,
|
||||
Theta = robot.AgvPosition.Theta,
|
||||
Loads = robot.Loads
|
||||
});
|
||||
StateHasChanged();
|
||||
}
|
||||
if (robot.RobotId == RobotSelectedId)
|
||||
{
|
||||
RobotPathRef.UpdatePath([.. robot.Navigation.RobotPath]);
|
||||
RobotCurrentPathRef.UpdatePath([.. robot.Navigation.RobotBasePath]);
|
||||
RobotLaserScanerRef.SetData(robot.Navigation.LaserScaner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ElementStateUpdated(IEnumerable<ElementDto> elementsState)
|
||||
{
|
||||
foreach (var elmenet in elementsState)
|
||||
{
|
||||
var elemetModel = elements.FirstOrDefault(e => e.Id == elmenet.Id);
|
||||
if (elemetModel is not null)
|
||||
{
|
||||
elemetModel.Update(elmenet);
|
||||
}
|
||||
else
|
||||
{
|
||||
var node = nodes.FirstOrDefault(n => n.Id == elmenet.NodeId);
|
||||
if (node is not null) elements.Add(new ElementModel(elmenet, node));
|
||||
}
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void DefaultIntValueChanged(Guid id, int value)
|
||||
{
|
||||
var property = ElementProperties.FirstOrDefault(p => p.Id == id);
|
||||
if (property is null) return;
|
||||
property.DefaultValue = value.ToString();
|
||||
}
|
||||
|
||||
private void DefaultDoubleValueChanged(Guid id, double value)
|
||||
{
|
||||
var property = ElementProperties.FirstOrDefault(p => p.Id == id);
|
||||
if (property is null) return;
|
||||
property.DefaultValue = value.ToString();
|
||||
}
|
||||
|
||||
private void DefaultBooleanValueChanged(Guid id, bool value)
|
||||
{
|
||||
var property = ElementProperties.FirstOrDefault(p => p.Id == id);
|
||||
if (property is null) return;
|
||||
property.DefaultValue = value.ToString();
|
||||
}
|
||||
|
||||
private void ElementDoubleClick(ElementModel model)
|
||||
{
|
||||
ElementUpdateModel.Id = model.Id;
|
||||
ElementUpdateModel.Name = model.Name;
|
||||
ElementUpdateModel.IsOpen = model.IsOpen;
|
||||
ElementUpdateModel.OffsetX = model.OffsetX;
|
||||
ElementUpdateModel.OffsetY = model.OffsetY;
|
||||
ElementUpdateModel.Content = model.Content;
|
||||
|
||||
if (model is not null && !string.IsNullOrEmpty(model.Content))
|
||||
{
|
||||
var properties = JsonSerializer.Deserialize<List<MapShares.Property.ElementProperty>>(model.Content, JsonOptionExtends.Read);
|
||||
if (properties is not null) ElementProperties = [.. properties];
|
||||
}
|
||||
|
||||
updateElementVisble = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task UpdateElement()
|
||||
{
|
||||
var selectedElement = elements.FirstOrDefault(e => e.Id == ElementUpdateModel.Id);
|
||||
if (selectedElement is null) return;
|
||||
|
||||
using var Http = HttpFactory.CreateClient("MapManagerAPI");
|
||||
var result = await (await Http.PutAsJsonAsync($"api/Elements", new ElementUpdateModel()
|
||||
{
|
||||
Id = ElementUpdateModel.Id,
|
||||
Name = ElementUpdateModel.Name,
|
||||
IsOpen = ElementUpdateModel.IsOpen,
|
||||
OffsetX = ElementUpdateModel.OffsetX,
|
||||
OffsetY = ElementUpdateModel.OffsetY,
|
||||
Content = JsonSerializer.Serialize(ElementProperties, JsonOptionExtends.Write),
|
||||
})).Content.ReadFromJsonAsync<MessageResult<ElementDto>>();
|
||||
if (result == null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (!result.IsSuccess) Snackbar.Add(result.Message, Severity.Error);
|
||||
else if (result.Data is null) Snackbar.Add("Lỗi dữ liệu", Severity.Error);
|
||||
else
|
||||
{
|
||||
selectedElement.Update(result.Data);
|
||||
Snackbar.Add("Cập nhật thành công", Severity.Success);
|
||||
}
|
||||
|
||||
updateElementVisble = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
.monitor-map {
|
||||
background-color: #808080;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
cursor: not-allowed;
|
||||
border-top: solid 2px #808080;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.monitor-map > div {
|
||||
width: fit-content;
|
||||
height: fit-content;
|
||||
position: absolute;
|
||||
cursor: default;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.monitor-map-image {
|
||||
user-select: none;
|
||||
image-rendering: pixelated;
|
||||
transform: scale(1, -1);
|
||||
}
|
||||
|
||||
.monitor-map-view {
|
||||
transform: scale(1, -1);
|
||||
}
|
||||
|
||||
.paper-property-container {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 50%;
|
||||
height: 240px;
|
||||
}
|
||||
|
||||
.paper-title {
|
||||
font-size: 12px;
|
||||
padding: 0 5px;
|
||||
position: absolute;
|
||||
background-color: var(--mud-palette-surface);
|
||||
top: 0px;
|
||||
left: 15px;
|
||||
}
|
||||
|
||||
.paper-property {
|
||||
padding: 10px;
|
||||
border-radius: var(--mud-default-borderradius);
|
||||
border: 1px solid var(--mud-palette-lines-inputs);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
margin: 8px;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<div class="d-flex flex-row justify-content-between w-100 overflow-x-auto px-1">
|
||||
<div class="d-flex flex-row">
|
||||
<MudIconButton Class="mx-1 my-2" Icon="@Icons.Material.Filled.ZoomIn" Variant="Variant.Outlined" OnClick="(async () => await ButtonEventClick.InvokeAsync(MonitorToolbarButtonType.ZoomIn))" />
|
||||
<MudIconButton Class="mx-1 my-2" Icon="@Icons.Material.Filled.ZoomOut" Variant="Variant.Outlined" OnClick="(async () => await ButtonEventClick.InvokeAsync(MonitorToolbarButtonType.ZoomOut))" />
|
||||
<MudIconButton Class="mx-1 my-2" Icon="@Icons.Material.Filled.FitScreen" Variant="Variant.Outlined" OnClick="(async () => await ButtonEventClick.InvokeAsync(MonitorToolbarButtonType.Fit))" />
|
||||
<MudIconButton Class="mx-1 my-2" Icon="@Icons.Material.Filled.MyLocation" Variant="Variant.Outlined" OnClick="(async () => await ButtonEventClick.InvokeAsync(MonitorToolbarButtonType.Focus))" />
|
||||
<div class="mt-1 d-flex flex-row">
|
||||
<MudCheckBox @bind-Value="Model.FocusRobot" Label="Focus" T="bool" UncheckedColor="Color.Default" Color="Color.Success" @bind-Value:after="(() => CheckedClick(MonitorToolbarCheckedType.FocusRobot, Model.FocusRobot))"></MudCheckBox>
|
||||
<MudCheckBox @bind-Value="Model.ShowPath" Label="Path" T="bool" UncheckedColor="Color.Default" Color="Color.Success" @bind-Value:after="(() => CheckedClick(MonitorToolbarCheckedType.ShowPath, Model.ShowPath))"></MudCheckBox>
|
||||
<MudCheckBox @bind-Value="Model.ShowName" Label="Name" T="bool" UncheckedColor="Color.Default" Color="Color.Success" @bind-Value:after="(() => CheckedClick(MonitorToolbarCheckedType.ShowName, Model.ShowName))"></MudCheckBox>
|
||||
<MudCheckBox @bind-Value="Model.ShowElement" Label="Element" T="bool" UncheckedColor="Color.Default" Color="Color.Success" @bind-Value:after="(() => CheckedClick(MonitorToolbarCheckedType.ShowElement, Model.ShowElement))"></MudCheckBox>
|
||||
<MudCheckBox @bind-Value="Model.ShowGrid" Label="Grid" T="bool" UncheckedColor="Color.Default" Color="Color.Success" @bind-Value:after="(() => CheckedClick(MonitorToolbarCheckedType.ShowGrid, Model.ShowGrid))"></MudCheckBox>
|
||||
<MudCheckBox @bind-Value="Model.ShowLaser" Label="Laser" T="bool" UncheckedColor="Color.Default" Color="Color.Success" @bind-Value:after="(() => CheckedClick(MonitorToolbarCheckedType.ShowLaser, Model.ShowLaser))"></MudCheckBox>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex flex-row">
|
||||
<MudSelect Class="ms-2" Label="Map Name" Variant="Variant.Outlined" T="MapInfoDto" Margin="Margin.Dense" Dense @bind-Value="MapSelected" Style="width: 200px" @bind-Value:after="(async () => await MapChanged.InvokeAsync(MapSelected))">
|
||||
@foreach(var map in Maps)
|
||||
{
|
||||
<MudSelectItem Value="@map">@map.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
<MudSelect Class="ms-2" @bind-Value="@RobotSelected" T="RobotInfomationDto" @bind-Value:after="(async () => await RobotChanged.InvokeAsync(RobotSelected))" Margin="Margin.Dense" Dense Variant="Variant.Outlined" Label="Robot Name" Style="width: 200px">
|
||||
@foreach (var robot in Robots)
|
||||
{
|
||||
<MudSelectItem Value="@robot">@robot.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
<MudIconButton Icon="@ExpandIcon" Color="Color.Success" OnClick="ExpandedClick" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public MonitorToolBarModel Model { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<MonitorToolbarButtonType> ButtonEventClick { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<bool> ExpandChanged { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<MapInfoDto> MapChanged { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<RobotInfomationDto> RobotChanged { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Func<MonitorToolbarCheckedType, bool, Task>? CheckedEventClick { get; set; }
|
||||
|
||||
public List<MapInfoDto> Maps = [];
|
||||
private MapInfoDto? MapSelected = default!;
|
||||
|
||||
private bool isExpand = true;
|
||||
private string ExpandIcon = @Icons.Material.Filled.ArrowForwardIos;
|
||||
|
||||
public List<RobotInfomationDto> Robots = [];
|
||||
private RobotInfomationDto? RobotSelected = null;
|
||||
|
||||
public void LoadMaps(List<MapInfoDto> maps, MapInfoDto mapSelected)
|
||||
{
|
||||
Maps = maps;
|
||||
MapSelected = mapSelected;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public void LoadRobots(List<RobotInfomationDto> robots)
|
||||
{
|
||||
Robots = robots;
|
||||
if(Robots.Count > 0 && (RobotSelected is null || !Robots.Any(r => r.RobotId == RobotSelected.RobotId)))
|
||||
{
|
||||
RobotSelected = Robots.First();
|
||||
_ = RobotChanged.InvokeAsync(RobotSelected);
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task ExpandedClick()
|
||||
{
|
||||
if (isExpand)
|
||||
{
|
||||
ExpandIcon = @Icons.Material.Filled.ArrowBackIos;
|
||||
isExpand = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
ExpandIcon = @Icons.Material.Filled.ArrowForwardIos;
|
||||
isExpand = true;
|
||||
}
|
||||
await ExpandChanged.InvokeAsync(isExpand);
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void CheckedClick(MonitorToolbarCheckedType type, bool value) => CheckedEventClick?.Invoke(type, value);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace RobotNet.WebApp.Robots.Components.Monitoring;
|
||||
|
||||
public class MonitorToolBarModel
|
||||
{
|
||||
public bool ShowGrid { get; set; }
|
||||
public bool ShowName { get; set; }
|
||||
public bool ShowPath { get; set; }
|
||||
public bool FocusRobot { get; set; }
|
||||
public bool ShowLaser { get; set; }
|
||||
public bool ShowElement { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<defs>
|
||||
<marker id="originvector" markerWidth="2.4" markerHeight="2.4" refX="0.4" refY="0.4">
|
||||
<line x1="0" y1="0.4" x2="2" y2="0.4" stroke="red" stroke-width="0.15" />
|
||||
<path d="M 2 0.6 L 2.4 0.4 L 2 0.2 Z" fill="red" stroke-width="0" />
|
||||
<line x1="0.4" y1="0" x2="0.4" y2="2" stroke="blue" stroke-width="0.15" />
|
||||
<path d="M 0.6 2 L 0.4 2.4 L 0.2 2 Z" fill="blue" stroke-width="0" />
|
||||
</marker>
|
||||
</defs>
|
||||
|
||||
<line class="origin" marker-end="url(#originvector)" />
|
||||
@@ -0,0 +1,4 @@
|
||||
line.origin {
|
||||
stroke-width: var(--origin-vector-stroke-width);
|
||||
fill: none;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<path d="@data" fill="none" stroke="Green" stroke-width="0.35" stroke-opacity="1" visibility="@(Show ? PathIsNot : "hidden")" />
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public bool Show { get; set; }
|
||||
|
||||
private string data = "";
|
||||
|
||||
private string PathIsNot = "hidden";
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
data = "";
|
||||
PathIsNot = "hidden";
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public void UpdatePath(List<NavigationPathEdge> path)
|
||||
{
|
||||
if (path.Count > 0)
|
||||
{
|
||||
var inPath = $"M {path[0].StartX} {path[0].StartY}";
|
||||
for (int i = 0; i < path.Count; i++)
|
||||
{
|
||||
if (path[i].Degree == 1) inPath = $"{inPath} L {path[i].EndX} {path[i].EndY}";
|
||||
else if (path[i].Degree == 2) inPath = $"{inPath} Q {path[i].ControlPoint1X} {path[i].ControlPoint1Y} {path[i].EndX} {path[i].EndY}";
|
||||
else inPath = $"{inPath} C {path[i].ControlPoint1X} {path[i].ControlPoint1Y}, {path[i].ControlPoint2X} {path[i].ControlPoint2Y}, {path[i].EndX} {path[i].EndY}";
|
||||
}
|
||||
data = inPath;
|
||||
PathIsNot = "visible";
|
||||
}
|
||||
else Clear();
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
@foreach (var point in LidarPoints)
|
||||
{
|
||||
<circle cx="@point.X" cy="@point.Y" r="0.05" fill="blue" visibility="@(ShowLaser ? "visible" : "hidden")" />
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public bool ShowLaser { get; set; }
|
||||
|
||||
private List<NavigationPathNode> LidarPoints { get; set; } = new();
|
||||
|
||||
public void SetData(List<NavigationPathNode> laser)
|
||||
{
|
||||
LidarPoints.Clear();
|
||||
LidarPoints.AddRange(laser);
|
||||
}
|
||||
}
|
||||
45
RobotNet.WebApp/Robots/Components/Monitoring/RobotPath.razor
Normal file
45
RobotNet.WebApp/Robots/Components/Monitoring/RobotPath.razor
Normal file
@@ -0,0 +1,45 @@
|
||||
<path d="@data" fill="none" stroke="Green" stroke-width="0.15" stroke-opacity="0.7" visibility="@(Show ? PathIsNot : "hidden")" marker-end="url(#target)" />
|
||||
<defs>
|
||||
<marker id="target" markerWidth="8" markerHeight="8" refX="4" refY="4">
|
||||
<circle r="0.8" cx="4" cy="4" fill="red" />
|
||||
<circle r="3" cx="4" cy="4" stroke="red" stroke-width="0.2" fill="transparent" stroke-dasharray="0.2 0.2" />
|
||||
<line x1="0" y1="4" x2="2" y2="4" stroke="red" stroke-width="0.2" />
|
||||
<line x1="6" y1="4" x2="8" y2="4" stroke="red" stroke-width="0.2" />
|
||||
<line x1="4" y1="0" x2="4" y2="2" stroke="red" stroke-width="0.2" />
|
||||
<line x1="4" y1="6" x2="4" y2="8" stroke="red" stroke-width="0.2" />
|
||||
</marker>
|
||||
</defs>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public bool Show { get; set; }
|
||||
|
||||
private string data = "";
|
||||
|
||||
private string PathIsNot = "hidden";
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
data = "";
|
||||
PathIsNot = "hidden";
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public void UpdatePath(List<NavigationPathEdge> path)
|
||||
{
|
||||
if (path.Count > 0)
|
||||
{
|
||||
var inPath = $"M {path[0].StartX} {path[0].StartY}";
|
||||
for (int i = 0; i < path.Count; i++)
|
||||
{
|
||||
if(path[i].Degree == 1) inPath = $"{inPath} L {path[i].EndX} {path[i].EndY}";
|
||||
else if (path[i].Degree == 2) inPath = $"{inPath} Q {path[i].ControlPoint1X} {path[i].ControlPoint1Y} {path[i].EndX} {path[i].EndY}";
|
||||
else inPath = $"{inPath} C {path[i].ControlPoint1X} {path[i].ControlPoint1Y}, {path[i].ControlPoint2X} {path[i].ControlPoint2Y}, {path[i].EndX} {path[i].EndY}";
|
||||
}
|
||||
data = inPath;
|
||||
PathIsNot = "visible";
|
||||
}
|
||||
else Clear();
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user