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