using Rs.Controls;
using Rs.DataAccess;
using Rs.Framework;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rs.MotionPlat.Commom
{
public enum EPointType
{
///
/// 基础点位
///
BASE,
///
/// 运行点位
///
RUN
}
///
/// 料盘点位管理
///
public class TrayPointManager
{
static SqliteHelper db = new SqliteHelper();
static ConcurrentDictionary basePoints = new ConcurrentDictionary();
static ConcurrentDictionary runPoints = new ConcurrentDictionary();
public static void LoadPoint()
{
string querySql = "select * from TrayBasePoints";
DataTable dt=db.GetDataTable(querySql);
if(ObjectHelper.IsNotNullorEmpty(dt))
{
foreach (DataRow dataRow in dt.Rows)
{
string recipeName = dataRow["recipename"].ToString();
string trayName = dataRow["trayname"].ToString();
string slotIndex = dataRow["slotIndex"].ToString();
float x = float.Parse(dataRow["x"].ToString());
float y = float.Parse(dataRow["y"].ToString());
string key = $"{recipeName}-{trayName}-{slotIndex}";
if (!basePoints.ContainsKey(key))
{
basePoints.TryAdd(key, new SlotPoint(x, y));
}
}
}
querySql = "select * from TrayRunPoints";
dt = db.GetDataTable(querySql);
if (ObjectHelper.IsNotNullorEmpty(dt))
{
foreach (DataRow dataRow in dt.Rows)
{
string recipeName = dataRow["recipename"].ToString();
string trayName = dataRow["trayname"].ToString();
string slotIndex = dataRow["slotIndex"].ToString();
float x = float.Parse(dataRow["x"].ToString());
float y = float.Parse(dataRow["y"].ToString());
string key = $"{recipeName}-{trayName}-{slotIndex}";
if (!runPoints.ContainsKey(key))
{
runPoints.TryAdd(key, new SlotPoint(x, y));
}
}
}
}
///
/// 获取料盘的点位
///
///
///
///
///
///
public static SlotPoint GetSlotPoint(string recipeName,string trayName,int slotIndex, EPointType pointType= EPointType.BASE)
{
string key = $"{recipeName}-{trayName}-{slotIndex}";
if(pointType== EPointType.BASE && basePoints.ContainsKey(key))
{
return basePoints[key];
}
else if(pointType== EPointType.RUN && runPoints.ContainsKey(key))
{
return runPoints[key];
}
return null;
}
public static SlotPoint GetDistToNozzle1(int nozzleIndex)
{
//先获取相机的中心位置
SlotPoint point = new SlotPoint();
double nozzle1ToCameraCenterX = SysConfigParam.GetValue("InkpadX") - SysConfigParam.GetValue("CameraInkpadX");
double nozzle1ToCameraCenterY = SysConfigParam.GetValue("InkpadY") - SysConfigParam.GetValue("CameraInkpadY");
//再加上指定吸嘴到吸嘴1的距离
double distToNozzle1X = SysConfigParam.GetValue($"Nozzle{nozzleIndex}CenterX") - SysConfigParam.GetValue($"Nozzle1CenterX");
double distToNozzle1Y = SysConfigParam.GetValue($"Nozzle{nozzleIndex}CenterY") - SysConfigParam.GetValue($"Nozzle1CenterY");
point.X = nozzle1ToCameraCenterX + distToNozzle1X;
point.Y = nozzle1ToCameraCenterY + distToNozzle1Y;
return point;
}
}
}