DrawingGannFann.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. using Microsoft.VisualBasic.CompilerServices;
  2. using MuchInfo.Chart.Data;
  3. using MuchInfo.Chart.Data.EnumTypes;
  4. using MuchInfo.Chart.Infrastructure.Helpers;
  5. using MuchInfo.Chart.Infrastructure.Utilities;
  6. using MuchInfo.Chart.WPF.Controls.Drawing;
  7. using MuchInfo.Chart.WPF.Controls.Editors;
  8. using MuchInfo.Chart.WPF.Helpers;
  9. using MuchInfo.Chart.WPF.Primitives.Interfaces;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Media;
  16. using System.Windows.Shapes;
  17. using System.Xml.Linq;
  18. namespace MuchInfo.Chart.WPF.Primitives.Drawing
  19. {
  20. public class DrawingGannFann : Drawing2PointBase
  21. {
  22. private Color drawingGannFann_1054;
  23. private List<Line> drawingGannFann_1055;
  24. private ExtendableLine drawingGannFann_1056;
  25. private int[] drawingGannFann_1057;
  26. public Color CenterColor
  27. {
  28. get
  29. {
  30. return this.drawingGannFann_1054;
  31. }
  32. set
  33. {
  34. bool flag = !value.Equals(this.drawingGannFann_1054);
  35. if (flag)
  36. {
  37. this.drawingGannFann_1054 = value;
  38. this.ColorChanged();
  39. this.PropertyChanged();
  40. }
  41. }
  42. }
  43. public DrawingGannFann()
  44. {
  45. this.drawingGannFann_1054 = Colors.White;
  46. this.drawingGannFann_1055 = new List<Line>();
  47. this.drawingGannFann_1057 = new int[]
  48. {
  49. 2,
  50. 3,
  51. 4,
  52. 8
  53. };
  54. }
  55. public override DrawingToolType ToolType()
  56. {
  57. return DrawingToolType.GannFann;
  58. }
  59. public override IDrawingTool Clone()
  60. {
  61. return new DrawingGannFann
  62. {
  63. mColor = Colors.Blue
  64. };
  65. }
  66. protected override List<FrameworkElement> GetDrawingPlots(Chart owner, ScaleLayer aScale, Rect aRect)
  67. {
  68. bool flag = this.drawingGannFann_1056 == null;
  69. if (flag)
  70. {
  71. this.drawingGannFann_1056 = new ExtendableLine(this, owner);
  72. this.drawingGannFann_1056.Stroke = new SolidColorBrush(this.drawingGannFann_1054);
  73. this.drawingGannFann_1056.StrokeThickness = 1.4;
  74. DoubleCollection doubleCollection = new DoubleCollection();
  75. doubleCollection.Add(10.0);
  76. doubleCollection.Add(10.0);
  77. this.drawingGannFann_1056.SetMainStrokeDash(doubleCollection);
  78. this.drawingGannFann_1056.ExtensionStroke = this.drawingGannFann_1056.Stroke;
  79. }
  80. flag = !ColorHelper.ColorIsContrasting(this.drawingGannFann_1054, owner.ChartBackgroundColor);
  81. if (flag)
  82. {
  83. this.drawingGannFann_1054 = ColorHelper.InverseColor(this.drawingGannFann_1054);
  84. }
  85. List<FrameworkElement> list = new List<FrameworkElement>();
  86. this.drawingGannFann_1055.Clear();
  87. int num = 0;
  88. checked
  89. {
  90. int arg_141_0;
  91. int num2;
  92. do
  93. {
  94. Line line = new Line();
  95. line.Stroke = (new SolidColorBrush(this.mColor));
  96. line.StrokeThickness = (1.4);
  97. this.drawingGannFann_1055.Add(line);
  98. list.Add(line);
  99. num++;
  100. arg_141_0 = num;
  101. num2 = 7;
  102. }
  103. while (arg_141_0 <= num2);
  104. this.MoveDrawingToNewLocations(aRect);
  105. list.Add(this.drawingGannFann_1056);
  106. return list;
  107. }
  108. }
  109. public override string RootName
  110. {
  111. get { return "DrawGannFan"; }
  112. }
  113. public override string MenuDescription()
  114. {
  115. return LanguageManager.FindResource(LanguageConst.DrawingTool_Abbreviation_GannFan);
  116. }
  117. public override string Abbreviation()
  118. {
  119. return "Gann";
  120. }
  121. public override string Description()
  122. {
  123. return this.MenuDescription();
  124. }
  125. public override List<ControlPair> GetPropertyEditors()
  126. {
  127. List<ControlPair> list = new List<ControlPair>();
  128. ControlPair controlPair = new ControlPair();
  129. TextBlock textBlock = new TextBlock();
  130. textBlock.Text = ("Fann Color");
  131. controlPair.ControlLeft = textBlock;
  132. ColorOpacityEditor controlRight = new ColorOpacityEditor(this, "Color", "", "");
  133. controlPair.ControlRight = controlRight;
  134. list.Add(controlPair);
  135. controlPair = new ControlPair();
  136. textBlock = new TextBlock();
  137. textBlock.Text = ("Center Line Color");
  138. controlPair.ControlLeft = textBlock;
  139. controlRight = new ColorOpacityEditor(this, "CenterColor", "", "");
  140. controlPair.ControlRight = controlRight;
  141. list.Add(controlPair);
  142. return list;
  143. }
  144. protected override void ColorChanged()
  145. {
  146. this.drawingGannFann_1056.Stroke = new SolidColorBrush(this.drawingGannFann_1054);
  147. try
  148. {
  149. List<Line>.Enumerator enumerator = this.drawingGannFann_1055.GetEnumerator();
  150. while (enumerator.MoveNext())
  151. {
  152. Line current = enumerator.Current;
  153. current.Stroke = (new SolidColorBrush(this.mColor));
  154. this.drawingGannFann_1056.ExtensionStroke = this.drawingGannFann_1056.Stroke;
  155. }
  156. }
  157. finally
  158. {
  159. //List<Line>.Enumerator enumerator;
  160. //enumerator.Dispose();
  161. }
  162. }
  163. protected override void MoveDrawingToNewLocations(Rect aRect)
  164. {
  165. Point point;
  166. Point point2;
  167. bool flag;
  168. checked
  169. {
  170. point = new Point((double)((int)Math.Round(this.mDrawP1.X)), (double)((int)Math.Round(this.mDrawP1.Y)));
  171. point2 = new Point((double)((int)Math.Round(this.mDrawP2.X)), (double)((int)Math.Round(this.mDrawP2.Y)));
  172. Point point3 = new Point((double)((int)Math.Round(
  173. unchecked
  174. (
  175. this.mDrawP2.X / 2.0 + this.mDrawP1.X / 2.0))),
  176. (double)((int)Math.Round(unchecked(this.mDrawP2.Y / 2.0 + this.mDrawP1.Y / 2.0))));
  177. Size size = new Size(12.0, 12.0);
  178. flag = (point.X != point2.X);
  179. }
  180. double num;
  181. if (flag)
  182. {
  183. num = Math.Atan2(point2.Y - point.Y, point2.X - point.X);
  184. num *= 57.295779513082323;
  185. }
  186. else
  187. {
  188. flag = (point.Y > point2.Y);
  189. if (flag)
  190. {
  191. num = 270.0;
  192. }
  193. else
  194. {
  195. num = 90.0;
  196. }
  197. }
  198. this.drawingGannFann_1056.SetPosition(this.mDrawP1, this.mDrawP2, this.mDrawP1.X > this.mDrawP2.X, this.mDrawP1.X < this.mDrawP2.X, aRect);
  199. int num2 = 0;
  200. int arg_1C9_0 = 0;
  201. checked
  202. {
  203. int num3 = Enumerable.Count<int>(this.drawingGannFann_1057) - 1;
  204. int num4 = arg_1C9_0;
  205. while (true)
  206. {
  207. int arg_405_0 = num4;
  208. int num5 = num3;
  209. if (arg_405_0 > num5)
  210. {
  211. break;
  212. }
  213. flag = (this.drawingGannFann_1057[num4] > 0);
  214. if (flag)
  215. {
  216. Point point4 = default(Point);
  217. float num6;
  218. float num7;
  219. num6 = (float)(aRect.Width + aRect.Height);
  220. num7 = (float)(Math.Atan2((double)this.drawingGannFann_1057[num4], 1.0) * 57.295779513082323);
  221. num7 = (float)((double)(num7 - 45f) + num);
  222. num7 = (float)((double)num7 * 3.1415926535897931 / 180.0);
  223. point4.X = ((double)((int)Math.Round(unchecked(point.X + (double)num6 * Math.Cos((double)num7)))));
  224. point4.Y = ((double)((int)Math.Round(unchecked(point.Y + (double)num6 * Math.Sin((double)num7)))));
  225. Point A = new Point();
  226. Point B = new Point();
  227. PointOfLineAtRectangleCalculator(ref A, ref B, point, point4, aRect);
  228. this.drawingGannFann_1055[num2].X1 = (A.X);
  229. this.drawingGannFann_1055[num2].Y1 = (A.Y);
  230. this.drawingGannFann_1055[num2].X2 = (B.X);
  231. this.drawingGannFann_1055[num2].Y2 = (B.Y);
  232. num2++;
  233. num7 = (float)(Math.Atan2(1.0, (double)this.drawingGannFann_1057[num4]) * 57.295779513082323);
  234. num7 = (float)((double)(num7 - 45f) + num);
  235. num7 = (float)((double)num7 * 3.1415926535897931 / 180.0);
  236. point4.X = ((double)((int)Math.Round(unchecked(point.X + (double)num6 * Math.Cos((double)num7)))));
  237. point4.Y = ((double)((int)Math.Round(unchecked(point.Y + (double)num6 * Math.Sin((double)num7)))));
  238. PointOfLineAtRectangleCalculator(ref A, ref B, point, point4, aRect);
  239. this.drawingGannFann_1055[num2].X1 = A.X;
  240. this.drawingGannFann_1055[num2].Y1 = A.Y;
  241. this.drawingGannFann_1055[num2].X2 = B.X;
  242. this.drawingGannFann_1055[num2].Y2 = B.Y;
  243. num2++;
  244. }
  245. num4++;
  246. }
  247. }
  248. }
  249. protected override void AddFromXml(XElement xml)
  250. {
  251. bool flag = xml.Attribute("CClr") != null;
  252. if (flag)
  253. {
  254. this.drawingGannFann_1054 = ColorHelper.ColorFromString(xml.Attribute("CClr").Value);
  255. }
  256. }
  257. protected override void AddToXml(XElement xml, List<object> args)
  258. {
  259. xml.Add(new XAttribute("CClr", this.drawingGannFann_1054.ToString()));
  260. }
  261. protected override void AddFromInfo(DrawingToolInfo info)
  262. {
  263. base.AddFromInfo(info);
  264. try
  265. {
  266. XElement xElement = XElement.Parse(info.XML);
  267. bool flag = xElement.Name == "Root";
  268. if (flag)
  269. {
  270. bool flag2 = xElement.Attribute("Color1") != null;
  271. if (flag2)
  272. {
  273. this.drawingGannFann_1054 = ColorHelper.ColorFromInt(int.Parse(xElement.Attribute("Color1").Value));
  274. }
  275. }
  276. }
  277. catch (Exception expr_A1)
  278. {
  279. ProjectData.SetProjectError(expr_A1);
  280. ProjectData.ClearProjectError();
  281. }
  282. }
  283. protected override void AddToInfo(DrawingToolInfo info)
  284. {
  285. base.AddToInfo(info);
  286. XElement xElement = new XElement("Root");
  287. xElement.Add(new XAttribute("Color1", ColorHelper.ColorToInt(this.drawingGannFann_1054)));
  288. info.XML = xElement.ToString();
  289. }
  290. public override ImageSource Icon()
  291. {
  292. ImageSource result;
  293. try
  294. {
  295. result = ImageHelper.GetImage("FibFan.png");
  296. }
  297. catch (Exception expr_3A)
  298. {
  299. ProjectData.SetProjectError(expr_3A);
  300. result = null;
  301. ProjectData.ClearProjectError();
  302. }
  303. return result;
  304. }
  305. protected override bool CanExtendLeft()
  306. {
  307. return false;
  308. }
  309. protected override bool CanExtendRight()
  310. {
  311. return false;
  312. }
  313. }
  314. }