SSPC-Tester/SSPCTester.UI/ViewModels/TestHostViewModel.cs
2026-07-13 03:51:13 +08:00

58 lines
1.8 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
[ObservableProperty] private int _selectedTabIndex;
private bool _isViewActive;
public ExperimentConsoleViewModel Console { get; }
public BasicTestViewModel Basic { get; }
public CurveTestViewModel Curve { get; }
public PowerTestViewModel Power { get; }
public ProtectViewModel Protect { get; }
public TestHostViewModel(ExperimentConsoleViewModel console, BasicTestViewModel basic, CurveTestViewModel curve, PowerTestViewModel power, ProtectViewModel protect)
{
Console = console;
Basic = basic; Curve = curve; Power = power; Protect = protect;
}
partial void OnSelectedTabIndexChanged(int value) => UpdateConsoleActive();
public void SetViewActive(bool active)
{
_isViewActive = active;
UpdateConsoleActive();
}
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);
Protect.AttachSession(s);
}
private void UpdateConsoleActive()
{
// 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);
}
}