DrawingEllipse.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. using Microsoft.VisualBasic;
  2. using Microsoft.VisualBasic.CompilerServices;
  3. using MuchInfo.Chart.Data;
  4. using MuchInfo.Chart.Data.EnumTypes;
  5. using MuchInfo.Chart.Infrastructure.Helpers;
  6. using MuchInfo.Chart.Infrastructure.Utilities;
  7. using MuchInfo.Chart.WPF.Controls.Drawing;
  8. using MuchInfo.Chart.WPF.Controls.Editors;
  9. using MuchInfo.Chart.WPF.Helpers;
  10. using MuchInfo.Chart.WPF.Primitives.Interfaces;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Runtime.CompilerServices;
  14. using System.Windows;
  15. using System.Windows.Controls;
  16. using System.Windows.Media;
  17. using System.Windows.Shapes;
  18. using System.Xml.Linq;
  19. namespace MuchInfo.Chart.WPF.Primitives.Drawing
  20. {
  21. public class DrawingEllipse : Drawing2PointBase
  22. {
  23. #region Fields
  24. private bool _doFill;
  25. private ExtendableLine _extendableLine;
  26. private Color _fillColor;
  27. private double _fillOpacity;
  28. private Ellipse _ellipse;
  29. #endregion
  30. #region Constructors
  31. public DrawingEllipse()
  32. {
  33. this._doFill = true;
  34. this._fillOpacity = 30;
  35. this._fillColor = Colors.Gray;
  36. }
  37. #endregion
  38. #region Properties
  39. #region Public Properties
  40. public Color FillColor
  41. {
  42. get
  43. {
  44. return this._fillColor;
  45. }
  46. set
  47. {
  48. if (_fillColor.Equals(value))
  49. {
  50. this._fillColor = value;
  51. this.ColorChanged();
  52. this.PropertyChanged();
  53. }
  54. }
  55. }
  56. public bool DoFill
  57. {
  58. get
  59. {
  60. return this._doFill;
  61. }
  62. set
  63. {
  64. bool flag = this._doFill != value;
  65. if (flag)
  66. {
  67. this._doFill = value;
  68. this.ColorChanged();
  69. this.PropertyChanged();
  70. }
  71. }
  72. }
  73. public double FillOpacity
  74. {
  75. get
  76. {
  77. return this._fillOpacity;
  78. }
  79. set
  80. {
  81. bool flag = this._fillOpacity.Equals(value);
  82. if (flag)
  83. {
  84. this._fillOpacity = value;
  85. this.ColorChanged();
  86. this.PropertyChanged();
  87. }
  88. }
  89. }
  90. public override string RootName
  91. {
  92. get { return "DrawEllipse"; }
  93. }
  94. #endregion
  95. #endregion
  96. #region Methods
  97. #region Public Methods
  98. #endregion
  99. public override string Abbreviation()
  100. {
  101. return "Ellipse";
  102. }
  103. public override List<ControlPair> AdditionalEditors()
  104. {
  105. var Rlt = new List<ControlPair>();
  106. Rlt = new List<ControlPair>()
  107. {
  108. new ControlPair()
  109. {
  110. ControlLeft = new TextBlock() {Text="Ellipse"},
  111. ControlRight = new ColorOpacityEditor(this, "FillColor", "FillOpacity", "DoFill")
  112. }
  113. };
  114. return Rlt;
  115. }
  116. public override IDrawingTool Clone()
  117. {
  118. return new DrawingEllipse
  119. {
  120. mColor = Colors.White
  121. };
  122. }
  123. public override string Description()
  124. {
  125. return this.MenuDescription();
  126. }
  127. public override ImageSource Icon()
  128. {
  129. ImageSource result;
  130. try
  131. {
  132. result = ImageHelper.GetImage("Ellipse.png");
  133. }
  134. catch (Exception expr_3A)
  135. {
  136. ProjectData.SetProjectError(expr_3A);
  137. result = null;
  138. ProjectData.ClearProjectError();
  139. }
  140. return result;
  141. }
  142. public override string MenuDescription()
  143. {
  144. return LanguageManager.FindResource(LanguageConst.DrawingTool_Abbreviation_Ellipse);
  145. }
  146. public override DrawingToolType ToolType()
  147. {
  148. return DrawingToolType.Ellipse;
  149. }
  150. #region Protected Methods
  151. protected override void AddFromInfo(DrawingToolInfo info)
  152. {
  153. base.AddFromInfo(info);
  154. try
  155. {
  156. XElement xElement = XElement.Parse(info.XML);
  157. bool flag = xElement.Name == "Root";
  158. if (flag)
  159. {
  160. bool flag2 = xElement.Attribute("Color1") != null;
  161. if (flag2)
  162. {
  163. this._fillColor = ColorHelper.ColorFromInt(int.Parse(xElement.Attribute("Color1").Value));
  164. }
  165. flag2 = (xElement.Attribute("IntValue1") != null);
  166. if (flag2)
  167. {
  168. this._doFill = (int.Parse(xElement.Attribute("IntValue1").Value) == 1);
  169. }
  170. flag2 = (xElement.Attribute("IntValue2") != null);
  171. if (flag2)
  172. {
  173. this._fillOpacity = double.Parse(xElement.Attribute("IntValue2").Value);
  174. }
  175. }
  176. }
  177. catch (Exception expr_155)
  178. {
  179. ProjectData.SetProjectError(expr_155);
  180. ProjectData.ClearProjectError();
  181. }
  182. }
  183. protected override void AddFromXml(XElement xml)
  184. {
  185. bool flag = xml.Attribute("Fil") != null;
  186. if (flag)
  187. {
  188. this._fillColor = ColorHelper.ColorFromString(xml.Attribute("Fil").Value);
  189. }
  190. flag = (xml.Attribute("DF") != null);
  191. if (flag)
  192. {
  193. this._doFill = bool.Parse(xml.Attribute("DF").Value);
  194. }
  195. flag = (xml.Attribute("FO") != null);
  196. if (flag)
  197. {
  198. this._fillOpacity = int.Parse(xml.Attribute("FO").Value);
  199. }
  200. }
  201. protected override void AddToInfo(DrawingToolInfo info)
  202. {
  203. base.AddToInfo(info);
  204. XElement xElement = new XElement("Root");
  205. xElement.Add(new XAttribute("Color1", ColorHelper.ColorToInt(this._fillColor).ToString()));
  206. xElement.Add(new XAttribute("IntValue1", RuntimeHelpers.GetObjectValue(Interaction.IIf(this._doFill, "1", "0"))));
  207. xElement.Add(new XAttribute("IntValue2", this._fillOpacity.ToString()));
  208. info.XML = xElement.ToString();
  209. }
  210. protected override void AddToXml(XElement xml, List<object> args)
  211. {
  212. xml.Add(new XAttribute("Fil", this._fillColor.ToString()));
  213. xml.Add(new XAttribute("DF", this._doFill.ToString()));
  214. xml.Add(new XAttribute("FO", this._fillOpacity.ToString()));
  215. }
  216. protected override bool CanExtendLeft()
  217. {
  218. return false;
  219. }
  220. protected override bool CanExtendRight()
  221. {
  222. return false;
  223. }
  224. protected override void ColorChanged()
  225. {
  226. bool flag = this._ellipse != null;
  227. checked
  228. {
  229. if (flag)
  230. {
  231. this._ellipse.Stroke = (new SolidColorBrush(this.mColor));
  232. flag = !this._doFill;
  233. if (flag)
  234. {
  235. this._ellipse.Fill = (null);
  236. }
  237. else
  238. {
  239. int num = (int)Math.Round(unchecked(2.55 * (double)this._fillOpacity));
  240. flag = (num < 0);
  241. if (flag)
  242. {
  243. num = 0;
  244. }
  245. flag = (num > 255);
  246. if (flag)
  247. {
  248. num = 255;
  249. }
  250. this._ellipse.Fill = (new SolidColorBrush(Color.FromArgb((byte)num, this._fillColor.R, this._fillColor.G, this._fillColor.B)));
  251. }
  252. }
  253. }
  254. }
  255. protected override List<FrameworkElement> GetDrawingPlots(Chart owner, ScaleLayer aScale, Rect aRect)
  256. {
  257. var Rlt = new List<FrameworkElement>();
  258. if (this._extendableLine == null)
  259. {
  260. this._extendableLine = new ExtendableLine(this, owner);
  261. this._extendableLine.Stroke = new SolidColorBrush(Colors.Transparent);
  262. }
  263. this._ellipse = new Ellipse()
  264. {
  265. StrokeThickness = 1.4,
  266. IsHitTestVisible = false,
  267. };
  268. //this._ellipse.SetValue(Canvas.ZIndexProperty,-100);
  269. this.MoveDrawingToNewLocations(aRect);
  270. this.ColorChanged();
  271. Rlt.Add(this._ellipse);
  272. Rlt.Add(this._extendableLine);
  273. return Rlt;
  274. }
  275. protected override void MoveDrawingToNewLocations(Rect aRect)
  276. {
  277. if (this._extendableLine != null)
  278. {
  279. this._extendableLine.SetPosition(this.mDrawP1, this.mDrawP2, false, false, aRect);
  280. }
  281. if (this._ellipse != null)
  282. {
  283. bool flag2 = this.mDrawP1.X < this.mDrawP2.X;
  284. if (flag2)
  285. {
  286. this._ellipse.SetValue(Canvas.LeftProperty, this.mDrawP1.X);
  287. this._ellipse.Width = (this.mDrawP2.X - this.mDrawP1.X);
  288. }
  289. else
  290. {
  291. this._ellipse.SetValue(Canvas.LeftProperty, this.mDrawP2.X);
  292. this._ellipse.Width = (this.mDrawP1.X - this.mDrawP2.X);
  293. }
  294. flag2 = (this.mDrawP1.Y < this.mDrawP2.Y);
  295. if (flag2)
  296. {
  297. this._ellipse.SetValue(Canvas.TopProperty, this.mDrawP1.Y);
  298. this._ellipse.Height = (this.mDrawP2.Y - this.mDrawP1.Y);
  299. }
  300. else
  301. {
  302. this._ellipse.SetValue(Canvas.TopProperty, this.mDrawP2.Y);
  303. this._ellipse.Height = (this.mDrawP1.Y - this.mDrawP2.Y);
  304. }
  305. }
  306. }
  307. #endregion
  308. #endregion
  309. }
  310. }