Skip to content
Draft
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
12 changes: 6 additions & 6 deletions OpenEphys.Onix1.Design/ChannelConfigurationDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions OpenEphys.Onix1.Design/ChannelConfigurationDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ internal T OpenAndParseConfigurationFile<T>() where T : ProbeGroup

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

return newConfiguration;
}
Expand Down Expand Up @@ -927,7 +927,7 @@ private void MenuItemSaveFile(object sender, EventArgs e)

if (sfd.ShowDialog() == DialogResult.OK)
{
DesignHelper.SerializeObject(ProbeGroup, sfd.FileName);
JsonHelper.SerializeObject(ProbeGroup, sfd.FileName);
}
}

Expand Down
51 changes: 0 additions & 51 deletions OpenEphys.Onix1.Design/DesignHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,6 @@ namespace OpenEphys.Onix1.Design
{
static class DesignHelper
{
/// <summary>
/// Given a string with a valid JSON structure, deserialize the string to the given type.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="jsonString"></param>
/// <returns></returns>
#nullable enable
public static T? DeserializeString<T>(string jsonString)
{
var errors = new List<string>();

var serializerSettings = new JsonSerializerSettings()
{
Error = delegate(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
{
errors.Add(args.ErrorContext.Error.Message);
args.ErrorContext.Handled = true;
}
};

var obj = JsonConvert.DeserializeObject<T>(jsonString, serializerSettings);

if (errors.Count > 0)
{
MessageBox.Show($"There were errors encountered while parsing a JSON string. Check the console " +
$"for an error log.", "JSON Parse Error");

foreach (var e in errors)
{
Console.Error.WriteLine(e);
}

return default;
}

return obj;
}
#nullable disable

public static void SerializeObject(object _object, string filepath)
{
var serializerSettings = new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore,
};

var stringJson = JsonConvert.SerializeObject(_object, Formatting.Indented, serializerSettings);

File.WriteAllText(filepath, stringJson);
}

public static IEnumerable<Control> GetAllControls(this Control root)
{
var stack = new Stack<Control>();
Expand Down
17 changes: 10 additions & 7 deletions OpenEphys.Onix1.Design/NeuropixelsV1ChannelConfigurationDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public NeuropixelsV1ChannelConfigurationDialog(NeuropixelsV1ProbeConfiguration p

ReferenceContacts.AddRange(ReferenceContactsList);

ProbeConfiguration = probeConfiguration;
ProbeConfiguration = new(probeConfiguration);

HighlightEnabledContacts();
UpdateContactLabels();
Expand All @@ -52,7 +52,7 @@ internal override ProbeGroup DefaultChannelLayout()

internal override void LoadDefaultChannelLayout()
{
ProbeConfiguration = new(ProbeConfiguration.SpikeAmplifierGain, ProbeConfiguration.LfpAmplifierGain, ProbeConfiguration.Reference, ProbeConfiguration.SpikeFilter);
ProbeConfiguration.ProbeGroup = new();
ProbeGroup = ProbeConfiguration.ProbeGroup;

OnFileOpenHandler();
Expand All @@ -62,8 +62,7 @@ internal override bool OpenFile<T>()
{
if (base.OpenFile<NeuropixelsV1eProbeGroup>())
{
ProbeConfiguration = new((NeuropixelsV1eProbeGroup)ProbeGroup, ProbeConfiguration.SpikeAmplifierGain, ProbeConfiguration.LfpAmplifierGain, ProbeConfiguration.Reference, ProbeConfiguration.SpikeFilter);
ProbeGroup = ProbeConfiguration.ProbeGroup;
ProbeConfiguration.ProbeGroup = (NeuropixelsV1eProbeGroup)ProbeGroup;

OnFileOpenHandler();

Expand Down Expand Up @@ -112,7 +111,7 @@ internal override void DrawScale()

internal override void HighlightEnabledContacts()
{
if (ProbeConfiguration == null || ProbeConfiguration.ChannelMap == null)
if (ProbeConfiguration == null)
return;

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

var channelMap = ProbeConfiguration.ChannelMap;

var contactsToEnable = contactObjects.Where(c =>
{
var tag = c.Tag as ContactTag;
var channel = NeuropixelsV1Electrode.GetChannelNumber(tag.ContactIndex);
return ProbeConfiguration.ChannelMap[channel].Index == tag.ContactIndex;
return channelMap[channel].Index == tag.ContactIndex;
});

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

var channelMap = ProbeConfiguration.ChannelMap;

textObjsToUpdate = textObjs.Where(c =>
{
var tag = c.Tag as ContactTag;
var channel = NeuropixelsV1Electrode.GetChannelNumber(tag.ContactIndex);
return ProbeConfiguration.ChannelMap[channel].Index == tag.ContactIndex;
return channelMap[channel].Index == tag.ContactIndex;
});

foreach (var textObj in textObjsToUpdate)
Expand Down
37 changes: 6 additions & 31 deletions OpenEphys.Onix1.Design/NeuropixelsV1Dialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ namespace OpenEphys.Onix1.Design
/// </summary>
public partial class NeuropixelsV1Dialog : Form
{
readonly NeuropixelsV1ProbeConfigurationDialog ProbeConfigurationDialog;
internal readonly NeuropixelsV1ProbeConfigurationDialog ProbeConfigurationDialog;

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

/// <summary>
Expand All @@ -25,24 +26,10 @@ public NeuropixelsV1Dialog(IConfigureNeuropixelsV1 configureNode)
InitializeComponent();
Shown += FormShown;

if (configureNode is ConfigureNeuropixelsV1e configureV1e)
{
ConfigureNode = new ConfigureNeuropixelsV1e(configureV1e);
}
else if (configureNode is ConfigureNeuropixelsV1f configureV1f)
{
ConfigureNode = new ConfigureNeuropixelsV1f(configureV1f);
}

ProbeConfigurationDialog = new(ConfigureNode.ProbeConfiguration, ConfigureNode.AdcCalibrationFile, ConfigureNode.GainCalibrationFile, ConfigureNode.InvertPolarity)
{
TopLevel = false,
FormBorderStyle = FormBorderStyle.None,
Dock = DockStyle.Fill,
Parent = this
};

panelProbe.Controls.Add(ProbeConfigurationDialog);
ProbeConfigurationDialog = new(configureNode.ProbeConfiguration);
ProbeConfigurationDialog
.SetChildFormProperties(this)
.AddDialogToPanel(panelProbe);

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

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

DialogResult = DialogResult.OK;
}

internal void SaveVariables()
{
ConfigureNode.ProbeConfiguration = ProbeConfigurationDialog.ProbeConfiguration;

ConfigureNode.GainCalibrationFile = ProbeConfigurationDialog.textBoxGainCalibrationFile.Text;
ConfigureNode.AdcCalibrationFile = ProbeConfigurationDialog.textBoxAdcCalibrationFile.Text;

ConfigureNode.InvertPolarity = ProbeConfigurationDialog.InvertPolarity;
}
}
}
6 changes: 1 addition & 5 deletions OpenEphys.Onix1.Design/NeuropixelsV1Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ public override bool EditComponent(ITypeDescriptorContext context, object compon

if (editorDialog.ShowDialog() == DialogResult.OK)
{
configureNeuropixelsV1.Enable = editorDialog.ConfigureNode.Enable;
configureNeuropixelsV1.GainCalibrationFile = editorDialog.ConfigureNode.GainCalibrationFile;
configureNeuropixelsV1.AdcCalibrationFile = editorDialog.ConfigureNode.AdcCalibrationFile;
configureNeuropixelsV1.ProbeConfiguration = editorDialog.ConfigureNode.ProbeConfiguration;
configureNeuropixelsV1.InvertPolarity = editorDialog.ConfigureNode.InvertPolarity;
configureNeuropixelsV1.ProbeConfiguration = editorDialog.ProbeConfigurationDialog.ProbeConfiguration;

return true;
}
Expand Down
55 changes: 24 additions & 31 deletions OpenEphys.Onix1.Design/NeuropixelsV1ProbeConfigurationDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,36 @@ private enum ChannelPreset
}

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

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

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

ProbeConfiguration = new(probeConfiguration);

ChannelConfiguration = new(ProbeConfiguration)
{
TopLevel = false,
FormBorderStyle = FormBorderStyle.None,
Dock = DockStyle.Fill,
Parent = this,
};

InvertPolarity = invertPolarity;
ChannelConfiguration = new(probeConfiguration);
ChannelConfiguration
.SetChildFormProperties(this)
.AddDialogToPanel(panelProbe);

panelProbe.Controls.Add(ChannelConfiguration);
this.AddMenuItemsFromDialogToFileOption(ChannelConfiguration);

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

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

textBoxAdcCalibrationFile.Text = adcCalibrationFile;
textBoxAdcCalibrationFile.Text = ProbeConfiguration.AdcCalibrationFileName;
textBoxAdcCalibrationFile.TextChanged += (sender, e) => ProbeConfiguration.AdcCalibrationFileName = ((TextBox)sender).Text;

textBoxGainCalibrationFile.Text = gainCalibrationFile;
textBoxGainCalibrationFile.Text = ProbeConfiguration.GainCalibrationFileName;
textBoxGainCalibrationFile.TextChanged += (sender, e) => ProbeConfiguration.GainCalibrationFileName = ((TextBox)sender).Text;

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

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

private void FormShown(object sender, EventArgs e)
Expand Down
2 changes: 0 additions & 2 deletions OpenEphys.Onix1.Design/NeuropixelsV1eHeadstageDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public NeuropixelsV1eHeadstageDialog(ConfigureNeuropixelsV1e configureNeuropixel

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

DialogResult = DialogResult.OK;
}
}
Expand Down
8 changes: 2 additions & 6 deletions OpenEphys.Onix1.Design/NeuropixelsV1eHeadstageEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@ public override bool EditComponent(ITypeDescriptorContext context, object compon

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

configureHeadstage.NeuropixelsV1e.AdcCalibrationFile = editorDialog.DialogNeuropixelsV1e.ConfigureNode.AdcCalibrationFile;
configureHeadstage.NeuropixelsV1e.GainCalibrationFile = editorDialog.DialogNeuropixelsV1e.ConfigureNode.GainCalibrationFile;
configureHeadstage.NeuropixelsV1e.Enable = editorDialog.DialogNeuropixelsV1e.ConfigureNode.Enable;
configureHeadstage.NeuropixelsV1e.ProbeConfiguration = editorDialog.DialogNeuropixelsV1e.ConfigureNode.ProbeConfiguration;
configureHeadstage.NeuropixelsV1e.InvertPolarity = editorDialog.DialogNeuropixelsV1e.ConfigureNode.InvertPolarity;
configureHeadstage.NeuropixelsV1e.ProbeConfiguration = editorDialog.DialogNeuropixelsV1e.ProbeConfigurationDialog.ProbeConfiguration;

return true;
}
Expand Down
3 changes: 0 additions & 3 deletions OpenEphys.Onix1.Design/NeuropixelsV1fHeadstageDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ public NeuropixelsV1fHeadstageDialog(ConfigureNeuropixelsV1f configureNeuropixel

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

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

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

configureHeadstage.NeuropixelsV1A.AdcCalibrationFile = editorDialog.DialogNeuropixelsV1A.ConfigureNode.AdcCalibrationFile;
configureHeadstage.NeuropixelsV1A.GainCalibrationFile = editorDialog.DialogNeuropixelsV1A.ConfigureNode.GainCalibrationFile;
configureHeadstage.NeuropixelsV1A.Enable = editorDialog.DialogNeuropixelsV1A.ConfigureNode.Enable;
configureHeadstage.NeuropixelsV1A.ProbeConfiguration = editorDialog.DialogNeuropixelsV1A.ConfigureNode.ProbeConfiguration;
configureHeadstage.NeuropixelsV1A.InvertPolarity = editorDialog.DialogNeuropixelsV1A.ConfigureNode.InvertPolarity;

configureHeadstage.NeuropixelsV1B.AdcCalibrationFile = editorDialog.DialogNeuropixelsV1B.ConfigureNode.AdcCalibrationFile;
configureHeadstage.NeuropixelsV1B.GainCalibrationFile = editorDialog.DialogNeuropixelsV1B.ConfigureNode.GainCalibrationFile;
configureHeadstage.NeuropixelsV1B.Enable = editorDialog.DialogNeuropixelsV1B.ConfigureNode.Enable;
configureHeadstage.NeuropixelsV1B.ProbeConfiguration = editorDialog.DialogNeuropixelsV1B.ConfigureNode.ProbeConfiguration;
configureHeadstage.NeuropixelsV1B.InvertPolarity = editorDialog.DialogNeuropixelsV1B.ConfigureNode.InvertPolarity;
configureHeadstage.NeuropixelsV1A.ProbeConfiguration = editorDialog.DialogNeuropixelsV1A.ProbeConfigurationDialog.ProbeConfiguration;
configureHeadstage.NeuropixelsV1B.ProbeConfiguration = editorDialog.DialogNeuropixelsV1B.ProbeConfigurationDialog.ProbeConfiguration;

return true;
}
Expand Down
Loading