Skip to content

Commit 8e0f8cd

Browse files
authored
Merge pull request #522 from open-ephys/issue-366-v2
Move Neuropixels V1 ProbeInterface configurations from Bonsai file to JSON files
2 parents 0b1197a + da25ca5 commit 8e0f8cd

25 files changed

+611
-295
lines changed

OpenEphys.Onix1.Design/ChannelConfigurationDialog.Designer.cs

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

OpenEphys.Onix1.Design/ChannelConfigurationDialog.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ internal T OpenAndParseConfigurationFile<T>() where T : ProbeGroup
313313

314314
if (ofd.ShowDialog() == DialogResult.OK && File.Exists(ofd.FileName))
315315
{
316-
var newConfiguration = DesignHelper.DeserializeString<T>(File.ReadAllText(ofd.FileName));
316+
var newConfiguration = JsonHelper.DeserializeString<T>(File.ReadAllText(ofd.FileName));
317317

318318
return newConfiguration;
319319
}
@@ -927,7 +927,7 @@ private void MenuItemSaveFile(object sender, EventArgs e)
927927

928928
if (sfd.ShowDialog() == DialogResult.OK)
929929
{
930-
DesignHelper.SerializeObject(ProbeGroup, sfd.FileName);
930+
JsonHelper.SerializeObject(ProbeGroup, sfd.FileName);
931931
}
932932
}
933933

OpenEphys.Onix1.Design/DesignHelper.cs

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,6 @@ namespace OpenEphys.Onix1.Design
1010
{
1111
static class DesignHelper
1212
{
13-
/// <summary>
14-
/// Given a string with a valid JSON structure, deserialize the string to the given type.
15-
/// </summary>
16-
/// <typeparam name="T"></typeparam>
17-
/// <param name="jsonString"></param>
18-
/// <returns></returns>
19-
#nullable enable
20-
public static T? DeserializeString<T>(string jsonString)
21-
{
22-
var errors = new List<string>();
23-
24-
var serializerSettings = new JsonSerializerSettings()
25-
{
26-
Error = delegate(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
27-
{
28-
errors.Add(args.ErrorContext.Error.Message);
29-
args.ErrorContext.Handled = true;
30-
}
31-
};
32-
33-
var obj = JsonConvert.DeserializeObject<T>(jsonString, serializerSettings);
34-
35-
if (errors.Count > 0)
36-
{
37-
MessageBox.Show($"There were errors encountered while parsing a JSON string. Check the console " +
38-
$"for an error log.", "JSON Parse Error");
39-
40-
foreach (var e in errors)
41-
{
42-
Console.Error.WriteLine(e);
43-
}
44-
45-
return default;
46-
}
47-
48-
return obj;
49-
}
50-
#nullable disable
51-
52-
public static void SerializeObject(object _object, string filepath)
53-
{
54-
var serializerSettings = new JsonSerializerSettings()
55-
{
56-
NullValueHandling = NullValueHandling.Ignore,
57-
};
58-
59-
var stringJson = JsonConvert.SerializeObject(_object, Formatting.Indented, serializerSettings);
60-
61-
File.WriteAllText(filepath, stringJson);
62-
}
63-
6413
public static IEnumerable<Control> GetAllControls(this Control root)
6514
{
6615
var stack = new Stack<Control>();

OpenEphys.Onix1.Design/NeuropixelsV1ChannelConfigurationDialog.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public NeuropixelsV1ChannelConfigurationDialog(NeuropixelsV1ProbeConfiguration p
3737

3838
ReferenceContacts.AddRange(ReferenceContactsList);
3939

40-
ProbeConfiguration = probeConfiguration;
40+
ProbeConfiguration = new(probeConfiguration);
4141

4242
HighlightEnabledContacts();
4343
UpdateContactLabels();
@@ -52,7 +52,7 @@ internal override ProbeGroup DefaultChannelLayout()
5252

5353
internal override void LoadDefaultChannelLayout()
5454
{
55-
ProbeConfiguration = new(ProbeConfiguration.SpikeAmplifierGain, ProbeConfiguration.LfpAmplifierGain, ProbeConfiguration.Reference, ProbeConfiguration.SpikeFilter);
55+
ProbeConfiguration.ProbeGroup = new();
5656
ProbeGroup = ProbeConfiguration.ProbeGroup;
5757

5858
OnFileOpenHandler();
@@ -62,8 +62,7 @@ internal override bool OpenFile<T>()
6262
{
6363
if (base.OpenFile<NeuropixelsV1eProbeGroup>())
6464
{
65-
ProbeConfiguration = new((NeuropixelsV1eProbeGroup)ProbeGroup, ProbeConfiguration.SpikeAmplifierGain, ProbeConfiguration.LfpAmplifierGain, ProbeConfiguration.Reference, ProbeConfiguration.SpikeFilter);
66-
ProbeGroup = ProbeConfiguration.ProbeGroup;
65+
ProbeConfiguration.ProbeGroup = (NeuropixelsV1eProbeGroup)ProbeGroup;
6766

6867
OnFileOpenHandler();
6968

@@ -112,7 +111,7 @@ internal override void DrawScale()
112111

113112
internal override void HighlightEnabledContacts()
114113
{
115-
if (ProbeConfiguration == null || ProbeConfiguration.ChannelMap == null)
114+
if (ProbeConfiguration == null)
116115
return;
117116

118117
var contactObjects = zedGraphChannels.GraphPane.GraphObjList.OfType<BoxObj>()
@@ -125,11 +124,13 @@ internal override void HighlightEnabledContacts()
125124
contact.Fill.Color = DisabledContactFill;
126125
}
127126

127+
var channelMap = ProbeConfiguration.ChannelMap;
128+
128129
var contactsToEnable = contactObjects.Where(c =>
129130
{
130131
var tag = c.Tag as ContactTag;
131132
var channel = NeuropixelsV1Electrode.GetChannelNumber(tag.ContactIndex);
132-
return ProbeConfiguration.ChannelMap[channel].Index == tag.ContactIndex;
133+
return channelMap[channel].Index == tag.ContactIndex;
133134
});
134135

135136
foreach (var contact in contactsToEnable)
@@ -155,11 +156,13 @@ internal override void UpdateContactLabels()
155156
textObj.FontSpec.FontColor = DisabledContactTextColor;
156157
}
157158

159+
var channelMap = ProbeConfiguration.ChannelMap;
160+
158161
textObjsToUpdate = textObjs.Where(c =>
159162
{
160163
var tag = c.Tag as ContactTag;
161164
var channel = NeuropixelsV1Electrode.GetChannelNumber(tag.ContactIndex);
162-
return ProbeConfiguration.ChannelMap[channel].Index == tag.ContactIndex;
165+
return channelMap[channel].Index == tag.ContactIndex;
163166
});
164167

165168
foreach (var textObj in textObjsToUpdate)

OpenEphys.Onix1.Design/NeuropixelsV1Dialog.cs

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ namespace OpenEphys.Onix1.Design
88
/// </summary>
99
public partial class NeuropixelsV1Dialog : Form
1010
{
11-
readonly NeuropixelsV1ProbeConfigurationDialog ProbeConfigurationDialog;
11+
internal readonly NeuropixelsV1ProbeConfigurationDialog ProbeConfigurationDialog;
1212

1313
/// <summary>
1414
/// Public <see cref="IConfigureNeuropixelsV1"/> interface that is manipulated by
1515
/// <see cref="NeuropixelsV1Dialog"/>.
1616
/// </summary>
17+
[Obsolete]
1718
public IConfigureNeuropixelsV1 ConfigureNode { get; set; }
1819

1920
/// <summary>
@@ -25,24 +26,10 @@ public NeuropixelsV1Dialog(IConfigureNeuropixelsV1 configureNode)
2526
InitializeComponent();
2627
Shown += FormShown;
2728

28-
if (configureNode is ConfigureNeuropixelsV1e configureV1e)
29-
{
30-
ConfigureNode = new ConfigureNeuropixelsV1e(configureV1e);
31-
}
32-
else if (configureNode is ConfigureNeuropixelsV1f configureV1f)
33-
{
34-
ConfigureNode = new ConfigureNeuropixelsV1f(configureV1f);
35-
}
36-
37-
ProbeConfigurationDialog = new(ConfigureNode.ProbeConfiguration, ConfigureNode.AdcCalibrationFile, ConfigureNode.GainCalibrationFile, ConfigureNode.InvertPolarity)
38-
{
39-
TopLevel = false,
40-
FormBorderStyle = FormBorderStyle.None,
41-
Dock = DockStyle.Fill,
42-
Parent = this
43-
};
44-
45-
panelProbe.Controls.Add(ProbeConfigurationDialog);
29+
ProbeConfigurationDialog = new(configureNode.ProbeConfiguration);
30+
ProbeConfigurationDialog
31+
.SetChildFormProperties(this)
32+
.AddDialogToPanel(panelProbe);
4633

4734
this.AddMenuItemsFromDialogToFileOption(ProbeConfigurationDialog);
4835
}
@@ -62,19 +49,7 @@ private void FormShown(object sender, EventArgs e)
6249

6350
internal void Okay_Click(object sender, EventArgs e)
6451
{
65-
SaveVariables();
66-
6752
DialogResult = DialogResult.OK;
6853
}
69-
70-
internal void SaveVariables()
71-
{
72-
ConfigureNode.ProbeConfiguration = ProbeConfigurationDialog.ProbeConfiguration;
73-
74-
ConfigureNode.GainCalibrationFile = ProbeConfigurationDialog.textBoxGainCalibrationFile.Text;
75-
ConfigureNode.AdcCalibrationFile = ProbeConfigurationDialog.textBoxAdcCalibrationFile.Text;
76-
77-
ConfigureNode.InvertPolarity = ProbeConfigurationDialog.InvertPolarity;
78-
}
7954
}
8055
}

OpenEphys.Onix1.Design/NeuropixelsV1Editor.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ public override bool EditComponent(ITypeDescriptorContext context, object compon
2222

2323
if (editorDialog.ShowDialog() == DialogResult.OK)
2424
{
25-
configureNeuropixelsV1.Enable = editorDialog.ConfigureNode.Enable;
26-
configureNeuropixelsV1.GainCalibrationFile = editorDialog.ConfigureNode.GainCalibrationFile;
27-
configureNeuropixelsV1.AdcCalibrationFile = editorDialog.ConfigureNode.AdcCalibrationFile;
28-
configureNeuropixelsV1.ProbeConfiguration = editorDialog.ConfigureNode.ProbeConfiguration;
29-
configureNeuropixelsV1.InvertPolarity = editorDialog.ConfigureNode.InvertPolarity;
25+
configureNeuropixelsV1.ProbeConfiguration = editorDialog.ProbeConfigurationDialog.ProbeConfiguration;
3026

3127
return true;
3228
}

OpenEphys.Onix1.Design/NeuropixelsV1ProbeConfigurationDialog.cs

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,45 +26,36 @@ private enum ChannelPreset
2626
}
2727

2828
/// <summary>
29-
/// Public <see cref="IConfigureNeuropixelsV2"/> interface that is manipulated by
30-
/// <see cref="NeuropixelsV2eDialog"/>.
29+
/// Gets or sets the probe configuration.
3130
/// </summary>
32-
/// <remarks>
33-
/// When a <see cref="IConfigureNeuropixelsV2"/> is passed to
34-
/// <see cref="NeuropixelsV1Dialog"/>, it is copied and stored in this
35-
/// variable so that any modifications made to configuration settings can be easily reversed
36-
/// by not copying the new settings back to the original instance.
37-
/// </remarks>
38-
public NeuropixelsV1ProbeConfiguration ProbeConfiguration { get; set; }
31+
public NeuropixelsV1ProbeConfiguration ProbeConfiguration
32+
{
33+
get => ChannelConfiguration.ProbeConfiguration;
34+
set => ChannelConfiguration.ProbeConfiguration = value;
35+
}
3936

40-
/// <inheritdoc cref="ConfigureNeuropixelsV1e.InvertPolarity"/>
41-
public bool InvertPolarity { get; set; }
37+
/// <inheritdoc cref="NeuropixelsV1ProbeConfiguration.InvertPolarity"/>
38+
[Obsolete]
39+
public bool InvertPolarity
40+
{
41+
get => ProbeConfiguration.InvertPolarity;
42+
set => ProbeConfiguration.InvertPolarity = value;
43+
}
4244

4345
/// <summary>
4446
/// Initializes a new instance of <see cref="NeuropixelsV1Dialog"/>.
4547
/// </summary>
4648
/// <param name="probeConfiguration">A <see cref="NeuropixelsV1ProbeConfiguration"/> object holding the current configuration settings.</param>
47-
/// <param name="adcCalibrationFile">String defining the path to the ADC calibration file.</param>
48-
/// <param name="gainCalibrationFile">String defining the path to the gain calibration file.</param>
49-
/// <param name="invertPolarity">Boolean denoting whether or not to invert the polarity of neural data.</param>
50-
public NeuropixelsV1ProbeConfigurationDialog(NeuropixelsV1ProbeConfiguration probeConfiguration, string adcCalibrationFile, string gainCalibrationFile, bool invertPolarity)
49+
public NeuropixelsV1ProbeConfigurationDialog(NeuropixelsV1ProbeConfiguration probeConfiguration)
5150
{
5251
InitializeComponent();
5352
Shown += FormShown;
5453

55-
ProbeConfiguration = new(probeConfiguration);
56-
57-
ChannelConfiguration = new(ProbeConfiguration)
58-
{
59-
TopLevel = false,
60-
FormBorderStyle = FormBorderStyle.None,
61-
Dock = DockStyle.Fill,
62-
Parent = this,
63-
};
64-
65-
InvertPolarity = invertPolarity;
54+
ChannelConfiguration = new(probeConfiguration);
55+
ChannelConfiguration
56+
.SetChildFormProperties(this)
57+
.AddDialogToPanel(panelProbe);
6658

67-
panelProbe.Controls.Add(ChannelConfiguration);
6859
this.AddMenuItemsFromDialogToFileOption(ChannelConfiguration);
6960

7061
ChannelConfiguration.OnZoom += UpdateTrackBarLocation;
@@ -85,12 +76,14 @@ public NeuropixelsV1ProbeConfigurationDialog(NeuropixelsV1ProbeConfiguration pro
8576
checkBoxSpikeFilter.Checked = ProbeConfiguration.SpikeFilter;
8677
checkBoxSpikeFilter.CheckedChanged += SpikeFilterIndexChanged;
8778

88-
checkBoxInvertPolarity.Checked = InvertPolarity;
79+
checkBoxInvertPolarity.Checked = ProbeConfiguration.InvertPolarity;
8980
checkBoxInvertPolarity.CheckedChanged += InvertPolarityIndexChanged;
9081

91-
textBoxAdcCalibrationFile.Text = adcCalibrationFile;
82+
textBoxAdcCalibrationFile.Text = ProbeConfiguration.AdcCalibrationFileName;
83+
textBoxAdcCalibrationFile.TextChanged += (sender, e) => ProbeConfiguration.AdcCalibrationFileName = ((TextBox)sender).Text;
9284

93-
textBoxGainCalibrationFile.Text = gainCalibrationFile;
85+
textBoxGainCalibrationFile.Text = ProbeConfiguration.GainCalibrationFileName;
86+
textBoxGainCalibrationFile.TextChanged += (sender, e) => ProbeConfiguration.GainCalibrationFileName = ((TextBox)sender).Text;
9487

9588
comboBoxChannelPresets.DataSource = Enum.GetValues(typeof(ChannelPreset));
9689
CheckForExistingChannelPreset();
@@ -101,7 +94,7 @@ public NeuropixelsV1ProbeConfigurationDialog(NeuropixelsV1ProbeConfiguration pro
10194

10295
private void InvertPolarityIndexChanged(object sender, EventArgs e)
10396
{
104-
InvertPolarity = ((CheckBox)sender).Checked;
97+
ProbeConfiguration.InvertPolarity = ((CheckBox)sender).Checked;
10598
}
10699

107100
private void FormShown(object sender, EventArgs e)

OpenEphys.Onix1.Design/NeuropixelsV1eHeadstageDialog.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ public NeuropixelsV1eHeadstageDialog(ConfigureNeuropixelsV1e configureNeuropixel
4343

4444
private void Okay_Click(object sender, System.EventArgs e)
4545
{
46-
DialogNeuropixelsV1e.SaveVariables();
47-
4846
DialogResult = DialogResult.OK;
4947
}
5048
}

OpenEphys.Onix1.Design/NeuropixelsV1eHeadstageEditor.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,9 @@ public override bool EditComponent(ITypeDescriptorContext context, object compon
2323

2424
if (editorDialog.ShowDialog() == DialogResult.OK)
2525
{
26-
configureHeadstage.Bno055.Enable = ((ConfigurePolledBno055)editorDialog.DialogBno055.Device).Enable;
26+
DesignHelper.CopyProperties((ConfigurePolledBno055)editorDialog.DialogBno055.Device, configureHeadstage.Bno055, DesignHelper.PropertiesToIgnore);
2727

28-
configureHeadstage.NeuropixelsV1e.AdcCalibrationFile = editorDialog.DialogNeuropixelsV1e.ConfigureNode.AdcCalibrationFile;
29-
configureHeadstage.NeuropixelsV1e.GainCalibrationFile = editorDialog.DialogNeuropixelsV1e.ConfigureNode.GainCalibrationFile;
30-
configureHeadstage.NeuropixelsV1e.Enable = editorDialog.DialogNeuropixelsV1e.ConfigureNode.Enable;
31-
configureHeadstage.NeuropixelsV1e.ProbeConfiguration = editorDialog.DialogNeuropixelsV1e.ConfigureNode.ProbeConfiguration;
32-
configureHeadstage.NeuropixelsV1e.InvertPolarity = editorDialog.DialogNeuropixelsV1e.ConfigureNode.InvertPolarity;
28+
configureHeadstage.NeuropixelsV1e.ProbeConfiguration = editorDialog.DialogNeuropixelsV1e.ProbeConfigurationDialog.ProbeConfiguration;
3329

3430
return true;
3531
}

OpenEphys.Onix1.Design/NeuropixelsV1fHeadstageDialog.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ public NeuropixelsV1fHeadstageDialog(ConfigureNeuropixelsV1f configureNeuropixel
6161

6262
private void Okay_Click(object sender, System.EventArgs e)
6363
{
64-
DialogNeuropixelsV1A.SaveVariables();
65-
DialogNeuropixelsV1B.SaveVariables();
66-
6764
DialogResult = DialogResult.OK;
6865
}
6966
}

0 commit comments

Comments
 (0)