CgImageForm.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. public CgImageForm()
  31. {
  32. InitializeComponent();
  33. int w = (this.chartControl1.AnnotationRepository[0] as ImageAnnotation).Width;
  34. int h = (this.chartControl1.AnnotationRepository[0] as ImageAnnotation).Height;
  35. Bitmap bmp = new Bitmap(w, h);
  36. for (int x = 0; x < w; x++)
  37. {
  38. for (int y = 0; y < h; y++)
  39. {
  40. var rgbb = ColorRGB.GetSpecColor(x / 1d / w);
  41. int r = rgbb.R;
  42. int g = rgbb.G;
  43. int b = rgbb.B;
  44. Color c = Color.FromArgb(r, g, b);
  45. bmp.SetPixel(x, y, c);
  46. }
  47. }
  48. var bgColor = ColorRGB.GetSpecColor(0);
  49. chartControl1.BackColor = bgColor;
  50. (this.chartControl1.Diagram as XYDiagram).DefaultPane.BackColor = bgColor;
  51. (this.chartControl1.AnnotationRepository[0] as ImageAnnotation).Image.DXImage = bmp;
  52. (this.chartControl1.AnnotationRepository[1] as TextAnnotation).BackColor = bgColor;
  53. (this.chartControl1.AnnotationRepository[1] as TextAnnotation).TextColor = Color.White;
  54. (this.chartControl1.AnnotationRepository[2] as TextAnnotation).BackColor = bgColor;
  55. (this.chartControl1.AnnotationRepository[2] as TextAnnotation).TextColor = Color.White;
  56. (this.chartControl1.Diagram as XYDiagram).AxisX.Color = Color.White;
  57. (this.chartControl1.Diagram as XYDiagram).AxisX.Label.TextColor = Color.White;
  58. (this.chartControl1.Diagram as XYDiagram).AxisY.Color = Color.White;
  59. (this.chartControl1.Diagram as XYDiagram).AxisY.Label.TextColor = Color.White;
  60. this.chartControl1.Series[0].ToolTipEnabled = DevExpress.Utils.DefaultBoolean.True;
  61. (this.chartControl1.Series[0].View as PointSeriesView).PointMarkerOptions.Size = 12;//点的大小
  62. //ToolTipPointPattern可以参考以下网站说明
  63. //https://docs.devexpress.com/CoreLibraries/DevExpress.XtraCharts.SeriesBase.ToolTipPointPattern?utm_source=visualstudio&utm_medium=DXHelpAssistant&utm_campaign=onlinehelp
  64. this.chartControl1.Series[0].ToolTipPointPattern = "{A:f3}us\r\n{V:f3}Hz\r\n{}dB";
  65. }
  66. public CgImageForm(List<ImageResult> list)
  67. : this()
  68. {
  69. this.list = list;
  70. var maxX = (list[0].XMax - 1 + list[0].XFlag) * 1e6 / list[0].FsHz;
  71. var minX = (list[0].XFlag) * 1e6 / list[0].FsHz;
  72. var maxY = list.Max(p => p.YValue) + 100;
  73. (this.chartControl1.AnnotationRepository[2] as TextAnnotation).Text = $"共{list.Count}个点";
  74. (this.chartControl1.Diagram as XYDiagram).AxisX.WholeRange.SetMinMaxValues(minX, maxX);
  75. (this.chartControl1.Diagram as XYDiagram).AxisX.VisualRange.SetMinMaxValues(minX, maxX);
  76. (this.chartControl1.Diagram as XYDiagram).AxisY.WholeRange.SetMinMaxValues(-maxY, maxY);
  77. (this.chartControl1.Diagram as XYDiagram).AxisY.VisualRange.SetMinMaxValues(-maxY, maxY);
  78. }
  79. private void Test_Load(object sender, EventArgs e)
  80. {
  81. chartControl1.QueryCursor += ChartControl1_QueryCursor;
  82. foreach (var item in list)
  83. {
  84. double xValue = (item.XValue + item.XFlag) * 1e6 / item.FsHz;//us
  85. this.chartControl1.Series[0].Points.Add(new SeriesPoint()
  86. {
  87. Argument = xValue.ToString(),
  88. Values = new double[1] { item.YValue },
  89. Color = item.GetColor(),
  90. Tag = item.Snr.ToString("f1"),
  91. });
  92. }
  93. }
  94. private void ChartControl1_QueryCursor(object sender, QueryCursorEventArgs e)
  95. {
  96. e.Cursor = Cursors.Default;
  97. }
  98. }
  99. }