using System.Windows; using Prism.Ioc; using XP.ImageProcessing.RoiControl.Controls; using XplorePlane.ViewModels; namespace XplorePlane.Views.ImageProcessing { public partial class BubbleMeasurePanel : Window { private PolygonRoiCanvas _canvas; public BubbleMeasurePanel() { InitializeComponent(); Loaded += OnLoaded; } private void OnLoaded(object sender, RoutedEventArgs e) { // 获取主界面的 RoiCanvas try { var mainWin = Owner as MainWindow; if (mainWin != null) { _canvas = FindChild(mainWin); } } catch { } // 工具切换 RbRoi.Checked += (s, ev) => _canvas?.SetBubbleTool(PolygonRoiCanvas.BubbleSubTool.Roi); RbWand.Checked += (s, ev) => _canvas?.SetBubbleTool(PolygonRoiCanvas.BubbleSubTool.Wand); RbBrush.Checked += (s, ev) => _canvas?.SetBubbleTool(PolygonRoiCanvas.BubbleSubTool.Brush); RbEraser.Checked += (s, ev) => _canvas?.SetBubbleTool(PolygonRoiCanvas.BubbleSubTool.Eraser); // 阈值同步 SliderThreshold.ValueChanged += (s, ev) => { TbThreshold.Text = ((int)SliderThreshold.Value).ToString(); _canvas?.SetBubbleThreshold((int)SliderThreshold.Value); }; // 画笔大小同步 SliderBrushSize.ValueChanged += (s, ev) => { TbBrushSize.Text = ((int)SliderBrushSize.Value).ToString(); _canvas?.SetBubbleBrushSize((int)SliderBrushSize.Value); }; // 监听 canvas 的工具切换事件(ROI 画完后自动切换时同步面板) if (_canvas != null) { _canvas.BubbleToolChanged += (s, ev) => { // 同步面板 radio button }; _canvas.MeasureCompleted += (s, ev) => { if (ev is MeasureCompletedEventArgs args && args.MeasureType == "BubbleVoid") { TbResult.Text = $"空隙率: {args.Distance:F1}%"; } }; } } private void ClearMask_Click(object sender, RoutedEventArgs e) { _canvas?.ClearBubbleMeasure(); TbResult.Text = "空隙率: --"; } private void Undo_Click(object sender, RoutedEventArgs e) { _canvas?.UndoBubble(); } private void Finish_Click(object sender, RoutedEventArgs e) { Close(); } private static T FindChild(DependencyObject parent) where T : DependencyObject { int count = System.Windows.Media.VisualTreeHelper.GetChildrenCount(parent); for (int i = 0; i < count; i++) { var child = System.Windows.Media.VisualTreeHelper.GetChild(parent, i); if (child is T t) return t; var result = FindChild(child); if (result != null) return result; } return null; } } }