/// <summary>
        /// Creates Oxyplot library plot model
        /// </summary>
        /// <returns></returns>
        private PlotModel CreateOxyPlotModel(XyPlot plot)
        {
            var tmp = new PlotModel {
                Title = plot.Name
            };

            tmp.IsLegendVisible = ShowLegend;

            this.ShowLegendChanged += (o, e) => { tmp.IsLegendVisible = this.ShowLegend; OxyPlotModel.InvalidatePlot(false); };

            for (var i = 0; i < plot.Series.Count; i++)
            {
                if (plot.Series[i].Points.Count > 1)
                {
                    var series = new LineSeries {
                        Title = plot.Series[i].Name, MarkerType = MarkerType.None, Color = OxyColor.FromRgb((byte)rand.Next(255), (byte)rand.Next(255), (byte)rand.Next(255))
                    };

                    Series[i].Brush = new SolidColorBrush(Color.FromRgb(series.Color.R, series.Color.G, series.Color.B));

                    tmp.Series.Add(series);

                    for (var j = 0; j < plot.Series[i].Points.Count; j++)
                    {
                        var y = plot.Series[i].Points[j].Y;
                        series.Points.Add(new DataPoint(plot.Series[i].Points[j].X, y));
                    }

                    series.IsVisible = Series[i].Selected;

                    Series[i].SelectedChanged += (o, e) => { series.IsVisible = ((SpiceSharpGUI.Windows.ViewModels.Series)o).Selected; OxyPlotModel.InvalidatePlot(false); };
                }
                else
                {
                    var scatterSeries = new ScatterSeries {
                        Title         = plot.Series[i].Name,
                        MarkerSize    = 3,
                        SelectionMode = SelectionMode.Single,
                        MarkerType    = MarkerType.Circle,
                        MarkerFill    = OxyColor.FromRgb((byte)rand.Next(255), (byte)rand.Next(255), (byte)rand.Next(255))
                    };
                    Series[i].Brush = new SolidColorBrush(Color.FromRgb(scatterSeries.MarkerFill.R, scatterSeries.MarkerFill.G, scatterSeries.MarkerFill.B));

                    scatterSeries.Points.Add(new ScatterPoint(plot.Series[i].Points[0].X, plot.Series[i].Points[0].Y));
                    tmp.Series.Add(scatterSeries);

                    scatterSeries.IsVisible    = Series[i].Selected;
                    Series[i].SelectedChanged += (o, e) => { scatterSeries.IsVisible = ((SpiceSharpGUI.Windows.ViewModels.Series)o).Selected; OxyPlotModel.InvalidatePlot(false); };
                }
            }

            CreateAxis(plot, tmp);

            YScaleLogChanged += (o, e) => { CreateAxis(plot, tmp); OxyPlotModel.InvalidatePlot(false); };
            XScaleLogChanged += (o, e) => { CreateAxis(plot, tmp); OxyPlotModel.InvalidatePlot(false); };

            return(tmp);
        }
示例#2
0
 public void AddDVHs(List <DoseVolumeHistogram> dvhs)
 {
     OxyPlotModel.Series.Clear();
     foreach (var dvh in dvhs)
     {
         OxyPlotModel.Series.Add(createLineSeries(dvh));
     }
     OxyPlotModel.InvalidatePlot(true);
 }
示例#3
0
 /// <summary>
 /// Method to invoke when the Edit command is executed.
 /// </summary>
 private async Task OnClearExecute()
 {
     lock (_lockObject)
     {
         Messages.Clear();
         _dataLog.Clear();
         foreach (OxyPlot.Series.LineSeries series in OxyPlotModel.Series)
         {
             series.Points.Clear();
         }
         foreach (var ax in OxyPlotModel.Axes)
         {
             ax.Maximum = ax.Minimum = Double.NaN;
         }
         OxyPlotModel.ResetAllAxes();
         OxyPlotModel.InvalidatePlot(true);
         ViewModelCommandManager.InvalidateCommands(true);
     }
 }
示例#4
0
        private void OnPlotConfigurationChanged()
        {
            ClearPlot();
            if (PlotModel.PlotConfiguration == null)
            {
                return;
            }

            foreach (AxisDefinitionModel axis in PlotModel.PlotConfiguration.Axes)
            {
                var yAxis = new OxyPlot.Axes.LinearAxis {
                    Position = ConvertAxisToOxyPlot(axis.AxisPosition), Title = axis.AxisTitle, Unit = axis.Unit, Key = axis.Key
                };
                yAxis.Tag          = axis;
                axis.OxyAxis       = yAxis;
                yAxis.AxisChanged += _plotService.OnAxisChanged;
                OxyPlotModel.Axes.Add(yAxis);
            }
            StringBuilder logFormat = new StringBuilder();

            foreach (SeriesDefinitionModel series in PlotModel.PlotConfiguration.Series)
            {
                var oxseries = new OxyPlot.Series.LineSeries
                {
                    Title    = series.SeriesTitle,
                    Color    = OxyColor.FromArgb(series.Color.A, series.Color.R, series.Color.G, series.Color.B),
                    YAxisKey = series.YAxisKey
                };
                oxseries.Tag     = series;
                series.OxySeries = oxseries;
                OxyPlotModel.Series.Add(oxseries);
                //oxseries.Smooth;add option for this
            }
            AppendLogFormatFromSeries(logFormat, PlotModel.PlotConfiguration.Series);
            PlotModel.LogFormat = logFormat.ToString();
            OnLogFormatChanged();
            //string tmp = this.PrintfLogString;
            OxyPlotModel.Title = PlotModel.PlotConfiguration.PlotName;
            OxyPlotModel.InvalidatePlot(true);
        }
示例#5
0
        protected void UpdatePlotConfiguration()
        {
            // "PlotName"
            {
                OxyPlotModel.Title = PlotModel.PlotConfiguration.PlotName;
            }
            // "Axes"
            {
                //remove deleted Axes first
                var toRemoveAxis = new List <OxyPlot.Axes.LinearAxis>();
                foreach (OxyPlot.Axes.LinearAxis oxaxis in OxyPlotModel.Axes)
                {
                    if (oxaxis.Position != AxisPosition.Bottom)
                    {
                        var axis = PlotModel.PlotConfiguration.Axes.FirstOrDefault(x => x.OxyAxis == oxaxis);//don't remove xaxis
                        if (axis == null)
                        {
                            toRemoveAxis.Add(oxaxis);
                        }
                    }
                }
                foreach (OxyPlot.Axes.LinearAxis oxaxis in toRemoveAxis)
                {
                    OxyPlotModel.Axes.Remove(oxaxis);
                }

                foreach (AxisDefinitionModel axis in PlotModel.PlotConfiguration.Axes)
                {
                    //can't use FirstOrDefault as OxyPlot sets default to first axis
                    OxyPlot.Axes.LinearAxis oxaxis = null;
                    foreach (OxyPlot.Axes.LinearAxis oa in OxyPlotModel.Axes)
                    {
                        if ((AxisDefinitionModel)oa.Tag == axis)
                        {
                            oxaxis = oa;
                            break;
                        }
                    }
                    //OxyPlot.Axes.LinearAxis oxaxis = OxyPlotModel.Axes.FirstOrDefault(x => x.Tag == axis) as OxyPlot.Axes.LinearAxis;
                    if (oxaxis == null)
                    {
                        var yAxis = new OxyPlot.Axes.LinearAxis {
                            Position = ConvertAxisToOxyPlot(axis.AxisPosition), Title = axis.AxisTitle, Unit = axis.Unit, Key = axis.Key
                        };
                        yAxis.Tag = axis;
                        OxyPlotModel.Axes.Add(yAxis);
                    }
                    else
                    {
                        //update
                        oxaxis.Position = ConvertAxisToOxyPlot(axis.AxisPosition);
                        oxaxis.Title    = axis.AxisTitle;
                        oxaxis.Unit     = axis.Unit;
                        oxaxis.Key      = axis.Key;
                    }
                }
            }
            //"Series"
            {
                //delete removed series first.
                var toRemoveSeries = new List <OxyPlot.Series.LineSeries>();
                foreach (OxyPlot.Series.LineSeries oxseries in OxyPlotModel.Series)
                {
                    {
                        var series = PlotModel.PlotConfiguration.Series.FirstOrDefault(x => x.OxySeries == oxseries);//don't remove xaxis
                        if (series == null)
                        {
                            toRemoveSeries.Add(oxseries);
                        }
                    }
                }
                foreach (OxyPlot.Series.LineSeries oxseries in toRemoveSeries)
                {
                    OxyPlotModel.Series.Remove(oxseries);
                }

                foreach (SeriesDefinitionModel series in PlotModel.PlotConfiguration.Series)
                {
                    //can't use FirstOrDefault as OxyPlot sets default to first axis
                    OxyPlot.Series.LineSeries oxseries = null;
                    foreach (OxyPlot.Series.LineSeries os in OxyPlotModel.Series)
                    {
                        if ((AxisDefinitionModel)os.Tag == series)
                        {
                            oxseries = os;
                            break;
                        }
                    }
                    //var oxseries = OxyPlotModel.Series.FirstOrDefault(x => x.Tag == series) as OxyPlot.Series.LineSeries;
                    if (oxseries == null)
                    {
                        oxseries = new OxyPlot.Series.LineSeries
                        {
                            Title    = series.SeriesTitle,
                            Color    = OxyColor.FromArgb(series.Color.A, series.Color.R, series.Color.G, series.Color.B),
                            YAxisKey = series.YAxisKey
                        };
                        oxseries.Tag = series;
                        OxyPlotModel.Series.Add(oxseries);
                    }
                    else
                    {
                        //update
                        oxseries.Title    = series.SeriesTitle;
                        oxseries.Color    = OxyColor.FromArgb(series.Color.A, series.Color.R, series.Color.G, series.Color.B);
                        oxseries.YAxisKey = series.YAxisKey;
                    }
                }
                StringBuilder logFormat = new StringBuilder();//always have time as first parameter
                AppendLogFormatFromSeries(logFormat, PlotModel.PlotConfiguration.Series);
                PlotModel.LogFormat = logFormat.ToString();
                OnLogFormatChanged();
            }

            OxyPlotModel.InvalidatePlot(true);
        }
示例#6
0
        private bool PlotMessages()
        {
            var seriespoints = new List <List <DataPoint> >();

            foreach (SeriesDefinitionModel series in PlotModel.PlotConfiguration.Series)
            {
                seriespoints.Add(new List <DataPoint>());
            }

            foreach (string[] msg in Messages)
            {
                //Typical log statement:
                //Sample,Time,Command,Position,Output
                //printf("@F,%g,%g,%g,%g\n",tickcurr,CHANNELTOTEST->Dest,CHANNELTOTEST->Position,CHANNELTOTEST->Output);
                //where @F is the log identifier, so msg[0] == "@F", which we ignore here, data starts at index 1, which
                //is always time
                //PlotDefinition.Series.ToList().Zip(OxyPlotModel.Series, (n, w) => new { Number = n, Word = w });
                if (msg.Count() != _data.Format.LogDelimitCount)
                {
                    string errmsg = string.Format("Invalid message for this plot, format length {0:D} does not equal message length {1:D}.", _data.Format.LogDelimitCount, msg.Count());
                    LogTo.Error(errmsg);
                    Messages.Clear();
                    return(false);
                }

                double x, y1, y2;
                if (FromHex)
                {
                    LongToDouble xh = new LongToDouble(0.0d);
                    ulong.TryParse(msg[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out xh.ul);
                    x = xh.d;
                    //double dd =  0;
                    //Double.TryParse(msg[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out dd);
                }
                else
                {
                    Double.TryParse(msg[1], out x);//first param is always time, x axis
                }

                var zip = PlotModel.PlotConfiguration.Series.ToList().Zip(seriespoints, (n, w) => new { series = n, seriesPoints = w });
                foreach (var defAndSeries in zip)
                //foreach (SeriesDefinitionModel series in PlotDefinition.Series)
                {
                    if (FromHex)
                    {
                        LongToDouble y1h = new LongToDouble(0.0d);
                        ulong.TryParse(msg[defAndSeries.series.ResultIndex1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out y1h.ul);
                        y1 = y1h.d;
                    }
                    else
                    {
                        Double.TryParse(msg[defAndSeries.series.ResultIndex1], out y1);//first param is always time, x axis
                    }
                    //Double.TryParse(msg[defAndSeries.series.ResultIndex1], out y1);
                    DataPoint p = new DataPoint(x, y1);
                    if (defAndSeries.series.ResultOperator != PlotAxisOperatorEnum.None)
                    {
                        if (FromHex)
                        {
                            LongToDouble y2h = new LongToDouble(0.0d);
                            ulong.TryParse(msg[defAndSeries.series.ResultIndex2.Value], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out y2h.ul);
                            y2 = y2h.d;
                        }
                        else
                        {
                            Double.TryParse(msg[defAndSeries.series.ResultIndex2.Value], out y2);//first param is always time, x axis
                        }
                        //Double.TryParse(msg[defAndSeries.series.ResultIndex2.Value], out y2);
                        switch (defAndSeries.series.ResultOperator)
                        {
                        case PlotAxisOperatorEnum.Add:
                            p = new DataPoint(x, y1 + y2);
                            break;

                        case PlotAxisOperatorEnum.Subtract:
                            p = new DataPoint(x, y1 - y2);
                            break;

                        case PlotAxisOperatorEnum.Multiple:
                            p = new DataPoint(x, y1 * y2);
                            break;

                        case PlotAxisOperatorEnum.Divide:
                            p = new DataPoint(x, y1 / y2);
                            break;

                        default:
                            LogTo.Error("This should never happen.");
                            break;
                        }
                    }

                    defAndSeries.seriesPoints.Add(p);
                }
            }
            _dataLog.AddRange(Messages);
            Messages.Clear();

            if (seriespoints.Count > 0 && seriespoints[0] != null && seriespoints[0].Count > 0)
            {
                //Update the plot on the GUI thread
                _userInterfaceDispatcher.Invoke(() =>
                {
                    var zip = OxyPlotModel.Series.Zip(seriespoints, (n, w) => new { series = n, seriesPoints = w });
                    foreach (var seriesAndPoints in zip)
                    {
                        OxyPlot.Series.LineSeries ls = seriesAndPoints.series as OxyPlot.Series.LineSeries;
                        if (ls.Points.Count >= MaxPlotPoints)
                        {
                            ls.Points.RemoveRange(0, seriesAndPoints.seriesPoints.Count);
                        }
                        ls.Points.AddRange(seriesAndPoints.seriesPoints);
                    }
                    OxyPlotModel.InvalidatePlot(true);
                });
            }
            return(true);
        }