예제 #1
0
        private string GetTagInf(GUTag tag, ITagDB db)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("当前选中标签:" + tag);

            List <GUTag> parents = db.QueryTagParent(tag);

            if (parents.Count > 0)
            {
                sb.Append(" Parent::= ");
                foreach (GUTag s in parents)
                {
                    sb.Append(" " + s.Title);
                }
            }


            List <GUTag> children = TagDB.QueryTagChildren(tag);

            if (children.Count > 0)
            {
                sb.Append(" Children::= ");
                foreach (GUTag s in children)
                {
                    sb.Append(" " + s.Title);
                }
            }
            return(sb.ToString().Trim());
        }
예제 #2
0
        private static GTagBoxTree ExpandChildNoCompact(int level, int MaxLevel, ITagDB db, GTagBoxTree root, GTagBoxTree pre, GUTag ctag, int direct, Size size, TreeLayoutEnv env, LayoutMode mode)
        {
            GTagBoxTree cur;

            Logger.D("ChoosePos:pre:{0}-{1}-{2} cur:{0}-{1},",
                     pre?.GTagBox.Tag,
                     pre == null ? 0 : db.QueryTagChildren(pre.GTagBox.Tag).Count,
                     pre == null ? 0 : pre.totalRange.Right,
                     ctag, db.QueryTagChildren(ctag).Count);

            if (pre == null)
            {
                Logger.D("Place {0} after {1}:follow", ctag, root.GTagBox.Tag);
                cur = ExpandNode(ctag, level + 1, db,
                                 direct == 1 ? root.GTagBox.OutterBox.Right : root.GTagBox.OutterBox.Left,
                                 root.totalRange.Top, direct, size, env, mode);
            }
            else
            {
                Logger.D("Place {0} after {1}:newline", ctag, root.GTagBox.Tag);
                cur = ExpandNode(ctag, level + 1, db,
                                 direct == 1 ? root.GTagBox.OutterBox.Right : root.GTagBox.OutterBox.Left,
                                 root.totalRange.Bottom, direct, size, env, mode);
            }

            env.AddLine(root, cur, direct);
            return(cur);
        }
예제 #3
0
        private static int GetTagTreeWidth(GUTag tag, ITagDB db, int level, int maxlevel)
        {
            int          ret      = -1;
            List <GUTag> children = db.QueryTagChildren(tag);

            if (level > maxlevel)
            {
                ret = 1;
            }
            else if (level == maxlevel)
            {
                ret = children.Count + 1; //所有子节点+自己
            }

            //只有两种情况下不需要换行:
            //1. 父节点 -- 子, 孙,重孙
            //2. 父节点 -- 子,子,子,子
            else if (children.Count <= 1) //情况1:
            {
                //只有一列子孙节点,所有都是独生子
                ret = 1;
                GUTag tmp = tag;
                for (int i = level; i < maxlevel; i++)
                {
                    children = db.QueryTagChildren(tmp);
                    if (children.Count > 1)
                    {
                        ret = -1;
                        break;
                    }
                    else if (children.Count == 0)
                    {
                        ret++;
                        break;
                    }
                    else if (children.Count == 1)
                    {
                        tmp = children[0];
                        ret++;
                    }
                }
                return(ret);
            }
            else
            {
                //情况2:只有一层子节点,所有子节点都是叶子(显示为子,子,子,子)
                ret = children.Count;
                foreach (GUTag ctag in children)
                {
                    if (db.QueryChildrenCount(ctag) > 0) //有子节点非叶子,并且自己子节点数量>1,表示不能在一行内显示
                    {
                        ret = -1;
                    }
                }
            }

            Logger.D("GetTagTreeWidth : {0} {1}", tag.ToString(), ret);
            return(ret);
        }
예제 #4
0
        public void testBaseAdd()
        {
            db.AddTag("p", "c1");

            List <string> c = db.QueryTagChildren("p");

            Assert.AreEqual(1, c.Count);
            Assert.AreEqual("c1", c[0]);
        }
예제 #5
0
        public static GTagBoxTree ExpandNode(GUTag tag, int level, ITagDB db, double x, double y, int direct, Size size, TreeLayoutEnv env, LayoutMode mode)
        {
            Logger.IN(tag.Title);
            Logger.D("Expand " + tag + " " + x + " " + y);
            //已经展开过,直接返回
            if (env.Get(tag) != null)
            {
                Logger.D("FOUND " + tag);
                Logger.OUT();
                return(env.Get(tag));
            }


            //创建子树的根对象
            GTagBoxTree root = new GTagBoxTree();

            root.GTagBox    = new GTagBox(level, tag, x, y, direct);
            root.totalRange = root.GTagBox.OutterBox;
            root.D("计算自身大小(不包括子节点)" + root.GTagBox.Tag);
            env.Add(tag, root);//这个特别需要注意,在递归展开之前,先要将该节点加入DB,否则可能会出现无限递归

            List <GUTag> children     = db.QueryTagChildren(tag);
            List <Size>  childrenSize = new List <Size>();

            GTagBoxTree pre      = null;
            GTagBoxTree cur      = null;
            double      childX   = x + direct * root.GTagBox.OutterBox.Width;
            double      childY   = y;
            int         MaxLevel = CalcMaxLevel(mode);

            //double h = 0;
            //double w = 0;
            if (level < MaxLevel)
            {
                //遍历展开所有子节点
                foreach (GUTag ctag in children)
                {
                    if (env.Get(ctag) != null)
                    {
                        continue;
                    }
                    cur = null;

                    //GTreeObj child = ExpandNode(ctag, level + 1, db, x + root.box.InnerBox.Width, y + h);
                    //h += child.OutBox.Height;
                    //w = Math.Max(w, child.OutBox.Width);
                    switch (mode)
                    {
                    case LayoutMode.TREE_COMPACT_MORE:
                    case LayoutMode.LRTREE_COMPACT_MORE:
                        cur = ExpandChildMoreCompact(level, MaxLevel, db, root, pre, ctag, direct, size, env, mode);
                        break;

                    case LayoutMode.TREE_COMPACT:
                    case LayoutMode.LRTREE_COMPACT:
                        cur = ExpandChildCompact(level, MaxLevel, db, root, pre, ctag, direct, size, env, mode);
                        break;

                    case LayoutMode.TREE_NO_COMPACT:
                    case LayoutMode.LRTREE_NO_COMPACT:
                        cur = ExpandChildNoCompact(level, MaxLevel, db, root, pre, ctag, direct, size, env, mode);
                        break;

                    default:
                        break;
                    }



                    //h += cur.OutBox.Height;
                    //w = Math.Max(w, cur.OutBox.Width);
                    root.totalRange.Union(cur.totalRange);
                    root.Children.Add(cur);


                    pre = cur;
                }
            }

            //根据所有子节点所占区域的大小,计算自己的位置
            //root.OutBox.Width = w + root.box.InnerBox.Width;
            //root.OutBox.Height = Math.Max(h, root.box.InnerBox.Height);
            //root.GTagBox.InnerBox.Y = (root.TotalRange.Top + root.TotalRange.Bottom) / 2;
            root.GTagBox.CenterRootY(root.totalRange);

            root.D(null);
            Logger.OUT();
            return(root);
        }
예제 #6
0
        private static GTagBoxTree ExpandChildCompact(int rootLevel, int MaxLevel, ITagDB db, GTagBoxTree root, GTagBoxTree pre, GUTag ctag, int direct, Size size, TreeLayoutEnv env, LayoutMode mode)
        {
            GTagBoxTree cur;

            Logger.D("ChoosePos:pre:{0}-{1}-{2} cur:{0}-{1},",
                     pre?.GTagBox.Tag,
                     pre == null ? 0 : db.QueryTagChildren(pre.GTagBox.Tag).Count,
                     pre == null ? 0 : pre.totalRange.Right,
                     ctag, db.QueryTagChildren(ctag).Count);

            bool          leftOK = true, rightOK = true;
            TagBoxSizeInf sizeinf      = new TagBoxSizeInf(ctag, rootLevel + 1, StaticCfg.Ins.GFontName);
            int           OneLineChild = GetTagTreeWidth(ctag, db, rootLevel + 1, MaxLevel);

            //右边是否有足够空间(初步预估,用OneLineChild*本节点的宽度预估)
            if (pre != null && direct == 1)
            {
                rightOK = pre.totalRange.Right + sizeinf.OutterBoxSize.Width < size.Width;
            }
            //左边是否有足够空间
            if (pre != null && direct == -1)
            {
                leftOK = sizeinf.OutterBoxSize.Width < pre.totalRange.Left;
            }


            //只有满足严格条件的情况下,才放在兄弟节点的后面,否则在父节点后展开
            if (pre != null && OneLineChild >= 0 &&
                (db.QueryTagChildren(pre.GTagBox.Tag).Count == 0 || rootLevel + 1 == MaxLevel) &&
                rightOK && leftOK)
            {
                Logger.D("Place {0} after {1}:follow", ctag, pre.GTagBox.Tag);
                cur = ExpandNode(ctag, rootLevel + 1, db,
                                 direct == 1 ? pre.totalRange.Right : pre.totalRange.Left,  //X
                                 pre.totalRange.Top,                                        //Y
                                 direct, size, env, mode);
            }

            //第一个节点,没有兄弟节点,放在父节点后面   ==== > 放在父节点的同一行
            //非叶子节点,也直接放在父节点后面 or        ==== > 放在父节点的下一行
            //前一个兄弟已经把这一行占完了               ==== > 放在父节点的下一行
            else
            {
                if (pre == null)
                {
                    Logger.D("Place {0} after {1}:follow", ctag, root.GTagBox.Tag);
                    cur = ExpandNode(ctag, rootLevel + 1, db,
                                     direct == 1 ? root.GTagBox.OutterBox.Right : root.GTagBox.OutterBox.Left,
                                     root.totalRange.Top, direct, size, env, mode);
                }
                else
                {
                    Logger.D("Place {0} after {1}:newline", ctag, root.GTagBox.Tag);
                    cur = ExpandNode(ctag, rootLevel + 1, db,
                                     direct == 1 ? root.GTagBox.OutterBox.Right : root.GTagBox.OutterBox.Left,
                                     root.totalRange.Bottom, direct, size, env, mode);
                }
                env.AddLine(root, cur, direct);
            }

            return(cur);
        }
예제 #7
0
        public void ITagDB_Test_AddBase()//简单添加
        {
            GUTag p  = db.NewTag("p");
            GUTag c1 = db.NewTag("c1");

            db.SetParent(p, c1);

            List <GUTag> c = db.QueryTagChildren(p);

            Assert.AreEqual(1, c.Count);
            Assert.AreEqual("c1", c[0].Title);
        }
예제 #8
0
        public override void Layout(ITagDB db, GUTag rootTag, Size size, TreeLayoutEnv env)
        {
            //初始化准备工作
            GTagBoxTree subTree = null;
            double      y       = 0;

            oriSize = size;
            this.db = db;
            env.Reset();
            tags = new List <TagBox>();



            //计算出Root节点的位置信息
            double rootTagBoxX = size.Width / 2;

            root         = new GTagBoxTree();
            root.GTagBox = new GTagBox(0, rootTag, rootTagBoxX, 0, 1);
            root.Move(-1 * root.GTagBox.InnerBox.Width * 3 / 4, 0);
            env.Add(rootTag, root);

            //计算左右子节点的开始位置(估算)
            double l, r;

            l = root.GTagBox.InnerBoxLeftTop.X - StaticCfg.Ins.LayoutXPadding * 5;
            r = root.GTagBox.InnerBoxLeftTop.X + root.GTagBox.InnerBox.Width + StaticCfg.Ins.LayoutXPadding * 5;
            Rect outterbox = Rect.Empty;

            List <GUTag> allChild = db.QueryTagChildren(rootTag);

            allChild.Remove(rootTag);

            int idx = 0;
            int mid = CalcMid(allChild, db);

            GTagBoxTree[] children = new GTagBoxTree[allChild.Count];

            int direct = 1;
            //希望现实是按照顺时针方向现实
            List <GUTag> Left  = new List <GUTag>();
            List <GUTag> Right = new List <GUTag>();

            for (int i = 0; i < allChild.Count; i++)
            {
                if (i < mid)
                {
                    Right.Add(allChild[i]);
                }
                else
                {
                    Left.Add(allChild[i]);
                }
            }
            List <GUTag> all = new List <GUTag>();

            all.AddRange(Right);
            Left.Reverse();
            all.AddRange(Left);

            foreach (GUTag c in all)
            {
                if (c == rootTag)
                {
                    continue;              //临时规避数据上的一个问题,有些节点自己成环了。
                }
                //确定当前子节点时放在左边,还是放在右边:半数放在左边,半数放在右边
                if (idx == mid)
                {
                    y      = 0; //显示从左边转到右边,将y重置
                    direct = -1;
                }
                //展开第idx个子节点
                subTree       = GTagBoxTree.ExpandNode(c, 1, db, direct == 1?r:l, y, direct, size, env, myLayoutMode);
                children[idx] = subTree;

                //更新整个显示区的大小。(outterBox)
                if (idx == 0)
                {
                    outterbox = subTree.TotalRange;
                }
                else
                {
                    outterbox.Union(subTree.TotalRange);
                }
                root.Children.Add(subTree);
                env.AddLine(root, subTree, direct);
                y += subTree.TotalRange.Height;
                idx++;
            }
            outterbox.Union(root.GTagBox.OutterBox);
            root.TotalRange = outterbox;
            root.CenterRootY();
            root.GTagBox.IsRoot = true;

            LRBanlance(children, mid);
            //如果有图形在坐标0的左边,将其往右移一些。
            if (outterbox.X < 0)
            {
                root.Move(-outterbox.X, 0);
            }
            //ShowParent(root);
            tags  = env.GetAllTagBox();
            lines = env.GetAllLines().Cast <UIElement>();
        }