Example #1
0
 /// <exception cref="ArgumentNullException">
 /// <paramref name="shape"/> is null.
 /// </exception>
 internal TerminalNode(EntityShape shape, Point mouseLocation) : this(shape)
 {
     SetPosition(mouseLocation);
 }
Example #2
0
 internal TerminalNode()
 {
     shape = null;
 }
Example #3
0
        private void PerpendicularCalculation()
        {
            if (startNode.Shape == null || endNode.Shape == null)
            {
                return;
            }

            EntityShape startShape = StartNode.Shape;
            EntityShape endShape   = EndNode.Shape;

            if (StartNode.IsVertical)
            {
                nodes[0].X = StartNode.AbsoluteLocation;

                if ((StartNode.AbsoluteLocation < endShape.Left - MarginSize ||
                     StartNode.AbsoluteLocation >= endShape.Right + MarginSize) &&
                    (EndNode.AbsoluteLocation < startShape.Top - MarginSize ||
                     EndNode.AbsoluteLocation >= startShape.Bottom + MarginSize))
                {
                    nodeCount = 3;

                    if (startShape.Top < endShape.Top)
                    {
                        nodes[0].Y = startShape.Bottom;
                    }
                    else
                    {
                        nodes[0].Y = startShape.Top - 1;
                    }

                    if (startShape.Left < endShape.Left)
                    {
                        nodes[2].X = endShape.Left - 1;
                    }
                    else
                    {
                        nodes[2].X = endShape.Right;
                    }

                    nodes[1]   = new Point(StartNode.AbsoluteLocation, EndNode.AbsoluteLocation);
                    nodes[2].Y = EndNode.AbsoluteLocation;
                }
                else
                {
                    Point connector = new Point();
                    bool  vertical  = StartNode.AbsoluteLocation >= endShape.Left - MarginSize &&
                                      StartNode.AbsoluteLocation < endShape.Right + MarginSize;

                    nodeCount = 5;

                    if (StartNode.AbsoluteLocation < (endShape.Left + endShape.Right) / 2 &&
                        vertical || (!vertical && endShape.Left > startShape.Left))
                    {
                        connector.X = endShape.Left - MarginSize - 1;
                        nodes[4].X  = endShape.Left - 1;
                    }
                    else
                    {
                        connector.X = endShape.Right + MarginSize;
                        nodes[4].X  = endShape.Right;
                    }

                    if (EndNode.AbsoluteLocation < (startShape.Top + startShape.Bottom) / 2 &&
                        !vertical || (vertical && startShape.Top >= endShape.Top))
                    {
                        connector.Y = startShape.Top - MarginSize - 1;
                        nodes[0].Y  = startShape.Top - 1;
                    }
                    else
                    {
                        connector.Y = startShape.Bottom + MarginSize;
                        nodes[0].Y  = startShape.Bottom;
                    }

                    nodes[1]   = new Point(StartNode.AbsoluteLocation, connector.Y);
                    nodes[2]   = connector;
                    nodes[3]   = new Point(connector.X, EndNode.AbsoluteLocation);
                    nodes[4].Y = EndNode.AbsoluteLocation;
                }
            }
            else               // startNode.IsHorizontal
            {
                nodes[0].Y = StartNode.AbsoluteLocation;

                if ((StartNode.AbsoluteLocation < endShape.Top - MarginSize ||
                     StartNode.AbsoluteLocation >= endShape.Bottom + MarginSize) &&
                    (EndNode.AbsoluteLocation < startShape.Left - MarginSize ||
                     EndNode.AbsoluteLocation >= startShape.Right + MarginSize))
                {
                    nodeCount = 3;

                    if (startShape.Left < endShape.Left)
                    {
                        nodes[0].X = startShape.Right;
                    }
                    else
                    {
                        nodes[0].X = startShape.Left - 1;
                    }

                    if (startShape.Top < endShape.Top)
                    {
                        nodes[2].Y = endShape.Top - 1;
                    }
                    else
                    {
                        nodes[2].Y = endShape.Bottom;
                    }

                    nodes[1]   = new Point(EndNode.AbsoluteLocation, StartNode.AbsoluteLocation);
                    nodes[2].X = EndNode.AbsoluteLocation;
                }
                else
                {
                    Point connector  = new Point();
                    bool  horizontal = StartNode.AbsoluteLocation >= endShape.Top - MarginSize &&
                                       StartNode.AbsoluteLocation < endShape.Bottom + MarginSize;

                    nodeCount = 5;

                    if (StartNode.AbsoluteLocation < (endShape.Top + endShape.Bottom) / 2 &&
                        horizontal || (!horizontal && endShape.Top > startShape.Top))
                    {
                        connector.Y = endShape.Top - MarginSize - 1;
                        nodes[4].Y  = endShape.Top - 1;
                    }
                    else
                    {
                        connector.Y = endShape.Bottom + MarginSize;
                        nodes[4].Y  = endShape.Bottom;
                    }

                    if (EndNode.AbsoluteLocation < (startShape.Left + startShape.Right) / 2 &&
                        !horizontal || (horizontal && startShape.Left >= endShape.Left))
                    {
                        connector.X = startShape.Left - MarginSize - 1;
                        nodes[0].X  = startShape.Left - 1;
                    }
                    else
                    {
                        connector.X = startShape.Right + MarginSize;
                        nodes[0].X  = startShape.Right;
                    }

                    nodes[1]   = new Point(connector.X, StartNode.AbsoluteLocation);
                    nodes[2]   = connector;
                    nodes[3]   = new Point(EndNode.AbsoluteLocation, connector.Y);
                    nodes[4].X = EndNode.AbsoluteLocation;
                }
            }
        }
Example #4
0
        private void Shape_MouseMove(object sender, MouseEventArgs e)
        {
            EntityShape shape = (EntityShape)sender;

            if (shapePositioning)
            {
                Size movingSize = new Size(e.Location.X - oldMouseLocation.X,
                                           e.Location.Y - oldMouseLocation.Y);

                // Resizing
                if (ShapeResizing)
                {
                    if (!shapeHorizontalResizing)
                    {
                        movingSize.Width = 0;
                    }
                    if (!shapeVerticalResizing)
                    {
                        movingSize.Height = 0;
                    }

                    if (Settings.CurrentSettings.UsePrecisionSnapping &&
                        Control.ModifierKeys != Keys.Shift)
                    {
                        SnapEdges(shape, ref movingSize);
                    }
                    oldMouseLocation += movingSize;
                    Size oldSize = shape.Size;
                    shape.Size       += movingSize;
                    oldMouseLocation -= oldSize - shape.Size + movingSize;
                }
                // Moving
                else
                {
                    movingSize = CheckDiagramBorders(movingSize);
                    if (Settings.CurrentSettings.UsePrecisionSnapping &&
                        Control.ModifierKeys != Keys.Shift)
                    {
                        SnapLocations(shape.Location, ref movingSize);
                    }
                    MoveSelectedItems(movingSize);
                }
            }
            else if (ConnectionPositioning)
            {
                if (startNode != null && !StartChosen)
                {
                    if (startNode.IsVertical)
                    {
                        startNode.RelativeLocation = e.X;
                    }
                    else
                    {
                        startNode.RelativeLocation = e.Y;
                    }
                }
                else if (endNode != null)
                {
                    if (endNode.IsVertical)
                    {
                        endNode.RelativeLocation = e.X;
                    }
                    else
                    {
                        endNode.RelativeLocation = e.Y;
                    }
                }
                Invalidate();
            }
            else if (!Connecting)
            {
                shapeHorizontalResizing = (e.Location.X >= shape.Width - ResizeMargin);
                shapeVerticalResizing   = (e.Location.Y >= shape.Height - ResizeMargin);

                if (shapeHorizontalResizing && shapeVerticalResizing)
                {
                    Cursor = Cursors.SizeNWSE;
                }
                else if (shapeHorizontalResizing)
                {
                    Cursor = Cursors.SizeWE;
                }
                else if (shapeVerticalResizing)
                {
                    Cursor = Cursors.SizeNS;
                }
                else
                {
                    Cursor = Cursors.Default;
                }
            }
        }
Example #5
0
        private void ParallelCalculation()
        {
            if (startNode.Shape == null || endNode.Shape == null)
            {
                return;
            }

            EntityShape startShape = StartNode.Shape;
            EntityShape endShape   = EndNode.Shape;

            nodeCount = 4;

            if (StartNode.IsVertical)
            {
                nodes[0].X = nodes[1].X = StartNode.AbsoluteLocation;
                nodes[2].X = nodes[3].X = EndNode.AbsoluteLocation;

                if (endShape.Top - startShape.Bottom >= 2 * MarginSize ||
                    startShape.Top - endShape.Bottom >= 2 * MarginSize)
                {
                    if (startShape.Top < endShape.Top)
                    {
                        int semiLength = (endShape.Top - startShape.Bottom) / 2;

                        nodes[0].Y = startShape.Bottom;
                        nodes[1].Y = startShape.Bottom + semiLength;
                        nodes[2].Y = startShape.Bottom + semiLength;
                        nodes[3].Y = endShape.Top - 1;
                    }
                    else
                    {
                        int semiLength = (startShape.Top - endShape.Bottom) / 2;

                        nodes[0].Y = startShape.Top - 1;
                        nodes[1].Y = endShape.Bottom + semiLength;
                        nodes[2].Y = endShape.Bottom + semiLength;
                        nodes[3].Y = endShape.Bottom;
                    }
                }
                else
                {
                    EntityShape bottomShape = (startShape.Top < endShape.Top) ?
                                              endShape : startShape;

                    nodes[0].Y = startShape.Bottom;
                    nodes[1].Y = bottomShape.Bottom + MarginSize;
                    nodes[2].Y = bottomShape.Bottom + MarginSize;
                    nodes[3].Y = endShape.Bottom;
                }
            }
            else               // Horizontal
            {
                nodes[0].Y = nodes[1].Y = StartNode.AbsoluteLocation;
                nodes[2].Y = nodes[3].Y = EndNode.AbsoluteLocation;

                if (endShape.Left - startShape.Right >= 2 * MarginSize ||
                    startShape.Left - endShape.Right >= 2 * MarginSize)
                {
                    if (startShape.Left < endShape.Left)
                    {
                        int semiLength = (endShape.Left - startShape.Right) / 2;

                        nodes[0].X = startShape.Right;
                        nodes[1].X = startShape.Right + semiLength;
                        nodes[2].X = startShape.Right + semiLength;
                        nodes[3].X = endShape.Left - 1;
                    }
                    else
                    {
                        int semiLength = (startShape.Left - endShape.Right) / 2;

                        nodes[0].X = startShape.Left - 1;
                        nodes[1].X = endShape.Right + semiLength;
                        nodes[2].X = endShape.Right + semiLength;
                        nodes[3].X = endShape.Right;
                    }
                }
                else
                {
                    EntityShape rightShape = (startShape.Left < endShape.Left) ?
                                             endShape : startShape;

                    nodes[0].X = startShape.Right;
                    nodes[1].X = rightShape.Right + MarginSize;
                    nodes[2].X = rightShape.Right + MarginSize;
                    nodes[3].X = endShape.Right;
                }
            }
        }