Ejemplo n.º 1
0
        public static Bitmap Visualize(EvaluationContext context, TreeStyle style)
        {
            ComputedNode root = CreateNodes(context);

            Bitmap   bitmap = new Bitmap(1, 1);
            Graphics g      = Graphics.FromImage(bitmap);

            g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            root.Measure(g, style);

            int titleWidth  = (int)(context.Plan.Title == null ? 0 : g.MeasureString(context.Plan.Title, style.TitleFont).Width);
            int titleHeight = (int)(context.Plan.Title == null ? 0 : g.MeasureString(context.Plan.Title, style.TitleFont).Height + style.TitleTopMargin + style.TitleBottomMargin);
            int imageWidth  = (int)(Math.Max(titleWidth, root.Width) + style.LeftMargin + style.RightMargin);
            int imageHeight = (int)(root.Height + style.TopMargin + style.BottomMargin + titleHeight);

            root.Layout(style, style.LeftMargin + (imageWidth - style.LeftMargin - style.RightMargin - root.Width) / 2, style.TopMargin + titleHeight);
            root.PostLayout(style);
            g.Dispose();


            Bitmap renderedBitmap = new Bitmap(imageWidth, imageHeight);

            g = Graphics.FromImage(renderedBitmap);
            root.Draw(g, style);
            DrawTitle(g, style, context.Plan.Title, imageWidth);
            g.Dispose();

            return(renderedBitmap);
        }
Ejemplo n.º 2
0
        public override void Layout(TreeStyle style, double left, double top)
        {
            layoutTimes++;

            if (layoutTimes == 1)
            {
                Left = left;
                Top  = top;
            }
            else
            {
                double[] rect = MergeRects(Left, Top, Width, Height, left, top, Width, Height);
                Left   = rect[0];
                Top    = rect[1];
                Width  = rect[2];
                Height = rect[3];
            }

            NodeLeft = Left + (Width - NodeWidth) / 2;
            NodeTop  = Top;

            double x = Left + (Width - branchesWidth) / 2;
            double y = Top + NodeHeight + style.VerticalNodeSpacing;

            foreach (Branch branch in Branches)
            {
                branch.Node.Layout(style, x, y);
                x += branch.Node.Width + style.HorizontalNodeSpacing;
            }
        }
Ejemplo n.º 3
0
 public override void Layout(TreeStyle style, double left, double top)
 {
     NodeLeft = left;
     NodeTop  = top;
     Left     = NodeLeft;
     Top      = NodeTop;
 }
Ejemplo n.º 4
0
        public override void Draw(Graphics g, TreeStyle style)
        {
            if (style.VariableFillColor != null)
            {
                Brush b = new SolidBrush(style.VariableFillColor);
                g.FillRectangle(b, (float)NodeLeft, (float)NodeTop, (float)NodeWidth, (float)NodeHeight);
                b.Dispose();
            }

            Pen p = new Pen(new SolidBrush(style.VariableBorderColor));

            g.DrawRectangle(p, (float)NodeLeft, (float)NodeTop, (float)NodeWidth, (float)NodeHeight);
            p.Dispose();


            double y = NodeTop;

            g.DrawString(Description, style.Font, Brushes.Black, (float)NodeLeft, (float)y);
            y += g.MeasureString(Description, style.Font).Height;

            Font f = new Font(style.Font.Name, 9);

            Text.Draw(g, style.Font, f, Brushes.Black, (int)NodeLeft, (int)y);
            f.Dispose();


            y += Text.Size.Height;

            g.DrawString(GetValueString(Value), style.ValueFont, Brushes.Black, (float)NodeLeft, (float)y);
        }
Ejemplo n.º 5
0
 private static void DrawTitle(Graphics g, TreeStyle style, string title, int imageWidth)
 {
     if (title != null)
     {
         SizeF size = g.MeasureString(title, style.TitleFont);
         g.DrawString(title, style.TitleFont, Brushes.Black, (float)((imageWidth - size.Width) / 2), style.TopMargin + style.TitleTopMargin);
     }
 }
Ejemplo n.º 6
0
 public override void PostLayout(TreeStyle style)
 {
     foreach (Branch branch in Branches)
     {
         branch.Node.PostLayout(style);
         ComputeBranchLine(branch, style);
     }
 }
Ejemplo n.º 7
0
        public override void Measure(Graphics g, TreeStyle style)
        {
            foreach (Branch branch in Branches)
            {
                branch.Node.Measure(g, style);
            }


            if (Branches.Count > 0)
            {
                branchesWidth  = Branches.Sum(i => i.Node.Width) + (Branches.Count - 1) * style.HorizontalNodeSpacing;
                branchesHeight = Branches.Max(i => i.Node.Height);
            }


            List <SizeF> lines = new List <SizeF>();

            lines.Add(g.MeasureString(Description, style.Font));
            lines.Add(new SizeF(ExpressionImage.Width, ExpressionImage.Height));


            int index = 0;

            foreach (object result in Results)
            {
                string s = GetValueString(result);
                if (Results.Length > 1)
                {
                    s = ResultVariableNames[index] + "=" + s;
                }

                lines.Add(g.MeasureString(GetValueString(s), style.ValueFont));
                index++;
            }


            NodeWidth  = lines.Max(i => i.Width);
            NodeHeight = lines.Sum(i => i.Height);

            Width  = Math.Max(branchesWidth, NodeWidth);
            Height = Branches.Count == 0 ? NodeHeight : branchesHeight + style.VerticalNodeSpacing + NodeHeight;
        }
Ejemplo n.º 8
0
        public override void Measure(Graphics g, TreeStyle style)
        {
            Font f = new Font(style.Font.Name, 9);

            Text.Measure(g, style.Font, f);
            f.Dispose();

            SizeF[] lines = new SizeF[]
            {
                g.MeasureString(Description, style.Font),
                Text.Size,
                g.MeasureString(GetValueString(Value), style.ValueFont)
            };

            NodeWidth  = lines.Max(i => i.Width);
            NodeHeight = lines.Sum(i => i.Height);

            Width  = NodeWidth;
            Height = NodeHeight;
        }
Ejemplo n.º 9
0
        private void ComputeBranchLine(Branch branch, TreeStyle style)
        {
            double x1    = branch.Node.NodeLeft + branch.Node.NodeWidth / 2;
            double y1    = branch.Node.NodeTop;
            double x2    = NodeLeft + NodeWidth / 2;
            double y2    = NodeTop + NodeHeight / 2;
            double angle = Funcs.Atan(x1, y1, x2, y2);


            branch.LineX1 = x1;
            branch.LineY1 = y1 - style.JointSpacing;


            double interX = x1 - (NodeTop + NodeHeight - y1) / Math.Tan(angle);

            if (interX >= NodeLeft && interX <= NodeLeft + NodeWidth)
            {
                double d = (NodeHeight / 2 + style.JointSpacing) / Math.Abs(Math.Sin(angle));

                branch.LineX2 = x2 - d * Math.Cos(angle);
                branch.LineY2 = y2 + d * Math.Sin(angle);
            }
            else
            {
                double d = (NodeWidth / 2 + style.JointSpacing) / Math.Abs(Math.Cos(angle));

                branch.LineX2 = x2 - d * Math.Cos(angle);
                branch.LineY2 = y2 + d * Math.Sin(angle);
            }


            if (Math.Abs(branch.LineX1 - branch.LineX2) <= 2 && Math.Abs(branch.LineY1 - branch.LineY2) >= 20)
            {
                double x = (branch.LineX1 + branch.LineX2) / 2;
                branch.LineX1 = x;
                branch.LineX2 = x;
            }


            ComputeArrowPath(branch, angle);
        }
Ejemplo n.º 10
0
 public static Bitmap Visualize(EvaluationContext context)
 {
     return(Visualize(context, TreeStyle.CreateDefault()));
 }
Ejemplo n.º 11
0
        public override void Draw(Graphics g, TreeStyle style)
        {
            if (style.ExpressionFillColor != null)
            {
                Brush b = new SolidBrush(style.ExpressionFillColor);
                g.FillRectangle(b, (float)NodeLeft, (float)NodeTop, (float)NodeWidth, (float)NodeHeight);
                b.Dispose();
            }

            Pen p = new Pen(new SolidBrush(style.ExpressionBorderColor));

            g.DrawRectangle(p, (float)NodeLeft, (float)NodeTop, (float)NodeWidth, (float)NodeHeight);
            p.Dispose();

            foreach (Branch branch in Branches)
            {
                Brush b = new SolidBrush(branch.Node is VariableNode ? style.VariableArrowColor : style.ExpressionArrowColor);

                p = new Pen(b);
                g.DrawLine(p, (float)branch.LineX1, (float)branch.LineY1, (float)branch.LineX2, (float)branch.LineY2);
                p.Dispose();

                g.FillPath(b, branch.ArrowPath);
                b.Dispose();
            }

            p.Dispose();


            double y = NodeTop;

            g.DrawString(Description, style.Font, Brushes.Black, (float)NodeLeft, (float)y);
            y += g.MeasureString(Description, style.Font).Height;

            g.DrawImage(ExpressionImage, (float)NodeLeft, (float)y);
            y += ExpressionImage.Height;


            int index = 0;

            foreach (object result in Results)
            {
                string s = GetValueString(result);
                if (Results.Length > 1)
                {
                    s = ResultVariableNames[index] + "=" + s;
                }

                g.DrawString(s, style.ValueFont, Brushes.Black, (float)NodeLeft, (float)y);
                y += g.MeasureString(s, style.ValueFont).Height;
                index++;
            }

            foreach (Branch branch in Branches)
            {
                branch.Node.Draw(g, style);
            }


            if (Step.State == StepState.Skipped)
            {
                p = new Pen(Brushes.DarkRed, 2);
                g.TranslateTransform(-10, -10);
                g.DrawLine(p, (float)NodeLeft, (float)NodeTop, (float)(NodeLeft + 20), (float)(NodeTop + 20));
                g.DrawLine(p, (float)(NodeLeft + 20), (float)NodeTop, (float)NodeLeft, (float)(NodeTop + 20));
                g.TranslateTransform(10, 10);
                p.Dispose();
            }
        }
Ejemplo n.º 12
0
 public abstract void Draw(Graphics g, TreeStyle style);
Ejemplo n.º 13
0
 public virtual void PostLayout(TreeStyle style)
 {
 }
Ejemplo n.º 14
0
 public abstract void Layout(TreeStyle style, double left, double top);
Ejemplo n.º 15
0
 public abstract void Measure(Graphics g, TreeStyle style);