Skip to content

Commit

Permalink
Explicitly define orientation of Rhs2116 channel configuration
Browse files Browse the repository at this point in the history
- Added contact annotation labels to the default configuration that aligns with documentation images (i.e., A1 / B1 / etc.)
- Added a label to the top of the image that defines the side of the PCB that contains the tether
bparks13 committed Dec 18, 2024
1 parent 74f6f22 commit eb74c92
Showing 6 changed files with 115 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<UseArtifactsOutput>true</UseArtifactsOutput>
<PackageIcon>icon.png</PackageIcon>
<VersionPrefix>0.4.2</VersionPrefix>
<VersionPrefix>0.4.3</VersionPrefix>
<VersionSuffix></VersionSuffix>
<LangVersion>10.0</LangVersion>
<Features>strict</Features>
23 changes: 18 additions & 5 deletions OpenEphys.Onix1.Design/ChannelConfigurationDialog.cs
Original file line number Diff line number Diff line change
@@ -739,8 +739,6 @@ internal virtual void DrawContactLabels()

zedGraphChannels.GraphPane.GraphObjList.RemoveAll(obj => obj is TextObj && obj.Tag is ContactTag);

var fontSize = CalculateFontSize(0.5);

int probeNumber = 0;
int indexOffset = 0;

@@ -757,7 +755,7 @@ internal virtual void DrawContactLabels()
Tag = new ContactTag(probeNumber, i)
};

SetTextObj(textObj, fontSize);
SetTextObj(textObj);

textObj.FontSpec.FontColor = indices[i] == -1 ? DisabledContactTextColor : EnabledContactTextColor;

@@ -769,13 +767,12 @@ internal virtual void DrawContactLabels()
}
}

internal void SetTextObj(TextObj textObj, float fontSize)
internal void SetTextObj(TextObj textObj)
{
textObj.FontSpec.IsBold = true;
textObj.FontSpec.Border.IsVisible = false;
textObj.FontSpec.Fill.IsVisible = false;
textObj.FontSpec.Fill.IsVisible = false;
textObj.FontSpec.Size = fontSize;
}

const string DisabledContactString = "Off";
@@ -1086,6 +1083,7 @@ private void MenuItemLoadDefaultConfig(object sender, EventArgs e)
{
LoadDefaultChannelLayout();
DrawProbeGroup();
UpdateFontSize();
RefreshZedGraph();
}

@@ -1339,5 +1337,20 @@ private static PointD TransformPixelsToCoordinates(Point pixels, GraphPane graph

return new PointD(x, y);
}

internal static bool HasContactAnnotations(ProbeGroup probeGroup)
{
foreach (var probe in probeGroup.Probes)
{
if (probe.ContactAnnotations != null
&& probe.ContactAnnotations.Annotations != null
&& probe.ContactAnnotations.Annotations.Length > 0)
{
return true;
}
}

return false;
}
}
}
2 changes: 1 addition & 1 deletion OpenEphys.Onix1.Design/OpenEphys.Onix1.Design.csproj
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
<PackageReference Include="Bonsai.Design" Version="2.8.5" />
<PackageReference Include="Bonsai.Design.Visualizers" Version="2.8.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="OpenEphys.ProbeInterface.NET" Version="0.2.0" />
<PackageReference Include="OpenEphys.ProbeInterface.NET" Version="0.3.0" />
<PackageReference Include="ZedGraph" Version="5.1.7" />
</ItemGroup>

68 changes: 66 additions & 2 deletions OpenEphys.Onix1.Design/Rhs2116ChannelConfigurationDialog.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Linq;
using System.Windows.Forms;
using Newtonsoft.Json;
using OpenEphys.ProbeInterface.NET;
using ZedGraph;

@@ -67,9 +69,71 @@ private void OnZoomHandler()
OnZoom?.Invoke(this, EventArgs.Empty);
}

internal override float CalculateFontSize(double _)
internal override float CalculateFontSize(double scale)
{
return base.CalculateFontSize(1.35);
scale *= HasContactAnnotations(ProbeGroup) ? 0.5 : 1;
return base.CalculateFontSize(1.35 * scale);
}

internal override string ContactString(int deviceChannelIndex, int index)
{
string s = base.ContactString(deviceChannelIndex, index);

int indexOffset = 0;
int probeIndex = 0;

foreach (var probe in ProbeGroup.Probes)
{
if (probe.NumberOfContacts - 1 + indexOffset < index)
{
indexOffset += probe.NumberOfContacts;
probeIndex++;
}
else break;
}

int currentIndex = index - indexOffset;

var currentProbe = ProbeGroup.Probes.ElementAt(probeIndex);

if (currentProbe.ContactAnnotations != null
&& currentProbe.ContactAnnotations.Annotations != null
&& currentProbe.ContactAnnotations.Annotations.Length > currentIndex)
{
s += "\n" + currentProbe.ContactAnnotations.Annotations[currentIndex];
}

return s;
}

// NB: Currently there is only a text label drawn as the scale for this dialog, used to denote the
// absolute orientation of the default probe group
internal override void DrawScale()
{
const string scaleTag = "scale";

zedGraphChannels.GraphPane.GraphObjList.RemoveAll(obj => obj.Tag is string tag && tag == scaleTag);

bool isDefault = JsonConvert.SerializeObject(ProbeGroup) == JsonConvert.SerializeObject(new Rhs2116ProbeGroup());

if (isDefault)
{
var middle = GetProbeContourLeft(zedGraphChannels.GraphPane.GraphObjList)
+ (GetProbeContourRight(zedGraphChannels.GraphPane.GraphObjList) - GetProbeContourLeft(zedGraphChannels.GraphPane.GraphObjList)) / 2;
var top = GetProbeContourTop(zedGraphChannels.GraphPane.GraphObjList);

TextObj textObj = new("Tether Side", middle, top + 0.5, CoordType.AxisXYScale, AlignH.Center, AlignV.Center)
{
ZOrder = ZOrder.A_InFront,
Tag = scaleTag
};

SetTextObj(textObj);

textObj.FontSpec.Size = CalculateFontSize(4.0);

zedGraphChannels.GraphPane.GraphObjList.Add(textObj);
}
}
}
}
2 changes: 1 addition & 1 deletion OpenEphys.Onix1/OpenEphys.Onix1.csproj
Original file line number Diff line number Diff line change
@@ -13,6 +13,6 @@
<PackageReference Include="Bonsai.Core" Version="2.8.5" />
<PackageReference Include="clroni" Version="6.1.2" />
<PackageReference Include="OpenCV.Net" Version="3.4.2" />
<PackageReference Include="OpenEphys.ProbeInterface.NET" Version="0.2.0" />
<PackageReference Include="OpenEphys.ProbeInterface.NET" Version="0.3.0" />
</ItemGroup>
</Project>
30 changes: 28 additions & 2 deletions OpenEphys.Onix1/Rhs2116ProbeGroup.cs
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ private static Probe[] DefaultProbes()
probe[0] = new(ProbeNdim.Two,
ProbeSiUnits.mm,
new ProbeAnnotations("Rhs2116A", ""),
null,
DefaultContactAnnotations(DefaultNumberOfChannelsPerProbe, 0),
DefaultContactPositions(DefaultNumberOfChannelsPerProbe, 0),
Probe.DefaultContactPlaneAxes(DefaultNumberOfChannelsPerProbe),
Probe.DefaultContactShapes(DefaultNumberOfChannelsPerProbe, ContactShape.Circle),
@@ -44,7 +44,7 @@ private static Probe[] DefaultProbes()
probe[1] = new(ProbeNdim.Two,
ProbeSiUnits.mm,
new ProbeAnnotations("Rhs2116B", ""),
null,
DefaultContactAnnotations(DefaultNumberOfChannelsPerProbe, 1),
DefaultContactPositions(DefaultNumberOfChannelsPerProbe, 1),
Probe.DefaultContactPlaneAxes(DefaultNumberOfChannelsPerProbe),
Probe.DefaultContactShapes(DefaultNumberOfChannelsPerProbe, ContactShape.Circle),
@@ -82,6 +82,32 @@ public Rhs2116ProbeGroup(Rhs2116ProbeGroup probeGroup)
{
}

internal static ContactAnnotations DefaultContactAnnotations(int numberOfChannels, int probeIndex)
{
string[] contactAnnotations = new string[numberOfChannels];

if (probeIndex == 0)
{
for (int i = 0; i < numberOfChannels; i++)
{
contactAnnotations[i] = "A" + i.ToString();
}
}
else if (probeIndex == 1)
{
for (int i = 0; i < numberOfChannels; i++)
{
contactAnnotations[i] = "B" + i.ToString();
}
}
else
{
throw new InvalidOperationException($"Probe {probeIndex} is invalid for getting default contact annotations for {nameof(Rhs2116ProbeGroup)}");
}

return new(contactAnnotations);
}

internal static float[][] DefaultContactPositions(int numberOfChannels, int probeIndex)
{
float[][] contactPositions = new float[numberOfChannels][];

0 comments on commit eb74c92

Please sign in to comment.