コード例 #1
0
            public TreeNode(FCurves window, Utl.ParameterTreeNode paramTreeNode)
            {
                this.window = window;
                ID          = "###" + Manager.GetUniqueID().ToString();

                Children = new List <TreeNode>();
                FCurves  = new List <FCurve>();

                ParamTreeNode = paramTreeNode;

                foreach (var tn in paramTreeNode.Children)
                {
                    Children.Add(new TreeNode(window, tn));
                }

                foreach (var v in paramTreeNode.Parameters)
                {
                    var v_ = FCurve.Create(v, window);
                    v_.ParentNode = this;

                    FCurves.Add(v_);
                }
            }
コード例 #2
0
        void SetParameters(Utl.ParameterTreeNode paramTreeNodes)
        {
            List <FCurve> befores = new List <FCurve>();
            List <FCurve> afters  = new List <FCurve>();

            Action <TreeNode, List <FCurve> > getFcurves = null;

            getFcurves = (node, target) =>
            {
                if (node == null)
                {
                    return;
                }
                foreach (var f in node.FCurves)
                {
                    target.Add(f);
                }

                foreach (var c in node.Children)
                {
                    getFcurves(c, target);
                }
            };

            getFcurves(treeNodes, befores);

            // initialize
            if (treeNodes == null)
            {
                treeNodes = new TreeNode(this, paramTreeNodes);
            }

            // compare node structures
            if (treeNodes.ParamTreeNode.Node != paramTreeNodes.Node)
            {
                treeNodes = new TreeNode(this, paramTreeNodes);
            }
            else
            {
                Action <Utl.ParameterTreeNode, TreeNode> refleshNodes = null;
                refleshNodes = (ptn, tn) =>
                {
                    // check whether modification doesn't exist
                    bool nochange = tn.Children.Count() == ptn.Children.Count();
                    for (int i = 0; i < ptn.Children.Count() && nochange; i++)
                    {
                        if (tn.Children[i].ParamTreeNode.Node != ptn.Children[i].Node)
                        {
                            nochange = false;
                            break;
                        }
                    }
                    if (nochange)
                    {
                        return;
                    }

                    // if moditications exsist
                    var a = new TreeNode[ptn.Children.Count()];

                    for (int i = 0; i < ptn.Children.Count(); i++)
                    {
                        TreeNode tn_ = tn.Children.FirstOrDefault(_ => _.ParamTreeNode.Node == ptn.Children[i].Node);
                        if (tn_ != null)
                        {
                            // copy
                            refleshNodes(ptn.Children[i], tn_);
                            a[i] = tn_;
                        }
                        else
                        {
                            // new
                            a[i] = new TreeNode(this, ptn.Children[i]);
                        }
                    }

                    tn.Children.Clear();
                    tn.Children.AddRange(a);
                };

                refleshNodes(paramTreeNodes, treeNodes);
            }

            // compare node structures
            {
                Action <Utl.ParameterTreeNode, TreeNode> refleshNodes = null;
                refleshNodes = (ptn, tn) =>
                {
                    // check whether modification doesn't exist
                    bool nochange = true;
                    if (tn.FCurves.Count() == ptn.Parameters.Count())
                    {
                        for (int i = 0; i < tn.FCurves.Count(); i++)
                        {
                            if (tn.FCurves[i].GetValueAsObject() != ptn.Parameters[i].Item2)
                            {
                                nochange = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        nochange = false;
                    }

                    if (nochange)
                    {
                        for (int i = 0; i < tn.Children.Count(); i++)
                        {
                            refleshNodes(ptn.Children[i], tn.Children[i]);
                        }
                        return;
                    }

                    // if moditications exsist
                    var a = new FCurve[ptn.Parameters.Count()];

                    for (int i = 0; i < ptn.Parameters.Count(); i++)
                    {
                        FCurve f = tn.FCurves.FirstOrDefault(_ => _.GetValueAsObject() == ptn.Parameters[i].Item2);
                        if (f != null)
                        {
                            // copy
                            a[i] = f;
                        }
                        else
                        {
                            // new
                            a[i]            = FCurve.Create(ptn.Parameters[i], this);
                            a[i].ParentNode = tn;
                        }
                    }

                    tn.FCurves.Clear();
                    tn.FCurves.AddRange(a);

                    for (int i = 0; i < tn.Children.Count(); i++)
                    {
                        refleshNodes(ptn.Children[i], tn.Children[i]);
                    }
                };

                refleshNodes(paramTreeNodes, treeNodes);
            }

            getFcurves(treeNodes, afters);

            // event on removing
            foreach (var f in befores)
            {
                if (!afters.Contains(f))
                {
                    f.OnRemoved();
                }
            }

            // event on adding
            foreach (var f in afters)
            {
                if (!befores.Contains(f))
                {
                    f.OnAdded();
                }
            }

            paramaterTreeNode = paramTreeNodes;
        }