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 { /// /// Interaction logic for WaferProcessPointView.xaml /// public partial class WaferProcessPointView : UserControl { public delegate void PointClickedEvent(Point clickedPoint, double width, double height); public List ProcessAreas= new List(); 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 topPoint = new List(); List bottomPoint = new List(); 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); } } } }