Repository navigation
Expand file tree
/
Copy pathIoListTestingWindow.P0BenchUx.cs
More file actions
204 lines (171 loc) · 8.14 KB
/
Copy pathIoListTestingWindow.P0BenchUx.cs
File metadata and controls
204 lines (171 loc) · 8.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using ArIED61850Tester.Models.IoTesting;
namespace ArIED61850Tester;
/// <summary>
/// Bench-facing FAT UX corrections. FAT deliberately disables ToolTips so hover creation
/// cannot compete with report-backed updates on relay benches; Engineering ToolTips live in
/// MainWindow and are untouched. The FAT action strip is kept in one compact adaptive row.
/// </summary>
public partial class IoListTestingWindow
{
private static readonly bool P0BenchUxClassHandlerRegistered = RegisterP0BenchUxClassHandler();
private bool _p0BenchUxInstalled;
private WrapPanel? _p0PrimaryHeaderActions;
private WrapPanel? _p0SecondaryHeaderActions;
private static bool RegisterP0BenchUxClassHandler()
{
EventManager.RegisterClassHandler(
typeof(IoListTestingWindow),
FrameworkElement.LoadedEvent,
new RoutedEventHandler(P0BenchUxLoaded));
return true;
}
private static void P0BenchUxLoaded(object sender, RoutedEventArgs e)
{
if (sender is not IoListTestingWindow window || window._p0BenchUxInstalled)
return;
window._p0BenchUxInstalled = true;
window.Closed += window.P0BenchUxClosed;
// FAT-only. Do not touch MainWindow/Engineering ToolTips.
ToolTipService.SetIsEnabled(window, false);
// Final FAT V2 schema is installed before first visible render.
window.InstallFatV2WorkspaceUx();
window.ApplyP0BenchUx();
}
private void P0BenchUxClosed(object? sender, EventArgs e)
=> Closed -= P0BenchUxClosed;
private void ApplyP0BenchUx()
{
ConfigureP0StableFatColumns();
ConfigureP0AdaptiveHeaderActions();
ConfigureP2CompactHeader();
}
private void ConfigureP0StableFatColumns()
{
if (_fatSignalsGrid == null)
return;
// Removed signals remain in the immutable project/evidence model so they can be
// restored from the dedicated Removed Signals UX, but they are not active FAT rows.
// Collapse them at the row-container layer so a removed point consumes no grid space
// and reappears automatically as soon as IsIncludedInFat becomes true again.
var activeFatRowStyle = new Style(typeof(DataGridRow), _fatSignalsGrid.RowStyle);
activeFatRowStyle.Triggers.Add(new DataTrigger
{
Binding = new Binding(nameof(IoTestPointPlan.IsIncludedInFat)),
Value = false,
Setters =
{
new Setter(UIElement.VisibilityProperty, Visibility.Collapsed)
}
});
_fatSignalsGrid.RowStyle = activeFatRowStyle;
foreach (var column in _fatSignalsGrid.Columns.OfType<DataGridTemplateColumn>())
{
var header = column.Header?.ToString()?.Trim() ?? string.Empty;
if (header.Equals("LIVE VALUE", StringComparison.OrdinalIgnoreCase))
{
column.CellTemplate = BuildP0LiveValueTemplate();
continue;
}
if (header.Equals("VALUE 1", StringComparison.OrdinalIgnoreCase))
{
column.CellTemplate = BuildP0EvidenceValueTemplate(FatValueSlot.Value1);
continue;
}
if (header.Equals("VALUE 2", StringComparison.OrdinalIgnoreCase))
column.CellTemplate = BuildP0EvidenceValueTemplate(FatValueSlot.Value2);
}
}
private static DataTemplate BuildP0LiveValueTemplate()
{
var panel = new FrameworkElementFactory(typeof(StackPanel));
panel.SetValue(StackPanel.OrientationProperty, Orientation.Vertical);
var value = new FrameworkElementFactory(typeof(TextBlock));
value.SetBinding(TextBlock.TextProperty, new Binding("Runtime.CurrentValue")
{
Converter = P0FatCanonicalValueConverter.Instance,
Mode = BindingMode.OneWay
});
value.SetValue(TextBlock.FontWeightProperty, FontWeights.SemiBold);
value.SetValue(TextBlock.FontSizeProperty, 12.0);
value.SetValue(TextBlock.ForegroundProperty, new SolidColorBrush(Color.FromRgb(30, 60, 100)));
panel.AppendChild(value);
var quality = new FrameworkElementFactory(typeof(TextBlock));
quality.SetBinding(TextBlock.TextProperty, new Binding("Runtime.CurrentQuality") { Mode = BindingMode.OneWay });
quality.SetValue(TextBlock.FontSizeProperty, 9.5);
quality.SetValue(TextBlock.ForegroundProperty, new SolidColorBrush(Color.FromRgb(105, 121, 143)));
panel.AppendChild(quality);
return new DataTemplate { VisualTree = panel };
}
private static DataTemplate BuildP0EvidenceValueTemplate(FatValueSlot slot)
{
var isValue1 = slot == FatValueSlot.Value1;
var panel = new FrameworkElementFactory(typeof(StackPanel));
panel.SetValue(StackPanel.OrientationProperty, Orientation.Vertical);
panel.SetValue(FrameworkElement.MarginProperty, new Thickness(0, 1, 0, 1));
var value = new FrameworkElementFactory(typeof(TextBlock));
value.SetBinding(TextBlock.TextProperty, new Binding(isValue1
? nameof(IoTestPointPlan.Value1Text)
: nameof(IoTestPointPlan.Value2Text))
{
Converter = P0FatCanonicalValueConverter.Instance,
Mode = BindingMode.OneWay
});
value.SetValue(TextBlock.FontWeightProperty, FontWeights.SemiBold);
value.SetValue(TextBlock.FontSizeProperty, 11.4);
value.SetValue(TextBlock.TextTrimmingProperty, TextTrimming.CharacterEllipsis);
panel.AppendChild(value);
var timestamp = new FrameworkElementFactory(typeof(TextBlock));
timestamp.SetBinding(TextBlock.TextProperty, new Binding(isValue1
? nameof(IoTestPointPlan.Value1RelayTimestampText)
: nameof(IoTestPointPlan.Value2RelayTimestampText)));
timestamp.SetValue(TextBlock.FontSizeProperty, 8.8);
timestamp.SetValue(TextBlock.FontFamilyProperty, new FontFamily("Cascadia Mono, Consolas"));
timestamp.SetValue(TextBlock.ForegroundProperty, new SolidColorBrush(Color.FromRgb(112, 126, 145)));
panel.AppendChild(timestamp);
return new DataTemplate { VisualTree = panel };
}
private void ConfigureP0AdaptiveHeaderActions()
{
if (_p0PrimaryHeaderActions != null || WorkspacePreviewToggle.Parent is not StackPanel actionPanel)
return;
var children = actionPanel.Children.Cast<UIElement>().ToArray();
if (children.Length == 0)
return;
actionPanel.Children.Clear();
actionPanel.Orientation = Orientation.Vertical;
actionPanel.HorizontalAlignment = HorizontalAlignment.Right;
actionPanel.VerticalAlignment = VerticalAlignment.Center;
_p0PrimaryHeaderActions = new WrapPanel
{
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0)
};
// Retained as an empty compatibility panel because P2 helpers reference it. All FAT
// actions/status now share the one visible compact row instead of forcing a second row.
_p0SecondaryHeaderActions = new WrapPanel
{
Orientation = Orientation.Horizontal,
Visibility = Visibility.Collapsed,
Margin = new Thickness(0)
};
foreach (var child in children)
_p0PrimaryHeaderActions.Children.Add(child);
actionPanel.Children.Add(_p0PrimaryHeaderActions);
}
private bool IsP0SecondaryHeaderAction(UIElement element) => false;
}
public sealed class P0FatCanonicalValueConverter : IValueConverter
{
public static P0FatCanonicalValueConverter Instance { get; } = new();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
=> MainWindow.P0CanonicalLiveValue(value?.ToString());
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> Binding.DoNothing;
}