| 1 | #nullable enable |
| 2 | |
| 3 | using CascadeIDE.Models; |
| 4 | |
| 5 | namespace CascadeIDE.Cockpit.Composition.HostSurface; |
| 6 | |
| 7 | /// <summary>Размещение полосы <see cref="CockpitStandardInstrumentIds.WorkspaceBackgroundStatusV1"/> по зонам (ADR 0050 extension).</summary> |
| 8 | public static class InstrumentStatusStripPlacement |
| 9 | { |
| 10 | /// <summary>Ключ отсутствует в <c>[display.instruments]</c> — полоса включена (совместимость с <c>show_background_status_on_pfd</c>).</summary> |
| 11 | public static bool IsZoneEnabled(DisplaySettings? display, string stripSlotKey) |
| 12 | { |
| 13 | var routing = display?.Instruments; |
| 14 | if (routing is null || routing.Count == 0) |
| 15 | return true; |
| 16 | |
| 17 | if (!TryGetRoutingValue(routing, stripSlotKey, out var raw)) |
| 18 | return true; |
| 19 | |
| 20 | if (!InstrumentStatusStripRouting.TryParse(raw, out var show, out _)) |
| 21 | return false; |
| 22 | |
| 23 | return show; |
| 24 | } |
| 25 | |
| 26 | public static bool IsVisibleOnPfd(DisplaySettings? display, bool masterEnabled) => |
| 27 | masterEnabled && IsZoneEnabled(display, InstrumentRoutingSlotKeys.PfdStatusStrip); |
| 28 | |
| 29 | public static bool IsVisibleOnForward(DisplaySettings? display, bool masterEnabled) => |
| 30 | masterEnabled && IsZoneEnabled(display, InstrumentRoutingSlotKeys.ForwardStatusStrip); |
| 31 | |
| 32 | private static bool TryGetRoutingValue( |
| 33 | IReadOnlyDictionary<string, string> routing, |
| 34 | string stripSlotKey, |
| 35 | out string raw) |
| 36 | { |
| 37 | foreach (var kv in routing) |
| 38 | { |
| 39 | if (!kv.Key.Equals(stripSlotKey, StringComparison.OrdinalIgnoreCase)) |
| 40 | continue; |
| 41 | |
| 42 | raw = kv.Value?.Trim() ?? ""; |
| 43 | return true; |
| 44 | } |
| 45 | |
| 46 | raw = ""; |
| 47 | return false; |
| 48 | } |
| 49 | } |
| 50 | |