public void GetProgramCommentInfo(LaserSimulater laser, string ncPath, ProgramDetailDto info, bool bmp, string bmpPath, int bmpWidth, int bmpHeight) { string str = ""; GetProgramString(ncPath, ref str); GetInfo(info, str); List <PreProgramBlock> preBlocks = new List <PreProgramBlock>(); ProgramBlockPreDecompile(str, info, preBlocks); List <ProgramBlock> pBlocks = new List <ProgramBlock>(); ProgramBlockDecompile(preBlocks, pBlocks); List <DrawBlock> dBlocks = new List <DrawBlock>(); ProgramInfoAnalysis(laser, info, pBlocks, dBlocks); if (bmp == true) { var thumbnail = new LaserProgramThumbnai(bmpWidth, bmpHeight, Color.FromArgb(0xFF, 0x00, 0xD8, 0xFF), (float)0.05, Color.Yellow, (float)0.05, Color.FromArgb(0xFF, 0x28, 0x26, 0x20)); thumbnail.DrawXYThumbnai(dBlocks, info.Max_X + 20, info.Max_Y + 20, bmpPath); } }
private void ProgramInfoAnalysis(LaserSimulater laser, ProgramDetailDto info, List <ProgramBlock> pBlocks, List <DrawBlock> dBlocks) { int total_pericing_count = 0; double total_cutting_length = 0; double total_cycletime = 0; double?max_x = null, max_y = null, min_x = null, min_y = null; foreach (var block in pBlocks) { var tempInfo = block.Info; dBlocks.Add(tempInfo.DrawBlockInfo); laser.FeedSpeed = (int)block.F_Adr.Value; total_cycletime += laser.GetFeedTime(tempInfo.CuttingLength); total_cutting_length += tempInfo.CuttingLength; total_pericing_count += tempInfo.PiercingCount; total_cycletime += tempInfo.DirectTime / 1000.0; if (tempInfo.Max_X.HasValue) { max_x = max_x.HasValue ? Math.Max(max_x.Value, tempInfo.Max_X.Value) : tempInfo.Max_X.Value; } if (tempInfo.Max_Y.HasValue) { max_y = max_y.HasValue ? Math.Max(max_y.Value, tempInfo.Max_Y.Value) : tempInfo.Max_Y.Value; } if (tempInfo.Min_X.HasValue) { min_x = min_x.HasValue ? Math.Min(min_x.Value, tempInfo.Min_X.Value) : tempInfo.Min_X.Value; } if (tempInfo.Min_Y.HasValue) { min_y = min_y.HasValue ? Math.Min(min_y.Value, tempInfo.Min_Y.Value) : tempInfo.Min_Y.Value; } } info.CuttingTime = total_cycletime; info.CuttingDistance = total_cutting_length; info.PiercingCount = total_pericing_count; info.UsedPlateSize = $"X最小:{min_x.Value},X最大:{max_x.Value},Y最小:{min_y.Value},Y最大:{max_y.Value}"; info.Max_X = max_x.Value; info.Max_Y = max_y.Value; info.Min_X = min_x.Value; info.Min_Y = min_y.Value; info.UsedPlateSize_W = max_x.Value; info.UsedPlateSize_H = max_y.Value; }
public ProgramResolveResultDto ProgramResolve(ProgramResovleDto resovleDto) { LaserProgramHelper helper = new LaserProgramHelper(); LaserSimulater laser = new LaserSimulater(48, 1000, 96, 12000); ProgramDetailDto info = new ProgramDetailDto(); helper.GetProgramCommentInfo(laser, resovleDto.FilePath, info, false, "", 0, 0); return(new ProgramResolveResultDto() { ConnectId = resovleDto.ConnectId, Id = "ProgramResolve", Data = info, ImagePath = "", BmpName = "", }); }
private void ProgramBlockPreDecompile(string str, ProgramDetailDto info, List <PreProgramBlock> preBlocks) { var progBlocks = str.Split('\n'); int blockIndex = 0; foreach (var block in progBlocks) { if (blockIndex < LaserCommentLineCount) { GetInfo(info, block); } var tempStr = Regex.Replace(block, @"\(.*\)", ""); tempStr = Regex.Replace(tempStr, @"\<.*\>", ""); tempStr = tempStr.Replace(" ", "").Replace("\r", ""); var str_num = Regex.Replace(tempStr, @"[A-Z]", "_"); var nums = str_num.Split('_'); var adrs = Regex.Replace(tempStr, @"[^A-Z]", ""); var dblock = new PreProgramBlock(); for (int i = 0; i < adrs.Length; i++) { switch (adrs[i]) { case 'G': dblock.G_Codes[dblock.G_Code_Count] = double.Parse(nums[i + 1]); dblock.G_Code_Count++; break; case 'M': dblock.M_Codes[dblock.M_Code_Count] = double.Parse(nums[i + 1]); dblock.M_Code_Count++; break; case 'N': dblock.BlockNum = int.Parse(nums[i + 1]); break; case 'X': dblock.X_Adr = double.Parse(nums[i + 1]); break; case 'Y': dblock.Y_Adr = double.Parse(nums[i + 1]); break; case 'Z': dblock.Z_Adr = double.Parse(nums[i + 1]); break; case 'I': dblock.I_Adr = double.Parse(nums[i + 1]); break; case 'J': dblock.J_Adr = double.Parse(nums[i + 1]); break; case 'K': dblock.K_Adr = double.Parse(nums[i + 1]); break; case 'R': dblock.R_Adr = double.Parse(nums[i + 1]); break; case 'F': dblock.F_Adr = double.Parse(nums[i + 1]); break; case 'S': dblock.S_Adr = double.Parse(nums[i + 1]); break; case 'P': dblock.P_Adr = double.Parse(nums[i + 1]); break; case 'Q': dblock.Q_Adr = double.Parse(nums[i + 1]); break; case 'H': dblock.F_Adr = double.Parse(nums[i + 1]); break; default: break; } } preBlocks.Add(dblock); blockIndex++; } }
private void GetInfo(ProgramDetailDto info, string blockStr) { Regex matRegex = new Regex(@"(?<=\(#MATERIAL=)\w*(?=\))"); Match matMatch = matRegex.Match(blockStr); if (matMatch.Success == true) { info.Material = matMatch.Value; } Regex thickRegex = new Regex(@"(?<=\(#THICKNESS=)\w*(?=\))"); Match thickMatch = thickRegex.Match(blockStr); if (thickMatch.Success == true) { info.Thickness = double.Parse(thickMatch.Value); } Regex gasRegex = new Regex(@"(?<=\(#CUTTING_GAS_KIND=)\w*(?=\))"); Match gasMatch = gasRegex.Match(blockStr); if (gasMatch.Success == true) { info.Gas = gasMatch.Value; } Regex focalRegex = new Regex(@"(?<=\(#FOCAL_POSITION=)\w*(?=\))"); Match focalMatch = focalRegex.Match(blockStr); if (focalMatch.Success == true) { info.FocalPosition = double.Parse(focalMatch.Value); } Regex nozzleDiaRegex = new Regex(@"(?<=\(#NOZZLE_DIA=)\w*(?=\))"); Match nozzleDiaMatch = nozzleDiaRegex.Match(blockStr); if (nozzleDiaMatch.Success == true) { info.NozzleDiameter = double.Parse(nozzleDiaMatch.Value); } Regex nozzleTypeRegex = new Regex(@"(?<=\(#NOZZLE_TYPE=)\w*(?=\))"); Match nozzleTypeMatch = nozzleTypeRegex.Match(blockStr); if (nozzleTypeMatch.Success == true) { info.NozzleKind = nozzleTypeMatch.Value; } Regex plateSizeRegex = new Regex(@"(?<=\(#PLATE_SIZE=)\w*(?=\))"); Match plateSizeMatch = plateSizeRegex.Match(blockStr); if (plateSizeMatch.Success == true) { info.PlateSize = plateSizeMatch.Value; var datas = plateSizeMatch.Value.Split('X'); if (datas.Length == 2) { info.PlateSize_W = double.Parse(datas[0]); info.PlateSize_H = double.Parse(datas[1]); } } Regex usedPlateSizeRegex = new Regex(@"(?<=\(#USED_SIZE=)\w*(?=\))"); Match usedPlateSizeMatch = usedPlateSizeRegex.Match(blockStr); if (usedPlateSizeMatch.Success == true) { info.UsedPlateSize = usedPlateSizeMatch.Value; var datas = usedPlateSizeMatch.Value.Split('X'); if (datas.Length == 2) { info.UsedPlateSize_W = double.Parse(datas[0]); info.UsedPlateSize_H = double.Parse(datas[1]); } } Regex cuttingDistanceRegex = new Regex(@"(?<=\(#CUTTING_DISTANCE=)\w*(?=\))"); Match cuttingDistanceMatch = cuttingDistanceRegex.Match(blockStr); if (cuttingDistanceMatch.Success == true) { info.CuttingDistance = double.Parse(cuttingDistanceMatch.Value); } Regex piercingRegex = new Regex(@"(?<=\(#PIERCING_COUNT=)\w*(?=\))"); Match piercingMatch = piercingRegex.Match(blockStr); if (piercingMatch.Success == true) { info.PiercingCount = int.Parse(piercingMatch.Value); } Regex cuttingTimeRegex = new Regex(@"(?<=\(#CUTTING_TIME=)\w*(?=\))"); Match cuttingTimeMatch = cuttingTimeRegex.Match(blockStr); if (cuttingTimeMatch.Success == true) { info.CuttingTime = double.Parse(cuttingTimeMatch.Value); } }