领胜LDS 键盘AOI检测项目
xcd
2020-06-24 d6c577e17ee7bb5331dd51d803f9b42441b0f0e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
 
namespace Bro.Common.ImageCanvas
{
    public class ZoomAndPanScrollViewer : ScrollViewer
    {
        public Action<Point> OnMousePositionChanged { get; set; }
 
        // private ZoomAndPanControl _zoomAndPanControl;
 
        #region constructor and overrides
        /// <summary>
        /// Static constructor to define metadata for the control (and link it to the style in Generic.xaml).
        /// </summary>
        static ZoomAndPanScrollViewer()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ZoomAndPanScrollViewer), new FrameworkPropertyMetadata(typeof(ZoomAndPanScrollViewer)));
        }
 
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            ZoomAndPanContent = Template.FindName("PART_ZoomAndPanControl", this) as ZoomAndPanControl;
            OnPropertyChanged(new DependencyPropertyChangedEventArgs(ZoomAndPanContentProperty, null, ZoomAndPanContent));
            RefreshProperties();
        }
        #endregion
 
        /// <summary>
        /// Get/set the maximum value for 'ViewportZoom'.
        /// </summary>
        public ZoomAndPanControl ZoomAndPanContent
        {
            get { return (ZoomAndPanControl)GetValue(ZoomAndPanContentProperty); }
            set { SetValue(ZoomAndPanContentProperty, value); }
        }
        public static readonly DependencyProperty ZoomAndPanContentProperty = DependencyProperty.Register("ZoomAndPanContent",
            typeof(ZoomAndPanControl), typeof(ZoomAndPanScrollViewer), new FrameworkPropertyMetadata(null));
 
        #region DependencyProperties
 
        /// <summary>
        /// Get/set the maximum value for 'ViewportZoom'.
        /// </summary>
        public MinimumZoomTypeEnum MinimumZoomType
        {
            get { return (MinimumZoomTypeEnum)GetValue(MinimumZoomTypeProperty); }
            set { SetValue(MinimumZoomTypeProperty, value); }
        }
        public static readonly DependencyProperty MinimumZoomTypeProperty = DependencyProperty.Register("MinimumZoomType",
            typeof(MinimumZoomTypeEnum), typeof(ZoomAndPanScrollViewer), new FrameworkPropertyMetadata(MinimumZoomTypeEnum.MinimumZoom));
 
        /// <summary>
        /// Get/set the MinimumZoom value for 'ViewportZoom'.
        /// </summary>
        public Point? MousePosition
        {
            get { return (Point?)GetValue(MousePositionProperty); }
            set { SetValue(MousePositionProperty, value); }
        }
        public static readonly DependencyProperty MousePositionProperty = DependencyProperty.Register("MousePosition",
            typeof(Point?), typeof(ZoomAndPanScrollViewer), new PropertyMetadata(null, OnMousePointPropertyChanged));
 
        private static void OnMousePointPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ZoomAndPanScrollViewer ctrl = d as ZoomAndPanScrollViewer;
            if (ctrl != null)
            {
                Point? p = (Point?)e.NewValue;
 
                if (p != null)
                {
                    ctrl.OnMousePositionChanged?.BeginInvoke(p.Value, null, null);
                }
            }
        }
 
 
        /// <summary>
        /// Disables animations if set to false
        /// </summary>
        public bool UseAnimations
        {
            get { return (bool)GetValue(UseAnimationsProperty); }
            set { SetValue(UseAnimationsProperty, value); }
        }
        public static readonly DependencyProperty UseAnimationsProperty = DependencyProperty.Register("UseAnimations",
            typeof(bool), typeof(ZoomAndPanScrollViewer), new FrameworkPropertyMetadata(true));
 
        /// <summary>
        /// Get/set the current scale (or zoom factor) of the content.
        /// </summary>
        public double ViewportZoom
        {
            get { return (double)GetValue(ViewportZoomProperty); }
            set { SetValue(ViewportZoomProperty, value); }
        }
        public static readonly DependencyProperty ViewportZoomProperty = DependencyProperty.Register("ViewportZoom",
            typeof(double), typeof(ZoomAndPanScrollViewer), new FrameworkPropertyMetadata(1.0));
 
        /// <summary>
        /// The duration of the animations (in seconds) started by calling AnimatedZoomTo and the other animation methods.
        /// </summary>
        public ZoomAndPanInitialPositionEnum ZoomAndPanInitialPosition
        {
            get { return (ZoomAndPanInitialPositionEnum)GetValue(ZoomAndPanInitialPositionProperty); }
            set { SetValue(ZoomAndPanInitialPositionProperty, value); }
        }
        public static readonly DependencyProperty ZoomAndPanInitialPositionProperty = DependencyProperty.Register("ZoomAndPanInitialPosition",
            typeof(ZoomAndPanInitialPositionEnum), typeof(ZoomAndPanScrollViewer), new FrameworkPropertyMetadata(ZoomAndPanInitialPositionEnum.Default));
        #endregion
 
        #region Commands
        /// <summary>
        ///     Command to implement the zoom to fill 
        /// </summary>
        public ICommand FillCommand => _fillCommand ?? (_fillCommand =
                new RelayCommand(
                    () => ZoomAndPanContent.FillCommand.Execute(null),
                    () => ZoomAndPanContent?.FillCommand.CanExecute(null) ?? true));
        private RelayCommand _fillCommand;
 
        /// <summary>
        ///     Command to implement the zoom to fit 
        /// </summary>
        public ICommand FitCommand => _fitCommand ?? (_fitCommand =
                new RelayCommand(
                    () => ZoomAndPanContent.FitCommand.Execute(null),
                    () => ZoomAndPanContent?.FitCommand.CanExecute(null) ?? true));
        private RelayCommand _fitCommand;
 
        /// <summary>
        ///     Command to implement the zoom to 100% 
        /// </summary>
        public ICommand ZoomPercentCommand => _zoomPercentCommand ?? (_zoomPercentCommand =
                new RelayCommand<double>(
                    value => ZoomAndPanContent.ZoomPercentCommand.Execute(value),
                    value => ZoomAndPanContent?.ZoomPercentCommand.CanExecute(value) ?? true));
        private RelayCommand<double> _zoomPercentCommand;
 
        /// <summary>
        ///     Command to implement the zoom to 100% 
        /// </summary>
        public ICommand ZoomRatioFromMinimumCommand => _zoomRatioFromMinimumCommand ?? (_zoomRatioFromMinimumCommand =
                new RelayCommand<double>(
                    value => ZoomAndPanContent.ZoomRatioFromMinimumCommand.Execute(value),
                    value => ZoomAndPanContent?.ZoomRatioFromMinimumCommand.CanExecute(value) ?? true));
        private RelayCommand<double> _zoomRatioFromMinimumCommand;
 
        /// <summary>
        ///     Command to implement the zoom out by 110% 
        /// </summary>
        public ICommand ZoomOutCommand => _zoomOutCommand ?? (_zoomOutCommand =
                new RelayCommand(
                    () => ZoomAndPanContent.ZoomOutCommand.Execute(null),
                    () => ZoomAndPanContent?.ZoomOutCommand.CanExecute(null) ?? true));
        private RelayCommand _zoomOutCommand;
 
        /// <summary>
        ///     Command to implement the zoom in by 91% 
        /// </summary>
        public ICommand ZoomInCommand => _zoomInCommand ?? (_zoomInCommand =
                new RelayCommand(
                    () => ZoomAndPanContent.ZoomInCommand.Execute(null),
                    () => ZoomAndPanContent?.ZoomInCommand.CanExecute(null) ?? true));
        private RelayCommand _zoomInCommand;
 
        /// <summary>
        ///     Command to implement Undo 
        /// </summary>
        public ICommand UndoZoomCommand => _undoZoomCommand ?? (_undoZoomCommand =
                new RelayCommand(
                    () => ZoomAndPanContent.UndoZoomCommand.Execute(null),
                    () => ZoomAndPanContent?.UndoZoomCommand.CanExecute(null) ?? true));
        private RelayCommand _undoZoomCommand;
 
        /// <summary>
        ///     Command to implement Redo 
        /// </summary>
        public ICommand RedoZoomCommand => _redoZoomCommand ?? (_redoZoomCommand =
                new RelayCommand(
                    () => ZoomAndPanContent.RedoZoomCommand.Execute(null),
                    () => ZoomAndPanContent?.RedoZoomCommand.CanExecute(null) ?? true));
        private RelayCommand _redoZoomCommand;
        #endregion
 
        private void RefreshProperties()
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FillCommand)));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FitCommand)));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ZoomPercentCommand)));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ZoomRatioFromMinimumCommand)));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ZoomInCommand)));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ZoomOutCommand)));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(UndoZoomCommand)));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(RedoZoomCommand)));
        }
 
        public event PropertyChangedEventHandler PropertyChanged;
    }
}