You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

277 lines
9.7 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using ibk.IPD.Entity.IpdPs;
using SOA.Persistent;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace ibk.IPD.Service.IPD_PS
{
public class LowestLine
{
/// <summary>
/// 旋转90度
/// </summary>
/// <param name="pd">订单信息</param>
public void rotate_new(Product pd)
{
int wid = pd.WID;
int len = pd.LEN;
pd.WID = len;
pd.LEN = wid;
}
/// <summary>
/// 查询满足条件的面积最大订单
/// </summary>
/// <param name="target_width">宽</param>
/// <param name="target_higth">高</param>
/// <param name="products">全部订单信息</param>
/// <returns></returns>
public Product SearchBySize(int target_width, int target_higth, List<Product> products)
{
//横放
if (products.Where(p => p.LEN <= target_width && p.WID <= target_higth && p.DEL_FLG != "1").Count() > 0)
{
//获取第一个
return products.Where(p => p.LEN <= target_width && p.WID <= target_higth && p.DEL_FLG != "1").ToList().OrderByDescending(p => p.LEN).ThenByDescending(p => p.WID).FirstOrDefault();
}
//竖放
if (products.Where(p => p.LEN <= target_higth && p.WID <= target_width && p.DEL_FLG != "1").Count() > 0)
{
//获取第一个
Product pd = products.Where(p => p.LEN <= target_higth && p.WID <= target_width && p.DEL_FLG != "1").ToList().OrderByDescending(p => p.LEN).ThenByDescending(p => p.WID).FirstOrDefault();
//长宽互换位置
rotate_new(pd);
return pd;
}
return null;
}
/// <summary>
/// 初始化水平线集合起始x位置终止x位置高度
/// </summary>
public void INIT_LINE_LIST(RACTLAYOUT RL, int origin, int end, int height)
{
OutLine ol = new OutLine();
ol.ORIGIN = origin;
ol.END = end;
ol.HEIGHT = height;
RL.LINE_LIST.Add(ol);
RL.LOWEST_LINE = ol;
RL.LOWEST_LINE_IDX = 0;
}
/// <summary>
/// 提升最低水平线
/// </summary>
/// <param name="RL">布局</param>
/// <param name="index">索引</param>
public void ENHANCE_LINE(RACTLAYOUT RL, int index)
{
if (RL.LINE_LIST.Count > 1)
{
//获取高度较低的相邻水平线索引,并更新水平线集
int neighbor_idx = 0;
if (index == 0)
{
neighbor_idx = 1;
}
else if (index + 1 == RL.LINE_LIST.Count)
{
neighbor_idx = index - 1;
}
else
{
// 左边相邻水平线
OutLine left_neighbor = RL.LINE_LIST[index - 1];
// 右边相邻水平线
OutLine right_neighbor = RL.LINE_LIST[index + 1];
// 选择高度较低的相邻水平线,左右相邻水平线高度相同时,选择左边相邻的水平线
if (left_neighbor.HEIGHT < right_neighbor.HEIGHT)
{
neighbor_idx = index - 1;
}
else if (left_neighbor.HEIGHT == right_neighbor.HEIGHT)
{
if (left_neighbor.ORIGIN < right_neighbor.ORIGIN)
{
neighbor_idx = index - 1;
}
else
{
neighbor_idx = index + 1;
}
}
else
{
neighbor_idx = index + 1;
}
}
// 选中的高度较低的相邻水平线
OutLine old = RL.LINE_LIST[neighbor_idx];
OutLine OL_ADD = new OutLine();
//更新相邻水平线
if (neighbor_idx < index)
{
OL_ADD.ORIGIN = old.ORIGIN;
OL_ADD.END = old.END + line_width(RL, index);
OL_ADD.HEIGHT = old.HEIGHT;
RL.LINE_LIST[neighbor_idx] = OL_ADD;
}
else
{
OL_ADD.ORIGIN = old.ORIGIN - line_width(RL, index);
OL_ADD.END = old.END;
OL_ADD.HEIGHT = old.HEIGHT;
RL.LINE_LIST[neighbor_idx] = OL_ADD;
}
//删除当前水平线
RL.LINE_LIST.RemoveAt(index);
}
}
/// <summary>
/// 计算水平线宽度
/// </summary>
/// <param name="RL">布局类</param>
/// <param name="index">索引</param>
/// <returns></returns>
public int line_width(RACTLAYOUT RL, int index)
{
OutLine line = RL.LINE_LIST[index];
return line.END - line.ORIGIN;
}
/// <summary>
/// 按位置更新水平线
/// </summary>
/// <param name="RL">布局类</param>
/// <param name="index">索引</param>
/// <param name="new_line">新的水平线</param>
public void update_line_list(RACTLAYOUT RL, int index, OutLine new_line)
{
RL.LINE_LIST[index] = new_line;
}
/// <summary>
/// 按位置插入水平线(插在某索引位置后面)
/// </summary>
/// <param name="RL">布局类</param>
/// <param name="index">索引</param>
/// <param name="new_line">新线</param>
public void insert_line_list(RACTLAYOUT RL, int index, OutLine new_line)
{
List<OutLine> list = new List<OutLine>();
if (RL.LINE_LIST.Count == index + 1)
{
RL.LINE_LIST.Add(new_line);
}
else
{
for (int i = 0; i < index + 1; i++)
{
list.Add(RL.LINE_LIST[i]);
}
list.Add(new_line);
for (int i = index + 1; i < RL.LINE_LIST.Count; i++)
{
list.Add(RL.LINE_LIST[i]);
}
RL.LINE_LIST = list;
}
}
//# 计算水平线高度
public int line_higth2(RACTLAYOUT RL, int index)
{
OutLine line = RL.LINE_LIST[index];
return line.HEIGHT;
}
//# 计算水平线上限高度
public int line_higth(RACTLAYOUT RL, int index, int maxHeight)
{
OutLine line = RL.LINE_LIST[index];
return maxHeight - line.HEIGHT;
}
//找出最低水平线(如果最低水平线不止一条则选取最左边的那条)
public void find_lowest_line(RACTLAYOUT RL)
{
//最低高度
int lowest = RL.LINE_LIST.OrderBy(p => p.HEIGHT).First().HEIGHT;
//# 最低高度时,最小开始横坐标
int origin = RL.LINE_LIST.OrderBy(p => p.HEIGHT).First().ORIGIN;
for (int i = 0; i < RL.LINE_LIST.Count; i++)
{
if (RL.LINE_LIST[i].ORIGIN == origin && RL.LINE_LIST[i].HEIGHT == lowest)
{
RL.LOWEST_LINE_IDX = i;
RL.LOWEST_LINE = RL.LINE_LIST[i];
}
}
}
//计算最高水平线高度,即所用板材最大高度
public int cal_high_line(RACTLAYOUT RL)
{
int max_height = RL.LINE_LIST.OrderByDescending(p => p.HEIGHT).First().HEIGHT;
return max_height;
}
//将矩形物品排样
public void packing(RACTLAYOUT RL, Product _pro, List<RESULT_POS> ltResultPos)
{
//最低水平线宽度
int lowest_line_width = line_width(RL, RL.LOWEST_LINE_IDX);
//对矩形件排样
RESULT_POS RP = new RESULT_POS();
RP.NUM = _pro.NUM;
RP.ORIGIN = RL.LOWEST_LINE.ORIGIN;
RP.HEIGHT = RL.LOWEST_LINE.HEIGHT;
RP.W = _pro.WID;
RP.H = _pro.LEN;
RP.BOI = _pro.BOI;
ltResultPos.Add(RP);
OutLine new_line1 = new OutLine();
new_line1.ORIGIN = RL.LOWEST_LINE.ORIGIN;
new_line1.HEIGHT = RL.LOWEST_LINE.HEIGHT + _pro.LEN;
new_line1.END = RL.LOWEST_LINE.ORIGIN + _pro.WID;
OutLine new_line2 = new OutLine();
new_line2.ORIGIN = RL.LOWEST_LINE.ORIGIN + _pro.WID;
new_line2.END = RL.LOWEST_LINE.ORIGIN + lowest_line_width;
new_line2.HEIGHT = RL.LOWEST_LINE.HEIGHT;
//更新水平线集
update_line_list(RL, RL.LOWEST_LINE_IDX, new_line1);
if (lowest_line_width - _pro.WID > 0)
{
insert_line_list(RL, RL.LOWEST_LINE_IDX, new_line2);
}
}
/// <summary>
/// 有效利用率
/// </summary>
/// <param name="ltResultPos"></param>
/// <param name="GP"></param>
/// <returns></returns>
public decimal cal_used_ratio(List<RESULT_POS> ltResultPos, GP_PLATE GP)
{
decimal total_ratio = 0;
foreach (RESULT_POS item in ltResultPos)
{
total_ratio += item.W * item.H;
}
return Math.Round(total_ratio / (Convert.ToDecimal(GP.LEN) * Convert.ToDecimal(GP.WID)), 2);
}
}
}