SharedDrawingToolSpec.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using MuchInfo.Chart.Data;
  2. using MuchInfo.Chart.Data.EnumTypes;
  3. using MuchInfo.Chart.WPF.Helpers;
  4. using MuchInfo.Chart.WPF.Primitives.Interfaces;
  5. using System;
  6. using NPOI.SS.UserModel;
  7. namespace MuchInfo.Chart.WPF.Primitives.Drawing
  8. {
  9. public class SharedDrawingToolSpec : IDrawingToolSpec
  10. {
  11. #region Fields
  12. private DrawingToolInfo _drawingToolInfo;
  13. private SharedDrawingToolContainer _sharedDrawingToolContainer;
  14. #endregion Fields
  15. #region Constructors
  16. public SharedDrawingToolSpec(SharedDrawingToolContainer aOwner, string symbol, IDrawingTool aTool, TimeSpan timeFrame, Guid scaleGuid, bool isPriceScale)
  17. {
  18. this._sharedDrawingToolContainer = aOwner;
  19. this._drawingToolInfo = new DrawingToolInfo
  20. {
  21. DrawType = checked((short)aTool.ToolType()),
  22. DrawingGUID = Guid.NewGuid(),
  23. TimeFrame = timeFrame.Ticks,
  24. Symbol = symbol
  25. };
  26. bool flag = !isPriceScale;
  27. if (flag)
  28. {
  29. this._drawingToolInfo.ScaleGUID = scaleGuid;
  30. }
  31. aTool.GetDrawingInfo(this._drawingToolInfo);
  32. this._drawingToolInfo.ChartID = "ORIGSCALEGUID|" + this._sharedDrawingToolContainer.ScaleLayer().ScaleGUID.ToString();
  33. SharedDrawingManager.AddDrawing(this._drawingToolInfo);
  34. }
  35. public SharedDrawingToolSpec(SharedDrawingToolContainer aOwner, DrawingToolInfo info)
  36. {
  37. this._sharedDrawingToolContainer = aOwner;
  38. this._drawingToolInfo = info;
  39. }
  40. #endregion Constructors
  41. #region Methods
  42. #region Public Static Methods
  43. public static IDrawingTool CreateToolFromInfo(DrawingToolInfo aInfo, SharedDrawingToolSpec aOwner)
  44. {
  45. IDrawingTool result;
  46. try
  47. {
  48. var drawingToolType = (DrawingToolType)(aInfo.DrawType.Value);
  49. IDrawingTool drawingTool = null;
  50. switch (drawingToolType)
  51. {
  52. //case DrawingToolType.AndrewsFork:
  53. // drawingTool = new drawingAndrewsPitchfork();
  54. // break;
  55. case DrawingToolType.Ellipse:
  56. drawingTool = new DrawingEllipse();
  57. break;
  58. case DrawingToolType.ErrorChannel:
  59. drawingTool = new DrawingErrorChannel();
  60. break;
  61. //case DrawingToolType.FibArc:
  62. // drawingTool = new drawingFibArc();
  63. // break;
  64. case DrawingToolType.FibFan:
  65. drawingTool = new DrawingFibFan();
  66. break;
  67. case DrawingToolType.GannBox:
  68. drawingTool = new DrawingGannBox();
  69. break;
  70. case DrawingToolType.FibRetr:
  71. drawingTool = new DrawingFibRetracement();
  72. break;
  73. case DrawingToolType.FibTime:
  74. drawingTool = new DrawingFibTimeZones();
  75. break;
  76. case DrawingToolType.GannFann:
  77. drawingTool = new DrawingGannFann();
  78. break;
  79. case DrawingToolType.HLine:
  80. drawingTool = new DrawingHorizontalLine();
  81. break;
  82. case DrawingToolType.QuadLines:
  83. drawingTool = new DrawingQuadrantLines();
  84. break;
  85. //case DrawingToolType.RaffReg:
  86. // drawingTool = new drawingRaffRegression();
  87. // break;
  88. case DrawingToolType.Rectangle:
  89. drawingTool = new DrawingRectangle();
  90. break;
  91. //case DrawingToolType.RegrChan:
  92. // drawingTool = new drawingRegressionChannel();
  93. // break;
  94. //case DrawingToolType.RegrLine:
  95. // drawingTool = new drawingRegressionLine();
  96. // break;
  97. case DrawingToolType.SpeedLines:
  98. drawingTool = new DrawingSpeedLines();
  99. break;
  100. case DrawingToolType.Text:
  101. drawingTool = new DrawingText();
  102. break;
  103. case DrawingToolType.Tirone:
  104. drawingTool = new DrawingTironeLevels();
  105. break;
  106. case DrawingToolType.TrendLine:
  107. drawingTool = new DrawingTrendLine();
  108. break;
  109. case DrawingToolType.VLine:
  110. drawingTool = new DrawingVerticalLine();
  111. break;
  112. case DrawingToolType.Arrow:
  113. drawingTool = new DrawingArrow();
  114. break;
  115. }
  116. bool flag = drawingTool != null;
  117. if (flag)
  118. {
  119. drawingTool.FromInfo(aInfo);
  120. drawingTool.OwnerSpec = aOwner;
  121. result = drawingTool;
  122. return result;
  123. }
  124. }
  125. catch (Exception expr_1B2)
  126. {
  127. throw expr_1B2;
  128. }
  129. result = null;
  130. return result;
  131. }
  132. #endregion Public Static Methods
  133. #region Public Methods
  134. public void DeleteTool()
  135. {
  136. SharedDrawingManager.DeleteDrawing(this._drawingToolInfo);
  137. bool flag = this._sharedDrawingToolContainer != null;
  138. if (flag)
  139. {
  140. this._sharedDrawingToolContainer.SharedDrawingToolContainer_3819(this);
  141. }
  142. }
  143. public DrawingToolInfo GetDrawingInfo()
  144. {
  145. return this._drawingToolInfo;
  146. }
  147. public IDrawingTool GetTool()
  148. {
  149. return SharedDrawingToolSpec.CreateToolFromInfo(this._drawingToolInfo, this);
  150. }
  151. public ScaleLayer ScaleLayer()
  152. {
  153. return this._sharedDrawingToolContainer.ScaleLayer();
  154. }
  155. public void ToolChanged(IDrawingTool aTool)
  156. {
  157. aTool.GetDrawingInfo(this._drawingToolInfo);
  158. SharedDrawingManager.UpdateDrawing(this._drawingToolInfo);
  159. }
  160. #endregion Public Methods
  161. #region Internal Methods
  162. internal Guid SharedDrawingToolSpec_3830()
  163. {
  164. bool flag = this._drawingToolInfo != null;
  165. Guid drawingGUID = Guid.Empty;
  166. if (flag)
  167. {
  168. drawingGUID = this._drawingToolInfo.DrawingGUID;
  169. }
  170. return drawingGUID;
  171. }
  172. #endregion Internal Methods
  173. #endregion Methods
  174. }
  175. }