private static void ExtractOperators(SqlParseTree tree)
        {
            List <OperatorColor> operatorColors      = new List <OperatorColor>(ViewerSettings.Instance.OperatorColors);
            Dictionary <string, OperatorColor> index = new Dictionary <string, OperatorColor>();

            operatorColors.ForEach(o => { if (index.ContainsKey(o.OperatorName) == false)
                                          {
                                              index.Add(o.OperatorName, o);
                                          }
                                   });
            List <SqlParseTreeNode> nodes = new List <SqlParseTreeNode>()
            {
                tree.RootNode
            };

            while (nodes.Count > 0)
            {
                foreach (SqlParseTreeNode node in nodes)
                {
                    if (string.IsNullOrEmpty(node.OperationName) == false &&
                        index.ContainsKey(node.OperationName) == false)
                    {
                        OperatorColor operatorColor = new OperatorColor();
                        operatorColor.OperatorName = node.OperationName;
                        operatorColor.DisplayColor = GetColorForOperator(node.OperationName);
                        index.Add(node.OperationName, operatorColor);
                        ViewerSettings.Instance.AddOperatorColor(node.OperationName, operatorColor.DisplayColor);
                    }
                }

                nodes = nodes.SelectMany(n => n.Children).ToList();
            }
        }
コード例 #2
0
        public static SqlParseTree RemoveLowValueLeafLevelNodes(SqlParseTree inputTree)
        {
            SqlParseTree tree = SqlParseTree.Clone(inputTree);

            RemoveLowValueLeafLevelNodes(tree.RootNode);
            return(tree);
        }
        public override Bitmap Render(SqlParseTree tree, out List <TreeNodeIcon> nodeIcons)
        {
            if (tree == null)
            {
                throw new ArgumentNullException(nameof(tree));
            }

            int maxDepth;
            int maxWidth;
            List <TreeNodeIcon> icons = FlattenTree(tree, out maxDepth, out maxWidth);

            int width  = _leftMargin + _rightMargin + maxWidth * _blockWidth + (maxWidth - 1) * _spacingWidth;
            int height = _topMargin + _bottomMargin + maxDepth * _blockHeight + (maxDepth - 1) * _spacingHeight;

            CenterLevels(icons, width);
            BalanceNodes(icons);
            PositionNodes(icons, out width);

            Font font = new Font("Times New Roman", 10);
            Pen  leafNodeBorderPen = new Pen(Color.Red, 2);

            Bitmap bitmap = new Bitmap(width, height);

            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                graphics.FillRectangle(Brushes.White, 0, 0, width, height);
                foreach (TreeNodeIcon icon in icons)
                {
                    Rectangle rectangle = new Rectangle(icon.Left, icon.Top, icon.Width, icon.Height);
                    //graphics.FillRectangle(Brushes.LightSteelBlue, rectangle);
                    Brush brush     = GetBrushForOperator(icon.Node.OperationName);
                    Pen   borderPen = icon.IsLeafNode ? leafNodeBorderPen : null;
                    DrawFilledRoundedRectangle(graphics, brush, rectangle, borderPen);
                    SizeF      textSize      = graphics.MeasureString(icon.Node.OperationName, font);
                    RectangleF textRectangle = new RectangleF(
                        icon.Left + icon.Width / 2 - textSize.Width / 2,
                        icon.Top + icon.Height / 2 - textSize.Height / 2,
                        textSize.Width,
                        textSize.Height);
                    graphics.DrawString(icon.Node.OperationName, font, Brushes.Black, textRectangle);

                    if (icon.Parent != null)
                    {
                        graphics.DrawLine(Pens.Black, icon.Left + icon.Width / 2, icon.Top, icon.Parent.Left + icon.Parent.Width / 2, icon.Parent.Top + icon.Parent.Height);
                    }
                }
            }

            nodeIcons = icons;
            ExtractOperators(tree);
            return(bitmap);
        }
        private static List <TreeNodeIcon> FlattenTree(SqlParseTree tree, out int maxDepth, out int maxWidth)
        {
            Dictionary <int, int> levelCounts = new Dictionary <int, int>();
            List <TreeNodeIcon>   icons       = new List <TreeNodeIcon>();

            MeasureNode(tree.RootNode, 0, levelCounts, icons);

            maxDepth = levelCounts.Keys.Count;
            maxWidth = levelCounts.Values.Max();
            FixupParentLinks(icons);

            return(icons);
        }
コード例 #5
0
        public TabPage DrawTree(SqlParseTree tree)
        {
            TabPage tab = new TabPage(tree.TreeDescription);

            ParseTreeTab subTab = new ParseTreeTab();

            subTab.Left   = 0;
            subTab.Top    = 0;
            subTab.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;

            tab.Controls.Add(subTab);
            tab.Size    = mainTabControl.Size;
            subTab.Size = tab.Size;

            List <TreeNodeIcon> treeNodeIcons;
            TreeVisualizer      treeVisualizer = TreeVisualizer.Create();
            Bitmap bitmap = treeVisualizer.Render(tree, out treeNodeIcons);

            subTab.DrawingSurface.Image = bitmap;
            subTab.TreeText             = tree.InnerTreeText;
            subTab.SetIcons(treeNodeIcons.ConvertAll(i => i as NodeIcon));

            return(tab);
        }
コード例 #6
0
        public override Bitmap Render(SqlParseTree tree, out List <TreeNodeIcon> nodeIcons)
        {
            if (tree == null)
            {
                throw new ArgumentNullException(nameof(tree));
            }

            if (ViewerSettings.Instance.HideLowValueLeafLevelNodes.Value == true)
            {
                tree = TreeSimplifier.RemoveLowValueLeafLevelNodes(tree);
            }

            using (Bitmap dummyBitmap = new Bitmap(1, 1))
            {
                _dummyGraphics = Graphics.FromImage(dummyBitmap);
                try
                {
                    nodeIcons = PositionNodes(tree);
                }
                finally
                {
                    _dummyGraphics.Dispose();
                }
            }

            int width  = _leftMargin + nodeIcons.GetWidth() + _rightMargin;
            int height = _topMargin + nodeIcons.GetHeight() + _bottomMargin;

            Bitmap bitmap = new Bitmap(width, height);

            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                graphics.FillRectangle(Brushes.White, 0, 0, width, height);
                foreach (TreeNodeIcon icon in nodeIcons)
                {
                    if (icon.Icon != null)
                    {
                        graphics.DrawIcon(icon.Icon, icon.IconRectangle);
                    }
                    else
                    {
                        graphics.DrawRectangle(Pens.Black, icon.IconRectangle);
                    }
                    graphics.DrawString(icon.Text, _textFont, Brushes.Black, icon.TextRectangle);

                    // Draw connectors between icons
                    if (icon.Children.Count > 0)
                    {
                        int arrowLeft     = icon.IconRectangle.Left + icon.IconRectangle.Width + _connectorHorizontalSpacing;
                        int firstArrowTop = (icon.IconRectangle.Top + icon.IconRectangle.Bottom) / 2 - _connectorVerticalSpacing * (icon.Children.Count - 1) / 2;
                        int arrowTop      = firstArrowTop;

                        if (arrowTop + _connectorVerticalSpacing * (icon.Children.Count - 1) > icon.IconRectangle.Bottom)
                        {
                            arrowLeft = Math.Max(arrowLeft, icon.TextRectangle.Left + icon.TextRectangle.Width + _connectorHorizontalSpacing);
                        }

                        int  centerAdjustment = _connectorHorizontalSpacing * icon.Children.Count / 2;
                        bool isFirst          = true;

                        foreach (var childIcon in icon.Children)
                        {
                            int arrowRight            = childIcon.IconRectangle.Left - _connectorHorizontalSpacing;
                            int arrowBottom           = isFirst ? firstArrowTop : (childIcon.IconRectangle.Top + childIcon.IconRectangle.Bottom) / 2;
                            int arrowHorizontalCenter = (arrowLeft + arrowRight) / 2 + centerAdjustment;

                            graphics.DrawLine(Pens.Black, arrowLeft, arrowTop, arrowHorizontalCenter, arrowTop);
                            graphics.DrawLine(Pens.Black, arrowHorizontalCenter, arrowTop, arrowHorizontalCenter, arrowBottom);
                            graphics.DrawLine(Pens.Black, arrowHorizontalCenter, arrowBottom, arrowRight, arrowBottom);

                            isFirst           = false;
                            arrowTop         += _connectorVerticalSpacing;
                            centerAdjustment -= _connectorHorizontalSpacing;
                        }
                    }
                }
            }

            return(bitmap);
        }
コード例 #7
0
        private List <TreeNodeIcon> PositionNodes(SqlParseTree tree)
        {
            List <TreeNodeIcon> nodeIcons = PositionSubtree(tree.RootNode, _leftMargin, _topMargin);

            return(nodeIcons);
        }
コード例 #8
0
 public abstract Bitmap Render(SqlParseTree tree, out List <TreeNodeIcon> nodeIcons);