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.

97 lines
2.9 KiB
C#

using Rs.Controls;
using Rs.Framework;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rs.MotionPlat.Commom
{
public class TrayPosition
{
private int m_row = 26;
private int m_column = 10;
public int RowNum
{
get { return m_row; }
set { m_row = value; }
}
public int ColumnNum
{
get { return m_column; }
set { m_column = value; }
}
private TrayPosition()
{
//for (int i = 0; i < m_row; i++)
//{
// for(int j=0;j<m_column;j++)
// {
// TraySlot ts = new TraySlot();
// ts.Row = i + 1;
// ts.Column= j + 1;
// ts.Position = new PointF(0, 0);
// SlotPoints.Add(ts);
// }
//}
}
public TrayPosition(int row,int column,string trayName) {
//m_row= row;
//m_column= column;
RowNum = row;
ColumnNum= column;
TrayName= trayName;
}
public string TrayName { get; set; } = "料盘1";
public PointF LeftTop { get; set; } = new PointF(0, 0);
public PointF LeftBottom { get; set; } = new PointF(0, 0);
public PointF RightBottom { get; set; } = new PointF(0, 0);
public BindingList<TraySlot> SlotPoints { get; set; } = new BindingList<TraySlot>();
public bool Save()
{
try
{
float offsetX = Math.Abs(LeftTop.X - RightBottom.X)/(ColumnNum-1);
float offsetY = Math.Abs(LeftTop.Y - LeftBottom.Y)/(RowNum-1);
int index = 0;
SlotPoints.Clear();
for (int i = 0; i < m_column; i++)
{
for (int j = 0; j < m_row; j++)
{
index++;
TraySlot ts = new TraySlot();
ts.Index = index;
ts.Row = i + 1;
ts.Column = j + 1;
ts.Position = new PointF(LeftTop.X + (i * offsetX), LeftTop.Y + (j * offsetY));
SlotPoints.Add(ts);
}
}
XmlSerializerHelper.Instance.Serialize($"Recipe/{TrayName}.xml", this);
}
catch (Exception)
{
return false;
}
return true;
}
public static TrayPosition Load(string trayName,int row=26,int column=10)
{
XmlSerializerHelper.Instance.Deserialize($"Recipe/{trayName}.xml",out TrayPosition entity);
if (entity == null)
return new TrayPosition(row,column, trayName);
return entity;
}
}
}