Ejemplo n.º 1
0
        private void LayoutChildShapes(DiagramShapeControlBase parentShape, DiagramLayoutDirection direction)
        {
            allowRefresh = false;
            this.SuspendLayout();

            if (parentShape != null && parentShape.Expanded)
            {
                int childPos = 0;

                foreach (DiagramShapeControlBase childShape in parentShape.childShapes)
                {
                    int childSize = 0;

                    // First of all, get the maximum size of the all the expanded child nodes
                    if (direction == DiagramLayoutDirection.Vertical)
                    {
                            childSize = GetMaxExpandedChildNodesSize(childShape, direction, childShape.Width);
                            childShape.newLocation = new Point(childPos + (childSize - childShape.Width) / 2, parentShape.Bottom + childNodeMargin);
                    }
                    else if (direction == DiagramLayoutDirection.Horizontal)
                    {
                            childSize = GetMaxExpandedChildNodesSize(childShape, direction, childShape.Height);
                            childShape.newLocation = new Point(parentShape.Right + childNodeMargin, childPos + (childSize - childShape.Height) / 2);
                    }

                    childPos += childSize + peerNodeMargin;
                }

                childPos -= peerNodeMargin;

                int shift = 0;

                if (direction == DiagramLayoutDirection.Vertical)
                    shift = parentShape.Left + parentShape.Width / 2 - childPos / 2;//(this.Width - childPos) / 2 - (rootShape.Left - parentShape.Left);
                else if (direction == DiagramLayoutDirection.Horizontal)
                    shift = parentShape.Top + parentShape.Height / 2 - childPos / 2;//(this.Width - childPos) / 2 - (rootShape.Left - parentShape.Left);

                // Now center our child nodes
                foreach (DiagramShapeControlBase childShape in parentShape.childShapes)
                {
                    if (direction == DiagramLayoutDirection.Vertical)
                        childShape.newLocation.Offset(shift, 0);
                    else if (direction == DiagramLayoutDirection.Horizontal)
                        childShape.newLocation.Offset(0, shift);

                    childShape.Location = childShape.newLocation;
                    childShape.Visible = true;

                    LayoutChildShapes(childShape, direction);
                }
            }

            if (parentShape != null)
            {
                // Update our expander
                if (direction == DiagramLayoutDirection.Vertical)
                {
                    parentShape.expander.Left = parentShape.Left + (parentShape.Width - parentShape.expander.Width) / 2;
                    parentShape.expander.Top = parentShape.Bottom;
                }
                else if (direction == DiagramLayoutDirection.Horizontal)
                {
                    parentShape.expander.Left = parentShape.Right;
                    parentShape.expander.Top = parentShape.Top + (parentShape.Height - parentShape.expander.Height) / 2;
                }
            }

            this.ResumeLayout(true);

            this.Invalidate(false);
            allowRefresh = true;
        }
Ejemplo n.º 2
0
        private int GetMaxExpandedChildNodesSize(DiagramShapeControlBase parentShape, DiagramLayoutDirection direction, int maxExpandedSize)
        {
            // If the parent node is expanded get the number of child nodes to this node
            int maxChildSize = 0;

            if (parentShape.Expanded)
            {
                foreach (DiagramShapeControlBase childShape in parentShape.childShapes)
                {
                    if (direction == DiagramLayoutDirection.Vertical)
                        maxChildSize += GetMaxExpandedChildNodesSize(childShape, direction, childShape.Width);
                    else if (direction == DiagramLayoutDirection.Horizontal)
                        maxChildSize += GetMaxExpandedChildNodesSize(childShape, direction, childShape.Height);

                    maxChildSize += peerNodeMargin;
                }

                maxChildSize -= peerNodeMargin;
            }

            return Math.Max(maxChildSize, maxExpandedSize);
        }
Ejemplo n.º 3
0
        private void DrawConnectors(DiagramShapeControlBase parentShape, Graphics g, Pen pen, Brush brush, DiagramLayoutDirection direction, DiagramConnectorType connectorType)
        {
            if (parentShape.Expanded)
            {
                Point startPoint = new Point();
                Point endPoint = new Point();

                if (showExpanders)
                {
                    startPoint.X = parentShape.expander.Left + parentShape.expander.Width / 2;
                    startPoint.Y = parentShape.expander.Top + parentShape.expander.Height / 2;
                }
                else
                {
                    if (direction == DiagramLayoutDirection.Vertical)
                    {
                        startPoint.X = parentShape.Left + parentShape.Width / 2;
                        startPoint.Y = parentShape.Bottom;
                    }
                    else if (direction == DiagramLayoutDirection.Horizontal)
                    {
                        startPoint.Y = parentShape.Top + parentShape.Height / 2;
                        startPoint.X = parentShape.Right;
                    }
                }

                foreach (DiagramShapeControlBase shape in parentShape.childShapes)
                {
                    if (direction == DiagramLayoutDirection.Vertical)
                    {
                        endPoint.Y = shape.Top;
                        endPoint.X = shape.Left + (shape.Width / 2);
                    }
                    else if (direction == DiagramLayoutDirection.Horizontal)
                    {
                        endPoint.Y = shape.Top + (shape.Height / 2);
                        endPoint.X = shape.Left;
                    }

                    switch (connectorType)
                    {
                        case DiagramConnectorType.Standard:
                            g.DrawLine(pen, startPoint, endPoint);

                            break;

                        case DiagramConnectorType.Bezier:
                            Point pt1 = Point.Empty;
                            Point pt2 = Point.Empty;

                            if (direction == DiagramLayoutDirection.Vertical)
                            {
                                pt1 = new Point(startPoint.X, startPoint.Y + 20);
                                pt2 = new Point(endPoint.X, endPoint.Y - 20);
                            }
                            else if (direction == DiagramLayoutDirection.Horizontal)
                            {
                                pt1 = new Point(startPoint.X + 20, startPoint.Y);
                                pt2 = new Point(endPoint.X - 20, endPoint.Y);
                            }

                            g.DrawBezier(pen, startPoint, pt1, pt2, endPoint);

                            break;
                    }

                    // Draw arrows
                    if (drawArrows)
                    {
                        Point anglePoint = new Point(endPoint.X - startPoint.X, endPoint.Y - startPoint.Y);
                        float angle = (float)(Math.Atan2(anglePoint.Y, anglePoint.X) * (180.0 / Math.PI));

                        if (connectorType == DiagramConnectorType.Bezier)
                        {
                            if (direction == DiagramLayoutDirection.Horizontal)
                                angle *= 0.5f;
                            else
                                angle = 90.0f + (angle - 90.0f) * 0.5f;
                        }

                        g.TranslateTransform(endPoint.X, endPoint.Y);
                        g.RotateTransform(angle);

                        g.FillPath(brush, arrowPath);

                        g.ResetTransform();
                    }

                    DrawConnectors(shape, g, pen, brush, direction, connectorType);
                }
            }
        }
Ejemplo n.º 4
0
        private int GetMaxExpandedChildNodesSize(DiagramShapeControlBase parentShape, DiagramLayoutDirection direction, int maxExpandedSize)
        {
            // If the parent node is expanded get the number of child nodes to this node
            int maxChildSize = 0;

            if (parentShape.Expanded)
            {
                foreach (DiagramShapeControlBase childShape in parentShape.childShapes)
                {
                    if (direction == DiagramLayoutDirection.Vertical)
                    {
                        maxChildSize += GetMaxExpandedChildNodesSize(childShape, direction, childShape.Width);
                    }
                    else if (direction == DiagramLayoutDirection.Horizontal)
                    {
                        maxChildSize += GetMaxExpandedChildNodesSize(childShape, direction, childShape.Height);
                    }

                    maxChildSize += peerNodeMargin;
                }

                maxChildSize -= peerNodeMargin;
            }

            return(Math.Max(maxChildSize, maxExpandedSize));
        }
Ejemplo n.º 5
0
        private void DrawConnectors(DiagramShapeControlBase parentShape, Graphics g, Pen pen, Brush brush, DiagramLayoutDirection direction, DiagramConnectorType connectorType)
        {
            if (parentShape.Expanded)
            {
                Point startPoint = new Point();
                Point endPoint   = new Point();

                if (showExpanders)
                {
                    startPoint.X = parentShape.expander.Left + parentShape.expander.Width / 2;
                    startPoint.Y = parentShape.expander.Top + parentShape.expander.Height / 2;
                }
                else
                {
                    if (direction == DiagramLayoutDirection.Vertical)
                    {
                        startPoint.X = parentShape.Left + parentShape.Width / 2;
                        startPoint.Y = parentShape.Bottom;
                    }
                    else if (direction == DiagramLayoutDirection.Horizontal)
                    {
                        startPoint.Y = parentShape.Top + parentShape.Height / 2;
                        startPoint.X = parentShape.Right;
                    }
                }

                foreach (DiagramShapeControlBase shape in parentShape.childShapes)
                {
                    if (direction == DiagramLayoutDirection.Vertical)
                    {
                        endPoint.Y = shape.Top;
                        endPoint.X = shape.Left + (shape.Width / 2);
                    }
                    else if (direction == DiagramLayoutDirection.Horizontal)
                    {
                        endPoint.Y = shape.Top + (shape.Height / 2);
                        endPoint.X = shape.Left;
                    }

                    switch (connectorType)
                    {
                    case DiagramConnectorType.Standard:
                        g.DrawLine(pen, startPoint, endPoint);

                        break;

                    case DiagramConnectorType.Bezier:
                        Point pt1 = Point.Empty;
                        Point pt2 = Point.Empty;

                        if (direction == DiagramLayoutDirection.Vertical)
                        {
                            pt1 = new Point(startPoint.X, startPoint.Y + 20);
                            pt2 = new Point(endPoint.X, endPoint.Y - 20);
                        }
                        else if (direction == DiagramLayoutDirection.Horizontal)
                        {
                            pt1 = new Point(startPoint.X + 20, startPoint.Y);
                            pt2 = new Point(endPoint.X - 20, endPoint.Y);
                        }

                        g.DrawBezier(pen, startPoint, pt1, pt2, endPoint);

                        break;
                    }

                    // Draw arrows
                    if (drawArrows)
                    {
                        Point anglePoint = new Point(endPoint.X - startPoint.X, endPoint.Y - startPoint.Y);
                        float angle      = (float)(Math.Atan2(anglePoint.Y, anglePoint.X) * (180.0 / Math.PI));

                        if (connectorType == DiagramConnectorType.Bezier)
                        {
                            if (direction == DiagramLayoutDirection.Horizontal)
                            {
                                angle *= 0.5f;
                            }
                            else
                            {
                                angle = 90.0f + (angle - 90.0f) * 0.5f;
                            }
                        }

                        g.TranslateTransform(endPoint.X, endPoint.Y);
                        g.RotateTransform(angle);

                        g.FillPath(brush, arrowPath);

                        g.ResetTransform();
                    }

                    DrawConnectors(shape, g, pen, brush, direction, connectorType);
                }
            }
        }
Ejemplo n.º 6
0
        private void LayoutChildShapes(DiagramShapeControlBase parentShape, DiagramLayoutDirection direction)
        {
            allowRefresh = false;
            this.SuspendLayout();

            if (parentShape != null && parentShape.Expanded)
            {
                int childPos = 0;

                foreach (DiagramShapeControlBase childShape in parentShape.childShapes)
                {
                    int childSize = 0;

                    // First of all, get the maximum size of the all the expanded child nodes
                    if (direction == DiagramLayoutDirection.Vertical)
                    {
                        childSize = GetMaxExpandedChildNodesSize(childShape, direction, childShape.Width);
                        childShape.newLocation = new Point(childPos + (childSize - childShape.Width) / 2, parentShape.Bottom + childNodeMargin);
                    }
                    else if (direction == DiagramLayoutDirection.Horizontal)
                    {
                        childSize = GetMaxExpandedChildNodesSize(childShape, direction, childShape.Height);
                        childShape.newLocation = new Point(parentShape.Right + childNodeMargin, childPos + (childSize - childShape.Height) / 2);
                    }

                    childPos += childSize + peerNodeMargin;
                }

                childPos -= peerNodeMargin;

                int shift = 0;

                if (direction == DiagramLayoutDirection.Vertical)
                {
                    shift = parentShape.Left + parentShape.Width / 2 - childPos / 2;//(this.Width - childPos) / 2 - (rootShape.Left - parentShape.Left);
                }
                else if (direction == DiagramLayoutDirection.Horizontal)
                {
                    shift = parentShape.Top + parentShape.Height / 2 - childPos / 2;//(this.Width - childPos) / 2 - (rootShape.Left - parentShape.Left);
                }
                // Now center our child nodes
                foreach (DiagramShapeControlBase childShape in parentShape.childShapes)
                {
                    if (direction == DiagramLayoutDirection.Vertical)
                    {
                        childShape.newLocation.Offset(shift, 0);
                    }
                    else if (direction == DiagramLayoutDirection.Horizontal)
                    {
                        childShape.newLocation.Offset(0, shift);
                    }

                    childShape.Location = childShape.newLocation;
                    childShape.Visible  = true;

                    LayoutChildShapes(childShape, direction);
                }
            }

            if (parentShape != null)
            {
                // Update our expander
                if (direction == DiagramLayoutDirection.Vertical)
                {
                    parentShape.expander.Left = parentShape.Left + (parentShape.Width - parentShape.expander.Width) / 2;
                    parentShape.expander.Top  = parentShape.Bottom;
                }
                else if (direction == DiagramLayoutDirection.Horizontal)
                {
                    parentShape.expander.Left = parentShape.Right;
                    parentShape.expander.Top  = parentShape.Top + (parentShape.Height - parentShape.expander.Height) / 2;
                }
            }

            this.ResumeLayout(true);

            this.Invalidate(false);
            allowRefresh = true;
        }