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
48 changes: 36 additions & 12 deletions OpenEphys.Onix1.Design/ChannelConfigurationDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract partial class ChannelConfigurationDialog : Form

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

internal readonly bool[] SelectedContacts = null;
internal bool[] SelectedContacts { get; private set; } = null;

/// <summary>
/// Constructs the dialog window using the given probe group, and plots all contacts after loading.
Expand All @@ -35,7 +35,7 @@ public ChannelConfigurationDialog(ProbeGroup probeGroup)

if (probeGroup == null)
{
LoadDefaultChannelLayout();
LoadDefaultProbeGroup();
}
else
{
Expand Down Expand Up @@ -68,11 +68,12 @@ public ChannelConfigurationDialog(ProbeGroup probeGroup)
/// </code>
/// </example>
/// <returns>Returns an object that inherits from <see cref="ProbeInterface.NET.ProbeGroup"/></returns>
internal abstract ProbeGroup DefaultChannelLayout();
internal abstract ProbeGroup DefaultProbeGroup();

internal virtual void LoadDefaultChannelLayout()
internal virtual void LoadDefaultProbeGroup()
{
ProbeGroup = DefaultChannelLayout();
ProbeGroup = DefaultProbeGroup();
SelectedContacts = new bool[ProbeGroup.NumberOfContacts];
}

/// <summary>
Expand Down Expand Up @@ -432,13 +433,26 @@ internal virtual bool OpenFile<T>() where T : ProbeGroup
return false;
}

if (ProbeGroup.NumberOfContacts == newConfiguration.NumberOfContacts)
bool skipContactNumberMismatchCheck = false;

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

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

skipContactNumberMismatchCheck = true; // NB: If the probe names do not match, skip the check to see if the number of contacts match.
// Example: loading a Neuropixels 1.0 probe, but the current probe is a 1.0 UHD probe.
}

if (skipContactNumberMismatchCheck || ProbeGroup.NumberOfContacts == newConfiguration.NumberOfContacts)
{
newConfiguration.Validate();

ProbeGroup = newConfiguration;
DrawProbeGroup();
RefreshZedGraph();
SelectedContacts = new bool[ProbeGroup.NumberOfContacts];

return true;
}
Expand Down Expand Up @@ -1081,7 +1095,7 @@ private void MenuItemOpenFile(object sender, EventArgs e)

private void MenuItemLoadDefaultConfig(object sender, EventArgs e)
{
LoadDefaultChannelLayout();
LoadDefaultProbeGroup();
DrawProbeGroup();
UpdateFontSize();
RefreshZedGraph();
Expand Down Expand Up @@ -1124,7 +1138,7 @@ public void MoveToVerticalPosition(float relativePosition)
var minY = GetProbeBottom(zedGraphChannels.GraphPane.GraphObjList);
var maxY = GetProbeTop(zedGraphChannels.GraphPane.GraphObjList);

var newMinY = (maxY - minY - currentRange) * relativePosition;
var newMinY = (maxY - minY - currentRange) * relativePosition + minY;

zedGraphChannels.GraphPane.YAxis.Scale.Min = newMinY;
zedGraphChannels.GraphPane.YAxis.Scale.Max = newMinY + currentRange;
Expand Down Expand Up @@ -1155,9 +1169,13 @@ internal void RefreshZedGraph()

PointD clickStart = new(0.0, 0.0);

bool selectElectrodes = true;

internal void SetSelectElectrodesStatus(bool status) => selectElectrodes = status;

private bool MouseDownEvent(ZedGraphControl sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
if (selectElectrodes && e.Button == MouseButtons.Left)
{
clickStart = TransformPixelsToCoordinates(e.Location, sender.GraphPane);
}
Expand All @@ -1171,6 +1189,12 @@ private bool MouseMoveEvent(ZedGraphControl sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (!selectElectrodes)
{
sender.Cursor = Cursors.Arrow;
return true;
}

sender.Cursor = Cursors.Cross;

if (clickStart.X == default && clickStart.Y == default)
Expand Down Expand Up @@ -1232,7 +1256,7 @@ private bool MouseUpEvent(ZedGraphControl sender, MouseEventArgs e)
{
sender.Cursor = Cursors.Arrow;

if (e.Button == MouseButtons.Left)
if (selectElectrodes && e.Button == MouseButtons.Left)
{
if (sender.GraphPane.GraphObjList[SelectionAreaTag] is BoxObj selectionArea && selectionArea != null && ProbeGroup != null)
{
Expand Down
17 changes: 17 additions & 0 deletions OpenEphys.Onix1.Design/DesignHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
using Newtonsoft.Json;

Expand Down Expand Up @@ -182,5 +184,20 @@ public static void AddMenuItemsFromDialogToFileOption(this Form thisForm, Form c
thisFileMenuItem.DropDownItems.Add(newChildMenuItems);
}
}

internal static string GetEnumDescription(this Enum value)
{
FieldInfo field = value.GetType().GetField(value.ToString());
if (field != null)
{
DescriptionAttribute attribute = field.GetCustomAttribute<DescriptionAttribute>();
if (attribute != null)
{
return attribute.Description;
}
}

return value.ToString();
}
}
}
51 changes: 36 additions & 15 deletions OpenEphys.Onix1.Design/NeuropixelsV1ChannelConfigurationDialog.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
Expand All @@ -16,7 +17,7 @@ public partial class NeuropixelsV1ChannelConfigurationDialog : ChannelConfigurat
internal event EventHandler OnZoom;
internal event EventHandler OnFileLoad;

readonly IReadOnlyList<int> ReferenceContactsList = new List<int> { 191, 575, 959 };
readonly IReadOnlyList<int> ReferenceContactsNp1 = new List<int> { 191, 575, 959 };

/// <summary>
/// Public <see cref="NeuropixelsV1ProbeConfiguration"/> object that is modified by
Expand All @@ -36,28 +37,48 @@ public NeuropixelsV1ChannelConfigurationDialog(NeuropixelsV1ProbeConfiguration p

zedGraphChannels.ZoomStepFraction = 0.5;

ReferenceContacts.AddRange(ReferenceContactsList);
UpdateReferenceContacts(probeConfiguration.ProbeType);

ProbeConfiguration = probeConfiguration;

ZoomInBoundaryX = 400;
ZoomInBoundaryY = 400;
ZoomInBoundaryX = 100;
ZoomInBoundaryY = 100;

HighlightEnabledContacts();
UpdateContactLabels();
DrawScale();
RefreshZedGraph();
}

internal override ProbeGroup DefaultChannelLayout()
void UpdateReferenceContacts(NeuropixelsV1ProbeType probeType)
{
return new NeuropixelsV1eProbeGroup();
ReferenceContacts.Clear();
ReferenceContacts.AddRange(GetReferenceContacts(probeType));
}

internal override void LoadDefaultChannelLayout()
List<int> GetReferenceContacts(NeuropixelsV1ProbeType probeType) => probeType switch
{
ProbeConfiguration = new(ProbeConfiguration.SpikeAmplifierGain, ProbeConfiguration.LfpAmplifierGain, ProbeConfiguration.Reference, ProbeConfiguration.SpikeFilter);
ProbeGroup = ProbeConfiguration.ProbeGroup;
NeuropixelsV1ProbeType.NP1 => ReferenceContactsNp1.ToList(),
NeuropixelsV1ProbeType.UHD => new List<int>(),
_ => throw new InvalidEnumArgumentException(nameof(NeuropixelsV1ProbeType))
};

internal override ProbeGroup DefaultProbeGroup()
{
return new NeuropixelsV1eProbeGroup(ProbeConfiguration.ProbeType);
}

internal override void LoadDefaultProbeGroup()
{
base.LoadDefaultProbeGroup();
ProbeConfiguration = new((NeuropixelsV1eProbeGroup)ProbeGroup,
ProbeConfiguration.ProbeType,
ProbeConfiguration.SpikeAmplifierGain,
ProbeConfiguration.LfpAmplifierGain,
ProbeConfiguration.Reference,
ProbeConfiguration.SpikeFilter);

UpdateReferenceContacts(ProbeConfiguration.ProbeType);

OnFileOpenHandler();
}
Expand All @@ -66,9 +87,8 @@ 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 = new((NeuropixelsV1eProbeGroup)ProbeGroup, ProbeConfiguration.ProbeType, ProbeConfiguration.SpikeAmplifierGain, ProbeConfiguration.LfpAmplifierGain, ProbeConfiguration.Reference, ProbeConfiguration.SpikeFilter);
UpdateReferenceContacts(ProbeConfiguration.ProbeType);
OnFileOpenHandler();

return true;
Expand Down Expand Up @@ -175,13 +195,14 @@ internal override void DrawScale()
countMajorTicks++;
}

var curve = zedGraphChannels.GraphPane.AddCurve(ScalePointsTag, pointList, Color.Black, SymbolType.None);
var curve = zedGraphChannels.GraphPane.AddCurve("", pointList, Color.Black, SymbolType.None);

const float scaleBarWidth = 1;

curve.Line.Width = scaleBarWidth;
curve.Label.IsVisible = false;
curve.Symbol.IsVisible = false;
curve.Tag = ScalePointsTag;
}

internal override void HighlightEnabledContacts()
Expand All @@ -202,7 +223,7 @@ internal override void HighlightEnabledContacts()
var contactsToEnable = contactObjects.Where(c =>
{
var tag = c.Tag as ContactTag;
var channel = NeuropixelsV1Electrode.GetChannelNumber(tag.ContactIndex);
var channel = NeuropixelsV1Electrode.GetChannelNumber(tag.ContactIndex, ProbeConfiguration.ProbeType);
return ProbeConfiguration.ChannelMap[channel].Index == tag.ContactIndex;
});

Expand Down Expand Up @@ -232,7 +253,7 @@ internal override void UpdateContactLabels()
textObjsToUpdate = textObjs.Where(c =>
{
var tag = c.Tag as ContactTag;
var channel = NeuropixelsV1Electrode.GetChannelNumber(tag.ContactIndex);
var channel = NeuropixelsV1Electrode.GetChannelNumber(tag.ContactIndex, ProbeConfiguration.ProbeType);
return ProbeConfiguration.ChannelMap[channel].Index == tag.ContactIndex;
});

Expand Down
Loading
Loading