Files
HC_APTBS/ViewModels/PhaseCardViewModel.cs
LucianoDev 827b811b39 feat: developer tools page, auto-test orchestrator, BIP display, tests redesign
Bundles several feature streams that have been iterating on the working tree:

- Developer Tools page (Debug-only via DEVELOPER_TOOLS symbol): hosts the
  identification card, manual KWP write + transaction log, ROM/EEPROM dump
  card with progress banner and completion message, persisted custom-commands
  library, persisted EEPROM passwords library. New service primitives:
  IKwpService.SendRawCustomAsync / ReadEepromAsync / ReadRomEepromAsync.
  Persistence mirrors the Clients XML pattern in two new files
  (custom_commands.xml, eeprom_passwords.xml).
- Auto-test orchestrator (IAutoTestOrchestrator + AutoTestState): linear
  K-Line read -> unlock -> bench-on -> test sequence with snackbar UI and
  progress dialog VM, gated on dashboard alarms.
- BIP-STATUS display: BipDisplayViewModel + BipDisplayView, RAM read at
  0x0106 via IKwpService.ReadBipStatusAsync; status definitions in
  BipStatusDefinition.
- Tests page redesign: TestSectionCard + PhaseTileView replacing the old
  TestPlanView/TestRunningView/TestDoneView/TestPreconditionsView/
  TestSectionView controls and their VMs.
- Pump command sliders: Fluent thick-track style with overhang thumb,
  click-anywhere-and-drag, mouse-wheel adjustment.
- Window startup: app.manifest declares PerMonitorV2 DPI awareness,
  MainWindow installs a WM_GETMINMAXINFO hook in OnSourceInitialized and
  maximizes there (after the hook is in place) so the app fits the work
  area exactly on any display configuration.
- Misc: PercentToPixelsConverter, seed_aliases.py one-shot pump-alias
  importer, tools/Import-BipStatus.ps1, kline_eeprom_spec.md and
  dump-functions reference docs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-07 13:59:50 +02:00

118 lines
5.9 KiB
C#

using System;
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using HC_APTBS.Models;
using HC_APTBS.Services;
namespace HC_APTBS.ViewModels
{
/// <summary>
/// Represents a single phase card within a test section.
/// Displays the phase name, enable/disable toggle, operation values,
/// and graphic result indicators.
/// </summary>
public sealed partial class PhaseCardViewModel : ObservableObject
{
private readonly ILocalizationService _loc;
/// <summary>Initialises a new phase card with a localization service.</summary>
public PhaseCardViewModel(ILocalizationService loc) => _loc = loc;
// ── Identity ──────────────────────────────────────────────────────────────
/// <summary>Display name of the phase (e.g. "1 - S_001").</summary>
[ObservableProperty] private string _name = string.Empty;
/// <summary>True when failure in this phase halts the entire test sequence.</summary>
[ObservableProperty] private bool _isCritical;
// ── Enable/disable ────────────────────────────────────────────────────────
/// <summary>
/// Whether this phase is included in the test run.
/// Writing this property also updates the underlying <see cref="PhaseDefinition.Enabled"/>
/// and notifies the parent <see cref="TestSectionViewModel"/> to recalculate its
/// <c>AllPhasesChecked</c> state.
/// </summary>
[ObservableProperty] private bool _isEnabled = true;
// ── Execution state ───────────────────────────────────────────────────────
/// <summary>True while this phase is actively executing.</summary>
[ObservableProperty] private bool _isActive;
/// <summary>True when the phase completed and passed all criteria.</summary>
[ObservableProperty] private bool _isPassed;
/// <summary>True when the phase completed but failed one or more criteria.</summary>
[ObservableProperty] private bool _isFailed;
/// <summary>Short result label shown in the card (e.g. "PASS", "FAIL", "-").</summary>
[ObservableProperty] private string _resultText = string.Empty;
// ── Operation values visibility ───────────────────────────────────────────
/// <summary>
/// Controls visibility of the operation values section (RPM, ME, FBKW).
/// Bound from <see cref="TestPanelViewModel.ShowOperationValues"/>.
/// </summary>
[ObservableProperty] private bool _showOperationValues;
// ── Collections ───────────────────────────────────────────────────────────
/// <summary>Send parameters displayed in the card (RPM, ME, FBKW, etc.).</summary>
public ObservableCollection<OperationValueViewModel> OperationValues { get; } = new();
/// <summary>Readiness conditions displayed in the card (temperature, etc.).</summary>
public ObservableCollection<OperationValueViewModel> ReadyValues { get; } = new();
/// <summary>Graphic result indicators, one per receive parameter.</summary>
public ObservableCollection<GraphicIndicatorViewModel> ResultIndicators { get; } = new();
// ── Back-references ───────────────────────────────────────────────────────
/// <summary>Back-reference to the model for writing enabled state changes.</summary>
internal PhaseDefinition? Source { get; set; }
/// <summary>
/// Callback invoked when <see cref="IsEnabled"/> changes, so the parent
/// <see cref="TestSectionViewModel"/> can recalculate <c>AllPhasesChecked</c>.
/// </summary>
internal Action<PhaseCardViewModel>? EnabledChanged { get; set; }
// ── Change handlers ───────────────────────────────────────────────────────
partial void OnIsEnabledChanged(bool value)
{
// Write back to the model.
if (Source != null)
Source.Enabled = value;
ResultText = value ? "\u2013" : _loc.GetString("Common.Disabled");
// Notify parent.
EnabledChanged?.Invoke(this);
}
// ── Commands ──────────────────────────────────────────────────────────────
/// <summary>Inverts <see cref="IsEnabled"/>. Bound to the card's click gesture.</summary>
[RelayCommand]
private void ToggleEnabled() => IsEnabled = !IsEnabled;
// ── Public API ────────────────────────────────────────────────────────────
/// <summary>Resets execution state for a new test run.</summary>
public void Reset()
{
IsActive = false;
IsPassed = false;
IsFailed = false;
ResultText = IsEnabled ? "\u2013" : _loc.GetString("Common.Disabled");
foreach (var indicator in ResultIndicators)
indicator.Reset();
}
}
}