public NodeConnection Connect(NodeConnector from, NodeConnector to, string name) { if (from != null) { foreach (var other in from.Node.Connections) { if (other.From == from && other.To == to) { return(null); } } } if (to != null) { foreach (var other in to.Node.Connections) { if (other.From == from && other.To == to) { return(null); } } } var connection = new NodeConnection(); connection.From = from; connection.To = to; connection.Name = name; if (from != null) { from.Node.AddConnection(connection); } if (to != null) { to.Node.AddConnection(connection); } if (ConnectionAdded != null) { var eventArgs = new AcceptNodeConnectionEventArgs(connection); ConnectionAdded(this, eventArgs); if (eventArgs.Cancel) { Disconnect(connection); return(null); } } UpdateRevisionIndex(); if (InvalidateViews != null) { InvalidateViews(this, EventArgs.Empty); } return(connection); }
public bool ConnectionIsAllowed(NodeConnector from, NodeConnector to) { if (null != CompatibilityStrategy) { if (CompatibilityStrategy.CanConnect(from, to) == ConnectionType.Incompatible) { return(false); } } // If someone has subscribed to the ConnectionAdding event, // give them a chance to interrupt this connection attempt. if (null != ConnectionAdding) { // Populate a temporary NodeConnection instance. var connection = new NodeConnection(); connection.From = from; connection.To = to; // Fire the event and see if someone cancels it. var eventArgs = new AcceptNodeConnectionEventArgs(connection); ConnectionAdding(this, eventArgs); if (eventArgs.Cancel) { return(false); } } return(true); }
public bool Disconnect(NodeConnection connection) { if (connection == null) { return(false); } if (ConnectionRemoving != null) { var eventArgs = new AcceptNodeConnectionEventArgs(connection); ConnectionRemoving(this, eventArgs); if (eventArgs.Cancel) { return(false); } } // if (HasFocus(connection)) // FocusElement = null; var from = connection.From; var to = connection.To; if (from != null && from.Node != null) { from.Node.RemoveConnection(connection); } if (to != null && to.Node != null) { to.Node.RemoveConnection(connection); } // Just in case somebody stored it somewhere .. connection.From = null; connection.To = null; if (ConnectionRemoved != null) { ConnectionRemoved(this, new NodeConnectionEventArgs(from, to, connection)); } UpdateRevisionIndex(); if (InvalidateViews != null) { InvalidateViews(this, EventArgs.Empty); } return(true); }
void OnConnectionRemoved(object sender, AcceptNodeConnectionEventArgs e) { ShaderFragmentNodeUtil.InvalidateShaderStructure(graphControl); }
void OnConnectionAdding(object sender, AcceptNodeConnectionEventArgs e) { }
void OnConnectionAdded(object sender, AcceptNodeConnectionEventArgs e) { e.Connection.Name = "Connection " + counter ++; ShaderFragmentNodeUtil.InvalidateShaderStructure(graphControl); }
public bool Disconnect(NodeConnection connection) { if (connection == null) return false; if (ConnectionRemoving != null) { var eventArgs = new AcceptNodeConnectionEventArgs(connection); ConnectionRemoving(this, eventArgs); if (eventArgs.Cancel) return false; } if (HasFocus(connection)) FocusElement = null; var from = connection.From; var to = connection.To; if (from != null && from.Node != null) { from.Node.connections.Remove(connection); } if (to != null && to.Node != null) { to.Node.connections.Remove(connection); } // Just in case somebody stored it somewhere .. connection.From = null; connection.To = null; if (ConnectionRemoved != null) ConnectionRemoved(this, new NodeConnectionEventArgs(from, to, connection)); this.Invalidate(); return true; }
public NodeConnection Connect(NodeConnector from, NodeConnector to) { if (from == null || to == null || from.Node == null || to.Node == null || !from.Enabled || !to.Enabled) return null; foreach (var other in from.Node.connections) { if (other.From == from && other.To == to) return null; } foreach (var other in to.Node.connections) { if (other.From == from && other.To == to) return null; } var connection = new NodeConnection(); connection.From = from; connection.To = to; from.Node.connections.Add(connection); to.Node.connections.Add(connection); if (ConnectionAdded != null) { var eventArgs = new AcceptNodeConnectionEventArgs(connection); ConnectionAdded(this, eventArgs); if (eventArgs.Cancel) { Disconnect(connection); return null; } } return connection; }
/// <summary> /// Checks whether the connection between two connectors is allowed. /// This is achieved through event propagation. /// </summary> /// <returns></returns> private bool ConnectionIsAllowed(NodeConnector from, NodeConnector to) { if (HighlightCompatible && null != CompatibilityStrategy) { if (CompatibilityStrategy.CanConnect(from, to) == ConnectionType.Incompatible) return false; } // If someone has subscribed to the ConnectionAdding event, // give them a chance to interrupt this connection attempt. if (null != ConnectionAdding) { // Populate a temporary NodeConnection instance. var connection = new NodeConnection(); connection.From = from; connection.To = to; // Fire the event and see if someone cancels it. var eventArgs = new AcceptNodeConnectionEventArgs(connection); ConnectionAdding(this, eventArgs); if (eventArgs.Cancel) return false; } return true; }
public NodeConnection Connect(NodeConnector from, NodeConnector to, string name) { if (from != null) { foreach (var other in from.Node.Connections) { if (other.From == from && other.To == to) return null; } } if (to != null) { foreach (var other in to.Node.Connections) { if (other.From == from && other.To == to) return null; } } var connection = new NodeConnection(); connection.From = from; connection.To = to; connection.Name = name; if (from != null) from.Node.AddConnection(connection); if (to != null) to.Node.AddConnection(connection); if (ConnectionAdded != null) { var eventArgs = new AcceptNodeConnectionEventArgs(connection); ConnectionAdded(this, eventArgs); if (eventArgs.Cancel) { Disconnect(connection); return null; } } UpdateRevisionIndex(); if (InvalidateViews != null) InvalidateViews(this, EventArgs.Empty); return connection; }