Esempio n. 1
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));
        }
Esempio n. 2
0
        public void AddRandomShape(DiagramShapeControlBase shape)
        {
            Random rand = new Random();

            int shapeControls = 0;

            foreach (Control control in Controls)
            {
                if (control is DiagramShapeControlBase)
                {
                    shapeControls++;
                }
            }

            int randomShapeIndex = rand.Next(shapeControls);

            shapeControls = 0;

            foreach (Control control in Controls)
            {
                if (control is DiagramShapeControlBase)
                {
                    if (shapeControls == randomShapeIndex)
                    {
                        ((DiagramShapeControlBase)control).AddChildShape(shape);
                        return;
                    }

                    shapeControls++;
                }
            }
        }
        private void RemoveShapeFromDiagram(DiagramShapeControlBase shape)
        {
            if (this.Parent != null)
            {
                this.Parent.Controls.Remove(shape);

                foreach (DiagramShapeControlBase childShape in shape.childShapes)
                {
                    RemoveShapeFromDiagram(childShape);
                }
            }
        }
        private void AddShapeToDiagram(DiagramShapeControlBase shape)
        {
            if (this.Parent != null)
            {
                this.Parent.Controls.Add(shape);

                foreach (DiagramShapeControlBase childShape in shape.childShapes)
                {
                    AddShapeToDiagram(childShape);
                }
            }
        }
Esempio n. 5
0
        public void CollapseAll()
        {
            allowRefresh = false;

            foreach (Control control in this.Controls)
            {
                DiagramShapeControlBase shapeControl = control as DiagramShapeControlBase;

                if (shapeControl != null)
                {
                    shapeControl.Expanded = false;
                }
            }

            allowRefresh = true;
            RefreshDiagram();
        }
        public void RemoveChildShape(DiagramShapeControlBase childShape)
        {
            if (this.childShapes.Contains(childShape))
            {
                RemoveShapeFromDiagram(childShape);

                this.childShapes.Remove(childShape);
                childShape.parentShape = null;

                UpdateExpander();

                if (Parent is DiagramControl)
                {
                    ((DiagramControl)Parent).RefreshDiagram();
                }
            }
        }
        public DiagramShapeControlBase InsertChildShape(int index, DiagramShapeControlBase childShape)
        {
            // If the child already belongs to another parent, make sure you remove it from that parent
            if (childShape.parentShape != null)
            {
                childShape.ParentShape.RemoveChildShape(childShape);
            }

            this.childShapes.Insert(index, childShape);
            childShape.parentShape = this;

            AddShapeToDiagram(childShape);

            UpdateExpander();

            if (Parent is DiagramControl)
            {
                ((DiagramControl)Parent).RefreshDiagram();
            }

            return(childShape);
        }
Esempio n. 8
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);
                }
            }
        }
Esempio n. 9
0
        public void AddRandomShape(DiagramShapeControlBase shape)
        {
            Random rand = new Random();

            int shapeControls = 0;

            foreach (Control control in Controls)
            {
                if (control is DiagramShapeControlBase)
                    shapeControls++;
            }

            int randomShapeIndex = rand.Next(shapeControls);
            shapeControls = 0;

            foreach (Control control in Controls)
            {
                if (control is DiagramShapeControlBase)
                {
                    if (shapeControls == randomShapeIndex)
                    {
                        ((DiagramShapeControlBase)control).AddChildShape(shape);
                        return;
                    }

                    shapeControls++;
                }
            }
        }
Esempio n. 10
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);
                }
            }
        }
        private void RemoveShapeFromDiagram(DiagramShapeControlBase shape)
        {
            if (this.Parent != null)
            {
                this.Parent.Controls.Remove(shape);

                foreach (DiagramShapeControlBase childShape in shape.childShapes)
                {
                    RemoveShapeFromDiagram(childShape);
                }
            }
        }
        private void AddShapeToDiagram(DiagramShapeControlBase shape)
        {
            if (this.Parent != null)
            {
                this.Parent.Controls.Add(shape);

                foreach (DiagramShapeControlBase childShape in shape.childShapes)
                {
                    AddShapeToDiagram(childShape);
                }
            }
        }
        public void RemoveChildShape(DiagramShapeControlBase childShape)
        {
            if (this.childShapes.Contains(childShape))
            {
                RemoveShapeFromDiagram(childShape);

                this.childShapes.Remove(childShape);
                childShape.parentShape = null;

                UpdateExpander();

                if (Parent is DiagramControl)
                    ((DiagramControl)Parent).RefreshDiagram();
            }
        }
        public DiagramShapeControlBase InsertChildShape(int index, DiagramShapeControlBase childShape)
        {
            // If the child already belongs to another parent, make sure you remove it from that parent
            if (childShape.parentShape != null)
            {
                childShape.ParentShape.RemoveChildShape(childShape);
            }

            this.childShapes.Insert(index, childShape);
            childShape.parentShape = this;

            AddShapeToDiagram(childShape);

            UpdateExpander();

            if (Parent is DiagramControl)
                ((DiagramControl)Parent).RefreshDiagram();

            return childShape;
        }
Esempio n. 15
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);
        }
Esempio n. 16
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;
        }
Esempio n. 17
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;
        }