精简rstray控件

master
lhiven 2 years ago
parent 3bcc38ca89
commit c6357341bd

@ -32,10 +32,7 @@ namespace Rs.Controls
public partial class RsTray : UserControl
{
public string RecipeName { get; set; } = "default";
private int CurrentSlot { get; set; } = 1;
private TrayInfo trayInfo;
public string ItemName { get; set; }
public ESortDir SortDir { get; set; } = ESortDir.Horizontal;
public event Action<TraySlot, MouseEventArgs> SlotClickEvent;
@ -73,11 +70,6 @@ namespace Rs.Controls
};
}
public void NextSlot()
{
CurrentSlot++;
}
public void ResetTray()
{
CurrentSlot = 1;
@ -267,8 +259,6 @@ namespace Rs.Controls
slot.Row = r;
slot.Column = c;
slot.SlotStatus = status;
//slot.Bound = new RectangleF((LeftSpaceWidth + widthPer * c), (TopSpaceHeight + heightPer * r), (int)widthPer - 5, (int)heightPer - 5);
//slot.Draw(g2);
traySlots.Add(slot);
traySlotsDic.Add(index, slot);
}
@ -286,8 +276,6 @@ namespace Rs.Controls
slot.Row = r;
slot.Column = c;
slot.SlotStatus = status;
//slot.Bound = new RectangleF((LeftSpaceWidth + widthPer * c), (TopSpaceHeight + heightPer * r), (int)widthPer - 5, (int)heightPer - 5);
//slot.Draw(g2);
traySlots.Add(slot);
traySlotsDic.Add(index, slot);
}
@ -297,63 +285,6 @@ namespace Rs.Controls
}
public void Init()
{
trayInfo = new TrayInfo(SortDir, RowNum, ColumnNum, ItemName);
trayInfo = trayInfo.Init(RecipeName);
}
public bool Save()
{
return trayInfo.Save(this);
}
public void SetLeftTop(PointF point)
{
trayInfo.LeftTop = point;
}
public void SetLeftBottom(PointF point)
{
trayInfo.LeftBottom = point;
}
public void SetRightBottom(PointF point)
{
trayInfo.RightBottom = point;
}
public PointF GetLeftTop()
{
return trayInfo.LeftTop;
}
public PointF GetLeftBottom()
{
return trayInfo.LeftBottom;
}
public PointF GetRightBottom()
{
return trayInfo.RightBottom;
}
public List<TraySlot> GetAllSlot()
{
return trayInfo.SlotPoints;
}
public TraySlot GetSlot(int index)
{
return trayInfo.GetSlot(index);
}
public TraySlot GetCurrentSlot()
{
return trayInfo.GetSlot(CurrentSlot);
}
public void Fill()
{
foreach (TraySlot item in traySlots)
@ -377,8 +308,6 @@ namespace Rs.Controls
traySlotsDic[index].SlotStatus = status;
traySlotsDic[index].Refresh(this.panel2.CreateGraphics(), ShowText);
}
//panel2_Paint(null, null);
}
private void UpdateSlotPos()
@ -445,13 +374,6 @@ namespace Rs.Controls
//画料盘的行号
g2.DrawString((r + 1).ToString(), new Font("宋体", 7.0F), new SolidBrush(Color.White), new PointF(5, TopSpaceHeight + (heightPer * r)));
}
//Rectangle rect = new Rectangle((int)(LeftSpaceWidth + widthPer * c), (int)(TopSpaceHeight + heightPer * r), (int)widthPer - 5, (int)heightPer - 5);
//g2.DrawRectangle(Pens.Red, (LeftSpaceWidth + widthPer * c), (TopSpaceHeight + heightPer * r), (int)widthPer - 5, (int)heightPer - 5);
//TraySlot slot = new TraySlot();
//slot.Row = r;
//slot.Column = c;
//slot.Bound = new RectangleF((LeftSpaceWidth + widthPer * c), (TopSpaceHeight + heightPer * r), (int)widthPer - 5, (int)heightPer - 5);
//slot.Draw(g2);
if (traySlotsDic.ContainsKey(index))
{
traySlotsDic[index].Draw(g2, ShowText);
@ -462,9 +384,6 @@ namespace Rs.Controls
g.DrawImage(drawImage, 0, 0, drawImage.Width, drawImage.Height);
if (drawRegion)
{
//drawRect.Width = 20;
//drawRect.Height = 20;
//g.DrawRectangle(Pens.Green, drawRect);
g.FillRectangle(new SolidBrush(Color.FromArgb(200, Color.Pink)), drawRect);
}
g.Flush();
@ -640,16 +559,6 @@ namespace Rs.Controls
default:
break;
}
//if(Status==1)
//{
// g.FillRectangle(new SolidBrush(Color.Red), Bound.X, Bound.Y, Bound.Width - 1, Bound.Height - 1);
//}
//else if(Status==0)
//{
// g.FillRectangle(new SolidBrush(Color.FromArgb(11, 16, 36)), Bound.X, Bound.Y, Bound.Width-1, Bound.Height-1);
// // g.FillRectangle(new SolidBrush(Color.Red), Bound.X, Bound.Y, Bound.Width , Bound.Height );
//}
g.DrawRectangle(Pens.White, Bound.X, Bound.Y, Bound.Width, Bound.Height);
if (isShowText)
{
@ -659,150 +568,4 @@ namespace Rs.Controls
}
}
public class TrayInfo
{
public TrayInfo() { }
public TrayInfo(ESortDir sortDir,int rowNum,int colNum,string itemName) {
RowNum=rowNum;
ColumnNum=colNum;
ItemName=itemName;
SortDir=sortDir;
}
public ESortDir SortDir { get; set; } = ESortDir.Horizontal;
public string ItemName { get; set; }
private int _RowNum = 26;
/// <summary>
/// 行数
/// </summary>
public int RowNum
{
get { return _RowNum; }
set { _RowNum = value; }
}
private int _ColumnNum = 10;
/// <summary>
/// 列数量
/// </summary>
public int ColumnNum
{
get { return _ColumnNum; }
set { _ColumnNum = value; }
}
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 List<TraySlot> SlotPoints { get; set; } = new List<TraySlot>();
public bool Save(RsTray rsTray)
{
try
{
float offsetX = -12.8f;
float offsetY = 11.8f;
int index = 0;
int rowNum = 0;
SlotPoints.Clear();
HTuple rows = new HTuple();
HTuple columns = new HTuple();
if (SortDir == ESortDir.Horizontal)
{
for (int i = 0; i < RowNum; i++)
{
for (int j = 0; j < ColumnNum; j++)
{
index++;
TraySlot ts = new TraySlot();
ts.Index = index;
ts.Row = i + 1;
ts.Column = j + 1;
ts.Position = new PointF(LeftTop.X + (j * rsTray.OffsetX), LeftTop.Y + (i * rsTray.OffsetY));
//1 2 3 4
//ts.Position = new PointF(LeftTop.X + (j * rsTray.OffsetX), LeftTop.Y + ((i-(i/2)) * rsTray.OffsetY) +(i/2)*rsTray.OffsetYEven);
rows.Append(ts.Position.Y);
columns.Append(ts.Position.X);
SlotPoints.Add(ts);
}
}
if(!rsTray.SinglePoint)
{
//求斜率
HOperatorSet.AngleLx(LeftTop.Y, LeftTop.X, LeftBottom.Y, LeftBottom.X, out HTuple angle);
double deg = AngleTool.Rad2Deg(angle) + 90;
HOperatorSet.HomMat2dIdentity(out HTuple homMat2dIdentity);
HOperatorSet.HomMat2dRotate(homMat2dIdentity, AngleTool.Deg2Rad(deg), LeftTop.Y, LeftTop.X, out HTuple homMat2dRotate);
HOperatorSet.AffineTransPoint2d(homMat2dRotate, rows, columns, out HTuple qx, out HTuple qy);
for (int i = 0; i < qx.Length; i++)
{
GetSlot(i + 1).Position = new PointF((float)qy.DArr[i], (float)qx.DArr[i]);
}
}
}
else
{
for (int i = 0; i < ColumnNum; i++)
{
for (int j = 0; j < RowNum; 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);
}
}
}
string dirPath = Path.Combine("recipe",rsTray.RecipeName, ItemName);
if (!Directory.Exists(dirPath))
{
Directory.CreateDirectory(dirPath);
}
XmlSerializerHelper.Instance.Serialize($"{dirPath}/tray.xml", this);
}
catch (Exception)
{
return false;
}
return true;
}
public TrayInfo Init(string recipeName)
{
string dirPath = Path.Combine("recipe",recipeName, ItemName);
if (!Directory.Exists(dirPath))
{
Directory.CreateDirectory(dirPath);
}
XmlSerializerHelper.Instance.Deserialize($"{dirPath}/tray.xml", out TrayInfo tray);
if (tray == null)
return new TrayInfo(SortDir,RowNum,ColumnNum,ItemName);
tray.RowNum = RowNum;
tray.ColumnNum = ColumnNum;
return tray;
}
public TraySlot GetSlot(int index)
{
if (SlotPoints != null && SlotPoints.Count > 0)
{
TraySlot ts = SlotPoints.Where(s => s.Index == index).First();
if (ts != null)
return ts;
}
return null;
}
}
}

@ -556,7 +556,6 @@
this.trayEmpty1.OffsetX = 0F;
this.trayEmpty1.OffsetY = 0F;
this.trayEmpty1.OffsetYEven = 0F;
this.trayEmpty1.RecipeName = "default";
this.trayEmpty1.RowNum = 9;
this.trayEmpty1.RowSpace = 3;
this.trayEmpty1.SelectSlot = null;
@ -585,7 +584,6 @@
this.trayInput.OffsetX = 0F;
this.trayInput.OffsetY = 0F;
this.trayInput.OffsetYEven = 0F;
this.trayInput.RecipeName = "default";
this.trayInput.RowNum = 9;
this.trayInput.RowSpace = 3;
this.trayInput.SelectSlot = null;
@ -614,7 +612,6 @@
this.trayOk.OffsetX = 0F;
this.trayOk.OffsetY = 0F;
this.trayOk.OffsetYEven = 0F;
this.trayOk.RecipeName = "default";
this.trayOk.RowNum = 9;
this.trayOk.RowSpace = 3;
this.trayOk.SelectSlot = null;
@ -644,7 +641,6 @@
this.trayNg.OffsetX = 0F;
this.trayNg.OffsetY = 0F;
this.trayNg.OffsetYEven = 0F;
this.trayNg.RecipeName = "default";
this.trayNg.RowNum = 9;
this.trayNg.RowSpace = 3;
this.trayNg.SelectSlot = null;
@ -674,7 +670,6 @@
this.trayMulti.OffsetX = 0F;
this.trayMulti.OffsetY = 0F;
this.trayMulti.OffsetYEven = 0F;
this.trayMulti.RecipeName = "default";
this.trayMulti.RowNum = 9;
this.trayMulti.RowSpace = 3;
this.trayMulti.SelectSlot = null;
@ -704,7 +699,6 @@
this.trayEmpty2.OffsetX = 0F;
this.trayEmpty2.OffsetY = 0F;
this.trayEmpty2.OffsetYEven = 0F;
this.trayEmpty2.RecipeName = "default";
this.trayEmpty2.RowNum = 9;
this.trayEmpty2.RowSpace = 3;
this.trayEmpty2.SelectSlot = null;
@ -758,7 +752,6 @@
this.trayTurnover.OffsetX = 0F;
this.trayTurnover.OffsetY = 0F;
this.trayTurnover.OffsetYEven = 0F;
this.trayTurnover.RecipeName = "default";
this.trayTurnover.RowNum = 4;
this.trayTurnover.RowSpace = 3;
this.trayTurnover.SelectSlot = null;

@ -369,7 +369,7 @@ namespace Rs.MotionPlat
ColumnNum = 8,
};
turnoverTray.ItemName = "中转盘";
turnoverTray.Init();
//turnoverTray.Init();
GlobalTray.TurnoverTray = turnoverTray;
@ -388,14 +388,14 @@ namespace Rs.MotionPlat
hwin_vac1.HobjectToHimage(image);
//hSmartWindowControl1.HalconWindow.SetDraw("margin");
}
trayEmpty1.ItemName = "料盘1";
trayEmpty1.Init();
trayEmpty1.ItemName = "Empty1";
//trayEmpty1.Init();
trayInput.ItemName = "Input";
trayInput.Init();
trayOk.ItemName = "料盘3";
trayOk.Init();
trayNg.ItemName = "料盘4";
trayNg.Init();
//trayInput.Init();
trayOk.ItemName = "Ok";
//trayOk.Init();
trayNg.ItemName = "Ng";
//trayNg.Init();
//okTray1.ItemName = "料盘5";
//okTray1.Init();

@ -448,7 +448,6 @@
this.rsTray1.OffsetX = 0F;
this.rsTray1.OffsetY = 0F;
this.rsTray1.OffsetYEven = 0F;
this.rsTray1.RecipeName = "default";
this.rsTray1.RowNum = 9;
this.rsTray1.RowSpace = 5;
this.rsTray1.SelectSlot = null;

@ -133,7 +133,6 @@
this.rsTray1.OffsetX = 0F;
this.rsTray1.OffsetY = 0F;
this.rsTray1.OffsetYEven = 0F;
this.rsTray1.RecipeName = "default";
this.rsTray1.RowNum = 9;
this.rsTray1.RowSpace = 3;
this.rsTray1.SelectSlot = null;

@ -55,12 +55,12 @@ namespace Rs.MotionPlat
{
panel2.Visible = false;
}
rsTray1.Init();
//rsTray1.Init();
rsTray1.Clear();
slot_lefttop.Position = rsTray1.GetLeftTop();//.LeftTop;
slot_leftbottom.Position = rsTray1.GetLeftBottom();
slot_rightbottom.Position = rsTray1.GetRightBottom();
dataGridView1.DataSource = rsTray1.GetAllSlot().Select(sp => new { Index = sp.Index, X = sp.Position.X, Y = sp.Position.Y }).ToList();
//slot_lefttop.Position = rsTray1.GetLeftTop();//.LeftTop;
//slot_leftbottom.Position = rsTray1.GetLeftBottom();
//slot_rightbottom.Position = rsTray1.GetRightBottom();
//dataGridView1.DataSource = rsTray1.GetAllSlot().Select(sp => new { Index = sp.Index, X = sp.Position.X, Y = sp.Position.Y }).ToList();
}
@ -87,30 +87,30 @@ namespace Rs.MotionPlat
protected void SavePosEvent(object sender, EventArgs e)
{
if (rsTray1.Save())
{
dataGridView1.DataSource = null;
dataGridView1.DataSource = rsTray1.GetAllSlot().Select(sp => new { Index = sp.Index, X = sp.Position.X, Y = sp.Position.Y }).ToList();
Msg.ShowInfo("Save point success!");
}
//if (rsTray1.Save())
//{
// dataGridView1.DataSource = null;
// dataGridView1.DataSource = rsTray1.GetAllSlot().Select(sp => new { Index = sp.Index, X = sp.Position.X, Y = sp.Position.Y }).ToList();
// Msg.ShowInfo("Save point success!");
//}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
if (e.ColumnIndex == 3)
{
int slot = e.RowIndex + 1;
DialogResult dr = MessageBox.Show($"确定移动到{slot}号槽位吗?","Tips",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
if(dr== DialogResult.OK)
{
TraySlot ts =rsTray1.GetAllSlot()[slot - 1];
AxisControl.LoadX.MovePos(ts.Position.X,10);
AxisControl.LoadY.MovePos(ts.Position.Y, 10);
}
}
}
//if (e.RowIndex >= 0)
//{
// if (e.ColumnIndex == 3)
// {
// int slot = e.RowIndex + 1;
// DialogResult dr = MessageBox.Show($"确定移动到{slot}号槽位吗?","Tips",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
// if(dr== DialogResult.OK)
// {
// TraySlot ts =rsTray1.GetAllSlot()[slot - 1];
// AxisControl.LoadX.MovePos(ts.Position.X,10);
// AxisControl.LoadY.MovePos(ts.Position.Y, 10);
// }
// }
//}
}
private void rsTray1_SlotClickEvent(TraySlot obj, MouseEventArgs e)
@ -120,13 +120,13 @@ namespace Rs.MotionPlat
private void tsmi_go_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show($"确定移动到{rsTray1.SelectSlot.Index.ToString()}号槽位吗?", "Tips", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if(dr== DialogResult.OK)
{
TraySlot ts =rsTray1.GetSlot(rsTray1.SelectSlot.Index);
AxisControl.LoadX.MovePos(ts.Position.X, 10);
AxisControl.LoadY.MovePos(ts.Position.Y, 10);
}
//DialogResult dr = MessageBox.Show($"确定移动到{rsTray1.SelectSlot.Index.ToString()}号槽位吗?", "Tips", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
//if(dr== DialogResult.OK)
//{
// TraySlot ts =rsTray1.GetSlot(rsTray1.SelectSlot.Index);
// AxisControl.LoadX.MovePos(ts.Position.X, 10);
// AxisControl.LoadY.MovePos(ts.Position.Y, 10);
//}
}
@ -154,38 +154,38 @@ namespace Rs.MotionPlat
private void slot_lefttop_FetchPositionEvent(object sender, EventArgs e)
{
ErrorCode errCode = AxisControl.LoadX.GetEncoderPosition(out double dEncPosX);
if (errCode > ErrorCode.Ok)
{
Msg.ShowError(errCode.ToString());
return;
}
AxisControl.LoadY.GetEncoderPosition(out double dEncPosY);
if (errCode > ErrorCode.Ok)
{
Msg.ShowError(errCode.ToString());
return;
}
slot_lefttop.Position = new PointF((float)dEncPosX, (float)dEncPosY);
rsTray1.SetLeftTop(slot_lefttop.Position);
//ErrorCode errCode = AxisControl.LoadX.GetEncoderPosition(out double dEncPosX);
//if (errCode > ErrorCode.Ok)
//{
// Msg.ShowError(errCode.ToString());
// return;
//}
//AxisControl.LoadY.GetEncoderPosition(out double dEncPosY);
//if (errCode > ErrorCode.Ok)
//{
// Msg.ShowError(errCode.ToString());
// return;
//}
//slot_lefttop.Position = new PointF((float)dEncPosX, (float)dEncPosY);
//rsTray1.SetLeftTop(slot_lefttop.Position);
}
private void slot_leftbottom_FetchPositionEvent(object sender, EventArgs e)
{
ErrorCode errCode = AxisControl.LoadX.GetEncoderPosition(out double dEncPosX);
if (errCode > ErrorCode.Ok)
{
Msg.ShowError(errCode.ToString());
return;
}
AxisControl.LoadY.GetEncoderPosition(out double dEncPosY);
if (errCode > ErrorCode.Ok)
{
Msg.ShowError(errCode.ToString());
return;
}
slot_leftbottom.Position = new PointF((float)dEncPosX, (float)dEncPosY);
rsTray1.SetLeftBottom(slot_leftbottom.Position);
//ErrorCode errCode = AxisControl.LoadX.GetEncoderPosition(out double dEncPosX);
//if (errCode > ErrorCode.Ok)
//{
// Msg.ShowError(errCode.ToString());
// return;
//}
//AxisControl.LoadY.GetEncoderPosition(out double dEncPosY);
//if (errCode > ErrorCode.Ok)
//{
// Msg.ShowError(errCode.ToString());
// return;
//}
//slot_leftbottom.Position = new PointF((float)dEncPosX, (float)dEncPosY);
//rsTray1.SetLeftBottom(slot_leftbottom.Position);
}
private void TrayRecipe_FormClosing(object sender, FormClosingEventArgs e)

@ -845,7 +845,6 @@
this.rsTray1.OffsetX = 0F;
this.rsTray1.OffsetY = 0F;
this.rsTray1.OffsetYEven = 0F;
this.rsTray1.RecipeName = "default";
this.rsTray1.RowNum = 4;
this.rsTray1.RowSpace = 3;
this.rsTray1.SelectSlot = null;

Loading…
Cancel
Save