diff --git a/PLCSharpWpf/Core/UserControls/ImageEditExtensions.cs b/PLCSharpWpf/Core/UserControls/ImageEditExtensions.cs new file mode 100644 index 0000000..ee44c73 --- /dev/null +++ b/PLCSharpWpf/Core/UserControls/ImageEditExtensions.cs @@ -0,0 +1,82 @@ +using System.Windows.Controls; +using System.Windows.Media; +using System.Windows.Shapes; + +namespace PLCSharp.Core.UserControls; + +/// +/// ImageEdit 的扩展方法,提供便捷的图形绘制辅助 +/// +internal static class ImageEditExtensions +{ + /// + /// 在 ImageEdit 上画矩形边框 + 中心十字 + /// + public static void DrawRectVisual(this ImageEdit imageEdit, double left, double top, double width, double height) + { + var rectBorder = new Rectangle + { + Width = width, + Height = height, + Stroke = Brushes.Magenta, + StrokeThickness = 2, + Tag = "ORB匹配", + }; + Canvas.SetLeft(rectBorder, left); + Canvas.SetTop(rectBorder, top); + imageEdit.Draw(rectBorder); + + double cx = left + width / 2.0, cy = top + height / 2.0; + imageEdit.DrawCross(cx, cy); + } + + /// + /// 在 ImageEdit 上画圆形边框 + 中心十字 + /// + public static void DrawCircleVisual(this ImageEdit imageEdit, double cx, double cy, double radius) + { + var ellipse = new Ellipse + { + Width = radius * 2, + Height = radius * 2, + Stroke = Brushes.Magenta, + StrokeThickness = 2, + Tag = "ORB匹配", + }; + Canvas.SetLeft(ellipse, cx - radius); + Canvas.SetTop(ellipse, cy - radius); + imageEdit.Draw(ellipse); + + imageEdit.DrawCross(cx, cy); + } + + /// + /// 在 ImageEdit 上画中心十字 + /// + public static void DrawCross(this ImageEdit imageEdit, double cx, double cy) + { + const int len = 10; + var crossH = new Line + { + X1 = cx - len, + Y1 = cy, + X2 = cx + len, + Y2 = cy, + Stroke = Brushes.Magenta, + StrokeThickness = 1, + Tag = "ORB匹配", + }; + imageEdit.Draw(crossH); + var crossV = new Line + { + X1 = cx, + Y1 = cy - len, + X2 = cx, + Y2 = cy + len, + Stroke = Brushes.Magenta, + StrokeThickness = 1, + Tag = "ORB匹配", + }; + imageEdit.Draw(crossV); + } +} diff --git a/PLCSharpWpf/GlobalSuppressions.cs b/PLCSharpWpf/GlobalSuppressions.cs index 6dba617..28c7d82 100644 --- a/PLCSharpWpf/GlobalSuppressions.cs +++ b/PLCSharpWpf/GlobalSuppressions.cs @@ -10,3 +10,4 @@ using System.Diagnostics.CodeAnalysis; [assembly: SuppressMessage("Performance", "SYSLIB1045:转换为“GeneratedRegexAttribute”。")] [assembly: SuppressMessage("Usage", "VSTHRD100:Avoid async void methods", Justification = "<挂起>", Scope = "member", Target = "~M:PLCSharp.VVMs.Workflows.Script.CustomTextEditor.OnDataContextChanged(System.Object,System.Windows.DependencyPropertyChangedEventArgs)")] [assembly: SuppressMessage("Usage", "VSTHRD001:Avoid legacy thread switching APIs")] +[assembly: SuppressMessage("Style", "IDE0305:简化集合初始化")] diff --git a/PLCSharpWpf/VVMs/MainWindow/SystemConfig.xaml b/PLCSharpWpf/VVMs/MainWindow/SystemConfig.xaml index b99b79b..918b9cc 100644 --- a/PLCSharpWpf/VVMs/MainWindow/SystemConfig.xaml +++ b/PLCSharpWpf/VVMs/MainWindow/SystemConfig.xaml @@ -17,13 +17,16 @@ + + + - + - +