CSpecialGrayRangeParam.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using OTSDataType;
  2. using OTSModelSharp;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Xml;
  10. namespace OTSMeasureApp._0_OTSModel.Measure.ParamData
  11. {
  12. public class CSpecialGrayRange:ISlo
  13. {
  14. public CIntRange range=new CIntRange();
  15. public CIntRange diameterRange = new CIntRange();
  16. public bool ifCollectXray;
  17. public override void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
  18. {
  19. xInt xStart = new xInt();
  20. xInt xEnd = new xInt();
  21. xInt xdiaStart = new xInt();
  22. xInt xdiaEnd = new xInt();
  23. xBool xIfXray = new xBool();
  24. Slo slo = new Slo();
  25. slo.Register("start", xStart);
  26. slo.Register("end", xEnd);
  27. slo.Register("diameterStart", xdiaStart);
  28. slo.Register("diameterEnd", xdiaEnd);
  29. slo.Register("collectXray", xIfXray);
  30. if (isStoring)
  31. {
  32. xStart.AssignValue(range.GetStart());
  33. xEnd.AssignValue(range.GetEnd());
  34. xdiaStart.AssignValue(diameterRange.GetStart());
  35. xdiaEnd.AssignValue(diameterRange.GetEnd());
  36. xIfXray.AssignValue(ifCollectXray);
  37. slo.Serialize(true, classDoc, rootNode);
  38. }
  39. else
  40. {
  41. slo.Serialize(false, classDoc, rootNode);
  42. range.SetStart(xStart.value());
  43. range.SetEnd(xEnd.value());
  44. diameterRange.SetStart(xdiaStart.value());
  45. diameterRange.SetEnd(xdiaEnd.value());
  46. ifCollectXray = xIfXray.value();
  47. }
  48. }
  49. }
  50. public class CSpecialGrayRangeParam: ISlo
  51. {
  52. const string STRSPECIALGRAYCONFIGFILE = "SpecialGrayConfig.xml";
  53. private List<CSpecialGrayRange> Ranges=new List<CSpecialGrayRange>();
  54. private bool isToRun=false;
  55. private bool isInited=false;
  56. public static string GetParamFileFullName()
  57. {
  58. String path = ".\\" + DataPublic.STR_COFIGPATH + "\\" + DataPublic.STR_SYSTEM_DATA + "\\" + STRSPECIALGRAYCONFIGFILE;
  59. return path;
  60. }
  61. public bool GetIsToRun()
  62. {
  63. if (isInited == false)
  64. {
  65. LoadParam();
  66. isInited = true;
  67. }
  68. return isToRun;
  69. }
  70. public void SetIsToRun(bool value)
  71. {
  72. isToRun = value;
  73. }
  74. public bool IsInited { get => isInited; set => isInited = value; }
  75. public List<CSpecialGrayRange> GetSpecialGreyRanges()
  76. {
  77. if (isInited == false)
  78. {
  79. LoadParam();
  80. isInited = true;
  81. }
  82. return Ranges;
  83. }
  84. public void SetSpecailGrayRanges(List<CSpecialGrayRange> value)
  85. {
  86. Ranges = value;
  87. }
  88. public override void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
  89. {
  90. Collection<CSpecialGrayRange> xRangelist = new Collection<CSpecialGrayRange>();
  91. xBool xtoRun = new xBool();
  92. Slo slo = new Slo();
  93. slo.Register("ToRun", xtoRun);
  94. slo.Register("GrayRangeList", xRangelist);
  95. if (isStoring)
  96. {
  97. xtoRun.AssignValue(isToRun);
  98. for (int i = 0; i < Ranges.Count; i++)
  99. {
  100. xRangelist.addItem(Ranges[i]);
  101. }
  102. slo.Serialize(true, classDoc, rootNode);
  103. }
  104. else
  105. {
  106. slo.Serialize(false, classDoc, rootNode);
  107. isToRun = xtoRun.value();
  108. Ranges.Clear();
  109. for (int i = 0; i < xRangelist.size(); i++)
  110. {
  111. Ranges.Add(xRangelist.getItem(i));
  112. }
  113. }
  114. }
  115. public bool LoadParam()
  116. {
  117. String path = ".\\" + DataPublic.STR_COFIGPATH + "\\" + DataPublic.STR_SYSTEM_DATA + "\\"+ STRSPECIALGRAYCONFIGFILE;
  118. // 5. check if the stage file exist
  119. if (File.Exists(path))
  120. {// the stage file exist
  121. XmlDocument doc = new XmlDocument();
  122. //载入xml文件
  123. doc.Load(path);
  124. XmlNode root = doc.SelectSingleNode("XMLData");
  125. Serialize(false, doc, root);
  126. isInited = true;
  127. return true;
  128. }
  129. return false;
  130. }
  131. }
  132. }