DrawingFibFan.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using Microsoft.VisualBasic.CompilerServices;
  2. using MuchInfo.Chart.Data.EnumTypes;
  3. using MuchInfo.Chart.Infrastructure.Helpers;
  4. using MuchInfo.Chart.WPF.Controls.Drawing;
  5. using MuchInfo.Chart.WPF.Helpers;
  6. using MuchInfo.Chart.WPF.Primitives.Interfaces;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Windows;
  10. using System.Windows.Media;
  11. using System.Windows.Shapes;
  12. namespace MuchInfo.Chart.WPF.Primitives.Drawing
  13. {
  14. public class DrawingFibFan : DrawingFibBase
  15. {
  16. private ExtendableLine drawingFibFan_1043;
  17. private Path drawingFibFan_1044;
  18. private PathGeometry drawingFibFan_1045;
  19. public DrawingFibFan()
  20. {
  21. base.TurnOnForArc();
  22. }
  23. public override DrawingToolType ToolType()
  24. {
  25. return DrawingToolType.FibFan;
  26. }
  27. public override IDrawingTool Clone()
  28. {
  29. return new DrawingFibFan
  30. {
  31. Color = Colors.White
  32. };
  33. }
  34. protected override List<FrameworkElement> GetDrawingPlots(Chart owner, ScaleLayer aScale, Rect aRect)
  35. {
  36. List<FrameworkElement> list = new List<FrameworkElement>();
  37. bool flag = this.drawingFibFan_1043 == null;
  38. if (flag)
  39. {
  40. this.drawingFibFan_1043 = new ExtendableLine(this, owner);
  41. this.drawingFibFan_1043.Stroke = new SolidColorBrush(this.mColor);
  42. this.drawingFibFan_1043.ExtensionStroke = new SolidColorBrush(this.mColor);
  43. this.drawingFibFan_1043.StrokeThickness = 1.4;
  44. DoubleCollection doubleCollection = new DoubleCollection();
  45. doubleCollection.Add(10.0);
  46. doubleCollection.Add(10.0);
  47. this.drawingFibFan_1043.SetExtensionStrokeDash(doubleCollection);
  48. }
  49. this.drawingFibFan_1044 = new Path();
  50. this.drawingFibFan_1044.Stroke = (new SolidColorBrush(this.mColor));
  51. this.drawingFibFan_1044.StrokeThickness = (1.4);
  52. this.drawingFibFan_1045 = new PathGeometry();
  53. this.drawingFibFan_1044.Data = (this.drawingFibFan_1045);
  54. this.drawingFibFan_1044.IsHitTestVisible = (false);
  55. this.MoveDrawingToNewLocations(aRect);
  56. list.Add(this.drawingFibFan_1044);
  57. list.Add(this.drawingFibFan_1043);
  58. return list;
  59. }
  60. public override string RootName
  61. {
  62. get { return "drawFIBFAN"; }
  63. }
  64. public override string MenuDescription()
  65. {
  66. return LanguageManager.FindResource(LanguageConst.DrawingTool_Abbreviation_FibonacciFan);
  67. }
  68. public override string Abbreviation()
  69. {
  70. return "Fib Fan";
  71. }
  72. public override string Description()
  73. {
  74. return this.MenuDescription();
  75. }
  76. protected override void ColorChanged()
  77. {
  78. bool flag = this.drawingFibFan_1043 != null;
  79. if (flag)
  80. {
  81. this.drawingFibFan_1043.Stroke = new SolidColorBrush(this.mColor);
  82. this.drawingFibFan_1043.ExtensionStroke = this.drawingFibFan_1043.Stroke;
  83. }
  84. flag = (this.drawingFibFan_1044 != null);
  85. if (flag)
  86. {
  87. this.drawingFibFan_1044.Stroke = (new SolidColorBrush(this.mColor));
  88. }
  89. }
  90. protected override void MoveDrawingToNewLocations(Rect aRect)
  91. {
  92. bool flag = this.mLastScale == null || this.mLastScale.GetmScaler() == null;
  93. if (!flag)
  94. {
  95. this.drawingFibFan_1045.Figures.Clear();
  96. Point point;
  97. Point point2;
  98. checked
  99. {
  100. point = new Point((double)((int)Math.Round(this.mDrawP1.X)), (double)((int)Math.Round(this.mDrawP1.Y)));
  101. point2 = new Point((double)((int)Math.Round(this.mDrawP2.X)), (double)((int)Math.Round(this.mDrawP2.Y)));
  102. Point point3 = new Point((double)((int)Math.Round(unchecked(this.mDrawP2.X / 2.0 + this.mDrawP1.X / 2.0))), (double)((int)Math.Round(unchecked(this.mDrawP2.Y / 2.0 + this.mDrawP1.Y / 2.0))));
  103. Size size = new Size(12.0, 12.0);
  104. flag = (this.drawingFibFan_1043 != null);
  105. if (flag)
  106. {
  107. this.drawingFibFan_1043.SetPosition(this.mDrawP1, this.mDrawP2, this.mDrawP1.X > this.mDrawP2.X, this.mDrawP1.X < this.mDrawP2.X, aRect);
  108. }
  109. flag = (point.X != point2.X);
  110. }
  111. if (flag)
  112. {
  113. float num = this.P1Val - this.P2Val;
  114. try
  115. {
  116. point.X = drawingFibFan_1043.lineMain.X1;
  117. List<DrawingFibBase.FibLevel>.Enumerator enumerator = this.FibLevels.GetEnumerator();
  118. while (enumerator.MoveNext())
  119. {
  120. DrawingFibBase.FibLevel current = enumerator.Current;
  121. flag = current.IsOn;
  122. if (flag)
  123. {
  124. float num2 = num * current.Value / 100f;
  125. num2 += this.P2Val;
  126. num2 = this.mLastScale.GetmScaler().PercentFromValue(num2);
  127. num2 = this.mLastScale.GetmScaler().YFromPercent(num2, aRect);
  128. Point point4 = new Point(point2.X, (double)num2);
  129. Point point5 = point4;
  130. double slope = GeometryHelper.LineSlope(ref point, ref point5);
  131. flag = (point2.X > point.X);
  132. float num3;
  133. if (flag)
  134. {
  135. num3 = (float)aRect.Right;
  136. }
  137. else
  138. {
  139. num3 = (float)aRect.Left;
  140. }
  141. Point p = new Point((double)checked((int)Math.Round((double)num3)), GeometryHelper.YFromLine(point, slope, (double)num3));
  142. flag = (p.Y < aRect.Top);
  143. if (flag)
  144. {
  145. p = new Point(GeometryHelper.XFromLine(point, slope, aRect.Top), aRect.Top);
  146. }
  147. flag = (p.Y > aRect.Bottom);
  148. if (flag)
  149. {
  150. p = new Point(GeometryHelper.XFromLine(point, slope, aRect.Bottom), aRect.Bottom);
  151. }
  152. if (p.X < aRect.Left)
  153. {
  154. p = new Point(aRect.Left, GeometryHelper.YFromLine(point, slope, aRect.Left));
  155. }
  156. if (p.X > aRect.Width)
  157. {
  158. p = new Point(aRect.Width, GeometryHelper.YFromLine(point, slope, aRect.Width));
  159. }
  160. this.AddLine(this.drawingFibFan_1045, point, p);
  161. }
  162. }
  163. }
  164. finally
  165. {
  166. //List<drawingFibBase.FibLevel>.Enumerator enumerator;
  167. //enumerator.Dispose();
  168. }
  169. }
  170. }
  171. }
  172. protected void AddLine(PathGeometry geom, Point p1, Point p2)
  173. {
  174. PathFigure pathFigure = new PathFigure();
  175. geom.Figures.Add(pathFigure);
  176. LineSegment lineSegment = new LineSegment();
  177. pathFigure.Segments.Add(lineSegment);
  178. pathFigure.StartPoint = (p1);
  179. lineSegment.Point = (p2);
  180. }
  181. public override ImageSource Icon()
  182. {
  183. ImageSource result;
  184. try
  185. {
  186. result = ImageHelper.GetImage("FibFan.png");
  187. }
  188. catch (Exception expr_3A)
  189. {
  190. ProjectData.SetProjectError(expr_3A);
  191. result = null;
  192. ProjectData.ClearProjectError();
  193. }
  194. return result;
  195. }
  196. protected override bool CanExtendLeft()
  197. {
  198. return false;
  199. }
  200. protected override bool CanExtendRight()
  201. {
  202. return false;
  203. }
  204. }
  205. }