Esempio n. 1
0
        //private string GetNewTagTitle()
        //{
        //    string tag = StaticCfg.Ins.DefaultNewTag;
        //    int i = 0;
        //    while(TagDB.QueryTagAlias(tag).Count>0)
        //    {
        //        tag = StaticCfg.Ins.DefaultNewTag + "-" + (++i);
        //    }
        //    return tag;
        //}
        private void EnsureVisible(GUTag newTag, GUTag currentRoot)
        {
            int   MaxLevel = GTagBoxTree.CalcMaxLevel(MyLayoutMode);
            GUTag tmp      = newTag;

            for (int i = 0; i < MaxLevel; i++)
            {
                List <GUTag> tmpP = TagDB.QueryTagParent(tmp);
                if (tmpP.Count > 0)
                {
                    tmp = tmpP[0];
                }
                else //无法回溯,直接返回
                {
                    return;
                }

                if (tmp == currentRoot) //根节点已经可见,直接返回。
                {
                    return;
                }
            }
            ChangeRoot(tmp, newTag);
        }
Esempio n. 2
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>();
        }
Esempio n. 3
0
        //public static Line CreateLine(GBoxObj parent, GBoxObj child)
        //{
        //    Line l = new Line();
        //    l.X1 = parent.ColorBox.X + parent.ColorBox.Width / 2;
        //    l.Y1 = parent.ColorBox.Y + parent.ColorBox.Height;
        //    l.X2 = child.ColorBox.X + child.ColorBox.Width / 2;
        //    l.Y2 = child.ColorBox.Y;
        //    l.Tag = parent.Tag.ToString() + StaticCfg.Ins.ParentChildSplit + child.Tag.ToString();
        //    if (Math.Min(parent.GTagBox.Level, child.GTagBox.Level) == 0)
        //    {
        //        l.Stroke = new SolidColorBrush(GetColor(parent.GTagBox.Distance + 1, parent.GTagBox.Level + 1));
        //        l.StrokeThickness = StaticCfg.Ins.StrokeThickness * 1.5;
        //        l.StrokeDashArray = StaticCfg.Ins.StrokeDashArray;
        //    }
        //    else
        //    {
        //        l.Stroke = new SolidColorBrush(GetColor(parent.GTagBox.Distance + 1, parent.GTagBox.Level + 1));
        //        l.StrokeThickness = StaticCfg.Ins.StrokeThickness;
        //        l.StrokeDashArray = StaticCfg.Ins.StrokeDashArray;
        //    }
        //    return l;
        //}
        public static Path CreateBezier(Tuple <GTagBoxTree, GTagBoxTree, int> p_c, TreeLayoutEnv env)
        {
            GTagBoxTree p      = p_c.Item1;
            GTagBoxTree c      = p_c.Item2;
            int         direct = (int)p_c.Item3;

            System.Windows.Point p1 = new System.Windows.Point();
            System.Windows.Point p5 = new System.Windows.Point();
            System.Windows.Point p2 = new System.Windows.Point();
            System.Windows.Point p4 = new System.Windows.Point();
            System.Windows.Point p3 = new System.Windows.Point();

            if (direct == 1)
            {
                p1.X = p.GTagBox.InnerBox.Right;
                p5.X = c.GTagBox.InnerBox.Left;
            }
            else
            {
                p1.X = p.GTagBox.InnerBox.Left;
                p5.X = c.GTagBox.InnerBox.Right;
            }
            p1.Y = (p.GTagBox.InnerBox.Top + p.GTagBox.InnerBox.Bottom) / 2;
            p5.Y = (c.GTagBox.InnerBox.Top + c.GTagBox.InnerBox.Bottom) / 2;


            p3.X = (p1.X + p5.X) / 2;
            p3.Y = (p1.Y + p5.Y) / 2;

            const int N = 3;

            p2.X = (p1.X * N + p5.X) / (N + 1);
            p4.X = (p1.X + p5.X * N) / (N + 1);

            p2.Y = p1.Y;
            p4.Y = p5.Y;



            Path path = env.New(p_c);


            if (path.Data == null)
            {
                PathGeometry         pg   = new PathGeometry();
                PathFigureCollection pfc  = new PathFigureCollection();
                PathFigure           pf   = new PathFigure();
                BezierSegment        seg1 = new BezierSegment(p1, p2, p3, true);
                seg1.IsSmoothJoin = true;
                BezierSegment seg2 = new BezierSegment(p3, p4, p5, true);
                seg2.IsSmoothJoin = true;

                //Path->PathGeometry->PathFigureCollection->PathFigure->PathSegmentCollection->BezierSegment
                path.Data = pg;
                //PathGeometry
                pg.Figures = pfc;
                //PathFigureCollection
                pfc.Add(pf);

                //PF
                pf.StartPoint = p1;
                pf.Segments.Add(seg1);
                pf.Segments.Add(seg2);
                pg.Figures.Add(pf);
            }
            else
            {
                PathGeometry         pg  = path.Data as PathGeometry;
                PathFigureCollection pfc = pg.Figures as PathFigureCollection;
                PathFigure           pf  = pfc[0] as PathFigure;
                pf.StartPoint = p1;
                BezierSegment seg1 = pf.Segments[0] as BezierSegment;
                BezierSegment seg2 = pf.Segments[1] as BezierSegment;
                seg1.Point1 = p1;   seg1.Point2 = p2;   seg1.Point3 = p3;
                seg2.Point1 = p3;   seg2.Point2 = p4;   seg2.Point3 = p5;
                //pg.Figures.Add(pf);
            }
            SetBezierStyle(p.GTagBox, c.GTagBox, path);
            return(path);
        }