SharedDrawingToolContainer.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using MuchInfo.Chart.Data;
  2. using MuchInfo.Chart.WPF.Helpers;
  3. using MuchInfo.Chart.WPF.Primitives.Interfaces;
  4. using System;
  5. using System.Collections.Generic;
  6. namespace MuchInfo.Chart.WPF.Primitives.Drawing
  7. {
  8. public class SharedDrawingToolContainer
  9. {
  10. public delegate void ReloadDrawingsEventHandler();
  11. private ScaleLayer _scaleLayer;
  12. public event SharedDrawingToolContainer.ReloadDrawingsEventHandler ReloadDrawings;
  13. protected virtual void OnReloadDrawings()
  14. {
  15. ReloadDrawingsEventHandler handler = ReloadDrawings;
  16. if (handler != null) handler();
  17. }
  18. public SharedDrawingToolContainer(ScaleLayer owner)
  19. {
  20. this._scaleLayer = owner;
  21. }
  22. public SharedDrawingToolSpec AddNewDrawing(string symbol, IDrawingTool aDrawing, TimeSpan timeFrame, Guid scaleGUID, bool IsPriceScale)
  23. {
  24. return new SharedDrawingToolSpec(this, symbol, aDrawing, timeFrame, scaleGUID, IsPriceScale);
  25. }
  26. internal void SharedDrawingToolContainer_3819(SharedDrawingToolSpec aSpec)
  27. {
  28. bool flag = this._scaleLayer != null;
  29. if (flag)
  30. {
  31. this._scaleLayer.RefreshChart(true);
  32. }
  33. }
  34. private IDrawingTool GetDrawingTool(DrawingToolInfo info, Guid scaleGuid, bool isPriceScale)
  35. {
  36. if (info == null) return null;
  37. if (isPriceScale)
  38. {
  39. if (info.ScaleGUID.HasValue && info.ScaleGUID.Value != scaleGuid) return null;
  40. var toolSpec = new SharedDrawingToolSpec(this, info);
  41. return toolSpec.GetTool();
  42. }
  43. else
  44. {
  45. var currentGuid = info.OriginalScaleGUID();
  46. if (currentGuid != scaleGuid) return null;
  47. var toolSpec = new SharedDrawingToolSpec(this, info);
  48. return toolSpec.GetTool();
  49. }
  50. }
  51. public List<IDrawingTool> DrawingForSymbol(string symbol, Guid scaleGuid, bool isPriceScale, Chart chart)
  52. {
  53. var list = new List<IDrawingTool>();
  54. if (string.IsNullOrWhiteSpace(symbol)) return list;
  55. var drawingTools = SharedDrawingManager.GetDrawingsForSymbol(symbol);
  56. if (drawingTools != null)
  57. {
  58. foreach (var current in drawingTools)
  59. {
  60. var tool = GetDrawingTool(current, scaleGuid, isPriceScale);
  61. if (tool == null) continue;
  62. list.Add(tool);
  63. }
  64. }
  65. var drawingInfos = SharedDrawingManager.GetDrawingsOnAllSymbols();
  66. if (drawingInfos != null)
  67. {
  68. foreach (var current in drawingInfos)
  69. {
  70. var tool = GetDrawingTool(current, scaleGuid, isPriceScale);
  71. if (tool == null) continue;
  72. list.Add(tool);
  73. }
  74. }
  75. return list;
  76. }
  77. public ScaleLayer ScaleLayer()
  78. {
  79. return this._scaleLayer;
  80. }
  81. }
  82. }