PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/NerdSharp.Net_Studio/NerdSharp_UberNet/Science/Comp_Sci/StudioComponents/Widgets/OtherControls/ArcReadout.xaml.cs

https://bitbucket.org/pastageek/scide-cad-scilife
C# | 283 lines | 232 code | 32 blank | 19 comment | 13 complexity | c1285cc00a5456aefbb1c3307db47e84 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using T = NerdSharp.Net_Studio.NerdSharp_UberNet.Science.Math.Utils.Trigonometry;
  15. using M = System.Math;
  16. using Graph = NerdSharp.Net_Studio.NerdSharp_UberNet.Science.Math.TypeLibrary.Graphs_ChartsWidgets.Utils;
  17. namespace NerdSharp.Net_Studio.NerdSharp_UberNet.Science.Comp_Sci.StudioComponents.Widgets.OtherControls
  18. {
  19. /// <summary>
  20. /// Interaction logic for ArcReadout.xaml
  21. /// </summary>
  22. public partial class ArcReadout : UserControl
  23. {
  24. public ArcReadout()
  25. {
  26. InitializeComponent();
  27. }
  28. public enum ArcType { Ellipse, Arc }
  29. private ArcType renderType = ArcType.Ellipse;
  30. public ArcType RenderType
  31. {
  32. get { return renderType; }
  33. set
  34. {
  35. renderType = value;
  36. Render();
  37. }
  38. }
  39. private double width = 50;
  40. public double Width1
  41. {
  42. get { return width; }
  43. set
  44. {
  45. width = value;
  46. mainGrid.Width = value;
  47. this.width = value;
  48. Render();
  49. }
  50. }
  51. private double height = 50;
  52. public double Height1
  53. {
  54. get { return height; }
  55. set
  56. {
  57. height = value;
  58. mainGrid.Height = value;
  59. this.height = value;
  60. Render();
  61. }
  62. }
  63. private Brush brush = new RadialGradientBrush(Colors.BlueViolet, Colors.CadetBlue);
  64. public Brush Brush
  65. {
  66. get { return brush; }
  67. set
  68. {
  69. brush = value;
  70. if (backgroundObj != null)
  71. {
  72. backgroundObj.Fill = brush;
  73. }
  74. }
  75. }
  76. public Brush BackGroundBrush
  77. {
  78. get { return mainGrid.Background; }
  79. set { mainGrid.Background = value; }
  80. }
  81. public enum Marks { Numbers, TickMarks }
  82. private int AmountOfMainMarks = 12;
  83. private int fontSize = 10;
  84. private double startTheta = 270;
  85. private List<Line> lines = null;
  86. public List<Line> Lines
  87. {
  88. get { return lines; }
  89. set
  90. {
  91. lines = value;
  92. RenderLines();
  93. }
  94. }
  95. private Shape backgroundObj = null;
  96. private List<Brush> SegmentedBrushes = null;
  97. public List<Brush> SegmentedBrushes1
  98. {
  99. get { return SegmentedBrushes; }
  100. set { SegmentedBrushes = value; }
  101. }
  102. private void Render()
  103. {
  104. mainGrid.Children.Clear();
  105. mainGrid.Width = this.width;
  106. mainGrid.Height = this.height;
  107. if (renderType == ArcType.Arc)
  108. {
  109. //creates all the objects need to render the arc
  110. Path path = new Path();
  111. backgroundObj = path;
  112. //main arcSegement
  113. ArcSegment meterArc = new ArcSegment();
  114. PathGeometry arcGeom = new PathGeometry();
  115. PathFigure arcPathFigure = new PathFigure();
  116. //extrasegments
  117. ArcSegment meterArc1 = new ArcSegment();
  118. LineSegment lineSeg0 = new LineSegment();
  119. LineSegment lineSeg1 = new LineSegment();
  120. //adds parts together
  121. arcGeom.Figures.Add(arcPathFigure);
  122. path.Data = arcGeom;
  123. //sets properties
  124. path.Stroke = new SolidColorBrush(Colors.Black);
  125. path.StrokeThickness = 1.5;
  126. path.Fill = brush;
  127. path.StrokeThickness = 2;
  128. arcPathFigure.IsFilled = true;
  129. arcPathFigure.IsFilled = true;
  130. arcPathFigure.StartPoint = new Point(0, this.Height1/2);
  131. meterArc.Point = new Point(this.Width1, this.Height1 / 2);
  132. meterArc.RotationAngle = 20;
  133. meterArc.Size = new Size(20, 20);
  134. meterArc.SweepDirection = SweepDirection.Clockwise;
  135. meterArc.IsSmoothJoin = true;
  136. meterArc.IsStroked = true;
  137. arcPathFigure.Segments.Add(meterArc);
  138. //set properties of others
  139. lineSeg0.Point = new Point(meterArc.Point.X - 5, meterArc.Point.Y + 8);
  140. arcPathFigure.Segments.Add(lineSeg0);
  141. meterArc1.Point = new Point(5, (this.Height1 / 2) + 5);
  142. meterArc1.Size = meterArc.Size;
  143. meterArc1.RotationAngle = 20;
  144. meterArc1.SweepDirection = SweepDirection.Counterclockwise;
  145. meterArc1.IsStroked = true;
  146. meterArc1.IsStroked = true;
  147. arcPathFigure.Segments.Add(meterArc1);
  148. lineSeg1.Point = new Point(arcPathFigure.StartPoint.X, arcPathFigure.StartPoint.Y);
  149. arcPathFigure.Segments.Add(lineSeg1);
  150. mainGrid.Children.Add(path);
  151. //renders the arcSegemted in Color
  152. if (SegmentedBrushes != null)
  153. {
  154. Point previousPoint = new Point(arcPathFigure.StartPoint.X, arcPathFigure.StartPoint.Y);
  155. for (int i = 0; i < SegmentedBrushes.Count; i++)
  156. {
  157. Path colorSegmentPath = new Path();
  158. colorSegmentPath.Fill = SegmentedBrushes[i];
  159. mainGrid.Children.Add(colorSegmentPath);
  160. }
  161. }
  162. RenderTickMarks();
  163. }
  164. else if (renderType == ArcType.Ellipse)
  165. {
  166. Ellipse elip = new Ellipse();
  167. this.backgroundObj = elip;
  168. elip.Stroke = new SolidColorBrush(Colors.Black);
  169. elip.StrokeThickness = 1;
  170. elip.Width = this.width;
  171. elip.Height = this.height;
  172. elip.Fill = this.brush;
  173. mainGrid.Children.Add(elip);
  174. RenderNumbers(elip);
  175. }
  176. }
  177. private void ReSizeControl()
  178. {
  179. }
  180. private Thickness[] RenderMarks(double theta, double radius)
  181. {
  182. List<Thickness> thicknesses = new List<Thickness>();
  183. return thicknesses.ToArray();
  184. }
  185. private void RenderTickMarks()
  186. {
  187. double theta = 180;
  188. double radius = this.mainGrid.Height / 2;
  189. for (int i = 0; i < AmountOfMainMarks; i++)
  190. {
  191. theta += theta / AmountOfMainMarks;
  192. Line einLine = new Line();
  193. einLine.Stroke = new SolidColorBrush(Colors.Orange);
  194. einLine.StrokeThickness = 2;
  195. double x = T.X(theta, radius);
  196. double y = T.Y(theta, radius);
  197. Point startPoint =
  198. Graph.FromGraphToScreen(Width1, Height1, new Point(x, y));
  199. einLine.X1 = startPoint.X;
  200. einLine.Y1 = startPoint.Y;
  201. einLine.X2 = einLine.X1;
  202. einLine.Y2 = einLine.Y2 + 5;
  203. mainGrid.Children.Add(einLine);
  204. }
  205. }
  206. private void RenderLines()
  207. {
  208. if (this.backgroundObj is Ellipse)
  209. {
  210. Ellipse elip = (Ellipse)backgroundObj;
  211. foreach (Line item in lines)
  212. {
  213. mainGrid.Children.Add(item);
  214. }
  215. }
  216. }
  217. private void RenderNumbers(Ellipse element)
  218. {
  219. //renders the numbers
  220. double angleDivision = 360 / 12;
  221. double theta = startTheta;
  222. double radius = (element.Width / 2) - 15;
  223. //debug
  224. string debug = "";
  225. for (int i = 0; i < AmountOfMainMarks; i++)
  226. {
  227. //rounds the numbers for numeric saftey
  228. theta += angleDivision;
  229. Thickness einThickness = new Thickness();
  230. //gets positions in terms of a four quadrant graph
  231. double x = T.X(theta, radius);
  232. double y = T.Y(theta, radius);
  233. //conversion from stardard grpahing points
  234. Point labelPoint = Graph.FromGraphToScreen(element.ActualWidth,
  235. element.ActualHeight, new Point(x, y));
  236. einThickness.Left = labelPoint.X + (element.Width / 3);
  237. einThickness.Top = labelPoint.Y + (element.Height / 3);
  238. //used to bring points into the clock
  239. //debug += x.ToString() + "," + y.ToString() + " ; ";
  240. Label hour = new Label();
  241. hour.Margin = einThickness;
  242. hour.FontSize = this.fontSize;
  243. hour.Foreground = new SolidColorBrush(Colors.Black);
  244. hour.Content = (i + 1).ToString();
  245. mainGrid.Children.Add(hour);
  246. }
  247. //debug
  248. //MessageBox.Show(debug);
  249. }
  250. }
  251. }