Skip to content

Commit ac3d9b5

Browse files
committed
Save probe configurations for both probe types
- Instead of reverting to the default settings for a probe type if the user switches types, hold both configurations in memory and swap between them so that the user does not lose any configurations accidentally
1 parent 235ce6b commit ac3d9b5

File tree

3 files changed

+48
-23
lines changed

3 files changed

+48
-23
lines changed

OpenEphys.Onix1.Design/ChannelConfigurationDialog.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ internal virtual bool OpenFile<T>() where T : ProbeGroup
295295

296296
if (ProbeGroup.Probes.First().Annotations.Name != newConfiguration.Probes.First().Annotations.Name)
297297
{
298-
var result = MessageBox.Show($"There is a mismatch between the current probe name ({ProbeGroup.Probes.First().Annotations.Name})" +
299-
$" and the new probe name ({newConfiguration.Probes.First().Annotations.Name}). Continue loading?", "Probe Name Mismatch", MessageBoxButtons.YesNo);
298+
var result = MessageBox.Show($"There is a mismatch between the current probe type ({ProbeGroup.Probes.First().Annotations.Name})" +
299+
$" and the new probe type ({newConfiguration.Probes.First().Annotations.Name}). Continue loading?", "Probe Type Mismatch", MessageBoxButtons.YesNo);
300300

301301
if (result == DialogResult.No)
302302
return false;

OpenEphys.Onix1.Design/NeuropixelsV2eProbeConfigurationDialog.cs

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.ComponentModel;
34
using System.IO;
45
using System.Linq;
@@ -69,6 +70,8 @@ public NeuropixelsV2ProbeConfiguration ProbeConfiguration
6970
get => ChannelConfiguration.ProbeConfiguration;
7071
}
7172

73+
readonly Dictionary<NeuropixelsV2ProbeType, NeuropixelsV2ProbeConfiguration> probeConfigurations;
74+
7275
/// <inheritdoc cref="ConfigureNeuropixelsV2e.InvertPolarity"/>
7376
public bool InvertPolarity { get; set; }
7477

@@ -86,7 +89,15 @@ public NeuropixelsV2eProbeConfigurationDialog(NeuropixelsV2ProbeConfiguration co
8689

8790
textBoxProbeCalibrationFile.Text = calibrationFile;
8891

89-
ChannelConfiguration = new(configuration)
92+
probeConfigurations = new()
93+
{
94+
[NeuropixelsV2ProbeType.SingleShank] = new(configuration.Probe, NeuropixelsV2ProbeType.SingleShank, configuration.Reference),
95+
[NeuropixelsV2ProbeType.QuadShank] = new(configuration.Probe, NeuropixelsV2ProbeType.QuadShank, configuration.Reference)
96+
};
97+
98+
probeConfigurations[configuration.ProbeType].SelectElectrodes(configuration.ChannelMap);
99+
100+
ChannelConfiguration = new(probeConfigurations[configuration.ProbeType])
90101
{
91102
TopLevel = false,
92103
FormBorderStyle = FormBorderStyle.None,
@@ -110,21 +121,17 @@ public NeuropixelsV2eProbeConfigurationDialog(NeuropixelsV2ProbeConfiguration co
110121
else
111122
comboBoxProbeType.SelectedIndexChanged += SelectedProbeTypeChanged;
112123

113-
comboBoxReference.DataSource = NeuropixelsV2ProbeConfiguration.FilterNeuropixelsV2ShankReference(ProbeConfiguration.ProbeType);
114-
comboBoxReference.SelectedItem = ProbeConfiguration.Reference;
115-
comboBoxReference.SelectedIndexChanged += SelectedReferenceChanged;
116-
117124
comboBoxChannelPresets.DataSource = GetComboBoxChannelPresets(ProbeConfiguration.ProbeType);
118125
comboBoxChannelPresets.SelectedIndexChanged += SelectedChannelPresetChanged;
119126

120127
checkBoxInvertPolarity.Checked = InvertPolarity;
121128
checkBoxInvertPolarity.CheckedChanged += InvertPolarityIndexChanged;
122129

123-
CheckForExistingChannelPreset();
124-
125130
CheckStatus();
126131

127132
Text += ": " + ProbeConfiguration.Probe.ToString();
133+
134+
UpdateProbeConfiguration();
128135
}
129136

130137
static Array GetComboBoxChannelPresets(NeuropixelsV2ProbeType probeType)
@@ -173,27 +180,30 @@ private void FormShown(object sender, EventArgs e)
173180

174181
void UpdateProbeConfiguration()
175182
{
183+
var probeType = (NeuropixelsV2ProbeType)comboBoxProbeType.SelectedItem;
184+
185+
ChannelConfiguration.ProbeConfiguration = probeConfigurations[probeType];
186+
ChannelConfiguration.ProbeGroup = ProbeConfiguration.ProbeGroup;
187+
176188
ChannelConfiguration.DrawProbeGroup();
177189
ChannelConfiguration.ResetZoom();
178190
ChannelConfiguration.RefreshZedGraph();
179191

180-
comboBoxReference.DataSource = NeuropixelsV2ProbeConfiguration.FilterNeuropixelsV2ShankReference(ProbeConfiguration.ProbeType);
181-
182192
comboBoxChannelPresets.SelectedIndexChanged -= SelectedChannelPresetChanged; // NB: Temporarily detach handler so the loaded electrode configuration is respected
183193
comboBoxChannelPresets.DataSource = GetComboBoxChannelPresets(ProbeConfiguration.ProbeType);
184194
comboBoxChannelPresets.SelectedIndexChanged += SelectedChannelPresetChanged;
195+
196+
comboBoxReference.SelectedIndexChanged -= SelectedReferenceChanged;
197+
comboBoxReference.DataSource = NeuropixelsV2ProbeConfiguration.FilterNeuropixelsV2ShankReference(ProbeConfiguration.ProbeType);
198+
comboBoxReference.SelectedItem = ProbeConfiguration.Reference;
199+
comboBoxReference.SelectedIndexChanged += SelectedReferenceChanged;
200+
201+
CheckForExistingChannelPreset();
185202
}
186203

187204
void SelectedProbeTypeChanged(object sender, EventArgs e)
188205
{
189-
var probeType = (NeuropixelsV2ProbeType)((ComboBox)sender).SelectedItem;
190-
191-
if (probeType != ProbeConfiguration.ProbeType)
192-
{
193-
ProbeConfiguration.ProbeType = probeType;
194-
ChannelConfiguration.LoadDefaultChannelLayout();
195-
UpdateProbeConfiguration();
196-
}
206+
UpdateProbeConfiguration();
197207
}
198208

199209
private void SelectedReferenceChanged(object sender, EventArgs e)
@@ -647,10 +657,25 @@ void CheckQuadShankForChannelPreset(NeuropixelsV2Electrode[] channelMap)
647657

648658
private void OnFileLoadEvent(object sender, EventArgs e)
649659
{
650-
ProbeConfiguration.ProbeType = NeuropixelsV2eProbeGroup.GetProbeTypeFromProbeName(ChannelConfiguration.ProbeGroup.Probes.First().Annotations.Name);
651-
comboBoxProbeType.SelectedItem = ProbeConfiguration.ProbeType;
660+
NeuropixelsV2ProbeType probeType;
661+
662+
try
663+
{
664+
probeType = NeuropixelsV2eProbeGroup.GetProbeTypeFromProbeName(ChannelConfiguration.ProbeGroup.Probes.First().Annotations.Name);
665+
}
666+
catch (ArgumentException ex)
667+
{
668+
MessageBox.Show(ex.Message);
669+
return;
670+
}
671+
672+
probeConfigurations[probeType] = new((NeuropixelsV2eProbeGroup)ChannelConfiguration.ProbeGroup,
673+
probeConfigurations[probeType].Probe,
674+
probeConfigurations[probeType].ProbeType,
675+
probeConfigurations[probeType].Reference);
676+
677+
comboBoxProbeType.SelectedItem = probeType;
652678
UpdateProbeConfiguration();
653-
CheckForExistingChannelPreset();
654679
}
655680

656681
private void FileTextChanged(object sender, EventArgs e)

OpenEphys.Onix1/NeuropixelsV2eProbeGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ internal static NeuropixelsV2ProbeType GetProbeTypeFromProbeName(string name)
5050
return NeuropixelsV2ProbeType.QuadShank;
5151

5252
else
53-
throw new ArgumentException($"The name '{name}' does not match any known Neuropixels 2.0 probe names.");
53+
throw new ArgumentException($"The type '{name}' does not match any implemented Neuropixels 2.0 probe types.");
5454
}
5555

5656
private static Probe[] DefaultProbes(NeuropixelsV2ProbeType probeType)

0 commit comments

Comments
 (0)