/// <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); }
/// <summary> /// Compute possibilities of movedItem to move without overlapping any other item /// </summary> /// <param name="movedItem">Item which possibilities are created</param> /// <returns>Computed possibilities</returns> private ItemMoveability computePossibilities(DiagramItem movedItem) { if (movedItem.IsRootItem) { return(new ItemMoveability(double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity)); } var container = movedItem.ContainingDiagramCanvas; //we have to check possibilities relative to parent! //so using relative position is necessary var currentPosition = getPosition(movedItem); var currentLocalPosition = movedItem.AsLocalPosition(currentPosition); var span = SceneNavigator.GetSpan(movedItem, currentLocalPosition); var contMargin = container.Margin; var upPossib = span.Top; var downPossib = container.DesiredSize.Height - span.Bottom - contMargin.Bottom - contMargin.Top; var rightPossib = container.DesiredSize.Width - span.Right - contMargin.Right - contMargin.Left; var leftPossib = span.Left; return(new ItemMoveability( upPossib, downPossib, leftPossib, rightPossib )); }
/// <summary> /// Compute needs of movedItem to not to overlap currItem /// </summary> /// <param name="movedItem">Item that will be moved</param> /// <param name="currItem">Item that is tested to be not overlapped</param> /// <returns>Computed needs</returns> private ItemMoveability computeNeeds(DiagramItem movedItem, DiagramItem currItem) { var movedSpan = _navigator.GetSpan(movedItem); var currSpan = _navigator.GetSpan(currItem); var intersection = Rect.Intersect(movedSpan, currSpan); var debug = intersection.IsEmpty; var upNeed = currSpan.Top - movedSpan.Bottom; var downNeed = movedSpan.Top - currSpan.Bottom; var rightNeed = movedSpan.Left - currSpan.Right; var leftNeed = currSpan.Left - movedSpan.Right; var epsilon = 1; upNeed = Math.Abs(upNeed) + epsilon; downNeed = Math.Abs(downNeed) + epsilon; rightNeed = Math.Abs(rightNeed) + epsilon; leftNeed = Math.Abs(leftNeed) + epsilon; return(new ItemMoveability(upNeed, downNeed, leftNeed, rightNeed)); }
/// <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 }); }
private Rect getLocalSpan(DiagramItem item) { return(SceneNavigator.GetSpan(item, item.LocalPosition)); }