Example #1
0
        internal void CalculatePanelSizes()
        {
            int count = 0;

            if (MatrixModel?.Hierarchy != null)
            {
                TreeIterator <Element> iterator = new TreeIterator <Element>(MatrixModel.Hierarchy);
                TreeNode <Element>     treeNode = iterator.Next();

                while (treeNode != null)
                {
                    if (treeNode.IsCollapsed)
                    {
                        count++;
                        treeNode = iterator.Skip();
                    }
                    else
                    {
                        treeNode = iterator.Next();
                    }
                }
            }

            _selector.Size = new Size(_selector.Width,
                                      count * _displayOptions.CellHeight + _displayOptions.RootHeight);

            _matrix.Size = new Size(count * _displayOptions.CellHeight,
                                    count * _displayOptions.CellHeight + _displayOptions.RootHeight);
        }
Example #2
0
        void Draw(Graphics g)
        {
            int y = -Controller.OffsetY + Controller.DisplayOptions.RootHeight;

            TreeIterator <Element> iterator = new TreeIterator <Element>(Controller.MatrixModel.Hierarchy);

            TreeNode <Element> treeNode = iterator.Next();

            //
            // RootTree has priority - so it is painted last but its panel is saved first in the hList
            if (treeNode != null)
            {
                Rectangle rootBounds = new Rectangle(
                    -Controller.OffsetX, 0,
                    Size.Width, Controller.DisplayOptions.RootHeight);

                // note  for root hpanel treeNode of nodepanel is null
                _hLayout.Add(new NodePanel(null, rootBounds));
            }

            while (treeNode != null)
            {
                if (treeNode.IsCollapsed == false || treeNode.IsHidden)
                {
                    treeNode = iterator.Next();
                }
                else
                {
                    DrawPanel(g, treeNode, y);
                    y += Controller.DisplayOptions.CellHeight;

                    treeNode = iterator.Skip();
                }
            }

            Size = new Size(y + Controller.OffsetY - Controller.DisplayOptions.RootHeight + 1, y + Controller.OffsetY + 1);

            DrawGroupingSquares(g);

            DrawRootPanel(g);
        }
Example #3
0
        void DrawGroupingSquares(Graphics g)
        {
            TreeIterator <Element> iterator = new TreeIterator <Element>(Controller.MatrixModel.Hierarchy);
            TreeNode <Element>     treeNode = iterator.Next();

            int xPos = -Controller.OffsetX + 1;
            int yPos = -Controller.OffsetY + Controller.DisplayOptions.RootHeight + 1;

            while (treeNode != null)
            {
                if (treeNode.IsHidden == false)
                {
                    if (treeNode.IsCollapsed == false)
                    {
                        int       width = Controller.CountNbDisplayableNested(treeNode) * Controller.DisplayOptions.CellHeight;
                        Rectangle rect  = new Rectangle(xPos, yPos, width - 1, width - 1);

                        if (g.Clip.IsVisible(rect))
                        {
                            g.DrawRectangle(new Pen(Brushes.DarkGray, 2), rect);
                        }
                        treeNode = iterator.Next();
                    }
                    else
                    {
                        xPos    += Controller.DisplayOptions.CellHeight;
                        yPos    += Controller.DisplayOptions.CellHeight;
                        treeNode = iterator.Skip();
                    }
                }
                else
                {
                    treeNode = iterator.Next();
                }
            }
        }
Example #4
0
        void Draw(Graphics g)
        {
            int y = -Controller.OffsetY + Controller.DisplayOptions.RootHeight;

            TreeIterator <Element> iterator = new TreeIterator <Element>(Controller.MatrixModel.Hierarchy);
            TreeNode <Element>     treeNode = iterator.Next();

            while (treeNode != null)
            {
                if (treeNode.IsHidden == false)
                {
                    if (treeNode.IsCollapsed == false)
                    {
                        Rectangle bounds = new Rectangle(
                            treeNode.Depth * Controller.DisplayOptions.CellHeight,
                            y,
                            Controller.DisplayOptions.CellHeight,
                            Controller.CountNbDisplayableNested(treeNode) * Controller.DisplayOptions.CellHeight);

                        if (g.Clip.IsVisible(bounds))
                        {
                            DrawPanel(g, bounds, treeNode);
                            _layout.Add(new NodePanel(treeNode, bounds));
                        }

                        // y position does not change for next treeNode

                        treeNode = iterator.Next();
                    }
                    else
                    {
                        // treeNode is collapsed - draw the module at position
                        // if the treeNode has childrenskip them
                        int x = treeNode.Depth * Controller.DisplayOptions.CellHeight;

                        Rectangle bounds =
                            new Rectangle(x, y, Size.Width - x, Controller.DisplayOptions.CellHeight);

                        if (g.Clip.IsVisible(bounds))
                        {
                            DrawPanel(g, bounds, treeNode);
                            _layout.Add(new NodePanel(treeNode, bounds));
                        }

                        // position for next panel
                        y += Controller.DisplayOptions.CellHeight;

                        treeNode = iterator.Skip();
                    }
                }
                else
                {
                    treeNode = iterator.Next();
                }
            }

            Size = new Size(Size.Width, y + Controller.OffsetY);
            g.DrawRectangle(_borderPen, new Rectangle(0, 0, Width - 1, Height - 1));

            Rectangle rootBounds = new Rectangle(0, 0, Size.Width - 1, Controller.DisplayOptions.RootHeight - 2);

            DrawRootPanel(g, rootBounds);
        }
Example #5
0
        void DrawPanel(Graphics g, TreeNode <Element> rowTreeNode, int y)
        {
            Rectangle rowBounds = new Rectangle(0, y, Size.Width, Controller.DisplayOptions.CellHeight);

            if (g.Clip.IsVisible(rowBounds))
            {
                _hLayout.Add(new NodePanel(rowTreeNode, rowBounds));

                // can draw some of the row
                int x = -Controller.OffsetX;

                TreeIterator <Element> iterator = new TreeIterator <Element>(Controller.MatrixModel.Hierarchy);

                TreeNode <Element> treeNode = iterator.Next();

                Element rowModule = rowTreeNode.NodeValue;

                int stateDisplay = 0;
                // trisstate optimisation 0 not started dispaying, 1 currently displaying
                // 2 finished displaying and can therefore break out of the loop

                while (treeNode != null && stateDisplay != 2)
                {
                    Element module = treeNode.NodeValue;

                    if (treeNode.IsCollapsed == false || treeNode.IsHidden)
                    {
                        treeNode = iterator.Next();
                    }
                    else
                    {
                        Rectangle cell = new Rectangle(
                            x, y, Controller.DisplayOptions.CellHeight, Controller.DisplayOptions.CellHeight);

                        if (g.Clip.IsVisible(cell))
                        {
                            if (treeNode == rowTreeNode)                                                      // the diagonal
                            {
                                g.FillRectangle(Controller.GetBackgroundColour(rowTreeNode, treeNode), cell); // TODO - OK
                            }
                            else
                            {
                                if (Controller.DisplayOptions.ShowCyclicRelations &&
                                    Controller.MatrixModel.HasCyclicRelation(module, rowModule))
                                {
                                    g.FillRectangle(Brushes.Yellow, cell);
                                }
                                //else if ( (_hPanel != null && _hPanel.TreeNode == rowTreeNode ) ||
                                //    (_vPanel != null && _vPanel.TreeNode == treeNode ) )
                                else if (Controller.ProviderTreeNode == rowTreeNode ||
                                         Controller.ConsumerTreeNode == treeNode)
                                {
                                    g.FillRectangle(Brushes.White, cell);
                                }
                                else
                                {
                                    g.FillRectangle(Controller.GetBackgroundColour(rowTreeNode, treeNode), cell);
                                    //if (rowTreeNode.Parent == treeNode.Parent )
                                    //{
                                    //    g.FillRectangle(
                                    //        Controller.GetBackgroundColour(rowTreeNode.Parent), cell); // TODO - OK
                                    //}
                                    //else
                                    //{
                                    //    //g.FillRectangle(Brushes.AliceBlue, cell);
                                    //    g.FillRectangle(
                                    //       Controller.GetBackgroundColour( treeNode ), cell );
                                    //}
                                }
                                DrawWeight(g, rowModule, module, cell);
                            }

                            g.DrawRectangle(_borderPen, cell);

                            if (stateDisplay == 0)
                            {
                                stateDisplay++;
                            }
                        }
                        else if (stateDisplay == 1)
                        {
                            stateDisplay++;
                        }

                        x       += Controller.DisplayOptions.CellHeight;
                        treeNode = iterator.Skip();
                    }
                }
            }
        }
Example #6
0
        private void DrawRootPanel(Graphics g)
        {
            int stateDisplay = 0;  // tri-state optimisation 0 not started dispaying, 1 currently displaying
                                   // 2 finished displaying and can therefore break out of the loop

            int x = -Controller.OffsetX;

            TreeIterator <Element> iterator = new TreeIterator <Element>(Controller.MatrixModel.Hierarchy);
            TreeNode <Element>     treeNode = iterator.Next();

            while (treeNode != null && stateDisplay != 2)
            {
                Element module = treeNode.NodeValue;

                if (treeNode.IsCollapsed == false || treeNode.IsHidden)
                {
                    treeNode = iterator.Next();
                }
                else
                {
                    Rectangle cell = new Rectangle(x, 0,
                                                   Controller.DisplayOptions.CellHeight, Controller.DisplayOptions.RootHeight - 2);

                    if (g.Clip.IsVisible(cell))
                    {
                        // for each visible cell we create a vertical panel in vLayout of
                        // height of _matrix
                        Rectangle vPanelRec =
                            new Rectangle(x, 0, Controller.DisplayOptions.CellHeight, Size.Height);
                        _vLayout.Add(new NodePanel(treeNode, vPanelRec));

                        g.FillRectangle(
                            Controller.ConsumerTreeNode == treeNode
                                ? Brushes.White
                                : Controller.GetBackgroundColour(treeNode, null), cell);

                        if (treeNode.HasChildren)
                        {
                            g.DrawImage(_imgCollapsed, cell.Left + (cell.Width / 2.0f) - 4, cell.Top + 2);
                        }

                        g.DrawString(module.Id.ToString(), Controller.DisplayOptions.TextFont,
                                     _fcBrush, x, 10, _vStringFormat);

                        g.DrawRectangle(_borderPen, cell);
                        g.DrawLine(new Pen(Brushes.White, 1),
                                   cell.Left, cell.Bottom + 1, cell.Right, cell.Bottom + 1);

                        if (stateDisplay == 0)
                        {
                            stateDisplay++;
                        }
                    }
                    else if (stateDisplay == 1)
                    {
                        stateDisplay++; // finished displaying
                    }
                    x += Controller.DisplayOptions.CellHeight;

                    treeNode = iterator.Skip();
                }
            }
        }