public static unsafe void DrawScatterSeries1(IntPtr pointer, List <Point2> data, MarkerType mkty, double mksize, byte r, byte g, byte b)
        {
            GCHandle handle = GCHandle.FromIntPtr(pointer);

            if (handle.IsAllocated)
            {
                PlotModel model = handle.Target as PlotModel;
                if (model != null)
                {
                    List <double> ydata = new List <double>();
                    List <double> xdata = new List <double>();
                    for (int i = 0; i < data.Count; i++)
                    {
                        xdata.Add((double)data[i].X);
                        ydata.Add((double)data[i].Y);
                    }

                    List <double> txdata = new List <double>();
                    List <double> tydata = new List <double>();

                    txdata.Add(xdata[0]);
                    tydata.Add(ydata[0]);

                    for (int i = 1; i < data.Count; i++)
                    {
                        if (xdata[i] - xdata[i - 1] > 1.5)
                        {
                            if (txdata.Count > 0)
                            {
                                model.AddLineSeries(txdata, tydata, OxyColor.FromRgb(r, g, b), LineStyle.Dash);
                                txdata.Clear();
                                tydata.Clear();
                            }
                            txdata.Add(xdata[i]);
                            tydata.Add(ydata[i]);
                        }
                        else
                        {
                            txdata.Add(xdata[i]);
                            tydata.Add(ydata[i]);
                        }
                    }

                    if (txdata.Count > 0)
                    {
                        model.AddLineSeries(txdata, tydata, OxyColor.FromRgb(r, g, b), LineStyle.Dash);
                        txdata.Clear();
                        tydata.Clear();
                    }

                    model.AddScatterSeries(xdata, ydata, OxyColor.FromRgb(r, g, b), mkty, mksize);
                }
            }
        }
Ejemplo n.º 2
0
        OxyPlot.PlotModel CreateColumnResultsModel(double[] x, double[] y, string xtitle, string ytitle)
        {
            var model = new PlotModel()
            {
                Subtitle = "Column Profile", Title = SimObject.GraphicObject.Tag
            };

            model.TitleFontSize    = 14;
            model.SubtitleFontSize = 11;
            model.Axes.Add(new LinearAxis()
            {
                MajorGridlineStyle = LineStyle.Dash,
                MinorGridlineStyle = LineStyle.Dot,
                Position           = AxisPosition.Bottom,
                FontSize           = 12,
                Title = xtitle
            });
            if (Math.Abs(y[0] - 1.0f) < 0.0001)
            {
                model.Axes.Add(new LinearAxis()
                {
                    MajorGridlineStyle = LineStyle.Dash,
                    MinorGridlineStyle = LineStyle.Dot,
                    Position           = AxisPosition.Left,
                    FontSize           = 12,
                    Title         = ytitle,
                    StartPosition = 1,
                    EndPosition   = 0,
                    MajorStep     = 1.0f,
                    MinorStep     = 0.5f
                });
            }
            else
            {
                model.Axes.Add(new LinearAxis()
                {
                    MajorGridlineStyle = LineStyle.Dash,
                    MinorGridlineStyle = LineStyle.Dot,
                    Position           = AxisPosition.Left,
                    FontSize           = 12,
                    Title = ytitle
                });
            }
            model.LegendFontSize           = 11;
            model.LegendPlacement          = LegendPlacement.Outside;
            model.LegendOrientation        = LegendOrientation.Vertical;
            model.LegendPosition           = LegendPosition.BottomCenter;
            model.TitleHorizontalAlignment = TitleHorizontalAlignment.CenteredWithinView;
            model.AddLineSeries(x, y);

            return(model);
        }
        public static unsafe void DrawLineSeries(IntPtr pointer, List <double> data, byte r, byte g, byte b)
        {
            GCHandle handle = GCHandle.FromIntPtr(pointer);

            if (handle.IsAllocated)
            {
                PlotModel model = handle.Target as PlotModel;
                if (model != null)
                {
                    List <double> xdata = Enumerable.Range(0, data.Count - 1).Select(x => (double)x).ToList();
                    model.AddLineSeries(xdata, data, OxyColor.FromRgb(r, g, b), MarkerType.None, 1.0);
                }
            }
        }
        public static unsafe void DrawLineSeries(IntPtr pointer, float *data, int length, byte r, byte g, byte b)
        {
            GCHandle handle = GCHandle.FromIntPtr(pointer);

            if (handle.IsAllocated)
            {
                PlotModel model = handle.Target as PlotModel;
                if (model != null)
                {
                    List <double> ydata = new List <double>();
                    List <double> xdata = Enumerable.Range(0, length - 1).Select(x => (double)x).ToList();
                    for (int i = 0; i < length; i++)
                    {
                        ydata.Add((double)data[i]);
                    }
                    model.AddLineSeries(xdata, ydata, OxyColor.FromRgb(r, g, b), MarkerType.None, 1.0);
                }
            }
        }
Ejemplo n.º 5
0
        OxyPlot.PlotModel CreatePFRResultsModel(Reactor_PFR reactor)
        {
            var su = SimObject.GetFlowsheet().FlowsheetOptions.SelectedUnitSystem;

            var model = new PlotModel()
            {
                Subtitle = "Properties Profile", Title = SimObject.GraphicObject.Tag
            };

            model.TitleFontSize    = 14;
            model.SubtitleFontSize = 11;
            model.Axes.Add(new LinearAxis()
            {
                MajorGridlineStyle = LineStyle.Dash,
                MinorGridlineStyle = LineStyle.Dot,
                Position           = AxisPosition.Bottom,
                FontSize           = 12,
                Title = "Reactor Length (" + su.distance + ")"
            });
            model.Axes.Add(new LinearAxis()
            {
                MajorGridlineStyle = LineStyle.Dash,
                MinorGridlineStyle = LineStyle.Dot,
                Position           = AxisPosition.Left,
                FontSize           = 12,
                Title = "Concentration (" + su.molar_conc + ")",
                Key   = "conc"
            });
            model.Axes.Add(new LinearAxis()
            {
                MajorGridlineStyle = LineStyle.Dash,
                MinorGridlineStyle = LineStyle.Dot,
                Position           = AxisPosition.Right,
                FontSize           = 12,
                Title        = "Temperature (" + su.temperature + ")",
                Key          = "temp",
                PositionTier = 0
            });
            model.Axes.Add(new LinearAxis()
            {
                MajorGridlineStyle = LineStyle.Dash,
                MinorGridlineStyle = LineStyle.Dot,
                Position           = AxisPosition.Right,
                FontSize           = 12,
                Title        = "Pressure (" + su.pressure + ")",
                Key          = "press",
                PositionTier = 1
            });

            model.LegendFontSize           = 11;
            model.LegendPlacement          = LegendPlacement.Outside;
            model.LegendOrientation        = LegendOrientation.Horizontal;
            model.LegendPosition           = LegendPosition.BottomCenter;
            model.TitleHorizontalAlignment = TitleHorizontalAlignment.CenteredWithinView;

            List <double>         vx = new List <double>(), vy = new List <double>();
            List <List <double> > vya = new List <List <double> >();
            List <string>         vn  = new List <string>();

            foreach (var obj in reactor.points)
            {
                vx.Add(((double[])obj)[0]);
            }
            int j;

            for (j = 1; j <= reactor.ComponentConversions.Count + 2; j++)
            {
                vy = new List <double>();
                foreach (var obj in reactor.points)
                {
                    vy.Add(((double[])obj)[j]);
                }
                vya.Add(vy);
            }
            foreach (var st in reactor.ComponentConversions.Keys)
            {
                vn.Add(st);
            }
            OxyColor color;

            for (j = 0; j <= vn.Count - 1; j++)
            {
                color = OxyColor.FromRgb(Convert.ToByte(new Random().Next(0, 255)), Convert.ToByte(new Random().Next(0, 255)), Convert.ToByte(new Random().Next(0, 255)));
                model.AddLineSeries(cv.ConvertArrayFromSI(su.volume, vx.ToArray()), cv.ConvertArrayFromSI(su.molar_conc, vya[j].ToArray()), color);
                model.Series[model.Series.Count - 1].Title = vn[j];
                ((OxyPlot.Series.LineSeries)(model.Series[model.Series.Count - 1])).YAxisKey = "conc";
            }
            color = OxyColor.FromRgb(Convert.ToByte(new Random().Next(0, 255)), Convert.ToByte(new Random().Next(0, 255)), Convert.ToByte(new Random().Next(0, 255)));
            model.AddLineSeries(cv.ConvertArrayFromSI(su.volume, vx.ToArray()), cv.ConvertArrayFromSI(su.temperature, vya[j].ToArray()), color);
            model.Series[model.Series.Count - 1].Title = "Temperature";
            ((OxyPlot.Series.LineSeries)(model.Series[model.Series.Count - 1])).YAxisKey = "temp";
            color = OxyColor.FromRgb(Convert.ToByte(new Random().Next(0, 255)), Convert.ToByte(new Random().Next(0, 255)), Convert.ToByte(new Random().Next(0, 255)));
            model.AddLineSeries(cv.ConvertArrayFromSI(su.volume, vx.ToArray()), cv.ConvertArrayFromSI(su.pressure, vya[j + 1].ToArray()), color);
            model.Series[model.Series.Count - 1].Title = "Pressure";
            ((OxyPlot.Series.LineSeries)(model.Series[model.Series.Count - 1])).YAxisKey = "press";

            return(model);
        }
Ejemplo n.º 6
0
 public static void AddLineSeries(this PlotModel model, IEnumerable <DateTime> xSeries, IEnumerable <double> ySeries, OxyColor color)
 {
     model.Axes.Add(new DateTimeAxis());
     model.AddLineSeries(xSeries.Select(x => DateTimeAxis.ToDouble(x)), ySeries);
 }
Ejemplo n.º 7
0
 public static void AddLineSeries(this PlotModel model, IEnumerable <DateTime> xSeries, IEnumerable <double> ySeries)
 {
     model.AddLineSeries(xSeries, ySeries, OxyColors.Automatic);
 }
Ejemplo n.º 8
0
        void Init()
        {
            DynamicLayout p1, p2;

            StackLayout t1;

            p1 = UI.Shared.Common.GetDefaultContainer();
            p2 = UI.Shared.Common.GetDefaultContainer();

            p1.Width = 380;
            p2.Width = 380;

            t1 = new StackLayout();
            t1.Items.Add(new StackLayoutItem(p1));
            t1.Items.Add(new StackLayoutItem(p2));
            t1.Orientation = Orientation.Horizontal;

            Padding = new Padding(10);

            if (flowsheet.SensAnalysisCollection.Count == 0)
            {
                flowsheet.SensAnalysisCollection.Add(new DWSIM.SharedClasses.Flowsheet.Optimization.SensitivityAnalysisCase());
            }

            mycase = flowsheet.SensAnalysisCollection.First();

            var su = flowsheet.FlowsheetOptions.SelectedUnitSystem;
            var nf = flowsheet.FlowsheetOptions.NumberFormat;

            s.CreateAndAddLabelRow2(this, "Use the Sensitivity Analysis tool to study/analyze the influence of a process variable on other variables in the flowsheet.");

            this.Add(t1);

            s.CreateAndAddLabelRow(p1, "Case ID");
            s.CreateAndAddFullTextBoxRow(p1, mycase.name, (arg3, arg2) => { mycase.name = arg3.Text; });

            s.CreateAndAddLabelRow(p1, "Case Description");
            s.CreateAndAddFullTextBoxRow(p1, mycase.description, (arg3, arg2) => { mycase.description = arg3.Text; });

            s.CreateAndAddLabelRow(p1, "Independent Variable");

            var objlist = flowsheet.SimulationObjects.Values.Select((x2) => x2.GraphicObject.Tag).ToList();

            objlist.Insert(0, "");

            var spinner = s.CreateAndAddDropDownRow(p1, "Object", objlist, 0, null);

            var spinner2 = s.CreateAndAddDropDownRow(p1, "Property", new List <string>(), 0, null);

            List <string> proplist = new List <string>();

            spinner.SelectedIndexChanged += (sender, e) =>
            {
                if (spinner.SelectedIndex > 0)
                {
                    mycase.iv1.objectID  = flowsheet.GetFlowsheetSimulationObject(objlist[spinner.SelectedIndex]).Name;
                    mycase.iv1.objectTAG = objlist[spinner.SelectedIndex];
                    proplist             = flowsheet.GetFlowsheetSimulationObject(objlist[spinner.SelectedIndex]).GetProperties(PropertyType.WR).ToList();
                    proplist.Insert(0, "");
                    spinner2.Items.Clear();
                    spinner2.Items.AddRange(proplist.Select(x => new ListItem {
                        Key = x, Text = flowsheet.GetTranslatedString(x)
                    }).ToList());
                    spinner2.SelectedIndex = (proplist.IndexOf(mycase.iv1.propID));
                }
                else
                {
                    spinner2.Items.Clear();
                }
            };
            if (flowsheet.SimulationObjects.ContainsKey(mycase.iv1.objectID))
            {
                spinner.SelectedIndex = (objlist.IndexOf(flowsheet.SimulationObjects[mycase.iv1.objectID].GraphicObject.Tag));
            }

            var txtLowerLimit = s.CreateAndAddTextBoxRow(p1, nf, "Initial Value", 0, null);
            var txtUpperLimit = s.CreateAndAddTextBoxRow(p1, nf, "Final Value", 0, null);
            var txtSteps      = s.CreateAndAddTextBoxRow(p1, "0", "Number of Steps", 0, null);

            txtLowerLimit.Text = mycase.iv1.lowerlimit.GetValueOrDefault().ToString(nf);
            txtUpperLimit.Text = mycase.iv1.upperlimit.GetValueOrDefault().ToString(nf);
            txtSteps.Text      = mycase.iv1.points.ToString();

            var labelUnits = s.CreateAndAddTwoLabelsRow(p1, "Property Units", "");

            spinner2.SelectedIndexChanged += (sender, e) =>
            {
                if (spinner2.SelectedIndex > 0)
                {
                    mycase.iv1.propID = proplist[spinner2.SelectedIndex];
                    mycase.iv1.unit   = flowsheet.GetFlowsheetSimulationObject(objlist[spinner.SelectedIndex]).GetPropertyUnit(proplist[spinner2.SelectedIndex], su);
                    labelUnits.Text   = mycase.iv1.unit;
                }
            };

            double dummy = 0.0f;

            txtLowerLimit.TextChanged += (sender2, e2) =>
            {
                if (double.TryParse(txtLowerLimit.Text.ToString(), out dummy))
                {
                    mycase.iv1.lowerlimit = Double.Parse(txtLowerLimit.Text);
                }
            };

            txtUpperLimit.TextChanged += (sender2, e2) =>
            {
                if (double.TryParse(txtUpperLimit.Text.ToString(), out dummy))
                {
                    mycase.iv1.upperlimit = Double.Parse(txtUpperLimit.Text);
                }
            };

            txtSteps.TextChanged += (sender2, e2) =>
            {
                if (double.TryParse(txtSteps.Text.ToString(), out dummy))
                {
                    mycase.iv1.points = Int32.Parse(txtSteps.Text);
                }
            };

            s.CreateAndAddEmptySpace(p1);
            s.CreateAndAddEmptySpace(p1);
            s.CreateAndAddEmptySpace(p1);
            s.CreateAndAddEmptySpace(p1);
            s.CreateAndAddEmptySpace(p1);
            s.CreateAndAddEmptySpace(p1);

            var btnAddDepVar = s.CreateAndAddBoldLabelAndButtonRow(p2, "Dependent Variables", "Add New", null, null);

            var ll = new StackLayout {
                Orientation = Orientation.Vertical, Padding = new Eto.Drawing.Padding(2), Spacing = 10
            };

            ll.RemoveAll();

            var sc = new Scrollable {
                Border = BorderType.None, Content = ll
            };

            s.CreateAndAddControlRow(p2, sc);

            t1.SizeChanged += (sender, e) => {
                if (p1.ParentWindow != null)
                {
                    p1.Width  = (int)(p1.ParentWindow.Width / 2 - 10);
                    p2.Width  = (int)(p2.ParentWindow.Width / 2 - 10);
                    p1.Height = p1.ParentWindow.Height - 170;
                    p2.Height = p1.Height;
                    sc.Height = p2.Height - btnAddDepVar.Height - 30;
                    foreach (var item in ll.Items)
                    {
                        item.Control.Width = sc.Width - 25;
                    }
                }
            };

            foreach (var dvar in mycase.depvariables.Values)
            {
                AddDepVar(ll, dvar, objlist);
            }

            btnAddDepVar.Click += (sender2, e2) =>
            {
                var depvar = new DWSIM.SharedClasses.Flowsheet.Optimization.SAVariable();
                depvar.id = Guid.NewGuid().ToString();
                mycase.depvariables.Add(depvar.id, depvar);
                AddDepVar(ll, depvar, objlist);
            };

            var btnRun = s.CreateAndAddButtonRow(this, "Run Analysis", null, null);

            var btnAbort = s.CreateAndAddButtonRow(this, "Abort Run", null, null);

            btnAbort.Enabled = false;

            resulttextbox = new TextArea {
                Height = 400, Text = "", Font = Fonts.Monospace(GlobalSettings.Settings.ResultsReportFontSize), ReadOnly = true
            };

            s.CreateAndAddLabelRow(this, "Results");

            var btnrt = s.CreateAndAddLabelAndButtonRow(this, "View Results Report", "View Report", null, (sender, e) =>
            {
                var form = s.GetDefaultEditorForm("Sensitivity Analysis Report", 500, 500, resulttextbox, true);
                form.Show();
            });

            btnrt.Enabled = false;

            resultschart = new Eto.OxyPlot.Plot {
                Height = 400
            };

            var btnrc = s.CreateAndAddLabelAndButtonRow(this, "View Results Chart", "View Chart", null, (sender, e) =>
            {
                var form = s.GetDefaultEditorForm("Sensitivity Analysis Result", 500, 500, resultschart, true);
                form.Show();
            });

            btnrc.Enabled = false;

            btnRun.Click += (sender2, e2) =>
            {
                int    iv1np, i;
                double iv1ll, iv1ul, iv1val, iv1val0;
                string iv1id, iv1prop;
                List <List <double> > results = new List <List <double> >();

                iv1ll   = Converter.ConvertToSI(mycase.iv1.unit, mycase.iv1.lowerlimit.GetValueOrDefault());
                iv1ul   = Converter.ConvertToSI(mycase.iv1.unit, mycase.iv1.upperlimit.GetValueOrDefault());
                iv1np   = mycase.iv1.points - 1;
                iv1id   = mycase.iv1.objectID;
                iv1prop = mycase.iv1.propID;

                flowsheet.SupressMessages = true;

                Application.Instance.Invoke(() =>
                {
                    btnAbort.Enabled = true;
                    btnrt.Enabled    = false;
                    btnrc.Enabled    = false;
                    flowsheet.ShowMessage("Starting Sensitivity Analysis, please wait...", IFlowsheet.MessageType.Information);
                });

                var task = new Task(() =>
                {
                    flowsheet.SolveFlowsheet(true);

                    iv1val0 = Convert.ToDouble(flowsheet.SimulationObjects[iv1id].GetPropertyValue(iv1prop));

                    for (i = 0; i <= iv1np; i++)
                    {
                        iv1val = iv1ll + i * (iv1ul - iv1ll) / iv1np;
                        flowsheet.SimulationObjects[iv1id].SetPropertyValue(iv1prop, iv1val);
                        flowsheet.SolveFlowsheet(true);
                        List <double> depvarvals = new List <double>();
                        foreach (var depvar in mycase.depvariables.Values)
                        {
                            depvar.currentvalue = Convert.ToDouble(flowsheet.SimulationObjects[depvar.objectID].GetPropertyValue(depvar.propID));
                            depvarvals.Add(depvar.currentvalue);
                        }
                        results.Add(depvarvals);
                    }

                    mycase.results = new System.Collections.ArrayList();

                    foreach (var res in results)
                    {
                        mycase.results.Add(res.ToArray());
                    }

                    flowsheet.SimulationObjects[iv1id].SetPropertyValue(iv1prop, iv1val0);
                    flowsheet.SolveFlowsheet(true);
                }, GlobalSettings.Settings.TaskCancellationTokenSource.Token);

                task.ContinueWith((t) =>
                {
                    flowsheet.SupressMessages = false;

                    if (t.Exception != null)
                    {
                        Application.Instance.Invoke(() =>
                        {
                            btnAbort.Enabled = false;
                            btnrt.Enabled    = false;
                            btnrc.Enabled    = false;

                            flowsheet.ShowMessage("Error: " + t.Exception.Message, IFlowsheet.MessageType.GeneralError);
                        });
                    }
                    else
                    {
                        Application.Instance.Invoke(() =>
                        {
                            btnAbort.Enabled = false;
                            btnrt.Enabled    = true;
                            btnrc.Enabled    = true;

                            flowsheet.ShowMessage("Sensitivity Analysis finished successfully.", IFlowsheet.MessageType.Information);
                            if (t.Status == TaskStatus.RanToCompletion)
                            {
                                var str = new System.Text.StringBuilder();
                                str.AppendLine("Sensitivity Analysis Run Results");
                                str.AppendLine();
                                str.AppendLine("Independent Variable: " + flowsheet.SimulationObjects[iv1id].GraphicObject.Tag + " / " + flowsheet.GetTranslatedString(mycase.iv1.propID));
                                str.AppendLine();
                                str.AppendLine("Range: " + mycase.iv1.lowerlimit.GetValueOrDefault() + " to " + mycase.iv1.upperlimit.GetValueOrDefault() + " " + mycase.iv1.unit + ", " + mycase.iv1.points + " steps");
                                str.AppendLine();
                                str.AppendLine("Dependent Variables:");
                                int count = 1;
                                str.AppendLine();
                                foreach (var dvar in mycase.depvariables.Values)
                                {
                                    str.AppendLine(count + " - " + flowsheet.SimulationObjects[dvar.objectID].GraphicObject.Tag + " / " + flowsheet.GetTranslatedString(dvar.propID) + " (" + dvar.unit + ")");
                                    count += 1;
                                }
                                str.AppendLine();
                                str.AppendLine("Ind var\t\tDep. vars");
                                int cnt                  = 0;
                                List <double> px         = new List <double>();
                                List <List <double> > py = new List <List <double> >();
                                foreach (var dvar in mycase.depvariables.Values)
                                {
                                    py.Add(new List <double>());
                                }
                                foreach (double[] res in mycase.results)
                                {
                                    var dv = Converter.ConvertFromSI(mycase.iv1.unit, iv1ll + cnt * (iv1ul - iv1ll) / iv1np);
                                    px.Add(dv);
                                    string line = dv.ToString(nf) + "\t\t";
                                    int j       = 0;
                                    foreach (var d in res)
                                    {
                                        py[j].Add(Converter.ConvertFromSI(mycase.depvariables.Values.ElementAt(j).unit, d));
                                        line += Converter.ConvertFromSI(mycase.depvariables.Values.ElementAt(j).unit, d).ToString(nf) + "\t\t";
                                        j    += 1;
                                    }
                                    str.AppendLine(line);
                                    cnt += 1;
                                }

                                Application.Instance.Invoke(() => resulttextbox.Text = str.ToString());

                                var model = new PlotModel()
                                {
                                    Subtitle = "Sensitivity Analysis Run Results", Title = flowsheet.FlowsheetOptions.SimulationName
                                };
                                model.TitleFontSize    = 14;
                                model.SubtitleFontSize = 11;
                                model.Axes.Add(new LinearAxis()
                                {
                                    MajorGridlineStyle = LineStyle.Dash,
                                    MinorGridlineStyle = LineStyle.Dot,
                                    Position           = AxisPosition.Bottom,
                                    FontSize           = 12,
                                    Title = mycase.iv1.objectTAG + " / " + flowsheet.GetTranslatedString(mycase.iv1.propID) + " (" + mycase.iv1.unit + ")"
                                });
                                int cnt2 = 0;
                                foreach (var dvar in mycase.depvariables.Values)
                                {
                                    model.Axes.Add(new LinearAxis()
                                    {
                                        MajorGridlineStyle = LineStyle.Dash,
                                        MinorGridlineStyle = LineStyle.Dot,
                                        FontSize           = 12,
                                        Title = dvar.objectTAG + " / " + flowsheet.GetTranslatedString(dvar.propID) + " (" + dvar.unit + ")"
                                    });
                                    model.Axes[cnt2 + 1].Key           = cnt2.ToString();
                                    model.Axes[cnt2 + 1].PositionTier  = cnt2;
                                    model.Axes[cnt2 + 1].AxislineStyle = LineStyle.Solid;
                                    model.AddLineSeries(px, py[cnt2]);
                                    model.Series[cnt2].Title = dvar.objectTAG + " / " + flowsheet.GetTranslatedString(dvar.propID);
                                    ((OxyPlot.Series.LineSeries)(model.Series[cnt2])).YAxisKey = cnt2.ToString();
                                    cnt2 += 1;
                                }
                                model.LegendFontSize           = 11;
                                model.LegendPlacement          = LegendPlacement.Outside;
                                model.LegendOrientation        = LegendOrientation.Vertical;
                                model.LegendPosition           = LegendPosition.BottomCenter;
                                model.TitleHorizontalAlignment = TitleHorizontalAlignment.CenteredWithinView;

                                Application.Instance.Invoke(() => { resultschart.Model = model; resultschart.Invalidate(); });
                            }
                        });
                    }
                });

                btnAbort.Click += (sender, e) =>
                {
                    GlobalSettings.Settings.TaskCancellationTokenSource.Cancel();
                };

                task.Start();
            };
        }
Ejemplo n.º 9
0
        public void UpdatePlotModelData()
        {
            try
            {
                if (Chart.PlotModel != null)
                {
                    if ((Chart.ChartSource == ChartSource.FlowsheetObject))
                    {
                        if (Chart.ChartSourceObjectAutoUpdate)
                        {
                            Chart.PlotModel = Flowsheet.SimulationObjects[Chart.ChartSourceObjectID].GetChartModel(Chart.ChartSourceObjectChartID);
                        }
                    }
                    else
                    {
                        PlotModel pm = (PlotModel)Chart.PlotModel;
                        if (((pm.Series.Count != Chart.SpreadsheetDataSourcesX.Count) &&
                             (pm.Series.Count != Chart.SpreadsheetDataSourcesY.Count)))
                        {
                            pm.Series.Clear();
                            List <List <double> > xnumbers = new List <List <double> >();
                            List <List <double> > ynumbers = new List <List <double> >();
                            foreach (var item in Chart.SpreadsheetDataSourcesX)
                            {
                                List <double> xlist = new List <double>();
                                var           sheet = Spreadsheet.GetWorksheetByName(item.Split('!')[0]);
                                object[,] data = sheet.GetRangeData(new RangePosition(item.Split('!')[1]));
                                if ((data.GetLength(0) > 1))
                                {
                                    int j = 0;
                                    for (j = 0; (j
                                                 <= (data.GetLength(0) - 1)); j++)
                                    {
                                        double d = 0;
                                        double.TryParse(data[j, 0].ToString(), out d);
                                        xlist.Add(d);
                                    }
                                }
                                else if ((data.GetLength(1) > 1))
                                {
                                    int j = 0;
                                    for (j = 0; (j
                                                 <= (data.GetLength(1) - 1)); j++)
                                    {
                                        double d = 0;
                                        double.TryParse(data[0, j].ToString(), out d);
                                        xlist.Add(d);
                                    }
                                }

                                xnumbers.Add(xlist);
                            }

                            foreach (var item in Chart.SpreadsheetDataSourcesY)
                            {
                                List <double> ylist = new List <double>();
                                var           sheet = Spreadsheet.GetWorksheetByName(item.Split('!')[0]);
                                object[,] data = sheet.GetRangeData(new RangePosition(item.Split('!')[1]));
                                if ((data.GetLength(0) > 1))
                                {
                                    int j = 0;
                                    for (j = 0; (j
                                                 <= (data.GetLength(0) - 1)); j++)
                                    {
                                        double d = 0;
                                        double.TryParse(data[j, 0].ToString(), out d);
                                        ylist.Add(d);
                                    }
                                }
                                else if ((data.GetLength(1) > 1))
                                {
                                    int j = 0;
                                    for (j = 0; (j
                                                 <= (data.GetLength(1) - 1)); j++)
                                    {
                                        double d = 0;
                                        double.TryParse(data[0, j].ToString(), out d);
                                        ylist.Add(d);
                                    }
                                }

                                ynumbers.Add(ylist);
                            }

                            for (int i = 0; (i
                                             <= (xnumbers.Count - 1)); i++)
                            {
                                pm.AddLineSeries(xnumbers[i], ynumbers[i], ("Series" + (i + 1).ToString()));
                            }
                        }
                        else
                        {
                            List <List <double> > xnumbers = new List <List <double> >();
                            List <List <double> > ynumbers = new List <List <double> >();
                            foreach (var item in Chart.SpreadsheetDataSourcesX)
                            {
                                List <double> xlist = new List <double>();
                                var           sheet = Spreadsheet.GetWorksheetByName(item.Split('!')[0]);
                                object[,] data = sheet.GetRangeData(new RangePosition(item.Split('!')[1]));
                                if ((data.GetLength(0) > 1))
                                {
                                    int j = 0;
                                    for (j = 0; (j
                                                 <= (data.GetLength(0) - 1)); j++)
                                    {
                                        double d = 0;
                                        double.TryParse(data[j, 0].ToString(), out d);
                                        xlist.Add(d);
                                    }
                                }
                                else if ((data.GetLength(1) > 1))
                                {
                                    int j = 0;
                                    for (j = 0; (j
                                                 <= (data.GetLength(1) - 1)); j++)
                                    {
                                        double d = 0;
                                        double.TryParse(data[0, j].ToString(), out d);
                                        xlist.Add(d);
                                    }
                                }

                                xnumbers.Add(xlist);
                            }

                            foreach (var item in Chart.SpreadsheetDataSourcesY)
                            {
                                List <double> ylist = new List <double>();
                                var           sheet = Spreadsheet.GetWorksheetByName(item.Split('!')[0]);
                                object[,] data = sheet.GetRangeData(new RangePosition(item.Split('!')[1]));
                                if ((data.GetLength(0) > 1))
                                {
                                    int j = 0;
                                    for (j = 0; (j
                                                 <= (data.GetLength(0) - 1)); j++)
                                    {
                                        double d = 0;
                                        double.TryParse(data[j, 0].ToString(), out d);
                                        ylist.Add(d);
                                    }
                                }
                                else if ((data.GetLength(1) > 1))
                                {
                                    int j = 0;
                                    for (j = 0; (j
                                                 <= (data.GetLength(1) - 1)); j++)
                                    {
                                        double d = 0;
                                        double.TryParse(data[0, j].ToString(), out d);
                                        ylist.Add(d);
                                    }
                                }

                                ynumbers.Add(ylist);
                            }

                            for (int i = 0; (i
                                             <= (xnumbers.Count - 1)); i++)
                            {
                                LineSeries lineSeries = (LineSeries)pm.Series[i];
                                lineSeries.Points.Clear();
                                for (int j = 0; (j
                                                 <= (xnumbers[i].Count - 1)); j++)
                                {
                                    lineSeries.Points.Add(new DataPoint(xnumbers[i][j], ynumbers[i][j]));
                                }
                            }
                        }
                    }

                    PlotModel pm2 = (PlotModel)Chart.PlotModel;

                    pm2.InvalidatePlot(true);
                    ChartView.Model = pm2;
                    ChartView.Invalidate();
                }
            }
            catch (Exception ex)
            {
                Flowsheet.ShowMessage("Error updating chart data: " + ex.Message, Interfaces.IFlowsheet.MessageType.GeneralError);
            }
        }