//绘制MARK点 internal static void Draw(Graphics g, Channels chnls, ChannelMark[] mrks, AixsVisibleArea ava, ChannelPictureArea cpa, Font mrkFont) { int k = 0; //扫描mrks中所有的点 for (int i = 0; i < mrks.Length; i++) { //第i个MARK点,可见,则绘制它 //并且根据不同的MarkType,绘制动作会有差异 if (mrks[i].showText) { if (mrks[i].markType == MarkType.mrkNormal) DrawMark(k, (i + 1), g, chnls, mrks[i], ava, cpa, mrkFont); else if (mrks[i].markType == MarkType.mrkPeak) DrawPeak(k, (i + 1), g, chnls, mrks[i], ava, cpa, mrkFont); else continue; //else if (mrks[i].markType == MarkType.mrkValley) // ; //递增可见MARK点的个数 k++; } else continue; } }
//在mrk.sequence[]中指定的那些channel中,搜索MARK点 //把找到的点,合并成一个文本,作为该MARK点文本 //绘制MARK点文本和MARK图形 private static void DrawMark( int mrkCount, int mrkOrder, Graphics g, Channels chnls, ChannelMark mrk, AixsVisibleArea ava, ChannelPictureArea cpa, Font mrkFont) { int i, j; SizeF szf; Channel chnl; string label = ""; bool bExists = false; PointF srcPoint = new PointF(float.MinValue, float.MinValue); //用于绘制MARK线时,定位坐标 PointF gphPoint = srcPoint; //计算MARK点的世界坐标,即mrk.value,由外部传入 MarkInfo[] mi = new MarkInfo[mrk.sequence.Length]; //在指定的channel中构造MARK文本 for (i = 0; i < mrk.sequence.Length; i++) { mi[i].iChannel = -1; mi[i].iOrder = mrkOrder; j = mrk.sequence[i]; chnl = chnls.ChannelOf(j); if (chnl == null) continue; srcPoint = Search2(chnl, ava, cpa, mrk.searchType, mrk.value); if (srcPoint.X > float.MinValue) { if (!bExists) { bExists = true; gphPoint = srcPoint; } } mi[i].fPoint = srcPoint; mi[i].iChannel = (j + 1); } //若找到MARK点 if ((mrk.showMarkShape) && (gphPoint.X > float.MinValue)) { //使用找的MARK,绘制其文本 if (GenMarkText != null) { label = GenMarkText(mi); szf = g.MeasureString(label, mrkFont); g.DrawString(label, mrkFont, new LinearGradientBrush(new RectangleF(0, 0, szf.Width, szf.Height), mrk.markColor, mrk.markColor, 0.0), new Point(cpa.rec.X, (int)(cpa.rec.Y + mrkCount * szf.Height + MARKMARGIN))); } //使用找的MARK,构造形状 Point[] p; RectangleF recf; //使用找到点的X坐标值来计算MARK点页面坐标在X轴方向的值,不使用mrk.value float x = (int)(cpa.rec.X + (gphPoint.X - ava.xBegin) * cpa.rec.Width / (ava.xEnd - ava.xBegin)); if (mrk.markShape == MarkShape.markPloygon) { p = new Point[7]; recf = MakeMarkPolygon(p, (int)x, cpa); } else { p = new Point[3]; int y = (int)(cpa.rec.Y + cpa.rec.Height - (gphPoint.Y - ava.yBegin) * cpa.rec.Height / (ava.yEnd - ava.yBegin)); recf = MakeMarkTriangle(p, new Point((int)x, y), cpa); } //绘制MARK形状 g.DrawPolygon(new Pen(mrk.markColor), p); //绘制MARK形状内的文本 szf = g.MeasureString(mrkOrder.ToString(), mrkFont); g.DrawString(mrkOrder.ToString(), mrkFont, new LinearGradientBrush(recf, mrk.markColor, mrk.markColor, 0.0), new PointF(recf.X + (recf.Width - szf.Width) / 2, recf.Y + (recf.Height - szf.Height) / 2) ); } }
//在mrk.sequence[]中指定的那些channel中,搜索Y值最大的点 //绘制PEAK点文本和PEAK图形 private static void DrawPeak( int mrkCount, int mrkOrder, Graphics g, Channels chnls, ChannelMark mrk, AixsVisibleArea ava, ChannelPictureArea cpa, Font mrkFont) { SizeF szf; Channel chnl; string label = ""; PointF p2 = new PointF(float.MinValue, float.MinValue); PointF srcPoint = p2; //在mrk.sequence指定的channel搜索PEAK点 int k = -1; for (int i = 0; i < mrk.sequence.Length; i++) { chnl = chnls.ChannelOf(mrk.sequence[i]); if (chnl != null) { p2 = SearchPeak(chnl); if (p2.Y > srcPoint.Y) { k = i; srcPoint = p2; } } } //找到PEAK点 if ((mrk.showMarkShape) && (srcPoint.X > float.MinValue)) { //对srcPoint的X坐标执行世界变换 int x = (int)(cpa.rec.X + (srcPoint.X - ava.xBegin) * cpa.rec.Width / (ava.xEnd - ava.xBegin)); MarkInfo[] mi = new MarkInfo[1]; mi[0].fPoint = srcPoint; mi[0].iChannel = (k + 1); mi[0].iOrder = mrkOrder; //构造并绘制PEAK文本 if (GenPeakText != null) { label = GenPeakText(mi); szf = g.MeasureString(label, mrkFont); g.DrawString(label, mrkFont, new LinearGradientBrush(new RectangleF(0, 0, szf.Width, szf.Height), mrk.markColor, mrk.markColor, 0.0), new Point(cpa.rec.X, (int)(cpa.rec.Y + mrkCount * szf.Height + MARKMARGIN))); } Point[] p; RectangleF recf; p = new Point[7]; recf = MakeMarkPolygon(p, x, cpa); //绘制PEAK形状 g.DrawPolygon(new Pen(mrk.markColor), p); //绘制PEAK形状内的文本 szf = g.MeasureString(mrkOrder.ToString(), mrkFont); g.DrawString(mrkOrder.ToString(), mrkFont, new LinearGradientBrush(recf, mrk.markColor, mrk.markColor, 0.0), new PointF(recf.X + (recf.Width - szf.Width) / 2, recf.Y + (recf.Height - szf.Height) / 2) ); } }
//语句依据次序执行,建立控件 internal PlotEx(XY2dPlotEx plot) { //保存控件的winform对象 this.plot = plot; //默认,启用采样,仅绘制坐标轴可见范围内的数据 Sampling = true; //设置控件内边距,默认10像素 innerMargin = 10; GridBackColor = Color.SkyBlue; AixsLineColor = Color.Black; //构造控件的标题对象 tt = new plotTitle(); //构造控件的X轴对象 xa = new XAixs(); //构造控件的Y轴对象 ya = new YAixs(); //构造控件的当前可见区域对象 aixvblArea = new AixsVisibleArea(xa.start, xa.stop, ya.start, ya.stop); //构造控件的绘图区域对象 chnlPicArea = new ChannelPictureArea(); //构造控件的边框控制对象 pltBorder = new PlotBorder(); //使用上述部件,绘制控件 RedrawInNewBitmap(); //构造数据对象,用于绘制曲线 chnls = new Channels(); //构造支持的MARK对象 marks = new ChannelMark[MARKCAPCITY]; for (int i = 0; i < marks.Length; i++) marks[i] = new ChannelMark(chnls.Length); }