Skip to content

Commit de8004a

Browse files
committed
Save zoom state when writing stimulus parameters
1 parent 4fd9cb5 commit de8004a

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

OpenEphys.Onix1.Design/Rhs2116StimulusSequenceDialog.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using System;
22
using System.Drawing;
3+
using System.IO;
34
using System.Linq;
45
using System.Windows.Forms;
56
using ZedGraph;
6-
using System.IO;
77

88
namespace OpenEphys.Onix1.Design
99
{
@@ -74,7 +74,7 @@ public Rhs2116StimulusSequenceDialog(Rhs2116StimulusSequencePair sequence, Rhs21
7474
}
7575

7676
InitializeZedGraphWaveform();
77-
DrawStimulusWaveform();
77+
DrawStimulusWaveform(false);
7878

7979
zedGraphWaveform.ZoomEvent += OnZoom_Waveform;
8080
zedGraphWaveform.MouseMoveEvent += MouseMoveEvent;
@@ -262,12 +262,20 @@ private double GetPeakToPeakAmplitudeInMicroAmps()
262262
: Sequence.CurrentStepSizeuA * 1; // NB: Used to give a buffer when plotting the stimulus waveform
263263
}
264264

265-
private void DrawStimulusWaveform()
265+
private void DrawStimulusWaveform(bool setZoomState = true)
266266
{
267267
bool plotAllContacts = ChannelDialog.SelectedContacts.All(x => x == false);
268268

269269
zedGraphWaveform.GraphPane.CurveList.Clear();
270270
zedGraphWaveform.GraphPane.GraphObjList.Clear();
271+
272+
var (XMin, XMax, YMin, YMax)= (
273+
zedGraphWaveform.GraphPane.XAxis.Scale.Min,
274+
zedGraphWaveform.GraphPane.XAxis.Scale.Max,
275+
zedGraphWaveform.GraphPane.YAxis.Scale.Min,
276+
zedGraphWaveform.GraphPane.YAxis.Scale.Max
277+
);
278+
271279
zedGraphWaveform.ZoomOutAll(zedGraphWaveform.GraphPane);
272280

273281
double peakToPeak = GetPeakToPeakAmplitudeInMicroAmps() * 1.1;
@@ -316,19 +324,30 @@ private void DrawStimulusWaveform()
316324
zedGraphWaveform.GraphPane.YAxis.Scale.Min = -Sequence.Stimuli.Length - 2;
317325
zedGraphWaveform.GraphPane.YAxis.Scale.Max = 1;
318326

319-
zedGraphWaveform.GraphPane.YAxis.ScaleFormatEvent += (GraphPane gp, Axis axis, double val, int index) =>
327+
zedGraphWaveform.GraphPane.YAxis.ScaleFormatEvent += (gp, axis, val, index) =>
320328
{
321329
return Math.Abs(val).ToString("0");
322330
};
323331

324-
DrawScale();
325-
326332
SetZoomOutBoundaries(zedGraphWaveform);
327333

328334
ZoomInBoundaryX = (ZoomOutBoundaryRight - ZoomOutBoundaryLeft) * 0.05;
329335

330336
dataGridViewStimulusTable.Refresh();
331337

338+
if (setZoomState)
339+
{
340+
zedGraphWaveform.GraphPane.XAxis.Scale.Min = XMin;
341+
zedGraphWaveform.GraphPane.XAxis.Scale.Max = XMax;
342+
zedGraphWaveform.GraphPane.YAxis.Scale.Min = YMin;
343+
zedGraphWaveform.GraphPane.YAxis.Scale.Max = YMax;
344+
}
345+
346+
if (!CheckZoomBoundaries(zedGraphWaveform))
347+
zedGraphWaveform.ZoomOutAll(zedGraphWaveform.GraphPane);
348+
349+
DrawScale();
350+
332351
zedGraphWaveform.AxisChange();
333352
zedGraphWaveform.Refresh();
334353
}

0 commit comments

Comments
 (0)