CgImageForm.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using DevExpress.Charts.Native;
  2. using DevExpress.Map.Dashboard;
  3. using DevExpress.Map.Native;
  4. using DevExpress.XtraBars;
  5. using DevExpress.XtraCharts;
  6. using DevExpress.XtraEditors.Repository;
  7. using ExtensionsDev;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Data;
  12. using System.Drawing;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows;
  17. using System.Windows.Forms;
  18. using System.Windows.Media.Imaging;
  19. using System.Xml.Linq;
  20. using XdCxRhDW.Core;
  21. using XdCxRhDW.Core.Api;
  22. using static DevExpress.XtraEditors.Mask.Design.MaskSettingsForm.DesignInfo.MaskManagerInfo;
  23. using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
  24. using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolTip;
  25. namespace XdCxRhDW.App.CorTools
  26. {
  27. public partial class CgImageForm : DevExpress.XtraEditors.XtraForm
  28. {
  29. List<ImageResult> list;
  30. float maxY;
  31. public CgImageForm()
  32. {
  33. InitializeComponent();
  34. int w = (this.chartControl1.AnnotationRepository[0] as ImageAnnotation).Width;
  35. int h = (this.chartControl1.AnnotationRepository[0] as ImageAnnotation).Height;
  36. Bitmap bmp = new Bitmap(w, h);
  37. for (int x = 0; x < w; x++)
  38. {
  39. for (int y = 0; y < h; y++)
  40. {
  41. var rgbb = ColorRGB.GetSpecColor(x / 1d / w);
  42. int r = rgbb.R;
  43. int g = rgbb.G;
  44. int b = rgbb.B;
  45. Color c = Color.FromArgb(r, g, b);
  46. bmp.SetPixel(x, y, c);
  47. }
  48. }
  49. var bgColor = ColorRGB.GetSpecColor(0);
  50. chartControl1.BackColor = bgColor;
  51. (this.chartControl1.Diagram as XYDiagram).DefaultPane.BackColor = bgColor;
  52. (this.chartControl1.AnnotationRepository[0] as ImageAnnotation).Image.DXImage = bmp;
  53. (this.chartControl1.AnnotationRepository[1] as TextAnnotation).BackColor = bgColor;
  54. (this.chartControl1.AnnotationRepository[1] as TextAnnotation).TextColor = Color.White;
  55. (this.chartControl1.AnnotationRepository[2] as TextAnnotation).BackColor = bgColor;
  56. (this.chartControl1.AnnotationRepository[2] as TextAnnotation).TextColor = Color.White;
  57. (this.chartControl1.Diagram as XYDiagram).AxisX.Color = Color.White;
  58. (this.chartControl1.Diagram as XYDiagram).AxisX.Label.TextColor = Color.White;
  59. (this.chartControl1.Diagram as XYDiagram).AxisY.Color = Color.White;
  60. (this.chartControl1.Diagram as XYDiagram).AxisY.Label.TextColor = Color.White;
  61. this.chartControl1.Series[0].ToolTipEnabled = DevExpress.Utils.DefaultBoolean.True;
  62. (this.chartControl1.Series[0].View as PointSeriesView).PointMarkerOptions.Size = 12;//点的大小
  63. //ToolTipPointPattern可以参考以下网站说明
  64. //https://docs.devexpress.com/CoreLibraries/DevExpress.XtraCharts.SeriesBase.ToolTipPointPattern?utm_source=visualstudio&utm_medium=DXHelpAssistant&utm_campaign=onlinehelp
  65. this.chartControl1.Series[0].ToolTipPointPattern = "{A:f3}us\r\n{V:f3}Hz\r\n{}dB";
  66. }
  67. public CgImageForm(List<ImageResult> list)
  68. : this()
  69. {
  70. this.list = list;
  71. var maxX = (list[0].XMax - 1 + list[0].XFlag) * 1e6 / list[0].FsHz;
  72. var minX = (list[0].XFlag) * 1e6 / list[0].FsHz;
  73. maxY = list.Max(p => p.YValue) + 200;
  74. (this.chartControl1.AnnotationRepository[2] as TextAnnotation).Text = $"共{list.Count}个点";
  75. (this.chartControl1.Diagram as XYDiagram).AxisX.WholeRange.SetMinMaxValues(minX, maxX);
  76. (this.chartControl1.Diagram as XYDiagram).AxisX.VisualRange.SetMinMaxValues(minX, maxX);
  77. (this.chartControl1.Diagram as XYDiagram).AxisY.WholeRange.SetMinMaxValues(-maxY, maxY);
  78. (this.chartControl1.Diagram as XYDiagram).AxisY.VisualRange.SetMinMaxValues(-maxY, maxY);
  79. }
  80. private void Test_Load(object sender, EventArgs e)
  81. {
  82. chartControl1.QueryCursor += ChartControl1_QueryCursor;
  83. chartControl1.Zoom += ChartControl1_Zoom;
  84. foreach (var item in list)
  85. {
  86. double xValue = (item.XValue + item.XFlag) * 1e6 / item.FsHz;//us
  87. this.chartControl1.Series[0].Points.Add(new SeriesPoint()
  88. {
  89. Argument = xValue.ToString(),
  90. Values = new double[1] { item.YValue },
  91. Color = item.GetColor(),
  92. Tag = item.Snr.ToString("f1"),
  93. });
  94. }
  95. }
  96. private void ChartControl1_QueryCursor(object sender, QueryCursorEventArgs e)
  97. {
  98. e.Cursor = Cursors.Default;
  99. }
  100. private void ChartControl1_Zoom(object sender, ChartZoomEventArgs e)
  101. {
  102. if ((double)e.NewYRange.MinValue < -maxY || (double)e.NewYRange.Max > maxY)
  103. {
  104. (this.chartControl1.Diagram as XYDiagram).AxisY.WholeRange.SetMinMaxValues(-maxY, maxY);
  105. (this.chartControl1.Diagram as XYDiagram).AxisY.VisualRange.SetMinMaxValues(-maxY, maxY);
  106. }
  107. else
  108. {
  109. if (e.Type == ChartZoomEventType.ZoomOut)
  110. {
  111. (this.chartControl1.Diagram as XYDiagram).AxisY.WholeRange.SetMinMaxValues((double)e.NewYRange.MinValue - 10, (double)e.NewYRange.MaxValue + 10);
  112. (this.chartControl1.Diagram as XYDiagram).AxisY.VisualRange.SetMinMaxValues((double)e.NewYRange.MinValue - 10, (double)e.NewYRange.MaxValue + 10);
  113. }
  114. else
  115. {
  116. if ((double)e.NewYRange.MaxValue - (double)e.NewYRange.MinValue < 40)
  117. {
  118. //(this.chartControl1.Diagram as XYDiagram).AxisY.WholeRange.SetMinMaxValues(e.NewYRange.MinValue, e.NewYRange.MaxValue);
  119. (this.chartControl1.Diagram as XYDiagram).AxisY.VisualRange.SetMinMaxValues(e.NewYRange.MinValue, e.NewYRange.MaxValue);
  120. }
  121. }
  122. }
  123. }
  124. }
  125. }