예제 #1
0
        /// <summary>
        /// Построение геометрической информации
        /// </summary>
        /// <param name="srcGraphic">исходный двумерный график</param>
        /// <param name="rect">область вывода на экране</param>
        /// <returns>геометрическиая информация</returns>
        public static PathGeometry ConstructGeometry(GeometryGraphic srcGraphic, Rect rect, TimeSpan leftTimeBorder, TimeSpan rightTimeBorder)
        {
            PathGeometry PtColl = new PathGeometry();

            if (srcGraphic.Points.Count == 0)
            {
                return(PtColl);
            }
            GeometryPoint prevPt = srcGraphic.Points[0];

            if ((prevPt.SourcePoint.Time.CompareTo(leftTimeBorder) >= 0) && (prevPt.SourcePoint.Time.CompareTo(rightTimeBorder) <= 0))
            {
                PtColl.AddGeometry(new EllipseGeometry(prevPt.Position, 1, 1));
            }
            foreach (GeometryPoint item in srcGraphic.Points)
            {
                if (prevPt.Y != item.Y)
                {
                    if ((prevPt.SourcePoint.Time.CompareTo(leftTimeBorder) >= 0) && (prevPt.SourcePoint.Time.CompareTo(rightTimeBorder) <= 0))
                    {
                        PtColl.AddGeometry(new EllipseGeometry(item.Position, 1, 1));
                    }
                    prevPt = item;
                }
            }
            return(PtColl);
        }
예제 #2
0
        /// <summary>
        /// Аппроксимация двумерного графика
        /// (необходимо, когда точки расположены очень близко друг к другу, т.е. человеческий глаз не отличит (5 пикселей))
        /// (это даёт увеличение производительности и сбережение памяти)
        /// </summary>
        /// <param name="geometryGraphic">исходный двумерный график</param>
        /// <param name="isAppearApproximation">флаг-признак наличия аппроксимации</param>
        /// /// <param name="accuracyApproximationPx">Коэффициент применения аппроксимации в px</param>
        /// <returns>аппроксимированный двумерный график</returns>
        public static GeometryGraphic Approximation(GeometryGraphic geometryGraphic, ref bool isAppearApproximation, double accuracyApproximationPx)
        {
            isAppearApproximation = false;
            GeometryGraphic resultGeometryGraphic = new GeometryGraphic();

            if (geometryGraphic.Points.Count < 30)
            {
                return(geometryGraphic);
            }
            resultGeometryGraphic.Points.Add(geometryGraphic.Points[0]);
            resultGeometryGraphic.Points.Add(geometryGraphic.Points[1]);
            GeometryPoint prevPt      = geometryGraphic.Points[1];
            int           countPoints = geometryGraphic.Points.Count;

            for (int i = 2; i < countPoints - 1; i++)
            {
                if ((geometryGraphic.Points[i].X - prevPt.X) < accuracyApproximationPx)
                {
                    isAppearApproximation = true;
                    continue;
                }
                else
                {
                    resultGeometryGraphic.Points.Add(geometryGraphic.Points[i]);
                    prevPt = geometryGraphic.Points[i];
                }
            }
            resultGeometryGraphic.Points.Add(geometryGraphic.Points[countPoints - 1]);
            return(resultGeometryGraphic);
        }
예제 #3
0
        /// <summary>
        /// построение видимых участков графика и определение наличия аппроксимации
        /// </summary>
        protected void UpdateData()
        {
            CommonData.RenderedGraphics.Clear();
            IsAppearApproximation = false;
            CalculationHeightGraphic();
            Point locGraphic = this.Field.Location;

            foreach (SourceGraphic srcGraphic in CommonData.SourceGraphics)
            {
                bool            flagApproximation = false;
                GeometryGraphic renderedGraphic   = GeometryGraphicConstructor.Construct(srcGraphic,
                                                                                         new Rect(locGraphic, new Size(this.Field.Width, HeightGraphic)), CommonData.TimeInPoint,
                                                                                         CommonData.LeftTime, CommonData.RightTime);
                GeometryGraphic renderedGraphicApproximated = GeometryGraphicConstructor.Approximation(renderedGraphic, ref flagApproximation, 5);
                //GeometryGraphic renderedGraphicApproximated = GeometryGraphicConstructor.ConstructWithApproximation(srcGraphic,
                //    new Rect(locGraphic, new Size(this.Field.Width, HeightGraphic)), CommonData.TimeInPoint,
                //    CommonData.LeftTime, CommonData.RightTime, 5, out flagApproximation);
                if (flagApproximation)
                {
                    IsAppearApproximation = true;
                }
                CommonData.RenderedGraphics.Add(renderedGraphicApproximated);
                locGraphic.Y += (HeightGraphic + HeightBetweenGraphics);
            }
        }
예제 #4
0
        /// <summary>
        /// Отрисовка графика
        /// </summary>
        /// <param name="dc">контекст рисования</param>
        /// <param name="renderedGraphic"></param>
        protected void DrawGraphic(DrawingContext dc, GeometryGraphic renderedGraphic, Brush lineBrush, Rect rect)
        {
            PathGeometry graphic;

            graphic = GeometryLinesConstructor.ConstructGeometry(renderedGraphic, rect);
            dc.DrawGeometry(null, new Pen(lineBrush, 0.5), graphic);
            graphic = GeometryPointsConstructor.ConstructGeometry(renderedGraphic, rect, CommonData.LeftTime, CommonData.RightTime);
            dc.DrawGeometry(null, new Pen(Brushes.BlueViolet, 1.0), graphic);
            DrawValuePoint(dc, renderedGraphic);
        }
예제 #5
0
 /// <summary>
 /// Рисование значения в точке
 /// </summary>
 /// <param name="dc">контекст рисования</param>
 /// <param name="renderedGraphic"></param>
 protected void DrawValuePoint(DrawingContext dc, GeometryGraphic renderedGraphic)
 {
     {
         dc.PushOpacity(0.5);
         Rect valueRect = new Rect(new Point(renderedGraphic.Points[0].Position.X + 2, renderedGraphic.Points[0].Position.Y + 2),
                                   new Size(renderedGraphic.Points[0].SourcePoint.Value.ToString().Length * 5 + 10, 13));
         dc.DrawRoundedRectangle(Brushes.WhiteSmoke, new Pen(Brushes.White, 1), valueRect, valueRect.Height / 5, valueRect.Height / 5);
         ToolFunctions.DrawAutoTxt(dc, "0x" + renderedGraphic.Points[0].SourcePoint.Value.ToString("X"), valueRect, Brushes.Brown, TextAlignment.Center, 1.95);
         //
         valueRect = new Rect(new Point(renderedGraphic.Points.Last().Position.X + 2, renderedGraphic.Points.Last().Position.Y + 2),
                              new Size(renderedGraphic.Points.Last().SourcePoint.Value.ToString().Length * 5 + 10, 13));
         dc.DrawRoundedRectangle(Brushes.WhiteSmoke, new Pen(Brushes.White, 1), valueRect, valueRect.Height / 5, valueRect.Height / 5);
         ToolFunctions.DrawAutoTxt(dc, "0x" + renderedGraphic.Points.Last().SourcePoint.Value.ToString("X"), valueRect, Brushes.Brown, TextAlignment.Center, 1.95);
         dc.Pop();
     }
 }
예제 #6
0
 /// <summary>
 /// построение видимых участков графика и определение наличия аппроксимации
 /// </summary>
 protected void UpdateData()
 {
     CommonData.RenderedGraphics.Clear();
     IsAppearApproximation = false;
     foreach (SourceGraphic srcGraphic in CommonData.SourceGraphics)
     {
         bool            flagApproximation = false;
         GeometryGraphic renderedGraphic   = GeometryGraphicConstructor.Construct(srcGraphic, this.Field, CommonData.TimeInPoint,
                                                                                  CommonData.LeftTime, CommonData.RightTime);
         GeometryGraphic renderedGraphicApproximated = GeometryGraphicConstructor.Approximation(renderedGraphic, ref flagApproximation, 5);
         if (flagApproximation)
         {
             IsAppearApproximation = true;
         }
         CommonData.RenderedGraphics.Add(renderedGraphicApproximated);
     }
 }
예제 #7
0
        /// <summary>
        /// Построение геометрической информации
        /// </summary>
        /// <param name="srcGraphic">исходный двумерный график</param>
        /// <param name="rect">область вывода на экране</param>
        /// <returns>геометрическая информация</returns>
        public static PathGeometry ConstructGeometry(GeometryGraphic srcGraphic, Rect rect, TimeSpan leftTimeBorder, TimeSpan rightTimeBorder)
        {
            PathGeometry PtColl = new PathGeometry();

            if (srcGraphic.Points.Count == 0)
            {
                return(PtColl);
            }
            foreach (GeometryPoint item in srcGraphic.Points)
            {
                if ((item.SourcePoint.Time.CompareTo(leftTimeBorder) < 0) || (item.SourcePoint.Time.CompareTo(rightTimeBorder) > 0))
                {
                    continue;
                }
                PtColl.AddGeometry(new EllipseGeometry(item.Position, 1, 1));
            }
            return(PtColl);
        }
        /// <summary>
        /// Построение геометрической информации
        /// </summary>
        /// <param name="srcGraphic">исходный двумерный график</param>
        /// <param name="rect">область вывода на экране</param>
        /// <returns>геометрическая информация</returns>
        public static PathGeometry ConstructGeometry(GeometryGraphic srcGraphic, Rect rect)
        {
            PathGeometry LineColl    = new PathGeometry();
            int          countPoints = srcGraphic.Points.Count;

            if (countPoints < 2)
            {
                return(LineColl);
            }
            for (int i = 0; i < countPoints - 1; i++)
            {
                LineGeometry line = new LineGeometry(srcGraphic.Points[i].Position, new Point(srcGraphic.Points[i + 1].X, srcGraphic.Points[i].Y));
                LineColl.AddGeometry(line);
                if (!srcGraphic.Points[i].Y.Equals(srcGraphic.Points[i + 1].Y))
                {
                    LineGeometry lineV = new LineGeometry(new Point(srcGraphic.Points[i + 1].X, srcGraphic.Points[i].Y), new Point(srcGraphic.Points[i + 1].X, srcGraphic.Points[i + 1].Y));
                    LineColl.AddGeometry(lineV);
                }
            }
            return(LineColl);
        }
예제 #9
0
        /// <summary>
        /// Рисование значения в точке
        /// </summary>
        /// <param name="dc">контекст рисования</param>
        /// <param name="renderedGraphic"></param>
        protected void DrawValuePoint(DrawingContext dc, GeometryGraphic renderedGraphic)
        {
            int  countPoints          = renderedGraphic.Points.Count;
            bool IsTextUnderPrevPoint = true;

            for (int i = 0; i < countPoints - 1; i++)
            {
                Size cellSize = new Size(renderedGraphic.Points[i].SourcePoint.Value.ToString().Length * 5 + 10, 13);
                IsTextUnderPrevPoint = ToolFunctions.DrawTxtValue(dc, renderedGraphic.Points[i].Position, renderedGraphic.Points[i + 1].Position,
                                                                  renderedGraphic.Points[i].SourcePoint.Value, IsTextUnderPrevPoint, cellSize);
            }
            //Last point
            if (renderedGraphic.Points[countPoints - 1].SourcePoint.Time.CompareTo(CommonData.RightTime) > 0)
            {
                return;
            }
            Size cellSizeLast = new Size(renderedGraphic.Points[countPoints - 1].SourcePoint.Value.ToString().Length * 5 + 10, 13);

            IsTextUnderPrevPoint = ToolFunctions.DrawTxtValue(dc, renderedGraphic.Points[countPoints - 1].Position, renderedGraphic.Points[countPoints - 1].Position,
                                                              renderedGraphic.Points[countPoints - 1].SourcePoint.Value, IsTextUnderPrevPoint, cellSizeLast);
        }
예제 #10
0
        /*-------------------------------------------------------------------------------------------------------------*/
        /// <summary>
        /// Построить двумерный график
        /// </summary>
        /// <param name="srcGraphic">Исходные данные</param>
        /// <param name="rect">область отображения на экране</param>
        /// <param name="timeInPoint">коэффициент</param>
        /// <param name="leftTime">левая временная граница</param>
        /// <param name="rightTime">правая временная граница</param>
        /// <returns>двумерный график</returns>
        public static GeometryGraphic Construct(SourceGraphic srcGraphic, Rect rect, double timeInPoint, TimeSpan leftTime, TimeSpan rightTime)
        {
            GeometryGraphic geometryGraphic = new GeometryGraphic();

            if (srcGraphic.Points.Count == 0)
            {
                return(geometryGraphic);
            }
            double minV        = rect.Location.Y + rect.Height; // -30;
            double maxV        = rect.Location.Y;               // +10;
            double valInPx     = (minV - maxV) / srcGraphic.MaxValue;
            int    countPoints = srcGraphic.Points.Count;

            for (int i = 0; i < countPoints; i++)
            {
                if ((i < (countPoints - 1)) && (srcGraphic.Points[i].Time.CompareTo(leftTime) <= 0) && (srcGraphic.Points[i + 1].Time.CompareTo(leftTime) >= 0))
                {
                    Point         curPosPoint = new Point(rect.Location.X + ToolFunctions.GetDxByTime(leftTime, timeInPoint, leftTime), (minV - srcGraphic.Points[i].Value * valInPx));
                    GeometryPoint curPoint    = new GeometryPoint(curPosPoint, srcGraphic.Points[i]);
                    geometryGraphic.Points.Add(curPoint);
                }
                else if ((srcGraphic.Points[i].Time.CompareTo(leftTime) > 0) && (srcGraphic.Points[i].Time.CompareTo(rightTime) < 0))
                {
                    Point         curPosPoint = new Point(rect.Location.X + ToolFunctions.GetDxByTime(srcGraphic.Points[i].Time, timeInPoint, leftTime), (minV - srcGraphic.Points[i].Value * valInPx));
                    GeometryPoint curPoint    = new GeometryPoint(curPosPoint, srcGraphic.Points[i]);
                    geometryGraphic.Points.Add(curPoint);
                }
                else if (srcGraphic.Points[i].Time.CompareTo(rightTime) >= 0)
                {
                    Point         curPosPoint = new Point(rect.Location.X + +ToolFunctions.GetDxByTime(rightTime, timeInPoint, leftTime), (minV - srcGraphic.Points[i].Value * valInPx));
                    GeometryPoint curPoint    = new GeometryPoint(curPosPoint, srcGraphic.Points[i]);
                    geometryGraphic.Points.Add(curPoint);
                    return(geometryGraphic);
                }
            }
            return(geometryGraphic);
        }
예제 #11
0
        public static GeometryGraphic ConstructWithApproximation(SourceGraphic srcGraphic, Rect rect, double timeInPoint, TimeSpan leftTime, TimeSpan rightTime, double accuracyApproximationPx, out bool isAppearApproximation)
        {
            GeometryGraphic geometryGraphic = new GeometryGraphic();

            isAppearApproximation = false;
            if (srcGraphic.Points.Count == 0)
            {
                return(geometryGraphic);
            }
            double minV    = rect.Location.Y + rect.Height; // -30;
            double maxV    = rect.Location.Y;               // +10;
            double valInPx = (minV - maxV) / srcGraphic.MaxValue;

            int countPoints = srcGraphic.Points.Count;

            if (srcGraphic.Points.Count < 5)
            {
                for (int i = 0; i < countPoints; i++)
                {
                    geometryGraphic.Points.Add(GetGeometryPointFrom(srcGraphic.Points[i], (minV - srcGraphic.Points[i].Value * valInPx), rect, timeInPoint, leftTime, srcGraphic.Points[i].Time));
                }
                return(geometryGraphic);
            }

            GeometryPoint prevPt = new GeometryPoint();

            for (int i = 0; i < countPoints; i++)
            {
                if ((i < (countPoints - 1)) && (srcGraphic.Points[i].Time.CompareTo(leftTime) <= 0) && (srcGraphic.Points[i + 1].Time.CompareTo(leftTime) >= 0))
                {
                    Point         curPosPoint = new Point(rect.Location.X + ToolFunctions.GetDxByTime(leftTime, timeInPoint, leftTime), (minV - srcGraphic.Points[i].Value * valInPx));
                    GeometryPoint curPoint    = new GeometryPoint(curPosPoint, srcGraphic.Points[i]);
                    geometryGraphic.Points.Add(curPoint);
                    prevPt = curPoint;
                }
                else if ((srcGraphic.Points[i].Time.CompareTo(leftTime) > 0) && (srcGraphic.Points[i].Time.CompareTo(rightTime) < 0))
                {
                    Point         curPosPoint = new Point(rect.Location.X + ToolFunctions.GetDxByTime(srcGraphic.Points[i].Time, timeInPoint, leftTime), (minV - srcGraphic.Points[i].Value * valInPx));
                    GeometryPoint curPoint    = new GeometryPoint(curPosPoint, srcGraphic.Points[i]);

                    if (i == 1)
                    {
                        geometryGraphic.Points.Add(curPoint);
                        prevPt = curPoint;
                        continue;
                    }
                    if (i == (countPoints - 1 - 1))
                    {
                        geometryGraphic.Points.Add(curPoint);
                        prevPt = curPoint;
                        continue;
                    }

                    if ((curPoint.X - prevPt.X) < accuracyApproximationPx)
                    {
                        isAppearApproximation = true;
                        continue;
                    }
                    else
                    {
                        geometryGraphic.Points.Add(curPoint);
                        prevPt = curPoint;
                    }
                }
                else if (srcGraphic.Points[i].Time.CompareTo(rightTime) >= 0)
                {
                    Point         curPosPoint = new Point(rect.Location.X + +ToolFunctions.GetDxByTime(rightTime, timeInPoint, leftTime), (minV - srcGraphic.Points[i].Value * valInPx));
                    GeometryPoint curPoint    = new GeometryPoint(curPosPoint, srcGraphic.Points[i]);
                    geometryGraphic.Points.Add(curPoint);
                    return(geometryGraphic);
                }
            }

            return(geometryGraphic);
        }