| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- using System;
- using System.Collections.Generic;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- namespace AutoFocusTool
- {
- /// <summary>
- /// 自动标定独立窗口:4x4 显示16个well,标定完一个就在对应格显示该well照片,
- /// 顶部大字提示"正在标定第几个well",底部显示当前实时画面+参数。可全屏。
- /// </summary>
- public partial class CalibWindow : Window
- {
- public event Action StopRequested;
- private readonly Border[] _cells = new Border[17]; // 1-16
- private readonly Image[] _cellImgs = new Image[17];
- private readonly TextBlock[] _cellCaps = new TextBlock[17];
- private int _activeWell = 0; // 当前正在标定的well,实时帧画到这一格
- public CalibWindow()
- {
- InitializeComponent();
- BuildGrid();
- }
- private void BuildGrid()
- {
- for (int i = 1; i <= 16; i++)
- {
- var img = new Image { Stretch = Stretch.Uniform };
- var cap = new TextBlock
- {
- Text = $"well {i}",
- Foreground = Brushes.White,
- HorizontalAlignment = HorizontalAlignment.Center,
- TextAlignment = TextAlignment.Center,
- TextWrapping = TextWrapping.Wrap,
- FontSize = 15,
- FontWeight = FontWeights.Bold
- };
- var grid = new Grid();
- grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
- grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
- Grid.SetRow(img, 0); Grid.SetRow(cap, 1);
- grid.Children.Add(img); grid.Children.Add(cap);
- var cell = new Border
- {
- BorderBrush = new SolidColorBrush(Color.FromRgb(0x55, 0x55, 0x55)),
- BorderThickness = new Thickness(1),
- Margin = new Thickness(3),
- Background = new SolidColorBrush(Color.FromRgb(0x1A, 0x1A, 0x1A)),
- Child = grid
- };
- _cells[i] = cell; _cellImgs[i] = img; _cellCaps[i] = cap;
- WellGrid.Children.Add(cell);
- }
- }
- /// <summary>顶部大进度提示。</summary>
- public void SetProgress(string big, string sub = "")
- {
- Dispatcher.Invoke(() => { TxtBigProgress.Text = big; if (sub != null) TxtSubProgress.Text = sub; });
- }
- /// <summary>实时画面:直接画到当前正在标定的well格子里。</summary>
- public void SetCurrentFrame(BitmapSource bmp)
- {
- Dispatcher.Invoke(() =>
- {
- if (_activeWell >= 1 && _activeWell <= 16)
- _cellImgs[_activeWell].Source = bmp;
- });
- }
- /// <summary>底部当前参数/步骤文字,同时显示在当前活动well格标题上(大字)。</summary>
- public void SetCurrentInfo(string param, string step)
- {
- Dispatcher.Invoke(() =>
- {
- if (_activeWell >= 1 && _activeWell <= 16)
- {
- _cellCaps[_activeWell].Text = $"well {_activeWell} 标定中\n{step}\n{param}";
- _cellCaps[_activeWell].Foreground = Brushes.Yellow;
- }
- });
- }
- /// <summary>高亮"正在标定"的well格(黄框)。</summary>
- public void MarkActive(int well)
- {
- _activeWell = well;
- Dispatcher.Invoke(() =>
- {
- for (int i = 1; i <= 16; i++)
- _cells[i].BorderBrush = new SolidColorBrush(Color.FromRgb(0x55, 0x55, 0x55));
- if (well >= 1 && well <= 16)
- {
- _cells[well].BorderBrush = Brushes.Orange;
- _cells[well].BorderThickness = new Thickness(3);
- _cellCaps[well].Text = $"well {well} 标定中...";
- }
- });
- }
- /// <summary>某well标定完成,显示其照片+结果。</summary>
- public void SetWellResult(int well, BitmapSource bmp, string caption, bool ok)
- {
- Dispatcher.Invoke(() =>
- {
- if (well < 1 || well > 16) return;
- _cellImgs[well].Source = bmp;
- _cellCaps[well].Text = caption;
- _cellCaps[well].Foreground = ok ? Brushes.LightGreen : Brushes.Orange;
- _cells[well].BorderBrush = ok ? Brushes.LimeGreen : Brushes.Orange;
- _cells[well].BorderThickness = new Thickness(2);
- });
- }
- private void BtnCalStop_Click(object sender, RoutedEventArgs e)
- {
- StopRequested?.Invoke();
- TxtBigProgress.Text = "已请求停止...";
- }
- }
- }
|