private void MoveExternalOutput(ExternalPortView port, Vector2 newLocation) { // get connected wires to the port var connectedWires = NavigationHelper.ConnectedWires(scheme, port).ToList(); // update location port.MatrixLocation = newLocation; // adjust connected wires location foreach (var w in connectedWires) { var c2 = w.Connection; c2.MatrixEnd = newLocation; c2.EndPoint = port.GetCenterRelativeTo(scheme); w.SetConnection(c2); } }
public HashSet <ISchemeComponent> MoveExternalInputs(HashSet <ISchemeComponent> processed) { this.Log("Running..."); // get external inputs of the scheme. var externalInputs = scheme.ExternalInputs; this.Log($"Got {externalInputs.Count()} external inputs."); var portsWithIndexes = new List <(ExternalPortView port, int destLoc, int portIdx)>(); foreach (var i in externalInputs) { var wires = NavigationHelper.ConnectedWires(scheme, i); var dests = wires.Select(x => NavigationHelper.GetDestination(scheme, x)); var minLocDest = dests.OrderBy(x => x.MatrixLocation.X).ThenBy(x => x.MatrixLocation.Y).First(); var minLoc = minLocDest.MatrixLocation; var minPortIndex = 0; if (minLocDest is GateView gate) { var connectingWires = wires.Where(w => gate.WireEndConnects(w)); minPortIndex = connectingWires.Min(x => x.Connection.EndPort.Value); } portsWithIndexes.Add((i, (int)minLoc.Y, minPortIndex)); } var portsToPlace = portsWithIndexes.OrderBy(x => x.destLoc).ThenBy(x => x.portIdx).Select(x => x.port); foreach (var port in portsToPlace) { var place = NavigationHelper.GetNotOccupiedLocationOnColumn(processed, 0); MoveExternalInput(port, place); processed.Add(port); } this.Log("Done"); return(processed); }