764 lines
21 KiB
C#
764 lines
21 KiB
C#
using Community;
|
||
using DAL;
|
||
using Model;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Collections.ObjectModel;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using Views;
|
||
using MahApps.Metro.Controls.Dialogs;
|
||
using System.Windows.Controls;
|
||
using System.Threading;
|
||
using System.Reflection;
|
||
using System.Windows.Documents;
|
||
|
||
namespace ViewModel.Robots
|
||
{
|
||
/// <summary>
|
||
/// 机器人
|
||
/// </summary>
|
||
public abstract class FeiYuRobotVM : NotificationObject
|
||
{
|
||
/// <summary>
|
||
/// 上报异常的委托
|
||
/// </summary>
|
||
/// <param name="hv"></param>
|
||
public delegate void delegeateExcep(string hv);
|
||
/// <summary>
|
||
/// 上报异常的委托事件
|
||
/// </summary>
|
||
public abstract event delegeateExcep eventExcepReport;
|
||
|
||
|
||
/// <summary>
|
||
/// 刷新阵列点位
|
||
/// </summary>
|
||
/// <param name="type"></param>
|
||
public delegate void ShuaxinPoint(int type);
|
||
/// <summary>
|
||
/// 刷新阵列点位
|
||
/// </summary>
|
||
public abstract event ShuaxinPoint ShuaxinPointing;
|
||
|
||
|
||
private int speedS;
|
||
/// <summary>
|
||
/// 总速度
|
||
/// </summary>
|
||
public int SpeedS
|
||
{
|
||
get { return speedS; }
|
||
set
|
||
{
|
||
speedS = value;
|
||
this.RaisePropertyChanged("SpeedS");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 吸嘴对象集合
|
||
/// </summary>
|
||
public List<HandModel> XizuiLabelPaperList { get; set; }
|
||
|
||
|
||
#region 机器人参数对象
|
||
private RobotModel robotPer;
|
||
/// <summary>
|
||
/// 机器人参数对象
|
||
/// </summary>
|
||
public RobotModel RobotPer
|
||
{
|
||
get { return robotPer; }
|
||
set
|
||
{
|
||
robotPer = value;
|
||
this.RaisePropertyChanged("RobotPer");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 指令模型
|
||
/// <summary>
|
||
/// 指令模型
|
||
/// </summary>
|
||
public RobotPoint CommandModel { get; set; }
|
||
#endregion
|
||
|
||
#region 线程
|
||
/// <summary>
|
||
/// 线程1
|
||
/// </summary>
|
||
public Thread MyThread { get; set; }
|
||
/// <summary>
|
||
/// 线程2
|
||
/// </summary>
|
||
public Thread MyThread1 { get; set; }
|
||
|
||
#endregion
|
||
|
||
#region 通讯参数
|
||
|
||
/// <summary>
|
||
/// 控制器通讯对象(用于对控制器的操作通讯)
|
||
/// </summary>
|
||
public RobotSocket ControllerConn { get; set; }
|
||
/// <summary>
|
||
/// 指令交互通讯对象(用于下达运行指令的通讯)
|
||
/// </summary>
|
||
public RobotSocket CommandInteraction { get; set; }
|
||
|
||
|
||
#endregion
|
||
|
||
#region 对应的窗口对象
|
||
private UserControl myWindow;
|
||
/// <summary>
|
||
/// 对应的窗口对象
|
||
/// </summary>
|
||
public UserControl MyWindow
|
||
{
|
||
get { return myWindow; }
|
||
set
|
||
{
|
||
myWindow = value;
|
||
this.RaisePropertyChanged("MyWindow");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 命令执行交互信息
|
||
private string rcvShowInfo;
|
||
/// <summary>
|
||
/// 命令执行交互信息
|
||
/// </summary>
|
||
public string RcvShowInfo
|
||
{
|
||
get { return rcvShowInfo; }
|
||
set
|
||
{
|
||
rcvShowInfo = value;
|
||
this.RaisePropertyChanged("RcvShowInfo");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 错误代码信息
|
||
private string errorMsgShow;
|
||
/// <summary>
|
||
/// 错误代码信息
|
||
/// </summary>
|
||
public string ErrorMsgShow
|
||
{
|
||
get { return errorMsgShow; }
|
||
set
|
||
{
|
||
errorMsgShow = value;
|
||
this.RaisePropertyChanged("ErrorMsgShow");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 机器人状态显示信息
|
||
|
||
#region TeachShow
|
||
private ShowInfo teachShow;
|
||
public ShowInfo TeachShow
|
||
{
|
||
get { return teachShow; }
|
||
set
|
||
{
|
||
teachShow = value;
|
||
this.RaisePropertyChanged("TeachShow");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region AutoShow
|
||
private ShowInfo autoShow;
|
||
|
||
public ShowInfo AutoShow
|
||
{
|
||
get { return autoShow; }
|
||
set
|
||
{
|
||
autoShow = value;
|
||
this.RaisePropertyChanged("AutoShow");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region WarningShow
|
||
private ShowInfo warningShow;
|
||
|
||
public ShowInfo WarningShow
|
||
{
|
||
get { return warningShow; }
|
||
set
|
||
{
|
||
warningShow = value;
|
||
this.RaisePropertyChanged("WarningShow");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region SErrorShow
|
||
private ShowInfo sErrorShow;
|
||
|
||
public ShowInfo SErrorShow
|
||
{
|
||
get { return sErrorShow; }
|
||
set
|
||
{
|
||
sErrorShow = value;
|
||
this.RaisePropertyChanged("SErrorShow");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region SafeDoorShow
|
||
private ShowInfo safeDoorShow;
|
||
|
||
public ShowInfo SafeDoorShow
|
||
{
|
||
get { return safeDoorShow; }
|
||
set
|
||
{
|
||
safeDoorShow = value;
|
||
this.RaisePropertyChanged("SafeDoorShow");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region EStopShow
|
||
private ShowInfo eStopShow;
|
||
|
||
public ShowInfo EStopShow
|
||
{
|
||
get { return eStopShow; }
|
||
set
|
||
{
|
||
eStopShow = value;
|
||
this.RaisePropertyChanged("EStopShow");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region ErrorShow
|
||
private ShowInfo errorShow;
|
||
|
||
public ShowInfo ErrorShow
|
||
{
|
||
get { return errorShow; }
|
||
set
|
||
{
|
||
errorShow = value;
|
||
this.RaisePropertyChanged("ErrorShow");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region PausedShow
|
||
private ShowInfo pausedShow;
|
||
|
||
public ShowInfo PausedShow
|
||
{
|
||
get { return pausedShow; }
|
||
set
|
||
{
|
||
pausedShow = value;
|
||
this.RaisePropertyChanged("PausedShow");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region RunningShow
|
||
private ShowInfo runningShow;
|
||
|
||
public ShowInfo RunningShow
|
||
{
|
||
get { return runningShow; }
|
||
set
|
||
{
|
||
runningShow = value;
|
||
this.RaisePropertyChanged("RunningShow");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region ReadyShow
|
||
private ShowInfo readyShow;
|
||
|
||
public ShowInfo ReadyShow
|
||
{
|
||
get { return readyShow; }
|
||
set
|
||
{
|
||
readyShow = value;
|
||
this.RaisePropertyChanged("ReadyShow");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
#region 机器人重置
|
||
/// <summary>
|
||
/// 机器人重置
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
public abstract void Reset(object obj);
|
||
#endregion
|
||
|
||
#region 各种方法
|
||
|
||
/// <summary>
|
||
/// 重置方法
|
||
/// </summary>
|
||
public DelegateCommand ResetCommand { get; set; }
|
||
/// <summary>
|
||
/// 编辑当前点位
|
||
/// </summary>
|
||
public DelegateCommand EditorRobotPointCommand { get; set; }
|
||
/// <summary>
|
||
/// 运行到选中点位
|
||
/// </summary>
|
||
public DelegateCommand RunSelectedRobotPointCommand { get; set; }
|
||
/// <summary>
|
||
/// 保存机器人点位
|
||
/// </summary>
|
||
public DelegateCommand SaveRobotPointCommand { get; set; }
|
||
|
||
/// <summary>
|
||
/// 更新工具坐标系
|
||
/// </summary>
|
||
public DelegateCommand UpToolCoordinateCommand { get; set; }
|
||
|
||
/// <summary>
|
||
/// 鼠标点击PG移动
|
||
/// </summary>
|
||
public DelegateCommand RobotPGMoveCommand { get; set; }
|
||
|
||
/// <summary>
|
||
/// 手动回原点
|
||
/// </summary>
|
||
public DelegateCommand GoHomeCommand { get; set; }
|
||
|
||
/// <summary>
|
||
/// 保存备用参数
|
||
/// </summary>
|
||
public DelegateCommand SaveLaserCommand { get; set; }
|
||
|
||
#endregion
|
||
public int RobotNumber { get; set; }
|
||
#region 对应的生产机种
|
||
private MachineModel machineObj;
|
||
/// <summary>
|
||
/// 对应的生产机种
|
||
/// </summary>
|
||
public MachineModel MachineObj
|
||
{
|
||
get { return machineObj; }
|
||
set
|
||
{
|
||
machineObj = value;
|
||
if (value.ID > 0)
|
||
{
|
||
machineObj.RobotPointList = dal.GetRobotPoint(value.ID);
|
||
RobotPointList = machineObj.RobotPointList.Where(w => w.PointClass == RobotNumber).ToList();
|
||
}
|
||
this.RaisePropertyChanged("MachineObj");
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 所有测试站集合
|
||
//private ObservableCollection<TestBoxModel> stationList;
|
||
///// <summary>
|
||
///// 所有测试站集合
|
||
///// </summary>
|
||
//public ObservableCollection<TestBoxModel> StationList
|
||
//{
|
||
// get { return stationList; }
|
||
// set
|
||
// {
|
||
// stationList = value;
|
||
|
||
// if (StationList != null)
|
||
// {
|
||
// CommonList = new List<CommonClass>();
|
||
// CommonList.Add(new CommonClass() { ID = 0, CommonName = "公共点位" });
|
||
// CommonList.Add(new CommonClass() { ID = 101, CommonName = "取料1" });
|
||
// CommonList.Add(new CommonClass() { ID = 102, CommonName = "取料2" });
|
||
// CommonList.Add(new CommonClass() { ID = 103, CommonName = "Buff1" });
|
||
// CommonList.Add(new CommonClass() { ID = 104, CommonName = "Buff2" });
|
||
// CommonList.Add(new CommonClass() { ID = 105, CommonName = "Buff3" });
|
||
// CommonList.Add(new CommonClass() { ID = 106, CommonName = "Buff4" });
|
||
// CommonList.Add(new CommonClass() { ID = 107, CommonName = "Buff5" });
|
||
// CommonList.Add(new CommonClass() { ID = 108, CommonName = "不良1" });
|
||
// CommonList.Add(new CommonClass() { ID = 109, CommonName = "不良2" });
|
||
// CommonList.Add(new CommonClass() { ID = 110, CommonName = "清Socket" });
|
||
// CommonList.Add(new CommonClass() { ID = 111, CommonName = "标准件1" });
|
||
// CommonList.Add(new CommonClass() { ID = 112, CommonName = "标准件2" });
|
||
// foreach (var item in value)
|
||
// {
|
||
// CommonList.Add(new CommonClass() { ID = item.ID, CommonName = item.StationName });
|
||
// }
|
||
// }
|
||
|
||
// //this.RaisePropertyChanged("StationList");
|
||
// }
|
||
//}
|
||
|
||
#endregion
|
||
|
||
#region 所有点位的分类集合 用于点位分类筛选
|
||
private List<CommonClass> commonList;
|
||
/// <summary>
|
||
/// 所有点位的分类集合 用于点位分类筛选
|
||
/// </summary>
|
||
public List<CommonClass> CommonList
|
||
{
|
||
get { return commonList; }
|
||
set
|
||
{
|
||
commonList = value;
|
||
this.RaisePropertyChanged("CommonList");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 选中的测试站(测试箱)ID 这里用于切换对应测试箱的点位
|
||
private int selectStationID;
|
||
/// <summary>
|
||
/// 选中的测试站(测试箱)ID 这里用于切换对应测试箱的点位
|
||
/// </summary>
|
||
public int SelectStationID
|
||
{
|
||
get { return selectStationID; }
|
||
set
|
||
{
|
||
selectStationID = value;
|
||
if (RobotPointList != null && RobotPointList.Count > 0)
|
||
{
|
||
LocalRobotPointList = new ObservableCollection<RobotPoint>(RobotPointList.Where(w => w.PointClass == value).ToList());
|
||
SelectStationName = CommonList.Where(w => w.ID == value).FirstOrDefault().CommonName;
|
||
}
|
||
this.RaisePropertyChanged("SelectStationID");
|
||
}
|
||
}
|
||
|
||
private string selectStationName;
|
||
/// <summary>
|
||
/// 选中的局部点位名称
|
||
/// </summary>
|
||
public string SelectStationName
|
||
{
|
||
get { return selectStationName; }
|
||
set { selectStationName = value;
|
||
this.RaisePropertyChanged("SelectStationName");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
#region 选中的局部点位
|
||
private ObservableCollection<RobotPoint> localRobotPointList;
|
||
/// <summary>
|
||
/// 选中的局部点位
|
||
/// </summary>
|
||
public ObservableCollection<RobotPoint> LocalRobotPointList
|
||
{
|
||
get { return localRobotPointList; }
|
||
set
|
||
{
|
||
localRobotPointList = value;
|
||
this.RaisePropertyChanged("LocalRobotPointList");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 公共点位集合
|
||
private ObservableCollection<RobotPoint> publicPointList;
|
||
/// <summary>
|
||
/// 公共点位集合
|
||
/// </summary>
|
||
public ObservableCollection<RobotPoint> PublicPointList
|
||
{
|
||
get { return publicPointList; }
|
||
set
|
||
{
|
||
publicPointList = value;
|
||
this.RaisePropertyChanged("PublicPointList");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 数据对象
|
||
/// <summary>
|
||
/// 数据对象
|
||
/// </summary>
|
||
public MainWindowDAL dal = new MainWindowDAL();
|
||
#endregion
|
||
|
||
#region 机器人点位参数集合
|
||
|
||
private List<RobotPoint> robotPointList;
|
||
/// <summary>
|
||
/// 机器人点位参数集合
|
||
/// </summary>
|
||
public List<RobotPoint> RobotPointList
|
||
{
|
||
get { return robotPointList; }
|
||
set
|
||
{
|
||
robotPointList = value;
|
||
if (RobotPointList != null && RobotPointList.Count > 0)
|
||
{
|
||
PublicPointList = new ObservableCollection<RobotPoint>(RobotPointList.Where(w => w.PointClass == RobotNumber).ToList());
|
||
LocalRobotPointList = PublicPointList;
|
||
}
|
||
this.RaisePropertyChanged("RobotPointList");
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 机器人当前位置
|
||
private RobotPoint robotCurPos;
|
||
/// <summary>
|
||
/// 机器人当前位置
|
||
/// </summary>
|
||
public RobotPoint RobotCurPos
|
||
{
|
||
get { return robotCurPos; }
|
||
set
|
||
{
|
||
robotCurPos = value;
|
||
this.RaisePropertyChanged("RobotCurPos");
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 选中的机器人点位
|
||
private RobotPoint selectedRobotPoint;
|
||
/// <summary>
|
||
/// 选中的机器人点位
|
||
/// </summary>
|
||
public RobotPoint SelectedRobotPoint
|
||
{
|
||
get { return selectedRobotPoint; }
|
||
set
|
||
{
|
||
selectedRobotPoint = value;
|
||
EditingEnabled = false;
|
||
this.RaisePropertyChanged("SelectedRobotPoint");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 机器人点位编辑相关
|
||
|
||
#region 启用编辑
|
||
private bool editingEnabled;
|
||
/// <summary>
|
||
/// 启用编辑
|
||
/// </summary>
|
||
public bool EditingEnabled
|
||
{
|
||
get { return editingEnabled; }
|
||
set
|
||
{
|
||
editingEnabled = value;
|
||
this.RaisePropertyChanged("EditingEnabled");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 机器人微调参数
|
||
private double robotTuningDis;
|
||
/// <summary>
|
||
/// 机器人微调参数
|
||
/// </summary>
|
||
public double RobotTuningDis
|
||
{
|
||
get { return robotTuningDis; }
|
||
set
|
||
{
|
||
robotTuningDis = value;
|
||
this.RaisePropertyChanged("RobotTuningDis");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 机器人PG移动方法
|
||
/// <summary>
|
||
/// 机器人PG移动方法
|
||
/// </summary>
|
||
public abstract void RobotMove(string direction);
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 鼠标点击PG移动
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
public abstract void RobotPGMove(object obj);
|
||
|
||
|
||
#region 编辑点位
|
||
/// <summary>
|
||
/// 编辑点位
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
public abstract void EditorRobotPoint(object obj);
|
||
#endregion
|
||
|
||
#region 保存机器人点位
|
||
/// <summary>
|
||
/// 保存机器人点位
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
public abstract void SaveRobotPoint(object obj);
|
||
#endregion
|
||
|
||
#region 运行到选中点位
|
||
/// <summary>
|
||
/// 运行到选中点位
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
public abstract void RunSelectedRobotPointPoint(object obj);
|
||
#endregion
|
||
#endregion
|
||
|
||
#region 手动回原点
|
||
/// <summary>
|
||
/// 手动回原点
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
public abstract void GoHome(object obj);
|
||
#endregion
|
||
|
||
#region 机器人回原点
|
||
/// <summary>
|
||
/// 机器人回原点步骤
|
||
/// </summary>
|
||
public GengralProcessEnum HomeStep { get; set; }
|
||
public DateTime HomeTime { get; set; }
|
||
/// <summary>
|
||
/// 机器人回原点
|
||
/// </summary>
|
||
public abstract void RobotOrgin();
|
||
|
||
#endregion
|
||
|
||
#region 运行点位
|
||
/// <summary>
|
||
/// 运行点位
|
||
/// </summary>
|
||
/// <param name="point"></param>
|
||
/// <param name="runType">是否是PG运行</param>
|
||
/// <returns></returns>
|
||
public abstract bool RunRobotPoint(RobotPoint point, bool runType = false);
|
||
|
||
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 更新工具坐标系
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
public abstract void UpToolCoordinate(object obj);
|
||
|
||
/// <summary>
|
||
/// 保存备用参数
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
public abstract void SaveLaser(object obj);
|
||
|
||
/// <summary>
|
||
/// 比较两个坐标未知 适用发那科
|
||
/// </summary>
|
||
/// <param name="point"></param>
|
||
/// <param name="point2"></param>
|
||
/// <returns></returns>
|
||
public abstract bool Bijiao(RobotPoint point);
|
||
|
||
|
||
|
||
#region 利用反射进行对象复制
|
||
/// <summary>
|
||
/// 利用反射进行对象复制
|
||
/// </summary>
|
||
/// <typeparam name="InsertRunPar">复制对象类型</typeparam>
|
||
/// <param name="startPoint">被复制对象</param>
|
||
/// <returns></returns>
|
||
public RobotPoint Coper(RobotPoint startPoint)
|
||
{
|
||
RobotPoint irpa = new RobotPoint();
|
||
try
|
||
{
|
||
var Types = startPoint.GetType();//获得类型
|
||
var Typed = irpa.GetType();
|
||
foreach (PropertyInfo sp in Types.GetProperties())//获得类型的属性字段
|
||
{
|
||
foreach (PropertyInfo dp in Typed.GetProperties())
|
||
{
|
||
if (dp.Name == sp.Name)//判断属性名是否相同
|
||
{
|
||
dp.SetValue(irpa, sp.GetValue(startPoint, null), null);//获得s对象属性的值复制给d对象的属性
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
|
||
return irpa;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 利用反射进行对象复制
|
||
/// </summary>
|
||
/// <typeparam name="T"></typeparam>
|
||
/// <param name="Coperobj"></param>
|
||
/// <returns></returns>
|
||
public T Coper<T>(T Coperobj)
|
||
{
|
||
T a = System.Activator.CreateInstance<T>();
|
||
try
|
||
{
|
||
var Types = Coperobj.GetType();//获得类型
|
||
var Typed = a.GetType();
|
||
foreach (PropertyInfo sp in Types.GetProperties())//获得类型的属性字段
|
||
{
|
||
foreach (PropertyInfo dp in Typed.GetProperties())
|
||
{
|
||
if (dp.Name == sp.Name)//判断属性名是否相同
|
||
{
|
||
dp.SetValue(a, sp.GetValue(Coperobj, null), null);//获得s对象属性的值复制给d对象的属性
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
|
||
return a;
|
||
}
|
||
|
||
#endregion
|
||
|
||
}
|
||
}
|