using System.Threading.Tasks; using Avalonia; using Avalonia.Controls; using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.Layout; using Avalonia.Media; using OpenNest.Forms; namespace OpenNest.Avalonia { /// /// Calculate Cut Time's result, as the WinForms Timing Information window: cut time, cut and /// rapid distance, pierces and intersections, then the feed, rapid and pierce time used. /// internal sealed class TimingDialog : Window { private TimingDialog(CutTimeReport report) { Title = "Timing Information"; SizeToContent = SizeToContent.WidthAndHeight; MinWidth = 320; CanResize = false; ShowInTaskbar = false; WindowStartupLocation = WindowStartupLocation.CenterOwner; var rows = new (string Label, string Value, string Name)[] { ("Cut Time :", report.CutTimeText, "CutTime"), ("Cut Distance :", report.CutDistanceText, "CutDistance"), ("Rapid Distance :", report.RapidDistanceText, "RapidDistance"), ("# of Pierces :", report.PierceCountText, "Pierces"), ("# of Intersections :", report.IntersectionCountText, "Intersections"), (null, null, null), ("Feedrate :", report.FeedrateText, "Feedrate"), ("Rapid Feedrate :", report.RapidText, "Rapid"), ("Pierce Time :", report.PierceTimeText, "PierceTime"), }; var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*"), ColumnSpacing = 16, RowSpacing = 6 }; for (var i = 0; i < rows.Length; i++) { grid.RowDefinitions.Add(new RowDefinition(GridLength.Auto)); var (label, value, name) = rows[i]; if (label == null) { var line = new Border { Height = 1, Background = Brushes.Silver, Margin = new Thickness(0, 4) }; Grid.SetRow(line, i); Grid.SetColumnSpan(line, 2); grid.Children.Add(line); continue; } var caption = new TextBlock { Text = label }; Grid.SetRow(caption, i); grid.Children.Add(caption); var text = new TextBlock { Name = name, Text = value }; Grid.SetRow(text, i); Grid.SetColumn(text, 1); grid.Children.Add(text); } var close = new Button { Name = "Close", Content = "Close", IsDefault = true, IsCancel = true, MinWidth = 80, HorizontalAlignment = HorizontalAlignment.Right, }; close.Click += (_, _) => Close(); var panel = new StackPanel { Margin = new Thickness(12), Spacing = 14 }; panel.Children.Add(grid); panel.Children.Add(close); Content = panel; AddHandler(KeyDownEvent, (_, e) => { if (e.Key != Key.Escape) return; e.Handled = true; Close(); }, RoutingStrategies.Tunnel); } public static Task ShowAsync(Window owner, CutTimeReport report) => new TimingDialog(report).ShowDialog(owner); } }