Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GUI for Neuropixels V1e #231

Merged
merged 8 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageIcon>icon.png</PackageIcon>
<VersionPrefix>0.1.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<LangVersion>9.0</LangVersion>
<LangVersion>10.0</LangVersion>
<Features>strict</Features>
</PropertyGroup>

Expand Down
39 changes: 39 additions & 0 deletions OpenEphys.Onix1.Design/Bno055Dialog.Designer.cs

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

42 changes: 42 additions & 0 deletions OpenEphys.Onix1.Design/Bno055Dialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;

namespace OpenEphys.Onix1.Design
{
/// <summary>
/// Simple dialog that attaches the <see cref="ConfigureBno055"/> to a property grid.
/// </summary>
public partial class Bno055Dialog : GenericDeviceDialog
{
/// <summary>
/// Gets or sets the <see cref="ConfigureBno055"/>, allowing for changes made in the dialog to be reflected in the main editor.
/// </summary>
public ConfigureBno055 ConfigureNode
{
get => (ConfigureBno055)propertyGrid.SelectedObject;
set => propertyGrid.SelectedObject = value;
}

/// <summary>
/// Initializes a new dialog for the <see cref="ConfigureBno055"/> operator.
/// </summary>
/// <param name="configureNode"></param>
public Bno055Dialog(ConfigureBno055 configureNode)
{
InitializeComponent();
Shown += FormShown;

ConfigureNode = new(configureNode);
}

private void FormShown(object sender, EventArgs e)
{
if (!TopLevel)
{
splitContainer1.Panel2Collapsed = true;
splitContainer1.Panel2.Hide();

MaximumSize = new System.Drawing.Size(0, 0);
}
}
}
}
35 changes: 35 additions & 0 deletions OpenEphys.Onix1.Design/Bno055Editor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Bonsai.Design;
using System.ComponentModel;
using System.Windows.Forms;
using System;

namespace OpenEphys.Onix1.Design
{
/// <summary>
/// Class that opens a new dialog for a <see cref="ConfigureBno055"/>.
/// </summary>
public class Bno055Editor : WorkflowComponentEditor
{
/// <inheritdoc/>
public override bool EditComponent(ITypeDescriptorContext context, object component, IServiceProvider provider, IWin32Window owner)
{
if (provider != null)
{
var editorState = (IWorkflowEditorState)provider.GetService(typeof(IWorkflowEditorState));
if (editorState != null && !editorState.WorkflowRunning && component is ConfigureBno055 configureBno055)
{
using var editorDialog = new Bno055Dialog(configureBno055);

if (editorDialog.ShowDialog() == DialogResult.OK)
{
configureBno055.Enable = editorDialog.ConfigureNode.Enable;

return true;
}
}
}

return false;
}
}
}
32 changes: 28 additions & 4 deletions OpenEphys.Onix1.Design/ChannelConfigurationDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public ChannelConfigurationDialog(ProbeGroup probeGroup)

SelectedContacts = new bool[ChannelConfiguration.NumberOfContacts];

ReferenceContacts = new List<int>();

zedGraphChannels.MouseDownEvent += MouseDownEvent;
zedGraphChannels.MouseMoveEvent += MouseMoveEvent;
zedGraphChannels.MouseUpEvent += MouseUpEvent;
Expand Down Expand Up @@ -630,10 +632,34 @@ internal virtual void HighlightEnabledContacts()

foreach (var contact in contactsToEnable)
{
var tag = (ContactTag)contact.Tag;
contact.Fill.Color = EnabledContactFill;
}
}

HighlightReferenceContacts();
}

contact.Fill.Color = ReferenceContacts.Any(x => x == tag.ContactIndex) ? ReferenceContactFill : EnabledContactFill;
internal void HighlightReferenceContacts()
{
if (ChannelConfiguration == null)
return;

var contactObjects = zedGraphChannels.GraphPane.GraphObjList.OfType<BoxObj>()
.Where(c => c is not PolyObj);

var referenceContacts = contactObjects.Where(c =>
{
if (c.Tag is ContactTag tag)
{
return ReferenceContacts.Any(r => tag.ContactIndex == r);
}

return false;
});

foreach (var contact in referenceContacts)
{
contact.Fill.Color = ReferenceContactFill;
}
}

Expand Down Expand Up @@ -1079,7 +1105,6 @@ private bool MouseMoveEvent(ZedGraphControl sender, MouseEventArgs e)
private bool MouseUpEvent(ZedGraphControl sender, MouseEventArgs e)
{
sender.Cursor = Cursors.Arrow;

if (e.Button == MouseButtons.Left)
{
if (sender.GraphPane.GraphObjList[SelectionAreaTag] is BoxObj selectionArea && selectionArea != null && ChannelConfiguration != null)
Expand All @@ -1095,7 +1120,6 @@ private bool MouseUpEvent(ZedGraphControl sender, MouseEventArgs e)
{
var x = c.Location.X + c.Location.Width / 2;
var y = c.Location.Y - c.Location.Height / 2;

return c is not PolyObj &&
x >= rect.X &&
x <= rect.X + rect.Width &&
Expand Down
2 changes: 1 addition & 1 deletion OpenEphys.Onix1.Design/ContactTag.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

namespace OpenEphys.Onix1.Design
{
Expand Down
2 changes: 1 addition & 1 deletion OpenEphys.Onix1.Design/DesignHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down
39 changes: 39 additions & 0 deletions OpenEphys.Onix1.Design/NeuropixelsV1eBno055Dialog.Designer.cs

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

42 changes: 42 additions & 0 deletions OpenEphys.Onix1.Design/NeuropixelsV1eBno055Dialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;

namespace OpenEphys.Onix1.Design
{
/// <summary>
/// Partial class to create a GUI for <see cref="ConfigureNeuropixelsV1eBno055"/>.
/// </summary>
public partial class NeuropixelsV1eBno055Dialog : GenericDeviceDialog
{
/// <summary>
/// Gets or sets the <see cref="ConfigureNeuropixelsV1eBno055"/> object attached to
/// the property grid.
/// </summary>
public ConfigureNeuropixelsV1eBno055 ConfigureNode
{
get => (ConfigureNeuropixelsV1eBno055)propertyGrid.SelectedObject;
set => propertyGrid.SelectedObject = value;
}

/// <summary>
/// Initializes a new <see cref="NeuropixelsV1eBno055Dialog"/> instance with the given
/// <see cref="ConfigureNeuropixelsV1eBno055"/> object.
/// </summary>
/// <param name="configureNode">A <see cref="ConfigureNeuropixelsV1eBno055"/> object that contains configuration settings.</param>
public NeuropixelsV1eBno055Dialog(ConfigureNeuropixelsV1eBno055 configureNode)
{
InitializeComponent();
Shown += FormShown;

ConfigureNode = new(configureNode);
}

private void FormShown(object sender, EventArgs e)
{
if (!TopLevel)
{
splitContainer1.Panel2Collapsed = true;
splitContainer1.Panel2.Hide();
}
}
}
}
31 changes: 31 additions & 0 deletions OpenEphys.Onix1.Design/NeuropixelsV1eBno055Editor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.ComponentModel;
using Bonsai.Design;
using System.Windows.Forms;

namespace OpenEphys.Onix1.Design
{
internal class NeuropixelsV1eBno055Editor : WorkflowComponentEditor
{
public override bool EditComponent(ITypeDescriptorContext context, object component, IServiceProvider provider, IWin32Window owner)
{
if (provider != null)
{
var editorState = (IWorkflowEditorState)provider.GetService(typeof(IWorkflowEditorState));
if (editorState != null && !editorState.WorkflowRunning && component is ConfigureNeuropixelsV1eBno055 configureBno055)
{
using var editorDialog = new NeuropixelsV1eBno055Dialog(configureBno055);

if (editorDialog.ShowDialog() == DialogResult.OK)
{
configureBno055.Enable = editorDialog.ConfigureNode.Enable;

return true;
}
}
}

return false;
}
}
}

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

Loading