Пример #1
0
        protected void DrawTreeNode(Graphics graphics, VisualTreeNode <ISymbolicExpressionTreeNode> visualTreeNode)
        {
            graphics.Clip = new Region(new Rectangle(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width + 1, visualTreeNode.Height + 1));
            graphics.Clear(backgroundColor);
            var node = visualTreeNode.Content;

            using (var textBrush = new SolidBrush(visualTreeNode.TextColor))
                using (var nodeLinePen = new Pen(visualTreeNode.LineColor))
                    using (var nodeFillBrush = new SolidBrush(visualTreeNode.FillColor)) {
                        var x = visualTreeNode.X;
                        var y = visualTreeNode.Y;
                        var w = visualTreeNode.Width - 1;  // allow 1px for the drawing of the line
                        var h = visualTreeNode.Height - 1; // allow 1px for the drawing of the line
                        // draw leaf nodes as rectangles and internal nodes as ellipses
                        if (node.SubtreeCount > 0)
                        {
                            fill = graphics.FillEllipse; draw = graphics.DrawEllipse;
                        }
                        else
                        {
                            fill = graphics.FillRectangle; draw = graphics.DrawRectangle;
                        }
                        fill(nodeFillBrush, x, y, w, h);
                        draw(nodeLinePen, x, y, w, h);
                        //draw name of symbol
                        graphics.DrawString(node.ToString(), textFont, textBrush, new RectangleF(x, y, w, h), stringFormat);
                    }
        }
        protected void DrawTreeNode(Graphics graphics, VisualTreeNode <ISymbolicExpressionTreeNode> visualTreeNode)
        {
            graphics.Clip = new Region(new Rectangle(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width + 1, visualTreeNode.Height + 1));
            graphics.Clear(backgroundColor);
            var node = visualTreeNode.Content;

            using (var textBrush = new SolidBrush(visualTreeNode.TextColor))
                using (var nodeLinePen = new Pen(visualTreeNode.LineColor))
                    using (var nodeFillBrush = new SolidBrush(visualTreeNode.FillColor)) {
                        //draw terminal node
                        if (node.SubtreeCount == 0)
                        {
                            graphics.FillRectangle(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
                            graphics.DrawRectangle(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
                        }
                        else
                        {
                            graphics.FillEllipse(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
                            graphics.DrawEllipse(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
                        }
                        //draw name of symbol
                        var text = node.ToString();
                        graphics.DrawString(text, textFont, textBrush, new RectangleF(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height), stringFormat);
                    }
        }
        protected virtual void SymbolicExpressionTreeChart_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            VisualTreeNode <ISymbolicExpressionTreeNode> visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y);

            if (visualTreeNode != null)
            {
                OnSymbolicExpressionTreeNodeDoubleClicked(visualTreeNode, e);
            }
        }
 public void RepaintNode(VisualTreeNode <ISymbolicExpressionTreeNode> visualNode)
 {
     if (!suspendRepaint)
     {
         using (var graphics = Graphics.FromImage(image)) {
             graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
             graphics.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
             DrawTreeNode(graphics, visualNode);
         }
         this.Refresh();
     }
 }
        protected void DrawLine(Graphics graphics, VisualTreeNode <ISymbolicExpressionTreeNode> startNode, VisualTreeNode <ISymbolicExpressionTreeNode> endNode)
        {
            var origin = new Point(startNode.X + startNode.Width / 2, startNode.Y + startNode.Height);
            var target = new Point(endNode.X + endNode.Width / 2, endNode.Y);

            graphics.Clip = new Region(new Rectangle(Math.Min(origin.X, target.X), origin.Y, Math.Max(origin.X, target.X), target.Y));
            var visualLine = GetVisualSymbolicExpressionTreeNodeConnection(startNode.Content, endNode.Content);

            using (var linePen = new Pen(visualLine.LineColor)) {
                linePen.DashStyle = visualLine.DashStyle;
                graphics.DrawLine(linePen, origin, target);
            }
        }
Пример #6
0
        private void RecursiveLayout(Dictionary <T, VisualTreeNode <T> > nodeMap, VisualTreeNode <T> visualTreeNode, int x, int y, int width, int height)
        {
            float center_x     = x + width / 2;
            float center_y     = y + height / 2;
            int   actualWidth  = width - HorizontalSpacing;
            int   actualHeight = height - VerticalSpacing;

            //calculate size of node
            if (actualWidth >= visualTreeNode.PreferredWidth && actualHeight >= visualTreeNode.PreferredHeight)
            {
                visualTreeNode.Width  = visualTreeNode.PreferredWidth;
                visualTreeNode.Height = visualTreeNode.PreferredHeight;
                visualTreeNode.X      = (int)center_x - visualTreeNode.Width / 2;
                visualTreeNode.Y      = (int)center_y - visualTreeNode.Height / 2;
            }
            //width too small to draw in desired sized
            else if (actualWidth < visualTreeNode.PreferredWidth && actualHeight >= visualTreeNode.PreferredHeight)
            {
                visualTreeNode.Width  = actualWidth;
                visualTreeNode.Height = visualTreeNode.PreferredHeight;
                visualTreeNode.X      = x;
                visualTreeNode.Y      = (int)center_y - visualTreeNode.Height / 2;
            }
            //height too small to draw in desired sized
            else if (actualWidth >= visualTreeNode.PreferredWidth && actualHeight < visualTreeNode.PreferredHeight)
            {
                visualTreeNode.Width  = visualTreeNode.PreferredWidth;
                visualTreeNode.Height = actualHeight;
                visualTreeNode.X      = (int)center_x - visualTreeNode.Width / 2;
                visualTreeNode.Y      = y;
            }
            //width and height too small to draw in desired size
            else
            {
                visualTreeNode.Width  = actualWidth;
                visualTreeNode.Height = actualHeight;
                visualTreeNode.X      = x;
                visualTreeNode.Y      = y;
            }
            //calculate areas for the subtrees according to their tree size
            var node     = visualTreeNode.Content;
            var children = GetChildren(node).ToList();

            int[] xBoundaries = new int[children.Count + 1];
            xBoundaries[0] = x;
            for (int i = 0; i < children.Count; i++)
            {
                xBoundaries[i + 1] = (int)(xBoundaries[i] + (width * (double)GetLength(children[i])) / (GetLength(node) - 1));
                RecursiveLayout(nodeMap, nodeMap[children[i]], xBoundaries[i], y + height, xBoundaries[i + 1] - xBoundaries[i], height);
            }
        }
Пример #7
0
        private void CreateVisualNodes(T root, Dictionary <T, VisualTreeNode <T> > map)
        {
            var node = new VisualTreeNode <T>(root)
            {
                PreferredWidth  = NodeWidth,
                PreferredHeight = NodeHeight
            };

            map.Add(root, node);
            var children = GetChildren(root).ToList();

            if (children.Any())
            {
                foreach (var child in children)
                {
                    CreateVisualNodes(child, map);
                }
            }
        }
        private void SymbolicExpressionTreeChart_MouseMove(object sender, MouseEventArgs e)
        {
            VisualTreeNode <ISymbolicExpressionTreeNode> visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y);

            if (draggedSymbolicExpressionTree != null &&
                draggedSymbolicExpressionTree != visualTreeNode)
            {
                OnSymbolicExpressionTreeNodeDragDrag(draggedSymbolicExpressionTree, new ItemDragEventArgs(dragButtons, draggedSymbolicExpressionTree));
                draggedSymbolicExpressionTree = null;
            }
            else if (draggedSymbolicExpressionTree == null &&
                     visualTreeNode != null)
            {
                string tooltipText = visualTreeNode.ToolTip;
                if (this.toolTip.GetToolTip(this) != tooltipText)
                {
                    this.toolTip.SetToolTip(this, tooltipText);
                }
            }
            else if (visualTreeNode == null)
            {
                this.toolTip.SetToolTip(this, "");
            }
        }
 private void SymbolicExpressionTreeChart_MouseUp(object sender, MouseEventArgs e)
 {
     this.draggedSymbolicExpressionTree = null;
     this.dragButtons = MouseButtons.None;
 }
 private void SymbolicExpressionTreeChart_MouseDown(object sender, MouseEventArgs e)
 {
     this.dragButtons = e.Button;
     this.draggedSymbolicExpressionTree = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y);
 }