Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions OpenEphys.Onix1.Design/NeuropixelsV2eChannelConfigurationDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public NeuropixelsV2eChannelConfigurationDialog(NeuropixelsV2ProbeConfiguration

zedGraphChannels.ZoomStepFraction = 0.5;

ProbeConfiguration = Activator.CreateInstance(probeConfiguration.GetType(), probeConfiguration) as NeuropixelsV2ProbeConfiguration;
ProbeConfiguration = probeConfiguration.Clone();
ProbeConfiguration.ProbeGroup = (NeuropixelsV2eProbeGroup)ProbeGroup;

GetChannelNumberFunc = ProbeConfiguration.ChannelMap[0].GetChannelNumberFunc();
Expand All @@ -49,7 +49,16 @@ internal override ProbeGroup DefaultChannelLayout()

internal override void LoadDefaultChannelLayout()
{
base.LoadDefaultChannelLayout();
try
{
ProbeConfiguration.ProbeGroup = DefaultChannelLayout() as NeuropixelsV2eProbeGroup;
ProbeGroup = ProbeConfiguration.ProbeGroup;
}
catch (InvalidOperationException ex)
{
MessageBox.Show("Unable to Load Default", ex.Message);
return;
}

OnFileOpenHandler();
}
Expand Down
100 changes: 30 additions & 70 deletions OpenEphys.Onix1.Design/NeuropixelsV2eDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,33 @@ namespace OpenEphys.Onix1.Design
/// </summary>
public partial class NeuropixelsV2eDialog : Form
{
readonly IReadOnlyList<NeuropixelsV2eProbeConfigurationDialog> ProbeConfigurations;
internal readonly Dictionary<NeuropixelsV2Probe, NeuropixelsV2eProbeConfigurationDialog> ProbeConfigurations;

internal NeuropixelsV2ProbeConfiguration ProbeConfigurationA
{
get
{
return ProbeConfigurations.TryGetValue(NeuropixelsV2Probe.ProbeA, out var probeConfigurationDialog)
? probeConfigurationDialog.ProbeConfiguration
: throw new NullReferenceException("Unable to find the probe configuration dialog for Probe A.");
}
}

internal NeuropixelsV2ProbeConfiguration ProbeConfigurationB
{
get
{
return ProbeConfigurations.TryGetValue(NeuropixelsV2Probe.ProbeB, out var probeConfigurationDialog)
? probeConfigurationDialog.ProbeConfiguration
: throw new NullReferenceException("Unable to find the probe configuration dialog for Probe B.");
}
}

/// <summary>
/// Public <see cref="IConfigureNeuropixelsV2"/> interface that is manipulated by
/// <see cref="NeuropixelsV2eDialog"/>.
/// </summary>
[Obsolete]
public IConfigureNeuropixelsV2 ConfigureNode { get; set; }

/// <summary>
Expand All @@ -26,75 +47,27 @@ public NeuropixelsV2eDialog(IConfigureNeuropixelsV2 configureNode)
InitializeComponent();
Shown += FormShown;

if (configureNode is ConfigureNeuropixelsV2eBeta configureV2eBeta)
if (configureNode is ConfigureNeuropixelsV2eBeta)
{
ConfigureNode = new ConfigureNeuropixelsV2eBeta(configureV2eBeta);
Text = Text.Replace("NeuropixelsV2e ", "NeuropixelsV2eBeta ");
}
else if (configureNode is ConfigureNeuropixelsV2e configureV2e)
{
ConfigureNode = new ConfigureNeuropixelsV2e(configureV2e);
}

ProbeConfigurations = new List<NeuropixelsV2eProbeConfigurationDialog>
ProbeConfigurations = new()
{
new(ConfigureNode.ProbeConfigurationA, ConfigureNode.GainCalibrationFileA, ConfigureNode.InvertPolarity)
{
TopLevel = false,
FormBorderStyle = FormBorderStyle.None,
Dock = DockStyle.Fill,
Parent = this,
Tag = NeuropixelsV2Probe.ProbeA
},
new(ConfigureNode.ProbeConfigurationB, ConfigureNode.GainCalibrationFileB, ConfigureNode.InvertPolarity)
{
TopLevel = false,
FormBorderStyle = FormBorderStyle.None,
Dock = DockStyle.Fill,
Parent = this,
Tag = NeuropixelsV2Probe.ProbeB
}
{ NeuropixelsV2Probe.ProbeA, new(configureNode.ProbeConfigurationA) },
{ NeuropixelsV2Probe.ProbeB, new(configureNode.ProbeConfigurationB) }
};

foreach (var channelConfiguration in ProbeConfigurations)
{
channelConfiguration.InvertPolarityChanged += InvertPolarityChanged;

string probeName = GetProbeName((NeuropixelsV2Probe)channelConfiguration.Tag);
string probeName = channelConfiguration.Key.ToString();

tabControlProbe.TabPages.Add(probeName, probeName);
tabControlProbe.TabPages[probeName].Controls.Add(channelConfiguration);
this.AddMenuItemsFromDialogToFileOption(channelConfiguration, probeName);
channelConfiguration.Value.SetChildFormProperties(this).AddDialogToTab(tabControlProbe.TabPages[probeName]);
this.AddMenuItemsFromDialogToFileOption(channelConfiguration.Value, probeName);
}
}

private void InvertPolarityChanged(object sender, EventArgs e)
{
NeuropixelsV2eProbeConfigurationDialog sendingDialog = (NeuropixelsV2eProbeConfigurationDialog)sender;
foreach (var channelConfiguration in ProbeConfigurations)
{
if (channelConfiguration.Tag != sendingDialog.Tag)
{
channelConfiguration.SetInvertPolarity(sendingDialog.InvertPolarity);
}
}
}

private string GetProbeName(NeuropixelsV2Probe probe)
{
return probe switch
{
NeuropixelsV2Probe.ProbeA => "Probe A",
NeuropixelsV2Probe.ProbeB => "Probe B",
_ => "Invalid probe was specified."
};
}

private int GetProbeIndex(NeuropixelsV2Probe probe)
{
return probe == NeuropixelsV2Probe.ProbeA ? 0 : 1;
}

private void FormShown(object sender, EventArgs e)
{
if (!TopLevel)
Expand All @@ -107,26 +80,13 @@ private void FormShown(object sender, EventArgs e)

foreach (var channelConfiguration in ProbeConfigurations)
{
channelConfiguration.Show();
channelConfiguration.Value.Show();
}
}

internal void Okay_Click(object sender, EventArgs e)
{
SaveVariables();

DialogResult = DialogResult.OK;
}

internal void SaveVariables()
{
ConfigureNode.ProbeConfigurationA = ProbeConfigurations[GetProbeIndex(NeuropixelsV2Probe.ProbeA)].ProbeConfiguration;
ConfigureNode.ProbeConfigurationB = ProbeConfigurations[GetProbeIndex(NeuropixelsV2Probe.ProbeB)].ProbeConfiguration;

ConfigureNode.GainCalibrationFileA = ProbeConfigurations[GetProbeIndex(NeuropixelsV2Probe.ProbeA)].textBoxProbeCalibrationFile.Text;
ConfigureNode.GainCalibrationFileB = ProbeConfigurations[GetProbeIndex(NeuropixelsV2Probe.ProbeB)].textBoxProbeCalibrationFile.Text;

ConfigureNode.InvertPolarity = ProbeConfigurations[GetProbeIndex(NeuropixelsV2Probe.ProbeA)].InvertPolarity;
}
}
}
8 changes: 2 additions & 6 deletions OpenEphys.Onix1.Design/NeuropixelsV2eEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ public override bool EditComponent(ITypeDescriptorContext context, object compon

if (editorDialog.ShowDialog() == DialogResult.OK)
{
configureNeuropixelsV2e.Enable = editorDialog.ConfigureNode.Enable;
configureNeuropixelsV2e.GainCalibrationFileA = editorDialog.ConfigureNode.GainCalibrationFileA;
configureNeuropixelsV2e.GainCalibrationFileB = editorDialog.ConfigureNode.GainCalibrationFileB;
configureNeuropixelsV2e.ProbeConfigurationA = editorDialog.ConfigureNode.ProbeConfigurationA;
configureNeuropixelsV2e.ProbeConfigurationB = editorDialog.ConfigureNode.ProbeConfigurationB;
configureNeuropixelsV2e.InvertPolarity = editorDialog.ConfigureNode.InvertPolarity;
DesignHelper.CopyProperties(editorDialog.ProbeConfigurationA, configureNeuropixelsV2e.ProbeConfigurationA, DesignHelper.PropertiesToIgnore);
DesignHelper.CopyProperties(editorDialog.ProbeConfigurationB, configureNeuropixelsV2e.ProbeConfigurationB, DesignHelper.PropertiesToIgnore);

return true;
}
Expand Down
2 changes: 0 additions & 2 deletions OpenEphys.Onix1.Design/NeuropixelsV2eHeadstageDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public NeuropixelsV2eHeadstageDialog(IConfigureNeuropixelsV2 configureNeuropixel

private void Okay_Click(object sender, System.EventArgs e)
{
DialogNeuropixelsV2e.SaveVariables();

DialogResult = DialogResult.OK;
}
}
Expand Down
22 changes: 7 additions & 15 deletions OpenEphys.Onix1.Design/NeuropixelsV2eHeadstageEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@ public override bool EditComponent(ITypeDescriptorContext context, object compon

if (editorDialog.ShowDialog() == DialogResult.OK)
{
configureV2eHeadstage.Bno055.Enable = ((ConfigurePolledBno055)editorDialog.DialogBno055.Device).Enable;
DesignHelper.CopyProperties((ConfigurePolledBno055)editorDialog.DialogBno055.Device, configureV2eHeadstage.Bno055, DesignHelper.PropertiesToIgnore);

configureV2eHeadstage.NeuropixelsV2e.Enable = editorDialog.DialogNeuropixelsV2e.ConfigureNode.Enable;
configureV2eHeadstage.NeuropixelsV2e.ProbeConfigurationA = editorDialog.DialogNeuropixelsV2e.ConfigureNode.ProbeConfigurationA;
configureV2eHeadstage.NeuropixelsV2e.ProbeConfigurationB = editorDialog.DialogNeuropixelsV2e.ConfigureNode.ProbeConfigurationB;
configureV2eHeadstage.NeuropixelsV2e.GainCalibrationFileA = editorDialog.DialogNeuropixelsV2e.ConfigureNode.GainCalibrationFileA;
configureV2eHeadstage.NeuropixelsV2e.GainCalibrationFileB = editorDialog.DialogNeuropixelsV2e.ConfigureNode.GainCalibrationFileB;
configureV2eHeadstage.NeuropixelsV2e.InvertPolarity = editorDialog.DialogNeuropixelsV2e.ConfigureNode.InvertPolarity;
configureV2eHeadstage.NeuropixelsV2e.ProbeConfigurationA = editorDialog.DialogNeuropixelsV2e.ProbeConfigurationA;
configureV2eHeadstage.NeuropixelsV2e.ProbeConfigurationB = editorDialog.DialogNeuropixelsV2e.ProbeConfigurationB;

return true;
}
Expand All @@ -41,14 +37,10 @@ public override bool EditComponent(ITypeDescriptorContext context, object compon

if (editorDialog.ShowDialog() == DialogResult.OK)
{
configureV2eBetaHeadstage.Bno055.Enable = ((ConfigurePolledBno055)editorDialog.DialogBno055.Device).Enable;

configureV2eBetaHeadstage.NeuropixelsV2eBeta.Enable = editorDialog.DialogNeuropixelsV2e.ConfigureNode.Enable;
configureV2eBetaHeadstage.NeuropixelsV2eBeta.ProbeConfigurationA = editorDialog.DialogNeuropixelsV2e.ConfigureNode.ProbeConfigurationA;
configureV2eBetaHeadstage.NeuropixelsV2eBeta.ProbeConfigurationB = editorDialog.DialogNeuropixelsV2e.ConfigureNode.ProbeConfigurationB;
configureV2eBetaHeadstage.NeuropixelsV2eBeta.GainCalibrationFileA = editorDialog.DialogNeuropixelsV2e.ConfigureNode.GainCalibrationFileA;
configureV2eBetaHeadstage.NeuropixelsV2eBeta.GainCalibrationFileB = editorDialog.DialogNeuropixelsV2e.ConfigureNode.GainCalibrationFileB;
configureV2eBetaHeadstage.NeuropixelsV2eBeta.InvertPolarity = editorDialog.DialogNeuropixelsV2e.ConfigureNode.InvertPolarity;
DesignHelper.CopyProperties((ConfigurePolledBno055)editorDialog.DialogBno055.Device, configureV2eBetaHeadstage.Bno055, DesignHelper.PropertiesToIgnore);

configureV2eBetaHeadstage.NeuropixelsV2eBeta.ProbeConfigurationA = editorDialog.DialogNeuropixelsV2e.ProbeConfigurationA;
configureV2eBetaHeadstage.NeuropixelsV2eBeta.ProbeConfigurationB = editorDialog.DialogNeuropixelsV2e.ProbeConfigurationB;

return true;
}
Expand Down
20 changes: 11 additions & 9 deletions OpenEphys.Onix1.Design/NeuropixelsV2eProbeConfigurationDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,26 @@ public NeuropixelsV2ProbeConfiguration ProbeConfiguration
}

/// <inheritdoc cref="ConfigureNeuropixelsV2e.InvertPolarity"/>
public bool InvertPolarity { get; set; }
[Obsolete]
public bool InvertPolarity
{
get => ProbeConfiguration.InvertPolarity;
set => ProbeConfiguration.InvertPolarity = value;
}

INeuropixelsV2ProbeInfo ProbeData { get; set; }

/// <summary>
/// Initializes a new instance of <see cref="NeuropixelsV2ProbeConfiguration"/>.
/// </summary>
/// <param name="configuration">A <see cref="NeuropixelsV2ProbeConfiguration"/> object holding the current configuration settings.</param>
/// <param name="calibrationFile">String containing the path to the calibration file for this probe.</param>
/// <param name="invertPolarity">Boolean denoting whether or not to invert the polarity of neural data.</param>
public NeuropixelsV2eProbeConfigurationDialog(NeuropixelsV2ProbeConfiguration configuration, string calibrationFile, bool invertPolarity)
public NeuropixelsV2eProbeConfigurationDialog(NeuropixelsV2ProbeConfiguration configuration)
{
InitializeComponent();
Shown += FormShown;

textBoxProbeCalibrationFile.Text = calibrationFile;

InvertPolarity = invertPolarity;
textBoxProbeCalibrationFile.Text = configuration.GainCalibrationFileName;
textBoxProbeCalibrationFile.TextChanged += (sender, e) => ProbeConfiguration.GainCalibrationFileName = ((TextBox)sender).Text;

ChannelConfiguration = new(configuration);
ChannelConfiguration.SetChildFormProperties(this).AddDialogToPanel(panelProbe);
Expand All @@ -61,7 +63,7 @@ public NeuropixelsV2eProbeConfigurationDialog(NeuropixelsV2ProbeConfiguration co
comboBoxChannelPresets.DataSource = ProbeData.GetComboBoxChannelPresets();
comboBoxChannelPresets.SelectedIndexChanged += SelectedChannelPresetChanged;

checkBoxInvertPolarity.Checked = InvertPolarity;
checkBoxInvertPolarity.Checked = ProbeConfiguration.InvertPolarity;
checkBoxInvertPolarity.CheckedChanged += InvertPolarityIndexChanged;

CheckForExistingChannelPreset();
Expand All @@ -83,7 +85,7 @@ static INeuropixelsV2ProbeInfo ProbeDataFactory(NeuropixelsV2ProbeConfiguration

private void InvertPolarityIndexChanged(object sender, EventArgs e)
{
InvertPolarity = ((CheckBox)sender).Checked;
ProbeConfiguration.InvertPolarity = ((CheckBox)sender).Checked;
OnInvertPolarityChangedHandler();
}

Expand Down
15 changes: 1 addition & 14 deletions OpenEphys.Onix1.Design/NeuropixelsV2eProbeConfigurationEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ public override object EditValue(ITypeDescriptorContext context, IServiceProvide
{
var instance = (IConfigureNeuropixelsV2)context.Instance;

var calibrationFile = configuration.Probe == NeuropixelsV2Probe.ProbeA ? instance.GainCalibrationFileA : instance.GainCalibrationFileB;

bool isBeta = instance is ConfigureNeuropixelsV2eBeta;

using var editorDialog = new NeuropixelsV2eProbeConfigurationDialog(configuration, calibrationFile, instance.InvertPolarity);
using var editorDialog = new NeuropixelsV2eProbeConfigurationDialog(configuration);

if (isBeta)
{
Expand All @@ -44,17 +42,6 @@ public override object EditValue(ITypeDescriptorContext context, IServiceProvide

if (editorDialog.ShowDialog() == DialogResult.OK)
{
if (configuration.Probe == NeuropixelsV2Probe.ProbeA)
{
instance.GainCalibrationFileA = editorDialog.textBoxProbeCalibrationFile.Text;
}
else
{
instance.GainCalibrationFileB = editorDialog.textBoxProbeCalibrationFile.Text;
}

instance.InvertPolarity = editorDialog.InvertPolarity;

return editorDialog.ProbeConfiguration;
}
}
Expand Down
Loading