Skip to content

Commit 9ea1b94

Browse files
committed
Move scale to second pane
- Only applies for dialogs that need to draw a scale (such as NeuropixelsV1e/V1f and NeuropixelsV2e/V2eBeta) - Updated the logic for constraining pan/zoom in all dialogs so that the probe is always in view - Standardized dialog sizes for consistency
1 parent 6677a31 commit 9ea1b94

10 files changed

+381
-547
lines changed

OpenEphys.Onix1.Design/ChannelConfigurationDialog.cs

Lines changed: 239 additions & 229 deletions
Large diffs are not rendered by default.

OpenEphys.Onix1.Design/NeuropixelsV1ChannelConfigurationDialog.cs

Lines changed: 11 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Drawing;
43
using System.Linq;
54
using System.Windows.Forms;
65
using OpenEphys.ProbeInterface.NET;
@@ -40,8 +39,8 @@ public NeuropixelsV1ChannelConfigurationDialog(NeuropixelsV1ProbeConfiguration p
4039

4140
ProbeConfiguration = probeConfiguration;
4241

43-
ZoomInBoundaryX = 400;
44-
ZoomInBoundaryY = 400;
42+
ZoomInBoundaryX = 200;
43+
ZoomInBoundaryY = 200;
4544

4645
HighlightEnabledContacts();
4746
UpdateContactLabels();
@@ -87,7 +86,6 @@ internal override void ZoomEvent(ZedGraphControl sender, ZoomState oldState, Zoo
8786
base.ZoomEvent(sender, oldState, newState);
8887

8988
UpdateFontSize();
90-
DrawScale();
9189
RefreshZedGraph();
9290

9391
OnZoomHandler();
@@ -98,90 +96,21 @@ private void OnZoomHandler()
9896
OnZoom?.Invoke(this, EventArgs.Empty);
9997
}
10098

99+
internal override bool IsDrawScale() => true;
100+
101101
internal override void DrawScale()
102102
{
103-
if (ProbeConfiguration == null)
103+
if (ProbeConfiguration == null || zedGraphChannels.MasterPane.PaneList.Count < 2)
104104
return;
105105

106-
const string ScalePointsTag = "scale_points";
107-
const string ScaleTextTag = "scale_text";
108-
109-
zedGraphChannels.GraphPane.GraphObjList.RemoveAll(obj => obj is TextObj && obj.Tag is string tag && tag == ScaleTextTag);
110-
zedGraphChannels.GraphPane.CurveList.RemoveAll(curve => curve.Tag is string tag && tag == ScalePointsTag);
111-
112-
const int MajorTickIncrement = 100;
113-
const int MajorTickLength = 10;
114-
const int MinorTickIncrement = 10;
115-
const int MinorTickLength = 5;
116-
117-
if (ProbeConfiguration.ProbeGroup.Probes.ElementAt(0).SiUnits != ProbeSiUnits.um)
118-
{
119-
MessageBox.Show("Warning: Expected ProbeGroup units to be in microns, but it is in millimeters. Scale might not be accurate.");
120-
}
121-
122-
var fontSize = CalculateFontSize();
123-
124-
var zoomedOut = fontSize <= 2;
125-
126-
fontSize = zoomedOut ? 6 : fontSize * 3;
127-
var majorTickOffset = MajorTickLength + CalculateScaleRange(zedGraphChannels.GraphPane.XAxis.Scale) * 0.015;
128-
majorTickOffset = majorTickOffset > 50 ? 50 : majorTickOffset;
129-
130-
var x = GetProbeRight(zedGraphChannels.GraphPane.GraphObjList) + 40;
131-
var minY = GetProbeBottom(zedGraphChannels.GraphPane.GraphObjList);
132-
var maxY = GetProbeTop(zedGraphChannels.GraphPane.GraphObjList);
133-
134-
int textPosition = 0;
135-
136-
PointPairList pointList = new();
137-
138-
var countMajorTicks = 0;
139-
140-
for (int i = (int)minY; i < maxY; i += MajorTickIncrement)
141-
{
142-
PointPair majorTickLocation = new(x + MajorTickLength, minY + MajorTickIncrement * countMajorTicks);
143-
144-
pointList.Add(new PointPair(x, minY + MajorTickIncrement * countMajorTicks));
145-
pointList.Add(majorTickLocation);
146-
pointList.Add(new PointPair(x, minY + MajorTickIncrement * countMajorTicks));
147-
148-
if (!zoomedOut || countMajorTicks % 5 == 0)
149-
{
150-
TextObj textObj = new($"{textPosition} µm", majorTickLocation.X + 10, majorTickLocation.Y, CoordType.AxisXYScale, AlignH.Left, AlignV.Center)
151-
{
152-
Tag = ScaleTextTag
153-
};
154-
textObj.FontSpec.Border.IsVisible = false;
155-
textObj.FontSpec.Size = fontSize;
156-
zedGraphChannels.GraphPane.GraphObjList.Add(textObj);
157-
158-
textPosition += zoomedOut ? 5 * MajorTickIncrement : MajorTickIncrement;
159-
}
160-
161-
if (!zoomedOut)
162-
{
163-
var countMinorTicks = 1;
164-
165-
for (int j = i + MinorTickIncrement; j < i + MajorTickIncrement && i + MinorTickIncrement * countMinorTicks < maxY; j += MinorTickIncrement)
166-
{
167-
pointList.Add(new PointPair(x, minY + MajorTickIncrement * countMajorTicks + MinorTickIncrement * countMinorTicks));
168-
pointList.Add(new PointPair(x + MinorTickLength, minY + MajorTickIncrement * countMajorTicks + MinorTickIncrement * countMinorTicks));
169-
pointList.Add(new PointPair(x, minY + MajorTickIncrement * countMajorTicks + MinorTickIncrement * countMinorTicks));
170-
171-
countMinorTicks++;
172-
}
173-
}
174-
175-
countMajorTicks++;
176-
}
177-
178-
var curve = zedGraphChannels.GraphPane.AddCurve(ScalePointsTag, pointList, Color.Black, SymbolType.None);
106+
var pane = zedGraphChannels.MasterPane.PaneList[1];
179107

180-
const float scaleBarWidth = 1;
108+
pane.YAxis.Scale.Min = GetProbeBottom(zedGraphChannels.GraphPane.GraphObjList);
109+
pane.YAxis.Scale.Max = GetProbeTop(zedGraphChannels.GraphPane.GraphObjList);
181110

182-
curve.Line.Width = scaleBarWidth;
183-
curve.Label.IsVisible = false;
184-
curve.Symbol.IsVisible = false;
111+
pane.YAxis.Scale.Format = "#####0' " + ProbeGroup.Probes.First().SiUnits.ToString() + "'";
112+
pane.YAxis.Scale.Mag = 0;
113+
pane.YAxis.Scale.MagAuto = false;
185114
}
186115

187116
internal override void HighlightEnabledContacts()

OpenEphys.Onix1.Design/NeuropixelsV1ProbeConfigurationDialog.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ private void FormShown(object sender, EventArgs e)
115115
}
116116

117117
ChannelConfiguration.Show();
118-
ChannelConfiguration.ConnectResizeEventHandler();
119118
ChannelConfiguration.OnResizeZedGraph += ResizeTrackBar;
120119
}
121120

@@ -317,22 +316,22 @@ private void CheckStatus()
317316

318317
panelProbe.Visible = adcCalibration.HasValue && gainCorrection.HasValue;
319318

320-
if (toolStripAdcCalSN.Text == NoFileSelected)
319+
if (toolStripAdcCalSN.Text == NoFileSelected)
321320
toolStripLabelAdcCalibrationSN.Image = Properties.Resources.StatusWarningImage;
322-
else if (toolStripAdcCalSN.Text == InvalidFile)
321+
else if (toolStripAdcCalSN.Text == InvalidFile)
323322
toolStripLabelAdcCalibrationSN.Image = Properties.Resources.StatusCriticalImage;
324323
else if (toolStripGainCalSN.Text != NoFileSelected && toolStripGainCalSN.Text != InvalidFile && toolStripAdcCalSN.Text != toolStripGainCalSN.Text)
325324
toolStripLabelAdcCalibrationSN.Image = Properties.Resources.StatusBlockedImage;
326-
else
325+
else
327326
toolStripLabelAdcCalibrationSN.Image = Properties.Resources.StatusReadyImage;
328327

329-
if (toolStripGainCalSN.Text == NoFileSelected)
328+
if (toolStripGainCalSN.Text == NoFileSelected)
330329
toolStripLabelGainCalibrationSn.Image = Properties.Resources.StatusWarningImage;
331-
else if (toolStripGainCalSN.Text == InvalidFile)
330+
else if (toolStripGainCalSN.Text == InvalidFile)
332331
toolStripLabelGainCalibrationSn.Image = Properties.Resources.StatusCriticalImage;
333332
else if (toolStripAdcCalSN.Text != NoFileSelected && toolStripAdcCalSN.Text != InvalidFile && toolStripAdcCalSN.Text != toolStripGainCalSN.Text)
334333
toolStripLabelGainCalibrationSn.Image = Properties.Resources.StatusBlockedImage;
335-
else
334+
else
336335
toolStripLabelGainCalibrationSn.Image = Properties.Resources.StatusReadyImage;
337336
}
338337

@@ -455,7 +454,6 @@ private void ResetZoom()
455454
{
456455
ChannelConfiguration.ResetZoom();
457456
ChannelConfiguration.RefreshZedGraph();
458-
ChannelConfiguration.DrawScale();
459457
}
460458

461459
private void MoveToVerticalPosition(float relativePosition)

OpenEphys.Onix1.Design/NeuropixelsV1eHeadstageDialog.Designer.cs

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)