예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
파일: ExampleForm.cs 프로젝트: ldh9451/XLE
 void OnConnectionRemoved(object sender, AcceptNodeConnectionEventArgs e)
 {
     ShaderFragmentNodeUtil.InvalidateShaderStructure(graphControl);
 }
예제 #5
0
파일: ExampleForm.cs 프로젝트: ldh9451/XLE
 void OnConnectionAdding(object sender, AcceptNodeConnectionEventArgs e)
 {
 }
예제 #6
0
파일: ExampleForm.cs 프로젝트: ldh9451/XLE
 void OnConnectionAdded(object sender, AcceptNodeConnectionEventArgs e)
 {
     e.Connection.Name = "Connection " + counter ++;
     ShaderFragmentNodeUtil.InvalidateShaderStructure(graphControl);
 }
예제 #7
0
파일: GraphControl.cs 프로젝트: ldh9451/XLE
        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;
        }
예제 #8
0
파일: GraphControl.cs 프로젝트: ldh9451/XLE
        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;
        }
예제 #9
0
파일: GraphControl.cs 프로젝트: ldh9451/XLE
        /// <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;
        }
예제 #10
0
파일: GraphModel.cs 프로젝트: coreafive/XLE
        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;
        }