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
167 changes: 30 additions & 137 deletions OpenEphys.Onix1.Design/ChannelConfigurationDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public partial class ChannelConfigurationDialog : Form
{
internal event EventHandler OnResizeZedGraph;
internal event EventHandler OnDrawProbeGroup;
internal event EventHandler OnMoveProbeGroup;

ProbeGroup probeGroup;

Expand Down Expand Up @@ -65,15 +66,6 @@ public ChannelConfigurationDialog(ProbeGroup probeGroup)
zedGraphChannels.MouseMoveEvent += MouseMoveEvent;
zedGraphChannels.MouseUpEvent += MouseUpEvent;

if (IsDrawScale())
{
var pane = new GraphPane();

InitializeScalePane(pane);

zedGraphChannels.MasterPane.Add(pane);
}

InitializeZedGraphControl(zedGraphChannels);
InitializeProbePane(zedGraphChannels.GraphPane);

Expand Down Expand Up @@ -131,15 +123,6 @@ internal virtual void ZoomEvent(ZedGraphControl sender, ZoomState oldState, Zoom
sender.ZoomOut(sender.GraphPane);
}
}

if (IsDrawScale())
SyncYAxes(zedGraphChannels.MasterPane.PaneList[0], zedGraphChannels.MasterPane.PaneList[1]);
}

static void SyncYAxes(GraphPane source, GraphPane target)
{
target.YAxis.Scale.Min = source.YAxis.Scale.Min;
target.YAxis.Scale.Max = source.YAxis.Scale.Max;
}

private void SetEqualAxisLimits(ZedGraphControl zedGraphControl)
Expand Down Expand Up @@ -359,14 +342,17 @@ internal void DrawProbeGroup()
HighlightSelectedContacts();
DrawContactLabels();

if (IsDrawScale())
{
DrawScale();
}

OnDrawProbeGroupHandler();
}

internal void UpdateProbeGroup()
{
HighlightEnabledContacts();
HighlightSelectedContacts();
UpdateContactLabels();
RefreshZedGraph();
}

void OnDrawProbeGroupHandler()
{
OnDrawProbeGroup?.Invoke(this, EventArgs.Empty);
Expand Down Expand Up @@ -670,10 +656,6 @@ internal virtual string ContactString(int deviceChannelIndex, int index)
return deviceChannelIndex == -1 ? DisabledContactString : index.ToString();
}

internal virtual bool IsDrawScale() => false;

internal virtual void DrawScale() { }

internal void UpdateFontSize()
{
var fontSize = CalculateFontSize();
Expand Down Expand Up @@ -849,78 +831,18 @@ static void InitializeZedGraphControl(ZedGraphControl zedGraph)
EnableZoom(zedGraph);
}

static void EnablePan(ZedGraphControl zedGraph)
internal static void EnablePan(ZedGraphControl zedGraph)
{
zedGraph.IsEnableHPan = true;
zedGraph.IsEnableVPan = true;
}

static void DisablePan(ZedGraphControl zedGraph)
{
zedGraph.IsEnableHPan = false;
zedGraph.IsEnableVPan = false;
}

static void EnableZoom(ZedGraphControl zedGraph)
internal static void EnableZoom(ZedGraphControl zedGraph)
{
zedGraph.IsEnableZoom = true;
zedGraph.IsEnableWheelZoom = true;
}

static void DisableZoom(ZedGraphControl zedGraph)
{
zedGraph.IsEnableZoom = false;
zedGraph.IsEnableWheelZoom = false;
}

static void InitializeScalePane(GraphPane pane)
{
pane.Title.IsVisible = false;
pane.TitleGap = 0;
pane.Border.IsVisible = false;
pane.Border.Width = 0;
pane.Chart.Border.IsVisible = false;
pane.Margin.All = 0;

pane.Y2Axis.IsVisible = false;

pane.XAxis.IsVisible = false;
pane.XAxis.IsAxisSegmentVisible = false;
pane.XAxis.Scale.MaxAuto = true;
pane.XAxis.Scale.MinAuto = true;
pane.XAxis.MajorGrid.IsZeroLine = false;
pane.XAxis.CrossAuto = false;
pane.XAxis.Cross = double.MinValue;

pane.YAxis.IsVisible = true;
pane.YAxis.IsAxisSegmentVisible = true;
pane.YAxis.Scale.MaxAuto = true;
pane.YAxis.Scale.MinAuto = true;
pane.YAxis.CrossAuto = false;
pane.YAxis.Cross = double.MinValue;

pane.YAxis.MajorGrid.IsZeroLine = false;
pane.YAxis.MajorGrid.IsVisible = false;
pane.YAxis.MinorGrid.IsVisible = false;

pane.YAxis.Scale.IsPreventLabelOverlap = true;
pane.YAxis.Scale.MajorStep = 100;
pane.YAxis.Scale.IsLabelsInside = true;
pane.YAxis.Scale.FontSpec.Size = 65f;
pane.YAxis.Scale.FontSpec.IsBold = false;
pane.YAxis.Scale.LabelGap = 0.6f;

pane.YAxis.MinorTic.IsInside = false;
pane.YAxis.MinorTic.IsOutside = false;
pane.YAxis.MinorTic.IsOpposite = false;

pane.YAxis.MajorTic.IsInside = true;
pane.YAxis.MajorTic.IsOutside = false;
pane.YAxis.MajorTic.IsOpposite = false;
pane.YAxis.MajorTic.Size = 40f;
pane.YAxis.MajorTic.PenWidth = 1.5f;
}

static void InitializeProbePane(GraphPane graphPane)
{
graphPane.Title.IsVisible = false;
Expand Down Expand Up @@ -976,62 +898,44 @@ private void ZedGraphChannels_Resize(object sender, EventArgs e)
internal void ResizeZedGraph()
{
ResizeAxes();

if (IsDrawScale())
{
var rect = zedGraphChannels.MasterPane.Rect;

float squareSize = rect.Height;

zedGraphChannels.MasterPane.PaneList[0].Rect = new RectangleF(rect.Left, rect.Top, squareSize, squareSize);
zedGraphChannels.MasterPane.PaneList[1].Rect = new RectangleF(rect.Left + squareSize, rect.Top, rect.Width - squareSize, squareSize);
}
OnResizeHandler();

UpdateFontSize();
RefreshZedGraph();
Update();
OnResizeHandler();
}

private void OnResizeHandler()
{
OnResizeZedGraph?.Invoke(this, EventArgs.Empty);
}

void ResizeAxes()
internal virtual void ResizeAxes()
{
float scalingFactor = IsDrawScale() ? 1.15f : 1.0f;
RectangleF rect = IsDrawScale() ? zedGraphChannels.MasterPane.Rect : zedGraphChannels.GraphPane.Rect;
RectangleF rect = zedGraphChannels.GraphPane.Rect;

float width = rect.Width;
float height = rect.Height;

float desiredWidth = height * scalingFactor;

if (width < desiredWidth)
if (width < height)
{
height = width / scalingFactor;
height = width;
}
else
{
width = desiredWidth;
width = height;
}

float x = MathF.Round(rect.Left + (rect.Width - width) / 2f);
float y = MathF.Round(rect.Top + (rect.Height - height) / 2f);

var newRect = new RectangleF(x, y, width, height);

if (IsDrawScale())
zedGraphChannels.MasterPane.Rect = newRect;
else
{
zedGraphChannels.GraphPane.Rect = newRect;
DisconnectResizeEventHandler();
zedGraphChannels.Size = new Size((int)newRect.Width, (int)newRect.Height);
zedGraphChannels.Location = new Point((int)newRect.X, (int)newRect.Y);
ConnectResizeEventHandler();
}
zedGraphChannels.GraphPane.Rect = newRect;
DisconnectResizeEventHandler();
zedGraphChannels.Size = new Size((int)newRect.Width, (int)newRect.Height);
zedGraphChannels.Location = new Point((int)newRect.X, (int)newRect.Y);
ConnectResizeEventHandler();
}

private void MenuItemOpenFile(object sender, EventArgs e)
Expand Down Expand Up @@ -1070,6 +974,11 @@ internal void ResetZoom()
UpdateFontSize();
}

void OnMoveProbeGroupHandler()
{
OnMoveProbeGroup?.Invoke(this, EventArgs.Empty);
}

/// <summary>
/// Shifts the whole ZedGraph to the given relative position, where 0.0 is the very bottom of the horizontal
/// space, and 1.0 is the very top. Note that this accounts for a buffer on the top and bottom, so giving a
Expand All @@ -1096,8 +1005,7 @@ public void MoveToVerticalPosition(float relativePosition)
zedGraphChannels.GraphPane.YAxis.Scale.Min = newMinY;
zedGraphChannels.GraphPane.YAxis.Scale.Max = newMinY + currentRange;

if (IsDrawScale())
SyncYAxes(zedGraphChannels.MasterPane.PaneList[0], zedGraphChannels.MasterPane.PaneList[1]);
OnMoveProbeGroupHandler();
}

internal float GetRelativeVerticalPosition()
Expand Down Expand Up @@ -1171,28 +1079,14 @@ private bool MouseMoveEvent(ZedGraphControl sender, MouseEventArgs e)
}
else if (e.Button == MouseButtons.Middle)
{
if (IsDrawScale())
SyncYAxes(zedGraphChannels.MasterPane.PaneList[0], zedGraphChannels.MasterPane.PaneList[1]);
OnMoveProbeGroupHandler();

return false;
}
else if (e.Button == MouseButtons.None)
{
sender.Cursor = Cursors.Arrow;

var currentPane = sender.MasterPane.FindPane(new PointF(e.X, e.Y));

if (currentPane == sender.MasterPane.PaneList[0])
{
EnablePan(sender);
EnableZoom(sender);
}
else if (IsDrawScale() && currentPane == sender.MasterPane.PaneList[1])
{
DisablePan(sender);
DisableZoom(sender);
}

return true;
}

Expand Down Expand Up @@ -1347,8 +1241,7 @@ private void ButtonResetZoom_Click(object sender, EventArgs e)
{
ResetZoom();

if (IsDrawScale())
SyncYAxes(zedGraphChannels.MasterPane.PaneList[0], zedGraphChannels.MasterPane.PaneList[1]);
OnMoveProbeGroupHandler();

RefreshZedGraph();
}
Expand Down
4 changes: 2 additions & 2 deletions OpenEphys.Onix1.Design/DesignHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static Form AddMenuItemsFromDialogToFileOption(this Form thisForm, Form c

if (childForm != null)
{
var childMenuStrip = childForm.GetAllControls()
var childMenuStrip = childForm.GetTopLevelControls()
.OfType<MenuStrip>()
.FirstOrDefault() ?? throw new InvalidOperationException($"There are no menu strips in any child controls of the {childForm.Text} dialog.");

Expand Down Expand Up @@ -97,7 +97,7 @@ public static Form AddMenuItemsFromDialogToFileOption(this Form thisForm, Form c

if (childForm != null)
{
var childMenuStrip = childForm.GetAllControls()
var childMenuStrip = childForm.GetTopLevelControls()
.OfType<MenuStrip>()
.First() ?? throw new InvalidOperationException($"There are no menu strips in any child controls of the {childForm.Text} dialog.");

Expand Down
Loading