1695 lines
54 KiB
C#
1695 lines
54 KiB
C#
using Community;
|
||
using DAL;
|
||
using MahApps.Metro.Controls.Dialogs;
|
||
using Model;
|
||
using Model.MotionControl;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Collections.ObjectModel;
|
||
using System.Linq;
|
||
using System.Reflection;
|
||
using System.Windows;
|
||
using System.Windows.Controls;
|
||
using System.Windows.Data;
|
||
using Views.Motion;
|
||
|
||
namespace ViewModel.MotionControl
|
||
{
|
||
public class MotionControlVM : NotificationObject
|
||
{
|
||
/// <summary>
|
||
/// 数据引擎
|
||
/// </summary>
|
||
MainWindowDAL dal = new MainWindowDAL();
|
||
|
||
/// <summary>
|
||
/// 上报异常的委托
|
||
/// </summary>
|
||
/// <param name="hv"></param>
|
||
public delegate void delegeateExcep(string hv);
|
||
/// <summary>
|
||
/// 上报异常的委托事件
|
||
/// </summary>
|
||
public event delegeateExcep eventExcepReport;
|
||
|
||
/// <summary>
|
||
/// 控制卡连接是否成功
|
||
/// </summary>
|
||
public bool CardConnection { get; set; }
|
||
|
||
|
||
#region 对应的窗口对象
|
||
private MotionControWindow myWindow;
|
||
/// <summary>
|
||
/// 对应的窗口对象
|
||
/// </summary>
|
||
public MotionControWindow MyWindow
|
||
{
|
||
get { return myWindow; }
|
||
set
|
||
{
|
||
myWindow = value;
|
||
this.RaisePropertyChanged("MyWindow");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 对应的生产机种
|
||
private MachineModel machineObj;
|
||
/// <summary>
|
||
/// 对应的生产机种
|
||
/// </summary>
|
||
public MachineModel MachineObj
|
||
{
|
||
get { return machineObj; }
|
||
set
|
||
{
|
||
machineObj = value;
|
||
if (value.ID > 0)
|
||
{
|
||
TrajListL = dal.GetMotionTrajectoryList(value.ID, 0);
|
||
//TrajListR = dal.GetMotionTrajectoryList(value.ID, 1);
|
||
MachineObj.MotionPointList = TrajListL[0].PointList;
|
||
MachineObj.MotionTrajectoryList = TrajListL;
|
||
}
|
||
this.RaisePropertyChanged("MachineObj");
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 显示权限
|
||
private Visibility displayLevel;
|
||
/// <summary>
|
||
/// 显示权限
|
||
/// </summary>
|
||
public Visibility DisplayLevel
|
||
{
|
||
get { return displayLevel; }
|
||
set
|
||
{
|
||
displayLevel = value;
|
||
this.RaisePropertyChanged("DisplayLevel");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 选中运动控制卡对象
|
||
private FeiYuCard selectCard;
|
||
/// <summary>
|
||
/// 选中运动控制卡对象
|
||
/// </summary>
|
||
public FeiYuCard SelectCard
|
||
{
|
||
get { return selectCard; }
|
||
set
|
||
{
|
||
selectCard = value;
|
||
this.RaisePropertyChanged("SelectCard");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 选中的轴对象
|
||
private FeiYuShaft selectShaft;
|
||
/// <summary>
|
||
/// 选中的轴对象
|
||
/// </summary>
|
||
public FeiYuShaft SelectShaft
|
||
{
|
||
get { return selectShaft; }
|
||
set
|
||
{
|
||
selectShaft = value;
|
||
this.RaisePropertyChanged("SelectShaft");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 运动控制卡集合
|
||
private ObservableCollection<FeiYuCard> cardList;
|
||
/// <summary>
|
||
/// 运动控制卡集合
|
||
/// </summary>
|
||
public ObservableCollection<FeiYuCard> CardList
|
||
{
|
||
get { return cardList; }
|
||
set
|
||
{
|
||
cardList = value;
|
||
this.RaisePropertyChanged("CardList");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 轨迹集合左 TrajListL
|
||
private ObservableCollection<MotionTrajectoryModel> trajListL;
|
||
/// <summary>
|
||
/// 轨迹集合左
|
||
/// </summary>
|
||
public ObservableCollection<MotionTrajectoryModel> TrajListL
|
||
{
|
||
get { return trajListL; }
|
||
set
|
||
{
|
||
trajListL = value;
|
||
this.RaisePropertyChanged("TrajListL");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 轨迹集合右 TrajListR
|
||
private ObservableCollection<MotionTrajectoryModel> trajListR;
|
||
/// <summary>
|
||
/// 轨迹集合右
|
||
/// </summary>
|
||
public ObservableCollection<MotionTrajectoryModel> TrajListR
|
||
{
|
||
get { return trajListR; }
|
||
set
|
||
{
|
||
trajListR = value;
|
||
this.RaisePropertyChanged("TrajListR");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 选中的运行轨迹
|
||
private MotionTrajectoryModel selectTrajectory;
|
||
/// <summary>
|
||
/// 选中的运行轨迹
|
||
/// </summary>
|
||
public MotionTrajectoryModel SelectTrajectory
|
||
{
|
||
get { return selectTrajectory; }
|
||
set
|
||
{
|
||
selectTrajectory = value;
|
||
this.RaisePropertyChanged("SelectTrajectory");
|
||
if (value == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
EnableTrajeEdit = value.TrajectoryTrype >= 2 ? false : true;
|
||
|
||
if (value.PointList.Count <= 0)
|
||
{
|
||
//如果是圆弧轨迹 则添加固定点位
|
||
if (value.TrajectoryTrype == 2)
|
||
{
|
||
List<MotionPointModel> plist = new List<MotionPointModel>() { new MotionPointModel() { MachineID = value.ID, PointName = "圆弧起点", PointType = 2 },
|
||
new MotionPointModel() { MachineID = value.ID, PointName = "圆弧中间", PointType = 2 },
|
||
new MotionPointModel() { MachineID = value.ID, PointName = "圆弧终点", PointType = 2 }};
|
||
foreach (MotionPointModel mp in plist)
|
||
{
|
||
dal.AddMotionPoint(mp);
|
||
}
|
||
}
|
||
else if (value.TrajectoryTrype == 3)
|
||
{
|
||
|
||
}
|
||
|
||
value.PointList = dal.GetMotionPointlList(value.ID);
|
||
}
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 启用轨迹点位编辑
|
||
private bool enableTrajeEdit;
|
||
/// <summary>
|
||
/// 启用轨迹点位编辑
|
||
/// </summary>
|
||
public bool EnableTrajeEdit
|
||
{
|
||
get { return enableTrajeEdit; }
|
||
set
|
||
{
|
||
enableTrajeEdit = value;
|
||
this.RaisePropertyChanged("EnableTrajeEdit");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 选中的运行点位
|
||
private MotionPointModel selectMotionPoint;
|
||
/// <summary>
|
||
/// 选中的运行点位
|
||
/// </summary>
|
||
public MotionPointModel SelectMotionPoint
|
||
{
|
||
get { return selectMotionPoint; }
|
||
set
|
||
{
|
||
if (RunSelectPointBool) return;
|
||
selectMotionPoint = value;
|
||
IsEnables = false;
|
||
this.RaisePropertyChanged("SelectMotionPoint");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 微调距离
|
||
private double tuningDis;
|
||
/// <summary>
|
||
/// 微调距离
|
||
/// </summary>
|
||
public double TuningDis
|
||
{
|
||
get { return tuningDis; }
|
||
set
|
||
{
|
||
tuningDis = value;
|
||
this.RaisePropertyChanged("TuningDis");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 所有轴集合
|
||
|
||
private ObservableCollection<FeiYuShaft> allShaftList;
|
||
/// <summary>
|
||
/// 所有轴集合
|
||
/// </summary>
|
||
public ObservableCollection<FeiYuShaft> AllShaftList
|
||
{
|
||
get { return allShaftList; }
|
||
set
|
||
{
|
||
allShaftList = value;
|
||
this.RaisePropertyChanged("AllShaftList");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
#region 轴对象
|
||
|
||
private FeiYuShaft shaft_X;
|
||
/// <summary>
|
||
/// X轴
|
||
/// </summary>
|
||
public FeiYuShaft Shaft_X
|
||
{
|
||
get { return shaft_X; }
|
||
set
|
||
{
|
||
shaft_X = value;
|
||
this.RaisePropertyChanged("Shaft_X");
|
||
}
|
||
}
|
||
private FeiYuShaft shaft_Y;
|
||
/// <summary>
|
||
/// Y轴
|
||
/// </summary>
|
||
public FeiYuShaft Shaft_Y
|
||
{
|
||
get { return shaft_Y; }
|
||
set
|
||
{
|
||
shaft_Y = value;
|
||
this.RaisePropertyChanged("Shaft_Y");
|
||
}
|
||
}
|
||
|
||
private FeiYuShaft shaft_Z;
|
||
/// <summary>
|
||
/// Z轴
|
||
/// </summary>
|
||
public FeiYuShaft Shaft_Z
|
||
{
|
||
get { return shaft_Z; }
|
||
set
|
||
{
|
||
shaft_Z = value;
|
||
this.RaisePropertyChanged("Shaft_Z");
|
||
}
|
||
}
|
||
|
||
private FeiYuShaft shaft_U;
|
||
/// <summary>
|
||
/// U轴
|
||
/// </summary>
|
||
public FeiYuShaft Shaft_U
|
||
{
|
||
get { return shaft_U; }
|
||
set
|
||
{
|
||
shaft_U = value;
|
||
this.RaisePropertyChanged("Shaft_U");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
#region 各种方法
|
||
/// <summary>
|
||
/// 新增运动控制卡
|
||
/// </summary>
|
||
public DelegateCommand AddCardCommand { get; set; }
|
||
/// <summary>
|
||
/// 保存运动控制卡信息
|
||
/// </summary>
|
||
public DelegateCommand SaveCardCommand { get; set; }
|
||
/// <summary>
|
||
/// 新增轴
|
||
/// </summary>
|
||
public DelegateCommand AddShaftCommand { get; set; }
|
||
/// <summary>
|
||
/// 保存轴参数
|
||
/// </summary>
|
||
public DelegateCommand SaveShaftCommand { get; set; }
|
||
|
||
|
||
/// <summary>
|
||
/// 鼠标左键按下时
|
||
/// </summary>
|
||
public DelegateCommand PreviewMouseLeftButtonDownCommand { get; set; }
|
||
|
||
/// <summary>
|
||
/// 鼠标左键松开时
|
||
/// </summary>
|
||
public DelegateCommand PreviewMouseLeftButtonUpCommand { get; set; }
|
||
|
||
/// <summary>
|
||
/// 编辑点位
|
||
/// </summary>
|
||
public DelegateCommand EditorPointCommand { get; set; }
|
||
/// <summary>
|
||
/// 新增点位
|
||
/// </summary>
|
||
public DelegateCommand AddPointCommand { get; set; }
|
||
/// <summary>
|
||
/// 删除点位
|
||
/// </summary>
|
||
public DelegateCommand DeletePointCommand { get; set; }
|
||
|
||
/// <summary>
|
||
/// 运行当前选中点位
|
||
/// </summary>
|
||
public DelegateCommand RunSelectPointCommand { get; set; }
|
||
/// <summary>
|
||
/// 保存运行点位坐标
|
||
/// </summary>
|
||
public DelegateCommand SaveMotionPointCommand { get; set; }
|
||
/// <summary>
|
||
/// 保存点位参数
|
||
/// </summary>
|
||
public DelegateCommand SavePointPerCommand { get; set; }
|
||
|
||
/// <summary>
|
||
/// 新增轨迹
|
||
/// </summary>
|
||
public DelegateCommand AddTrajectoryCommand { get; set; }
|
||
/// <summary>
|
||
/// 删除轨迹
|
||
/// </summary>
|
||
public DelegateCommand DeleteTrajectoryCommand { get; set; }
|
||
/// <summary>
|
||
/// 运行当前轨迹
|
||
/// </summary>
|
||
public DelegateCommand RunTrajectoryCommand { get; set; }
|
||
/// <summary>
|
||
/// 保存轨迹信息
|
||
/// </summary>
|
||
public DelegateCommand SaveTrajectoryCommand { get; set; }
|
||
|
||
#endregion
|
||
|
||
#region 输入信号集合
|
||
private List<InputSignal> inputList;
|
||
/// <summary>
|
||
/// 输入信号集合
|
||
/// </summary>
|
||
public List<InputSignal> InputList
|
||
{
|
||
get { return inputList; }
|
||
set
|
||
{
|
||
inputList = value;
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 输出信号集合
|
||
private List<OutputSignal> outputList;
|
||
/// <summary>
|
||
/// 输出信号集合
|
||
/// </summary>
|
||
public List<OutputSignal> OutputList
|
||
{
|
||
get { return outputList; }
|
||
set
|
||
{
|
||
outputList = value;
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 构造函数
|
||
public MotionControlVM(MachineModel machine, List<InputSignal> inputList, List<OutputSignal> outputList)
|
||
{
|
||
MachineObj = machine;
|
||
this.InputList = inputList;
|
||
this.OutputList = outputList;
|
||
|
||
DisplayLevel = Visibility.Collapsed;
|
||
CardList = dal.GetCardList();
|
||
HomeStep = GengralProcessEnum.End;
|
||
|
||
GetAllShaftList();
|
||
|
||
MyWindow = new MotionControWindow(AllShaftList);
|
||
MyWindow.DataContext = this;
|
||
|
||
|
||
AddCardCommand = new DelegateCommand();
|
||
AddCardCommand.ExecuteAction = new Action<object>(AddCard);
|
||
|
||
SaveCardCommand = new DelegateCommand();
|
||
SaveCardCommand.ExecuteAction = new Action<object>(SaveCard);
|
||
|
||
AddShaftCommand = new DelegateCommand();
|
||
AddShaftCommand.ExecuteAction = new Action<object>(AddShaft);
|
||
|
||
SaveShaftCommand = new DelegateCommand();
|
||
SaveShaftCommand.ExecuteAction = new Action<object>(SaveShaft);
|
||
|
||
PreviewMouseLeftButtonDownCommand = new DelegateCommand();
|
||
PreviewMouseLeftButtonDownCommand.ExecuteAction = new Action<object>(PreviewMouseLeftButtonDown);
|
||
|
||
PreviewMouseLeftButtonUpCommand = new DelegateCommand();
|
||
PreviewMouseLeftButtonUpCommand.ExecuteAction = new Action<object>(PreviewMouseLeftButtonUp);
|
||
|
||
this.EditorPointCommand = new DelegateCommand();
|
||
this.EditorPointCommand.ExecuteAction = new Action<object>(EditorPoint);
|
||
|
||
this.AddPointCommand = new DelegateCommand();
|
||
this.AddPointCommand.ExecuteAction = new Action<object>(AddPoint);
|
||
|
||
this.DeletePointCommand = new DelegateCommand();
|
||
this.DeletePointCommand.ExecuteAction = new Action<object>(DeletePoint);
|
||
|
||
this.RunSelectPointCommand = new DelegateCommand();
|
||
this.RunSelectPointCommand.ExecuteAction = new Action<object>(RunSelectPoint);
|
||
|
||
this.SaveMotionPointCommand = new DelegateCommand();
|
||
this.SaveMotionPointCommand.ExecuteAction = new Action<object>(SaveMotionPoint);
|
||
|
||
this.SavePointPerCommand = new DelegateCommand();
|
||
this.SavePointPerCommand.ExecuteAction = new Action<object>(SavePointPer);
|
||
|
||
this.AddTrajectoryCommand = new DelegateCommand();
|
||
this.AddTrajectoryCommand.ExecuteAction = new Action<object>(AddTrajectory);
|
||
|
||
this.DeleteTrajectoryCommand = new DelegateCommand();
|
||
this.DeleteTrajectoryCommand.ExecuteAction = new Action<object>(DeleteTrajectory);
|
||
|
||
this.RunTrajectoryCommand = new DelegateCommand();
|
||
this.RunTrajectoryCommand.ExecuteAction = new Action<object>(RunTrajectory);
|
||
|
||
this.SaveTrajectoryCommand = new DelegateCommand();
|
||
this.SaveTrajectoryCommand.ExecuteAction = new Action<object>(SaveTrajectory);
|
||
|
||
IsEnables = false;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 连接所有控制卡
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public bool ConnectAllCard()
|
||
{
|
||
//如果已连接
|
||
if (CardConnection)
|
||
{
|
||
return CardConnection;
|
||
}
|
||
|
||
CardConnection = true;
|
||
foreach (FeiYuCard cd in CardList)
|
||
{
|
||
if (cd.Connect())
|
||
{
|
||
cd.GetCradInfo();
|
||
foreach (var item in InputList)
|
||
{
|
||
if (cd.ID == item.CardID)
|
||
{
|
||
item.MyCard = cd;
|
||
}
|
||
}
|
||
|
||
foreach (var item in OutputList)
|
||
{
|
||
if (cd.ID == item.CardID)
|
||
{
|
||
item.MyCard = cd;
|
||
}
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
CardConnection = false;
|
||
eventExcepReport("运动控制器【" + cd.CardName + "】未连接");
|
||
break;
|
||
}
|
||
}
|
||
return CardConnection;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 鼠标左键松开时发生
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void PreviewMouseLeftButtonUp(object obj)
|
||
{
|
||
StopMove();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 鼠标左键按下时发生
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void PreviewMouseLeftButtonDown(object obj)
|
||
{
|
||
try
|
||
{
|
||
Button btn = obj as Button;
|
||
TuningDis = Convert.ToDouble(btn.ToolTip.ToString());
|
||
ShaftMove(btn.Tag.ToString());
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 保存轴参数
|
||
/// <summary>
|
||
/// 保存轴参数
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void SaveShaft(object obj)
|
||
{
|
||
if (SelectShaft == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (dal.UpdateShaft(SelectShaft) > 0)
|
||
{
|
||
SelectShaft.Initialize();
|
||
MyMessageBox.Show("保存成功");
|
||
GetAllShaftList();
|
||
}
|
||
else
|
||
{
|
||
MyMessageBox.Show("保存失败");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 新增轴
|
||
/// <summary>
|
||
/// 新增轴
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void AddShaft(object obj)
|
||
{
|
||
if (SelectCard == null || SelectCard.ID <= 0)
|
||
{
|
||
MyMessageBox.Show("请选择要添加轴的控制卡");
|
||
return;
|
||
}
|
||
|
||
|
||
if (SelectCard.Brand == 1)
|
||
{
|
||
FeiYuShaft sf = new LeiSaiShaft() { ShaftName = "新来的", SuperiorID = SelectCard.ID, MyCard = SelectCard };
|
||
SelectCard.ShaftList.Add(sf);
|
||
}
|
||
else
|
||
{
|
||
FeiYuShaft sf = new ZmotionShaft() { ShaftName = "新来的", SuperiorID = SelectCard.ID, MyCard = SelectCard };
|
||
SelectCard.ShaftList.Add(sf);
|
||
}
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 新增运动控制卡
|
||
/// <summary>
|
||
/// 新增运动控制卡
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void AddCard(object obj)
|
||
{
|
||
LeiSaiCard cardnew = new LeiSaiCard() { CardName = "新来的" };
|
||
CardList.Add(cardnew);
|
||
}
|
||
#endregion
|
||
|
||
#region 保存运动控制卡信息
|
||
/// <summary>
|
||
/// 保存运动控制卡信息
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void SaveCard(object obj)
|
||
{
|
||
if (SelectCard == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (dal.UpdateCard(SelectCard) > 0)
|
||
{
|
||
MyMessageBox.Show("保存成功");
|
||
CardList = dal.GetCardList();
|
||
}
|
||
else
|
||
{
|
||
MyMessageBox.Show("保存失败");
|
||
}
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 点位调试的轴移动方法
|
||
/// <summary>
|
||
/// 当前调试运动轴
|
||
/// </summary>
|
||
FeiYuShaft MoveShaft { get; set; }
|
||
/// <summary>
|
||
/// 点位调试的轴移动方法
|
||
/// </summary>
|
||
public void ShaftMove(string btnTag)
|
||
{
|
||
if (SelectMotionPoint == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
switch (btnTag)
|
||
{
|
||
case "XP":
|
||
MoveShaft = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_X).FirstOrDefault();//Shaft_X;
|
||
ShaftMoverRun(1);
|
||
break;
|
||
case "XN":
|
||
MoveShaft = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_X).FirstOrDefault();
|
||
ShaftMoverRun(0);
|
||
break;
|
||
case "YP":
|
||
MoveShaft = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_Y).FirstOrDefault(); //Shaft_Y;
|
||
ShaftMoverRun(1);
|
||
break;
|
||
case "YN":
|
||
MoveShaft = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_Y).FirstOrDefault(); //Shaft_Y;
|
||
ShaftMoverRun(0);
|
||
break;
|
||
case "ZP":
|
||
MoveShaft = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_Z).FirstOrDefault();// Shaft_Z;
|
||
ShaftMoverRun(1);
|
||
break;
|
||
case "ZN":
|
||
MoveShaft = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_Z).FirstOrDefault();// Shaft_Z;
|
||
ShaftMoverRun(0);
|
||
break;
|
||
case "UP":
|
||
MoveShaft = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_U).FirstOrDefault();// Shaft_U;
|
||
ShaftMoverRun(1);
|
||
break;
|
||
case "UN":
|
||
MoveShaft = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_U).FirstOrDefault();// Shaft_U;
|
||
ShaftMoverRun(0);
|
||
break;
|
||
default:
|
||
MoveShaft = null;
|
||
break;
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 轴移动运行
|
||
/// <summary>
|
||
/// 轴移动运行
|
||
/// </summary>
|
||
/// <param name="dir">运行方向</param>
|
||
private void ShaftMoverRun(ushort dir)
|
||
{
|
||
if (MoveShaft == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (TuningDis > 0)
|
||
{
|
||
if (TuningDis > 400)
|
||
{
|
||
MyMessageBox.Show("微调刻度超出限制,不应超出20MM");
|
||
}
|
||
else
|
||
if (dir == 1)
|
||
{
|
||
MoveShaft.MyMotionPar.ActualDir = Math.Round(MoveShaft.ActualDir + TuningDis, 2);
|
||
MoveShaft.DZDC(MoveShaft.MyMotionPar);
|
||
}
|
||
else if (dir == 0)
|
||
{
|
||
MoveShaft.MyMotionPar.ActualDir = Math.Round(MoveShaft.ActualDir - TuningDis, 2);
|
||
MoveShaft.DZDC(MoveShaft.MyMotionPar);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
MoveShaft.ContinuousMove(dir);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 停止运行
|
||
/// <summary>
|
||
/// 停止运行
|
||
/// </summary>
|
||
public void StopMove()
|
||
{
|
||
if (MoveShaft == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (TuningDis <= 0) //微调时 走完微调距离会自动停止
|
||
{
|
||
MoveShaft.ShaftStop();
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 获取所有轴
|
||
/// <summary>
|
||
/// 获取所有轴
|
||
/// </summary>
|
||
private void GetAllShaftList()
|
||
{
|
||
AllShaftList = new ObservableCollection<FeiYuShaft>();
|
||
|
||
foreach (FeiYuCard c in CardList)
|
||
{
|
||
AllShaftList = new ObservableCollection<FeiYuShaft>(AllShaftList.Concat(c.ShaftList).ToList());
|
||
}
|
||
|
||
ShaftStateGrid = GetShaftStateGrid();
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 获取轴状态Grid
|
||
private Grid shaftStateGrid;
|
||
/// <summary>
|
||
/// 轴状态Grid
|
||
/// </summary>
|
||
public Grid ShaftStateGrid
|
||
{
|
||
get { return shaftStateGrid; }
|
||
set
|
||
{
|
||
shaftStateGrid = value;
|
||
this.RaisePropertyChanged("ShaftStateGrid");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取轴状态Grid
|
||
/// </summary>
|
||
private Grid GetShaftStateGrid()
|
||
{
|
||
|
||
Grid g = new Grid();
|
||
|
||
int row = 0;
|
||
int column = 5;
|
||
int count = AllShaftList.Count;
|
||
if (count <= 12)
|
||
{
|
||
row = 12;
|
||
}
|
||
else
|
||
{
|
||
row = count;
|
||
|
||
}
|
||
int number = 0;
|
||
Border bor; //轴状态颜色
|
||
Label shaftname; //轴名称
|
||
Label StatuInfo; //轴状态信息
|
||
Label shaftDir;//轴当前位置
|
||
Button goHome;//回原点按钮
|
||
Button reset;//回原点按钮
|
||
|
||
|
||
for (int i = 0; i < column; i++)
|
||
{
|
||
g.ColumnDefinitions.Add(new ColumnDefinition()); //添加列
|
||
number = 0;
|
||
for (int j = 0; j < row; j++)
|
||
{
|
||
if (i == 0)
|
||
{
|
||
g.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(50) }); //添加行
|
||
}
|
||
|
||
if (number < count)
|
||
{
|
||
if (i == 0)
|
||
{
|
||
bor = new Border();
|
||
bor.DataContext = AllShaftList[number].ShaftState;
|
||
bor.SetBinding(Border.BackgroundProperty, new Binding("StatusBackground"));
|
||
bor.Margin = new Thickness(1); //设置边距
|
||
bor.Opacity = 0.8;//设置透明度
|
||
g.Children.Add(bor);
|
||
bor.SetValue(Grid.RowProperty, j); //设置按钮所在Grid控件的行
|
||
bor.SetValue(Grid.ColumnProperty, i); //设置按钮所在Grid控件的列
|
||
bor.SetValue(Grid.ColumnSpanProperty, column);
|
||
|
||
|
||
shaftname = new Label();
|
||
shaftname.DataContext = AllShaftList[number];
|
||
shaftname.SetBinding(Label.ContentProperty, new Binding("ShaftName"));
|
||
//shaftname.SetResourceReference(Label.ContentProperty, AllShaftList[number].ShaftName); //设定资源引用 即可进行语言的切换
|
||
shaftname.VerticalContentAlignment = VerticalAlignment.Center;
|
||
shaftname.HorizontalContentAlignment = HorizontalAlignment.Center;
|
||
shaftname.FontWeight = FontWeights.Bold;
|
||
shaftname.FontSize = 20;
|
||
g.Children.Add(shaftname);
|
||
shaftname.SetValue(Grid.RowProperty, j); //设置按钮所在Grid控件的行
|
||
shaftname.SetValue(Grid.ColumnProperty, i); //设置按钮所在Grid控件的列
|
||
}
|
||
|
||
|
||
if (i == 1)
|
||
{
|
||
StatuInfo = new Label();
|
||
StatuInfo.DataContext = AllShaftList[number].ShaftState;
|
||
StatuInfo.SetBinding(Label.ContentProperty, new Binding("StatuInfo"));
|
||
StatuInfo.SetBinding(Label.ForegroundProperty, new Binding("StatusForeground"));
|
||
StatuInfo.VerticalContentAlignment = VerticalAlignment.Center;
|
||
StatuInfo.HorizontalContentAlignment = HorizontalAlignment.Center;
|
||
StatuInfo.FontWeight = FontWeights.Bold;
|
||
StatuInfo.FontSize = 20;
|
||
g.Children.Add(StatuInfo);
|
||
StatuInfo.SetValue(Grid.RowProperty, j); //设置按钮所在Grid控件的行
|
||
StatuInfo.SetValue(Grid.ColumnProperty, i); //设置按钮所在Grid控件的列
|
||
}
|
||
|
||
if (i == 2)
|
||
{
|
||
shaftDir = new Label();
|
||
shaftDir.DataContext = AllShaftList[number];
|
||
shaftDir.SetBinding(Label.ContentProperty, new Binding("ActualDir"));
|
||
shaftDir.VerticalContentAlignment = VerticalAlignment.Center;
|
||
shaftDir.HorizontalContentAlignment = HorizontalAlignment.Center;
|
||
shaftDir.FontWeight = FontWeights.Bold;
|
||
shaftDir.FontSize = 20;
|
||
g.Children.Add(shaftDir);
|
||
shaftDir.SetValue(Grid.RowProperty, j); //设置按钮所在Grid控件的行
|
||
shaftDir.SetValue(Grid.ColumnProperty, i); //设置按钮所在Grid控件的列
|
||
}
|
||
|
||
if (i == 3)
|
||
{
|
||
goHome = new Button();
|
||
//指定样式
|
||
goHome.Style = (Style)Application.Current.FindResource("commBtn");//commBtn 这个样式是引用的资源文件中的样式名称
|
||
goHome.Tag = AllShaftList[number].ID;
|
||
goHome.Click += GoHome_Click;
|
||
goHome.Content = "回原点";
|
||
//goHome.SetResourceReference(Button.ContentProperty, "回原点"); //设定资源引用 即可进行语言的切换
|
||
//goHome.SetBinding(Button.CommandProperty, new Binding("GoHomeCommand"));
|
||
goHome.FontSize = 20;
|
||
goHome.FontWeight = FontWeights.Bold;
|
||
goHome.FontFamily = new System.Windows.Media.FontFamily("楷体");
|
||
goHome.Margin = new Thickness(5); //设置边距
|
||
goHome.Opacity = 0.8;//设置透明度
|
||
g.Children.Add(goHome);
|
||
goHome.SetValue(Grid.RowProperty, j); //设置按钮所在Grid控件的行
|
||
goHome.SetValue(Grid.ColumnProperty, i); //设置按钮所在Grid控件的列
|
||
|
||
}
|
||
if (i == 4)
|
||
{
|
||
reset = new Button();
|
||
//指定样式
|
||
reset.Style = (Style)Application.Current.FindResource("commBtn");//commBtn 这个样式是引用的资源文件中的样式名称
|
||
reset.Tag = AllShaftList[number].ID;
|
||
reset.Click += Reset_Click;
|
||
reset.Content = "复位";
|
||
//goHome.SetResourceReference(Button.ContentProperty, "回原点"); //设定资源引用 即可进行语言的切换
|
||
//goHome.SetBinding(Button.CommandProperty, new Binding("GoHomeCommand"));
|
||
reset.FontSize = 20;
|
||
reset.FontWeight = FontWeights.Bold;
|
||
reset.FontFamily = new System.Windows.Media.FontFamily("楷体");
|
||
reset.Margin = new Thickness(5); //设置边距
|
||
reset.Opacity = 0.8;//设置透明度
|
||
g.Children.Add(reset);
|
||
reset.SetValue(Grid.RowProperty, j); //设置按钮所在Grid控件的行
|
||
reset.SetValue(Grid.ColumnProperty, i); //设置按钮所在Grid控件的列
|
||
|
||
}
|
||
number++;
|
||
}
|
||
}
|
||
}
|
||
|
||
return g;
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region 单轴回原点
|
||
/// <summary>
|
||
/// 单轴回原点
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void GoHome_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
Button bnt = sender as Button;
|
||
int id = Convert.ToInt32(bnt.Tag);
|
||
FeiYuShaft shaft = AllShaftList.Where(w => w.ID == id).FirstOrDefault();
|
||
|
||
if (shaft != null)
|
||
{
|
||
if (shaft.InCode != "Z")
|
||
{
|
||
//这里Z轴防呆
|
||
List<FeiYuShaft> list = AllShaftList.Where(w => w.InCode == "Z").ToList();
|
||
foreach (var item in list)
|
||
{
|
||
if (item.ActualDir != 0)
|
||
{
|
||
MyMessageBox.Show(item.ShaftName + "的高度存在撞机风险");
|
||
return;
|
||
}
|
||
}
|
||
shaft.ShaftStop();
|
||
shaft.org_Successful = true;
|
||
}
|
||
else
|
||
{
|
||
shaft.org_Successful = true;
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
private void Reset_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
Button bnt = sender as Button;
|
||
int id = Convert.ToInt32(bnt.Tag);
|
||
FeiYuShaft shaft = AllShaftList.Where(w => w.ID == id).FirstOrDefault();
|
||
if (shaft != null)
|
||
{
|
||
shaft.Reset();
|
||
}
|
||
|
||
}
|
||
#region 编辑坐标点
|
||
private bool isEnables;
|
||
/// <summary>
|
||
/// 是否启用编辑
|
||
/// </summary>
|
||
public bool IsEnables
|
||
{
|
||
get { return isEnables; }
|
||
set
|
||
{
|
||
isEnables = value;
|
||
this.RaisePropertyChanged("IsEnables");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 编辑坐标点
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void EditorPoint(object obj)
|
||
{
|
||
if (SelectMotionPoint == null)
|
||
{
|
||
MyMessageBox.Show("请选择运行点位");
|
||
return;
|
||
}
|
||
if (!IsEnables)
|
||
{
|
||
IsEnables = true;
|
||
|
||
Shaft_X = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_X).FirstOrDefault();
|
||
Shaft_Y = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_Y).FirstOrDefault();
|
||
Shaft_Z = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_Z).FirstOrDefault();
|
||
Shaft_U = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_U).FirstOrDefault();
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 新增坐标点位
|
||
private int tabSelectNumber;
|
||
/// <summary>
|
||
/// 选中的点位分类
|
||
/// </summary>
|
||
public int TabSelectNumber
|
||
{
|
||
get { return tabSelectNumber; }
|
||
set
|
||
{
|
||
tabSelectNumber = value;
|
||
SelectMotionPoint = null;
|
||
SelectTrajectory = null;
|
||
this.RaisePropertyChanged("TabSelectNumber");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 新增坐标点位
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void AddPoint(object obj)
|
||
{
|
||
MotionPointModel p = new MotionPointModel() { MachineID = SelectTrajectory.ID, PointName = "新来的" };
|
||
|
||
if (dal.AddMotionPoint(p) > 0)
|
||
{
|
||
SelectTrajectory.PointList = dal.GetMotionPointlList(SelectTrajectory.ID);
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 删除点位
|
||
/// <summary>
|
||
/// 删除点位
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void DeletePoint(object obj)
|
||
{
|
||
if (SelectMotionPoint == null)
|
||
{
|
||
MyMessageBox.Show("请选择运行点位");
|
||
return;
|
||
}
|
||
|
||
if (MyMessageBox.Show("你确定要删除当前点位吗", "警告", MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Affirmative)
|
||
{
|
||
if (dal.DeleteMotionPoint(SelectMotionPoint.ID) > 0)
|
||
{
|
||
//if (SelectMotionPoint.PointClass == 1)
|
||
//{
|
||
// SelectTrajectory.PointList = dal.GetMotionPointlList(SelectTrajectory.ID, 1);
|
||
//}
|
||
//else if (SelectMotionPoint.PointClass == 2)
|
||
//{
|
||
// MotoinPointListR = dal.GetMotionPointlList(MachineObj.ID, 2);
|
||
//}
|
||
SelectTrajectory.PointList = dal.GetMotionPointlList(SelectTrajectory.ID);
|
||
}
|
||
else
|
||
{
|
||
MyMessageBox.Show("删除失败");
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 运行当前选中的坐标点
|
||
|
||
/// <summary>
|
||
/// 是否在进行运行到选择点位测试
|
||
/// </summary>
|
||
public bool RunSelectPointBool { get; set; }
|
||
|
||
/// <summary>
|
||
/// 运行当前选中的点胶点
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
public void RunSelectPoint(object obj)
|
||
{
|
||
if (SelectMotionPoint == null)
|
||
{
|
||
MyMessageBox.Show("请选择运行点位");
|
||
return;
|
||
}
|
||
|
||
//if (SelectMotionPoint.PointClass == 1)
|
||
//{
|
||
// for (int i = 46; i < 50; i++)
|
||
// {
|
||
// if (!InputList[i].LightUp)
|
||
// {
|
||
// MyMessageBox.Show(InputList[i].InputMeaning + "异常");
|
||
// return ;
|
||
// }
|
||
// }
|
||
//}
|
||
//else if (SelectMotionPoint.PointClass == 2)
|
||
//{
|
||
// for (int i = 50; i < 54; i++)
|
||
// {
|
||
// if (!InputList[i].LightUp)
|
||
// {
|
||
// MyMessageBox.Show(InputList[i].InputMeaning + "异常");
|
||
// return ;
|
||
// }
|
||
// }
|
||
//}
|
||
|
||
|
||
if (!RunSelectPointBool && !RunSelectTrajectory)
|
||
{
|
||
RunSelectPointBool = true;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 运行到选中点位
|
||
/// </summary>
|
||
public void PointRun()
|
||
{
|
||
if (!RunSelectPointBool)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (PointRun(SelectMotionPoint))
|
||
{
|
||
RunSelectPointBool = false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 运行到指定点位
|
||
/// </summary>
|
||
/// <param name="point">点位对象</param>
|
||
/// <param name="multiple">降速倍数</param>
|
||
/// <returns></returns>
|
||
public bool PointRun(MotionPointModel point, int multiple = 1)
|
||
{
|
||
bool bl = false;
|
||
|
||
|
||
//这里Z轴防呆
|
||
//List<FeiYuShaft> list = AllShaftList.Where(w => w.InCode == "Z" && w.ID != point.ShaftID_Z).ToList();
|
||
//foreach (var item in list)
|
||
//{
|
||
// if (item.ActualDir != 0)
|
||
// {
|
||
// eventExcepReport(item.ShaftName + "的高度存在撞机风险");
|
||
// return bl;
|
||
// }
|
||
//}
|
||
|
||
|
||
//if (point.PointClass == 1)
|
||
//{
|
||
// for (int i = 46; i < 50; i++)
|
||
// {
|
||
// if (!InputList[i].LightUp)
|
||
// {
|
||
// eventExcepReport(InputList[i].InputMeaning + "异常");
|
||
// RunSelectPointBool = false;
|
||
// return bl;
|
||
// }
|
||
// }
|
||
//}
|
||
//else if (point.PointClass == 2)
|
||
//{
|
||
// for (int i = 50; i < 54; i++)
|
||
// {
|
||
// if (!InputList[i].LightUp)
|
||
// {
|
||
// eventExcepReport(InputList[i].InputMeaning + "异常");
|
||
// RunSelectPointBool = false;
|
||
// return bl;
|
||
// }
|
||
// }
|
||
//}
|
||
|
||
return point.PointRun(AllShaftList, multiple);
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 保存运行点位坐标
|
||
/// <summary>
|
||
/// 保存运行点位坐标
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void SaveMotionPoint(object obj)
|
||
{
|
||
if (MyMessageBox.Show("确定要保存当前参数", "警告", MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Negative)
|
||
{
|
||
return;
|
||
}
|
||
|
||
Shaft_X = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_X).FirstOrDefault();
|
||
Shaft_Y = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_Y).FirstOrDefault();
|
||
Shaft_Z = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_Z).FirstOrDefault();
|
||
Shaft_U = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_U).FirstOrDefault();
|
||
|
||
SelectMotionPoint.ShaftPoint_X = Shaft_X != null ? Shaft_X.ActualDir : 0;
|
||
SelectMotionPoint.ShaftPoint_Y = Shaft_Y != null ? Shaft_Y.ActualDir : 0;
|
||
SelectMotionPoint.ShaftPoint_Z = Shaft_Z != null ? Shaft_Z.ActualDir : 0;
|
||
SelectMotionPoint.ShaftPoint_U = Shaft_U != null ? Shaft_U.ActualDir : 0;
|
||
|
||
|
||
SelectMotionPoint.Speed_X = Shaft_X != null ? Shaft_X.MyMotionPar.StartSpeed * SelectMotionPoint.Speed_Gear : 0;
|
||
SelectMotionPoint.Speed_Y = Shaft_Y != null ? Shaft_Y.MyMotionPar.StartSpeed * SelectMotionPoint.Speed_Gear : 0;
|
||
SelectMotionPoint.Speed_Z = Shaft_Z != null ? Shaft_Z.MyMotionPar.StartSpeed * SelectMotionPoint.Speed_Gear : 0;
|
||
SelectMotionPoint.Speed_U = Shaft_U != null ? Shaft_U.MyMotionPar.StartSpeed * SelectMotionPoint.Speed_Gear : 0;
|
||
|
||
|
||
if (dal.UpdateMotionPoint(SelectMotionPoint) > 0)
|
||
{
|
||
MyMessageBox.Show("保存成功");
|
||
}
|
||
else
|
||
{
|
||
MyMessageBox.Show("保存失败");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 保存点位参数
|
||
/// <summary>
|
||
/// 保存点位参数
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void SavePointPer(object obj)
|
||
{
|
||
if (SelectMotionPoint == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
//if (SelectMotionPoint.Speed_Gear > 30)
|
||
//{
|
||
// MyMessageBox.Show("速度挡位超过最大值");
|
||
// return;
|
||
//}
|
||
|
||
Shaft_X = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_X).FirstOrDefault();
|
||
Shaft_Y = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_Y).FirstOrDefault();
|
||
Shaft_Z = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_Z).FirstOrDefault();
|
||
Shaft_U = AllShaftList.Where(s => s.ID == SelectMotionPoint.ShaftID_U).FirstOrDefault();
|
||
|
||
|
||
SelectMotionPoint.Speed_X = Shaft_X != null ? Shaft_X.MyMotionPar.StartSpeed * SelectMotionPoint.Speed_Gear : 0;
|
||
SelectMotionPoint.Speed_Y = Shaft_Y != null ? Shaft_Y.MyMotionPar.StartSpeed * SelectMotionPoint.Speed_Gear : 0;
|
||
SelectMotionPoint.Speed_Z = Shaft_Z != null ? Shaft_Z.MyMotionPar.StartSpeed * SelectMotionPoint.Speed_Gear : 0;
|
||
SelectMotionPoint.Speed_U = Shaft_U != null ? Shaft_U.MyMotionPar.StartSpeed * SelectMotionPoint.Speed_Gear : 0;
|
||
|
||
|
||
if (dal.UpdateMotionPointPer(SelectMotionPoint) > 0)
|
||
{
|
||
MyMessageBox.Show("保存成功");
|
||
}
|
||
else
|
||
{
|
||
MyMessageBox.Show("保存失败");
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 所有轴回原点
|
||
/// <summary>
|
||
/// 所有轴自动回原点步骤
|
||
/// </summary>
|
||
public GengralProcessEnum HomeStep { get; set; }
|
||
|
||
/// <summary>
|
||
/// 所有轴回原点
|
||
/// </summary>
|
||
/// <param name="emg">急停信号</param>
|
||
public void OrginALL(InputSignal emg)
|
||
{
|
||
#region 监控手动回原点
|
||
|
||
foreach (FeiYuShaft df in AllShaftList)
|
||
{
|
||
if (df.ToOrgin)
|
||
{
|
||
df.HYD(emg);
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 自动回原点
|
||
bool bl = true;
|
||
switch (HomeStep)
|
||
{
|
||
case GengralProcessEnum.Start:
|
||
foreach (FeiYuShaft df in AllShaftList)
|
||
{
|
||
if (df.ToOrgin && df.GoHomeOrder == 1)
|
||
{
|
||
df.org_Successful = true;
|
||
df.HomeStep = GengralProcessEnum.Start;
|
||
}
|
||
}
|
||
HomeStep++;
|
||
break;
|
||
case GengralProcessEnum.Step1:
|
||
foreach (FeiYuShaft df in AllShaftList)
|
||
{
|
||
if (df.ToOrgin && df.GoHomeOrder == 1 && df.org_Successful)
|
||
{
|
||
bl = false;
|
||
}
|
||
}
|
||
|
||
if (bl == true)
|
||
{
|
||
HomeStep++;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step2:
|
||
foreach (FeiYuShaft df in AllShaftList)
|
||
{
|
||
if (df.ToOrgin && df.GoHomeOrder == 2)
|
||
{
|
||
df.org_Successful = true;
|
||
df.HomeStep = GengralProcessEnum.Start;
|
||
}
|
||
}
|
||
HomeStep++;
|
||
break;
|
||
case GengralProcessEnum.Step3:
|
||
foreach (FeiYuShaft df in AllShaftList)
|
||
{
|
||
if (df.ToOrgin && df.GoHomeOrder == 2 && df.org_Successful)
|
||
{
|
||
bl = false;
|
||
}
|
||
}
|
||
|
||
if (bl == true)
|
||
{
|
||
HomeStep++;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step4:
|
||
foreach (FeiYuShaft df in AllShaftList)
|
||
{
|
||
if (df.ToOrgin && df.GoHomeOrder == 3)
|
||
{
|
||
df.org_Successful = true;
|
||
df.HomeStep = GengralProcessEnum.Start;
|
||
}
|
||
}
|
||
HomeStep++;
|
||
break;
|
||
case GengralProcessEnum.Step5:
|
||
foreach (FeiYuShaft df in AllShaftList)
|
||
{
|
||
if (df.ToOrgin && df.GoHomeOrder == 3 && df.org_Successful)
|
||
{
|
||
bl = false;
|
||
}
|
||
}
|
||
|
||
if (bl == true)
|
||
{
|
||
HomeStep++;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step6:
|
||
foreach (FeiYuShaft df in AllShaftList)
|
||
{
|
||
if (df.ToOrgin && df.GoHomeOrder == 4)
|
||
{
|
||
df.org_Successful = true;
|
||
df.HomeStep = GengralProcessEnum.Start;
|
||
}
|
||
}
|
||
HomeStep++;
|
||
break;
|
||
case GengralProcessEnum.Step7:
|
||
foreach (FeiYuShaft df in AllShaftList)
|
||
{
|
||
if (df.ToOrgin && df.GoHomeOrder == 4 && df.org_Successful)
|
||
{
|
||
bl = false;
|
||
}
|
||
}
|
||
|
||
if (bl == true)
|
||
{
|
||
HomeStep++;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step8:
|
||
foreach (FeiYuShaft df in AllShaftList)
|
||
{
|
||
if (df.ToOrgin && df.GoHomeOrder == 5)
|
||
{
|
||
df.org_Successful = true;
|
||
df.HomeStep = GengralProcessEnum.Start;
|
||
}
|
||
}
|
||
HomeStep++;
|
||
break;
|
||
case GengralProcessEnum.Step9:
|
||
foreach (FeiYuShaft df in AllShaftList)
|
||
{
|
||
if (df.ToOrgin && df.GoHomeOrder == 5 && df.org_Successful)
|
||
{
|
||
bl = false;
|
||
}
|
||
}
|
||
|
||
if (bl == true)
|
||
{
|
||
HomeStep = GengralProcessEnum.End;
|
||
}
|
||
break;
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 所有轴状态
|
||
//所有轴状态
|
||
foreach (FeiYuShaft s in AllShaftList)
|
||
{
|
||
if (s.ID > 0)
|
||
{
|
||
s.GetAllStart();
|
||
if (s.ShaftState.StatusBackground == ColorStr.Yellow)
|
||
{
|
||
eventExcepReport(s.ShaftName + "异常");//抛出异常
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 停止所有轴
|
||
/// <summary>
|
||
/// 停止所有轴
|
||
/// </summary>
|
||
public void StopAllShaft()
|
||
{
|
||
foreach (FeiYuShaft sf in AllShaftList)
|
||
{
|
||
sf.ShaftStop();
|
||
}
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
#region 新增运行轨迹
|
||
/// <summary>
|
||
/// 新增运行轨迹
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void AddTrajectory(object obj)
|
||
{
|
||
int type = Convert.ToInt32(obj.ToString());
|
||
MotionTrajectoryModel mtm = new MotionTrajectoryModel() { TraName = "新来的", SuperiorID = MachineObj.ID, ClassType = TabSelectNumber, TrajectoryTrype = type };
|
||
if (dal.AddMotionTrajectory(mtm) > 0)
|
||
{
|
||
if (TabSelectNumber == 0)
|
||
{
|
||
TrajListL = dal.GetMotionTrajectoryList(MachineObj.ID, TabSelectNumber);
|
||
}
|
||
else
|
||
{
|
||
TrajListR = dal.GetMotionTrajectoryList(MachineObj.ID, TabSelectNumber);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
MyMessageBox.Show("新增轨迹失败");
|
||
}
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 删除运行轨迹
|
||
/// <summary>
|
||
/// 删除运行轨迹
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void DeleteTrajectory(object obj)
|
||
{
|
||
if (SelectTrajectory == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (MyMessageBox.Show("你确定要删除当前测量项目吗?", "警告", MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Affirmative)
|
||
{
|
||
if (dal.DeleteMotionTrajectory(SelectTrajectory) > 0)
|
||
{
|
||
TrajListL = dal.GetMotionTrajectoryList(MachineObj.ID);
|
||
}
|
||
else
|
||
{
|
||
MyMessageBox.Show("删除失败");
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 保存运行轨迹信息
|
||
/// <summary>
|
||
/// 保存运行轨迹信息
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void SaveTrajectory(object obj)
|
||
{
|
||
if (SelectTrajectory != null)
|
||
{
|
||
if (dal.UpdateMotionTrajectory(SelectTrajectory) > 0)
|
||
{
|
||
MyMessageBox.Show("保存成功");
|
||
}
|
||
else
|
||
{
|
||
MyMessageBox.Show("保存失败");
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 运行当前轨迹
|
||
/// <summary>
|
||
/// 是否正在在运行选中轨迹
|
||
/// </summary>
|
||
bool RunSelectTrajectory { get; set; }
|
||
|
||
|
||
/// <summary>
|
||
/// 运行当前轨迹
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void RunTrajectory(object obj)
|
||
{
|
||
if (SelectTrajectory == null)
|
||
{
|
||
MyMessageBox.Show("请选择运动轨迹");
|
||
return;
|
||
}
|
||
if (!RunSelectPointBool && !RunSelectTrajectory)
|
||
{
|
||
RunSelectTrajectory = true;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 运行选中的轨迹
|
||
/// </summary>
|
||
public void RunMotionTrajectory()
|
||
{
|
||
if (!RunSelectTrajectory)
|
||
{
|
||
return;
|
||
}
|
||
if (SelectTrajectory.TrajectoryTrype <= 0)
|
||
{
|
||
MyMessageBox.Show("点位轨迹,请使用单点运行");
|
||
return;
|
||
}
|
||
if (SelectTrajectory.TrajectoryRun(AllShaftList))
|
||
{
|
||
RunSelectTrajectory = false;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 利用反射进行对象复制
|
||
/// <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
|
||
|
||
}
|
||
}
|