-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaveSclWindow.xaml.cs
More file actions
124 lines (105 loc) · 4.01 KB
/
Copy pathSaveSclWindow.xaml.cs
File metadata and controls
124 lines (105 loc) · 4.01 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
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using AR.Iec61850.Scl.Export;
namespace ArIED61850Tester;
public sealed class SaveSclDialogViewModel : INotifyPropertyChanged
{
private readonly bool _legacySasCidMode;
private SclSchemaProfileDescriptor _selectedSchemaProfile;
private string _editionHint = string.Empty;
public SaveSclDialogViewModel(
string iedName,
string sourceDescription,
SclSchemaProfile selectedProfile = SclSchemaProfile.Edition2V31,
bool legacySasCidMode = false)
{
IedName = string.IsNullOrWhiteSpace(iedName) ? "IED" : iedName.Trim();
SourceDescription = string.IsNullOrWhiteSpace(sourceDescription)
? "IEC 61850 model"
: sourceDescription.Trim();
_legacySasCidMode = legacySasCidMode ||
SourceDescription.Contains("Legacy SAS filter", StringComparison.OrdinalIgnoreCase);
_selectedSchemaProfile = SclSchemaProfiles.Get(selectedProfile);
UpdateHint();
}
public event PropertyChangedEventHandler? PropertyChanged;
public string IedName { get; }
public string SourceDescription { get; }
public SclSchemaProfileDescriptor SelectedSchemaProfile
{
get => _selectedSchemaProfile;
private set
{
if (_selectedSchemaProfile.Profile == value.Profile)
return;
_selectedSchemaProfile = value;
OnPropertyChanged();
UpdateHint();
}
}
public string EditionHint
{
get => _editionHint;
private set
{
if (string.Equals(_editionHint, value, StringComparison.Ordinal))
return;
_editionHint = value;
OnPropertyChanged();
}
}
public bool IsEdition2 => SelectedSchemaProfile.IsEdition2;
public void Select(SclSchemaProfile profile)
{
SelectedSchemaProfile = SclSchemaProfiles.Get(profile);
OnPropertyChanged(nameof(IsEdition2));
}
private void UpdateHint()
{
if (_legacySasCidMode)
{
EditionHint = SelectedSchemaProfile.IsEdition2
? "Use when the target SAS accepts Edition 2. This selected-RCB workflow still saves a CID file."
: "Recommended for existing legacy SAS systems. The selected-RCB output is saved as an Edition 1 CID file.";
return;
}
EditionHint = SelectedSchemaProfile.IsEdition2
? "Recommended for modern engineering exchange. The output is saved as an IID file."
: "Use for legacy engineering systems that require Edition 1. The output is saved as an ICD file.";
}
private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public partial class SaveSclWindow : Window
{
public SaveSclWindow(
string iedName,
string sourceDescription,
SclSchemaProfile selectedProfile = SclSchemaProfile.Edition2V31,
bool legacySasCidMode = false)
{
InitializeComponent();
DataContext = new SaveSclDialogViewModel(iedName, sourceDescription, selectedProfile, legacySasCidMode);
}
public SaveSclDialogViewModel ViewModel => (SaveSclDialogViewModel)DataContext;
private void Window_Loaded(object sender, RoutedEventArgs e)
=> ApplyEditionVisuals();
private void Edition2_Click(object sender, RoutedEventArgs e)
{
ViewModel.Select(SclSchemaProfile.Edition2V31);
ApplyEditionVisuals();
}
private void Edition1_Click(object sender, RoutedEventArgs e)
{
ViewModel.Select(SclSchemaProfile.Edition1V16);
ApplyEditionVisuals();
}
private void ApplyEditionVisuals()
{
Edition2Toggle.IsChecked = ViewModel.IsEdition2;
Edition1Toggle.IsChecked = !ViewModel.IsEdition2;
}
private void Save_Click(object sender, RoutedEventArgs e)
=> DialogResult = true;
}