Exemplo n.º 1
0
        private void MPlot_MouseMove(object sender, MouseEventArgs e)
        {
            DataPoint mousepos = lineSerie.InverseTransform(new ScreenPoint(e.X, e.Y));

            if (!foundPointIsEndPoint)
            {
                if (mousepos.X <= before_foundPoint.X)
                {
                    foundPoint.X = before_foundPoint.X;
                }
                else if (mousepos.X >= after_foundPoint.X)
                {
                    foundPoint.X = after_foundPoint.X;
                }
                else
                {
                    foundPoint.X = mousepos.X;
                }
            }

            if (mousepos.Y >= control.Control.MaxSoftwareValue)
            {
                foundPoint.Y = control.Control.MaxSoftwareValue;
            }
            else if (mousepos.Y <= control.Control.MinSoftwareValue)
            {
                foundPoint.Y = control.Control.MinSoftwareValue;
            }
            else
            {
                foundPoint.Y = mousepos.Y;
            }


            double sensorvalue;

            if (sensor.SensorType == SensorType.Voltage)
            {
                sensorvalue = Math.Round(foundPoint.X, 4);
            }
            else if (sensor.SensorType == SensorType.Power)
            {
                sensorvalue = Math.Round(foundPoint.X, 1);
            }
            else if (sensor.SensorType == SensorType.Flow)
            {
                sensorvalue = Math.Round(foundPoint.X, 1);
            }
            else
            {
                sensorvalue = Math.Round(foundPoint.X, 0);
            }

            annotation.Text = Math.Round(foundPoint.Y, 0) + " " + controlTypename + " - " + sensorvalue + " " + sensorTypename;

            mPlot.Refresh();
        }
Exemplo n.º 2
0
        public static PlotModel TouchSeries()
        {
            var model = new PlotModel {
                Title = "Touch on a LineSeries"
            };
            var series = new LineSeries();

            series.Points.Add(new DataPoint(0, 0));
            series.Points.Add(new DataPoint(10, 10));
            model.Series.Add(series);

            series.TouchStarted += (s, e) =>
            {
                model.Subtitle = "The touch gesture started on the LineSeries";
                model.InvalidatePlot(false);
                e.Handled = true;
            };

            series.TouchDelta += (s, e) =>
            {
                series.Points.Add(series.InverseTransform(e.Position));
                model.InvalidatePlot(false);
            };

            series.TouchCompleted += (s, e) =>
            {
                model.Subtitle = "The touch gesture completed";
                model.InvalidatePlot(false);
                e.Handled = true;
            };

            return(model);
        }
Exemplo n.º 3
0
        public void PlotMouseMove(LineSeries lb, MapStatistics ms, OxyMouseEventArgs e)
        {
            if (lb.Points.Count != 0)
            {
                ms._endPoint1 = lb.InverseTransform(e.Position);
                if (ms._startPoint1.X != 0 || ms._startPoint1.Y != 0)
                {
                    ms._pm.Annotations.Clear();

                    var rectangle = new PolygonAnnotation();
                    rectangle.Layer           = AnnotationLayer.BelowAxes;
                    rectangle.StrokeThickness = 0.5;
                    rectangle.Stroke          = OxyColors.Red;
                    rectangle.Fill            = OxyColors.Transparent;
                    rectangle.LineStyle       = OxyPlot.LineStyle.Dot;

                    rectangle.Points.Add(new DataPoint(ms._startPoint1.X, ms._startPoint1.Y));
                    rectangle.Points.Add(new DataPoint(ms._endPoint1.X, ms._startPoint1.Y));
                    rectangle.Points.Add(new DataPoint(ms._endPoint1.X, ms._endPoint1.Y));
                    rectangle.Points.Add(new DataPoint(ms._startPoint1.X, ms._endPoint1.Y));

                    ms._pm.Annotations.Add(rectangle as Annotation);
                    ms._pm.InvalidatePlot(true);
                }
            }
        }
Exemplo n.º 4
0
 public void PlotMouseDown(LineSeries lb, MapStatistics ms, OxyMouseDownEventArgs e)
 {
     if (lb.Points.Count != 0)
     {
         //DataPoint dd = new DataPoint(lb.InverseTransform(e.Position).X, lb.InverseTransform(e.Position).Y);
         ms._startPoint1 = lb.InverseTransform(e.Position);
     }
 }
Exemplo n.º 5
0
        public static PlotModel TouchSeries()
        {
            var model = new PlotModel { Title = "Touch on a LineSeries" };
            var series = new LineSeries();
            series.Points.Add(new DataPoint(0, 0));
            series.Points.Add(new DataPoint(10, 10));
            model.Series.Add(series);

            series.TouchStarted += (s, e) =>
            {
                model.Subtitle = "The touch gesture started on the LineSeries";
                model.InvalidatePlot(false);
                e.Handled = true;
            };

            series.TouchDelta += (s, e) =>
            {
                series.Points.Add(series.InverseTransform(e.Position));
                model.InvalidatePlot(false);
            };

            series.TouchCompleted += (s, e) =>
            {
                model.Subtitle = "The touch gesture completed";
                model.InvalidatePlot(false);
                e.Handled = true;
            };

            return model;
        }
Exemplo n.º 6
0
        public static PlotModel MouseDownEvent()
        {
            var model = new PlotModel { Title = "MouseDown", Subtitle = "Left click to edit or add points.", LegendSymbolLength = 40 };

            // Add a line series
            var s1 = new LineSeries
            {
                Title = "LineSeries1",
                Color = OxyColors.SkyBlue,
                MarkerType = MarkerType.Circle,
                MarkerSize = 6,
                MarkerStroke = OxyColors.White,
                MarkerFill = OxyColors.SkyBlue,
                MarkerStrokeThickness = 1.5
            };
            s1.Points.Add(new DataPoint(0, 10));
            s1.Points.Add(new DataPoint(10, 40));
            s1.Points.Add(new DataPoint(40, 20));
            s1.Points.Add(new DataPoint(60, 30));
            model.Series.Add(s1);

            int indexOfPointToMove = -1;

            // Subscribe to the mouse down event on the line series
            s1.MouseDown += (s, e) =>
            {
                // only handle the left mouse button (right button can still be used to pan)
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    int indexOfNearestPoint = (int)Math.Round(e.HitTestResult.Index);
                    var nearestPoint = s1.Transform(s1.Points[indexOfNearestPoint]);

                    // Check if we are near a point
                    if ((nearestPoint - e.Position).Length < 10)
                    {
                        // Start editing this point
                        indexOfPointToMove = indexOfNearestPoint;
                    }
                    else
                    {
                        // otherwise create a point on the current line segment
                        int i = (int)e.HitTestResult.Index + 1;
                        s1.Points.Insert(i, s1.InverseTransform(e.Position));
                        indexOfPointToMove = i;
                    }

                    // Change the linestyle while editing
                    s1.LineStyle = LineStyle.DashDot;

                    // Remember to refresh/invalidate of the plot
                    model.InvalidatePlot(false);

                    // Set the event arguments to handled - no other handlers will be called.
                    e.Handled = true;
                }
            };

            s1.MouseMove += (s, e) =>
                {
                    if (indexOfPointToMove >= 0)
                    {
                        // Move the point being edited.
                        s1.Points[indexOfPointToMove] = s1.InverseTransform(e.Position);
                        model.InvalidatePlot(false);
                        e.Handled = true;
                    }
                };

            s1.MouseUp += (s, e) =>
            {
                // Stop editing
                indexOfPointToMove = -1;
                s1.LineStyle = LineStyle.Solid;
                model.InvalidatePlot(false);
                e.Handled = true;
            };

            model.MouseDown += (s, e) =>
                {
                    if (e.ChangedButton == OxyMouseButton.Left)
                    {
                        // Add a point to the line series.
                        s1.Points.Add(s1.InverseTransform(e.Position));
                        indexOfPointToMove = s1.Points.Count - 1;

                        model.InvalidatePlot(false);
                        e.Handled = true;
                    }
                };
            return model;
        }
Exemplo n.º 7
0
        public static PlotModel MouseDownEvent()
        {
            var model = new PlotModel {
                Title = "MouseDown", Subtitle = "Left click to edit or add points."
            };
            var l = new Legend
            {
                LegendSymbolLength = 40
            };

            model.Legends.Add(l);

            // Add a line series
            var s1 = new LineSeries
            {
                Title                 = "LineSeries1",
                Color                 = OxyColors.SkyBlue,
                MarkerType            = MarkerType.Circle,
                MarkerSize            = 6,
                MarkerStroke          = OxyColors.White,
                MarkerFill            = OxyColors.SkyBlue,
                MarkerStrokeThickness = 1.5
            };

            s1.Points.Add(new DataPoint(0, 10));
            s1.Points.Add(new DataPoint(10, 40));
            s1.Points.Add(new DataPoint(40, 20));
            s1.Points.Add(new DataPoint(60, 30));
            model.Series.Add(s1);

            int indexOfPointToMove = -1;

            // Subscribe to the mouse down event on the line series
            s1.MouseDown += (s, e) =>
            {
                // only handle the left mouse button (right button can still be used to pan)
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    int indexOfNearestPoint = (int)Math.Round(e.HitTestResult.Index);
                    var nearestPoint        = s1.Transform(s1.Points[indexOfNearestPoint]);

                    // Check if we are near a point
                    if ((nearestPoint - e.Position).Length < 10)
                    {
                        // Start editing this point
                        indexOfPointToMove = indexOfNearestPoint;
                    }
                    else
                    {
                        // otherwise create a point on the current line segment
                        int i = (int)e.HitTestResult.Index + 1;
                        s1.Points.Insert(i, s1.InverseTransform(e.Position));
                        indexOfPointToMove = i;
                    }

                    // Change the linestyle while editing
                    s1.LineStyle = LineStyle.DashDot;

                    // Remember to refresh/invalidate of the plot
                    model.InvalidatePlot(false);

                    // Set the event arguments to handled - no other handlers will be called.
                    e.Handled = true;
                }
            };

            s1.MouseMove += (s, e) =>
            {
                if (indexOfPointToMove >= 0)
                {
                    // Move the point being edited.
                    s1.Points[indexOfPointToMove] = s1.InverseTransform(e.Position);
                    model.InvalidatePlot(false);
                    e.Handled = true;
                }
            };

            s1.MouseUp += (s, e) =>
            {
                // Stop editing
                indexOfPointToMove = -1;
                s1.LineStyle       = LineStyle.Solid;
                model.InvalidatePlot(false);
                e.Handled = true;
            };

            model.MouseDown += (s, e) =>
            {
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    // Add a point to the line series.
                    s1.Points.Add(s1.InverseTransform(e.Position));
                    indexOfPointToMove = s1.Points.Count - 1;

                    model.InvalidatePlot(false);
                    e.Handled = true;
                }
            };
            return(model);
        }
Exemplo n.º 8
0
        public LineSeries GetSeries4Model2(string title, OxyColor color, int index)
        {
            var s1 = new LineSeries {
                Title = title,
                Color = color,
                //MarkerType = MarkerType.Circle,
                //MarkerSize = 6,
                //MarkerStroke = OxyColors.White,
                //MarkerFill = color,
                //MarkerStrokeThickness = 1.5
            };

            IndOfPointToMove.Add(index, -1);
            Annot.Add(index, new List <PointAnnotation>());


            // Subscribe to the mouse down event on the line series
            s1.MouseDown += (s, e) => {
                // only handle the left mouse button (right button can still be used to pan)
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    int indexOfNearestPoint = (int)Math.Round(e.HitTestResult.Index);
                    var nearestPoint        = s1.Transform(s1.Points[indexOfNearestPoint]);

                    // Check if we are near a point
                    if ((nearestPoint - e.Position).Length < 10)
                    {
                        // Start editing this point
                        IndOfPointToMove[index] = indexOfNearestPoint;
                    }
                    else
                    {
                        // otherwise create a point on the current line segment
                        //int i = (int)e.HitTestResult.Index + 1;
                        //s1.Points.Insert(i,s1.InverseTransform(e.Position));
                        //IndOfPointToMove[index] = i;
                    }

                    // Change the linestyle while editing
                    s1.LineStyle = LineStyle.DashDot;

                    // Remember to refresh/invalidate of the plot
                    Model2.InvalidatePlot(false);

                    // Set the event arguments to handled - no other handlers will be called.
                    e.Handled = true;
                }
            };

            s1.MouseMove += (s, e) =>
            {
                if (IndOfPointToMove[index] >= 0)
                {
                    // Move the point being edited.
                    s1.Points[IndOfPointToMove[index]]      = s1.InverseTransform(e.Position);
                    Annot[index][IndOfPointToMove[index]].X = s1.InverseTransform(e.Position).X;
                    Annot[index][IndOfPointToMove[index]].Y = s1.InverseTransform(e.Position).Y;
                    Model2.InvalidatePlot(false);
                    e.Handled = true;
                }
            };

            s1.MouseUp += (s, e) => {
                // Stop editing
                IndOfPointToMove[index] = -1;
                s1.LineStyle            = LineStyle.Solid;
                Model2.InvalidatePlot(false);
                e.Handled = true;
            };



            return(s1);
        }
Exemplo n.º 9
0
        public PlotModel CreatePlotModel()
        {
            var model = new PlotModel()
            {
                LegendSymbolLength = 6
            };

            // Add a line series
            data = new LineSeries()
            {
                Color                 = OxyColors.SkyBlue,
                MarkerType            = MarkerType.Square,
                MarkerSize            = 5,
                MarkerStroke          = OxyColors.White,
                MarkerFill            = OxyColors.SkyBlue,
                MarkerStrokeThickness = 1.5,
            };
            //data.
            bot  = new LinearAxis(AxisPosition.Bottom, control.Curve.Min, control.Curve.Max, 5, 1, "Value");
            left = new LinearAxis(AxisPosition.Left, minY - 1, maxY + 1, 10, 5, "Fan duty");
            bot.MajorGridlineStyle  = LineStyle.Dot;
            left.MajorGridlineStyle = LineStyle.Dot;
            bot.IsZoomEnabled       = false;
            left.IsZoomEnabled      = false;
            model.Axes.Add(bot);
            model.Axes.Add(left);
            model.PlotMargins     = new OxyThickness(0);
            model.IsLegendVisible = false;

            if (control.Controlled.UseCalibrated)
            {
                right = new LinearAxis(AxisPosition.Right, 0, control.Controlled.MaxRPM, 300, 100, "RPM");
                model.Axes.Add(right);
            }
            //series.Points.
            for (int i = 0; i < control.Curve.Count; i++)
            {
                data.Points.Add(new DataPoint(control.Curve[i].X, control.Curve[i].Y));
            }
            model.Series.Add(data);

            int indexOfPointToMove = -1;

            // Subscribe to the mouse down event on the line series
            data.MouseDown += (s, e) =>
            {
                // only handle the left mouse button (right button can still be used to pan)
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    int indexOfNearestPoint = (int)Math.Round(e.HitTestResult.Index);
                    var nearestPoint        = data.Transform(data.Points[indexOfNearestPoint]);

                    // Check if we are near a point
                    if ((nearestPoint - e.Position).Length < 10)
                    {
                        // Start editing this point
                        indexOfPointToMove = indexOfNearestPoint;

                        // Show tracker label
                        UpdatePlotTracker(e, data.Points[indexOfPointToMove].X, data.Points[indexOfPointToMove].Y);
                        plotLabel.Visible = true;
                    }
                    else
                    {
                        // otherwise create a point on the current line segment
                        int i = (int)e.HitTestResult.Index + 1;
                        data.Points.Insert(i, data.InverseTransform(e.Position));
                        indexOfPointToMove = i;
                        //control.Curve.AddOrdered(new PointF((float)data.Points[i].X, (float)data.Points[i].Y));
                        control.Curve.Insert(i, new PointF((float)data.Points[i].X, (float)data.Points[i].Y));

                        // Show tracker label
                        UpdatePlotTracker(e, data.Points[i].X, data.Points[i].Y);
                        plotLabel.Visible = true;
                    }

                    // Change the linestyle while editing
                    data.LineStyle = LineStyle.DashDot;
                    UpdateCurveTracker();
                    // Remember to refresh/invalidate of the plot
                    model.RefreshPlot(false);

                    control.OverrideHysteresis = true;
                    // Set the event arguments to handled - no other handlers will be called.
                    e.Handled = true;
                }
                else
                if (e.ChangedButton == OxyMouseButton.Right)
                {
                    if (data.Points.Count == 1)
                    {
                        // Cant remove the last point
                        e.Handled = true;
                        return;
                    }

                    int indexOfNearestPoint = (int)Math.Round(e.HitTestResult.Index);
                    var nearestPoint        = data.Transform(data.Points[indexOfNearestPoint]);

                    // Check if we are near a point
                    if ((nearestPoint - e.Position).Length < 10)
                    {
                        data.Points.Remove(data.Points[indexOfNearestPoint]);
                        control.Curve.RemoveAt(indexOfNearestPoint);

                        // Change the linestyle while editing
                        data.LineStyle = LineStyle.DashDot;
                        UpdateCurveTracker();
                        // Remember to refresh/invalidate of the plot
                        model.RefreshPlot(false);

                        control.OverrideHysteresis = true;
                        // Set the event arguments to handled - no other handlers will be called.
                        e.Handled = true;
                    }
                }
            };

            data.MouseMove += (s, e) =>
            {
                if (indexOfPointToMove >= 0)
                {
                    // Move the point being edited.
                    var p = data.InverseTransform(e.Position);
                    if (p.X > bot.Maximum)
                    {
                        p.X = bot.Maximum;
                    }
                    if (p.Y > maxY)
                    {
                        p.Y = maxY;
                    }
                    if (p.X < bot.Minimum)
                    {
                        p.X = bot.Minimum;
                    }
                    if (p.Y < minY)
                    {
                        p.Y = minY;
                    }
                    if ((indexOfPointToMove > 0 && p.X <= data.Points[indexOfPointToMove - 1].X))
                    {
                        p.X = data.Points[indexOfPointToMove - 1].X + 1;
                    }
                    if (indexOfPointToMove < data.Points.Count - 1 && p.X >= data.Points[indexOfPointToMove + 1].X)
                    {
                        p.X = data.Points[indexOfPointToMove + 1].X - 1;
                    }
                    control.Curve[indexOfPointToMove] = new PointF((float)p.X, (float)p.Y);
                    data.Points[indexOfPointToMove]   = p;

                    UpdateCurveTracker();
                    UpdatePlotTracker(e, p.X, p.Y);

                    model.RefreshPlot(false);
                    control.OverrideHysteresis = true;
                    e.Handled = true;
                }
            };

            data.MouseUp += (s, e) =>
            {
                // Stop editing
                indexOfPointToMove = -1;
                data.LineStyle     = LineStyle.Solid;
                plotLabel.Visible  = false;
                model.RefreshPlot(false);
                e.Handled = true;
            };

            TransformMode transformMode  = TransformMode.None;
            ScreenPoint   transformStart = new ScreenPoint();

            model.MouseDown += (s, e) =>
            {
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    var t = data.InverseTransform(e.Position);
                    // Add a point to the line series.

                    // Check for max values
                    if (t.X <= bot.Maximum && t.X >= bot.Minimum && t.Y <= maxY && t.Y >= minY)
                    {
                        // Check for x-collisions
                        if (data.Points.Count > 0 && (t.X > data.Points[data.Points.Count - 1].X || t.X < data.Points[0].X))
                        {
                            if (data.Points[0].X > t.X)
                            {
                                data.Points.Insert(0, t);
                                indexOfPointToMove = 0;
                                control.Curve.Insert(0, new PointF((float)t.X, (float)t.Y));
                            }
                            else
                            {
                                data.Points.Add(t);
                                indexOfPointToMove = data.Points.Count - 1;
                                control.Curve.Add(new PointF((float)t.X, (float)t.Y));
                            }
                        }
                    }
                    UpdateCurveTracker();
                    model.RefreshPlot(false);
                    e.Handled = true;
                }
                else if (e.ChangedButton == OxyMouseButton.Middle)
                {
                    transformStart = e.Position;
                    if (Control.ModifierKeys == Keys.Alt)
                    {
                        plot.SetCursorType(CursorType.ZoomVertical);
                        transformMode = TransformMode.Scale_LeftMost;
                    }
                    else if (Control.ModifierKeys == Keys.Control)
                    {
                        plot.SetCursorType(CursorType.ZoomVertical);
                        transformMode = TransformMode.Scale_RightMost;
                    }
                    else
                    {
                        plot.SetCursorType(CursorType.Pan);
                        transformMode = TransformMode.Pan;
                    }
                    e.Handled = true;
                }
            };

            model.MouseUp += (s, e) =>
            {
                transformMode = TransformMode.None;
                plot.SetCursorType(CursorType.Default);
                e.Handled = true;
            };

            model.MouseMove += (s, e) =>
            {
                if (transformMode == TransformMode.Pan)
                {
                    float shiftAmount = (float)(data.InverseTransform(e.Position).Y - data.InverseTransform(transformStart).Y);
                    // Up/Down shift transformation
                    // Check if any point would leave bounds
                    foreach (PointF p in control.Curve)
                    {
                        if ((p.Y + shiftAmount > 100) || (p.Y + shiftAmount < 0))
                        {
                            transformStart = e.Position;
                            e.Handled      = true;
                            return;
                        }
                    }
                    // If bounds are ok, do the shift
                    for (int i = 0; i < control.Curve.Count; i++)
                    {
                        PointF p = control.Curve[i];
                        p.Y += shiftAmount;
                        control.Curve[i] = p;
                        data.Points[i]   = new DataPoint(p.X, p.Y);
                    }
                }
                else if (transformMode == TransformMode.Scale_RightMost)
                {
                    float scaleAmount = 1f - (float)(data.InverseTransform(e.Position).Y - data.InverseTransform(transformStart).Y) / 200f;
                    float constValue  = 100f - control.Curve[control.Curve.Count - 1].Y;

                    foreach (PointF p in control.Curve)
                    {
                        if ((100f - (100f - p.Y - constValue) * scaleAmount - constValue > 100f) ||
                            (100f - (100f - p.Y - constValue) * scaleAmount - constValue < 0f))
                        {
                            transformStart = e.Position;
                            e.Handled      = true;
                            return;
                        }
                    }
                    // If bounds are ok, do the scaling
                    for (int i = 0; i < control.Curve.Count; i++)
                    {
                        PointF p = control.Curve[i];
                        p.Y = 100f - (100f - p.Y - constValue) * scaleAmount - constValue;
                        control.Curve[i] = p;
                        data.Points[i]   = new DataPoint(p.X, p.Y);
                    }
                }
                else if (transformMode == TransformMode.Scale_LeftMost)
                {
                    float scaleAmount = 1f + (float)(data.InverseTransform(e.Position).Y - data.InverseTransform(transformStart).Y) / 200f;
                    float constValue  = control.Curve[0].Y;

                    foreach (PointF p in control.Curve)
                    {
                        if (((p.Y - constValue) * scaleAmount + constValue > 100f) ||
                            ((p.Y - constValue) * scaleAmount + constValue < 0f))
                        {
                            transformStart = e.Position;
                            e.Handled      = true;
                            return;
                        }
                    }
                    // If bounds are ok, do the scaling
                    for (int i = 0; i < control.Curve.Count; i++)
                    {
                        PointF p = control.Curve[i];
                        p.Y = (p.Y - constValue) * scaleAmount + constValue;
                        control.Curve[i] = p;
                        data.Points[i]   = new DataPoint(p.X, p.Y);
                    }
                }
                else
                {
                    return;
                }

                InvalidatePlot();
                transformStart = e.Position;
                e.Handled      = true;
            };
            return(model);
        }
Exemplo n.º 10
0
        private void MPlot_MouseMove(object sender, MouseEventArgs e)
        {
            DataPoint mousePos = lineSeries.InverseTransform(new ScreenPoint(e.X, e.Y));

            if (_selectedPointIndex < 0)
            {
                return;
            }

            var currentPoint = lineSeries.Points[_selectedPointIndex];

            double newX = currentPoint.X;
            double newY = currentPoint.Y;

            if (_selectedPointIndex > 0 && _selectedPointIndex < lineSeries.Points.Count - 1)
            {
                var previousPoint = lineSeries.Points[_selectedPointIndex - 1];
                var nextPoint     = lineSeries.Points[_selectedPointIndex + 1];
                if (mousePos.X <= previousPoint.X)
                {
                    newX = previousPoint.X;
                }
                else if (mousePos.X >= nextPoint.X)
                {
                    newX = nextPoint.X;
                }
                else
                {
                    newX = mousePos.X;
                }
            }

            if (mousePos.Y >= control.Control.MaxSoftwareValue)
            {
                newY = control.Control.MaxSoftwareValue;
            }
            else if (mousePos.Y <= control.Control.MinSoftwareValue)
            {
                newY = control.Control.MinSoftwareValue;
            }
            else
            {
                newY = mousePos.Y;
            }

            double sensorValue;

            if (sensor.SensorType == SensorType.Voltage)
            {
                sensorValue = Math.Round(newX, 4);
            }
            else if (sensor.SensorType == SensorType.Power)
            {
                sensorValue = Math.Round(newX, 1);
            }
            else if (sensor.SensorType == SensorType.Flow)
            {
                sensorValue = Math.Round(newX, 1);
            }
            else
            {
                sensorValue = Math.Round(newX, 0);
            }

            annotation.Text = Math.Round(newY, 0) + " " + controlTypename + " - " + sensorValue + " " + sensorTypename;

            lineSeries.Points[_selectedPointIndex] = new DataPoint(newX, newY);

            mPlot.Refresh();
        }
Exemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewModel" /> class.
        /// </summary>
        public MainViewModel()
        {
            // Create the plot model
            var model = new PlotModel {
                Title = "Pump RPM by Temperature"
            };

            model.IsLegendVisible = false;


            // Create two line series (markers are hidden by default)
            var s1 = new LineSeries {
                Title                 = "Series 1",
                MarkerType            = MarkerType.Circle,
                MarkerFill            = OxyColor.FromArgb(0, 15, 35, 100),
                MarkerStroke          = OxyColor.FromArgb(255, 15, 35, 100),
                MarkerStrokeThickness = 2,
                MarkerSize            = 4,
                Color                 = OxyColor.FromArgb(255, 15, 35, 100)
            };

            s1.Points.Add(new DataPoint(00, 00));
            s1.Points.Add(new DataPoint(10, 10));
            s1.Points.Add(new DataPoint(20, 20));
            s1.Points.Add(new DataPoint(30, 30));
            s1.Points.Add(new DataPoint(40, 40));
            s1.Points.Add(new DataPoint(50, 50));
            s1.Points.Add(new DataPoint(60, 60));
            s1.Points.Add(new DataPoint(70, 70));
            s1.Points.Add(new DataPoint(80, 80));
            s1.Points.Add(new DataPoint(90, 90));
            s1.Points.Add(new DataPoint(100, 100));
            // Add the series to the plot model
            model.Series.Add(s1);

            int indexOfPointToMove = -1;

            // Subscribe to the mouse down event on the line series
            s1.MouseDown += (s, e) => {
                if (e.HitTestResult == null)
                {
                    return;
                }

                if (e.ChangedButton == OxyMouseButton.Right)
                {
                    int indexOfNearestPoint = (int)Math.Round(e.HitTestResult.Index);
                    var nearestPoint        = s1.Transform(s1.Points[indexOfNearestPoint]);
                    if ((nearestPoint - e.Position).Length < 10)
                    {
                        s1.Points.RemoveAt(indexOfNearestPoint);
                    }

                    indexOfPointToMove = -1;
                    model.InvalidatePlot(false);
                    e.Handled = true;
                }

                // only handle the left mouse button (right button can still be used to pan)
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    int indexOfNearestPoint = (int)Math.Round(e.HitTestResult.Index);
                    var nearestPoint        = s1.Transform(s1.Points[indexOfNearestPoint]);

                    // Check if we are near a point
                    if ((nearestPoint - e.Position).Length < 10)
                    {
                        // Start editing this point
                        indexOfPointToMove = indexOfNearestPoint;
                    }
                    else if (s1.Points.Count <= 64)
                    {
                        // otherwise create a point on the current line segment
                        int i = (int)e.HitTestResult.Index + 1;
                        s1.Points.Insert(i, s1.InverseTransform(e.Position));
                        s1.Points.Sort((a, b) => a.X.CompareTo(b.X));
                        indexOfPointToMove = i;
                    }

                    // Change the linestyle while editing
                    s1.LineStyle = LineStyle.DashDot;

                    // Remember to refresh/invalidate of the plot
                    model.InvalidatePlot(false);

                    // Set the event arguments to handled - no other handlers will be called.
                    e.Handled = true;
                }
            };

            s1.MouseMove += (s, e) => {
                if (indexOfPointToMove >= 0)
                {
                    // Move the point being edited.
                    s1.Points[indexOfPointToMove] = s1.InverseTransform(e.Position);
                    model.InvalidatePlot(false);
                    e.Handled = true;
                }
            };

            s1.MouseUp += (s, e) => {
                // Stop editing
                if (indexOfPointToMove >= 0)
                {
                    var pt = s1.Points[indexOfPointToMove];
                    var x  = Math.Round(pt.X);
                    var y  = Math.Round(pt.Y);
                    s1.Points[indexOfPointToMove] = new DataPoint(x, y);
                }

                s1.Points.Sort((a, b) => a.X.CompareTo(b.X));
                indexOfPointToMove = -1;
                s1.LineStyle       = LineStyle.Solid;
                model.InvalidatePlot(false);
                e.Handled = true;
            };

            model.MouseDown += (s, e) => {
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    // Add a point to the line series.
                    s1.Points.Add(s1.InverseTransform(e.Position));
                    s1.Points.Sort((a, b) => a.X.CompareTo(b.X));
                    indexOfPointToMove = s1.Points.Count - 1;

                    model.InvalidatePlot(false);
                    e.Handled = true;
                }
            };

            // Axes are created automatically if they are not defined

            // Set the Model property, the INotifyPropertyChanged event will make the WPF Plot control update its content
            this.Model = model;
        }