61 lines
2.2 KiB
C#
61 lines
2.2 KiB
C#
|
|
using System.Collections.ObjectModel;
|
|||
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|||
|
|
using CommunityToolkit.Mvvm.Input;
|
|||
|
|
using SSPCTester.Logic.Models;
|
|||
|
|
using SSPCTester.UI.Services;
|
|||
|
|
|
|||
|
|
namespace SSPCTester.UI.ViewModels;
|
|||
|
|
|
|||
|
|
/// <summary>保护功能页 VM(框架占位)。</summary>
|
|||
|
|
public partial class ProtectViewModel : ObservableObject
|
|||
|
|
{
|
|||
|
|
private readonly UiLogSink _log;
|
|||
|
|
public ObservableCollection<ProtectRow> Rows { get; } = new();
|
|||
|
|
|
|||
|
|
[ObservableProperty] private Project? _project;
|
|||
|
|
[ObservableProperty] private bool _enableTrip = true;
|
|||
|
|
[ObservableProperty] private bool _enableShort = true;
|
|||
|
|
[ObservableProperty] private bool _enableOverTemp = true;
|
|||
|
|
[ObservableProperty] private bool _enableOverVolt = true;
|
|||
|
|
[ObservableProperty] private bool _enableUnderVolt = true;
|
|||
|
|
[ObservableProperty] private bool _enableLimit = true;
|
|||
|
|
|
|||
|
|
[ObservableProperty] private double _overVoltThreshold = 32;
|
|||
|
|
[ObservableProperty] private double _underVoltThreshold = 22;
|
|||
|
|
[ObservableProperty] private double _overCurrentThreshold = 1.2;
|
|||
|
|
[ObservableProperty] private double _overTempThreshold = 85;
|
|||
|
|
|
|||
|
|
public ProtectViewModel(UiLogSink log) { _log = log; }
|
|||
|
|
|
|||
|
|
public void SetProject(Project p)
|
|||
|
|
{
|
|||
|
|
Project = p;
|
|||
|
|
Rows.Clear();
|
|||
|
|
foreach (var r in p.ProtectResults) Rows.Add(r);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[RelayCommand]
|
|||
|
|
private void RunDemo()
|
|||
|
|
{
|
|||
|
|
if (Project == null) return;
|
|||
|
|
Project.ProtectResults.Clear();
|
|||
|
|
Rows.Clear();
|
|||
|
|
var items = new (string, string)[]
|
|||
|
|
{
|
|||
|
|
("跳闸", "1.5x额定电流"),
|
|||
|
|
("短路", "输出短路"),
|
|||
|
|
("过温", $">={OverTempThreshold} ℃"),
|
|||
|
|
("过压", $">={OverVoltThreshold} V"),
|
|||
|
|
("欠压", $"<={UnderVoltThreshold} V"),
|
|||
|
|
("限流", $">={OverCurrentThreshold} A"),
|
|||
|
|
};
|
|||
|
|
for (int i = 0; i < items.Length; i++)
|
|||
|
|
{
|
|||
|
|
var r = new ProtectRow { ProtectType = items[i].Item1, Trigger = items[i].Item2, TripTimeMs = 2 + i * 0.3, Status = TestStatus.Pass };
|
|||
|
|
Project.ProtectResults.Add(r);
|
|||
|
|
Rows.Add(r);
|
|||
|
|
}
|
|||
|
|
_log.Add(UiLogLevel.Warning, "保护功能模块仅生成框架演示数据。");
|
|||
|
|
}
|
|||
|
|
}
|