示例#1
0
        /// <summary>
        /// Get contact points defined for given item
        /// <remarks>Note that because of simple getting contact points we store them as first four</remarks>.
        /// </summary>
        /// <param name="item">Item which points are generated.</param>
        /// <returns>Generated points.</returns>
        private IEnumerable <GraphPoint> generatePoints(DiagramItem item)
        {
            var span     = SceneNavigator.GetSpan(item, item.GlobalPosition);
            var topLeft  = new GraphPoint(span.TopLeft, TopLeftCorner, item);
            var topRight = new GraphPoint(span.TopRight, TopRightCorner, item);

            var bottomLeft  = new GraphPoint(span.BottomLeft, BottomLeftCorner, item);
            var bottomRight = new GraphPoint(span.BottomRight, BottomRightCorner, item);

            topLeft.SetEdgeStatus(topRight);
            topLeft.SetEdgeStatus(bottomLeft);

            bottomRight.SetEdgeStatus(topRight);
            bottomRight.SetEdgeStatus(bottomLeft);

            var points = new List <GraphPoint>();

            points.Add(topLeft);
            points.Add(topRight);
            points.Add(bottomLeft);
            points.Add(bottomRight);

            generateConnectorPoints(item.TopConnectorDrawings, ConnectorAlign.Top, item, points);
            generateConnectorPoints(item.LeftConnectorDrawings, ConnectorAlign.Left, item, points);
            generateConnectorPoints(item.BottomConnectorDrawings, ConnectorAlign.Bottom, item, points);
            generateConnectorPoints(item.RightConnectorDrawings, ConnectorAlign.Right, item, points);

            return(points);
        }
示例#2
0
        /// <summary>
        /// Try to add edge between given points if possible.
        /// </summary>
        /// <param name="fromCandidate">Point where edge should start.</param>
        /// <param name="toCandidate">Point where edge should end.</param>
        /// <param name="target">Target that is not considered to be an obstacle.</param>
        /// <param name="obstacle">Obstacle if any is present between from and to candidate, <c>null</c> otherwise.</param>
        /// <returns><c>true</c> if edge can be added, <c>false</c> otherwise.</returns>
        private bool tryAddEdge(GraphPoint fromCandidate, GraphPoint toCandidate, DiagramItem target, out DiagramItem obstacle)
        {
            obstacle = null;
            if (
                !fromCandidate.IsInAngle(toCandidate) ||
                !toCandidate.IsInAngle(fromCandidate)
                )
            {
                //edge is not possible between given points
                return(false);
            }

            if (fromCandidate.HasEdgeStatus(toCandidate))
            {
                //edge already exists or has been forbidden earlier
                return(false);
            }

            obstacle = _navigator.GetFirstObstacle(fromCandidate.Position, toCandidate.Position);
            var isEdgeValid = obstacle == null || obstacle == target;

            fromCandidate.SetEdgeStatus(toCandidate, isEdgeValid);

            return(isEdgeValid);
        }
示例#3
0
        /// <summary>
        /// Gets the input slots.
        /// </summary>
        /// <param name="connectorIndex">Index of the connector.</param>
        /// <param name="connectorsCount">The connectors count.</param>
        /// <param name="connector">The connector.</param>
        /// <param name="item">The item.</param>
        /// <param name="contactPoints">The contact points.</param>
        /// <returns>GraphPoint[].</returns>
        /// <exception cref="System.NotSupportedException">Connector align  + connectorAlign</exception>
        private GraphPoint[] getInputSlots(int connectorIndex, int connectorsCount, ConnectorDrawing connector, DiagramItem item, List <GraphPoint> contactPoints)
        {
            var connectorAlign = connector.Align;

            var span = _navigator.GetSpan(item);

            //find positions of slots for inputs according to connector align
            Point slot1End, slot1Start;
            Point slot2End;

            ViewAngle slot1View;
            ViewAngle slot2View;

            GraphPoint slot1Contact;
            GraphPoint slot2Contact;

            //slots has to be parallel with same length
            switch (connectorAlign)
            {
            case ConnectorAlign.Top:
                slot1Contact = contactPoints[2];
                slot2Contact = contactPoints[3];
                slot1View    = TopLeftCorner;
                slot2View    = TopRightCorner;
                slot1End     = span.TopLeft;
                slot2End     = span.TopRight;
                slot1Start   = new Point(slot1End.X, slot1End.Y + item.TopConnectors.DesiredSize.Height);
                break;

            case ConnectorAlign.Bottom:
                slot1Contact = contactPoints[0];
                slot2Contact = contactPoints[1];
                slot1View    = BottomLeftCorner;
                slot2View    = BottomRightCorner;
                slot1End     = span.BottomLeft;
                slot2End     = span.BottomRight;
                slot1Start   = new Point(slot1End.X, slot1End.Y - item.BottomConnectors.DesiredSize.Height);
                break;

            case ConnectorAlign.Left:
                slot1Contact = contactPoints[1];
                slot2Contact = contactPoints[3];
                slot1View    = TopLeftCorner;
                slot2View    = BottomLeftCorner;
                slot1End     = span.TopLeft;
                slot2End     = span.BottomLeft;
                slot1Start   = new Point(slot1End.X + item.LeftConnectors.DesiredSize.Width, slot1End.Y);
                break;

            case ConnectorAlign.Right:
                slot1Contact = contactPoints[0];
                slot2Contact = contactPoints[2];
                slot1View    = TopRightCorner;
                slot2View    = BottomRightCorner;
                slot1End     = span.TopRight;
                slot2End     = span.BottomRight;
                slot1Start   = new Point(slot1End.X - item.RightConnectors.DesiredSize.Width, slot1End.Y);
                break;

            default:
                throw new NotSupportedException("Connector align " + connectorAlign);
            }

            var slotVector = (slot1Start - slot1End) / (connectorsCount + 2);

            var slot1 = new GraphPoint(slot1End + slotVector * connectorIndex, slot1View, item);
            var slot2 = new GraphPoint(slot2End + slotVector * (connectorsCount - connectorIndex), slot2View, item);

            slot1.SetEdgeStatus(slot1Contact);
            slot2.SetEdgeStatus(slot2Contact);

            return(new[] { slot1, slot2 });
        }