Exemplo n.º 1
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);

            // 初期設定
            if (treeNodes == null)
            {
                treeNodes = new TreeNode(this, paramTreeNodes);
            }

            // ノードの構造比較変更
            if (treeNodes.ParamTreeNode.Node != paramTreeNodes.Node)
            {
                treeNodes = new TreeNode(this, paramTreeNodes);
            }
            else
            {
                Action<Utl.ParameterTreeNode, TreeNode> refleshNodes = null;
                refleshNodes = (ptn, tn) =>
                    {
                        // 変更がないか確認
                        bool nochange = tn.Children.Count() == ptn.Children.Count();
                        for (int i = 0; i < ptn.Children.Count() && nochange; i++)
                        {
                            if (tn.Children[i].ParamTreeNode != ptn.Children[i])
                            {
                                nochange = false;
                                break;
                            }
                        }
                        if (nochange) return;

                        // 変更があった場合
                        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)
                            {
                                // コピー
                                refleshNodes(ptn.Children[i], tn_);
                                a[i] = tn_;
                            }
                            else
                            {
                                // 新規
                                a[i] = new TreeNode(this, ptn.Children[i]);
                            }
                        }

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

                refleshNodes(paramTreeNodes, treeNodes);
            }

            // パラメーターの構造比較変更
            {
                Action<Utl.ParameterTreeNode, TreeNode> refleshNodes = null;
                refleshNodes = (ptn, tn) =>
                {
                    // 変更がないか確認
                    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;
                    }

                    // 変更があった場合
                    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)
                        {
                            // コピー
                            a[i] = f;
                        }
                        else
                        {
                            // 新規
                            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);

            // 消滅イベント
            foreach (var f in befores)
            {
                if (!afters.Contains(f))
                {
                    f.OnRemoved(this.splitContainer.Panel2);
                }
            }

            // 追加イベント
            foreach (var f in afters)
            {
                if (!befores.Contains(f))
                {
                    f.OnAdded(this.splitContainer.Panel2);
                }
            }

            treeNodes.CalculatePosition();

            paramaterTreeNode = paramTreeNodes;
        }
Exemplo n.º 2
0
            public TreeNode(FCurves window, Utl.ParameterTreeNode paramTreeNode)
            {
                this.window = window;

                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_);
                }
            }