Files
XplorePlane/XplorePlane/Views/ImageProcessing/BubbleMeasurePanel.xaml.cs
T

86 lines
2.8 KiB
C#

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<PolygonRoiCanvas>(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
};
}
}
private void ClearMask_Click(object sender, RoutedEventArgs e)
{
_canvas?.ClearBubbleMeasure();
TbResult.Text = "空隙率: --";
}
private void Finish_Click(object sender, RoutedEventArgs e)
{
Close();
}
private static T FindChild<T>(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<T>(child);
if (result != null) return result;
}
return null;
}
}
}