2026-06-30 12:10:29 +08:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
|
using SSPCTester.Logic.Models;
|
|
|
|
|
|
|
|
|
|
|
|
namespace SSPCTester.UI.ViewModels;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>测试主界面(TabControl 容器)。</summary>
|
|
|
|
|
|
public partial class TestHostViewModel : ObservableObject
|
|
|
|
|
|
{
|
|
|
|
|
|
[ObservableProperty] private Project? _project;
|
|
|
|
|
|
[ObservableProperty] private TestSessionViewModel? _session;
|
2026-07-12 12:07:41 +08:00
|
|
|
|
[ObservableProperty] private int _selectedTabIndex;
|
|
|
|
|
|
private bool _isViewActive;
|
2026-06-30 12:10:29 +08:00
|
|
|
|
|
2026-07-12 12:07:41 +08:00
|
|
|
|
public ExperimentConsoleViewModel Console { get; }
|
2026-06-30 12:10:29 +08:00
|
|
|
|
public BasicTestViewModel Basic { get; }
|
|
|
|
|
|
public CurveTestViewModel Curve { get; }
|
|
|
|
|
|
public PowerTestViewModel Power { get; }
|
|
|
|
|
|
public ProtectViewModel Protect { get; }
|
|
|
|
|
|
|
2026-07-12 12:07:41 +08:00
|
|
|
|
public TestHostViewModel(ExperimentConsoleViewModel console, BasicTestViewModel basic, CurveTestViewModel curve, PowerTestViewModel power, ProtectViewModel protect)
|
2026-06-30 12:10:29 +08:00
|
|
|
|
{
|
2026-07-12 12:07:41 +08:00
|
|
|
|
Console = console;
|
2026-06-30 12:10:29 +08:00
|
|
|
|
Basic = basic; Curve = curve; Power = power; Protect = protect;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-12 12:07:41 +08:00
|
|
|
|
partial void OnSelectedTabIndexChanged(int value) => UpdateConsoleActive();
|
|
|
|
|
|
|
|
|
|
|
|
public void SetViewActive(bool active)
|
|
|
|
|
|
{
|
|
|
|
|
|
_isViewActive = active;
|
|
|
|
|
|
UpdateConsoleActive();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-30 12:10:29 +08:00
|
|
|
|
public void SetProject(Project p)
|
|
|
|
|
|
{
|
|
|
|
|
|
Project = p;
|
|
|
|
|
|
Basic.SetProject(p);
|
|
|
|
|
|
Curve.SetProject(p);
|
|
|
|
|
|
Power.SetProject(p);
|
|
|
|
|
|
Protect.SetProject(p);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AttachSession(TestSessionViewModel s)
|
|
|
|
|
|
{
|
|
|
|
|
|
Session = s;
|
|
|
|
|
|
Curve.AttachSession(s);
|
2026-07-02 21:38:25 +08:00
|
|
|
|
Protect.AttachSession(s);
|
2026-06-30 12:10:29 +08:00
|
|
|
|
}
|
2026-07-12 12:07:41 +08:00
|
|
|
|
|
|
|
|
|
|
private void UpdateConsoleActive()
|
|
|
|
|
|
{
|
2026-07-13 03:51:13 +08:00
|
|
|
|
// Identify this host when acquiring/releasing console polling. During a
|
|
|
|
|
|
// project switch WPF can load the new host before unloading the old one;
|
|
|
|
|
|
// the old host must not stop the shared console on behalf of the new host.
|
|
|
|
|
|
Console.SetActive(this, _isViewActive && SelectedTabIndex == 0);
|
2026-07-12 12:07:41 +08:00
|
|
|
|
}
|
2026-06-30 12:10:29 +08:00
|
|
|
|
}
|