| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- using Prism.Mvvm;
- using System;
- using System.Collections.ObjectModel;
- namespace SKMC.Api.Recipe.Model
- {
- /// <summary>
- /// 电机点位配置模型
- /// 每个点位由1个或多个单轴位置RecipePointPosition组成
- /// </summary>
- public class RecipePoint : BindableBase, ICloneable
- {
- public long RecipeId { get; set; }
- private string _code;
- /// <summary>
- /// 点位码
- /// </summary>
- public string Code
- {
- get { return _code; }
- set { _code = value; RaisePropertyChanged(); }
- }
- private string _name;
- /// <summary>
- /// 点位名称
- /// </summary>
- 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 bool syncArrival;
- /// <summary>
- /// 多轴是否同步到达
- /// </summary>
- public bool SyncArrival
- {
- get { return syncArrival; }
- set { syncArrival = value; }
- }
- private double[] fixset;
- /// <summary>
- /// 该点位的单轴位置的偏移量数组, 序号与RecipePointPositions的序号一致
- /// </summary>
- 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];
- }
- }
- }
- }
- /// <summary>
- /// 清除偏移量
- /// </summary>
- 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;
- }
- }
- }
- /// <summary>
- /// 点位移动的安全条件 (可以用Lambda写法更方便的获取更多点位信息, 例如位置值)
- /// </summary>
- public Func<RecipePoint, bool> SafeChecker { get; set; }
- /// <summary>
- /// 点位单轴位置集合
- /// </summary>
- public ObservableCollection<RecipePointPosition> RecipePointPositions { get; set; } = new ObservableCollection<RecipePointPosition>();
- /// <summary>
- /// 获取点位的轴位置值
- /// </summary>
- /// <param name="index">绑定多轴时的获取的轴序号, 例如按顺序绑定了xy轴, x轴的序号为0、y轴的序号为1</param>
- /// <returns></returns>
- 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<RecipePointPosition>();
- foreach (var item in RecipePointPositions)
- {
- model.RecipePointPositions.Add((RecipePointPosition) item.Clone());
- }
- return model;
- }
- }
- }
|