RecipeCacher.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. using SKMC.Api.Recipe.Config;
  2. using SKMC.Api.Recipe.Model;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.Diagnostics;
  7. using System.Linq;
  8. namespace SKMC.Api.Recipe
  9. {
  10. /// <summary>
  11. /// 配方数据缓存器
  12. /// </summary>
  13. public abstract class RecipeCacher
  14. {
  15. /// <summary>
  16. /// 当前使用的配方
  17. /// </summary>
  18. public RecipeProfile RecipeProfile { get; set; }
  19. /// <summary>
  20. /// 获取流程参数配置集
  21. /// </summary>
  22. /// <param name="isAdv">是否高级类型</param>
  23. /// <param name="isMod">是否开关类型</param>
  24. /// <returns></returns>
  25. public ObservableCollection<RecipeParam> GetRecipeParams(short isAdv, short isMod)
  26. {
  27. if (isAdv == 0 && isMod == 0)
  28. {
  29. return GetRecipeBaseValueParams();
  30. }
  31. if (isAdv == 0 && isMod == 1)
  32. {
  33. return GetRecipeBaseModParams();
  34. }
  35. if (isAdv == 1 && isMod == 0)
  36. {
  37. return GetRecipeAdvValueParams();
  38. }
  39. if (isAdv == 1 && isMod == 1)
  40. {
  41. return GetRecipeAdvModParams();
  42. }
  43. return null;
  44. }
  45. /// <summary>
  46. /// 流程参数配置集(基础开关型)
  47. /// </summary>
  48. public ObservableCollection<RecipeParam> GetRecipeBaseModParams() => RecipeProfile.RecipeBaseModParams;
  49. /// <summary>
  50. /// 流程参数配置集(基础数值型)
  51. /// </summary>
  52. public ObservableCollection<RecipeParam> GetRecipeBaseValueParams() => RecipeProfile.RecipeBaseValueParams;
  53. /// <summary>
  54. /// 流程参数配置集(内部开关型)
  55. /// </summary>
  56. public ObservableCollection<RecipeParam> GetRecipeAdvModParams() => RecipeProfile.RecipeAdvModParams;
  57. /// <summary>
  58. /// 流程参数配置集(内部数值型)
  59. /// </summary>
  60. public ObservableCollection<RecipeParam> GetRecipeAdvValueParams() => RecipeProfile.RecipeAdvValueParams;
  61. /// <summary>
  62. /// 速度配置集
  63. /// </summary>
  64. // public ObservableCollection<RecipeSpeed> GetRecipeSpeeds() => RecipeProfile.RecipeSpeeds;
  65. /// <summary>
  66. /// 速度配置集
  67. /// 考虑到速度切换需要先进入“速度设置”页面才能获取到速度挡位。暂时先默认选择第一个速度组。
  68. /// </summary>
  69. public ObservableCollection<RecipeSpeed> GetRecipeSpeeds()
  70. {
  71. ObservableCollection<RecipeSpeed> recipeSpeeds = new ObservableCollection<RecipeSpeed>();
  72. var usedGroup = GetRecipeSpeedGroups().FirstOrDefault(t => t.CurrentUsed == 1);
  73. if (usedGroup == null) throw new ArgumentException($"Cannot Get Speed Group[{usedGroup.Name}]");
  74. recipeSpeeds = GetRecipeSpeeds(usedGroup);
  75. return recipeSpeeds;
  76. }
  77. /// <summary>
  78. /// 点位配置集
  79. /// </summary>
  80. public ObservableCollection<RecipePointGroup> GetRecipePointGroups() => RecipeProfile.RecipePointGroups;
  81. /// <summary>
  82. /// 速度分组配置集
  83. /// </summary>
  84. public ObservableCollection<RecipeSpeedGroup> GetRecipeSpeedGroups() => RecipeProfile.RecipeSpeedGroups;
  85. /// <summary>
  86. /// 点位配置集
  87. /// </summary>
  88. public ObservableCollection<RecipePoint> GetRecipePoints() => RecipeProfile.RecipePoints;
  89. /// <summary>
  90. /// 获取流程参数对象
  91. /// </summary>
  92. /// <param name="paramCode"></param>
  93. /// <returns></returns>
  94. public abstract RecipeParam GetRecipeParam(string paramCode);
  95. /// <summary>
  96. /// 获取流程参数配置(根据数据库配置加载)
  97. /// </summary>
  98. /// <param name="paramCode"></param>
  99. /// <returns></returns>
  100. public abstract T GetRecipeParamValue<T>(string paramCode);
  101. /// <summary>
  102. /// 获取流程点位
  103. /// </summary>
  104. /// <param name="code"></param>
  105. /// <returns></returns>
  106. public abstract RecipePoint GetRecipePoint(string code);
  107. /// <summary>
  108. /// 获取流程点位的轴位置数值
  109. /// </summary>
  110. /// <param name="code">点位码</param>
  111. /// <param name="index">点位中多个轴位置的序号, 默认为第一个</param>
  112. /// <returns></returns>
  113. public abstract double GetRecipePointVal(string code, int index = 0);
  114. /// <summary>
  115. /// 获取流程点位的轴位置数值
  116. /// </summary>
  117. /// <param name="recipePoint">点位对象</param>
  118. /// <param name="index">点位中多个轴位置的序号, 默认为第一个</param>
  119. /// <returns></returns>
  120. public abstract double GetRecipePointVal(RecipePoint recipePoint, int index = 0);
  121. /// <summary>
  122. /// 获取速度配置对象
  123. /// </summary>
  124. /// <param name="speedCode">速度码</param>
  125. /// <returns></returns>
  126. public abstract RecipeSpeed GetRecipeSpeed(string speedCode);
  127. /// <summary>
  128. /// 获取速度分组下的速度集合
  129. /// </summary>
  130. /// <param name="group"></param>
  131. /// <returns></returns>
  132. public ObservableCollection<RecipeSpeed> GetRecipeSpeeds(RecipeSpeedGroup group)
  133. {
  134. ObservableCollection<RecipeSpeed> speedModels = new ObservableCollection<RecipeSpeed>
  135. (
  136. RecipeProfile.RecipeSpeeds.Where(model => model.GroupId == group.Id)
  137. );
  138. if (speedModels == null) throw new ArgumentException($"Cannot Get Speed Group[{group.Name}]");
  139. return speedModels;
  140. }
  141. }
  142. }