private void SetAreaType(PlotElementInfoAbs plotElementInfo, AreaType areaType)
 {
     if (plotElementInfo != null)
     {
         plotElementInfo.AreaType = areaType;
     }
 }
        private RectangleF?DrawWaveSpecturum(Graphics graphics, WavePlotPara plotPara, IEnumerable <ChannelPlotData> plotDatas)
        {
            PlotElementInfoAbs wave = this._content;

            if (wave == null)
            {
                return(null);
            }

            //填充主波形背景
            if (wave.BackgroudColor != null)
            {
                graphics.FillRectangle(wave.BackgroudColor, wave.Area);
            }

            if (plotPara == null || plotDatas == null)
            {
                return(null);
            }

            double     sbto            = plotPara.SBTOMillisecond;      //显示区域起始时间
            double     seto            = plotPara.GetSETOMillisecond(); //显示区域结束时间
            RectangleF?wavSelectedArea = this.GetSelectedAreaBackground(wave.Area, plotPara, sbto, seto);

            if (wavSelectedArea.HasValue)
            {
                //填充主波形选中背景
                graphics.FillRectangle(this._seleactionAreaBrush, wavSelectedArea.Value);
            }

            //绘制波形图
            this.DrawWaveDb(graphics, wave, plotPara, plotDatas, false);

            return(wavSelectedArea);
        }
        /// <summary>
        /// 添加局部刷新区域[添加成功返回true,失败返回false]
        /// </summary>
        /// <param name="plotElementInfo">需要局部刷新的矩形区域</param>
        private void AddPartRefreshArea(PlotElementInfoAbs plotElementInfo)
        {
            if (plotElementInfo == null)
            {
                return;
            }

            this.AddPartRefreshArea(plotElementInfo.Area);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="wave"></param>
        /// <param name="plotPara"></param>
        /// <param name="pcmDatas"></param>
        /// <param name="dataType">true:GlobalViewData;alse:DrawData</param>
        private void DrawWave_A(Graphics graphics, PlotElementInfoAbs wave, WavePlotPara plotPara, IEnumerable <ChannelPlotData> pcmDatas, bool dataType)
        {
            PointF[] points;
            if (dataType)
            {
                points = new PointF[plotPara.GlobalViewPcmDataLength];
            }
            else
            {
                points = new PointF[plotPara.DrawPcmDataLength];
            }

            if (points.Length == 0)
            {
                return;
            }

            int   channeCount = pcmDatas.Count();
            float channelWaveAreaHeight = wave.Area.Height / channeCount;
            float channelWaveHalfHeight = channelWaveAreaHeight / 2;
            float separatorY = wave.Area.Y + channelWaveHalfHeight;
            float lx, y;
            bool  drawSeparator = false;

            short[] pcmData;
            float   xStep = this.CalXStep(points.Length);

            foreach (ChannelPlotData channelPlotData in pcmDatas)
            {
                if (drawSeparator)
                {
                    graphics.DrawLine(this._channelSeparatorPen, 0f, separatorY, wave.Area.Width, separatorY);
                }

                if (dataType)
                {
                    pcmData = channelPlotData.GlobalViewData;
                }
                else
                {
                    pcmData = channelPlotData.DrawData;
                }

                lx = 0f;
                for (int i = 0; i < points.Length && i < pcmData.Length; i++)
                {
                    y         = separatorY - ((float)pcmData[i] / short.MaxValue) * channelWaveHalfHeight;
                    points[i] = new PointF(lx, y);
                    lx        = lx + xStep;
                }

                graphics.DrawLines(wave.Pen, points);
                separatorY   += channelWaveAreaHeight;
                drawSeparator = true;
            }
        }
Exemple #5
0
        private bool Inner(Point point, PlotElementInfoAbs plotElementInfo)
        {
            if (plotElementInfo == null)
            {
                return(false);
            }

            if (point.Y <= plotElementInfo.Area.Bottom && point.Y >= plotElementInfo.Area.Top && point.X >= plotElementInfo.Area.Left && point.X <= plotElementInfo.Area.Right)
            {
                return(true);
            }

            return(false);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="wave"></param>
        /// <param name="plotPara"></param>
        /// <param name="pcmDatas"></param>
        /// <param name="dataType">true:GlobalViewData;alse:DrawData</param>
        private void DrawWaveDb(Graphics graphics, PlotElementInfoAbs wave, WavePlotPara plotPara, IEnumerable <ChannelPlotData> pcmDatas, bool dataType)
        {
            PointF[] points;
            if (dataType)
            {
                points = new PointF[plotPara.GlobalViewPcmDataLength];
            }
            else
            {
                points = new PointF[plotPara.DrawPcmDataLength];
            }

            if (points.Length == 0)
            {
                return;
            }

            int   channeCount = pcmDatas.Count();
            float channelWaveAreaHeight = wave.Area.Height / channeCount;
            float channelWaveHalfHeight = channelWaveAreaHeight / 2;
            float separatorY = wave.Area.Y + channelWaveHalfHeight;
            float lx, y;
            bool  drawSeparator = false;

            //float value;
            //float db;
            short[] pcmData;
            //bool negativePoint;
            float xStep = this.CalXStep(points.Length);

            ////const float DB_MAX = 10.397177190355384f;  // = Math.Log(short.MaxValue);
            //const float DB_MAX = 4.5154366811416988f;  // = Math.Log10(short.MaxValue);

            foreach (ChannelPlotData channelPlotData in pcmDatas)
            {
                if (drawSeparator)
                {
                    graphics.DrawLine(this._channelSeparatorPen, 0f, separatorY, wave.Area.Width, separatorY);
                }

                if (dataType)
                {
                    pcmData = channelPlotData.GlobalViewData;
                }
                else
                {
                    pcmData = channelPlotData.DrawData;
                }

                lx = 0f;
                //float minY = 0f, maxY = 0f;
                //float dbMin = 0f, dbMax = 0f;
                for (int i = 0; i < points.Length && i < pcmData.Length; i++)
                {
                    y = separatorY - ((float)pcmData[i] / short.MaxValue) * channelWaveHalfHeight;

                    //转分呗后画出的波形似乎不太对啊
                    //if (pcmData[i] == 0)
                    //{
                    //    y = separatorY;
                    //}
                    //else
                    //{
                    //    value = (float)pcmData[i];
                    //    if (value < 0)
                    //    {
                    //        negativePoint = true;
                    //        value = Math.Abs(value);
                    //    }
                    //    else
                    //    {
                    //        negativePoint = false;
                    //    }

                    //    //dB = 20 * log(A1 / A2)  => db = log(A)
                    //    //value = 20 * (float)(Math.Log10(value / short.MaxValue));
                    //    //db = (float)(Math.Log(value));
                    //    db = (float)(Math.Log10(value));

                    //    if (db < dbMin)
                    //    {
                    //        dbMin = db;
                    //    }

                    //    if (db > dbMax)
                    //    {
                    //        dbMax = db;
                    //    }


                    //    if (negativePoint)
                    //    {
                    //        y = separatorY + channelWaveHalfHeight * db / DB_MAX;
                    //    }
                    //    else
                    //    {
                    //        y = separatorY - channelWaveHalfHeight * db / DB_MAX;
                    //    }

                    //    if (y < minY)
                    //    {
                    //        minY = y;
                    //    }

                    //    if (y > maxY)
                    //    {
                    //        maxY = y;
                    //    }
                    //}

                    points[i] = new PointF(lx, y);
                    lx        = lx + xStep;
                }

                graphics.DrawLines(wave.Pen, points);

                separatorY   += channelWaveAreaHeight;
                drawSeparator = true;
            }
        }