Files
HC_APTBS/ViewModels/PhaseCardViewModel.cs
LucianoDev 37d099cdbd feat: add Ford VP44 unlock progress dialog, K-Line fast unlock, localization, safety dialogs, and settings
Unlock progress UI:
- UnlockProgressDialog with dark-themed progress ring, phase indicator, elapsed
  time, and cancel/close buttons (non-modal, draggable borderless window)
- UnlockProgressViewModel with event-driven progress tracking via IUnlockService
- Triggers on pump selection (manual or K-Line auto-detect), not test start

UnlockService rewrite:
- Persistent CAN senders that outlive the unlock sequence (StopSenders on pump change)
- Concurrent K-Line fast unlock: awaits session Connected, sends RAM timer shortcut
  ({02 88 02 03 A8 01 00}), verifies via CAN TestUnlock before skipping wait
- Fix Type 1 verification (Value == 0 means unlocked, was inverted)

K-Line fast unlock support:
- IKwpService.TryFastUnlockAsync / KwpService implementation

Additional features:
- ILocalizationService with ES/EN resource dictionaries and runtime switching
- Safety dialogs: VoltageWarning, OilPumpConfirm, RpmSafetyWarning
- SettingsDialog for app configuration
- BenchService enhancements, ConfigurationService improvements, PDF report updates
- All UI strings localized via DynamicResource

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:22:48 +02:00

111 lines
5.5 KiB
C#

using System;
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
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);
}
// ── 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();
}
}
}