BOOK-IQ4TD9B9LB\DIT-930
2023-05-15 f5120e92b525474f6b4e50130797946986c28eed
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
using SA_LTT.Info.RecipeInfo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
 
namespace SA_LTT_UI.Screen
{
    /// <summary>
    /// Interaction logic for WaferProcessPointView.xaml
    /// </summary>
    public partial class WaferProcessPointView : UserControl
    {
        public delegate void PointClickedEvent(Point clickedPoint, double width, double height);
 
        public List<Polygon> ProcessAreas= new List<Polygon>();
        Point Center = new Point(200, 200);
 
        private double _radius;
        private double _primaryFlat;
        public event PointClickedEvent PointClicked;
 
        private Rectangle _clickedLocation = new Rectangle();
        public double PrimaryFlat
        {
            get
            {
                return _primaryFlat;
            }
 
            set
            {
                _primaryFlat = value;
                RectPrimaryFlat.Height = (Radius - _primaryFlat) * _sizeRatio;
                RectPrimaryFlat.Margin = new Thickness(0, -RectPrimaryFlat.Height, 0, 0);
            }
        }
 
        public double Radius
        {
            get
            {
                return _radius;
            }
 
            set
            {
                _sizeRatio = 200 / value;
                _radius = value;
            }
        }
 
        private double _sizeRatio;
        
        public WaferProcessPointView(double radius = 75, double primaryFlat = 70)
        {
            InitializeComponent();
            Radius = radius;
            PrimaryFlat = primaryFlat;
 
            _clickedLocation.Fill = new SolidColorBrush(Colors.Lime);
            _clickedLocation.Opacity = 0.7;
            _clickedLocation.Height = 1;
            _clickedLocation.Width = 1;
        }
 
        public void AddProcessArea(double processStartY, double processEndY, Coord[] processPoint)
        {
            Polygon polygon = new Polygon();
            polygon.Fill = new SolidColorBrush(Colors.Red);
            polygon.Opacity = 0.3;
 
            processStartY = double.Parse($"{processStartY:F4}");
            processEndY = double.Parse($"{processEndY:F4}");
            List<Point> topPoint = new List<Point>();
            List<Point> bottomPoint = new List<Point>();
            Point point;
            double middlePoint = (processStartY + processEndY) / 2;
            middlePoint = double.Parse($"{middlePoint:F4}");
            foreach (Coord coord in processPoint)
            {
                double pointX = double.Parse($"{Center.X + coord.X * _sizeRatio:F4}");
                double pointY = double.Parse($"{Center.Y - coord.Y * _sizeRatio:F4}");
                point = new Point(pointX, pointY);
 
                if(processStartY >= 0 && processEndY >= 0) //가공위치가 y축 중심 보다 위에 있을 때 
                {
                    if (coord.Y > processEndY)
                    {
                        topPoint.Add(point);
                    }
                    else
                    {
                        bottomPoint.Add(point);
                    }
                }
                else if(processStartY < 0 && processEndY < 0) //가공위치가 y축 중심 보다 밑에 있을 때 
                {
                    if (coord.Y < processStartY)
                    {
                        bottomPoint.Add(point);
                    }
                    else
                    {
                        topPoint.Add(point);
                    }
                }
                else  //가공위치가 y축 중심을 지나갈 때
                {
                    if (coord.Y >= middlePoint)
                    {
                        topPoint.Add(point);
                    }
                    else
                    {
                        bottomPoint.Add(point);
                    }
                }
            }
 
            bottomPoint.Reverse();
 
            foreach(Point coord in topPoint)
            {
                polygon.Points.Add(coord);
            }
 
            foreach (Point coord in bottomPoint)
            {
                polygon.Points.Add(coord);
            }
            ProcessAreas.Add(polygon);
            MainScreen.Children.Add(polygon);
        }
 
        public void HighlightClear()
        {
            foreach (Polygon poly in ProcessAreas)
            {
                poly.Fill = new SolidColorBrush(Colors.Red);
            }
        }
 
        public void HighlightProcessAreas(int index)
        {
            if (ProcessAreas.Count < index + 1) return;
 
            ProcessAreas[index].Fill = new SolidColorBrush(Colors.Blue);
        }
 
        public void DeleteProcessArea(Polygon processArea)
        {
            MainScreen.Children.Remove(processArea);
 
            ProcessAreas.Remove(processArea);
        }
 
        public void ClearProcessArea()
        {
            foreach(Polygon processArea in ProcessAreas)
            {
                MainScreen.Children.Remove(processArea);
            }
            MainScreen.Children.Remove(_clickedLocation);
 
            ProcessAreas.Clear();
        }
 
        private void UserControl_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Point clickPoint = e.GetPosition((IInputElement)sender);
            
            double startX = (clickPoint.X - Center.X) / _sizeRatio;
            double startY = (Center.Y - clickPoint.Y) / _sizeRatio;
 
            startX = double.Parse($"{startX:F4}");
            startY = double.Parse($"{startY:F4}");
 
            SetClickedLocationPosition(startX, startY, _clickedLocation.Width / _sizeRatio, _clickedLocation.Height / _sizeRatio);
 
            Point point = new Point(startX, startY);
 
            PointClicked?.Invoke(point , 0, 0);
        }
 
        public void SetClickedLocationPosition(double startX, double startY, double width = 3, double height = 3)
        {
            double pointX = double.Parse($"{Center.X + startX * _sizeRatio:F4}");
            double pointY = double.Parse($"{Center.Y - startY * _sizeRatio:F4}");
 
            _clickedLocation.Width = width * _sizeRatio;
            _clickedLocation.Height = height * _sizeRatio;
 
            _clickedLocation.Margin = new Thickness(pointX, pointY, 0, 0);
 
            if (MainScreen.Children.Contains(_clickedLocation) == false)
            {
                MainScreen.Children.Add(_clickedLocation);
            }
        }
 
        private void UserControl_MouseMove(object sender, MouseEventArgs e)
        {
            if(e.LeftButton == MouseButtonState.Pressed)
            {
                Point clickPoint = e.GetPosition((IInputElement)sender);
 
                double startX = (_clickedLocation.Margin.Left - Center.X) / _sizeRatio;
                double startY = (Center.Y - _clickedLocation.Margin.Top) / _sizeRatio;
 
                double endX = (clickPoint.X - Center.X) / _sizeRatio;
                double endY = (Center.Y - clickPoint.Y) / _sizeRatio;
 
                double width = endX - startX;
                double height = startY - endY;
 
                if (width < 0)
                {
                    width = 0;
                }
 
                if (height < 0)
                {
                    height = 0;
                }
 
                PointClicked?.Invoke(new Point(startX, startY), width, height);
                SetClickedLocationPosition(startX, startY, width, height);
            }
        }
    }
}