DrawingToolSpec.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using MuchInfo.Chart.WPF.Helpers;
  2. using MuchInfo.Chart.WPF.Primitives.Interfaces;
  3. using System.Collections.Generic;
  4. using System.Xml.Linq;
  5. namespace MuchInfo.Chart.WPF.Primitives.Drawing
  6. {
  7. public class DrawingToolSpec : IXmlSavable, IDrawingToolSpec
  8. {
  9. #region Fields
  10. private string _drawingXElementString;
  11. private bool _plotOnAllSymbols;
  12. private string _uniqueId;
  13. #endregion Fields
  14. #region Constructors
  15. public DrawingToolSpec()
  16. {
  17. this._uniqueId = string.Empty;
  18. this._plotOnAllSymbols = false;
  19. }
  20. public DrawingToolSpec(string symbol, IDrawingTool drawingTool)
  21. {
  22. this._plotOnAllSymbols = false;
  23. this._uniqueId = symbol;
  24. this._drawingXElementString = drawingTool.ToXml(null).ToString();
  25. }
  26. #endregion Constructors
  27. #region Properties
  28. #region Public Properties
  29. public string RootName
  30. {
  31. get { return "DTSPEC"; }
  32. }
  33. #endregion Public Properties
  34. #region Internal Properties
  35. internal DrawingToolContainer DrawingToolContainer
  36. {
  37. get;
  38. set;
  39. }
  40. #endregion Internal Properties
  41. #endregion Properties
  42. #region Methods
  43. #region Public Methods
  44. public bool AppliesToSymbol(string symbolUniqueId)
  45. {
  46. if (_plotOnAllSymbols)
  47. {
  48. return true;
  49. }
  50. else
  51. {
  52. if (string.IsNullOrWhiteSpace(this._uniqueId) || string.IsNullOrWhiteSpace(symbolUniqueId))
  53. {
  54. return false;
  55. }
  56. else
  57. {
  58. return string.CompareOrdinal(this._uniqueId, symbolUniqueId) == 0;
  59. }
  60. }
  61. }
  62. public void DeleteTool()
  63. {
  64. bool flag = this.DrawingToolContainer != null;
  65. if (flag)
  66. {
  67. this.DrawingToolContainer.DrawingToolContainer_3724(this);
  68. }
  69. }
  70. public void FromXml(XElement node)
  71. {
  72. }
  73. public IDrawingTool GetTool()
  74. {
  75. var xElement = XElement.Parse(this._drawingXElementString);
  76. var xmlSavable = XmlTypeCreator.MakeElement(xElement);
  77. var drawingTool = xmlSavable as IDrawingTool;
  78. if (drawingTool == null) return null;
  79. drawingTool.OwnerSpec = this;
  80. return drawingTool;
  81. }
  82. public ScaleLayer ScaleLayer()
  83. {
  84. return this.DrawingToolContainer.ScaleLayer();
  85. }
  86. public string SymbolUniqueId()
  87. {
  88. return this._uniqueId;
  89. }
  90. public void ToolChanged(IDrawingTool aTool)
  91. {
  92. this._drawingXElementString = aTool.ToXml(null).ToString();
  93. this._plotOnAllSymbols = aTool.PlotOnAllSymbols;
  94. }
  95. public XElement ToXml(List<object> args)
  96. {
  97. var xElement = new XElement(this.RootName);
  98. xElement.Add(new XAttribute("BID", this._uniqueId));
  99. xElement.Add(new XAttribute("Xml", this._drawingXElementString));
  100. xElement.Add(new XAttribute("ALLS", this._plotOnAllSymbols.ToString()));
  101. return xElement;
  102. }
  103. #endregion Public Methods
  104. #region Internal Methods
  105. internal void DrawingToolSpec_3741(XElement el)
  106. {
  107. bool flag = el.Attribute("BID") != null;
  108. if (flag)
  109. {
  110. this._uniqueId = el.Attribute("BID").Value;
  111. }
  112. else
  113. {
  114. flag = (el.Attribute("UID") != null);
  115. if (flag)
  116. {
  117. string value = el.Attribute("UID").Value;
  118. if (!string.IsNullOrWhiteSpace(value))
  119. {
  120. this._uniqueId = value;
  121. }
  122. }
  123. }
  124. flag = (el.Attribute("Xml") != null);
  125. if (flag)
  126. {
  127. this._drawingXElementString = el.Attribute("Xml").Value;
  128. }
  129. flag = (el.Attribute("ALLS") != null);
  130. if (flag)
  131. {
  132. this._plotOnAllSymbols = bool.Parse(el.Attribute("ALLS").Value);
  133. }
  134. }
  135. #endregion Internal Methods
  136. #endregion Methods
  137. }
  138. }