Forge
csharpdeeb25a2
1using System.Collections.Immutable;
2using CascadeIDE.Contracts.Experimental;
3
4namespace CascadeIDE.Features.UiChrome;
5
6
7
8/// <summary>
9
10/// Канонические строковые id для TOML и API (нижний регистр, латиница). ADR 0021:
11
12/// три пространственных якоря (<see cref="Forward"/>, <see cref="Pfd"/>, <see cref="Mfd"/>),
13
14/// <see cref="Eicas"/> — <strong>канал</strong> оповещений (не четвёртый якорь-колонка), <see cref="Hud"/> — слой на лобовом.
15
16/// </summary>
17
18public static class AttentionZoneIds
19
20{
21
22 public const string Forward = AttentionZoneCanonicalIds.Forward;
23
24 public const string Pfd = AttentionZoneCanonicalIds.Pfd;
25
26 public const string Mfd = AttentionZoneCanonicalIds.Mfd;
27
28 public const string Eicas = AttentionZoneCanonicalIds.Eicas;
29
30 public const string Hud = AttentionZoneCanonicalIds.Hud;
31
32
33
34 /// <summary>Все допустимые id в стабильном порядке (для валидации и тестов).</summary>
35
36 public static ImmutableArray<string> All { get; } =
37
38 ImmutableArray.Create(Forward, Pfd, Mfd, Eicas, Hud);
39
40}
41
42
43
44/// <summary>
45
46/// Роль в модели внимания ADR 0021 (соответствует <see cref="AttentionZoneIds"/>).
47
48/// «Зона» в продуктовом смысле — про три якоря; <see cref="Eicas"/> — канал, не зона-якорь.
49
50/// </summary>
51
52public enum AttentionZone
53
54{
55
56 /// <summary>Лобовое (forward): редактор.</summary>
57
58 Forward,
59
60
61
62 /// <summary>PFD: контекст workspace.</summary>
63
64 Pfd,
65
66
67
68 /// <summary>MFD: вторичные инструменты.</summary>
69
70 Mfd,
71
72
73
74 /// <summary>EICAS/CAS: канал оповещений W/C/A — не четвёртый якорь рядом с PFD/MFD (ADR §5).</summary>
75
76 Eicas,
77
78
79
80 /// <summary>HUD: слой внутри лобового.</summary>
81
82 Hud,
83
84}
85
86
87
88/// <summary>Разбор и классификация <see cref="AttentionZone"/>.</summary>
89
90public static class AttentionZoneExtensions
91
92{
93
94 /// <summary>Сериализация в канонический id (строго совпадает с <see cref="AttentionZoneIds"/>).</summary>
95
96 public static string ToCanonicalId(this AttentionZone zone) =>
97
98 zone switch
99
100 {
101
102 AttentionZone.Forward => AttentionZoneIds.Forward,
103
104 AttentionZone.Pfd => AttentionZoneIds.Pfd,
105
106 AttentionZone.Mfd => AttentionZoneIds.Mfd,
107
108 AttentionZone.Eicas => AttentionZoneIds.Eicas,
109
110 AttentionZone.Hud => AttentionZoneIds.Hud,
111
112 _ => throw new ArgumentOutOfRangeException(nameof(zone), zone, null),
113
114 };
115
116
117
118 /// <summary>
119
120 /// Разбор канонической строки. Совпадение по <see cref="StringComparison.Ordinal"/> (как в данных ADR).
121
122 /// </summary>
123
124 public static bool TryParseCanonicalId(string? value, out AttentionZone zone)
125
126 {
127
128 zone = default;
129
130 if (string.IsNullOrEmpty(value))
131
132 return false;
133
134
135
136 if (value == AttentionZoneIds.Forward)
137
138 {
139
140 zone = AttentionZone.Forward;
141
142 return true;
143
144 }
145
146
147
148 if (value == AttentionZoneIds.Pfd)
149
150 {
151
152 zone = AttentionZone.Pfd;
153
154 return true;
155
156 }
157
158
159
160 if (value == AttentionZoneIds.Mfd)
161
162 {
163
164 zone = AttentionZone.Mfd;
165
166 return true;
167
168 }
169
170
171
172 if (value == AttentionZoneIds.Eicas)
173
174 {
175
176 zone = AttentionZone.Eicas;
177
178 return true;
179
180 }
181
182
183
184 if (value == AttentionZoneIds.Hud)
185
186 {
187
188 zone = AttentionZone.Hud;
189
190 return true;
191
192 }
193
194
195
196 return false;
197
198 }
199
200
201
202 /// <summary>Три пространственных якоря: лобовое, PFD, MFD.</summary>
203
204 public static bool IsSpatialAnchor(this AttentionZone zone) =>
205
206 zone is AttentionZone.Forward or AttentionZone.Pfd or AttentionZone.Mfd;
207
208
209
210 /// <summary>Канал оповещений EICAS/CAS.</summary>
211
212 public static bool IsAlertingChannel(this AttentionZone zone) => zone == AttentionZone.Eicas;
213
214
215
216 /// <summary>Слой HUD только на лобовом (редактор).</summary>
217
218 public static bool IsHudLayer(this AttentionZone zone) => zone == AttentionZone.Hud;
219
220}
221
222
223
View only · write via MCP/CIDE