GrooveComputerVM.cs
4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using HHECS.BllModel;
using HHECS.RobotTool.Dto;
using HHECS.RobotTool.Dto.WeldMonitor;
using HHECS.RobotTool.Service;
using static FreeSql.Internal.GlobalFilter;
using MessageBox = HandyControl.Controls.MessageBox;
namespace HHECS.RobotTool.ViewModel
{
internal partial class GrooveComputerVM : ObservableObject
{
[ObservableProperty]
private RobotInputParameter inputParameter = new RobotInputParameter();
[ObservableProperty]
private RobotOutputParameter outputParameter = new RobotOutputParameter();
[ObservableProperty]
private string monitorSource = string.Empty;
[ObservableProperty]
private List<WeldMonitorDataGrid> weldMonitorDataGrids = new List<WeldMonitorDataGrid>();
/// <summary>
/// 唯一标识
/// </summary>
private readonly Guid currentIdentifier;
private readonly GrooveService _grooveService;
private readonly HttpService _httpService;
public GrooveComputerVM(GrooveService grooveService, HttpService httpService)
{
currentIdentifier = Guid.NewGuid();
MonitorSource = $"http://172.16.29.87:6002/index.html#/Home?key={currentIdentifier}&w=750&h=450";
_grooveService = grooveService;
_httpService = httpService;
Reset();
}
[RelayCommand]
private void Computer()
{
var result = _grooveService.GetComputedData(InputParameter);
if (!result.Success)
{
MessageBox.Error($"数据计算出现异常:{result.Msg}");
return;
}
var data = result.Data;
OutputParameter = data;
WeldMonitorDataGrids = data.LayerModels.SelectMany(layer => layer.ChannelModels.Select(channel => new WeldMonitorDataGrid
{
Layer = layer.CurrentLayer,
LayerHeight = layer.LayerHeight,
SwingFrequency = layer.WeldSwingFrequency,
LeftAndRightDwellTime = layer.LeftAndRightDwellTime,
Channel = channel.CurrentChannel,
StartingPoint = channel.StartingPoint,
EndingPoint = channel.EndingPoint,
WeldSpeed = Math.Round(channel.WeldSpeed, 3),
Amplitude = channel.WeldAmplitude,
})).ToList(); ;
Task.Run(() =>
{
var reloadResult = ReloadMonitor(data);
if (!reloadResult.Success)
{
MessageBox.Error($"监控页面刷新失败:{reloadResult.Msg}");
}
});
}
[RelayCommand]
private void Reset()
{
InputParameter = new RobotInputParameter
{
GrooveWidth = 37,//坡口宽度BC
GrooveDepth = 30,//坡口深度H
WeldLength = 1000,//焊缝长度AD
WeldingWire = 1.2f,//焊丝直径1.2mm D
OneWeldHeight = 4.5f,//一次焊接的高度4.5mm
WeldHeight = 0,//盖面后所需焊缝余高2mm
WeldWidth = 0,//盖面后单边所需增加余宽1.5mm
WireFeedingSpeed = 154,//送丝速度固定154mm/s
OneLayerWireFeedingSpeed = 124,//一层打底速度
};
OutputParameter = new RobotOutputParameter();
}
private BllResult ReloadMonitor(RobotOutputParameter data)
{
try
{
var monitor = new WeldMonitorDto
{
Key = currentIdentifier,
Height = data.LayerModels.Sum(x => x.LayerHeight),
Data = data.LayerModels.Select(l => new LayerItem
{
Layer = l.CurrentLayer,
Height = l.LayerHeight,
Done = l.ChannelModels.Select(c => new DoneItem
{
State = 0,
Position = $"Y:{c.StartingPoint.Y},Z:{c.StartingPoint.Z}"
}).ToList()
}).ToList(),
};
return _httpService.SetWeldMonitorData(monitor);
}
catch (Exception ex)
{
return BllResultFactory.Error(ex.Message);
}
}
}
}