private void StoreConnections(TNode node, bool register) { if (!register) { if (m_connectionDeregisterActions.ContainsKey(node)) { foreach (var deregister in m_connectionDeregisterActions[node]) { deregister(); } } return; } foreach (var connector in node.Data.Connectors) { var connectorTemp = connector; Action <Output, bool> connected = (connection, mustExist) => { ConnectionUpdate(connection, connectorTemp, mustExist); }; connectorTemp.Connected += c => connected(c, true); connectorTemp.Disconnected += connection => { DisconnectionUpdate(connection, connectorTemp, UIInfo(connection).Area.Value); }; foreach (var connection in connectorTemp.Connections) { connected(connection, false); } Action deregister = UIInfo(connectorTemp).Area.Changed.Register(change => { foreach (var connection in connectorTemp.Connections) { var other = UIInfo(connection); //The nature of the bezier splines means they will never reach outside the bounding rectangle which includes their endpoints RectangleF fromBounds = RectangleF.Union(change.From, other.Area.Value); var pair = UnorderedTuple.Make(connectorTemp, connection); SpatiallyOrderedConnections.Remove(Tuple.Create(pair, fromBounds)); RectangleF toBounds = RectangleF.Union(change.To, other.Area.Value); SpatiallyOrderedConnections.Add(Tuple.Create(pair, toBounds), toBounds); } }); if (!m_connectionDeregisterActions.ContainsKey(node)) { m_connectionDeregisterActions[node] = new List <Action>(); } m_connectionDeregisterActions[node].Add(deregister); } }
private void ConnectionUpdate(Output connection, Output connectorTemp, bool mustExist) { var ui1 = UIInfo(connectorTemp, false); var ui2 = UIInfo(connection, !mustExist); if (ui2 != null) { //The nature of the bezier splines means they will never reach outside the bounding rectangle which includes their endpoints RectangleF bounds = RectangleF.Union(ui1.Area.Value, ui2.Area.Value); var pair = UnorderedTuple.Make(connectorTemp, connection); bool exists = SpatiallyOrderedConnections.FindTouchingRegion(bounds).Contains(Tuple.Create(pair, bounds)); if (!exists) { SpatiallyOrderedConnections.Add(Tuple.Create(pair, bounds), bounds); } else { } } }