Пример #1
0
            public override bool Equals(object obj)
            {
                if (obj is GraphStackItem)
                {
                    GraphStackItem s = obj as GraphStackItem;
                    return(s.id == id && s.type == type && s.parameter == parameter);
                }

                return(false);
            }
Пример #2
0
            public static GraphStackItem FromJson(string data)
            {
                GraphStackItemData d = JsonConvert.DeserializeObject <GraphStackItemData>(data);

                GraphStackItem i = new GraphStackItem();

                i.id        = d.id;
                i.parameter = d.parameter;
                i.type      = d.type;

                return(i);
            }
Пример #3
0
        public void Push(Node n, Graph graph, GraphStackType type, string param = null)
        {
            if (graph != null)
            {
                GraphStackItem item = new GraphStackItem();
                item.id        = n.Id;
                item.node      = n;
                item.graph     = graph;
                item.type      = type;
                item.parameter = param;


                if (!GraphStack.Contains(item))
                {
                    GraphStack.Push(item);
                    if (!Crumbs.Contains(n.Id))
                    {
                        BreadCrumb c = new BreadCrumb(Crumbs, graph.Name, this, n.Id);
                    }
                }
            }

            //no need to reload if it is the same graph already
            if (graph == Graph)
            {
                return;
            }
            if (graph == null)
            {
                return;
            }

            Graph.OnGraphUpdated -= Graph_OnGraphUpdated;

            ClearView();

            Graph = graph;

            Scale  = Graph.Zoom;
            XShift = Graph.ShiftX;
            YShift = Graph.ShiftY;

            ZoomLevel.Text = String.Format("{0:0}", Scale * 100);

            Graph.OnGraphUpdated += Graph_OnGraphUpdated;

            ReadOnly       = Graph.ReadOnly;
            Graph.ReadOnly = false;
            LoadGraphUI();
        }
Пример #4
0
        protected void RestoreStack()
        {
            if (StoredGraphStack != null)
            {
                var  graph = Original;
                Node n;
                for (int i = 0; i < StoredGraphStack.Length; i++)
                {
                    GraphStackItem item = GraphStackItem.FromJson(StoredGraphStack[i]);
                    if (graph.NodeLookup.TryGetValue(item.id, out n))
                    {
                        item.node = n;

                        if (item.type == GraphStackType.Pixel)
                        {
                            if (n is PixelProcessorNode)
                            {
                                graph      = (n as PixelProcessorNode).Function;
                                item.graph = graph;

                                if (!GraphStack.Contains(item))
                                {
                                    GraphStack.Push(item);

                                    if (!Crumbs.Contains(n.Id))
                                    {
                                        BreadCrumb c = new BreadCrumb(Crumbs, graph.Name, this, n.Id);
                                    }
                                }
                            }
                            else
                            {
                                //we return as the stack does not match
                                StoredGraphStack = null;
                                return;
                            }
                        }
                        else if (item.type == GraphStackType.Parameter && !string.IsNullOrEmpty(item.parameter))
                        {
                            if (graph.HasParameterValue(item.id, item.parameter))
                            {
                                if (graph.IsParameterValueFunction(item.id, item.parameter))
                                {
                                    var v = graph.GetParameterRaw(item.id, item.parameter);
                                    item.graph = v.Value as Graph;

                                    if (!GraphStack.Contains(item))
                                    {
                                        GraphStack.Push(item);

                                        if (!Crumbs.Contains(n.Id))
                                        {
                                            BreadCrumb c = new BreadCrumb(Crumbs, graph.Name, this, n.Id);
                                        }
                                    }
                                }
                                else
                                {
                                    StoredGraphStack = null;
                                    return;
                                }
                            }
                            else
                            {
                                StoredGraphStack = null;
                                return;
                            }
                        }
                        else if (item.type == GraphStackType.FX)
                        {
                            //do same as pixel basically
                        }
                        else if (item.type == GraphStackType.CustomFunction)
                        {
                            FunctionGraph fn = graph.CustomFunctions.Find(m => m.Name.Equals(item.id));

                            if (fn != null)
                            {
                                graph = item.graph = fn;

                                if (!GraphStack.Contains(item))
                                {
                                    GraphStack.Push(item);

                                    if (!Crumbs.Contains(item.id))
                                    {
                                        BreadCrumb c = new BreadCrumb(Crumbs, fn.Name, this, item.id);
                                    }
                                }
                            }
                            else
                            {
                                StoredGraphStack = null;
                                return;
                            }
                        }
                        else
                        {
                            StoredGraphStack = null;
                            return;
                        }
                    }
                    else
                    {
                        StoredGraphStack = null;
                        return;
                    }
                }

                if (graph != null)
                {
                    LoadGraph(graph);
                }

                StoredGraphStack = null;
            }
        }