예제 #1
0
        private void CreatePageOfGraphs(string sim, Graph[] graphs)
        {
            IStorageReader storage = GetStorage();
            GraphTab       tab     = new GraphTab(sim, this.presenter);

            for (int i = 0; i < graphs.Length; i++)
            {
                Graph graph = ReflectionUtilities.Clone(graphs[i]) as Graph;
                graph.Parent = panel;
                graph.ParentAllDescendants();

                if (panel.LegendOutsideGraph)
                {
                    graph.LegendOutsideGraph = true;
                }

                if (panel.LegendOrientation != GraphPanel.LegendOrientationType.Default)
                {
                    graph.LegendOrientation = (LegendOrientation)Enum.Parse(typeof(LegendOrientation), panel.LegendOrientation.ToString());
                }

                if (graph != null && graph.Enabled)
                {
                    // Apply transformation to graph.
                    panel.Script.TransformGraph(graph, sim);

                    if (panel.LegendPosition != GraphPanel.LegendPositionType.Default)
                    {
                        graph.LegendPosition = (LegendPosition)Enum.Parse(typeof(LegendPosition), panel.LegendPosition.ToString());
                    }

                    // Create and fill cache entry if it doesn't exist.
                    if (!panel.Cache.ContainsKey(sim) || panel.Cache[sim].Count <= i)
                    {
                        if (!storage.TryGetSimulationID(sim, out int _))
                        {
                            throw new Exception($"Illegal simulation name: '{sim}'. Try running the simulation, and if that doesn't fix it, there is a problem with your config script.");
                        }

                        var graphPage = new GraphPage();
                        graphPage.Graphs.Add(graph);
                        var definitions = graphPage.GetAllSeriesDefinitions(panel, storage, new List <string>()
                        {
                            sim
                        }).ToList();

                        if (!panel.Cache.ContainsKey(sim))
                        {
                            panel.Cache.Add(sim, new Dictionary <int, List <SeriesDefinition> >());
                        }

                        panel.Cache[sim][i] = definitions[0].SeriesDefinitions;
                    }
                    tab.AddGraph(graph, panel.Cache[sim][i]);
                }

                if (processingThread.CancellationPending)
                {
                    return;
                }
            }

            this.graphs.Add(tab);
            view.AddTab(tab, panel.NumCols);
        }