Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        private void CreatePlot(string plotImage, ParameterCollection parameters, ICircuitContext context, Simulation simulation)
        {
            var           plot    = new XyPlot(simulation.Name);
            List <Export> exports = GenerateExports(parameters, simulation, context);

            foreach (var export in exports)
            {
                plot.Series.Add(new Series(export.Name));
            }

            simulation.ExportSimulationData += (sender, args) => CreatePointForSeries(simulation, context, args, exports, plot.Series);
            simulation.AfterExecute         += (sender, args) => AddPlotToResultIfValid(plotImage, context, plot, simulation);
        }
Ejemplo n.º 3
0
 public static bool IsPlotPositive(XyPlot plot)
 {
     for (var i = 0; i < plot.Series.Count; i++)
     {
         for (var j = 0; j < plot.Series[i].Points.Count; j++)
         {
             var y = plot.Series[i].Points[j].Y;
             if (y <= 0)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Ejemplo n.º 4
0
        public XyPlotViewModel(XyPlot plot)
        {
            rand = new Random(Environment.TickCount);

            Series = new Series[plot.Series.Count];
            for (var i = 0; i < Series.Length; i++)
            {
                Series[i] = new Series()
                {
                    Name = plot.Series[i].Name, Selected = true
                };
            }

            YScaleLogEnabled = SpiceHelper.IsPlotPositive(plot);
            OxyPlotModel     = CreateOxyPlotModel(plot);
        }
Ejemplo n.º 5
0
        private void CreateAcSweepPlot(string variableName, List <Export> exports, ICircuitContext context)
        {
            var plot = new XyPlot("AC - Parameter sweep: " + variableName);

            foreach (var export in exports)
            {
                var series = new Series(export.Simulation.Name)
                {
                    XUnit = "Freq (parameter)",
                    YUnit = export.QuantityUnit,
                };
                AddAcPointsToSeries(export, series);

                plot.Series.Add(series);
            }

            context.Result.AddPlot(plot);
        }
Ejemplo n.º 6
0
        private void CreateOpSweepPlot(Context.Sweeps.ParameterSweep firstParameterSweep, string variableName, List <Export> exports, ICircuitContext context)
        {
            var plot = new XyPlot("OP - Parameter sweep: " + variableName);

            foreach (var export in exports)
            {
                var series = new Series(export.Simulation.Name)
                {
                    XUnit = firstParameterSweep.Parameter.Image,
                    YUnit = export.QuantityUnit,
                };
                AddOpPointToSeries(firstParameterSweep, export, context, series);

                plot.Series.Add(series);
            }

            context.Result.AddPlot(plot);
        }
Ejemplo n.º 7
0
        private void CreatePlot(string plotImage, ParameterCollection parameters, ICircuitContext context, IEnumerable <Simulation> simulations)
        {
            var plot = new XyPlot($"Merged: {plotImage}");

            foreach (var simulation in simulations)
            {
                List <Export> exports = GenerateExports(parameters, simulation, context);

                List <Series> series = new List <Series>();
                foreach (var export in exports)
                {
                    series.Add(new Series($"{simulation.Name} {export.Name}"));
                }

                plot.Series.AddRange(series);
                simulation.ExportSimulationData += (sender, args) => CreatePointForSeries(simulation, context, args, exports, series);
            }

            context.Result.AddPlot(plot);
        }
Ejemplo n.º 8
0
        private void CreateAxis(XyPlot plot, PlotModel tmp)
        {
            if (plot.Series.Count > 0)
            {
                string xUnit = plot.Series[0].XUnit;
                string yUnit = plot.Series[0].YUnit;

                tmp.Axes.Clear();

                if (XScaleLog)
                {
                    tmp.Axes.Add(new LogarithmicAxis {
                        Position = AxisPosition.Bottom, Unit = xUnit
                    });
                }
                else
                {
                    tmp.Axes.Add(new LinearAxis {
                        Position = AxisPosition.Bottom, Unit = xUnit
                    });
                }

                if (YScaleLog)
                {
                    tmp.Axes.Add(new LogarithmicAxis {
                        Position = AxisPosition.Left, Unit = yUnit
                    });
                }
                else
                {
                    tmp.Axes.Add(new LinearAxis {
                        Position = AxisPosition.Left, Unit = yUnit
                    });
                }
            }
        }
Ejemplo n.º 9
0
        private void AddPlotToResultIfValid(string plotImage, ICircuitContext context, XyPlot plot, Simulation simulation)
        {
            for (int i = plot.Series.Count - 1; i >= 0; i--)
            {
                Series series = plot.Series[i];
                if (series.Points.Count == 0)
                {
                    plot.Series.RemoveAt(i);
                }
            }

            if (plot.Series.Count > 0)
            {
                context.Result.AddPlot(plot);
            }
            else
            {
                context.Result.Validation.Add(new ValidationEntry(ValidationEntrySource.Reader, ValidationEntryLevel.Warning, $"{plotImage} is not valid for: {simulation.Name}"));
            }
        }