Files
HC_APTBS/ViewModels/DashboardAlarmsViewModel.cs
LucianoDev 0280a2fad1 feat: page-based navigation shell + Tests page wizard
Replace the monolithic MainWindow with a SelectedPage-driven shell
(Dashboard / Pump / Bench / Tests / Results / Settings). The Tests
page gets the Plan -> Preconditions -> Running -> Done wizard from
ui-structure.md \u00a74, backed by a 7-item precondition gate and
shared sub-views (PhaseCardView / TestSectionView / GraphicIndicatorView)
extracted from the now-deleted monolithic TestPanelView.

New VMs / views:
- Tests wizard: TestPreconditions, PhaseCard, GraphicIndicator,
  TestSection, TestPlan, TestRunning, TestDone
- Dashboard panels: DashboardConnection, DashboardReadings,
  DashboardAlarms, InterlockBanner, ResultHistory
- Pump / bench panels: PumpIdentificationPanel, PumpLiveData,
  UnlockPanel, BenchDriveControl, BenchReadings, RelayBank,
  TemperatureControl, DtcList, AuthGate
- Dialogs: generic ConfirmDialog, UserManageDialog, UserPromptDialog

Supporting changes:
- IsOilPumpOn exposed on MainViewModel for precondition evaluation
- RequiresAuth added to TestDefinition (XML round-trip)
- BipStatusDefinition + CompletedTestRun models
- ~35 new Test.* localization keys (en + es)
- Settings moved from modal dialog to full page
- Pause / Retry / Skip stubs in TestRunningView; full spec in
  docs/gap-test-running-controls.md for follow-up implementation
- docs/ui-structure.md captures the wizard design

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-18 13:11:34 +02:00

63 lines
2.2 KiB
C#

using System.Collections.Generic;
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using HC_APTBS.Models;
namespace HC_APTBS.ViewModels
{
/// <summary>
/// Dashboard-side alarm aggregator.
///
/// <para>Keeps an <see cref="ActiveAlarms"/> collection in sync with the
/// bench <c>Alarms</c> CAN bitmask, resolving each set bit against the
/// alarm definitions loaded from <c>alarms.xml</c>. The consumer (MainViewModel's
/// refresh tick) calls <see cref="Update"/> every refresh interval.</para>
/// </summary>
public sealed partial class DashboardAlarmsViewModel : ObservableObject
{
private readonly IReadOnlyList<Alarm> _definitions;
private int _lastMask = -1;
/// <summary>List of currently asserted alarms.</summary>
public ObservableCollection<Alarm> ActiveAlarms { get; } = new();
/// <summary>True when no alarms are active — used to show the "System OK" banner.</summary>
[ObservableProperty] private bool _isClear = true;
/// <summary>True when at least one active alarm is flagged critical.</summary>
[ObservableProperty] private bool _hasCritical;
public DashboardAlarmsViewModel(IReadOnlyList<Alarm> definitions)
{
_definitions = definitions;
}
/// <summary>
/// Rebuilds <see cref="ActiveAlarms"/> from the current bench alarm bitmask.
/// Cheap no-op when the mask has not changed since the last call.
/// Must be invoked on the UI thread.
/// </summary>
public void Update(int mask)
{
if (mask == _lastMask) return;
_lastMask = mask;
ActiveAlarms.Clear();
bool anyCritical = false;
foreach (var def in _definitions)
{
bool bitSet = (mask & (1 << def.Bit)) != 0;
def.IsActive = bitSet;
if (!bitSet) continue;
ActiveAlarms.Add(def);
if (def.IsCritical) anyCritical = true;
}
IsClear = ActiveAlarms.Count == 0;
HasCritical = anyCritical;
}
}
}