public void OnConnectionDragging(Point currentDragPoint, ConnectionViewModel connection) { // If current drag point is close to an input connector, show its snapped position. ConnectorViewModel nearbyConnector = null; if (connectingTo) { nearbyConnector = FindNearbyInputConnector(connection, currentDragPoint); } else { nearbyConnector = FindNearbyOutputConnector(connection, currentDragPoint); } Point pnt = (nearbyConnector != null) ? nearbyConnector.Position : currentDragPoint; if (connectingTo) { connection.ToPosition = pnt; } else { connection.FromPosition = pnt; } }
public ConnectionViewModel OnConnectionDragStarted(ConnectorViewModel sourceConnector, Point currentDragPoint) { if (sourceConnector is OutputConnectorViewModel) { connectingTo = true; var connection = new ConnectionViewModel((OutputConnectorViewModel)sourceConnector) { ToPosition = currentDragPoint }; Connections.Add(connection); return(connection); } else if (sourceConnector is InputConnectorViewModel) { connectingTo = false; var connection = new ConnectionViewModel((InputConnectorViewModel)sourceConnector) { FromPosition = currentDragPoint }; if (((InputConnectorViewModel)sourceConnector).Connection != null) { Connections.Remove(((InputConnectorViewModel)sourceConnector).Connection); } Connections.Add(connection); return(connection); } return(null); }
public void OnConnectionDragCompleted(Point currentDragPoint, ConnectionViewModel newConnection, ConnectorViewModel sourceConnector) { this.currentDragPoint = currentDragPoint; if (connectingTo) { InputConnectorViewModel nearbyConnector = FindNearbyInputConnector(newConnection, currentDragPoint); if (nearbyConnector == null) { RequestNodePickerWindow(newConnection); // pick return; } if (nearbyConnector == null || sourceConnector.Element == nearbyConnector.Element) { Connections.Remove(newConnection); return; } ConnectionViewModel existingConnection = nearbyConnector.Connection; if (existingConnection != null) { Connections.Remove(existingConnection); } newConnection.To = nearbyConnector; } else { OutputConnectorViewModel nearbyConnector = FindNearbyOutputConnector(newConnection, currentDragPoint); foreach (ConnectionViewModel con in Connections.Where(c => c.To == newConnection.To && c.From != null).ToList()) { Connections.Remove(con); } if (nearbyConnector == null) { RequestNodePickerWindow(newConnection); // pick return; } if (nearbyConnector == null || sourceConnector.Element == nearbyConnector.Element) { Connections.Remove(newConnection); return; } newConnection.From = nearbyConnector; } }
private OutputConnectorViewModel FindNearbyOutputConnector(ConnectionViewModel connection, Point mousePosition) { return(Elements.SelectMany(x => x.OutputConnectors).Where(x => x.IOType == (connection.To == null ? connection.From.IOType : connection.To.IOType)) .FirstOrDefault(x => AreClose(x.Position, mousePosition, 10))); }
internal void SetCurrentConnectionContext(ConnectionViewModel context) { contextConnection = context; SearchBox = ""; }