import { FaceType, PlaceBlock, PlaceBlockDetail, PlaceBorderContour, PlaceMaterial, PlaceStyle, SizeExpand } from "../confClass" import { BlockDetailHelperBase } from "../handleAbility/blockDetailHelperBase" import { PolylineHelper } from "../handleAbility/common/LayoutEngine/PolylineHelper" import { KnifeHelper } from "../handleAbility/knifeHelper" /** 小板明细 相关的计算 孔 造型 以及轮廓 */ export class BlockDetailHelper extends BlockDetailHelperBase { /** 预铣(板件外扩)值 */ preMillingSize = 0; constructor(config?: any) { super() if(config){ this.updateConfig(config) } } updateConfig(config) { if (config) { let keys = Object.keys(config) for (const key of keys) { if (Reflect.has(this, key)) { this[key] = config[key] } } } } /** 小板初始化:1各种轮廓|走刀路径|,2尺寸扩展后的轮廓与走刀路径 */ initBlock(block: PlaceBlock, pm: PlaceMaterial) { if (block.blockDetail == null) { // 异常情况 console.error(`【initBlock()】${block.blockNo}没用板件明细,请检查`); return } if (block.blockDetail.borderContour) return // 已初始化 // const pm = block.placeMaterial const bd = block.blockDetail if (pm == null) { return // 异常 } const cutKnifeR = pm.diameter / 2 const cutGap = pm.cutKnifeGap // 开料偏移值 ,矩形波倒角 bd.offsetKnifeRadius = pm.diameter / 2 bd.isOffsetRounding = true // 默认要倒角 bd.preMillingSize = pm.preMillingSize if (bd.points.length == 0) // 矩形板,设置不倒角 { bd.isOffsetRounding = false// sysConfig.RegularBlockFilletCurve; } else // 异形板 { // 异形板倒角 bd.isOffsetRounding = true // sysConfig.isUnRegularBlockChamfer } // 初始化 小板基础轮廓 // 1.原始轮廓,成品轮廓 const border_final = this.createFinalBorder(bd, block) // 2.开料轮廓 <不含预铣> const border_org = this.createOrgBorder(bd) bd.borderContour = new PlaceBorderContour(PlaceStyle.FRONT, border_final, border_org) // 3.开料轮廓_带预铣, 外扩尺寸 bd.borderContour.borderPreMilling = border_org bd.preMillingExpandSize = new SizeExpand() // console.log('开料轮廓_带预铣, 外扩尺寸', block, bd.preMillingExpandSize, sysConfig.preMillingSize) if (this.preMillingSize > 0.0001) { const rt = this.creatOrgBorderWithPrevCut(block, border_org, this.sysConfig.preMillingSize) bd.borderContour.borderPreMilling = rt.newBorders bd.preMillingExpandSize = rt.newSizeExpand // console.log('开料轮廓_带预铣, 外扩尺寸==》after', block, rt.newSizeExpand) } // 4. 板内走刀路径,板内空间 const innerGroup = this.analyeInners(bd, cutKnifeR, cutGap) bd.borderContour.borderModelThrough = innerGroup.borders_inner_org bd.borderContour.borderModelThroughR = innerGroup.borders_inner_r bd.borderContour.cutLinesModelThrough = innerGroup.borders_inner_cut bd.borderContour.borderInnerPlace = innerGroup.borders_inner_place bd.borderContour.blockInnerSpace = innerGroup.spaces // 5 造型外扩轮廓, 外扩尺寸 const { pls_model, sizeout: sizeout_model } = this.createPolyline_model(block) bd.borderContour.polylinesOutModel = pls_model bd.modelExpandSize = sizeout_model // 6. 2V刀路 外扩轮廓,外扩尺寸 const { pls_2v, sizeout_2v } = this.createPolyline_2vModel(block) bd.borderContour.polylines2vModel = pls_2v bd.vKnifeModelExpandSize = sizeout_2v // 7.同刀辅助 外扩尺寸 let isUseSameKnifeToHelpCut = this.sysConfig.helpCutStyle || 0 let useSameKnifeToHelpCutGap = this.sysConfig.helpCutGap || 0 const isSameKnifeToCut = isUseSameKnifeToHelpCut && useSameKnifeToHelpCutGap > 0 if (isSameKnifeToCut == false || bd.isUseSameKnifeToHelpCut == false) { // 未启动同刀辅助, 或 该小板 不需要同刀辅助 bd.useSameKnifeToHelpCutGap = 0 bd.sameKnfieHelpExpandSize = new SizeExpand() } else { const gap = useSameKnifeToHelpCutGap bd.useSameKnifeToHelpCutGap = gap bd.sameKnfieHelpExpandSize = new SizeExpand({ left: gap, right: gap, under: gap, upper: gap }) } // 2V刀路,预洗,同刀辅助开料,出板造型刀 this.resetBlock(block, pm) } /** 二维刀路初始化 */ init2VModel(blockDetail: PlaceBlockDetail, isCNC = false, _knifeHelper: KnifeHelper) { for (let model of blockDetail.models) { if (!model.isVKnifeModel) continue let vModels: any = [] model.VLines = vModels let isFaceB = model.face == FaceType.BACK if (model.pointList.length < 1) continue let ps = model.pointList.map((t) => { return { x: t.pointX, y: t.pointY, bul: t.curve } }) let pl = PolylineHelper.create(ps) if (model.VLines?.length > 0) return // 已经分析了 model.VLines = [] for (let os of model.offsetList) { let knife1 = isCNC ? null : _knifeHelper.getModelKnifeByName(os.name) // getModelKnifeByName(os.name) let knifeR = os.radius let knifeId = knife1 ? knife1.knifeId : -1 try { let vps_1 = PolylineHelper.getVModelPoints_offset(pl, os.offset, os.depth, os.angle) let vLine = { isFaceB, name: os.name, value: os.offset, knife: knife1, knifeId, knifeRadius: knifeR, depth: os.depth, points: vps_1, offset: os } vModels.push(vLine) // 偏移路径 model.VLines.push(vLine) } catch (err) { console.log('v型刀走刀路径算法出错。' + err) } } model.VLines = vModels } } }