| 1 | using CascadeIDE.Cockpit.Composition; |
| 2 | using CascadeIDE.Cockpit.Composition.HostSurface; |
| 3 | using CascadeIDE.Cockpit.Composition.WorkspaceHealth; |
| 4 | using CascadeIDE.ViewModels; |
| 5 | |
| 6 | namespace CascadeIDE.Cockpit.Cds; |
| 7 | |
| 8 | /// <summary> |
| 9 | /// Сборка CDS-снимка (ADR 0036 п.2) из публичного состояния <see cref="MainWindowViewModel"/>; ортогонально |
| 10 | /// <see cref="UiLayoutSnapshot"/> (дерево UI, п.4) и композиторам каналов (<see cref="IdeHealthSurfaceCompositor"/>, <see cref="EicasMessageSorter"/>, п.3). |
| 11 | /// </summary> |
| 12 | public static class CockpitSurfaceSnapshotBuilder |
| 13 | { |
| 14 | public const string CurrentSchemaVersion = "0.3"; |
| 15 | |
| 16 | public static CockpitSurfaceState Build(MainWindowViewModel vm) |
| 17 | { |
| 18 | var surfaceKind = ToCdsSurfaceKind(vm.ActiveAttentionLayoutSurface); |
| 19 | var layout = CockpitPresentationLayoutPolicy.InvariantsFromPresentation(vm.PresentationParse); |
| 20 | var instruments = vm.MainWindowHostSurfaceInstruments |
| 21 | .Select(static (CockpitInstrumentDescriptor i) => new CockpitSurfaceInstrument(i.InstrumentId, i.SlotId, i.SchemaVersion)) |
| 22 | .ToArray(); |
| 23 | return new CockpitSurfaceState( |
| 24 | SchemaVersion: CurrentSchemaVersion, |
| 25 | UiMode: vm.UiMode, |
| 26 | PresentationEffectiveLine: vm.EffectivePresentationLine, |
| 27 | PresentationParseSuccess: vm.PresentationParse.IsSuccess, |
| 28 | Topology: new CockpitSurfaceTopology( |
| 29 | SurfaceKind: surfaceKind, |
| 30 | MfdHostWindowOpen: vm.IsMfdHostWindowShellOpen, |
| 31 | PfdHostWindowOpen: vm.IsPfdHostWindowShellOpen, |
| 32 | MfdColumnVisibleInMain: vm.IsMfdColumnVisible), |
| 33 | MfdShell: new CockpitSurfaceMfdShell( |
| 34 | CurrentPage: vm.CurrentMfdShellPage.ToString()), |
| 35 | Zones: new CockpitSurfaceZones( |
| 36 | PfdVisible: vm.IsPfdColumnVisible, |
| 37 | ForwardVisible: true, |
| 38 | MfdVisible: vm.IsMfdColumnVisible, |
| 39 | PfdRequiredByPresentation: layout.PfdRequiredByPresentation, |
| 40 | ForwardRequiredByPresentation: layout.ForwardRequiredByPresentation, |
| 41 | MfdRequiredByPresentation: layout.MfdRequiredByPresentation), |
| 42 | Instruments: instruments); |
| 43 | } |
| 44 | |
| 45 | internal static string ToCdsSurfaceKind(AttentionLayoutSurfaceKind kind) => |
| 46 | kind switch |
| 47 | { |
| 48 | AttentionLayoutSurfaceKind.MainWindowDockedGrid => MainWindowHostSurfaceIds.DockedGrid, |
| 49 | AttentionLayoutSurfaceKind.MainWindowPlusMfdHostTopLevel => MainWindowHostSurfaceIds.PlusMfdHostTopLevel, |
| 50 | AttentionLayoutSurfaceKind.MainWindowPlusPfdHostTopLevel => MainWindowHostSurfaceIds.PlusPfdHostTopLevel, |
| 51 | AttentionLayoutSurfaceKind.MainWindowPlusPfdMfdHostTopLevel => MainWindowHostSurfaceIds.PlusPfdMfdHostTopLevel, |
| 52 | _ => kind.ToString(), |
| 53 | }; |
| 54 | } |
| 55 | |