Skip to content
Open
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
47 changes: 25 additions & 22 deletions OpenEphys.Onix1.Design/GenericStimulusSequenceDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ internal void OnSelect(object sender, EventArgs e)

void OnZoom_Waveform(ZedGraphControl sender, ZoomState oldState, ZoomState newState)
{
if (newState.Type == ZoomState.StateType.WheelZoom && sender.IsEnableHZoom && sender.IsEnableVZoom)
if (newState.Type == ZoomState.StateType.WheelZoom)
{
CenterAxesOnCursor(sender);
CenterAxesOnCursor(sender, sender.IsEnableHZoom, sender.IsEnableVZoom);
}

DrawScale();
Expand Down Expand Up @@ -207,7 +207,7 @@ internal void DrawStimulusWaveform(bool setZoomState = true)

zedGraphWaveform.GraphPane.YAxis.ScaleFormatEvent += (gp, axis, val, index) =>
{
return Math.Abs(val).ToString("0");
return val <= 0 ? Math.Abs(val).ToString("0") : "";
};

dataGridViewStimulusTable.Refresh();
Expand All @@ -226,10 +226,10 @@ internal void DrawStimulusWaveform(bool setZoomState = true)
zedGraphWaveform.Refresh();
}

internal string yAxisScaleUnits = "µA";
internal string xAxisScaleUnits = "ms";
internal virtual double GetPeakToPeakAmplitudeInMicroAmps() => throw new NotImplementedException();

internal string yAxisScale = "µA";

void DrawScale()
{
const string scaleString = "scale";
Expand Down Expand Up @@ -282,13 +282,13 @@ void DrawScale()

const double TextObjScaleFactor = 1.02;

TextObj timeScale = new(GetTimeScaleString(x) + " ms", zeroOffsetX + x * TextObjScaleFactor, zeroOffsetY, CoordType.AxisXYScale, AlignH.Left, AlignV.Center);
TextObj timeScale = new(GetTimeScaleString(x) + " " + xAxisScaleUnits, zeroOffsetX + x * TextObjScaleFactor, zeroOffsetY, CoordType.AxisXYScale, AlignH.Left, AlignV.Center);
timeScale.FontSpec.Border.IsVisible = false;
timeScale.FontSpec.Fill.IsVisible = false;
timeScale.ZOrder = ZOrder.A_InFront;
zedGraphWaveform.GraphPane.GraphObjList.Add(timeScale);

TextObj amplitudeScale = new(yScaleValue.ToString("0.##") + " µA", zeroOffsetX, zeroOffsetY + y * TextObjScaleFactor, CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom);
TextObj amplitudeScale = new(yScaleValue.ToString("0.##") + " " + yAxisScaleUnits, zeroOffsetX, zeroOffsetY + y * TextObjScaleFactor, CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom);
amplitudeScale.FontSpec.Border.IsVisible = false;
amplitudeScale.FontSpec.Fill.IsVisible = false;
amplitudeScale.ZOrder = ZOrder.A_InFront;
Expand All @@ -306,8 +306,7 @@ double GetTimeScaleString(double time)
< 10 => Math.Round(time, 1),
< 100 => Math.Round(time / 10, 1) * 10,
< 1000 => Math.Round(time / 100, 1) * 100,
< 10000 => Math.Round(time / 1000, 1) * 1000,
_ => time
_ => Math.Round(time / 1000, 1) * 1000
};
}

Expand Down Expand Up @@ -347,7 +346,6 @@ void InitializeZedGraphWaveform()
zedGraphWaveform.GraphPane.YAxis.Scale.IsSkipLastLabel = true;
zedGraphWaveform.GraphPane.YAxis.Scale.IsSkipFirstLabel = true;

zedGraphWaveform.GraphPane.XAxis.Title.Text = "Time [ms]";
zedGraphWaveform.GraphPane.YAxis.Title.Text = "Channel Number";

zedGraphWaveform.IsAutoScrollRange = true;
Expand Down Expand Up @@ -383,25 +381,30 @@ static PointD TransformPixelsToCoordinates(Point pixels, GraphPane graphPane)
return new PointD(x, y);
}

void CenterAxesOnCursor(ZedGraphControl zedGraphControl)
void CenterAxesOnCursor(ZedGraphControl zedGraphControl, bool hZoomEnabled, bool vZoomEnabled)
{
var mouseClientPosition = PointToClient(Cursor.Position);
mouseClientPosition.X -= (zedGraphControl.Parent.Width - zedGraphControl.Width) / 2;
mouseClientPosition.Y += (zedGraphControl.Parent.Height - zedGraphControl.Height) / 2;

var currentMousePosition = TransformPixelsToCoordinates(mouseClientPosition, zedGraphControl.GraphPane);

var centerX = CalculateScaleRange(zedGraphControl.GraphPane.XAxis.Scale) / 2 + zedGraphControl.GraphPane.XAxis.Scale.Min;
var centerY = CalculateScaleRange(zedGraphControl.GraphPane.YAxis.Scale) / 2 + zedGraphControl.GraphPane.YAxis.Scale.Min;
if (hZoomEnabled)
{
mouseClientPosition.X -= (zedGraphControl.Parent.Width - zedGraphControl.Width) / 2;
var centerX = CalculateScaleRange(zedGraphControl.GraphPane.XAxis.Scale) / 2 + zedGraphControl.GraphPane.XAxis.Scale.Min;
var diffX = centerX - currentMousePosition.X;

var diffX = centerX - currentMousePosition.X;
var diffY = centerY - currentMousePosition.Y;
zedGraphControl.GraphPane.XAxis.Scale.Min += diffX;
zedGraphControl.GraphPane.XAxis.Scale.Max += diffX;
}

zedGraphControl.GraphPane.XAxis.Scale.Min += diffX;
zedGraphControl.GraphPane.XAxis.Scale.Max += diffX;
if (vZoomEnabled)
{
mouseClientPosition.Y += (zedGraphControl.Parent.Height - zedGraphControl.Height) / 2;
var centerY = CalculateScaleRange(zedGraphControl.GraphPane.YAxis.Scale) / 2 + zedGraphControl.GraphPane.YAxis.Scale.Min;
var diffY = centerY - currentMousePosition.Y;

zedGraphControl.GraphPane.YAxis.Scale.Min += diffY;
zedGraphControl.GraphPane.YAxis.Scale.Max += diffY;
zedGraphControl.GraphPane.YAxis.Scale.Min += diffY;
zedGraphControl.GraphPane.YAxis.Scale.Max += diffY;
}
}

internal virtual bool IsSequenceValid()
Expand Down
13 changes: 13 additions & 0 deletions OpenEphys.Onix1.Design/Headstage64Dialog.Designer.cs

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

4 changes: 4 additions & 0 deletions OpenEphys.Onix1.Design/Headstage64Dialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public partial class Headstage64Dialog : Form
internal readonly GenericDeviceDialog Rhd2164Dialog;
internal readonly GenericDeviceDialog Bno055Dialog;
internal readonly GenericDeviceDialog TS4231V1Dialog;
internal readonly GenericDeviceDialog HeartbeatDialog;
internal readonly Headstage64ElectricalStimulatorSequenceDialog ElectricalStimulatorSequenceDialog;
internal readonly Headstage64OpticalStimulatorSequenceDialog OpticalStimulatorSequenceDialog;

Expand All @@ -31,6 +32,9 @@ public Headstage64Dialog(ConfigureHeadstage64 configureNode)
TS4231V1Dialog = new(new ConfigureTS4231V1(configureNode.TS4231));
TS4231V1Dialog.SetChildFormProperties(this).AddDialogToTab(tabPageTS4231);

HeartbeatDialog = new(new ConfigurePersistentHeartbeat(configureNode.Heartbeat));
HeartbeatDialog.SetChildFormProperties(this).AddDialogToTab(tabPageHeartbeat);

ElectricalStimulatorSequenceDialog = new(configureNode.ElectricalStimulator);
ElectricalStimulatorSequenceDialog.SetChildFormProperties(this).AddDialogToTab(tabPageElectricalStimulator);

Expand Down
1 change: 1 addition & 0 deletions OpenEphys.Onix1.Design/Headstage64Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public override bool EditComponent(ITypeDescriptorContext context, object compon
DesignHelper.CopyProperties((ConfigureRhd2164)editorDialog.Rhd2164Dialog.Device, configureNode.Rhd2164, DesignHelper.PropertiesToIgnore);
DesignHelper.CopyProperties((ConfigureBno055)editorDialog.Bno055Dialog.Device, configureNode.Bno055, DesignHelper.PropertiesToIgnore);
DesignHelper.CopyProperties((ConfigureTS4231V1)editorDialog.TS4231V1Dialog.Device, configureNode.TS4231, DesignHelper.PropertiesToIgnore);
DesignHelper.CopyProperties((ConfigurePersistentHeartbeat)editorDialog.HeartbeatDialog.Device, configureNode.Heartbeat, DesignHelper.PropertiesToIgnore);

if (editorDialog.ElectricalStimulatorSequenceDialog.DialogResult == DialogResult.OK)
configureNode.ElectricalStimulator = editorDialog.ElectricalStimulatorSequenceDialog.ElectricalStimulator;
Expand Down
Loading