using Prism.Mvvm;
using System;
using System.Collections.ObjectModel;
namespace SKMC.Api.Recipe.Model
{
///
/// 电机点位配置模型
/// 每个点位由1个或多个单轴位置RecipePointPosition组成
///
public class RecipePoint : BindableBase, ICloneable
{
private string _code;
///
/// 点位码
///
public string Code
{
get { return _code; }
set { _code = value; RaisePropertyChanged(); }
}
private string _name;
///
/// 点位名称
///
public string Name
{
get { return _name; }
set { _name = value; RaisePropertyChanged(); }
}
public string SerialName { get => $"[{Code}]: {Name}"; }
private string speedCode;
public string SpeedCode
{
get { return speedCode; }
set { speedCode = value; RaisePropertyChanged(); }
}
private double[] fixset;
///
/// 该点位的单轴位置的偏移量数组, 序号与RecipePointPositions的序号一致
///
public double[] Fixset
{
get { return fixset; }
set
{
fixset = value;
for (int i = 0; i < fixset.Length; i++)
{
if (RecipePointPositions != null && RecipePointPositions[i] != null)
{
RecipePointPositions[i].FixsetVal = fixset[i];
}
}
}
}
///
/// 清除偏移量
///
public void ClearFixset()
{
if (fixset != null)
{
for (int i = 0; i < fixset.Length; i++)
{
fixset[i] = 0;
}
}
if (RecipePointPositions != null)
{
foreach (RecipePointPosition pointPosition in RecipePointPositions)
{
pointPosition.FixsetVal = 0;
}
}
}
///
/// 点位移动的安全条件 (可以用Lambda写法更方便的获取更多点位信息, 例如位置值)
///
public Func SafeChecker { get; set; }
///
/// 点位单轴位置集合
///
public ObservableCollection RecipePointPositions { get; set; } = new ObservableCollection();
///
/// 获取点位的轴位置值
///
/// 绑定多轴时的获取的轴序号, 例如按顺序绑定了xy轴, x轴的序号为0、y轴的序号为1
///
public double PositionVal(int index = 0)
{
if (index < 0 || index > RecipePointPositions.Count - 1) return 0;
return RecipePointPositions[index].Position;
}
public object Clone()
{
var model = new RecipePoint
{
Code = this.Code,
Name = this.Name,
};
model.RecipePointPositions = new ObservableCollection();
foreach (var item in RecipePointPositions)
{
model.RecipePointPositions.Add((RecipePointPosition) item.Clone());
}
return model;
}
}
}