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;
namespace ViewModel.Robots
{
///
/// 机器人
///
public abstract class FeiYuRobotVM : NotificationObject
{
///
/// 上报异常的委托
///
///
public delegate void delegeateExcep(string hv);
///
/// 上报异常的委托事件
///
public abstract event delegeateExcep eventExcepReport;
private int speedS;
///
/// 总速度
///
public int SpeedS
{
get { return speedS; }
set
{
speedS = value;
this.RaisePropertyChanged("SpeedS");
}
}
#region 机器人参数对象
private RobotModel robotPer;
///
/// 机器人参数对象
///
public RobotModel RobotPer
{
get { return robotPer; }
set
{
robotPer = value;
this.RaisePropertyChanged("RobotPer");
}
}
#endregion
#region 指令模型
///
/// 指令模型
///
public RobotPoint CommandModel { get; set; }
#endregion
#region 线程
///
/// 线程1
///
public Thread MyThread { get; set; }
///
/// 线程2
///
public Thread MyThread1 { get; set; }
#endregion
#region 通讯参数
///
/// 控制器通讯对象(用于对控制器的操作通讯)
///
public RobotSocket ControllerConn { get; set; }
///
/// 指令交互通讯对象(用于下达运行指令的通讯)
///
public RobotSocket CommandInteraction { get; set; }
#endregion
#region 对应的窗口对象
private Robot myWindow;
///
/// 对应的窗口对象
///
public Robot MyWindow
{
get { return myWindow; }
set
{
myWindow = value;
this.RaisePropertyChanged("MyWindow");
}
}
#endregion
#region 命令执行交互信息
private string rcvShowInfo;
///
/// 命令执行交互信息
///
public string RcvShowInfo
{
get { return rcvShowInfo; }
set
{
rcvShowInfo = value;
this.RaisePropertyChanged("RcvShowInfo");
}
}
#endregion
#region 错误代码信息
private string errorMsgShow;
///
/// 错误代码信息
///
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 机器人重置
///
/// 机器人重置
///
///
public abstract void Reset(object obj);
#endregion
#region 各种方法
///
/// 重置方法
///
public DelegateCommand ResetCommand { get; set; }
///
/// 编辑当前点位
///
public DelegateCommand EditorRobotPointCommand { get; set; }
///
/// 运行到选中点位
///
public DelegateCommand RunSelectedRobotPointCommand { get; set; }
///
/// 保存机器人点位
///
public DelegateCommand SaveRobotPointCommand { get; set; }
///
/// 更新工具坐标系
///
public DelegateCommand UpToolCoordinateCommand { get; set; }
///
/// 鼠标点击PG移动
///
public DelegateCommand RobotPGMoveCommand { get; set; }
///
/// 手动回原点
///
public DelegateCommand GoHomeCommand { get; set; }
///
/// 保存备用参数
///
public DelegateCommand SaveLaserCommand { get; set; }
#endregion
#region 对应的生产机种
private MachineModel machineObj;
///
/// 对应的生产机种
///
public MachineModel MachineObj
{
get { return machineObj; }
set
{
machineObj = value;
if (value.ID > 0)
{
RobotPointList = dal.GetRobotPoint(value.ID);
MachineObj.RobotPointList = RobotPointList;
}
this.RaisePropertyChanged("MachineObj");
}
}
#endregion
#region 所有测试站集合
//private ObservableCollection stationList;
/////
///// 所有测试站集合
/////
//public ObservableCollection StationList
//{
// get { return stationList; }
// set
// {
// stationList = value;
// if (StationList != null)
// {
// CommonList = new List();
// 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 commonList;
///
/// 所有点位的分类集合 用于点位分类筛选
///
public List CommonList
{
get { return commonList; }
set
{
commonList = value;
this.RaisePropertyChanged("CommonList");
}
}
#endregion
#region 选中的测试站(测试箱)ID 这里用于切换对应测试箱的点位
private int selectStationID;
///
/// 选中的测试站(测试箱)ID 这里用于切换对应测试箱的点位
///
public int SelectStationID
{
get { return selectStationID; }
set
{
selectStationID = value;
if (RobotPointList != null && RobotPointList.Count > 0)
{
LocalRobotPointList = new ObservableCollection(RobotPointList.Where(w => w.PointClass == value).ToList());
}
this.RaisePropertyChanged("SelectStationID");
}
}
#endregion
#region 选中的局部点位
private ObservableCollection localRobotPointList;
///
/// 选中的局部点位
///
public ObservableCollection LocalRobotPointList
{
get { return localRobotPointList; }
set
{
localRobotPointList = value;
this.RaisePropertyChanged("LocalRobotPointList");
}
}
#endregion
#region 公共点位集合
private ObservableCollection publicPointList;
///
/// 公共点位集合
///
public ObservableCollection PublicPointList
{
get { return publicPointList; }
set
{
publicPointList = value;
this.RaisePropertyChanged("PublicPointList");
}
}
#endregion
#region 数据对象
///
/// 数据对象
///
public MainWindowDAL dal = new MainWindowDAL();
#endregion
#region 机器人点位参数集合
private List robotPointList;
///
/// 机器人点位参数集合
///
public List RobotPointList
{
get { return robotPointList; }
set
{
robotPointList = value;
if (RobotPointList != null && RobotPointList.Count > 0)
{
PublicPointList = new ObservableCollection(RobotPointList.Where(w => w.PointClass == 0).ToList());
LocalRobotPointList = PublicPointList;
}
this.RaisePropertyChanged("RobotPointList");
}
}
#endregion
#region 机器人当前位置
private RobotPoint robotCurPos;
///
/// 机器人当前位置
///
public RobotPoint RobotCurPos
{
get { return robotCurPos; }
set
{
robotCurPos = value;
this.RaisePropertyChanged("RobotCurPos");
}
}
#endregion
#region 选中的机器人点位
private RobotPoint selectedRobotPoint;
///
/// 选中的机器人点位
///
public RobotPoint SelectedRobotPoint
{
get { return selectedRobotPoint; }
set
{
selectedRobotPoint = value;
EditingEnabled = false;
this.RaisePropertyChanged("SelectedRobotPoint");
}
}
#endregion
#region 机器人点位编辑相关
#region 启用编辑
private bool editingEnabled;
///
/// 启用编辑
///
public bool EditingEnabled
{
get { return editingEnabled; }
set
{
editingEnabled = value;
this.RaisePropertyChanged("EditingEnabled");
}
}
#endregion
#region 机器人微调参数
private double robotTuningDis;
///
/// 机器人微调参数
///
public double RobotTuningDis
{
get { return robotTuningDis; }
set
{
robotTuningDis = value;
this.RaisePropertyChanged("RobotTuningDis");
}
}
#endregion
#region 机器人PG移动方法
///
/// 机器人PG移动方法
///
public abstract void RobotMove(string direction);
#endregion
///
/// 鼠标点击PG移动
///
///
public abstract void RobotPGMove(object obj);
#region 编辑点位
///
/// 编辑点位
///
///
public abstract void EditorRobotPoint(object obj);
#endregion
#region 保存机器人点位
///
/// 保存机器人点位
///
///
public abstract void SaveRobotPoint(object obj);
#endregion
#region 运行到选中点位
///
/// 运行到选中点位
///
///
public abstract void RunSelectedRobotPointPoint(object obj);
#endregion
#endregion
#region 手动回原点
///
/// 手动回原点
///
///
public abstract void GoHome(object obj);
#endregion
#region 机器人回原点
///
/// 机器人回原点步骤
///
public GengralProcessEnum HomeStep { get; set; }
public DateTime HomeTime { get; set; }
///
/// 机器人回原点
///
public abstract void RobotOrgin();
#endregion
#region 运行点位
///
/// 运行点位
///
///
/// 是否是PG运行
///
public abstract bool RunRobotPoint(RobotPoint point, bool runType = false);
#endregion
///
/// 更新工具坐标系
///
///
public abstract void UpToolCoordinate(object obj);
///
/// 保存备用参数
///
///
public abstract void SaveLaser(object obj);
///
/// 比较两个坐标未知 适用发那科
///
///
///
///
public abstract bool Bijiao(RobotPoint point);
#region 利用反射进行对象复制
///
/// 利用反射进行对象复制
///
/// 复制对象类型
/// 被复制对象
///
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对象的属性
//}
if (dp.Name == sp.Name)//判断属性名是否相同
{
if (dp.PropertyType.FullName == typeof(Array).FullName)
{
dp.SetValue(irpa, ((Array)sp.GetValue(startPoint, null)).Clone(), null);//获得s对象属性的值复制给d对象的属性
}
else
{
dp.SetValue(irpa, sp.GetValue(startPoint, null), null);//获得s对象属性的值复制给d对象的属性
}
}
}
}
}
catch (Exception ex)
{
throw ex;
}
return irpa;
}
///
/// 利用反射进行对象复制
///
///
///
///
public T Coper(T Coperobj)
{
T a = System.Activator.CreateInstance();
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对象的属性
//}
if (dp.Name == sp.Name)//判断属性名是否相同
{
if (dp.PropertyType.FullName == typeof(Array).FullName)
{
dp.SetValue(a, ((Array)sp.GetValue(Coperobj, null)).Clone(), null);//获得s对象属性的值复制给d对象的属性
}
else
{
dp.SetValue(a, sp.GetValue(Coperobj, null), null);//获得s对象属性的值复制给d对象的属性
}
}
}
}
}
catch
{
}
return a;
}
#endregion
}
}