using SKMC.Api.Recipe.Config;
using SKMC.Api.Recipe.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
namespace SKMC.Api.Recipe
{
///
/// 配方数据缓存器
///
public abstract class RecipeCacher
{
///
/// 当前使用的配方
///
public RecipeProfile RecipeProfile { get; set; }
///
/// 获取流程参数配置集
///
/// 是否高级类型
/// 是否开关类型
///
public ObservableCollection GetRecipeParams(short isAdv, short isMod)
{
if (isAdv == 0 && isMod == 0)
{
return GetRecipeBaseValueParams();
}
if (isAdv == 0 && isMod == 1)
{
return GetRecipeBaseModParams();
}
if (isAdv == 1 && isMod == 0)
{
return GetRecipeAdvValueParams();
}
if (isAdv == 1 && isMod == 1)
{
return GetRecipeAdvModParams();
}
return null;
}
///
/// 流程参数配置集(基础开关型)
///
public ObservableCollection GetRecipeBaseModParams() => RecipeProfile.RecipeBaseModParams;
///
/// 流程参数配置集(基础数值型)
///
public ObservableCollection GetRecipeBaseValueParams() => RecipeProfile.RecipeBaseValueParams;
///
/// 流程参数配置集(内部开关型)
///
public ObservableCollection GetRecipeAdvModParams() => RecipeProfile.RecipeAdvModParams;
///
/// 流程参数配置集(内部数值型)
///
public ObservableCollection GetRecipeAdvValueParams() => RecipeProfile.RecipeAdvValueParams;
///
/// 速度配置集
///
// public ObservableCollection GetRecipeSpeeds() => RecipeProfile.RecipeSpeeds;
///
/// 速度配置集
/// 考虑到速度切换需要先进入“速度设置”页面才能获取到速度挡位。暂时先默认选择第一个速度组。
///
public ObservableCollection GetRecipeSpeeds()
{
ObservableCollection recipeSpeeds = new ObservableCollection();
var usedGroup = GetRecipeSpeedGroups().FirstOrDefault(t => t.CurrentUsed == 1);
if (usedGroup == null) throw new ArgumentException($"Cannot Get Speed Group[{usedGroup.Name}]");
recipeSpeeds = GetRecipeSpeeds(usedGroup);
return recipeSpeeds;
}
///
/// 点位配置集
///
public ObservableCollection GetRecipePointGroups() => RecipeProfile.RecipePointGroups;
///
/// 速度分组配置集
///
public ObservableCollection GetRecipeSpeedGroups() => RecipeProfile.RecipeSpeedGroups;
///
/// 点位配置集
///
public ObservableCollection GetRecipePoints() => RecipeProfile.RecipePoints;
///
/// 获取流程参数对象
///
///
///
public abstract RecipeParam GetRecipeParam(string paramCode);
///
/// 获取流程参数配置(根据数据库配置加载)
///
///
///
public abstract T GetRecipeParamValue(string paramCode);
///
/// 获取流程点位
///
///
///
public abstract RecipePoint GetRecipePoint(string code);
///
/// 获取流程点位的轴位置数值
///
/// 点位码
/// 点位中多个轴位置的序号, 默认为第一个
///
public abstract double GetRecipePointVal(string code, int index = 0);
///
/// 获取流程点位的轴位置数值
///
/// 点位对象
/// 点位中多个轴位置的序号, 默认为第一个
///
public abstract double GetRecipePointVal(RecipePoint recipePoint, int index = 0);
///
/// 获取速度配置对象
///
/// 速度码
///
public abstract RecipeSpeed GetRecipeSpeed(string speedCode);
///
/// 获取速度分组下的速度集合
///
///
///
public ObservableCollection GetRecipeSpeeds(RecipeSpeedGroup group)
{
ObservableCollection speedModels = new ObservableCollection
(
RecipeProfile.RecipeSpeeds.Where(model => model.GroupId == group.Id)
);
if (speedModels == null) throw new ArgumentException($"Cannot Get Speed Group[{group.Name}]");
return speedModels;
}
}
}