DrawingFibRetracement.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. using Microsoft.VisualBasic;
  2. using Microsoft.VisualBasic.CompilerServices;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Media;
  8. using System.Windows.Shapes;
  9. using System.Xml.Linq;
  10. using MuchInfo.Chart.WPF.Controls.Drawing;
  11. using MuchInfo.Chart.Data.EnumTypes;
  12. using MuchInfo.Chart.WPF.Primitives.Interfaces;
  13. using MuchInfo.Chart.Infrastructure.Helpers;
  14. using MuchInfo.Chart.Infrastructure.Utilities;
  15. using MuchInfo.Chart.Infrastructure.Controls;
  16. using MuchInfo.Chart.WPF.Helpers;
  17. namespace MuchInfo.Chart.WPF.Primitives.Drawing
  18. {
  19. public class DrawingFibRetracement : DrawingFibBase
  20. {
  21. private ExtendableLine drawingFibRetracement_1046;
  22. private Line drawingFibRetracement_1047;
  23. private Path drawingFibRetracement_1048;
  24. private PathGeometry drawingFibRetracement_1049;
  25. private List<TextBlock> drawingFibRetracement_1050;
  26. private bool drawingFibRetracement_1051;
  27. public bool ShowValues
  28. {
  29. get
  30. {
  31. return this.drawingFibRetracement_1051;
  32. }
  33. set
  34. {
  35. bool flag = this.drawingFibRetracement_1051 != value;
  36. if (flag)
  37. {
  38. this.drawingFibRetracement_1051 = value;
  39. this.MoveDrawingToNewLocations(this.mLastRect);
  40. this.PropertyChanged();
  41. }
  42. }
  43. }
  44. public DrawingFibRetracement()
  45. {
  46. this.drawingFibRetracement_1051 = true;
  47. base.TurnAllOn();
  48. }
  49. public override DrawingToolType ToolType()
  50. {
  51. return DrawingToolType.FibRetr;
  52. }
  53. public override IDrawingTool Clone()
  54. {
  55. return new DrawingFibRetracement
  56. {
  57. Color = Colors.White
  58. };
  59. }
  60. protected override List<FrameworkElement> GetDrawingPlots(Chart owner, ScaleLayer aScale, Rect aRect)
  61. {
  62. List<FrameworkElement> list = new List<FrameworkElement>();
  63. bool flag = this.drawingFibRetracement_1046 == null;
  64. if (flag)
  65. {
  66. this.drawingFibRetracement_1046 = new ExtendableLine(this, owner);
  67. this.drawingFibRetracement_1046.Stroke = new SolidColorBrush(this.mColor);
  68. this.drawingFibRetracement_1046.StrokeThickness = 1.4;
  69. this.drawingFibRetracement_1046.ExtensionStroke = new SolidColorBrush(this.mExtensionColor);
  70. }
  71. flag = (this.drawingFibRetracement_1050 == null);
  72. if (flag)
  73. {
  74. this.drawingFibRetracement_1050 = new List<TextBlock>();
  75. SolidColorBrush foreground = new SolidColorBrush(this.mColor);
  76. try
  77. {
  78. List<DrawingFibBase.FibLevel>.Enumerator enumerator = this.FibLevels.GetEnumerator();
  79. while (enumerator.MoveNext())
  80. {
  81. DrawingFibBase.FibLevel current = enumerator.Current;
  82. TextBlock textBlock = new TextBlock();
  83. textBlock.FontSize = (8.0);
  84. textBlock.Visibility = (Visibility)(1);
  85. textBlock.Foreground = (foreground);
  86. textBlock.IsHitTestVisible = (false);
  87. this.drawingFibRetracement_1050.Add(textBlock);
  88. }
  89. }
  90. finally
  91. {
  92. //List<drawingFibBase.FibLevel>.Enumerator enumerator;
  93. //enumerator.Dispose();
  94. }
  95. }
  96. this.drawingFibRetracement_1047 = new Line();
  97. this.drawingFibRetracement_1047.Stroke = (new SolidColorBrush(this.mColor));
  98. this.drawingFibRetracement_1047.StrokeThickness = (0.5);
  99. this.drawingFibRetracement_1047.IsHitTestVisible = (false);
  100. this.drawingFibRetracement_1048 = new Path();
  101. this.drawingFibRetracement_1048.Stroke = (new SolidColorBrush(this.mColor));
  102. this.drawingFibRetracement_1048.StrokeThickness = (0.5);
  103. this.drawingFibRetracement_1049 = new PathGeometry();
  104. this.drawingFibRetracement_1048.Data = (this.drawingFibRetracement_1049);
  105. this.drawingFibRetracement_1048.IsHitTestVisible = (false);
  106. DoubleCollection doubleCollection = new DoubleCollection();
  107. doubleCollection.Add(10.0);
  108. doubleCollection.Add(10.0);
  109. this.drawingFibRetracement_1048.StrokeDashArray = (doubleCollection);
  110. this.MoveDrawingToNewLocations(aRect);
  111. try
  112. {
  113. List<TextBlock>.Enumerator enumerator2 = this.drawingFibRetracement_1050.GetEnumerator();
  114. while (enumerator2.MoveNext())
  115. {
  116. TextBlock current2 = enumerator2.Current;
  117. list.Add(current2);
  118. }
  119. }
  120. finally
  121. {
  122. //List<TextBlock>.Enumerator enumerator2;
  123. //enumerator2.Dispose();
  124. }
  125. list.Add(this.drawingFibRetracement_1046);
  126. list.Add(this.drawingFibRetracement_1047);
  127. list.Add(this.drawingFibRetracement_1048);
  128. return list;
  129. }
  130. public override string RootName
  131. {
  132. get { return "FibonacciRetracement"; }
  133. }
  134. public override string MenuDescription()
  135. {
  136. return LanguageManager.FindResource(LanguageConst.DrawingTool_Abbreviation_FibonacciRetracement);
  137. }
  138. public override string Abbreviation()
  139. {
  140. return "Fib Ret";
  141. }
  142. public override string Description()
  143. {
  144. return this.MenuDescription();
  145. }
  146. protected override void ColorChanged()
  147. {
  148. bool flag = this.drawingFibRetracement_1046 != null;
  149. if (flag)
  150. {
  151. this.drawingFibRetracement_1046.Stroke = new SolidColorBrush(this.mColor);
  152. this.drawingFibRetracement_1046.ExtensionStroke = new SolidColorBrush(this.mExtensionColor);
  153. }
  154. flag = (this.drawingFibRetracement_1050 != null);
  155. if (flag)
  156. {
  157. SolidColorBrush foreground = new SolidColorBrush(this.mColor);
  158. try
  159. {
  160. List<TextBlock>.Enumerator enumerator = this.drawingFibRetracement_1050.GetEnumerator();
  161. while (enumerator.MoveNext())
  162. {
  163. TextBlock current = enumerator.Current;
  164. current.Foreground = (foreground);
  165. }
  166. }
  167. finally
  168. {
  169. //List<TextBlock>.Enumerator enumerator;
  170. //enumerator.Dispose();
  171. }
  172. }
  173. flag = (this.drawingFibRetracement_1047 != null);
  174. if (flag)
  175. {
  176. this.drawingFibRetracement_1047.Stroke = (new SolidColorBrush(this.mColor));
  177. }
  178. flag = (this.drawingFibRetracement_1048 != null);
  179. if (flag)
  180. {
  181. this.drawingFibRetracement_1048.Stroke = (new SolidColorBrush(this.mColor));
  182. }
  183. }
  184. protected override void MoveDrawingToNewLocations(Rect aRect)
  185. {
  186. try
  187. {
  188. List<TextBlock>.Enumerator enumerator = this.drawingFibRetracement_1050.GetEnumerator();
  189. while (enumerator.MoveNext())
  190. {
  191. TextBlock current = enumerator.Current;
  192. current.Visibility = (Visibility)(1);
  193. }
  194. }
  195. finally
  196. {
  197. //List<TextBlock>.Enumerator enumerator;
  198. //enumerator.Dispose();
  199. }
  200. int num = 0;
  201. bool flag = this.mLastScale == null || this.mLastScale.GetmScaler() == null;
  202. if (!flag)
  203. {
  204. this.drawingFibRetracement_1049.Figures.Clear();
  205. checked
  206. {
  207. Point point = new Point((double)((int)Math.Round(this.mDrawP1.X)), (double)((int)Math.Round(this.mDrawP1.Y)));
  208. Point point2 = new Point((double)((int)Math.Round(this.mDrawP2.X)), (double)((int)Math.Round(this.mDrawP2.Y)));
  209. 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))));
  210. Size size = new Size(12.0, 12.0);
  211. flag = (this.drawingFibRetracement_1046 != null);
  212. if (flag)
  213. {
  214. this.drawingFibRetracement_1046.SetPosition(this.mDrawP1, this.mDrawP2, this.ExtendLeft, this.ExtendRight, aRect);
  215. }
  216. flag = (this.drawingFibRetracement_1047 != null);
  217. if (flag)
  218. {
  219. this.drawingFibRetracement_1047.X1 = (aRect.Left);
  220. this.drawingFibRetracement_1047.X2 = (aRect.Right);
  221. this.drawingFibRetracement_1047.Y1 = (this.mDrawP2.Y);
  222. this.drawingFibRetracement_1047.Y2 = (this.mDrawP2.Y);
  223. }
  224. }
  225. float num2 = this.P1Val - this.P2Val;
  226. try
  227. {
  228. List<DrawingFibBase.FibLevel>.Enumerator enumerator2 = this.FibLevels.GetEnumerator();
  229. while (enumerator2.MoveNext())
  230. {
  231. DrawingFibBase.FibLevel current2 = enumerator2.Current;
  232. flag = current2.IsOn;
  233. if (flag)
  234. {
  235. float num3 = num2 * current2.Value / 100f;
  236. num3 += this.P2Val;
  237. num3 = this.mLastScale.GetmScaler().PercentFromValue(num3);
  238. num3 = this.mLastScale.GetmScaler().YFromPercent(num3, aRect);
  239. flag = ((double)num3 >= aRect.Top && (double)num3 <= aRect.Bottom);
  240. checked
  241. {
  242. if (flag)
  243. {
  244. Point p = new Point(aRect.Left, (double)num3);
  245. Point p2 = new Point(aRect.Right, (double)num3);
  246. this.AddLine(this.drawingFibRetracement_1049, p, p2);
  247. flag = this.drawingFibRetracement_1051;
  248. if (flag)
  249. {
  250. TextBlock textBlock = this.drawingFibRetracement_1050[num];
  251. num++;
  252. textBlock.Text = (Strings.Format(current2.Value, "0.0"));
  253. textBlock.SetValue(Canvas.LeftProperty, 4.0);
  254. textBlock.SetValue(Canvas.TopProperty, (double)num3);
  255. textBlock.Visibility = (Visibility)(0);
  256. }
  257. }
  258. }
  259. }
  260. }
  261. }
  262. finally
  263. {
  264. //List<drawingFibBase.FibLevel>.Enumerator enumerator2;
  265. //enumerator2.Dispose();
  266. }
  267. }
  268. }
  269. protected void AddLine(PathGeometry geom, Point p1, Point p2)
  270. {
  271. PathFigure pathFigure = new PathFigure();
  272. geom.Figures.Add(pathFigure);
  273. LineSegment lineSegment = new LineSegment();
  274. pathFigure.Segments.Add(lineSegment);
  275. pathFigure.StartPoint = (p1);
  276. lineSegment.Point = (p2);
  277. }
  278. public override ImageSource Icon()
  279. {
  280. ImageSource result;
  281. try
  282. {
  283. result = ImageHelper.GetImage("FibRet.png");
  284. }
  285. catch (Exception expr_3A)
  286. {
  287. ProjectData.SetProjectError(expr_3A);
  288. result = null;
  289. ProjectData.ClearProjectError();
  290. }
  291. return result;
  292. }
  293. protected override bool CanExtendLeft()
  294. {
  295. return true;
  296. }
  297. protected override bool CanExtendRight()
  298. {
  299. return true;
  300. }
  301. protected override void AddFromXml(XElement xml)
  302. {
  303. base.AddFromXml(xml);
  304. bool flag = xml.Attribute("HideVals") != null;
  305. if (flag)
  306. {
  307. this.drawingFibRetracement_1051 = false;
  308. }
  309. }
  310. protected override void AddToXml(XElement xml, List<object> args)
  311. {
  312. base.AddToXml(xml, args);
  313. bool flag = !this.drawingFibRetracement_1051;
  314. if (flag)
  315. {
  316. xml.Add(new XAttribute("HideVals", "1"));
  317. }
  318. }
  319. public override List<ControlPair> AdditionalEditors()
  320. {
  321. List<ControlPair> list = base.AdditionalEditors();
  322. ControlPair controlPair = new ControlPair();
  323. BooleanEditor controlRight = new BooleanEditor(this, "ShowValues", "Show Values");
  324. controlPair.ControlRight = controlRight;
  325. list.Add(controlPair);
  326. return list;
  327. }
  328. }
  329. }