private bool ReopenCurrentGraph()
        {
            if (GraphTabs.Count == 0)
            {
                return(false);
            }
            GraphTab activeTab = GraphTabs[GraphTabs.Count - 1];
            Graph    graph     = activeTab.IsRootTab ? activeTab.Graph : activeTab.SubGraphNode.SubGraph;

            if (graph == null)
            {
                GraphTabs.Clear();
                return(false);
            }

            OpenGraph(graph, false, false, false, false);

            //remove any node, that has been soft deleted, from the graph's Nodes list
            foreach (Node deletedNode in DeletedNodes)
            {
                if (!CurrentGraph.Nodes.Contains(deletedNode))
                {
                    continue;
                }
                CurrentGraph.Nodes.Remove(deletedNode);
                CurrentGraph.SetDirty(false);
            }

            GraphEvent.Send(GraphEvent.EventType.EVENT_GRAPH_OPENED);

            m_graphAssetPath = AssetDatabase.GetAssetPath(CurrentGraph);

            return(true);
        }
Example #2
0
    private void RefillTabs()
    {
        CleanTabs();

        string key = GetCurrentKey();

        GraphTab sceneTab = Instantiate(graphTab, content);

        sceneTab.isSelected  = key == SceneGraphKey;
        sceneTab.isScene     = true;
        sceneTab.NTKey       = SceneGraphKey;
        sceneTab.DisplayName = SceneGraphKey;

        tabs.Add(sceneTab);

        foreach (SceneObjectGraph sog in SessionManager.Instance.GetAllGraphs())
        {
            GraphTab sceneObjectTab = Instantiate(graphTab, content);

            sceneObjectTab.isSelected  = key == sog.linkedNTVariable;
            sceneObjectTab.isScene     = false;
            sceneObjectTab.NTKey       = sog.linkedNTVariable;
            sceneObjectTab.DisplayName = sog.displayName;

            tabs.Add(sceneObjectTab);
        }
    }
Example #3
0
        private void CreatePageOfGraphs(string sim, Graph[] graphs)
        {
            if (!panel.Cache.ContainsKey(sim))
            {
                panel.Cache.Add(sim, new Dictionary <int, List <SeriesDefinition> >());
            }

            IStorageReader storage   = GetStorage();
            GraphPage      graphPage = new GraphPage();

            // Configure graphs by applying user overrides.
            for (int i = 0; i < graphs.Length; i++)
            {
                if (graphs[i] != null && graphs[i].Enabled)
                {
                    graphPage.Graphs.Add(ConfigureGraph(graphs[i], sim));
                }

                if (cts.Token.IsCancellationRequested)
                {
                    return;
                }
            }

            // If any sims in this tab are missing from the cache, then populate
            // the cache via the GraphPage instance.
            if (panel.Cache[sim].Count != graphs.Length)
            {
                // Read data from storage.
                IReadOnlyList <GraphPage.GraphDefinitionMap> definitions = graphPage.GetAllSeriesDefinitions(panel, storage, new List <string>()
                {
                    sim
                }).ToList();

                // Now populate the cache for this simulation. The definitions
                // should - in theory - be the same length as the graphs array.
                for (int i = 0; i < graphs.Length; i++)
                {
                    GraphPage.GraphDefinitionMap definition = definitions[i];
                    panel.Cache[sim][i] = definition.SeriesDefinitions;
                    if (cts.Token.IsCancellationRequested)
                    {
                        return;
                    }
                }
            }

            // Finally, add the graphs to the tab.
            GraphTab tab = new GraphTab(sim, this.presenter);

            for (int i = 0; i < graphPage.Graphs.Count; i++)
            {
                tab.AddGraph(graphPage.Graphs[i], panel.Cache[sim][i]);
            }

            this.graphs.Add(tab);
            view.AddTab(tab, panel.NumCols);
        }
Example #4
0
        private void CustomTitle_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            var key = e.Key;

            if (key == Key.Enter)
            {
                GraphTab.Focus();
            }
        }
Example #5
0
        private void StutteringThreshold_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            var key = e.Key;

            if (key == Key.Enter)
            {
                GraphTab.Focus();
                (DataContext as DataViewModel).OnStutteringOptionsChanged();
            }
        }
Example #6
0
        private void LastSecondsTextBox_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            var key = e.Key;

            if (key == Key.Enter)
            {
                GraphTab.Focus();
                (DataContext as DataViewModel).OnRangeSliderDragCompleted();
            }
        }
Example #7
0
        private void LastSecondsTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            var key = e.Key;

            if (key == Key.Enter)
            {
                GraphTab.Focus();
            }
            (DataContext as ComparisonViewModel).OnRangeSliderValuesChanged();
        }
Example #8
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 = (Graph.LegendOrientationType)Enum.Parse(typeof(Graph.LegendOrientationType), 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 = (Graph.LegendPositionType)Enum.Parse(typeof(Graph.LegendPositionType), panel.LegendPosition.ToString());

                    // Create and fill cache entry if it doesn't exist.
                    if (!panel.Cache.ContainsKey(sim) || panel.Cache[sim].Count <= i)
                    {
                        try
                        {
                            int x = storage.GetSimulationID(sim);
                        }
                        catch (KeyNotFoundException)
                        {
                            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.");
                        }
                        List<SeriesDefinition> definitions = graph.GetDefinitionsToGraph(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;
                    }
                    tab.AddGraph(graph, panel.Cache[sim][i]);
                }

                if (processingThread.CancellationPending)
                    return;
            }

            this.graphs.Add(tab);
            view.AddTab(tab, panel.NumCols);
        }
        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++)
            {
                if (graphs[i].Enabled)
                {
                    // Apply transformation to graph.
                    panel.Script.TransformGraph(graphs[i], sim);

                    // Create and fill cache entry if it doesn't exist.
                    if (!panel.Cache.ContainsKey(sim) || panel.Cache[sim].Count <= i)
                    {
                        try
                        {
                            int x = storage.GetSimulationID(sim);
                        }
                        catch (KeyNotFoundException)
                        {
                            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.");
                        }
                        List <SeriesDefinition> definitions = graphs[i].GetDefinitionsToGraph(storage, new List <string>()
                        {
                            sim
                        });
                        if (!panel.Cache.ContainsKey(sim))
                        {
                            panel.Cache.Add(sim, new Dictionary <int, List <SeriesDefinition> >());
                        }

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

                if (processingThread.CancellationPending)
                {
                    return;
                }
            }

            this.graphs.Add(tab);
            view.AddTab(tab, panel.NumCols);
        }
        public void OpenSubGraph(SubGraphNode subGraphNode)
        {
            if (subGraphNode == null || subGraphNode.SubGraph == null)
            {
                return;
            }

            GraphTab currentTab = GraphTabs[GraphTabs.Count - 1];

            currentTab.Zoom          = CurrentZoom;
            currentTab.PanOffset     = CurrentPanOffset;
            currentTab.SelectedNodes = new List <Node>(SelectedNodes);
            var newTab = new GraphTab(CurrentGraph, subGraphNode, CurrentZoom, CurrentPanOffset, SelectedNodes, DeletedNodes);

            OpenGraph(subGraphNode.SubGraph, true, false, true);
            GraphTabs.Add(newTab);
        }
Example #11
0
        private void DrawGraphTabs()
        {
            if (GraphTabs.Count == 0)
            {
                return;                                                          //if no tabs have been opened stop here -> do not draw anything
            }
            int   clickedTabIndex  = -1;                                         //index of the clicked tab
            float tabWidth         = NodySettings.Instance.GraphTabMaximumWidth; //get the tab max width
            float tabsCount        = GraphTabs.Count;                            //count the tabs
            bool  calculateTabWith = true;                                       //start dynamic tab width calculations

            while (calculateTabWith)
            {
                float totalSpaceWidth         = tabsCount * 2 * NodySettings.Instance.GraphTabElementSpacing;
                float totalDividersWidth      = (tabsCount - 1) * NodySettings.Instance.GraphTabDividerWidth;
                float totalTabsAvailableWidth = GraphTabsRect.width - totalSpaceWidth - totalDividersWidth;
                float calculatedTabWidth      = totalTabsAvailableWidth / tabsCount;

                if (calculatedTabWidth > NodySettings.Instance.GraphTabMaximumWidth)
                {
                    calculateTabWith = false;
                    tabWidth         = NodySettings.Instance.GraphTabMaximumWidth;
                }
                else if (calculatedTabWidth >= NodySettings.Instance.GraphTabMinimumWidth)
                {
                    calculateTabWith = false;
                    tabWidth         = calculatedTabWidth;
                }
                else
                {
                    tabsCount--;
                }
            }

            float x = GraphTabsRect.x;

            //Start drawing the tabs
            GUILayout.Space(DGUI.Properties.Space());
            GUILayout.BeginHorizontal();
            {
                GUILayout.Space(NodySettings.Instance.GraphTabElementSpacing);
                x += NodySettings.Instance.GraphTabElementSpacing;
                for (int index = 0; index < tabsCount; index++)
                {
                    if (index > 0)
                    {
                        float dividerHeight = NodySettings.Instance.GraphTabsAreaHeight - NodySettings.Instance.GraphTabElementSpacing * 3;
                        GUILayout.BeginVertical(GUILayout.Height(GraphTabsRect.height));
                        {
                            GUILayout.Space((GraphTabsRect.height - dividerHeight) / 2 - DGUI.Properties.Space());
                            Color color = GUI.color;
                            GUI.color = DGUI.Colors.TextColor(DGUI.Colors.DisabledTextColorName).WithAlpha(color.a * 0.4f);
                            GUILayout.Label(GUIContent.none, DGUI.Properties.White,
                                            GUILayout.Width(NodySettings.Instance.GraphTabDividerWidth),
                                            GUILayout.Height(dividerHeight));
                            GUI.color = color;
                        }
                        GUILayout.EndVertical();
                        GUILayout.Space(NodySettings.Instance.GraphTabElementSpacing);
                        x += NodySettings.Instance.GraphTabElementSpacing;
                        x += NodySettings.Instance.GraphTabDividerWidth;
                        x += NodySettings.Instance.GraphTabElementSpacing;
                    }

                    GraphTab graphTab   = GraphTabs[index];
                    var      buttonRect = new Rect(x, GraphTabsRect.y + NodySettings.Instance.GraphTabElementSpacing, tabWidth, GraphTabsRect.height - 2 * NodySettings.Instance.GraphTabElementSpacing);

                    GUI.color = InitialGUIColor;
                    if (index < tabsCount - 1)
                    {
                        GUI.color = GUI.color.WithAlpha(DGUI.Utility.IsProSkin ? 0.6f : 0.8f);
                    }
                    if (graphTab.DrawButton(buttonRect))
                    {
                        if (graphTab.IsRootTab && graphTab.Graph != null && CurrentGraph != graphTab.Graph)
                        {
                            OpenGraph(graphTab.Graph, true, false, false);
                        }
                        else if (!graphTab.IsRootTab && graphTab.SubGraphNode != null && graphTab.SubGraphNode.SubGraph != null && CurrentGraph != graphTab.SubGraphNode.SubGraph)
                        {
                            OpenGraph(graphTab.SubGraphNode.SubGraph, true, false, false);
                        }

                        CurrentZoom      = graphTab.Zoom;
                        CurrentPanOffset = graphTab.PanOffset;
                        SelectedNodes    = new List <Node>(graphTab.SelectedNodes);
                        clickedTabIndex  = index;

                        GraphEvent.Send(GraphEvent.EventType.EVENT_GRAPH_OPENED);

                        break;
                    }

                    GUILayout.Space(tabWidth);
                    x += tabWidth;
                }

                GUILayout.FlexibleSpace();
            }
            GUILayout.EndHorizontal();

            if (clickedTabIndex == -1)
            {
                return;
            }
            for (int i = GraphTabs.Count - 1; i >= 0; i--)
            {
                if (i > clickedTabIndex)
                {
                    GraphTabs.RemoveAt(i);
                }
            }
        }