Exemple #1
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     ///Check the state of the left mouse button! And if not pressed, pass back the same value of the solenoid current,
     ///else transform the X-coordinate coming in argument 'value'  to the solenoid current value corresponding to it
     if (Mouse.LeftButton == MouseButtonState.Pressed)
     {
         //При помощи массива значений параметров находим ближайший по времени
         if (_window.SolenoidI_graph_pairs != null)
         {
             TimeParameterPair tpp = _window.SolenoidI_graph_pairs.Where(x => Math.Abs(x.screenPoint.X - (double)value) < 1).Select(x => x).FirstOrDefault();
             _lastMeasuredValue = tpp.parameter;
         }
     }
     return(_lastMeasuredValue); //presumably get it from the parameter argument
 }
        private DrawingVisual CreateDrawingVisualPlot(List <TimeParameterPair> timeParameterPairs, Rect rect)
        {
            DrawingVisual  drawingVisual               = new DrawingVisual();
            DrawingContext drawingContext              = drawingVisual.RenderOpen();
            Pen            pen                         = new Pen(Brushes.Black, 1.0);
            double         LowerLimitForTimeOnXAxis    = 0;                                              //нижняя гравница временного интервала в миллисекундах
            double         UpperLimitForTimeOnXAxis    = MillisecondsSinceTheBeginning(this.finishTime); //верхняя гравница временного интервала в миллисекундах
            double         LowerLimitForCurrentOnYAxis = vm == null ? 0 : Double.Parse(vm.CurrentMin.Replace(',', '.'), CultureInfo.InvariantCulture);
            double         UpperLimitForCurrentOnYAxis = vm == null ? 50 : Double.Parse(vm.CurrentMax.Replace(',', '.'), CultureInfo.InvariantCulture);
            double         xmin                        = rect.X;
            double         xmax                        = rect.X + rect.Width;
            double         ymin                        = rect.Y;
            double         ymax                        = rect.Y + rect.Height;

            PrepareTransformations(
                LowerLimitForTimeOnXAxis, UpperLimitForTimeOnXAxis,
                LowerLimitForCurrentOnYAxis, UpperLimitForCurrentOnYAxis,
                xmin, xmax,
                ymin, ymax);

            Point WPoint = new Point(0, 0);         // миллисекунды, мм рт.ст.
            Point DPoint;                           // экранные координаты
            Point previousDPoint = new Point(0, 0); //предыдущая точка на графике, с которой соединяемся отрезком
            bool  FirstDot       = true;
            Point minDPoint      = new Point(0, 0);
            Point maxDPoint      = new Point(0, 0);
            //bool Clashed = false;

            TimeParameterPair time_parameter_pair;
            TimeParameterPair time_parameter_pair_with_coordinates;
            int DataLength = timeParameterPairs == null ? 0 : timeParameterPairs.Count;

            for (int i = 0; i < DataLength; i++)
            {
                time_parameter_pair = timeParameterPairs[i];
                WPoint.X            = MillisecondsSinceTheBeginning(time_parameter_pair.dt);
                WPoint.Y            = time_parameter_pair.parameter;
                DPoint = WtoD(WPoint);

                time_parameter_pair_with_coordinates = new TimeParameterPair()
                {
                    dt        = timeParameterPairs[i].dt,
                    parameter = timeParameterPairs[i].parameter,
                };

                time_parameter_pair_with_coordinates.screenPoint = DPoint;
                timeParameterPairs[i] = time_parameter_pair_with_coordinates;


                if (FirstDot)
                {
                    previousDPoint = DPoint; FirstDot = false;
                }
                else
                if (Math.Round(DPoint.X) != Math.Round(previousDPoint.X)) //алгоритм сглаживания(разрежения)
                {
                    //if (!Clashed)
                    //{
                    //    drawingContext.DrawLine(pen, previousDPoint, DPoint);
                    //    previousDPoint = DPoint;
                    //}
                    //else
                    //{
                    //    Clashed = false;
                    //    //Соединяем минимальную и максимальную точки,
                    //    //из них последнюю по времени соединяем с текущей.
                    //    drawingContext.DrawLine(pen, minDPoint, maxDPoint);
                    //    previousDPoint = minDPoint.X <= maxDPoint.X ? maxDPoint : minDPoint;
                    drawingContext.DrawLine(pen, previousDPoint, DPoint);
                    previousDPoint = DPoint;
                    //}
                }
                //else
                //{
                //    if (!Clashed)
                //    {
                //        Clashed = true;
                //        //определяем максимальную и минимальную точки
                //        //на неразличимом временном отрезке
                //        minDPoint = LowerPoint(previousDPoint, DPoint);
                //        maxDPoint = UpperPoint(previousDPoint, DPoint);
                //    }
                //    else
                //    {
                //        minDPoint = LowerPoint(minDPoint, DPoint);
                //        maxDPoint = UpperPoint(maxDPoint, DPoint);
                //    }


                //}
                //if(Clashed)
                //    drawingContext.DrawLine(pen, minDPoint, maxDPoint);
            }
            drawingContext.Close();
            return(drawingVisual);
        }