using System; using System.Collections.Generic; namespace SHARP_CLAS_UI { public class Scanner_Recipe { #region Enum public enum Ablation_Style { LEFT_RIGHT_ZIGZAG, LEFT_TO_RIGHT, TOP_TO_BOTTOM_ZIGZAG, } #endregion #region Property public List Recipe_Pos_Info { get; private set; } public Ablation_Style ablation_style { get; private set; } public float working_area_x { get; private set; } public float working_area_y { get; private set; } public float process_area_start_x { get; private set; } public float process_area_start_y { get; private set; } public float process_area_end_x { get; private set; } public float process_area_end_y { get; private set; } public float distance { get; private set; } public int jump_repeat { get; private set; } public int jump_range { get; private set; } public float process_area_degree { get; private set; } public float distance_start { get; private set; } public int repeat_start { get; private set; } public float distance_end { get; private set; } public int repeat_end { get; private set; } public float height_X { get; private set; } public float height_Y { get; private set; } public bool Reverse { get; private set; } #endregion #region Construct //구버전 가공 public Scanner_Recipe(float working_area_x, float working_area_y, float process_area_x, float process_area_y, float distance = 0.1f, int jump_repeat = 0, int jump_range = 0, Ablation_Style ablation_style = Ablation_Style.LEFT_RIGHT_ZIGZAG) { this.working_area_x = Math.Abs(working_area_x); this.working_area_y = Math.Abs(working_area_y); float Data_X, Data_Y; float degree_X, degree_Y; float startx, starty; this.process_area_degree = (float)DegreeToRadian(0); startx = process_area_x / 2; starty = process_area_y / 2; Data_X = (float)(Math.Cos(process_area_degree)); Data_Y = (float)(Math.Sin(process_area_degree)); degree_X = (startx * Data_X - starty * Data_Y); degree_Y = (startx * Data_Y + starty * Data_X); if (this.process_area_degree == 0) { float process_area_start_x = -startx; float process_area_start_y = -starty; float process_area_end_x = startx; float process_area_end_y = starty; } else { float process_area_start_x = -degree_X; float process_area_start_y = -degree_Y; float process_area_end_x = degree_X; float process_area_end_y = degree_Y; } this.process_area_start_x = Math.Abs(process_area_start_x) > working_area_x / 2 ? -(working_area_x / 2) : process_area_start_x; this.process_area_start_y = Math.Abs(process_area_start_y) > working_area_y / 2 ? -(working_area_y / 2) : process_area_start_y; this.process_area_end_x = Math.Abs(process_area_end_x) > working_area_x / 2 ? working_area_x / 2 : process_area_end_x < process_area_start_x ? working_area_x : process_area_end_x; this.process_area_end_y = Math.Abs(process_area_end_y) > working_area_y / 2 ? working_area_y / 2 : process_area_end_y < process_area_start_y ? working_area_x : process_area_end_y; this.ablation_style = ablation_style; this.distance = distance < 0.001f ? 0.001f : distance; this.jump_repeat = Math.Abs(jump_repeat); this.jump_range = Math.Abs(jump_range); Recipe_Pos_Info = new List(); Fill_Recipe_Pos_Info(); } //신버전 가공 Recipe Setting 후 변경 진행 public Scanner_Recipe(float working_area_x, float working_area_y, float process_area_start_x, float process_area_start_y, float process_area_end_x, float process_area_end_y, float distance = 0.1f, int jump_repeat = 0, int jump_range = 0, float dis_start = 0f, float dis_end = 0f, int rep_start = 0, int rep_end = 0, Ablation_Style ablation_style = Ablation_Style.TOP_TO_BOTTOM_ZIGZAG, double degree = 0, bool reverse = false) { float Data_X, Data_Y; float degree_X_Start, degree_Y_Start, degree_X_End, degree_Y_End; float startx, starty, endx, endy; float sam_x, sam_y; this.working_area_x = working_area_x; this.working_area_y = working_area_y; this.process_area_degree = (float)DegreeToRadian(degree); startx = process_area_start_x; starty = process_area_start_y; endx = process_area_end_x; endy = process_area_end_y; if (reverse) { sam_x = process_area_start_x - process_area_end_x; sam_y = process_area_start_y - process_area_end_y; } else { sam_x = -(process_area_start_x - process_area_end_x); sam_y = -(process_area_start_y - process_area_end_y); } this.height_X = sam_x; this.height_Y = sam_y; //Data_X = (float)(Math.Cos(process_area_degree)); //Data_Y = (float)(Math.Sin(process_area_degree)); //degree_X_Start = (float)Math.Round((startx * Data_X - starty * Data_Y),3, MidpointRounding.AwayFromZero); //degree_Y_Start = (float)Math.Round((startx * Data_Y + starty * Data_X), 3, MidpointRounding.AwayFromZero); //degree_X_End = (float)Math.Round((startx * Data_X - endy * Data_Y), 3, MidpointRounding.AwayFromZero); //degree_Y_End = (float)Math.Round((startx * Data_Y + endy * Data_X), 3, MidpointRounding.AwayFromZero); //if (this.process_area_degree == 0) //{ this.process_area_start_x = process_area_start_x; this.process_area_start_y = process_area_start_y; this.process_area_end_x = process_area_start_x; this.process_area_end_y = process_area_end_y; //} //else //{ // this.process_area_start_x = degree_X_Start; // this.process_area_start_y = degree_Y_Start; // this.process_area_end_x = degree_X_End; // this.process_area_end_y = degree_Y_End; //} this.ablation_style = ablation_style; this.distance = distance < 0.001f ? 0.001f : distance; this.distance_start = dis_start < 0.001f ? 0.001f : dis_start; this.distance_end = dis_end < 0.001f ? 0.001f : dis_end; this.jump_repeat = Math.Abs(jump_repeat); this.jump_range = Math.Abs(jump_range); this.repeat_start = rep_start; this.repeat_end = rep_end; this.Reverse = reverse; Recipe_Pos_Info = new List(); if (!Reverse) Fill_Recipe_Pos_Info_Start(); else Fill_Recipe_Pos_Info_end(); } #endregion #region Fuction public void Fill_Recipe_Pos_Info() { float valid_x = working_area_x; float valid_y = working_area_y; float valid_distance = distance * valid_y; float start_x = process_area_start_x * valid_x; float start_y = process_area_start_y * valid_y; float end_x = process_area_end_x * valid_x; float end_y = process_area_end_y * valid_y; bool jump_repeat_start = false; float line_cnt; int cnt = 0, jump_cnt = 0, jump_length = 0; short scan_start_x, scan_start_y, scan_end_x, scan_end_y; Recipe_Pos_Info.Clear(); if (valid_x == 0 || valid_y == 0 || valid_distance == 0) return; DateTime dt = DateTime.Now; System.Diagnostics.Debug.WriteLine(dt); if (ablation_style == Ablation_Style.TOP_TO_BOTTOM_ZIGZAG) { line_cnt = start_y; valid_distance = distance * valid_y; while (line_cnt <= end_y) { scan_start_x = (short)start_x; scan_start_y = (short)(line_cnt); scan_end_x = (short)end_x; scan_end_y = (short)(line_cnt); if (ablation_style == Ablation_Style.TOP_TO_BOTTOM_ZIGZAG) { if (cnt % 2 == 0) { Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_start_x, scan_start_y, false)); Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_end_x, scan_end_y, true)); } else { Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_end_x, scan_end_y, false)); Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_start_x, scan_start_y, true)); } } line_cnt += valid_distance; jump_length++; cnt++; } } else { line_cnt = start_x; valid_distance = distance * valid_x; while (line_cnt <= end_x) { scan_start_x = (short)(line_cnt); scan_start_y = (short)start_y; scan_end_x = (short)(line_cnt); scan_end_y = (short)end_y; if (ablation_style == Ablation_Style.LEFT_RIGHT_ZIGZAG) { if (cnt % 2 == 0) { Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_start_x, scan_start_y, false)); Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_end_x, scan_end_y, true)); } else { Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_end_x, scan_end_y, false)); Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_start_x, scan_start_y, true)); } } else if (ablation_style == Ablation_Style.LEFT_TO_RIGHT) { if (cnt % 2 == 0) { Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_start_x, scan_start_y, false)); Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_end_x, scan_end_y, true)); } else { Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_start_x, scan_start_y, false)); Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_end_x, scan_end_y, true)); } } line_cnt += valid_distance; jump_length++; cnt++; } } System.Diagnostics.Debug.WriteLine((DateTime.Now - dt).TotalSeconds); } public void Fill_Recipe_Pos_Info_Start() { float valid_x = (working_area_x); float valid_y = (working_area_y); float valid_distance = distance; float start_x = process_area_start_x; float start_y = process_area_start_y; float end_x = process_area_end_x; float end_y = process_area_end_y; float dis_Start = distance_start; float height_x = height_X; float height_y = height_Y; float Data_X = (float)(Math.Cos(process_area_degree)); float Data_Y = (float)(Math.Sin(process_area_degree)); bool jump_repeat_start = false; float line_cnt; float line_cnt_end; int cnt = 0, jump_cnt = 0, jump_length = 0; short scan_start_x, scan_start_y, scan_end_x, scan_end_y; Recipe_Pos_Info.Clear(); if (valid_x == 0 || valid_y == 0 || valid_distance == 0 || dis_Start == 0) return; DateTime dt = DateTime.Now; System.Diagnostics.Debug.WriteLine(dt); if (ablation_style == Ablation_Style.TOP_TO_BOTTOM_ZIGZAG) { line_cnt = start_y; valid_distance = distance * valid_y; while (line_cnt <= start_y + height_y) { scan_start_x = (short)((float)Math.Round(((start_x * Data_X - line_cnt * Data_Y) * valid_x), 3, MidpointRounding.AwayFromZero) - (float)Math.Round(-((end_x / 2) * valid_x), 3, MidpointRounding.AwayFromZero)); scan_start_y = (short)(float)Math.Round(((start_x * Data_Y + line_cnt * Data_X) * valid_y), 3, MidpointRounding.AwayFromZero); scan_end_x = (short)((float)Math.Round(((end_x * Data_X - line_cnt * Data_Y) * valid_x), 3, MidpointRounding.AwayFromZero) - (float)Math.Round(-((end_x / 2) * valid_x), 3, MidpointRounding.AwayFromZero)); scan_end_y = (short)(float)Math.Round(((end_x * Data_Y + line_cnt * Data_X) * valid_y), 3, MidpointRounding.AwayFromZero); if (ablation_style == Ablation_Style.TOP_TO_BOTTOM_ZIGZAG) { if (cnt % 2 == 0) { Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_start_x, scan_start_y, false)); Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_end_x, scan_end_y, true)); } else { Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_end_x, scan_end_y, false)); Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_start_x, scan_start_y, true)); } } if (cnt + 1 < repeat_start) { line_cnt += dis_Start; } else if (cnt + 1 > repeat_start) { line_cnt += valid_distance; } jump_length++; cnt++; } } else { line_cnt = start_x; valid_distance = distance; while (line_cnt <= start_x+height_x) { //scan_start_x = (short)(start_x + line_cnt); //scan_start_y = (short)start_y; //scan_end_x = (short)(end_x + line_cnt); //scan_end_y = (short)end_y; scan_start_x = (short)(float)Math.Round(-((line_cnt * Data_X - start_y * Data_Y) * valid_x), 3, MidpointRounding.AwayFromZero); scan_start_y = (short)((float)Math.Round(-((line_cnt * Data_Y + start_y * Data_X) * valid_y), 3, MidpointRounding.AwayFromZero) - (float)Math.Round(-((end_y / 2) * valid_x), 3, MidpointRounding.AwayFromZero)); scan_end_x = (short)(float)Math.Round(-((line_cnt * Data_X - end_y * Data_Y) * valid_x), 3, MidpointRounding.AwayFromZero); scan_end_y = (short)((float)Math.Round(-((line_cnt * Data_Y + end_y * Data_X) * valid_y), 3, MidpointRounding.AwayFromZero) - (float)Math.Round(-((end_y / 2) * valid_x), 3, MidpointRounding.AwayFromZero)); if (ablation_style == Ablation_Style.LEFT_RIGHT_ZIGZAG) { if (cnt % 2 == 0) { Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_start_x, scan_start_y, false)); Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_end_x, scan_end_y, true)); } else { Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_end_x, scan_end_y, false)); Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_start_x, scan_start_y, true)); } } else if (ablation_style == Ablation_Style.LEFT_TO_RIGHT) { if (cnt % 2 == 0) { Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_start_x, scan_start_y, false)); Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_end_x, scan_end_y, true)); } else { Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_start_x, scan_start_y, false)); Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_end_x, scan_end_y, true)); } } if (cnt + 1 <= repeat_start) { line_cnt += dis_Start; } else if (cnt + 1 > repeat_start) { line_cnt += valid_distance; } jump_length++; cnt++; } } System.Diagnostics.Debug.WriteLine((DateTime.Now - dt).TotalSeconds); } public void Fill_Recipe_Pos_Info_end() { float valid_x = working_area_x; float valid_y = working_area_y; float valid_distance = distance; float start_x = process_area_start_x; float start_y = process_area_start_y; float end_x = process_area_end_x; float end_y = process_area_end_y; float dis_end = distance_end; float height_x = height_X; float height_y = height_Y; float Data_X = (float)(Math.Cos(process_area_degree)); float Data_Y = (float)(Math.Sin(process_area_degree)); bool jump_repeat_start = false; float line_cnt; int cnt = 0, jump_cnt = 0, jump_length = 0; short scan_start_x, scan_start_y, scan_end_x, scan_end_y; Recipe_Pos_Info.Clear(); if (valid_x == 0 || valid_y == 0 || valid_distance == 0 || dis_end == 0) return; DateTime dt = DateTime.Now; System.Diagnostics.Debug.WriteLine(dt); if (ablation_style == Ablation_Style.TOP_TO_BOTTOM_ZIGZAG) { line_cnt = start_y; valid_distance = distance; while (line_cnt >= start_y+height_y) { //scan_start_x = (short)start_x; //scan_start_y = (short)(start_y + line_cnt); //scan_end_x = (short)end_x; //scan_end_y = (short)(end_y + line_cnt); scan_start_x = (short)((float)Math.Round(((start_x * Data_X - line_cnt * Data_Y) * valid_x), 3, MidpointRounding.AwayFromZero) - (float)Math.Round(-((end_x / 2) * valid_x), 3, MidpointRounding.AwayFromZero)); scan_start_y = (short)(float)Math.Round(((start_x * Data_Y + line_cnt * Data_X) * valid_y), 3, MidpointRounding.AwayFromZero); scan_end_x = (short)((float)Math.Round(((end_x * Data_X - line_cnt * Data_Y) * valid_x), 3, MidpointRounding.AwayFromZero) - (float)Math.Round(-((end_x / 2) * valid_x), 3, MidpointRounding.AwayFromZero)); scan_end_y = (short)(float)Math.Round(((end_x * Data_Y + line_cnt * Data_X) * valid_y), 3, MidpointRounding.AwayFromZero); if (ablation_style == Ablation_Style.TOP_TO_BOTTOM_ZIGZAG) { if (cnt % 2 == 0) { Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_start_x, scan_start_y, false)); Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_end_x, scan_end_y, true)); } else { Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_end_x, scan_end_y, false)); Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_start_x, scan_start_y, true)); } } if (cnt + 1 < repeat_end) { line_cnt -= dis_end; } else if (cnt + 1 > repeat_end) { line_cnt -= valid_distance; } jump_length++; cnt++; } } else { line_cnt = start_x; valid_distance = distance; while (line_cnt >= start_x - height_x) { //scan_start_x = (short)(start_x + line_cnt); //scan_start_y = (short)start_y; //scan_end_x = (short)(end_x + line_cnt); //scan_end_y = (short)end_y; scan_start_x = (short)(float)Math.Round(-((line_cnt * Data_X - start_y * Data_Y) * valid_x), 3, MidpointRounding.AwayFromZero); scan_start_y = (short)((float)Math.Round(-((line_cnt * Data_Y + start_y * Data_X) * valid_y), 3, MidpointRounding.AwayFromZero) - (float)Math.Round(-((end_y / 2) * valid_x), 3, MidpointRounding.AwayFromZero)); scan_end_x = (short)(float)Math.Round(-((line_cnt * Data_X - end_y * Data_Y) * valid_x), 3, MidpointRounding.AwayFromZero); scan_end_y = (short)((float)Math.Round(-((line_cnt * Data_Y + end_y * Data_X) * valid_y), 3, MidpointRounding.AwayFromZero) - (float)Math.Round(-((end_y / 2) * valid_x), 3, MidpointRounding.AwayFromZero)); if (ablation_style == Ablation_Style.LEFT_RIGHT_ZIGZAG) { if (cnt % 2 == 0) { Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_start_x, scan_start_y, false)); Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_end_x, scan_end_y, true)); } else { Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_end_x, scan_end_y, false)); Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_start_x, scan_start_y, true)); } } else if (ablation_style == Ablation_Style.LEFT_TO_RIGHT) { if (cnt % 2 == 0) { Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_start_x, scan_start_y, false)); Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_end_x, scan_end_y, true)); } else { Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_start_x, scan_start_y, false)); Recipe_Pos_Info.Add(new Scanner_Position_Info(scan_end_x, scan_end_y, true)); } } if (cnt + 1 <= repeat_end) { line_cnt -= dis_end; } else if (cnt + 1 > repeat_end) { line_cnt -= valid_distance; } jump_length++; cnt++; } } System.Diagnostics.Debug.WriteLine((DateTime.Now - dt).TotalSeconds); } public static double DegreeToRadian(double degree) { return (Math.PI / 180) * degree; } #endregion } }