first commit -push
This commit is contained in:
121
RobotNet.WebApp/Maps/Components/Editor/Edge/Edge.razor
Normal file
121
RobotNet.WebApp/Maps/Components/Editor/Edge/Edge.razor
Normal file
@@ -0,0 +1,121 @@
|
||||
@inject IJSRuntime JSRuntime
|
||||
@implements IDisposable
|
||||
|
||||
<path @ref="ErrorRef" style="stroke: red; opacity: 0.6; stroke-width: 0.6px;" />
|
||||
<path @ref="Ref" @ondblclick="@(async () => await DoubleClick.InvokeAsync(Model))" class="@(IsSetting ? "setting" : "")" />
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public EdgeModel Model { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<EdgeModel> DoubleClick { get; set; }
|
||||
|
||||
[CascadingParameter]
|
||||
protected bool MapIsActive { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EditorState EditorState { get; set; }
|
||||
|
||||
private ElementReference Ref;
|
||||
private ElementReference ErrorRef;
|
||||
private DotNetObjectReference<Edge> DotNetObj = null!;
|
||||
private bool IsError = false;
|
||||
|
||||
private bool IsSetting => EditorState == EditorState.NavigationEdit || EditorState == EditorState.CreateStraighEdge || EditorState == EditorState.CreateCurveEdge ||
|
||||
EditorState == EditorState.CreateDoubleCurveEdge;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
DotNetObj = DotNetObjectReference.Create(this);
|
||||
await JSRuntime.InvokeVoidAsync("AddEventListener", DotNetObj, Ref, "click", nameof(Click), false);
|
||||
await UpdatePathData();
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", ErrorRef, "visibility", "hidden");
|
||||
}
|
||||
|
||||
public override async Task SetParametersAsync(ParameterView parameters)
|
||||
{
|
||||
bool updateLine = false;
|
||||
if (parameters.TryGetValue(nameof(Model), out EdgeModel? model))
|
||||
{
|
||||
if (((Model?.Id ?? Guid.Empty) != (model?.Id ?? Guid.Empty)))
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.StartNodePositionChanged -= UpdatePathData;
|
||||
Model.EndNodePositionChanged -= UpdatePathData;
|
||||
Model.ControlPoint1PositionChanged -= UpdatePathData;
|
||||
Model.ControlPoint2PositionChanged -= UpdatePathData;
|
||||
Model.ActiveChanged -= ActivedChanged;
|
||||
Model.ErrorChanged -= ErrorChanged;
|
||||
}
|
||||
|
||||
if (model != null)
|
||||
{
|
||||
model.StartNodePositionChanged += UpdatePathData;
|
||||
model.EndNodePositionChanged += UpdatePathData;
|
||||
model.ControlPoint1PositionChanged += UpdatePathData;
|
||||
model.ControlPoint2PositionChanged += UpdatePathData;
|
||||
model.ActiveChanged += ActivedChanged;
|
||||
model.ErrorChanged += ErrorChanged;
|
||||
|
||||
updateLine = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await base.SetParametersAsync(parameters);
|
||||
if (updateLine) 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);
|
||||
if (IsError) await JSRuntime.InvokeVoidAsync("ElementSetAttribute", ErrorRef, "d", data);
|
||||
}
|
||||
|
||||
private async void ActivedChanged(bool state) => await JSRuntime.InvokeVoidAsync(state ? "AddSelected" : "RemoveSelected", Ref);
|
||||
|
||||
private async void ErrorChanged(bool state)
|
||||
{
|
||||
IsError = state;
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", ErrorRef, "visibility", state ? "visible" : "hidden");
|
||||
await UpdatePathData();
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public void Click() => Model.Selected();
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.StartNodePositionChanged -= UpdatePathData;
|
||||
Model.EndNodePositionChanged -= UpdatePathData;
|
||||
Model.ControlPoint1PositionChanged -= UpdatePathData;
|
||||
Model.ControlPoint2PositionChanged -= UpdatePathData;
|
||||
Model.ActiveChanged -= ActivedChanged;
|
||||
Model.ErrorChanged -= ErrorChanged;
|
||||
}
|
||||
if (DotNetObj != null) DotNetObj.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
24
RobotNet.WebApp/Maps/Components/Editor/Edge/Edge.razor.css
Normal file
24
RobotNet.WebApp/Maps/Components/Editor/Edge/Edge.razor.css
Normal file
@@ -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,128 @@
|
||||
@inject IJSRuntime JSRuntime
|
||||
@implements IDisposable
|
||||
|
||||
<g visibility="@Visibility">
|
||||
<path d="@EdgeData" />
|
||||
<line x1="@X1" y1="@Y1" x2="@CX1" y2="@CY1"/>
|
||||
<line x1="@CX1" y1="@CY1" x2="@X2" y2="@Y2" />
|
||||
<circle @ref="CP1Ref" cx="@CX1" cy="@CY1" />
|
||||
</g>
|
||||
|
||||
<g visibility="@ControlPoint2Visibility">
|
||||
<line x1="@X1" y1="@Y1" x2="@CX2" y2="@CY2" />
|
||||
<line x1="@CX2" y1="@CY2" x2="@X2" y2="@Y2" />
|
||||
<circle @ref="CP2Ref" cx="@CX2" cy="@CY2" />
|
||||
</g>
|
||||
|
||||
@code {
|
||||
private ElementReference CP1Ref;
|
||||
private ElementReference CP2Ref;
|
||||
private DotNetObjectReference<EdgeControlPoint> DotNetObj = null!;
|
||||
|
||||
private double X1;
|
||||
private double Y1;
|
||||
private double CX1;
|
||||
private double CY1;
|
||||
private double CX2;
|
||||
private double CY2;
|
||||
private double X2;
|
||||
private double Y2;
|
||||
private string EdgeData = "";
|
||||
private EdgeModel? Model;
|
||||
private string Visibility = "hidden";
|
||||
|
||||
private string ControlPoint2Visibility = "hidden";
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
DotNetObj = DotNetObjectReference.Create(this);
|
||||
await JSRuntime.InvokeVoidAsync("AddMouseDownEventListener", DotNetObj, CP1Ref, nameof(OnMouseDown1), false);
|
||||
await JSRuntime.InvokeVoidAsync("AddMouseDownEventListener", DotNetObj, CP2Ref, nameof(OnMouseDown2), false);
|
||||
}
|
||||
|
||||
public void SetControl(EdgeModel? model)
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.StartNodePositionChanged -= CaculatePath;
|
||||
Model.EndNodePositionChanged -= CaculatePath;
|
||||
Model.ControlPoint1PositionChanged -= CaculatePath;
|
||||
Model.ControlPoint2PositionChanged -= CaculatePath;
|
||||
}
|
||||
|
||||
Model = model;
|
||||
if (Model != null)
|
||||
{
|
||||
Visibility = "visible";
|
||||
if (Model.TrajectoryDegree == TrajectoryDegree.Three) ControlPoint2Visibility = "visible";
|
||||
CaculatePath();
|
||||
|
||||
Model.StartNodePositionChanged += CaculatePath;
|
||||
Model.EndNodePositionChanged += CaculatePath;
|
||||
Model.ControlPoint1PositionChanged += CaculatePath;
|
||||
Model.ControlPoint2PositionChanged += CaculatePath;
|
||||
if (Model.TrajectoryDegree == TrajectoryDegree.Three) ControlPoint2Visibility = "visible";
|
||||
else ControlPoint2Visibility = "hidden";
|
||||
Visibility = "visible";
|
||||
}
|
||||
else
|
||||
{
|
||||
Visibility = "hidden";
|
||||
ControlPoint2Visibility = "hidden";
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private Task CaculatePath()
|
||||
{
|
||||
if (Model == null) return Task.CompletedTask;
|
||||
|
||||
X1 = Model.X1;
|
||||
Y1 = Model.Y1;
|
||||
X2 = Model.X2;
|
||||
Y2 = Model.Y2;
|
||||
CX1 = Model.ControlPoint1X;
|
||||
CY1 = Model.ControlPoint1Y;
|
||||
CX2 = Model.ControlPoint2X;
|
||||
CY2 = Model.ControlPoint2Y;
|
||||
StateHasChanged();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public void OnMouseDown1(int button, bool altKey, bool ctrlKey, bool shiftKey)
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.ActivedControlPoint1 = true;
|
||||
Model.ActivedControlPoint2 = false;
|
||||
}
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public void OnMouseDown2(int button, bool altKey, bool ctrlKey, bool shiftKey)
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.ActivedControlPoint2 = true;
|
||||
Model.ActivedControlPoint1 = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.StartNodePositionChanged -= CaculatePath;
|
||||
Model.EndNodePositionChanged -= CaculatePath;
|
||||
Model.ControlPoint1PositionChanged -= CaculatePath;
|
||||
Model.ControlPoint2PositionChanged -= CaculatePath;
|
||||
Model = null;
|
||||
}
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
circle {
|
||||
cursor: default;
|
||||
fill: #FFBD33;
|
||||
stroke: #FF5733;
|
||||
stroke-width: 0;
|
||||
r: var(--node-r);
|
||||
}
|
||||
|
||||
circle:hover {
|
||||
stroke-width: 0.02px;
|
||||
}
|
||||
|
||||
circle:active {
|
||||
stroke-width: 0.02px;
|
||||
cursor: pointer;
|
||||
stroke: green;
|
||||
}
|
||||
|
||||
line {
|
||||
stroke-width: 0.03px;
|
||||
stroke: #d63384;
|
||||
stroke-dasharray: 0.1 0.1;
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<g @ref="Ref" visibility="hidden">
|
||||
<defs>
|
||||
<marker id="arrowhead" markerWidth="5" markerHeight="4" refX="5" refY="2" orient="auto">
|
||||
<line x1="0" y1="0" x2="5" y2="2" style="stroke: #ff0000; stroke-width: 1px;" />
|
||||
<line x1="5" y1="2" x2="0" y2="4" style="stroke: #ff0000; stroke-width: 1px;" />
|
||||
</marker>
|
||||
</defs>
|
||||
<path @ref="PathRef" />
|
||||
<line @ref="SubPath1Ref" x1="@StartNode.X" x2="@SubStartNode.X" y1="@StartNode.Y" y2="@SubStartNode.Y" stroke="#ff0000" stroke-width="0.05" marker-end="url(#arrowhead)" />
|
||||
<line @ref="SubPath2Ref" x1="@EndNode.X" x2="@SubEndNode.X" y1="@EndNode.Y" y2="@SubEndNode.Y" stroke="#ff0000" stroke-width="0.05" marker-end="url(#arrowhead)" />
|
||||
<circle cx="@StartNode.X" cy="@StartNode.Y" />
|
||||
<circle cx="@EndNode.X" cy="@EndNode.Y" />
|
||||
</g>
|
||||
|
||||
@code {
|
||||
private ElementReference Ref;
|
||||
private ElementReference PathRef;
|
||||
private ElementReference SubPath1Ref;
|
||||
private ElementReference SubPath2Ref;
|
||||
|
||||
private (double X, double Y) StartNode;
|
||||
private (double X, double Y) SubStartNode;
|
||||
private (double X, double Y) EndNode;
|
||||
private (double X, double Y) SubEndNode;
|
||||
|
||||
private TrajectoryDegree Degree;
|
||||
|
||||
private (double X, double Y) ControlPoint1;
|
||||
private (double X, double Y) ControlPoint2;
|
||||
|
||||
public CreateCurveEdgeStep CreateStep { get; set; } = CreateCurveEdgeStep.Hidden;
|
||||
|
||||
public async Task Update(double x, double y)
|
||||
{
|
||||
if (CreateStep == CreateCurveEdgeStep.CreateSubStartEdge)
|
||||
{
|
||||
SubStartNode.X = x;
|
||||
SubStartNode.Y = y;
|
||||
}
|
||||
else if (CreateStep == CreateCurveEdgeStep.FinishCreateSubStartEdge)
|
||||
{
|
||||
EndNode.X = x;
|
||||
EndNode.Y = y;
|
||||
await CreateTangentPath();
|
||||
}
|
||||
else if (CreateStep == CreateCurveEdgeStep.CreateSubEndEdge)
|
||||
{
|
||||
SubEndNode.X = x;
|
||||
SubEndNode.Y = y;
|
||||
await CreateTangentPath();
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public async Task CreateSubEdgeAsync(double x, double y, TrajectoryDegree degree = TrajectoryDegree.Two)
|
||||
{
|
||||
Degree = degree;
|
||||
if (CreateStep == CreateCurveEdgeStep.Hidden)
|
||||
{
|
||||
await Visible();
|
||||
StartNode.X = x;
|
||||
StartNode.Y = y;
|
||||
SubStartNode.X = x;
|
||||
SubStartNode.Y = y;
|
||||
CreateStep = CreateCurveEdgeStep.CreateSubStartEdge;
|
||||
}
|
||||
else if (CreateStep == CreateCurveEdgeStep.FinishCreateSubStartEdge)
|
||||
{
|
||||
EndNode.X = x;
|
||||
EndNode.Y = y;
|
||||
SubEndNode.X = x;
|
||||
SubEndNode.Y = y;
|
||||
CreateStep = CreateCurveEdgeStep.CreateSubEndEdge;
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", SubPath2Ref, "visibility", "visible");
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public async Task FinishSubEdgeAsync(double x, double y)
|
||||
{
|
||||
if (CreateStep == CreateCurveEdgeStep.CreateSubStartEdge)
|
||||
{
|
||||
SubStartNode.X = x;
|
||||
SubStartNode.Y = y;
|
||||
|
||||
EndNode.X = x;
|
||||
EndNode.Y = y;
|
||||
|
||||
CreateStep = CreateCurveEdgeStep.FinishCreateSubStartEdge;
|
||||
await CreateTangentPath();
|
||||
}
|
||||
else if (CreateStep == CreateCurveEdgeStep.CreateSubEndEdge) CreateStep = CreateCurveEdgeStep.Finish;
|
||||
}
|
||||
|
||||
public EdgeCreateModel GetEdgeCreateModel()
|
||||
{
|
||||
return new()
|
||||
{
|
||||
X1 = StartNode.X,
|
||||
Y1 = StartNode.Y,
|
||||
X2 = EndNode.X,
|
||||
Y2 = EndNode.Y,
|
||||
ControlPoint1X = ControlPoint1.X,
|
||||
ControlPoint1Y = ControlPoint1.Y,
|
||||
ControlPoint2X = ControlPoint2.X,
|
||||
ControlPoint2Y = ControlPoint2.Y,
|
||||
TrajectoryDegree = Degree,
|
||||
};
|
||||
}
|
||||
|
||||
private async Task CreateTangentPath()
|
||||
{
|
||||
var data = $"M {StartNode.X} {StartNode.Y}";
|
||||
if(Degree == TrajectoryDegree.Two)
|
||||
{
|
||||
var cp = MapEditorHelper.CaculateIntersectionPoint(SubStartNode.X, SubStartNode.Y, StartNode.X, StartNode.Y, EndNode.X, EndNode.Y, SubEndNode.X, SubEndNode.Y);
|
||||
if (cp is null || CreateStep == CreateCurveEdgeStep.FinishCreateSubStartEdge) cp = MapEditorHelper.CaculateControlPoint(StartNode.X, StartNode.Y, EndNode.X, EndNode.Y, 45, 1 / Math.Sqrt(2));
|
||||
data = $"{data} Q {cp.Value.X} {cp.Value.Y} {EndNode.X} {EndNode.Y}";
|
||||
ControlPoint1 = (cp.Value.X, cp.Value.Y);
|
||||
}
|
||||
else if(Degree == TrajectoryDegree.Three)
|
||||
{
|
||||
if (CreateStep == CreateCurveEdgeStep.FinishCreateSubStartEdge)
|
||||
{
|
||||
ControlPoint1 = MapEditorHelper.CaculateControlPoint(StartNode.X, StartNode.Y, EndNode.X, EndNode.Y, 45, 1 / Math.Sqrt(2));
|
||||
ControlPoint2 = MapEditorHelper.CaculateControlPoint(StartNode.X, StartNode.Y, EndNode.X, EndNode.Y, -45, 1 / Math.Sqrt(2));
|
||||
}
|
||||
else (ControlPoint1.X, ControlPoint1.Y, ControlPoint2.X, ControlPoint2.Y) = MapEditorHelper.CaculateDoubleControlPoint(SubStartNode.X, SubStartNode.Y, StartNode.X, StartNode.Y, EndNode.X, EndNode.Y, SubEndNode.X, SubEndNode.Y);
|
||||
data = $"{data} C {ControlPoint1.X} {ControlPoint1.Y}, {ControlPoint2.X} {ControlPoint2.Y}, {EndNode.X} {EndNode.Y}";
|
||||
}
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", PathRef, "d", data);
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public async Task Visible()
|
||||
{
|
||||
EndNode = (0, 0);
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", PathRef, "d", "");
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", SubPath1Ref, "visibility", "visible");
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", SubPath2Ref, "visibility", "hidden");
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "visibility", "visible");
|
||||
}
|
||||
|
||||
public async Task Hidden()
|
||||
{
|
||||
CreateStep = CreateCurveEdgeStep.Hidden;
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", SubPath1Ref, "visibility", "hidden");
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", SubPath2Ref, "visibility", "hidden");
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "visibility", "hidden");
|
||||
}
|
||||
|
||||
public enum CreateCurveEdgeStep
|
||||
{
|
||||
Hidden,
|
||||
CreateSubStartEdge,
|
||||
FinishCreateSubStartEdge,
|
||||
CreateSubEndEdge,
|
||||
Finish,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
path {
|
||||
stroke: red;
|
||||
stroke-width: var(--edge-stroke-width);
|
||||
fill: none;
|
||||
}
|
||||
|
||||
circle {
|
||||
fill: #FFBD33;
|
||||
stroke: #FF5733;
|
||||
stroke-width: 0;
|
||||
r: var(--node-r);
|
||||
}
|
||||
113
RobotNet.WebApp/Maps/Components/Editor/Edge/EdgeDirection.razor
Normal file
113
RobotNet.WebApp/Maps/Components/Editor/Edge/EdgeDirection.razor
Normal file
@@ -0,0 +1,113 @@
|
||||
@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();
|
||||
}
|
||||
|
||||
public override async Task SetParametersAsync(ParameterView parameters)
|
||||
{
|
||||
bool updateLine = false;
|
||||
if (parameters.TryGetValue(nameof(Model), out EdgeModel? model))
|
||||
{
|
||||
if (((Model?.Id ?? Guid.Empty) != (model?.Id ?? Guid.Empty)))
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.StartNodePositionChanged -= UpdatePathData;
|
||||
Model.EndNodePositionChanged -= UpdatePathData;
|
||||
Model.ControlPoint1PositionChanged -= UpdatePathData;
|
||||
Model.ControlPoint2PositionChanged -= UpdatePathData;
|
||||
Model.DirectionChanged -= UpdateMaker;
|
||||
}
|
||||
|
||||
if (model != null)
|
||||
{
|
||||
model.StartNodePositionChanged += UpdatePathData;
|
||||
model.EndNodePositionChanged += UpdatePathData;
|
||||
model.ControlPoint1PositionChanged += UpdatePathData;
|
||||
model.ControlPoint2PositionChanged += UpdatePathData;
|
||||
model.DirectionChanged += UpdateMaker;
|
||||
updateLine = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await base.SetParametersAsync(parameters);
|
||||
if (updateLine)
|
||||
{
|
||||
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()
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.StartNodePositionChanged -= UpdatePathData;
|
||||
Model.EndNodePositionChanged -= UpdatePathData;
|
||||
Model.ControlPoint1PositionChanged -= UpdatePathData;
|
||||
Model.ControlPoint2PositionChanged -= UpdatePathData;
|
||||
Model.DirectionChanged -= UpdateMaker;
|
||||
}
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
polyline {
|
||||
stroke-width: var(--edge-direction-stroke-width);
|
||||
stroke: none;
|
||||
fill: none;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<g @ref="Ref" visibility="hidden">
|
||||
<path @ref="PathRef" />
|
||||
<circle cx="@X1" cy="@Y1" />
|
||||
<circle cx="@X2" cy="@Y2" />
|
||||
</g>
|
||||
|
||||
@code {
|
||||
private ElementReference Ref;
|
||||
private ElementReference PathRef;
|
||||
|
||||
public double X1;
|
||||
public double Y1;
|
||||
public double X2;
|
||||
public double Y2;
|
||||
|
||||
|
||||
|
||||
public async Task Update(double x, double y)
|
||||
{
|
||||
X2 = x;
|
||||
Y2 = y;
|
||||
await CaculatePath();
|
||||
}
|
||||
|
||||
public async Task StartCreateAsync(double x, double y)
|
||||
{
|
||||
X1 = x;
|
||||
Y1 = y;
|
||||
X2 = x;
|
||||
Y2 = y;
|
||||
await CaculatePath();
|
||||
await Visible();
|
||||
}
|
||||
|
||||
private async Task CaculatePath()
|
||||
{
|
||||
var data = $"M {X1} {Y1} L {(X1 + X2) / 2} {(Y1 + Y2) / 2} L {X2} {Y2}";
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", PathRef, "d", data);
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public async Task Visible() => await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "visibility", "visible");
|
||||
public async Task Hidden() => await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "visibility", "hidden");
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
path {
|
||||
stroke: red;
|
||||
stroke-width: var(--edge-stroke-width);
|
||||
fill: none;
|
||||
}
|
||||
|
||||
circle {
|
||||
fill: #FFBD33;
|
||||
stroke: #FF5733;
|
||||
stroke-width: 0;
|
||||
r: var(--node-r);
|
||||
}
|
||||
255
RobotNet.WebApp/Maps/Components/Editor/Edge/MapEdge.razor
Normal file
255
RobotNet.WebApp/Maps/Components/Editor/Edge/MapEdge.razor
Normal file
@@ -0,0 +1,255 @@
|
||||
@implements IDisposable
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject IHttpClientFactory HttpClientFactory
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<g>
|
||||
@foreach (var edge in Models)
|
||||
{
|
||||
<Edge Model="edge" DoubleClick="OnEdgeDoubleClick" EditorState="@EditorState" />
|
||||
}
|
||||
@foreach (var edge in Models)
|
||||
{
|
||||
<EdgeDirection Model="edge" />
|
||||
}
|
||||
</g>
|
||||
|
||||
<MudDialog @bind-Visible="updateEdgeVisible">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">
|
||||
Update edge @UpdateModel.Id
|
||||
</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<div class="d-flex flex-row align-items-center">
|
||||
<MudText>
|
||||
Length: @SelectModelLength m
|
||||
</MudText>
|
||||
</div>
|
||||
<div class="d-flex flex-row mt-2">
|
||||
<div class="d-flex flex-column">
|
||||
<div class="mb-2">
|
||||
<MudNumericField @bind-Value="UpdateModel.ControlPoint1X" Label="Control Point 1 X" Variant="Variant.Outlined" Margin="Margin.Dense" Step="0.1" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<MudNumericField @bind-Value="UpdateModel.ControlPoint2X" Label="Control Point 2 X" Variant="Variant.Outlined" Margin="Margin.Dense" Step="0.1" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<MudSelect @bind-Value="UpdateModel.DirectionAllowed" Label="Direction Allowed" Variant="Variant.Outlined" AnchorOrigin="Origin.BottomLeft" Margin="Margin.Dense" Dense ReadOnly=@(MapIsActive)>
|
||||
<MudSelectItem Value="@(DirectionAllowed.None)" />
|
||||
<MudSelectItem Value="@(DirectionAllowed.Backward)" />
|
||||
<MudSelectItem Value="@(DirectionAllowed.Forward)" />
|
||||
<MudSelectItem Value="@(DirectionAllowed.Both)" />
|
||||
</MudSelect>
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<MudNumericField @bind-Value="UpdateModel.AllowedDeviationXy" Label="AllowedDeviationXy" Step="0.01" Min="0" Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<MudNumericField @bind-Value="UpdateModel.AllowedDeviationTheta" Label="AllowedDeviationTheta" Step="1" Min="0" Max="180" Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
<div class="d-flex">
|
||||
<MudCheckBox @bind-Value="UpdateModel.RotationAllowed" Label="Rotation Allowed" LabelPlacement="Placement.Start" ReadOnly=@(MapIsActive) UncheckedColor="Color.Default" Color="Color.Success" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-column ms-2">
|
||||
<div class="mb-2">
|
||||
<MudNumericField @bind-Value="UpdateModel.ControlPoint1Y" Label="Control Point 1 Y" Variant="Variant.Outlined" Margin="Margin.Dense" Step="0.1" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<MudNumericField @bind-Value="UpdateModel.ControlPoint2Y" Label="Control Point 2 Y" Variant="Variant.Outlined" Margin="Margin.Dense" Step="0.1" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<MudNumericField @bind-Value="UpdateModel.MaxSpeed" Label="Max Speed" Variant="Variant.Outlined" Margin="Margin.Dense" Step="0.1" Min="0" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<MudNumericField @bind-Value="UpdateModel.MaxRotationSpeed" Label="Max Rotation Speed" Variant="Variant.Outlined" Margin="Margin.Dense" Step="0.1" Min="0" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<MudNumericField @bind-Value="UpdateModel.MaxHeight" Label="Max Height" Variant="Variant.Outlined" Margin="Margin.Dense" Step="0.1" Min="0" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<MudNumericField @bind-Value="UpdateModel.MinHeight" Label="Min Height" Variant="Variant.Outlined" Margin="Margin.Dense" Step="0.1" Min="0" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-column ms-2 flex-grow-1">
|
||||
<div class="d-flex flex-row mb-2">
|
||||
<MudSelect @bind-Value=ActionSelected Margin="Margin.Dense" T="ActionDto" Label="Action" Variant="Variant.Outlined" Class="w-100" AnchorOrigin="Origin.BottomLeft">
|
||||
@foreach (var action in Actions)
|
||||
{
|
||||
<MudSelectItem Value="@action">@action.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
<MudFab Class="ms-2" Color="Color.Secondary" StartIcon="@Icons.Material.Filled.Add" Size="Size.Medium" OnClick="AddAction" />
|
||||
</div>
|
||||
<div class="paper-action">
|
||||
@foreach (var actionId in UpdateModel.Actions)
|
||||
{
|
||||
<div class="m-1" style="height: fit-content">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Info" Style="text-transform:none" OnClick="(() => DeleteAction(actionId))">
|
||||
@(Actions.FirstOrDefault(ac => ac.Id == actionId)?.Name)
|
||||
</MudButton>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="CancelUpdateEdge" Class="px-10" Variant="Variant.Filled">Cancel</MudButton>
|
||||
<MudButton OnClick="UpdateEdge" Variant="Variant.Filled" Color="Color.Primary" Class="px-10" Disabled=@(MapIsActive || EditorState == EditorState.View)>Update</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public MapEdgeModel Models { get; set; } = null!;
|
||||
|
||||
[CascadingParameter]
|
||||
protected bool MapIsActive { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<EdgeModel?> EdgeSelectedChanged { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EditorState EditorState { get; set; }
|
||||
|
||||
private EdgeUpdateModel UpdateModel = new();
|
||||
private bool updateEdgeVisible;
|
||||
private string ActionsText { get; set; } = "";
|
||||
private double SelectModelLength;
|
||||
|
||||
private List<ActionDto> Actions = [];
|
||||
private ActionDto? ActionSelected = null;
|
||||
private HttpClient Http = default!;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
Http = HttpClientFactory.CreateClient("MapManagerAPI");
|
||||
Models.Changed += StateHasChanged;
|
||||
Models.EdgeSelectedChanged += async (model) => await EdgeSelectedChanged.InvokeAsync(model);
|
||||
}
|
||||
|
||||
private async Task LoadActionAsync(Guid mapVersionId)
|
||||
{
|
||||
var result = await Http.GetFromJsonAsync<IEnumerable<ActionDto>>($"api/Actions/{mapVersionId}");
|
||||
|
||||
if (result is not null && result.Any())
|
||||
{
|
||||
Actions.Clear();
|
||||
Actions.AddRange(result);
|
||||
}
|
||||
if (Actions.Any()) ActionSelected = Actions.First();
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void AddAction()
|
||||
{
|
||||
if (ActionSelected is null) return;
|
||||
if (UpdateModel.Actions.Any(action => action == ActionSelected.Id))
|
||||
{
|
||||
Snackbar.Add("Action đã tồn tại", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateModel.Actions = [.. UpdateModel.Actions, ActionSelected.Id];
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void DeleteAction(Guid actionId)
|
||||
{
|
||||
UpdateModel.Actions = UpdateModel.Actions.Where(a => actionId != a).ToArray();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task OnEdgeDoubleClick(EdgeModel model)
|
||||
{
|
||||
if (model == null || EditorState != EditorState.NavigationEdit) return;
|
||||
|
||||
await LoadActionAsync(model.MapId);
|
||||
|
||||
UpdateModel.Id = model.Id;
|
||||
UpdateModel.ControlPoint1X = model.ControlPoint1X;
|
||||
UpdateModel.ControlPoint1Y = model.ControlPoint1Y;
|
||||
UpdateModel.ControlPoint2X = model.ControlPoint2X;
|
||||
UpdateModel.ControlPoint2Y = model.ControlPoint2Y;
|
||||
UpdateModel.DirectionAllowed = model.DirectionAllowed;
|
||||
UpdateModel.MaxSpeed = model.MaxSpeed;
|
||||
UpdateModel.MaxHeight = model.MaxHeight;
|
||||
UpdateModel.MinHeight = model.MinHeight;
|
||||
UpdateModel.RotationAllowed = model.RotationAllowed;
|
||||
UpdateModel.MaxRotationSpeed = model.MaxRotationSpeed;
|
||||
UpdateModel.AllowedDeviationXy = model.AllowedDeviationXy;
|
||||
UpdateModel.AllowedDeviationTheta = model.AllowedDeviationTheta;
|
||||
|
||||
UpdateModel.Actions = [];
|
||||
var actions = JsonSerializer.Deserialize<Guid[]>(model.Actions);
|
||||
if (actions is not null && actions.Length > 0)
|
||||
{
|
||||
UpdateModel.Actions = [.. actions];
|
||||
}
|
||||
|
||||
SelectModelLength = MapEditorHelper.GetEdgeLength(new()
|
||||
{
|
||||
TrajectoryDegree = model.TrajectoryDegree,
|
||||
X1 = model.X1,
|
||||
Y1 = model.Y1,
|
||||
X2 = model.X2,
|
||||
Y2 = model.Y2,
|
||||
ControlPoint1X = model.ControlPoint1X,
|
||||
ControlPoint1Y = model.ControlPoint1Y,
|
||||
ControlPoint2X = model.ControlPoint2X,
|
||||
ControlPoint2Y = model.ControlPoint2Y,
|
||||
});
|
||||
|
||||
updateEdgeVisible = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void CancelUpdateEdge()
|
||||
{
|
||||
updateEdgeVisible = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task UpdateEdge()
|
||||
{
|
||||
var selectedModel = Models.FirstOrDefault(e => e.Id == UpdateModel.Id);
|
||||
|
||||
if (selectedModel == null)
|
||||
{
|
||||
updateEdgeVisible = false;
|
||||
StateHasChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await (await Http.PutAsJsonAsync($"api/Edges", UpdateModel)).Content.ReadFromJsonAsync<MessageResult>();
|
||||
if (result is null)
|
||||
{
|
||||
Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
return;
|
||||
}
|
||||
else if (!result.IsSuccess)
|
||||
{
|
||||
Snackbar.Add(result.Message, Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
selectedModel.UpdateData(UpdateModel);
|
||||
updateEdgeVisible = false;
|
||||
Snackbar.Add("Cập nhật thành công", Severity.Success);
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Models.Changed -= StateHasChanged;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
.paper-action {
|
||||
padding: 5px;
|
||||
border: 1px solid silver;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-content: flex-start;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
width: 280px;
|
||||
max-height: 288px;
|
||||
height: 100%;
|
||||
}
|
||||
113
RobotNet.WebApp/Maps/Components/Editor/Element/Element.razor
Normal file
113
RobotNet.WebApp/Maps/Components/Editor/Element/Element.razor
Normal file
@@ -0,0 +1,113 @@
|
||||
@implements IDisposable
|
||||
|
||||
@inject IHttpClientFactory HttpClientFactory
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<g class="element" visibility="@(IsShow ? "visible" : "hidden")" @ondblclick="@(async () => await DoubleClick.InvokeAsync(Model))">
|
||||
<image @ref="@ImageRef" />
|
||||
<text @ref="textRef" visibility="@(ShowName && IsShow ? "visible" : "hidden")">@Model?.Name</text>
|
||||
</g>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public ElementModel Model { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public bool ShowName { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EditorState EditorState { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<ElementModel> DoubleClick { get; set; }
|
||||
|
||||
private ElementReference ImageRef;
|
||||
private ElementReference textRef;
|
||||
private ElementModelDto ElementModel = new();
|
||||
|
||||
private bool IsSetting => EditorState == EditorState.View;
|
||||
private bool IsShow => EditorState == EditorState.View;
|
||||
private HttpClient? Http;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
Http = HttpClientFactory.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.PositionChanged += Model_PositionChanged;
|
||||
Model.OffsetChanged += Model_OffsetChanged;
|
||||
await UpdatePosition(Model.X, Model.Y, Model.Theta);
|
||||
}
|
||||
}
|
||||
|
||||
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.OffsetChanged -= Model_OffsetChanged;
|
||||
Model.PositionChanged -= Model_PositionChanged;
|
||||
}
|
||||
|
||||
if (model != null)
|
||||
{
|
||||
updateRobot = true;
|
||||
model.OffsetChanged += Model_OffsetChanged;
|
||||
model.PositionChanged += Model_PositionChanged;
|
||||
|
||||
}
|
||||
}
|
||||
await base.SetParametersAsync(parameters);
|
||||
if (updateRobot && model != null)
|
||||
{
|
||||
if (Http is null) Http = HttpClientFactory.CreateClient("MapManagerAPI");
|
||||
var elementModel = await Http.GetFromJsonAsync<MessageResult<ElementModelDto?>>($"api/ElementModels/{model.ModelId}");
|
||||
if (elementModel is not null && elementModel.Data is not null) ElementModel = elementModel.Data;
|
||||
await SetElementImage(model.IsOpen);
|
||||
await UpdatePosition(model.X, model.Y, model.Theta);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SetElementImage(bool isOpen)
|
||||
{
|
||||
if (Http is null) Http = HttpClientFactory.CreateClient("MapManagerAPI");
|
||||
if(ElementModel is null)
|
||||
{
|
||||
var elementModel = await Http.GetFromJsonAsync<MessageResult<ElementModelDto?>>($"api/ElementModels/{Model.ModelId}");
|
||||
if (elementModel is not null && elementModel.Data is not null) ElementModel = elementModel.Data;
|
||||
}
|
||||
if (ElementModel is not null)
|
||||
{
|
||||
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("SetElementPosition", 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("SetElementPosition", ImageRef, textRef, Model.X + offsetX, Model.Y + offsetY, Model.Theta, -ElementModel.Width / 2, -ElementModel.Height / 2);
|
||||
|
||||
private async Task Model_PositionChanged() => await UpdatePosition(Model.X, Model.Y, Model.Theta);
|
||||
private async Task Model_OffsetChanged() => await UpdatePosition(Model.OffsetX, Model.OffsetY);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.OffsetChanged -= Model_OffsetChanged;
|
||||
Model.PositionChanged -= Model_PositionChanged;
|
||||
}
|
||||
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.3));
|
||||
transition: all 0.5s ease;
|
||||
}
|
||||
558
RobotNet.WebApp/Maps/Components/Editor/MapContainer.razor
Normal file
558
RobotNet.WebApp/Maps/Components/Editor/MapContainer.razor
Normal file
@@ -0,0 +1,558 @@
|
||||
@using RobotNet.MapShares.Models
|
||||
@using RobotNet.WebApp.Maps.Components.Editor.Edge
|
||||
@using RobotNet.WebApp.Maps.Components.Editor.Node
|
||||
@using RobotNet.WebApp.Maps.Components.Editor.Zone
|
||||
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject IHttpClientFactory HttpClientFactory
|
||||
@inject IDialogService Dialog
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<div class="map-viewer-container" @ref="ViewContainerRef" tabindex="1">
|
||||
<div @ref=ViewMovementRef>
|
||||
<svg @ref=MapContainerRef class="map-editor" letter-spacing="normal">
|
||||
<MapSvgDefs />
|
||||
<image @ref="MapImageRef" class="map-image" visibility="@(ShowMapSlam ? "visible" : "hidden")" />
|
||||
<OriginVector />
|
||||
|
||||
<CascadingValue Value="MapIsActive">
|
||||
<MapGrid @ref="@MapGridRef" Show="@ShowGrid" />
|
||||
<MapZone Models="@Zones" IsShow="@(EditorState != EditorState.CreateZone && EditorState != EditorState.SettingZone)" />
|
||||
<MapEdge @ref="MapEdgesRef" Models="@Edges" EdgeSelectedChanged="OnSelectedEdgeChanged" EditorState="@EditorState" />
|
||||
<MapNode Models="@Nodes" Elements="Elements" ShowName="@ShowName" EditorState="@EditorState" />
|
||||
<EdgeControlPoint @ref="EdgeControlPointRef" />
|
||||
<EdgeStraightCreating @ref="EdgeStraightCreatingRef" />
|
||||
<EdgeCurveCreating @ref="EdgeCurveCreatingRef" />
|
||||
<MapZone @ref=@MapZoneRef Models="@Zones" IsShow="@(EditorState == EditorState.CreateZone || EditorState == EditorState.SettingZone)" IsSetting="@(EditorState == EditorState.SettingZone)" ActivedZoneChanged="OnActivedZoneChanged" EditorState="@EditorState" />
|
||||
<MapScaner @ref=MapScanerRef />
|
||||
<ZoneCreating @ref=ZoneCreatingRef />
|
||||
<ZoneControlPoint @ref="ZoneControlPointRef"/>
|
||||
<MapCopy @ref=MapCopyRef />
|
||||
</CascadingValue>
|
||||
</svg>
|
||||
</div>
|
||||
<MapMousePosition @ref="MapInfoRef" />
|
||||
|
||||
<MudOverlay @bind-Visible="OverlayIsVisible" DarkBackground="true" Absolute="true">
|
||||
<MudText Typo="Typo.h1" Color="@Color.Error" Style="font-weight: bold;">@OverlayIsStr</MudText>
|
||||
</MudOverlay>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public bool ShowGrid { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool ShowName { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool ShowMapSlam { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool MapIsActive { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public ZoneType ZoneType { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EditorState EditorState { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<bool> MultiselectedEdgeChanged { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<bool> MultiselectedNodeChanged { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<bool> ZoneselectedChanged { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<bool> NodesUndoableChanged { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<EditorState> KeyPress { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<bool> MapIsChecking { get; set; }
|
||||
|
||||
private MapMousePosition MapInfoRef = null!;
|
||||
private EdgeStraightCreating EdgeStraightCreatingRef = null!;
|
||||
private EdgeCurveCreating EdgeCurveCreatingRef = null!;
|
||||
private MapEdge MapEdgesRef = null!;
|
||||
private MapGrid MapGridRef = null!;
|
||||
private EdgeControlPoint EdgeControlPointRef = null!;
|
||||
private MapScaner MapScanerRef = null!;
|
||||
private ZoneCreating ZoneCreatingRef = null!;
|
||||
private MapZone MapZoneRef = null!;
|
||||
private ZoneControlPoint ZoneControlPointRef = null!;
|
||||
private MapCopy MapCopyRef = null!;
|
||||
|
||||
private DotNetObjectReference<MapContainer> 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 Scale = 1;
|
||||
private double Left;
|
||||
private double Top;
|
||||
private double FitScale = 1;
|
||||
|
||||
private double Resolution = 1;
|
||||
private double OriginX;
|
||||
private double OriginY;
|
||||
private double ImageWidth;
|
||||
private double ImageHeight;
|
||||
|
||||
private MapDataDto MapData = new();
|
||||
public MapEdgeModel Edges { get; set; } = [];
|
||||
public MapNodeModel Nodes { get; set; } = [];
|
||||
public MapZoneModel Zones { get; set; } = [];
|
||||
public MapElementModel Elements { get; set; } = [];
|
||||
private HttpClient Http = default!;
|
||||
|
||||
private bool OverlayIsVisible = false;
|
||||
private string OverlayIsStr = "Loading...";
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
Http = HttpClientFactory.CreateClient("MapManagerAPI");
|
||||
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("AddMouseMoveEventListener", DotNetObj, ViewContainerRef, nameof(MouseMoveOnMapContainer));
|
||||
await JSRuntime.InvokeVoidAsync("AddEventListener", DotNetObj, ViewContainerRef, "click", nameof(ViewContainerClick));
|
||||
await JSRuntime.InvokeVoidAsync("AddKeyUpEventListener", DotNetObj, ViewContainerRef, nameof(ViewContainerKeyUp));
|
||||
|
||||
await JSRuntime.InvokeVoidAsync("AddMouseWheelEventListener", DotNetObj, MapContainerRef, nameof(MouseWheelOnMapContainer));
|
||||
await JSRuntime.InvokeVoidAsync("AddMouseUpEventListener", DotNetObj, MapContainerRef, nameof(MouseUpOnMapContainer));
|
||||
await JSRuntime.InvokeVoidAsync("AddMouseDownEventListener", DotNetObj, MapContainerRef, nameof(MouseDownOnMapContainer));
|
||||
await JSRuntime.InvokeVoidAsync("AddTouchMoveEventListener", DotNetObj, ViewContainerRef, nameof(TouchMoveOnMapContainer));
|
||||
}
|
||||
|
||||
private async Task LoadMap()
|
||||
{
|
||||
try
|
||||
{
|
||||
OverlayIsVisible = true;
|
||||
StateHasChanged();
|
||||
|
||||
var mapDataResult = await Http.GetFromJsonAsync<MessageResult<MapDataDto>>($"api/MapsData/{MapData.Id}");
|
||||
if (mapDataResult is not null && mapDataResult.Data is not null)
|
||||
{
|
||||
MapIsActive = mapDataResult.Data.Active;
|
||||
await LoadMap(mapDataResult.Data);
|
||||
OverlayIsVisible = false;
|
||||
}
|
||||
else OverlayIsStr = "Map Not Existed";
|
||||
StateHasChanged();
|
||||
}
|
||||
catch
|
||||
{
|
||||
OverlayIsStr = "Map Not Existed";
|
||||
StateHasChanged();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task LoadMap(MapDataDto? mapData)
|
||||
{
|
||||
if (mapData == null)
|
||||
{
|
||||
MapData = new();
|
||||
Nodes.ReplaceAll([]);
|
||||
Edges.ReplaceAll([]);
|
||||
Zones.ReplaceAll([]);
|
||||
Elements.ReplaceAll([]);
|
||||
Resolution = 1.0;
|
||||
OriginY = 0;
|
||||
OriginX = 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
|
||||
{
|
||||
MapData = mapData;
|
||||
Nodes.ReplaceAll(MapData.Nodes);
|
||||
Edges.ReplaceAll(MapData.Edges.Select(edge => new EdgeModel(edge, Nodes[edge.StartNodeId], Nodes[edge.EndNodeId])));
|
||||
Zones.ReplaceAll(MapData.Zones);
|
||||
Elements.ReplaceAll(MapData.Elements.Select(element => new ElementModel(element, Nodes[element.NodeId])));
|
||||
Resolution = mapData.Resolution;
|
||||
OriginY = -mapData.ImageHeight * Resolution - mapData.OriginY;
|
||||
OriginX = mapData.OriginX;
|
||||
ImageHeight = mapData.ImageHeight * Resolution;
|
||||
ImageWidth = mapData.ImageWidth * Resolution;
|
||||
MapGridRef.Resize(OriginX, OriginY, ImageHeight, ImageWidth);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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 - (MapData is null ? 0 : MapData.OriginY);
|
||||
|
||||
await SetViewMovement(Left - centerXBefore * deltaY, Top - (ImageHeight - centerYBefore) * deltaY);
|
||||
await JSRuntime.InvokeVoidAsync("SetMapSvgRect", MapContainerRef, ImageWidth * Scale, ImageHeight * Scale);
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public async Task ViewContainerClick() => await ViewContainerRef.FocusAsync();
|
||||
|
||||
[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 - (MapData is null ? 0 : MapData.OriginY);
|
||||
await SetViewMovement(Left - mouseX * scaleChange, Top - (ImageHeight - mouseY) * scaleChange);
|
||||
}
|
||||
|
||||
[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 (EditorState == EditorState.CreateCurveEdge || EditorState == EditorState.CreateDoubleCurveEdge) await EdgeCurveCreatingRef.Update(CursorX, CursorY);
|
||||
else if (EditorState == EditorState.CreateZone) await ZoneCreatingRef.Update(CursorX, CursorY);
|
||||
|
||||
switch (buttons)
|
||||
{
|
||||
case 1:
|
||||
if (MapIsActive) break;
|
||||
switch (EditorState)
|
||||
{
|
||||
case EditorState.CreateStraighEdge:
|
||||
await EdgeStraightCreatingRef.Update(CursorX, CursorY);
|
||||
break;
|
||||
case EditorState.CreateCurveEdge:
|
||||
case EditorState.CreateDoubleCurveEdge:
|
||||
await EdgeCurveCreatingRef.Update(CursorX, CursorY);
|
||||
break;
|
||||
case EditorState.Scaner:
|
||||
await MapScanerRef.Update(CursorX, CursorY);
|
||||
break;
|
||||
case EditorState.NavigationEdit:
|
||||
if (ctrlKey) NodePositionMove(CursorX, CursorY);
|
||||
break;
|
||||
case EditorState.SettingZone:
|
||||
if (ctrlKey) ZoneUpdateShape(CursorX, CursorY);
|
||||
break;
|
||||
case EditorState.Move:
|
||||
if (ctrlKey)
|
||||
{
|
||||
if (Edges.ActivedEdges.Count > 0) EdgesPositionMove(CursorX, CursorY);
|
||||
else NodesPositionMove(CursorX, CursorY);
|
||||
}
|
||||
break;
|
||||
case EditorState.Copy:
|
||||
if (ctrlKey) MapCopyRef.UpdateMove(CursorX, CursorY);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
await SetViewMovement(Left + movementX, Top + movementY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public async Task ViewContainerKeyUp(string code, string key, bool altKey, bool ctrlKey, bool shiftKey)
|
||||
{
|
||||
if (MapIsActive) return;
|
||||
switch (code)
|
||||
{
|
||||
case "Escape":
|
||||
await EditStateChange();
|
||||
break;
|
||||
case "Delete":
|
||||
_ = InvokeAsync(async Task () =>
|
||||
{
|
||||
if (EditorState == EditorState.NavigationEdit || EditorState == EditorState.Scaner) await DeleteEdge();
|
||||
else if (EditorState == EditorState.SettingZone) await DeleteZone();
|
||||
});
|
||||
break;
|
||||
case "KeyZ":
|
||||
if (ctrlKey) UndoEditorBackup();
|
||||
break;
|
||||
case "KeyS":
|
||||
if (ctrlKey) await SaveChanged();
|
||||
break;
|
||||
case "KeyM":
|
||||
if (EditorState != EditorState.Scaner) return;
|
||||
if (ctrlKey)
|
||||
{
|
||||
if (EditorBackup.Count > 0)
|
||||
{
|
||||
var save = await SaveChanged();
|
||||
if (!save) break;
|
||||
}
|
||||
await SetCursor("grab");
|
||||
await KeyPress.InvokeAsync(EditorState.Move);
|
||||
}
|
||||
break;
|
||||
case "KeyC":
|
||||
if (EditorState != EditorState.Scaner) return;
|
||||
if (ctrlKey) await KeyPress.InvokeAsync(EditorState.Copy);
|
||||
break;
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public async Task MouseUpOnMapContainer(int button, bool altKey, bool ctrlKey, bool shiftKey)
|
||||
{
|
||||
if (button == 0 && !MapIsActive)
|
||||
{
|
||||
switch (EditorState)
|
||||
{
|
||||
case EditorState.CreateStraighEdge:
|
||||
await CreateEdge(EdgeStraightCreatingRef.X1, EdgeStraightCreatingRef.Y1, EdgeStraightCreatingRef.X2, EdgeStraightCreatingRef.Y2);
|
||||
await EdgeStraightCreatingRef.Hidden();
|
||||
break;
|
||||
case EditorState.CreateCurveEdge:
|
||||
case EditorState.CreateDoubleCurveEdge:
|
||||
await EdgeCurveCreatingRef.FinishSubEdgeAsync(CursorX, CursorY);
|
||||
if (EdgeCurveCreatingRef.CreateStep == EdgeCurveCreating.CreateCurveEdgeStep.Finish)
|
||||
{
|
||||
var edgeCreateModel = EdgeCurveCreatingRef.GetEdgeCreateModel();
|
||||
await CreateEdge(edgeCreateModel.X1, edgeCreateModel.Y1, edgeCreateModel.X2, edgeCreateModel.Y2, edgeCreateModel.TrajectoryDegree, edgeCreateModel.ControlPoint1X, edgeCreateModel.ControlPoint1Y, edgeCreateModel.ControlPoint2X, edgeCreateModel.ControlPoint2Y);
|
||||
await EdgeCurveCreatingRef.Hidden();
|
||||
}
|
||||
break;
|
||||
case EditorState.Scaner:
|
||||
await ScanerActive(MapScanerRef.X1, MapScanerRef.Y1, MapScanerRef.X2, MapScanerRef.Y2);
|
||||
await MapScanerRef.Hidden();
|
||||
break;
|
||||
case EditorState.CreateZone:
|
||||
if (ZoneCreatingRef.Step == 4)
|
||||
{
|
||||
await CreateZone(ZoneCreatingRef.X1, ZoneCreatingRef.Y1, ZoneCreatingRef.X2, ZoneCreatingRef.Y2, ZoneCreatingRef.X3, ZoneCreatingRef.Y3, ZoneCreatingRef.X4, ZoneCreatingRef.Y4, ZoneType);
|
||||
await ZoneCreatingRef.Hidden();
|
||||
}
|
||||
break;
|
||||
case EditorState.SettingZone:
|
||||
if (Zones.ZoneActived is not null && Zones.ZoneActived.ActiveNode != 5) Zones.ZoneActived.ActiveNode = 5;
|
||||
break;
|
||||
case EditorState.NavigationEdit:
|
||||
if (Edges.ActivedEdges.Count == 1)
|
||||
{
|
||||
Edges.ActivedEdges[0].ActivedControlPoint1 = false;
|
||||
Edges.ActivedEdges[0].ActivedControlPoint2 = false;
|
||||
}
|
||||
Nodes.SelectedNode = null;
|
||||
break;
|
||||
case EditorState.Move:
|
||||
await SetCursor("grab");
|
||||
break;
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public async Task MouseDownOnMapContainer(int button, bool altKey, bool ctrlKey, bool shiftKey)
|
||||
{
|
||||
if (button == 0 && !MapIsActive)
|
||||
{
|
||||
var startNode = MapEditorHelper.GetClosesNode(CursorX, CursorY, Nodes.Select(node => new NodeDto() { X = node.X, Y = node.Y }).ToList());
|
||||
switch (EditorState)
|
||||
{
|
||||
case EditorState.CreateStraighEdge:
|
||||
await EdgeStraightCreatingRef.StartCreateAsync(startNode?.X ?? CursorX, startNode?.Y ?? CursorY);
|
||||
break;
|
||||
case EditorState.CreateCurveEdge:
|
||||
await EdgeCurveCreatingRef.CreateSubEdgeAsync(startNode?.X ?? CursorX, startNode?.Y ?? CursorY);
|
||||
break;
|
||||
case EditorState.CreateDoubleCurveEdge:
|
||||
await EdgeCurveCreatingRef.CreateSubEdgeAsync(startNode?.X ?? CursorX, startNode?.Y ?? CursorY, TrajectoryDegree.Three);
|
||||
break;
|
||||
case EditorState.Scaner:
|
||||
await MapScanerRef.CreateAsync(CursorX, CursorY);
|
||||
break;
|
||||
case EditorState.CreateZone:
|
||||
await ZoneCreatingRef.CreateAsync(CursorX, CursorY);
|
||||
break;
|
||||
case EditorState.SettingZone:
|
||||
if (Zones.ZoneActived is not null) Zones.ZoneActived.SetStartMovePosition(CursorX, CursorY);
|
||||
break;
|
||||
case EditorState.Move:
|
||||
await SetCursor("grabbing");
|
||||
Edges.SetStartMovePosition(CursorX, CursorY);
|
||||
Nodes.SetStartMovePosition(CursorX, CursorY);
|
||||
break;
|
||||
case EditorState.Copy:
|
||||
MapCopyRef.SetStartMovePosition(CursorX, CursorY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnSelectedEdgeChanged(EdgeModel? model)
|
||||
{
|
||||
if (model is not null && EditorState == EditorState.NavigationEdit)
|
||||
{
|
||||
if (model.TrajectoryDegree == TrajectoryDegree.One) EdgeControlPointRef.SetControl(null);
|
||||
else EdgeControlPointRef.SetControl(model);
|
||||
Edges.ActivedEdge([model]);
|
||||
await MultiselectedEdgeChanged.InvokeAsync(Edges.ActivedEdges.Count > 0);
|
||||
}
|
||||
else EdgeControlPointRef.SetControl(null);
|
||||
}
|
||||
|
||||
private void OnActivedZoneChanged((ZoneModel model, bool state) data)
|
||||
{
|
||||
if (EditorState == EditorState.SettingZone)
|
||||
{
|
||||
if (data.state)
|
||||
{
|
||||
ZoneControlPointRef.SetControl(data.model);
|
||||
_ = ZoneselectedChanged.InvokeAsync(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ZoneControlPointRef.SetControl(null);
|
||||
}
|
||||
|
||||
public async Task EditStateChange()
|
||||
{
|
||||
await EdgeCurveCreatingRef.Hidden();
|
||||
await EdgeStraightCreatingRef.Hidden();
|
||||
await ZoneCreatingRef.Hidden();
|
||||
MapCopyRef.OnShow(false, []);
|
||||
Zones.UnActivedZone();
|
||||
EdgeControlPointRef.SetControl(null);
|
||||
if (EditorState == EditorState.Copy) await CreateMapCopy();
|
||||
if (EditorState != EditorState.Move)
|
||||
{
|
||||
Edges.UnActivedEdge();
|
||||
Nodes.UnActivedNode();
|
||||
}
|
||||
if (EditorState != EditorState.Copy) await SaveChanged();
|
||||
if (EditorState != EditorState.Copy && EditorState != EditorState.Move) await SetCursor("initial");
|
||||
await MultiselectedEdgeChanged.InvokeAsync(Edges.ActivedEdges.Count() > 0);
|
||||
await MultiselectedNodeChanged.InvokeAsync(Nodes.ActivedNodes.Count() > 0);
|
||||
await ZoneselectedChanged.InvokeAsync(false);
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public async Task CreateMapCopy()
|
||||
{
|
||||
if (Edges.ActivedEdges.Count > 0)
|
||||
{
|
||||
if (EditorBackup.Count > 0)
|
||||
{
|
||||
var save = await SaveChanged();
|
||||
if (!save) return;
|
||||
}
|
||||
MapCopyRef.OnShow(true, Edges.ActivedEdges);
|
||||
EditorBackup.Add(new()
|
||||
{
|
||||
Type = MapEditorBackupType.Copy,
|
||||
});
|
||||
await NodesUndoableChanged.InvokeAsync(true);
|
||||
await SetCursor("copy");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SetCursor(string data) => await JSRuntime.InvokeVoidAsync("ElementSetAttribute", MapContainerRef, "cursor", data);
|
||||
}
|
||||
1092
RobotNet.WebApp/Maps/Components/Editor/MapContainer.razor.cs
Normal file
1092
RobotNet.WebApp/Maps/Components/Editor/MapContainer.razor.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,28 @@
|
||||
.map-viewer-container {
|
||||
background-color: #bfbfbf;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
cursor: not-allowed;
|
||||
border-top: solid 2px #808080;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.map-viewer-container > div {
|
||||
width: fit-content;
|
||||
height: fit-content;
|
||||
position: absolute;
|
||||
cursor: default;
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.map-image {
|
||||
user-select: none;
|
||||
image-rendering: pixelated;
|
||||
transform: scale(1, -1);
|
||||
}
|
||||
|
||||
.map-editor {
|
||||
transform: scale(1, -1);
|
||||
}
|
||||
121
RobotNet.WebApp/Maps/Components/Editor/MapCopy.razor
Normal file
121
RobotNet.WebApp/Maps/Components/Editor/MapCopy.razor
Normal file
@@ -0,0 +1,121 @@
|
||||
@implements IDisposable
|
||||
|
||||
@using RobotNet.WebApp.Maps.Components.Editor.Edge
|
||||
@using RobotNet.WebApp.Maps.Components.Editor.Node
|
||||
|
||||
<MapEdge Models="@this.EdgeModels" />
|
||||
<MapNode Models="@this.NodeModels" />
|
||||
|
||||
@code {
|
||||
public MapEdgeModel EdgeModels { get; set; } = [];
|
||||
public MapNodeModel NodeModels { get; set; } = [];
|
||||
public bool isMoving = false;
|
||||
|
||||
private bool isShowing = false;
|
||||
private (Guid Id, double X, double Y) StartPosition = new();
|
||||
|
||||
public void OnShow(bool isShow, List<EdgeModel> edgeModels)
|
||||
{
|
||||
isShowing = isShow;
|
||||
if (isShow && edgeModels.Count > 0)
|
||||
{
|
||||
isMoving = false;
|
||||
List<NodeDto> nodeDtos = [];
|
||||
foreach (var edge in edgeModels)
|
||||
{
|
||||
if (!nodeDtos.Any(n => n.Id == edge.StartNode.Id)) nodeDtos.Add(new()
|
||||
{
|
||||
Id = edge.StartNode.Id,
|
||||
MapId = edge.StartNode.MapId,
|
||||
Name = edge.StartNode.Name,
|
||||
X = edge.StartNode.X,
|
||||
Y = edge.StartNode.Y,
|
||||
Theta = edge.StartNode.Theta,
|
||||
AllowedDeviationXy = edge.StartNode.AllowedDeviationXy,
|
||||
AllowedDeviationTheta = edge.StartNode.AllowedDeviationTheta,
|
||||
Actions = edge.StartNode.Actions,
|
||||
});
|
||||
if (!nodeDtos.Any(n => n.Id == edge.EndNode.Id)) nodeDtos.Add(new()
|
||||
{
|
||||
Id = edge.EndNode.Id,
|
||||
MapId = edge.EndNode.MapId,
|
||||
Name = edge.EndNode.Name,
|
||||
X = edge.EndNode.X,
|
||||
Y = edge.EndNode.Y,
|
||||
Theta = edge.EndNode.Theta,
|
||||
AllowedDeviationXy = edge.EndNode.AllowedDeviationXy,
|
||||
AllowedDeviationTheta = edge.EndNode.AllowedDeviationTheta,
|
||||
Actions = edge.EndNode.Actions,
|
||||
});
|
||||
}
|
||||
|
||||
NodeModels.ReplaceAll(nodeDtos);
|
||||
List<EdgeModel> edges = edgeModels.Select(edge => new EdgeModel(new()
|
||||
{
|
||||
Id = edge.Id,
|
||||
MapId = edge.MapId,
|
||||
DirectionAllowed = edge.DirectionAllowed,
|
||||
TrajectoryDegree = edge.TrajectoryDegree,
|
||||
Actions = edge.Actions,
|
||||
AllowedDeviationTheta = edge.AllowedDeviationTheta,
|
||||
AllowedDeviationXy = edge.AllowedDeviationXy,
|
||||
RotationAllowed = edge.RotationAllowed,
|
||||
MaxHeight = edge.MaxHeight,
|
||||
MinHeight = edge.MinHeight,
|
||||
MaxRotationSpeed = edge.MaxRotationSpeed,
|
||||
MaxSpeed = edge.MaxRotationSpeed,
|
||||
ControlPoint1X = edge.ControlPoint1X,
|
||||
ControlPoint1Y = edge.ControlPoint1Y,
|
||||
ControlPoint2X = edge.ControlPoint2X,
|
||||
ControlPoint2Y = edge.ControlPoint2Y,
|
||||
},
|
||||
NodeModels[edge.StartNode.Id],
|
||||
NodeModels[edge.EndNode.Id]
|
||||
)).ToList();
|
||||
|
||||
EdgeModels.ReplaceAll(edges);
|
||||
EdgeModels.ActivedEdge(edges);
|
||||
if (NodeModels.Count() > 0)
|
||||
{
|
||||
StartPosition.Id = NodeModels[0].Id;
|
||||
StartPosition.X = NodeModels[0].X;
|
||||
StartPosition.Y = NodeModels[0].Y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
isMoving = false;
|
||||
NodeModels.ReplaceAll([]);
|
||||
EdgeModels.ReplaceAll([]);
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public void UpdateMove(double x, double y)
|
||||
{
|
||||
if (!isShowing) return;
|
||||
if (NodeModels.Count() > 0)
|
||||
{
|
||||
var nodeChange = NodeModels[StartPosition.Id];
|
||||
if (nodeChange is not null)
|
||||
{
|
||||
var distance = Math.Sqrt(Math.Pow(StartPosition.X - nodeChange.X, 2) + Math.Pow(StartPosition.Y - nodeChange.Y, 2));
|
||||
if (distance > 0.25) isMoving = true;
|
||||
else isMoving = false;
|
||||
}
|
||||
|
||||
EdgeModels.UpdateMoveEdge(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetStartMovePosition(double x, double y)
|
||||
{
|
||||
EdgeModels.SetStartMovePosition(x, y);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
37
RobotNet.WebApp/Maps/Components/Editor/MapGrid.razor
Normal file
37
RobotNet.WebApp/Maps/Components/Editor/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();
|
||||
}
|
||||
}
|
||||
6
RobotNet.WebApp/Maps/Components/Editor/MapGrid.razor.css
Normal file
6
RobotNet.WebApp/Maps/Components/Editor/MapGrid.razor.css
Normal file
@@ -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
|
||||
}
|
||||
40
RobotNet.WebApp/Maps/Components/Editor/MapScaner.razor
Normal file
40
RobotNet.WebApp/Maps/Components/Editor/MapScaner.razor
Normal file
@@ -0,0 +1,40 @@
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<polygon @ref="Ref" visibility="hidden" />
|
||||
|
||||
@code {
|
||||
private ElementReference Ref;
|
||||
|
||||
public double X1 { get; private set; }
|
||||
public double Y1 { get; private set; }
|
||||
public double X2 { get; private set; }
|
||||
public double Y2 { get; private set; }
|
||||
|
||||
public async Task CreateAsync(double x, double y)
|
||||
{
|
||||
X1 = x;
|
||||
Y1 = y;
|
||||
X2 = x;
|
||||
Y2 = y;
|
||||
|
||||
await CalculatorZone();
|
||||
await Visible();
|
||||
}
|
||||
|
||||
public async Task Update(double x, double y)
|
||||
{
|
||||
X2 = x;
|
||||
Y2 = y;
|
||||
await CalculatorZone();
|
||||
}
|
||||
|
||||
private async Task CalculatorZone()
|
||||
{
|
||||
var points = $"{X1},{Y1} {X1},{Y2} {X2},{Y2} {X2},{Y1}";
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "points", points);
|
||||
}
|
||||
|
||||
|
||||
public async Task Visible() => await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "visibility", "visible");
|
||||
public async Task Hidden() => await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "visibility", "hidden");
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
polygon {
|
||||
fill: #c2c2a3;
|
||||
stroke: none;
|
||||
fill-opacity: 0.5;
|
||||
}
|
||||
32
RobotNet.WebApp/Maps/Components/Editor/MapSvgDefs.razor
Normal file
32
RobotNet.WebApp/Maps/Components/Editor/MapSvgDefs.razor
Normal file
@@ -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;
|
||||
}
|
||||
489
RobotNet.WebApp/Maps/Components/Editor/Node/MapNode.razor
Normal file
489
RobotNet.WebApp/Maps/Components/Editor/Node/MapNode.razor
Normal file
@@ -0,0 +1,489 @@
|
||||
@using System.Text.Json
|
||||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||
@using RobotNet.WebApp.Maps.Components.Editor.Element
|
||||
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IHttpClientFactory HttpClientFactory
|
||||
@inject IDialogService Dialog
|
||||
|
||||
@foreach (var node in Models)
|
||||
{
|
||||
<Node Model="node" ShowName="@ShowName" OnClick="NodeClickChanged" DoubleClick="OnNodeDoubleClick" EditorState="@EditorState" />
|
||||
}
|
||||
|
||||
@foreach (var element in Elements)
|
||||
{
|
||||
<Element Model="@element" ShowName="@ShowName" EditorState="EditorState" DoubleClick="ElementDoubleClick" />
|
||||
}
|
||||
|
||||
<MudDialog @bind-Visible="updateNodeVisible">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">
|
||||
Update node @UpdateModel.Id
|
||||
</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<div class="d-flex flex-row">
|
||||
<div class="d-flex flex-column">
|
||||
<div class="mb-2">
|
||||
<MudTextField @bind-Value="UpdateModel.Name" Label="Name" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<MudNumericField @bind-Value="UpdateModel.X" Label="X" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<MudNumericField @bind-Value="UpdateModel.Y" Label="Y" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<MudNumericField @bind-Value="UpdateModel.Theta" Label="Theta" AdornmentText="Degree" Max="180" Min="-180" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<MudNumericField @bind-Value="UpdateModel.AllowedDeviationXy" Label="AllowedDeviationXy" Step="0.01" Min="0" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
<div>
|
||||
<MudNumericField @bind-Value="UpdateModel.AllowedDeviationTheta" Label="AllowedDeviationTheta" Step="1" Min="0" Max="180" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex flex-column ms-2 flex-grow-1">
|
||||
<div class="d-flex flex-row mb-5">
|
||||
<MudSelect @bind-Value=ActionSelected Margin="Margin.Dense" T="ActionDto" Label="Action" Variant="Variant.Outlined" Class="w-100" AnchorOrigin="Origin.BottomLeft">
|
||||
@foreach (var action in Actions)
|
||||
{
|
||||
<MudSelectItem Value="@action">@action.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
<MudFab Class="ms-2" Color="Color.Secondary" StartIcon="@Icons.Material.Filled.Add" Size="Size.Medium" OnClick="AddAction" />
|
||||
</div>
|
||||
<div class="paper-action">
|
||||
@foreach (var actionId in UpdateModel.Actions)
|
||||
{
|
||||
<div class="m-1" style="height: fit-content">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Info" Style="text-transform:none" OnClick="(() => DeleteAction(actionId))">
|
||||
@(Actions.FirstOrDefault(ac => ac.Id == actionId)?.Name)
|
||||
</MudButton>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="(() => updateNodeVisible = false)" Class="px-10" Variant="Variant.Filled">Cancel</MudButton>
|
||||
<MudButton OnClick="UpdateNode" Variant="Variant.Filled" Color="Color.Primary" Class="px-10 me-4" Disabled=@(MapIsActive)>Update</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
<MudDialog @bind-Visible="createElementVisible">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">
|
||||
Create Element Node @ElementCreateModel.NodeId
|
||||
</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<div class="d-flex flex-column" style="max-height: 700px; overflow-y: auto">
|
||||
<MudTextField Class="my-2"
|
||||
@bind-Value="ElementCreateModel.Name" T="string"
|
||||
Label="Name" Required="true" RequiredError="Name is required!"
|
||||
Counter="18" Variant="Variant.Outlined"
|
||||
Validation="@(new Func<string, IEnumerable<string>>(MapEditorHelper.NameValidation))" />
|
||||
<div class="d-flex flex-row mb-2">
|
||||
<MudNumericField Class="me-2" @bind-Value="ElementCreateModel.OffsetX" Label="Offset X" Step="0.1" Variant="Variant.Outlined" />
|
||||
<MudNumericField Class="ms-2" @bind-Value="ElementCreateModel.OffsetY" Label="Offset Y" Step="0.1" Variant="Variant.Outlined" />
|
||||
</div>
|
||||
<MudSelect Class="mb-2" T="ElementModelDto" Variant="Variant.Outlined" Label="Type" Required="true" RequiredError="Type is required!"
|
||||
@bind-Value="@ElementModelSelected">
|
||||
@foreach (var model in ElementModels)
|
||||
{
|
||||
<MudSelectItem Value="@model">@model.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</div>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="(() => createElementVisible = false)" Class="px-10" Variant="Variant.Filled">Cancel</MudButton>
|
||||
<MudButton OnClick="CreateElement" Variant="Variant.Filled" Color="Color.Primary" Class="px-10" Disabled=@(MapIsActive)>Create</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
<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" ReadOnly="@(MapIsActive)"
|
||||
Required="true" RequiredError="Name is required!"
|
||||
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="@(MapIsActive)" />
|
||||
<MudNumericField T="double" Label="Offset Y" @bind-value="ElementUpdateModel.OffsetY" Variant="Variant.Outlined" Step="0.1" ReadOnly="@(MapIsActive)" />
|
||||
@* <MudCheckBox Size="Size.Small" T="bool" LabelPlacement="Placement.Start" Label="IsOpen" @bind-value="ElementUpdateModel.IsOpen" Color="Color.Success"
|
||||
UncheckedColor="Color.Default" ReadOnly /> *@
|
||||
</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="@(MapIsActive)"
|
||||
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="@(MapIsActive)"
|
||||
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="@(MapIsActive)" 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="@(MapIsActive)"
|
||||
ValueChanged="((data) => property.DefaultValue = data)" />
|
||||
}
|
||||
}
|
||||
</div>
|
||||
<span class="paper-title">Properties</span>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="Delete" Variant="Variant.Filled" Color="Color.Secondary" Class="px-10" Disabled=@(MapIsActive)>Delete</MudButton>
|
||||
<MudButton OnClick="(() => updateElementVisble = false)" Class="px-10" Variant="Variant.Filled">Cancel</MudButton>
|
||||
<MudButton OnClick="UpdateElement" Variant="Variant.Filled" Color="Color.Primary" Class="px-10" Disabled=@(MapIsActive)>Update</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public MapNodeModel Models { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public MapElementModel Elements { get; set; } = [];
|
||||
|
||||
[CascadingParameter]
|
||||
protected bool MapIsActive { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool ShowName { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EditorState EditorState { get; set; }
|
||||
|
||||
private NodeUpdateModel UpdateModel = new();
|
||||
private bool updateNodeVisible;
|
||||
|
||||
private List<ActionDto> Actions = [];
|
||||
private ActionDto? ActionSelected = null;
|
||||
|
||||
public List<ElementModelDto> ElementModels { get; set; } = [];
|
||||
private bool createElementVisible;
|
||||
private ElementCreateModel ElementCreateModel = new();
|
||||
private ElementModelDto? ElementModelSelected = null;
|
||||
private NodeModel? NodeModelDoubleClick = null;
|
||||
|
||||
private bool updateElementVisble;
|
||||
private ElementUpdateModel ElementUpdateModel = new();
|
||||
private List<ElementProperty> ElementProperties = [];
|
||||
private HttpClient Http = default!;
|
||||
|
||||
protected override void OnAfterRender(bool firstRender)
|
||||
{
|
||||
base.OnAfterRender(firstRender);
|
||||
|
||||
if (!firstRender) return;
|
||||
|
||||
Http = HttpClientFactory.CreateClient("MapManagerAPI");
|
||||
Models.Changed += StateHasChanged;
|
||||
Elements.Changed += StateHasChanged;
|
||||
}
|
||||
|
||||
private void NodeClickChanged(NodeModel? node) => Models.SelectedNode = node;
|
||||
|
||||
private async Task LoadActionAsync(Guid mapId)
|
||||
{
|
||||
var result = await Http.GetFromJsonAsync<IEnumerable<ActionDto>>($"api/Actions/{mapId}");
|
||||
|
||||
if (result is not null && result.Any())
|
||||
{
|
||||
Actions.Clear();
|
||||
Actions.AddRange(result);
|
||||
}
|
||||
if (Actions.Any()) ActionSelected = Actions.First();
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task LoadElementModels(Guid mapId)
|
||||
{
|
||||
ElementModels.Clear();
|
||||
|
||||
var elModels = await Http.GetFromJsonAsync<MessageResult<IEnumerable<ElementModelDto>>>($"api/ElementModels/map/{mapId}");
|
||||
if (elModels is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (!elModels.IsSuccess) Snackbar.Add($"Có lỗi xảy ra: {elModels.Message}", Severity.Error);
|
||||
else if(elModels.Data is null || !elModels.Data.Any())
|
||||
{
|
||||
Snackbar.Add("Không có Element model nào trong bản đồ này", Severity.Warning);
|
||||
ElementModelSelected = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
ElementModels.AddRange(elModels.Data.OrderBy(el => el.Name));
|
||||
if (ElementModels.Count > 0)
|
||||
{
|
||||
ElementModelSelected = ElementModelSelected is null ? ElementModels.First() : ElementModels.FirstOrDefault(em => em.Id == ElementModelSelected.Id) ?? ElementModels.First();
|
||||
}
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void AddAction()
|
||||
{
|
||||
if (ActionSelected is null) return;
|
||||
if (UpdateModel.Actions.Any(action => action == ActionSelected.Id))
|
||||
{
|
||||
Snackbar.Add("Action đã tồn tại", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateModel.Actions = [.. UpdateModel.Actions, ActionSelected.Id];
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void DeleteAction(Guid actionId)
|
||||
{
|
||||
UpdateModel.Actions = UpdateModel.Actions.Where(a => actionId != a).ToArray();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task OnNodeDoubleClick(NodeModel model)
|
||||
{
|
||||
if (model == null || (EditorState != EditorState.NavigationEdit && EditorState != EditorState.View)) return;
|
||||
|
||||
NodeModelDoubleClick = model;
|
||||
if (EditorState == EditorState.NavigationEdit)
|
||||
{
|
||||
await LoadActionAsync(model.MapId);
|
||||
|
||||
UpdateModel.Id = model.Id;
|
||||
UpdateModel.Name = model.Name;
|
||||
UpdateModel.X = model.X;
|
||||
UpdateModel.Y = model.Y;
|
||||
UpdateModel.Theta = model.Theta;
|
||||
UpdateModel.AllowedDeviationXy = model.AllowedDeviationXy;
|
||||
UpdateModel.AllowedDeviationTheta = model.AllowedDeviationTheta;
|
||||
UpdateModel.Actions = [];
|
||||
var actions = JsonSerializer.Deserialize<Guid[]>(model.Actions ?? "");
|
||||
if (actions is not null && actions.Length > 0)
|
||||
{
|
||||
UpdateModel.Actions = [.. actions];
|
||||
}
|
||||
|
||||
updateNodeVisible = true;
|
||||
}
|
||||
else if (EditorState == EditorState.View)
|
||||
{
|
||||
await LoadElementModels(model.MapId);
|
||||
|
||||
ElementCreateModel.Name = "";
|
||||
ElementCreateModel.MapId = model.MapId;
|
||||
ElementCreateModel.NodeId = model.Id;
|
||||
|
||||
createElementVisible = true;
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task UpdateNode()
|
||||
{
|
||||
var selectedModel = Models.FirstOrDefault(e => e.Id == UpdateModel.Id);
|
||||
|
||||
if (selectedModel == null)
|
||||
{
|
||||
updateNodeVisible = false;
|
||||
StateHasChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await (await Http.PutAsJsonAsync($"api/Nodes", UpdateModel)).Content.ReadFromJsonAsync<MessageResult>();
|
||||
if (result is null)
|
||||
{
|
||||
Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
return;
|
||||
}
|
||||
else if (!result.IsSuccess)
|
||||
{
|
||||
Snackbar.Add(result.Message, Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
selectedModel.UpdateData(UpdateModel);
|
||||
updateNodeVisible = false;
|
||||
Snackbar.Add("Cập nhật thành công", Severity.Success);
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task CreateElement()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (NodeModelDoubleClick is null) return;
|
||||
if (ElementModelSelected is null)
|
||||
{
|
||||
Snackbar.Add("Hãy chọn Element model!", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(ElementCreateModel.Name))
|
||||
{
|
||||
Snackbar.Add("Name không được để trống.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var nameInvalid = MapEditorHelper.NameChecking(ElementCreateModel.Name);
|
||||
if (!nameInvalid.IsSuccess)
|
||||
{
|
||||
Snackbar.Add(nameInvalid.returnStr, Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
ElementCreateModel.ModelId = ElementModelSelected.Id;
|
||||
|
||||
var create = await (await Http.PostAsJsonAsync("api/Elements", ElementCreateModel)).Content.ReadFromJsonAsync<MessageResult<ElementDto>>();
|
||||
if (create is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (!create.IsSuccess) Snackbar.Add($"Có lỗi xảy ra: {create.Message}", Severity.Error);
|
||||
else if (create.Data is null) Snackbar.Add("Tạo Element không thành công", Severity.Error);
|
||||
else
|
||||
{
|
||||
|
||||
Elements.Add(new(create.Data, NodeModelDoubleClick));
|
||||
createElementVisible = false;
|
||||
Snackbar.Add("Tạo Element thành công!", Severity.Success);
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (AccessTokenNotAvailableException ex)
|
||||
{
|
||||
ex.Redirect();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
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<ElementProperty>>(model.Content, JsonOptionExtends.Read);
|
||||
if (properties is not null) ElementProperties = [.. properties];
|
||||
}
|
||||
|
||||
updateElementVisble = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task Delete()
|
||||
{
|
||||
var parameters = new DialogParameters<ConfirmDialog>
|
||||
{
|
||||
{ x => x.Content, $"Bạn có chắc chắn muốn xóa element {ElementUpdateModel.Name} đi không?" },
|
||||
{ x => x.ConfirmText, "Delete" },
|
||||
{ x => x.Color, Color.Secondary }
|
||||
};
|
||||
var ConfirmDelete = await Dialog.ShowAsync<ConfirmDialog>("Xoá Element", parameters);
|
||||
var result = await ConfirmDelete.Result;
|
||||
if (result is not null && result.Data is not null && bool.TryParse(result.Data.ToString(), out bool data) && data)
|
||||
{
|
||||
var response = await Http.DeleteFromJsonAsync<MessageResult>($"api/Elements/{ElementUpdateModel.Id}");
|
||||
if (response is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (!response.IsSuccess) Snackbar.Add(response.Message ?? "Lỗi chưa xác định.", Severity.Error);
|
||||
else
|
||||
{
|
||||
var elementData = Elements.FirstOrDefault(m => m.Id == ElementUpdateModel.Id);
|
||||
if (elementData is not null)
|
||||
{
|
||||
Elements.Remove(elementData);
|
||||
Snackbar.Add($"Xóa element thành công.", Severity.Success);
|
||||
}
|
||||
else Snackbar.Add($"Element không tồn tại.", Severity.Warning);
|
||||
}
|
||||
|
||||
updateElementVisble = false;
|
||||
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 async Task UpdateElement()
|
||||
{
|
||||
var selectedElement = Elements.FirstOrDefault(e => e.Id == ElementUpdateModel.Id);
|
||||
if (selectedElement is null) return;
|
||||
|
||||
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.UpdateElement(result.Data);
|
||||
Snackbar.Add("Cập nhật thành công", Severity.Success);
|
||||
}
|
||||
|
||||
updateElementVisble = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Models.Changed -= StateHasChanged;
|
||||
Elements.Changed -= StateHasChanged;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
.paper-action {
|
||||
padding: 5px;
|
||||
border: 1px solid silver;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-content: flex-start;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
width: 100%;
|
||||
max-width: 290px;
|
||||
height: 100%;
|
||||
max-height: 277px;
|
||||
}
|
||||
|
||||
.paper-property-container {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 50%;
|
||||
height: 193px;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
102
RobotNet.WebApp/Maps/Components/Editor/Node/Node.razor
Normal file
102
RobotNet.WebApp/Maps/Components/Editor/Node/Node.razor
Normal file
@@ -0,0 +1,102 @@
|
||||
@implements IDisposable
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<circle @ref="circleErrorRef" style="fill: red; opacity: 0.6; r: 0.3px;"/>
|
||||
<circle @ref="circleRef" @ondblclick="@(async () => await DoubleClick.InvokeAsync(Model))" class="@(IsSetting ? "setting" : "")" />
|
||||
<text @ref="textRef" visibility="@(ShowName ? "visible" : "hidden")" class="@(IsSetting ? "setting" : "")">@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; }
|
||||
|
||||
[Parameter]
|
||||
public EditorState EditorState { get; set; }
|
||||
|
||||
private ElementReference circleRef;
|
||||
private ElementReference textRef;
|
||||
private ElementReference circleErrorRef;
|
||||
private DotNetObjectReference<Node> DotNetObj = null!;
|
||||
private bool IsError = false;
|
||||
|
||||
private bool IsSetting => EditorState == EditorState.NavigationEdit || EditorState == EditorState.CreateStraighEdge || EditorState == EditorState.CreateCurveEdge ||
|
||||
EditorState == EditorState.CreateDoubleCurveEdge || EditorState == EditorState.View;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
DotNetObj = DotNetObjectReference.Create(this);
|
||||
await JSRuntime.InvokeVoidAsync("AddMouseDownEventListener", DotNetObj, circleRef, nameof(OnMouseDown), false);
|
||||
await UpdatePosition(Model.X, Model.Y);
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", circleErrorRef, "visibility", "hidden");
|
||||
}
|
||||
|
||||
public override async Task SetParametersAsync(ParameterView parameters)
|
||||
{
|
||||
bool updateNode = false;
|
||||
if (parameters.TryGetValue(nameof(Model), out NodeModel? model) && ((Model?.Id ?? Guid.Empty) != (model?.Id ?? Guid.Empty)))
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.PositionChanged -= Model_PositionChanged;
|
||||
Model.ActivedChanged -= ActivedChanged;
|
||||
Model.ErrorChanged -= ErrorChanged;
|
||||
}
|
||||
|
||||
if (model != null)
|
||||
{
|
||||
updateNode = true;
|
||||
model.PositionChanged += Model_PositionChanged;
|
||||
model.ActivedChanged += ActivedChanged;
|
||||
model.ErrorChanged += ErrorChanged;
|
||||
}
|
||||
}
|
||||
await base.SetParametersAsync(parameters);
|
||||
if (updateNode && model != null) await UpdatePosition(model.X, model.Y);
|
||||
}
|
||||
|
||||
private async void Model_PositionChanged() => await UpdatePosition(Model.X, Model.Y);
|
||||
|
||||
[JSInvokable]
|
||||
public async Task OnMouseDown(int button, bool altKey, bool ctrlKey, bool shiftKey) => await OnClick.InvokeAsync(Model);
|
||||
|
||||
private async Task UpdatePosition(double x, double y)
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("SetNodePosition", circleRef, textRef, x, y);
|
||||
if (IsError) await JSRuntime.InvokeVoidAsync("SetNodePosition", circleErrorRef, textRef, x, y);
|
||||
}
|
||||
|
||||
private async void ActivedChanged(bool state) => await JSRuntime.InvokeVoidAsync(state ? "AddSelected" : "RemoveSelected", circleRef);
|
||||
|
||||
private async void ErrorChanged(bool state)
|
||||
{
|
||||
IsError = state;
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", circleErrorRef, "visibility", state ? "visible" : "hidden");
|
||||
if (IsError) await JSRuntime.InvokeVoidAsync("SetNodePosition", circleErrorRef, textRef, Model.X, Model.Y);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.PositionChanged -= Model_PositionChanged;
|
||||
Model.ActivedChanged -= ActivedChanged;
|
||||
Model.ErrorChanged -= ErrorChanged;
|
||||
}
|
||||
if (DotNetObj != null) DotNetObj.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
41
RobotNet.WebApp/Maps/Components/Editor/Node/Node.razor.css
Normal file
41
RobotNet.WebApp/Maps/Components/Editor/Node/Node.razor.css
Normal file
@@ -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;
|
||||
}
|
||||
10
RobotNet.WebApp/Maps/Components/Editor/OriginVector.razor
Normal file
10
RobotNet.WebApp/Maps/Components/Editor/OriginVector.razor
Normal file
@@ -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;
|
||||
}
|
||||
156
RobotNet.WebApp/Maps/Components/Editor/Zone/MapZone.razor
Normal file
156
RobotNet.WebApp/Maps/Components/Editor/Zone/MapZone.razor
Normal file
@@ -0,0 +1,156 @@
|
||||
@implements IDisposable
|
||||
|
||||
@inject IHttpClientFactory HttpClientFactory
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
@foreach (var zone in Models)
|
||||
{
|
||||
<Zone Model="@zone" IsSetting="@IsSetting" DoubleClick="ZoneDoubleClick" IsShow="IsShow" />
|
||||
}
|
||||
|
||||
<MudDialog @bind-Visible="@UpdateZoneVisiable">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">
|
||||
Update zone @UpdateModel.Id
|
||||
</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<MudSelect Class="mt-2" @bind-Value="UpdateModel.Type" Label="Type" Variant="Variant.Outlined" AnchorOrigin="Origin.BottomLeft" Margin="Margin.Dense" Dense ReadOnly=@(MapIsActive)>
|
||||
<MudSelectItem Value="@(ZoneType.Operating)" />
|
||||
<MudSelectItem Value="@(ZoneType.OperatingHazard)" />
|
||||
<MudSelectItem Value="@(ZoneType.Restricted)" />
|
||||
<MudSelectItem Value="@(ZoneType.LoadTransfer)" />
|
||||
<MudSelectItem Value="@(ZoneType.Confined)" />
|
||||
<MudSelectItem Value="@(ZoneType.Forbidden)" />
|
||||
</MudSelect>
|
||||
<MudTextField Class="mt-2" @bind-Value="UpdateModel.Name" Label="Name" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
|
||||
<div class="d-flex flex-row mt-5">
|
||||
<div class="d-flex flex-column me-2 w-50">
|
||||
<div class="mb-4">
|
||||
<MudNumericField Class="mb-3" @bind-Value="UpdateModel.X1" Label="X1" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
|
||||
<MudNumericField @bind-Value="UpdateModel.Y1" Label="Y1" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
<div>
|
||||
<MudNumericField Class="mb-3" @bind-Value="UpdateModel.X2" Label="X2" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
|
||||
<MudNumericField @bind-Value="UpdateModel.Y2" Label="Y2" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex flex-column ms-2 w-50">
|
||||
<div class="mb-4">
|
||||
<MudNumericField Class="mb-3" @bind-Value="UpdateModel.X3" Label="X3" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
|
||||
<MudNumericField @bind-Value="UpdateModel.Y3" Label="Y3" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
<div>
|
||||
<MudNumericField Class="mb-3" @bind-Value="UpdateModel.X4" Label="X4" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
|
||||
<MudNumericField @bind-Value="UpdateModel.Y4" Label="Y4" ShrinkLabel Variant="Variant.Outlined" Margin="Margin.Dense" ReadOnly=@(MapIsActive) />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="CancelUpdateZone" Class="px-10" Variant="Variant.Filled">Cancel</MudButton>
|
||||
<MudButton OnClick="UpdateZone" Variant="Variant.Filled" Color="Color.Primary" Class="px-10" Disabled=@(MapIsActive)>Update</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public MapZoneModel Models { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public bool IsShow { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool IsSetting { get; set; }
|
||||
|
||||
[CascadingParameter]
|
||||
protected bool MapIsActive { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EditorState EditorState { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<(ZoneModel, bool)> ActivedZoneChanged { get; set; }
|
||||
|
||||
private ZoneUpdateModel UpdateModel = new();
|
||||
private bool UpdateZoneVisiable = false;
|
||||
private HttpClient Http = default!;
|
||||
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
Http = HttpClientFactory.CreateClient("MapManagerAPI");
|
||||
Models.Changed += StateHasChanged;
|
||||
Models.ActivedZoneChanged += OnActivedZoneChanged;
|
||||
}
|
||||
|
||||
private void OnActivedZoneChanged(ZoneModel model, bool state)
|
||||
{
|
||||
_ = ActivedZoneChanged.InvokeAsync((model, state));
|
||||
}
|
||||
|
||||
private void ZoneDoubleClick(ZoneModel model)
|
||||
{
|
||||
if (model == null || EditorState != EditorState.SettingZone) return;
|
||||
|
||||
UpdateModel.Id = model.Id;
|
||||
UpdateModel.Type = model.Type;
|
||||
UpdateModel.Name = model.Name;
|
||||
UpdateModel.X1 = model.X1;
|
||||
UpdateModel.Y1 = model.Y1;
|
||||
UpdateModel.X2 = model.X2;
|
||||
UpdateModel.Y2 = model.Y2;
|
||||
UpdateModel.X3 = model.X3;
|
||||
UpdateModel.Y3 = model.Y3;
|
||||
UpdateModel.X4 = model.X4;
|
||||
UpdateModel.Y4 = model.Y4;
|
||||
|
||||
UpdateZoneVisiable = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void CancelUpdateZone()
|
||||
{
|
||||
UpdateZoneVisiable = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task UpdateZone()
|
||||
{
|
||||
var selectedModel = Models.FirstOrDefault(e => e.Id == UpdateModel.Id);
|
||||
|
||||
if (selectedModel == null)
|
||||
{
|
||||
UpdateZoneVisiable = false;
|
||||
StateHasChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await (await Http.PutAsJsonAsync($"api/Zones", UpdateModel)).Content.ReadFromJsonAsync<MessageResult>();
|
||||
if (result is null)
|
||||
{
|
||||
Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
return;
|
||||
}
|
||||
else if (!result.IsSuccess)
|
||||
{
|
||||
Snackbar.Add(result.Message, Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
selectedModel.UpdateData(UpdateModel);
|
||||
UpdateZoneVisiable = false;
|
||||
Snackbar.Add("Cập nhật thành công", Severity.Success);
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Models.Changed -= StateHasChanged;
|
||||
Models.ActivedZoneChanged -= OnActivedZoneChanged;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
95
RobotNet.WebApp/Maps/Components/Editor/Zone/Zone.razor
Normal file
95
RobotNet.WebApp/Maps/Components/Editor/Zone/Zone.razor
Normal file
@@ -0,0 +1,95 @@
|
||||
@inject IJSRuntime JSRuntime
|
||||
@implements IDisposable
|
||||
|
||||
<polygon @ref="Ref" class="@(IsSetting ? "setting" : "")" fill="@Model.Fill" @ondblclick="OnDoubleClick" style="visibility: @(IsShow ? "visible" : "hidden")" />
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public ZoneModel Model { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<ZoneModel> DoubleClick { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool IsSetting { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool IsShow { get; set; }
|
||||
|
||||
[CascadingParameter]
|
||||
protected bool MapIsActive { get; set; }
|
||||
|
||||
private ElementReference Ref;
|
||||
private DotNetObjectReference<Zone> DotNetObj = null!;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
DotNetObj = DotNetObjectReference.Create(this);
|
||||
await JSRuntime.InvokeVoidAsync("AddEventListener", DotNetObj, Ref, "click", nameof(Click), false);
|
||||
await UpdateData();
|
||||
}
|
||||
|
||||
public override async Task SetParametersAsync(ParameterView parameters)
|
||||
{
|
||||
bool UpdateZone = false;
|
||||
if (parameters.TryGetValue(nameof(Model), out ZoneModel? model))
|
||||
{
|
||||
if (((Model?.Id ?? Guid.Empty) != (model?.Id ?? Guid.Empty)))
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.ControlNodePosittionChanged -= UpdateData;
|
||||
Model.TypeChanged -= StateHasChanged;
|
||||
Model.ActiveChanged -= ActiveChanged;
|
||||
}
|
||||
|
||||
if (model != null)
|
||||
{
|
||||
model.ControlNodePosittionChanged += UpdateData;
|
||||
model.TypeChanged += StateHasChanged;
|
||||
model.ActiveChanged += ActiveChanged;
|
||||
|
||||
UpdateZone = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await base.SetParametersAsync(parameters);
|
||||
if (UpdateZone) await UpdateData();
|
||||
}
|
||||
|
||||
private async Task OnDoubleClick()
|
||||
{
|
||||
await DoubleClick.InvokeAsync(Model);
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public void Click()
|
||||
{
|
||||
Model.Active();
|
||||
}
|
||||
|
||||
private async void ActiveChanged(ZoneModel zone, bool state) => await JSRuntime.InvokeVoidAsync(state ? "AddSelected" : "RemoveSelected", Ref);
|
||||
|
||||
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()
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.ControlNodePosittionChanged -= UpdateData;
|
||||
Model.ActiveChanged -= ActiveChanged;
|
||||
Model.TypeChanged -= StateHasChanged;
|
||||
}
|
||||
if (DotNetObj != null) DotNetObj.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
29
RobotNet.WebApp/Maps/Components/Editor/Zone/Zone.razor.css
Normal file
29
RobotNet.WebApp/Maps/Components/Editor/Zone/Zone.razor.css
Normal file
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
@inject IJSRuntime JSRuntime
|
||||
@implements IDisposable
|
||||
|
||||
|
||||
<g visibility="@Visibility">
|
||||
<circle @ref="Node1Ref" cx="@X1" cy="@Y1" />
|
||||
<text x="@X1" y="@(-Y1 - 0.15)">1</text>
|
||||
<circle @ref="Node2Ref" cx="@X2" cy="@Y2" />
|
||||
<text x="@X2" y="@(-Y2 - 0.15)">2</text>
|
||||
<circle @ref="Node3Ref" cx="@X3" cy="@Y3" />
|
||||
<text x="@X3" y="@(-Y3 - 0.15)">3</text>
|
||||
<circle @ref="Node4Ref" cx="@X4" cy="@Y4" />
|
||||
<text x="@X4" y="@(-Y4 - 0.15)">4</text>
|
||||
</g>
|
||||
|
||||
@code {
|
||||
private ElementReference Node1Ref;
|
||||
private ElementReference Node2Ref;
|
||||
private ElementReference Node3Ref;
|
||||
private ElementReference Node4Ref;
|
||||
private DotNetObjectReference<ZoneControlPoint> DotNetObj = null!;
|
||||
|
||||
private double X1;
|
||||
private double Y1;
|
||||
private double X2;
|
||||
private double Y2;
|
||||
private double X3;
|
||||
private double Y3;
|
||||
private double X4;
|
||||
private double Y4;
|
||||
private ZoneModel? Model;
|
||||
private string Visibility = "hidden";
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
DotNetObj = DotNetObjectReference.Create(this);
|
||||
await JSRuntime.InvokeVoidAsync("AddMouseDownEventListener", DotNetObj, Node1Ref, nameof(OnMouseDownNode1), false);
|
||||
await JSRuntime.InvokeVoidAsync("AddMouseDownEventListener", DotNetObj, Node2Ref, nameof(OnMouseDownNode2), false);
|
||||
await JSRuntime.InvokeVoidAsync("AddMouseDownEventListener", DotNetObj, Node3Ref, nameof(OnMouseDownNode3), false);
|
||||
await JSRuntime.InvokeVoidAsync("AddMouseDownEventListener", DotNetObj, Node4Ref, nameof(OnMouseDownNode4), false);
|
||||
}
|
||||
|
||||
public void SetControl(ZoneModel? model)
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.ControlNodePosittionChanged -= CaculateZoneAsync;
|
||||
}
|
||||
|
||||
Model = model;
|
||||
if (Model != null)
|
||||
{
|
||||
Visibility = "visible";
|
||||
CaculateZone();
|
||||
|
||||
Model.ControlNodePosittionChanged += CaculateZoneAsync;
|
||||
Visibility = "visible";
|
||||
}
|
||||
else
|
||||
{
|
||||
Visibility = "hidden";
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private Task CaculateZoneAsync()
|
||||
{
|
||||
CaculateZone();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void CaculateZone()
|
||||
{
|
||||
if (Model == null) return;
|
||||
|
||||
X1 = Model.X1;
|
||||
Y1 = Model.Y1;
|
||||
X2 = Model.X2;
|
||||
Y2 = Model.Y2;
|
||||
X3 = Model.X3;
|
||||
Y3 = Model.Y3;
|
||||
X4 = Model.X4;
|
||||
Y4 = Model.Y4;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public void OnMouseDownNode1(int button, bool altKey, bool ctrlKey, bool shiftKey)
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.ActiveNode = 1;
|
||||
}
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public void OnMouseDownNode2(int button, bool altKey, bool ctrlKey, bool shiftKey)
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.ActiveNode = 2;
|
||||
}
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public void OnMouseDownNode3(int button, bool altKey, bool ctrlKey, bool shiftKey)
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.ActiveNode = 3;
|
||||
}
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public void OnMouseDownNode4(int button, bool altKey, bool ctrlKey, bool shiftKey)
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.ActiveNode = 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.ControlNodePosittionChanged -= CaculateZoneAsync;
|
||||
Model = null;
|
||||
}
|
||||
if (DotNetObj is not null) DotNetObj.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
circle {
|
||||
cursor: default;
|
||||
fill: #FFBD33;
|
||||
stroke-width: 0;
|
||||
r: var(--node-r);
|
||||
}
|
||||
|
||||
circle:hover {
|
||||
stroke-width: 0.03px;
|
||||
cursor: pointer;
|
||||
stroke: green;
|
||||
}
|
||||
|
||||
circle:active {
|
||||
stroke-width: 0.03px;
|
||||
stroke: #FF5733;
|
||||
}
|
||||
|
||||
circle + text {
|
||||
transition-delay: 0.1s;
|
||||
font-size: 0.01em;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
text {
|
||||
dominant-baseline: middle;
|
||||
text-anchor: middle;
|
||||
fill: red;
|
||||
transform: scale(1, -1);
|
||||
user-select: none;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<polygon @ref="Ref" visibility="hidden" />
|
||||
<g @ref="PointRef" visibility="hidden">
|
||||
<circle cx="@X1" cy="@Y1" />
|
||||
<circle cx="@X2" cy="@Y2" />
|
||||
<circle cx="@X3" cy="@Y3" />
|
||||
<circle cx="@X4" cy="@Y4" />
|
||||
<circle cx="@X5" cy="@Y5" />
|
||||
</g>
|
||||
|
||||
@code {
|
||||
private ElementReference Ref;
|
||||
private ElementReference PointRef;
|
||||
|
||||
|
||||
public double X1 { get; private set; }
|
||||
public double Y1 { get; private set; }
|
||||
public double X2 { get; private set; }
|
||||
public double Y2 { get; private set; }
|
||||
public double X3 { get; private set; }
|
||||
public double Y3 { get; private set; }
|
||||
public double X4 { get; private set; }
|
||||
public double Y4 { get; private set; }
|
||||
public double X5 { get; private set; }
|
||||
public double Y5 { get; private set; }
|
||||
|
||||
public int Step { get; private set; }
|
||||
|
||||
public async Task CreateAsync(double x, double y)
|
||||
{
|
||||
if (Step == 0)
|
||||
{
|
||||
await Visible();
|
||||
Step = 1;
|
||||
X1 = x;
|
||||
Y1 = y;
|
||||
}
|
||||
else if (Step == 1) Step = 2;
|
||||
else if (Step == 2) Step = 3;
|
||||
else if (Step == 3)
|
||||
{
|
||||
X4 = x;
|
||||
Y4 = y;
|
||||
Step = 4;
|
||||
await CalculatorZone();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Update(double x, double y)
|
||||
{
|
||||
if (Step == 1)
|
||||
{
|
||||
X2 = x;
|
||||
Y2 = y;
|
||||
}
|
||||
else if (Step == 2)
|
||||
{
|
||||
X3 = x;
|
||||
Y3 = y;
|
||||
}
|
||||
else if (Step == 3)
|
||||
{
|
||||
X4 = x;
|
||||
Y4 = y;
|
||||
}
|
||||
await CalculatorZone();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task CalculatorZone()
|
||||
{
|
||||
var points = $"{X1},{Y1} {X2},{Y2}";
|
||||
if (Step == 2) points += $" {X3},{Y3}";
|
||||
if (Step == 3) points += $" {X3},{Y3} {X4},{Y4}";
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "points", points);
|
||||
}
|
||||
|
||||
public async Task Visible()
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "visibility", "visible");
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", PointRef, "visibility", "visible");
|
||||
}
|
||||
|
||||
public async Task Hidden()
|
||||
{
|
||||
Step = 0;
|
||||
X1 = X2 = X3 = X4 = Y1 = Y2 = Y3 = Y4 = 0;
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", Ref, "visibility", "hidden");
|
||||
await JSRuntime.InvokeVoidAsync("ElementSetAttribute", PointRef, "visibility", "hidden");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
polygon {
|
||||
fill: #c2c2a3;
|
||||
stroke: none;
|
||||
fill-opacity: 0.5;
|
||||
}
|
||||
|
||||
circle {
|
||||
fill: #FFBD33;
|
||||
stroke: #FF5733;
|
||||
stroke-width: 0;
|
||||
r: var(--node-r);
|
||||
}
|
||||
Reference in New Issue
Block a user