/// <summary> /// 更新水平线轮廓, /// 去除原有的轮廓线,新增排样后的轮廓线 /// </summary> /// <param name="lowestLine">最低水平线</param> /// <param name="getLength">长度</param> /// <param name="getWidth">宽度</param> public void update(OutLine lowestLine, float length, float width) { OutLine line1 = new OutLine(lowestLine.StartX, lowestLine.StartX + length, width + lowestLine.Y); this.update(line1); if (lowestLine.Length == length) { return; } OutLine line2 = new OutLine(lowestLine.StartX + length, lowestLine.EndX, lowestLine.Y); this.update(line2); //去除原有的水平轮廓线, this.outLineList.Remove(lowestLine); }
public void process() { IList <BoardInfo> usedBoardList = new List <BoardInfo>(); BoardInfo currentBoardInfo = null; for (int i = 0; i < this.panels.Count; i++) { if (outLineInfo == null) { outLineInfo = new OutLineInfo(); } if (i == 0) { currentBoardInfo = new BoardInfo(this.boardInfo); usedBoardList.Add(currentBoardInfo); Panel panel = Panel.copy(this.panels[i]); panel.setLeftBottomPoint(new Point(0, 0)); currentBoardInfo.addPanel(panel); OutLine outLine = new OutLine(0, panel.Length, panel.Width); OutLine outLine2 = new OutLine(panel.Length, boardInfo.Length, 0); outLineInfo.update(outLine); outLineInfo.update(outLine2); continue; } IList <OutLine> lowestLines = outLineInfo.getLowestOutline(); //只有一条最低水平轮廓线 if (lowestLines.Count == 1) { float lineY = lowestLines[0].Y; float lineLen = lowestLines[0].Length; int matchIndex = -1; searchMatchPanel(ref matchIndex, lineY, lineLen, panels, i); if (matchIndex == -1) //不存在找到合适的零件在当前板材上排放,即需要换新板 { currentBoardInfo = new BoardInfo(this.boardInfo); usedBoardList.Add(currentBoardInfo); } else { SwapPanel(i, matchIndex, panels); Panel panel = Panel.copy(this.panels[i]); addPanelAndUpdateOutLine(currentBoardInfo, panel, lowestLines[0]); } } else { OutLine line = null; SearchGoodLine(lowestLines, panels[i].Length, panels[i].Width, out line); //长度能放下 if (line != null) { //最低水平线+当前零件高度没有超出边界 if ((lowestLines[0].Y + panels[i].Width) <= boardInfo.Width) { addPanelAndUpdateOutLine(currentBoardInfo, Panel.copy(this.panels[i]), line); } else //搜索当前零件后的零件,看高度是否合适 { float lineY = line.Y; float lineLen = line.Length; int matchIndex = -1; searchMatchPanel(ref matchIndex, lineY, lineLen, panels, i); if (matchIndex == -1) //不存在找到合适的零件的高度在当前板材上排放,即需要换新板 { currentBoardInfo = new BoardInfo(this.boardInfo); usedBoardList.Add(currentBoardInfo); } else { SwapPanel(i, matchIndex, panels); Panel panel = Panel.copy(this.panels[i]); addPanelAndUpdateOutLine(currentBoardInfo, panel, line); } } } else //长度不合适,查找后面的零件 { float minLengh = this.panels.Skip(i + 1).Min(m => m.Length); //TODO: //// } } } }
public void SearchGoodLine(IList <OutLine> outLineList, float length, float width, out OutLine line) { line = null; float matchRate = 0; foreach (var outLine in outLineList) { if (length <= outLine.Length && length / outLine.Length > matchRate) { matchRate = length / outLine.Length; line = outLine; } } }
/// <summary> /// 增加零件且更新轮廓线 /// </summary> /// <param name="currentBoardInfo"></param> /// <param name="panel"></param> /// <param name="outLine"></param> private void addPanelAndUpdateOutLine(BoardInfo currentBoardInfo, Panel panel, OutLine outLine) { panel.setLeftBottomPoint(new Point(outLine.StartX, outLine.Y)); currentBoardInfo.addPanel(panel); outLineInfo.update(outLine, panel.Length, panel.Width); }
/** * 更新轮廓信息 * @param outLine */ public void update(OutLine outLine) { this.outLineList.Add(outLine); }