forked from arthurits/SignalAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInteractionGUI.cs
More file actions
400 lines (351 loc) · 15.9 KB
/
Copy pathUserInteractionGUI.cs
File metadata and controls
400 lines (351 loc) · 15.9 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
namespace SignalAnalysis;
partial class FrmMain
{
private void Exit_Click(object? sender, EventArgs e)
{
Close();
}
private void Open_Click(object? sender, EventArgs e)
{
DialogResult result;
string filePath;
using OpenFileDialog openDlg = new()
{
Filter = StringResources.OpenDlgFilter,
FilterIndex = 5,
InitialDirectory = _settings.RememberFileDialogPath ? _settings.UserOpenPath : _settings.DefaultOpenPath,
RestoreDirectory = true,
Title = StringResources.OpenDlgTitle,
};
using (new CenterWinDialog(this))
{
result = openDlg.ShowDialog(this);
}
if (result == DialogResult.OK && openDlg.FileName != "")
{
// Show a waiting cursor
var cursor = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
//Get the path of specified file and store the directory for future calls
filePath = openDlg.FileName;
if (_settings.RememberFileDialogPath) _settings.UserOpenPath = Path.GetDirectoryName(filePath) ?? string.Empty;
// Read the data file in the corresponding format
SignalStats? results = null;
SignalData signalData = new();
bool boolRead = Path.GetExtension(filePath).ToLower() switch
{
".elux" => ReadELuxData(filePath, signalData),
".sig" => ReadSigData(filePath, signalData),
".txt" => ReadTextData(filePath, signalData, results = new()),
".bin" => ReadBinData(filePath, signalData, results = new()),
_ => ReadNotImplemented(filePath)
};
if (boolRead)
{
// Data
Signal = signalData;
// Update UI
PopulateComboSeries();
SetFormTitle(this, openDlg.FileName);
UpdateUI_MeasuringTime();
// Check if computations are needed
if (results is not null)
{
Results = results;
txtStats.Text = Results.ToString(
culture: _settings.AppCulture,
boxplot: _settings.Boxplot,
entropy: _settings.ComputeEntropy,
entropyAlgorithm: _settings.ComputeEntropy ? StringResources.EntropyAlgorithms.Split(", ")[(int)_settings.EntropyAlgorithm] : string.Empty,
entropyM: (int)_settings.EntropyFactorM,
entropyR: _settings.EntropyFactorR,
integral: _settings.ComputeIntegration,
integralAlgorithm: _settings.ComputeIntegration ? StringResources.IntegrationAlgorithms.Split(", ")[(int)_settings.IntegrationAlgorithm] : string.Empty);
}
else
{
ComputeAsync(stripComboSeries.SelectedIndex,
deletePreviousResults: true,
stats: true,
boxplot: _settings.Boxplot,
derivative: _settings.ComputeDerivative,
integral: _settings.ComputeIntegration,
fractal: true,
progressive: _settings.CumulativeDimension,
entropy: _settings.ComputeEntropy,
fft: true,
fftPlot: true,
powerSpectra: _settings.PowerSpectra,
fftRoundUp: _settings.FFTRoundUp);
}
}
// Restore the cursor
Cursor.Current = cursor;
}
}
private void Export_Click(object? sender, EventArgs e)
{
DialogResult result;
string filePath;
// Extract the values to be exported
double[] signal = Array.Empty<double>();
if (Signal.Data.Length > 0)
signal = Signal.Data[stripComboSeries.SelectedIndex][Signal.IndexStart..(Signal.IndexEnd + 1)];
// Exit if there is no data to be saved
if (signal.Length == 0)
{
// Exit if no data has been received or the matrices are still un-initialized
using (new CenterWinDialog(this))
{
MessageBox.Show(this,
StringResources.MsgBoxNoData,
StringResources.MsgBoxNoDataTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
return;
}
// Displays a SaveFileDialog, so the user can save the data into a file
SaveFileDialog SaveDlg = new()
{
DefaultExt = "*.txt",
Filter = StringResources.SaveDlgFilter,
FilterIndex = 1,
InitialDirectory = _settings.RememberFileDialogPath ? _settings.UserSavePath : _settings.DefaultSavePath,
OverwritePrompt = true,
Title = StringResources.SaveDlgTitle
};
using (new CenterWinDialog(this))
{
result = SaveDlg.ShowDialog(this.Parent);
}
// If the file name is not an empty string, call the corresponding routine to save the data into a file.
if (result == DialogResult.OK && SaveDlg.FileName != "")
{
// Show a waiting cursor
var cursor = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
//Get the path of specified file and store the directory for future calls
filePath = SaveDlg.FileName;
if (_settings.RememberFileDialogPath) _settings.UserSavePath = Path.GetDirectoryName(filePath) ?? string.Empty;
var boolSave = Path.GetExtension(filePath).ToLower() switch
{
".txt" => SaveTextData(SaveDlg.FileName, signal, _settings.IndexStart, stripComboSeries.SelectedItem.ToString()),
".sig" => SaveSigData(SaveDlg.FileName, signal, _settings.IndexStart, stripComboSeries.SelectedItem.ToString()),
".bin" => SaveBinaryData(SaveDlg.FileName, signal, _settings.IndexStart, stripComboSeries.SelectedItem.ToString()),
".results" => SaveResultsData(SaveDlg.FileName, signal, _settings.IndexStart),
_ => SaveDefaultData(SaveDlg.FileName, signal, _settings.IndexStart, stripComboSeries.SelectedItem.ToString()),
};
// Restore the cursor
Cursor.Current = cursor;
if (boolSave)
{
// Show OK save data
using (new CenterWinDialog(this))
{
MessageBox.Show(this,
StringResources.MsgBoxOKSaveData,
StringResources.MsgBoxOKSaveDataTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
}
}
private void Settings_Click(object? sender, EventArgs e)
{
_settings.IndexStart = Signal.IndexStart;
_settings.IndexEnd = Signal.IndexEnd;
_settings.IndexMax = Signal.SeriesPoints > 0 ? Signal.SeriesPoints - 1 : 0;
FrmSettings frm = new(_settings);
frm.Icon = GraphicsResources.Load<Icon>(GraphicsResources.AppLogo);
frm.ShowDialog(this);
if (frm.DialogResult == DialogResult.OK)
{
Signal.IndexStart = _settings.IndexStart;
Signal.IndexEnd = _settings.IndexEnd;
// Update UI
//ComboSeries_SelectedIndexChanged(this, EventArgs.Empty);
ShowHideBoxplot(_settings.Boxplot);
statusStripLabelExBoxplot.Checked = _settings.Boxplot;
statusStripLabelExDerivative.Checked = _settings.ComputeDerivative;
statusStripLabelExIntegration.Checked = _settings.ComputeIntegration;
statusStripLabelExCumulative.Checked = _settings.CumulativeDimension;
statusStripLabelExPower.Checked = _settings.PowerSpectra;
statusStripLabelExEntropy.Checked = _settings.ComputeEntropy;
statusStripLabelExCrossHair.Checked = _settings.CrossHair;
UpdateUI_Language();
ComputeAsync(stripComboSeries.SelectedIndex,
deletePreviousResults: false,
stats: true,
boxplot: _settings.Boxplot,
derivative: _settings.ComputeDerivative,
integral: _settings.ComputeIntegration,
fractal: true,
progressive: _settings.CumulativeDimension,
entropy: _settings.ComputeEntropy,
fft: true,
fftPlot: true,
powerSpectra: _settings.PowerSpectra,
fftRoundUp: _settings.FFTRoundUp);
}
}
private void About_Click(object? sender, EventArgs e)
{
FrmAbout frmAbout = new();
frmAbout.ShowDialog();
}
private void Language_Click(object? sender, EventArgs e)
{
FrmLanguage frm = new(_settings);
frm.Icon = GraphicsResources.Load<Icon>(GraphicsResources.AppLogo);
frm.ShowDialog();
if (frm.DialogResult == DialogResult.OK)
UpdateUI_Language();
}
private void LabelEx_Click(object? sender, EventArgs e)
{
if (sender is not null && sender is ToolStripStatusLabelEx LabelEx)
{
var label = LabelEx;
label.Checked = !label.Checked;
// Change the text color
if (label.Checked)
label.ForeColor = Color.Black;
else
label.ForeColor = Color.LightGray;
// Update settings values
switch (label.Name)
{
case "statusStripLabelExBoxplot":
_settings.Boxplot = label.Checked;
ShowHideBoxplot(label.Checked);
ComputeAsync(stripComboSeries.SelectedIndex, boxplot: _settings.Boxplot);
break;
case "statusStripLabelExDerivative":
_settings.ComputeDerivative = label.Checked;
ComputeAsync(stripComboSeries.SelectedIndex, derivative: _settings.ComputeDerivative);
if (_settings.ComputeDerivative == false)
{
plotDerivative.Clear();
plotDerivative.Refresh();
}
break;
case "statusStripLabelExIntegration":
_settings.ComputeIntegration = label.Checked;
ComputeAsync(stripComboSeries.SelectedIndex, integral: _settings.ComputeIntegration);
break;
case "statusStripLabelExCumulative":
_settings.CumulativeDimension = label.Checked;
ComputeAsync(stripComboSeries.SelectedIndex, fractal: true, progressive: _settings.CumulativeDimension);
if (!label.Checked && statsTask is not null && statsTask.Status == TaskStatus.Running)
FrmMain_KeyPress(sender, new KeyPressEventArgs((char)Keys.Escape));
break;
case "statusStripLabelExPower":
_settings.PowerSpectra = label.Checked;
ComputeAsync(stripComboSeries.SelectedIndex, fftPlot: true, powerSpectra: _settings.PowerSpectra, fftRoundUp: _settings.FFTRoundUp);
break;
case "statusStripLabelExEntropy":
_settings.ComputeEntropy = label.Checked;
ComputeAsync(stripComboSeries.SelectedIndex, entropy: _settings.ComputeEntropy);
if (!label.Checked && statsTask is not null && statsTask.Status == TaskStatus.Running)
FrmMain_KeyPress(sender, new KeyPressEventArgs((char)Keys.Escape));
break;
case "statusStripLabelExCrossHair":
_settings.CrossHair = label.Checked;
if (plotOriginal is not null && plotOriginal.Plot.GetPlottables().Length > 0)
{
plotOriginal.ShowCrossHair = label.Checked;
plotOriginal.Refresh();
}
if (plotWindow is not null && plotWindow.Plot.GetPlottables().Length > 0)
{
plotWindow.ShowCrossHair = label.Checked;
plotWindow.Refresh();
}
if (plotApplied is not null && plotApplied.Plot.GetPlottables().Length > 0)
{
plotApplied.ShowCrossHair = label.Checked;
plotApplied.Refresh();
}
if (plotFractal is not null && plotFractal.Plot.GetPlottables().Length > 0)
{
plotFractal.ShowCrossHair = label.Checked;
plotFractal.Refresh();
}
if (plotFFT is not null && plotFFT.Plot.GetPlottables().Length > 0)
{
plotFFT.ShowCrossHair = label.Checked;
plotFFT.Refresh();
}
if (plotDerivative is not null && plotDerivative.Plot.GetPlottables().Length > 0)
{
plotDerivative.ShowCrossHair = label.Checked;
plotDerivative.Refresh();
}
break;
}
}
}
private void PopulateComboSeries(params string[] values)
{
stripComboSeries.Items.Clear();
if (values.Length != 0)
{
stripComboSeries.Items.AddRange(values);
stripComboSeries.Text = values[0];
}
else
{
stripComboSeries.Items.AddRange(Signal.SeriesLabels);
stripComboSeries.Text = Signal.SeriesLabels[0];
}
}
private void ComboSeries_SelectionChangeCommitted(object? sender, EventArgs e)
{
// Move the focus away in order to deselect the text
//this.tableLayoutPanel1.Focus();
if (Signal.Data.Length == 0) return;
//statusStripLabelExEntropy.Checked = false;
//_settings.Entropy = false;
// Update stats and plots
ComputeAsync(stripComboSeries.SelectedIndex,
deletePreviousResults: false,
stats: true,
boxplot: _settings.Boxplot,
derivative: _settings.ComputeDerivative,
integral: _settings.ComputeIntegration,
fractal: true,
progressive: _settings.CumulativeDimension,
entropy: _settings.ComputeEntropy,
fft: true,
powerSpectra: _settings.PowerSpectra,
fftRoundUp: _settings.FFTRoundUp);
}
private void ComboWindow_SelectionChangeCommitted(object? sender, EventArgs e)
{
// Move the focus away in order to deselect the text
//this.tableLayoutPanel1.Focus();
if (stripComboSeries.SelectedIndex < 0) return;
// Extract the values
var signal = Signal.Data[stripComboSeries.SelectedIndex][Signal.IndexStart..(Signal.IndexEnd + 1)];
if (signal is null || signal.Length == 0) return;
//UpdateWindowPlots(signal);
ComputeAsync(stripComboSeries.SelectedIndex,
deletePreviousResults: false,
stats: false,
boxplot: _settings.Boxplot,
derivative: false,
integral: false,
fractal: false,
progressive: false,
entropy: false,
fft: true,
powerSpectra: _settings.PowerSpectra,
fftRoundUp: _settings.FFTRoundUp);
}
private void ShowHideBoxplot (bool show = true)
{
layoutData.ColumnStyles[1].Width = show ? 20F : 0F;
}
}