Skip to content

Commit bcaadbc

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 0f71eaa commit bcaadbc

File tree

3 files changed

+59
-28
lines changed

3 files changed

+59
-28
lines changed

OpenEphys.Onix1.Design/ChannelConfigurationDialog.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,17 @@ public abstract partial class ChannelConfigurationDialog : Form
1818
{
1919
internal event EventHandler OnResizeZedGraph;
2020

21-
internal ProbeGroup ProbeGroup;
21+
ProbeGroup probeGroup;
22+
23+
internal ProbeGroup ProbeGroup
24+
{
25+
get => probeGroup;
26+
set
27+
{
28+
probeGroup = value;
29+
SelectedContacts = new bool[probeGroup.NumberOfContacts];
30+
}
31+
}
2232

2333
internal readonly List<int> ReferenceContacts = new();
2434

@@ -42,8 +52,6 @@ public ChannelConfigurationDialog(ProbeGroup probeGroup)
4252
ProbeGroup = probeGroup;
4353
}
4454

45-
SelectedContacts = new bool[ProbeGroup.NumberOfContacts];
46-
4755
ReferenceContacts = new List<int>();
4856

4957
zedGraphChannels.MouseDownEvent += MouseDownEvent;
@@ -73,7 +81,6 @@ public ChannelConfigurationDialog(ProbeGroup probeGroup)
7381
internal virtual void LoadDefaultChannelLayout()
7482
{
7583
ProbeGroup = DefaultChannelLayout();
76-
SelectedContacts = new bool[ProbeGroup.NumberOfContacts];
7784
}
7885

7986
/// <summary>
@@ -437,8 +444,8 @@ internal virtual bool OpenFile<T>() where T : ProbeGroup
437444

438445
if (ProbeGroup.Probes.First().Annotations.Name != newConfiguration.Probes.First().Annotations.Name)
439446
{
440-
var result = MessageBox.Show($"There is a mismatch between the current probe name ({ProbeGroup.Probes.First().Annotations.Name})" +
441-
$" and the new probe name ({newConfiguration.Probes.First().Annotations.Name}). Continue loading?", "Probe Name Mismatch", MessageBoxButtons.YesNo);
447+
var result = MessageBox.Show($"There is a mismatch between the current probe type ({ProbeGroup.Probes.First().Annotations.Name})" +
448+
$" and the new probe type ({newConfiguration.Probes.First().Annotations.Name}). Continue loading?", "Probe Type Mismatch", MessageBoxButtons.YesNo);
442449

443450
if (result == DialogResult.No)
444451
return false;
@@ -452,7 +459,6 @@ internal virtual bool OpenFile<T>() where T : ProbeGroup
452459
newConfiguration.Validate();
453460

454461
ProbeGroup = newConfiguration;
455-
SelectedContacts = new bool[ProbeGroup.NumberOfContacts];
456462

457463
return true;
458464
}

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.Drawing;
45
using System.IO;
@@ -70,6 +71,8 @@ public NeuropixelsV2ProbeConfiguration ProbeConfiguration
7071
get => ChannelConfiguration.ProbeConfiguration;
7172
}
7273

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

@@ -87,7 +90,15 @@ public NeuropixelsV2eProbeConfigurationDialog(NeuropixelsV2ProbeConfiguration co
8790

8891
textBoxProbeCalibrationFile.Text = calibrationFile;
8992

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

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

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

124-
CheckForExistingChannelPreset();
125-
126131
CheckStatus();
127132

128133
Text += ": " + ProbeConfiguration.Probe.ToString();
134+
135+
UpdateProbeConfiguration();
129136
}
130137

131138
static Array GetComboBoxChannelPresets(NeuropixelsV2ProbeType probeType)
@@ -184,27 +191,30 @@ private void ResizeTrackBar(object sender, EventArgs e)
184191

185192
void UpdateProbeConfiguration()
186193
{
194+
var probeType = (NeuropixelsV2ProbeType)comboBoxProbeType.SelectedItem;
195+
196+
ChannelConfiguration.ProbeConfiguration = probeConfigurations[probeType];
197+
ChannelConfiguration.ProbeGroup = ProbeConfiguration.ProbeGroup;
198+
187199
ChannelConfiguration.DrawProbeGroup();
188200
ChannelConfiguration.ResetZoom();
189201
ChannelConfiguration.RefreshZedGraph();
190202

191-
comboBoxReference.DataSource = NeuropixelsV2ProbeConfiguration.FilterNeuropixelsV2ShankReference(ProbeConfiguration.ProbeType);
192-
193203
comboBoxChannelPresets.SelectedIndexChanged -= SelectedChannelPresetChanged; // NB: Temporarily detach handler so the loaded electrode configuration is respected
194204
comboBoxChannelPresets.DataSource = GetComboBoxChannelPresets(ProbeConfiguration.ProbeType);
195205
comboBoxChannelPresets.SelectedIndexChanged += SelectedChannelPresetChanged;
206+
207+
comboBoxReference.SelectedIndexChanged -= SelectedReferenceChanged;
208+
comboBoxReference.DataSource = NeuropixelsV2ProbeConfiguration.FilterNeuropixelsV2ShankReference(ProbeConfiguration.ProbeType);
209+
comboBoxReference.SelectedItem = ProbeConfiguration.Reference;
210+
comboBoxReference.SelectedIndexChanged += SelectedReferenceChanged;
211+
212+
CheckForExistingChannelPreset();
196213
}
197214

198215
void SelectedProbeTypeChanged(object sender, EventArgs e)
199216
{
200-
var probeType = (NeuropixelsV2ProbeType)((ComboBox)sender).SelectedItem;
201-
202-
if (probeType != ProbeConfiguration.ProbeType)
203-
{
204-
ProbeConfiguration.ProbeType = probeType;
205-
ChannelConfiguration.LoadDefaultChannelLayout();
206-
UpdateProbeConfiguration();
207-
}
217+
UpdateProbeConfiguration();
208218
}
209219

210220
private void SelectedReferenceChanged(object sender, EventArgs e)
@@ -658,10 +668,25 @@ void CheckQuadShankForChannelPreset(NeuropixelsV2Electrode[] channelMap)
658668

659669
private void OnFileLoadEvent(object sender, EventArgs e)
660670
{
661-
ProbeConfiguration.ProbeType = NeuropixelsV2eProbeGroup.GetProbeTypeFromProbeName(ChannelConfiguration.ProbeGroup.Probes.First().Annotations.Name);
662-
comboBoxProbeType.SelectedItem = ProbeConfiguration.ProbeType;
671+
NeuropixelsV2ProbeType probeType;
672+
673+
try
674+
{
675+
probeType = NeuropixelsV2eProbeGroup.GetProbeTypeFromProbeName(ChannelConfiguration.ProbeGroup.Probes.First().Annotations.Name);
676+
}
677+
catch (ArgumentException ex)
678+
{
679+
MessageBox.Show(ex.Message);
680+
return;
681+
}
682+
683+
probeConfigurations[probeType] = new((NeuropixelsV2eProbeGroup)ChannelConfiguration.ProbeGroup,
684+
probeConfigurations[probeType].Probe,
685+
probeConfigurations[probeType].ProbeType,
686+
probeConfigurations[probeType].Reference);
687+
688+
comboBoxProbeType.SelectedItem = probeType;
663689
UpdateProbeConfiguration();
664-
CheckForExistingChannelPreset();
665690
}
666691

667692
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)