Skip to content

Commit 946fba0

Browse files
committed
Add PropertyGrid to NeuropixelsV2 dialogs
1 parent 3c8dbd2 commit 946fba0

File tree

3 files changed

+100
-13
lines changed

3 files changed

+100
-13
lines changed

OpenEphys.Onix1.Design/NeuropixelsV2eDialog.Designer.cs

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OpenEphys.Onix1.Design/NeuropixelsV2eDialog.cs

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel;
34
using System.Windows.Forms;
45

56
namespace OpenEphys.Onix1.Design
@@ -15,7 +16,11 @@ public partial class NeuropixelsV2eDialog : Form
1516
/// Public <see cref="IConfigureNeuropixelsV2"/> interface that is manipulated by
1617
/// <see cref="NeuropixelsV2eDialog"/>.
1718
/// </summary>
18-
public IConfigureNeuropixelsV2 ConfigureNode { get; set; }
19+
public IConfigureNeuropixelsV2 ConfigureNode
20+
{
21+
get => (IConfigureNeuropixelsV2)propertyGrid.SelectedObject;
22+
set => propertyGrid.SelectedObject = value;
23+
}
1924

2025
/// <summary>
2126
/// Initializes a new instance of <see cref="NeuropixelsV2eDialog"/>.
@@ -55,17 +60,6 @@ public NeuropixelsV2eDialog(IConfigureNeuropixelsV2 configureNode)
5560
Tag = NeuropixelsV2Probe.ProbeB
5661
}
5762
};
58-
59-
foreach (var channelConfiguration in ProbeConfigurations)
60-
{
61-
channelConfiguration.InvertPolarityChanged += InvertPolarityChanged;
62-
63-
string probeName = GetProbeName((NeuropixelsV2Probe)channelConfiguration.Tag);
64-
65-
tabControlProbe.TabPages.Add(probeName, probeName);
66-
tabControlProbe.TabPages[probeName].Controls.Add(channelConfiguration);
67-
this.AddMenuItemsFromDialogToFileOption(channelConfiguration, probeName);
68-
}
6963
}
7064

7165
private void InvertPolarityChanged(object sender, EventArgs e)
@@ -78,6 +72,8 @@ private void InvertPolarityChanged(object sender, EventArgs e)
7872
channelConfiguration.SetInvertPolarity(sendingDialog.InvertPolarity);
7973
}
8074
}
75+
76+
ConfigureNode.InvertPolarity = sendingDialog.InvertPolarity;
8177
}
8278

8379
private string GetProbeName(NeuropixelsV2Probe probe)
@@ -105,10 +101,38 @@ private void FormShown(object sender, EventArgs e)
105101
menuStrip.Visible = false;
106102
}
107103

104+
int index = 0;
105+
108106
foreach (var channelConfiguration in ProbeConfigurations)
109107
{
108+
channelConfiguration.InvertPolarityChanged += InvertPolarityChanged;
109+
channelConfiguration.ValueChanged += RefreshPropertyGrid;
110+
111+
string probeName = GetProbeName((NeuropixelsV2Probe)channelConfiguration.Tag);
112+
113+
tabControlProbe.TabPages.Insert(index++, probeName, probeName);
114+
tabControlProbe.TabPages[probeName].Controls.Add(channelConfiguration);
115+
this.AddMenuItemsFromDialogToFileOption(channelConfiguration, probeName);
116+
110117
channelConfiguration.Show();
111118
}
119+
120+
tabControlProbe.SelectedIndex = 0;
121+
}
122+
123+
void RefreshPropertyGrid(object s, EventArgs e)
124+
{
125+
var dialog = (NeuropixelsV2eProbeConfigurationDialog)s;
126+
if ((NeuropixelsV2Probe)dialog.Tag == NeuropixelsV2Probe.ProbeA)
127+
{
128+
ConfigureNode.GainCalibrationFileA = dialog.textBoxProbeCalibrationFile.Text;
129+
}
130+
else if ((NeuropixelsV2Probe)dialog.Tag == NeuropixelsV2Probe.ProbeB)
131+
{
132+
ConfigureNode.GainCalibrationFileB = dialog.textBoxProbeCalibrationFile.Text;
133+
}
134+
135+
propertyGrid.Refresh();
112136
}
113137

114138
internal void Okay_Click(object sender, EventArgs e)
@@ -128,5 +152,25 @@ internal void SaveVariables()
128152

129153
ConfigureNode.InvertPolarity = ProbeConfigurations[GetProbeIndex(NeuropixelsV2Probe.ProbeA)].InvertPolarity;
130154
}
155+
156+
void PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
157+
{
158+
var propertyGrid = (PropertyGrid)s;
159+
var configureNode = (IConfigureNeuropixelsV2)propertyGrid.SelectedObject;
160+
161+
foreach (var configuration in ProbeConfigurations)
162+
{
163+
if ((NeuropixelsV2Probe)configuration.Tag == NeuropixelsV2Probe.ProbeA)
164+
{
165+
configuration.UpdateControls(configureNode.ProbeConfigurationA, configureNode.GainCalibrationFileA, configureNode.InvertPolarity);
166+
}
167+
else if ((NeuropixelsV2Probe)configuration.Tag == NeuropixelsV2Probe.ProbeB)
168+
{
169+
configuration.UpdateControls(configureNode.ProbeConfigurationB, configureNode.GainCalibrationFileB, configureNode.InvertPolarity);
170+
}
171+
else
172+
throw new InvalidEnumArgumentException();
173+
}
174+
}
131175
}
132176
}

OpenEphys.Onix1.Design/NeuropixelsV2eProbeConfigurationDialog.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Linq;
33
using System.Windows.Forms;
4-
using System.Drawing;
54
using System.IO;
65

76
namespace OpenEphys.Onix1.Design
@@ -14,6 +13,7 @@ public partial class NeuropixelsV2eProbeConfigurationDialog : Form
1413
readonly NeuropixelsV2eChannelConfigurationDialog ChannelConfiguration;
1514

1615
internal event EventHandler InvertPolarityChanged;
16+
internal event EventHandler ValueChanged;
1717

1818
private enum ChannelPreset
1919
{
@@ -110,6 +110,8 @@ private void InvertPolarityIndexChanged(object sender, EventArgs e)
110110
{
111111
InvertPolarity = ((CheckBox)sender).Checked;
112112
OnInvertPolarityChangedHandler();
113+
114+
ValueChanged?.Invoke(this, EventArgs.Empty);
113115
}
114116

115117
/// <summary>
@@ -143,6 +145,8 @@ private void FormShown(object sender, EventArgs e)
143145
private void SelectedReferenceChanged(object sender, EventArgs e)
144146
{
145147
ProbeConfiguration.Reference = (NeuropixelsV2QuadShankReference)((ComboBox)sender).SelectedItem;
148+
149+
ValueChanged?.Invoke(this, EventArgs.Empty);
146150
}
147151

148152
private void SelectedChannelPresetChanged(object sender, EventArgs e)
@@ -532,6 +536,8 @@ private void OnFileLoadEvent(object sender, EventArgs e)
532536
private void FileTextChanged(object sender, EventArgs e)
533537
{
534538
CheckStatus();
539+
540+
ValueChanged?.Invoke(this, EventArgs.Empty);
535541
}
536542

537543
private void CheckStatus()
@@ -592,6 +598,8 @@ internal void ChooseCalibrationFile_Click(object sender, EventArgs e)
592598
}
593599

594600
CheckStatus();
601+
602+
ValueChanged?.Invoke(this, EventArgs.Empty);
595603
}
596604

597605
internal void ClearSelection_Click(object sender, EventArgs e)
@@ -646,5 +654,12 @@ void TextBoxKeyPress(object sender, KeyPressEventArgs e)
646654
{
647655
CheckStatus();
648656
}
657+
658+
internal void UpdateControls(NeuropixelsV2QuadShankProbeConfiguration configuration, string calibrationFile, bool invertPolarity)
659+
{
660+
comboBoxReference.SelectedItem = configuration.Reference;
661+
checkBoxInvertPolarity.Checked = invertPolarity;
662+
textBoxProbeCalibrationFile.Text = calibrationFile;
663+
}
649664
}
650665
}

0 commit comments

Comments
 (0)