public void AddConnection(Field a, Field b, Connection.Creator createdBy) { //Find out which is the input field and which is the output field Field input, output; if (InputFields.Contains(a) && OutputFields.Contains(b)) { input = a; output = b; } else if (InputFields.Contains(b) && OutputFields.Contains(a)) { input = b; output = a; } else { //Only connect inputs with outputs return; } // Remove any existing connections to a newly connected output. // There should never be more than one input connected to any given output var conflictingConnections = Connections.Where(conn => conn.Output == output).ToList(); foreach (var conn in conflictingConnections) { RemoveConnection(conn); } SelectionStatus selectionStatus; if (Selection.Contains(input) || Selection.Contains(output)) { selectionStatus = SelectionStatus.ConnectionSelected; } else { selectionStatus = SelectionStatus.NotSelected; } Connections.Add(new Connection(input, output, createdBy, selectionStatus)); input.IsConnected = true; output.IsConnected = true; }
public bool IsConnectable(Field a, Field b) { return(a != null && b != null && ((InputFields.Contains(a) && OutputFields.Contains(b)) || (InputFields.Contains(b) && OutputFields.Contains(a)))); }