GasDxfConvertXml.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Xml;
  8. namespace MECF.Framework.UI.Core.DxfScript
  9. {
  10. /// </summary>
  11. /// 名称:xml类
  12. /// 用途:自定义对象保存至xml文件信息/根据xml文件信息 转化为自定义对象加载ui界面
  13. /// </summary>
  14. public partial class GasDxfDocument
  15. {
  16. /// <summary>
  17. /// 保存为xml文件
  18. /// </summary>
  19. public void SaveGas()
  20. {
  21. if (Lines == null || Lines.Count == 0) return;
  22. XmlDocument xmlDoc = new XmlDocument();
  23. try
  24. {
  25. XmlElement root = xmlDoc.CreateElement("GasDxfDocument");
  26. xmlDoc.AppendChild(root);
  27. XmlElement nodeLines = xmlDoc.CreateElement("Lines");
  28. XmlElement nodeCircles = xmlDoc.CreateElement("Circles");
  29. XmlElement nodeFunnels = xmlDoc.CreateElement("Funnels");
  30. XmlElement nodeTexts = xmlDoc.CreateElement("Texts");
  31. XmlElement nodePolyLines = xmlDoc.CreateElement("PolyLines");
  32. XmlElement nodeValves = xmlDoc.CreateElement("Valves");
  33. XmlElement nodeButtons = xmlDoc.CreateElement("Buttons");
  34. XmlElement nodeAnalogs = xmlDoc.CreateElement("Analogs");
  35. XmlElement nodeBoolConditions = xmlDoc.CreateElement("BoolConditions");
  36. XmlElement nodeStringConditions = xmlDoc.CreateElement("StringConditions");
  37. XmlElement nodeClickConditions = xmlDoc.CreateElement("ClickConditions");
  38. XmlElement nodeInitScriptContent = xmlDoc.CreateElement("InitScriptContent");
  39. root.AppendChild(nodeLines);
  40. root.AppendChild(nodeCircles);
  41. root.AppendChild(nodeFunnels);
  42. root.AppendChild(nodeTexts);
  43. root.AppendChild(nodePolyLines);
  44. root.AppendChild(nodeValves);
  45. root.AppendChild(nodeButtons);
  46. root.AppendChild(nodeAnalogs);
  47. root.AppendChild(nodeBoolConditions);
  48. root.AppendChild(nodeStringConditions);
  49. root.AppendChild(nodeClickConditions);
  50. root.AppendChild(nodeInitScriptContent);
  51. foreach (GasLine line in Lines)
  52. {
  53. XmlElement nodeLine = xmlDoc.CreateElement("Line");
  54. SaveLineNodeBase(xmlDoc, nodeLine, line);
  55. nodeLines.AppendChild(nodeLine);
  56. SaveCondition(xmlDoc, nodeBoolConditions, nodeStringConditions, nodeClickConditions, line);
  57. }
  58. foreach (GasCircle circle in Circles)
  59. {
  60. XmlElement nodeCircle = xmlDoc.CreateElement("Circle");
  61. SaveCircleNodeBase(xmlDoc, nodeCircle, circle);
  62. nodeCircles.AppendChild(nodeCircle);
  63. SaveCondition(xmlDoc, nodeBoolConditions, nodeStringConditions, nodeClickConditions, circle);
  64. }
  65. foreach (GasFunnel funnel in Funnels)
  66. {
  67. XmlElement nodeFunnel = xmlDoc.CreateElement("Funnel");
  68. SaveFunnelNodeBase(xmlDoc, nodeFunnel, funnel);
  69. nodeFunnels.AppendChild(nodeFunnel);
  70. SaveCondition(xmlDoc, nodeBoolConditions, nodeStringConditions, nodeClickConditions, funnel);
  71. }
  72. foreach (GasText text in Texts)
  73. {
  74. XmlElement nodeText = xmlDoc.CreateElement("Text");
  75. SaveTextNodeBase(xmlDoc, nodeText, text);
  76. nodeTexts.AppendChild(nodeText);
  77. SaveCondition(xmlDoc, nodeBoolConditions, nodeStringConditions, nodeClickConditions, text);
  78. }
  79. foreach (GasPolyLine polyLine in PolyLines)
  80. {
  81. XmlElement nodePolyLine = xmlDoc.CreateElement("PolyLine");
  82. SavePolyLineNodeBase(xmlDoc, nodePolyLine, polyLine);
  83. nodePolyLines.AppendChild(nodePolyLine);
  84. SaveCondition(xmlDoc, nodeBoolConditions, nodeStringConditions, nodeClickConditions, polyLine);
  85. }
  86. foreach (GasAITValve valve in Valves)
  87. {
  88. XmlElement nodeValve = xmlDoc.CreateElement("Valve");
  89. SaveValveNodeBase(xmlDoc, nodeValve, valve);
  90. nodeValves.AppendChild(nodeValve);
  91. SaveCondition(xmlDoc, nodeBoolConditions, nodeStringConditions, nodeClickConditions, valve);
  92. }
  93. foreach (GasButton button in Buttons)
  94. {
  95. XmlElement nodeButton = xmlDoc.CreateElement("Button");
  96. SaveButtonNodeBase(xmlDoc, nodeButton, button);
  97. nodeButtons.AppendChild(nodeButton);
  98. SaveCondition(xmlDoc, nodeBoolConditions, nodeStringConditions, nodeClickConditions, button);
  99. }
  100. foreach (GasAnalogControl4Jet analog in Analogs)
  101. {
  102. XmlElement nodeAnalog = xmlDoc.CreateElement("Analog");
  103. SaveAnalogNodeBase(xmlDoc, nodeAnalog, analog);
  104. nodeAnalogs.AppendChild(nodeAnalog);
  105. SaveCondition(xmlDoc, nodeBoolConditions, nodeStringConditions, nodeClickConditions, analog);
  106. }
  107. XmlElement nodeDfxSize = xmlDoc.CreateElement("DxfSize");
  108. nodeDfxSize.SetAttribute("DxfWidth", DxfWidth.ToString());
  109. nodeDfxSize.SetAttribute("DxfHeight", DxfHeight.ToString());
  110. root.AppendChild(nodeDfxSize);
  111. xmlDoc.Save(GasFilename);
  112. IsGasFileModified = false;
  113. }
  114. catch (Exception e)
  115. {
  116. MessageBox.Show(e.Message, "Alert", MessageBoxButton.OK);
  117. }
  118. }
  119. /// <summary>
  120. /// 根据xml文件信息加载ui
  121. /// </summary>
  122. public void LoadGas()
  123. {
  124. if (IsGasFileModified)
  125. {
  126. MessageBox.Show($"Please save the current file first.");
  127. return;
  128. }
  129. XmlDocument xmlDoc = new XmlDocument();
  130. try
  131. {
  132. ClearAll();
  133. xmlDoc.Load(GasFilename);
  134. XmlNodeList nodeLines = xmlDoc.SelectNodes("/GasDxfDocument/Lines/Line");
  135. if (nodeLines != null)
  136. {
  137. foreach (XmlElement node in nodeLines)
  138. {
  139. GasLine line = LoadLineNodeBase(xmlDoc, node);
  140. Lines.Add(line);
  141. }
  142. }
  143. XmlNodeList nodeCircles = xmlDoc.SelectNodes("GasDxfDocument/Circles/Circle");
  144. if (nodeCircles != null)
  145. {
  146. foreach (XmlElement node in nodeCircles)
  147. {
  148. GasCircle circle = LoadCircleNodeBase(xmlDoc, node);
  149. Circles.Add(circle);
  150. }
  151. }
  152. XmlNodeList nodeFunnels = xmlDoc.SelectNodes("GasDxfDocument/Funnels/Funnel");
  153. if (nodeFunnels != null)
  154. {
  155. foreach (XmlElement node in nodeFunnels)
  156. {
  157. GasFunnel funnel = LoadFunnelNodeBase(xmlDoc, node);
  158. Funnels.Add(funnel);
  159. }
  160. }
  161. XmlNodeList nodeTexts = xmlDoc.SelectNodes("GasDxfDocument/Texts/Text");
  162. if (nodeTexts != null)
  163. {
  164. foreach (XmlElement node in nodeTexts)
  165. {
  166. GasText text = LoadTextNodeBase(xmlDoc, node);
  167. Texts.Add(text);
  168. }
  169. }
  170. XmlNodeList nodePolyLines = xmlDoc.SelectNodes("GasDxfDocument/PolyLines/PolyLine");
  171. if (nodePolyLines != null)
  172. {
  173. foreach (XmlElement node in nodePolyLines)
  174. {
  175. GasPolyLine polyLine = LoadPolyLineNodeBase(xmlDoc, node);
  176. PolyLines.Add(polyLine);
  177. }
  178. }
  179. XmlNodeList nodeValves = xmlDoc.SelectNodes("GasDxfDocument/Valves/Valve");
  180. if (nodeValves != null)
  181. {
  182. foreach (XmlElement node in nodeValves)
  183. {
  184. GasAITValve valve = LoadValveNodeBase(xmlDoc, node);
  185. Valves.Add(valve);
  186. }
  187. }
  188. XmlNodeList nodeButtons = xmlDoc.SelectNodes("GasDxfDocument/Buttons/Button");
  189. if (nodeButtons != null)
  190. {
  191. foreach (XmlElement node in nodeButtons)
  192. {
  193. GasButton button = LoadButtonNodeBase(xmlDoc, node);
  194. Buttons.Add(button);
  195. }
  196. }
  197. XmlNodeList nodeAnalogs = xmlDoc.SelectNodes("GasDxfDocument/Analogs/Analog");
  198. if (nodeAnalogs != null)
  199. {
  200. foreach (XmlElement node in nodeAnalogs)
  201. {
  202. GasAnalogControl4Jet analog = LoadAnalogNodeBase(xmlDoc, node);
  203. Analogs.Add(analog);
  204. }
  205. }
  206. XmlNodeList nodeDxfSizes = xmlDoc.SelectNodes("GasDxfDocument/DxfSize");
  207. foreach (XmlElement node in nodeDxfSizes)
  208. {
  209. DxfWidth = double.Parse(node.GetAttribute("DxfWidth"));
  210. DxfHeight = double.Parse(node.GetAttribute("DxfHeight"));
  211. }
  212. LoadCondition(xmlDoc);
  213. IsGasFileModified = false;
  214. }
  215. catch (Exception e)
  216. {
  217. MessageBox.Show(e.Message, "Alert", MessageBoxButton.OK);
  218. }
  219. }
  220. #region dxf信息保存至xml/根据xml文件初始化 ui展示
  221. //save line To xml
  222. private void SaveLineNodeBase(XmlDocument xmlDoc, XmlElement nodeLine, GasLine line)
  223. {
  224. nodeLine.SetAttribute("X1", line.X1.ToString());
  225. nodeLine.SetAttribute("Y1", line.Y1.ToString());
  226. nodeLine.SetAttribute("X2", line.X2.ToString());
  227. nodeLine.SetAttribute("Y2", line.Y2.ToString());
  228. nodeLine.SetAttribute("Id", line.Id.ToString());
  229. nodeLine.SetAttribute("Enable", line.Enable.ToString());
  230. }
  231. //Load line xml To Object
  232. private GasLine LoadLineNodeBase(XmlDocument xmlDoc, XmlElement nodeLine)
  233. {
  234. double x1, y1, x2, y2;
  235. bool enable;
  236. int id;
  237. x1 = double.Parse(nodeLine.GetAttribute("X1"));
  238. y1 = double.Parse(nodeLine.GetAttribute("Y1"));
  239. x2 = double.Parse(nodeLine.GetAttribute("X2"));
  240. y2 = double.Parse(nodeLine.GetAttribute("Y2"));
  241. id = int.Parse(nodeLine.GetAttribute("Id"));
  242. enable = bool.Parse(nodeLine.GetAttribute("Enable"));
  243. GasLine line = new GasLine(x1, y1, x2, y2);
  244. line.Id = id;
  245. line.Enable = enable;
  246. return line;
  247. }
  248. //save circle To xml
  249. private void SaveCircleNodeBase(XmlDocument xmlDoc, XmlElement nodeCircle, GasCircle circle)
  250. {
  251. nodeCircle.SetAttribute("X", circle.X.ToString());
  252. nodeCircle.SetAttribute("Y", circle.Y.ToString());
  253. nodeCircle.SetAttribute("R", circle.R.ToString());
  254. nodeCircle.SetAttribute("StartAngle", circle.StartAngle.ToString());
  255. nodeCircle.SetAttribute("EndAngle", circle.EndAngle.ToString());
  256. nodeCircle.SetAttribute("Id", circle.Id.ToString());
  257. nodeCircle.SetAttribute("Enable", circle.Enable.ToString());
  258. }
  259. //Load circle xml To Object
  260. private GasCircle LoadCircleNodeBase(XmlDocument xmlDoc, XmlElement nodeCircle)
  261. {
  262. double x, y, r, startAngle, endAngle;
  263. bool enable;
  264. int id;
  265. x = double.Parse(nodeCircle.GetAttribute("X"));
  266. y = double.Parse(nodeCircle.GetAttribute("Y"));
  267. r = double.Parse(nodeCircle.GetAttribute("R"));
  268. startAngle = double.Parse(nodeCircle.GetAttribute("StartAngle"));
  269. endAngle = double.Parse(nodeCircle.GetAttribute("EndAngle"));
  270. id = int.Parse(nodeCircle.GetAttribute("Id"));
  271. enable = bool.Parse(nodeCircle.GetAttribute("Enable"));
  272. GasCircle circle = new GasCircle(x, y, r, startAngle, endAngle);
  273. circle.Id = id;
  274. circle.Enable = enable;
  275. return circle;
  276. }
  277. //save funnel To xml
  278. private void SaveFunnelNodeBase(XmlDocument xmlDoc, XmlElement nodeFunnel, GasFunnel funnel)
  279. {
  280. nodeFunnel.SetAttribute("X", funnel.X.ToString());
  281. nodeFunnel.SetAttribute("Y", funnel.Y.ToString());
  282. nodeFunnel.SetAttribute("Z", funnel.Z.ToString());
  283. nodeFunnel.SetAttribute("ScaleX", funnel.ScaleX.ToString());
  284. nodeFunnel.SetAttribute("ScaleY", funnel.ScaleY.ToString());
  285. nodeFunnel.SetAttribute("ScaleZ", funnel.ScaleZ.ToString());
  286. nodeFunnel.SetAttribute("Rotation", funnel.Rotation.ToString());
  287. nodeFunnel.SetAttribute("Id", funnel.Id.ToString());
  288. nodeFunnel.SetAttribute("Enable", funnel.Enable.ToString());
  289. XmlElement xmlElement = xmlDoc.CreateElement("GasLines");
  290. nodeFunnel.AppendChild(xmlElement);
  291. foreach (var line in funnel.GasLines)
  292. {
  293. XmlElement lineElement = xmlDoc.CreateElement("GasLine");
  294. SaveLineNodeBase(xmlDoc, lineElement, line);
  295. xmlElement.AppendChild(lineElement);
  296. }
  297. }
  298. //Load funnel xml To Object
  299. private GasFunnel LoadFunnelNodeBase(XmlDocument xmlDoc, XmlElement nodeFunnel)
  300. {
  301. XmlNodeList gasLinesXml = nodeFunnel.SelectNodes("GasLines/GasLine");
  302. if (gasLinesXml == null) return null;
  303. var x = double.Parse(nodeFunnel.GetAttribute("X"));
  304. var y = double.Parse(nodeFunnel.GetAttribute("Y"));
  305. var z = double.Parse(nodeFunnel.GetAttribute("Z"));
  306. var scaleX = double.Parse(nodeFunnel.GetAttribute("ScaleX"));
  307. var scaleY = double.Parse(nodeFunnel.GetAttribute("ScaleY"));
  308. var scaleZ = double.Parse(nodeFunnel.GetAttribute("ScaleZ"));
  309. var rotation = double.Parse(nodeFunnel.GetAttribute("Rotation"));
  310. var id = int.Parse(nodeFunnel.GetAttribute("Id"));
  311. var enable = bool.Parse(nodeFunnel.GetAttribute("Enable"));
  312. GasFunnel gasFunnel = new GasFunnel(x, y, z, scaleX, scaleY, scaleZ, rotation);
  313. gasFunnel.Id = id;
  314. gasFunnel.Enable = enable;
  315. foreach (XmlElement item in gasLinesXml)
  316. {
  317. GasLine line = LoadLineNodeBase(xmlDoc, item);
  318. if (line == null) continue;
  319. gasFunnel.GasLines.Add(line);
  320. }
  321. return gasFunnel;
  322. }
  323. //save text To xml
  324. private void SaveTextNodeBase(XmlDocument xmlDoc, XmlElement nodeText, GasText text)
  325. {
  326. nodeText.SetAttribute("X", text.X.ToString());
  327. nodeText.SetAttribute("Y", text.Y.ToString());
  328. nodeText.SetAttribute("Text", text.Text.ToString());
  329. nodeText.SetAttribute("RectWidth", text.RectWidth.ToString());
  330. nodeText.SetAttribute("RectHeight", text.RectHeight.ToString());
  331. nodeText.SetAttribute("TextHeight", text.TextHeight.ToString());
  332. nodeText.SetAttribute("LineSpacce", text.LineSpace.ToString());
  333. nodeText.SetAttribute("Alignment", text.Alignment.ToString());
  334. nodeText.SetAttribute("FontSize", text.FontSize.ToString());
  335. nodeText.SetAttribute("Id", text.Id.ToString());
  336. nodeText.SetAttribute("Enable", text.Enable.ToString());
  337. }
  338. //Load text xml To Object
  339. private GasText LoadTextNodeBase(XmlDocument xmlDoc, XmlElement nodeText)
  340. {
  341. double x, y;
  342. bool enable;
  343. int id;
  344. string _text;
  345. x = double.Parse(nodeText.GetAttribute("X"));
  346. y = double.Parse(nodeText.GetAttribute("Y"));
  347. double fontSize = double.Parse(nodeText.GetAttribute("FontSize"));
  348. double rectWidth = double.Parse(nodeText.GetAttribute("RectWidth"));
  349. double rectHeight = double.Parse(nodeText.GetAttribute("RectHeight"));
  350. double textHeight = double.Parse(nodeText.GetAttribute("TextHeight"));
  351. int alignment = int.Parse(nodeText.GetAttribute("Alignment"));
  352. double lineSpace = double.Parse(nodeText.GetAttribute("LineSpacce"));
  353. _text = nodeText.GetAttribute("Text");
  354. id = int.Parse(nodeText.GetAttribute("Id"));
  355. enable = bool.Parse(nodeText.GetAttribute("Enable"));
  356. GasText text = new GasText(x, y, _text);
  357. text.Id = id;
  358. text.Enable = enable;
  359. text.RectWidth = rectWidth;
  360. text.RectHeight = rectHeight;
  361. text.TextHeight = textHeight;
  362. text.LineSpace = lineSpace;
  363. text.FontSize = fontSize;
  364. text.Alignment = alignment;
  365. return text;
  366. }
  367. //save polyLine To xml
  368. private void SavePolyLineNodeBase(XmlDocument xmlDoc, XmlElement nodePolyLine, GasPolyLine polyLine)
  369. {
  370. nodePolyLine.SetAttribute("Id", polyLine.Id.ToString());
  371. nodePolyLine.SetAttribute("Enable", polyLine.Enable.ToString());
  372. XmlElement nodeInnerLines = xmlDoc.CreateElement("InnerLines");
  373. nodePolyLine.AppendChild(nodeInnerLines);
  374. foreach (GasLine innerLine in polyLine.InnerLines)
  375. {
  376. XmlElement nodeInnerLine = xmlDoc.CreateElement("InnerLine");
  377. SaveLineNodeBase(xmlDoc, nodeInnerLine, innerLine);
  378. nodeInnerLines.AppendChild(nodeInnerLine);
  379. }
  380. }
  381. //Load polyLine xml To Object
  382. private GasPolyLine LoadPolyLineNodeBase(XmlDocument xmlDoc, XmlElement nodePolyLine)
  383. {
  384. bool enable;
  385. int id;
  386. XmlNodeList nodeInnerLines = nodePolyLine.SelectNodes("InnerLines/InnerLine");
  387. if (nodeInnerLines == null)
  388. {
  389. return null;
  390. }
  391. GasPolyLine polyLine = new GasPolyLine();
  392. id = int.Parse(nodePolyLine.GetAttribute("Id"));
  393. enable = bool.Parse(nodePolyLine.GetAttribute("Enable"));
  394. polyLine.Id = id;
  395. polyLine.Enable = enable;
  396. foreach (XmlElement nodeInnerLine in nodeInnerLines)
  397. {
  398. GasLine line = LoadLineNodeBase(xmlDoc, nodeInnerLine);
  399. if (line != null)
  400. {
  401. polyLine.InnerLines.Add(line);
  402. }
  403. }
  404. return polyLine;
  405. }
  406. //save button To xml
  407. private void SaveButtonNodeBase(XmlDocument xmlDoc, XmlElement nodeButton, GasButton button)
  408. {
  409. nodeButton.SetAttribute("Id", button.Id.ToString());
  410. nodeButton.SetAttribute("Enable", button.Enable.ToString());
  411. XmlElement nodeInnerPolyLine = xmlDoc.CreateElement("InnerPolyLine");
  412. XmlElement nodeInnerText = xmlDoc.CreateElement("InnerText");
  413. SavePolyLineNodeBase(xmlDoc, nodeInnerPolyLine, button.InnerPolyLine);
  414. SaveTextNodeBase(xmlDoc, nodeInnerText, button.InnerText);
  415. nodeButton.AppendChild(nodeInnerPolyLine);
  416. nodeButton.AppendChild(nodeInnerText);
  417. }
  418. //Load button xml To Object
  419. private GasButton LoadButtonNodeBase(XmlDocument xmlDoc, XmlElement nodeButton)
  420. {
  421. bool enable;
  422. int id;
  423. id = int.Parse(nodeButton.GetAttribute("Id"));
  424. enable = bool.Parse(nodeButton.GetAttribute("Enable"));
  425. GasPolyLine polyLine = LoadPolyLineNodeBase(xmlDoc, nodeButton.SelectSingleNode("InnerPolyLine") as XmlElement);
  426. GasText text = LoadTextNodeBase(xmlDoc, nodeButton.SelectSingleNode("InnerText") as XmlElement);
  427. GasButton button = new GasButton(polyLine, text);
  428. button.Id = id;
  429. button.Enable = enable;
  430. return button;
  431. }
  432. //save valve To xml
  433. private void SaveValveNodeBase(XmlDocument xmlDoc, XmlElement nodeValve, GasAITValve valve)
  434. {
  435. nodeValve.SetAttribute("Id", valve.Id.ToString());
  436. nodeValve.SetAttribute("Enable", valve.Enable.ToString());
  437. XmlElement nodeInnerPolyLine = xmlDoc.CreateElement("InnerPolyLine");
  438. XmlElement nodeInnerText = xmlDoc.CreateElement("InnerText");
  439. XmlElement nodeInnerCircle = xmlDoc.CreateElement("InnerCircle");
  440. if (valve.InnerPolyLine != null)
  441. {
  442. SavePolyLineNodeBase(xmlDoc, nodeInnerPolyLine, valve.InnerPolyLine);
  443. nodeValve.AppendChild(nodeInnerPolyLine);
  444. }
  445. SaveCircleNodeBase(xmlDoc, nodeInnerCircle, valve.InnerCircle);
  446. SaveTextNodeBase(xmlDoc, nodeInnerText, valve.InnerText);
  447. nodeValve.AppendChild(nodeInnerText);
  448. nodeValve.AppendChild(nodeInnerCircle);
  449. }
  450. //Load valve xml To Object
  451. private GasAITValve LoadValveNodeBase(XmlDocument xmlDoc, XmlElement nodeValve)
  452. {
  453. bool enable;
  454. int id;
  455. id = int.Parse(nodeValve.GetAttribute("Id"));
  456. enable = bool.Parse(nodeValve.GetAttribute("Enable"));
  457. XmlElement nodePolyLine = nodeValve.SelectSingleNode("InnerPolyLine") as XmlElement;
  458. GasPolyLine polyLine = null;
  459. if (nodePolyLine != null)
  460. {
  461. polyLine = LoadPolyLineNodeBase(xmlDoc, nodePolyLine);
  462. }
  463. GasText text = LoadTextNodeBase(xmlDoc, nodeValve.SelectSingleNode("InnerText") as XmlElement);
  464. GasCircle circle = LoadCircleNodeBase(xmlDoc, nodeValve.SelectSingleNode("InnerCircle") as XmlElement);
  465. if (polyLine == null || polyLine.InnerLines == null || polyLine.InnerLines.Count == 0)
  466. {
  467. polyLine = null;
  468. }
  469. GasAITValve valve = new GasAITValve(circle, text, polyLine);
  470. valve.Id = id;
  471. valve.Enable = enable;
  472. return valve;
  473. }
  474. //save analog To xml
  475. private void SaveAnalogNodeBase(XmlDocument xmlDoc, XmlElement nodeAnalog, GasAnalogControl4Jet analog)
  476. {
  477. nodeAnalog.SetAttribute("Id", analog.Id.ToString());
  478. nodeAnalog.SetAttribute("Enable", analog.Enable.ToString());
  479. XmlElement nodeTopButton = xmlDoc.CreateElement("TopButton");
  480. XmlElement nodeLeftButton = xmlDoc.CreateElement("LeftButton");
  481. XmlElement nodeRightButton = xmlDoc.CreateElement("RightButton");
  482. XmlElement nodeInnerButton = xmlDoc.CreateElement("InnerButton");
  483. SaveButtonNodeBase(xmlDoc, nodeTopButton, analog.TopButton);
  484. SaveButtonNodeBase(xmlDoc, nodeLeftButton, analog.LeftButton);
  485. SaveButtonNodeBase(xmlDoc, nodeRightButton, analog.RightButton);
  486. SaveButtonNodeBase(xmlDoc, nodeInnerButton, analog.InnerButton);
  487. nodeAnalog.AppendChild(nodeTopButton);
  488. nodeAnalog.AppendChild(nodeLeftButton);
  489. nodeAnalog.AppendChild(nodeRightButton);
  490. nodeAnalog.AppendChild(nodeInnerButton);
  491. }
  492. //Load analog xml To Object
  493. private GasAnalogControl4Jet LoadAnalogNodeBase(XmlDocument xmlDoc, XmlElement nodeAnalog)
  494. {
  495. bool enable;
  496. int id;
  497. id = int.Parse(nodeAnalog.GetAttribute("Id"));
  498. enable = bool.Parse(nodeAnalog.GetAttribute("Enable"));
  499. XmlElement nodeTopButton = nodeAnalog.SelectSingleNode("TopButton") as XmlElement;
  500. XmlElement nodeLeftButton = nodeAnalog.SelectSingleNode("LeftButton") as XmlElement;
  501. XmlElement nodeRightButton = nodeAnalog.SelectSingleNode("RightButton") as XmlElement;
  502. XmlElement nodeInnerButton = nodeAnalog.SelectSingleNode("InnerButton") as XmlElement;
  503. GasButton topButton = LoadButtonNodeBase(xmlDoc, nodeTopButton);
  504. GasButton leftButton = LoadButtonNodeBase(xmlDoc, nodeLeftButton);
  505. GasButton rightButton = LoadButtonNodeBase(xmlDoc, nodeRightButton);
  506. GasButton innerButton = LoadButtonNodeBase(xmlDoc, nodeInnerButton);
  507. GasAnalogControl4Jet analog = new GasAnalogControl4Jet(innerButton, topButton, leftButton, rightButton);
  508. analog.Id = id;
  509. analog.Enable = enable;
  510. return analog;
  511. }
  512. #endregion
  513. }
  514. }