Exemple #1
0
        /// <summary>
        /// The current Option disconnects the target Option
        /// </summary>
        /// <param name="op">Option to be disconnected</param>
        /// <returns></returns>
        public virtual ConnectionStatus DisConnectOption(STNodeOption op)
        {
            if (!this.DisConnectingOption(op))
            {
                this.STNodeEidtorDisConnected(new STNodeEditorOptionEventArgs(op, this, ConnectionStatus.Reject));
                return(ConnectionStatus.Reject);
            }

            if (op.Owner == null)
            {
                return(ConnectionStatus.NoOwner);
            }
            if (this._Owner == null)
            {
                return(ConnectionStatus.NoOwner);
            }
            if (op.Owner.LockOption && this._Owner.LockOption)
            {
                this.STNodeEidtorDisConnected(new STNodeEditorOptionEventArgs(op, this, ConnectionStatus.Locked));
                return(ConnectionStatus.Locked);
            }
            op.RemoveConnection(this, false);
            this.RemoveConnection(op, true);
            this.ControlBuildLinePath();

            this.STNodeEidtorDisConnected(new STNodeEditorOptionEventArgs(op, this, ConnectionStatus.DisConnected));
            return(ConnectionStatus.DisConnected);
        }
Exemple #2
0
        /// <summary>
        /// The current Option is connected to the target Option
        /// </summary>
        /// <param name="op">Option to connect</param>
        /// <returns>Connection result</returns>
        public virtual ConnectionStatus ConnectOption(STNodeOption op)
        {
            if (!this.ConnectingOption(op))
            {
                this.STNodeEidtorConnected(new STNodeEditorOptionEventArgs(op, this, ConnectionStatus.Reject));
                return(ConnectionStatus.Reject);
            }

            var v = this.CanConnect(op);

            if (v != ConnectionStatus.Connected)
            {
                this.STNodeEidtorConnected(new STNodeEditorOptionEventArgs(op, this, v));
                return(v);
            }
            v = op.CanConnect(this);
            if (v != ConnectionStatus.Connected)
            {
                this.STNodeEidtorConnected(new STNodeEditorOptionEventArgs(op, this, v));
                return(v);
            }
            op.AddConnection(this, false);
            this.AddConnection(op, true);
            this.ControlBuildLinePath();

            this.STNodeEidtorConnected(new STNodeEditorOptionEventArgs(op, this, v));
            return(v);
        }
Exemple #3
0
        void input_Connected(object sender, STNodeOptionEventArgs e)
        {
            STNodeOption op     = sender as STNodeOption;
            int          nIndex = this.InputOptions.IndexOf(op);
            var          t      = typeof(object);

            if (op.DataType == t)
            {
                op.DataType = e.TargetOption.DataType;
                this.OutputOptions[nIndex].DataType = op.DataType;
                foreach (STNodeOption v in this.InputOptions)
                {
                    if (v.DataType == t)
                    {
                        return;
                    }
                }
                this.Addhub();
            }
            else
            {
                //this.OutputOptions[nIndex].Data = e.TargetOption.Data;
                this.OutputOptions[nIndex].TransferData(e.TargetOption.Data);
            }
        }
Exemple #4
0
            public override ConnectionStatus CanConnect(STNodeOption op)
            {
                if (op == STNodeOption.Empty)
                {
                    return(ConnectionStatus.EmptyOption);
                }
                if (this.DataType != typeof(object))
                {
                    return(base.CanConnect(op));
                }
                if (this.IsInput == op.IsInput)
                {
                    return(ConnectionStatus.SameInputOrOutput);
                }
                if (op.Owner == null || this.Owner == null)
                {
                    return(ConnectionStatus.NoOwner);
                }
                if (op.Owner == this.Owner)
                {
                    return(ConnectionStatus.SameOwner);
                }
                if (this.Owner.LockOption || op.Owner.LockOption)
                {
                    return(ConnectionStatus.Locked);
                }
                if (this.IsSingle && m_hs_connected.Count == 1)
                {
                    return(ConnectionStatus.SingleOption);
                }
                if (op.IsInput && STNodeEditor.CanFindNodePath(op.Owner, this.Owner))
                {
                    return(ConnectionStatus.Loop);
                }
                if (m_hs_connected.Contains(op))
                {
                    return(ConnectionStatus.Exists);
                }
                if (op.DataType == typeof(object))
                {
                    return(ConnectionStatus.ErrorType);
                }

                if (!this.IsInput)
                {
                    return(ConnectionStatus.Connected);
                }
                foreach (STNodeOption owner_input in this.Owner.InputOptions)
                {
                    foreach (STNodeOption o in owner_input.ConnectedOption)
                    {
                        if (o == op)
                        {
                            return(ConnectionStatus.Exists);
                        }
                    }
                }
                return(ConnectionStatus.Connected);;
            }
Exemple #5
0
 public STNodeOption[] ToArray()
 {
     STNodeOption[] ops = new STNodeOption[this._Count];
     for (int i = 0; i < ops.Length; i++)
     {
         ops[i] = m_options[i];
     }
     return(ops);
 }
Exemple #6
0
 /// <summary>
 /// Check if there is enough space to expand the capacity
 /// </summary>
 /// <param name="elements">Number of elements to be added</param>
 private void EnsureSpace(int elements)
 {
     if (elements + this._Count > m_options.Length)
     {
         STNodeOption[] arrTemp = new STNodeOption[Math.Max(m_options.Length * 2, elements + this._Count)];
         m_options.CopyTo(arrTemp, 0);
         m_options = arrTemp;
     }
 }
Exemple #7
0
        public void Remove(STNodeOption option)
        {
            int nIndex = this.IndexOf(option);

            if (nIndex != -1)
            {
                this.RemoveAt(nIndex);
            }
        }
Exemple #8
0
        void input_DataTransfer(object sender, STNodeOptionEventArgs e)
        {
            STNodeOption op     = sender as STNodeOption;
            int          nIndex = this.InputOptions.IndexOf(op);

            if (e.Status != ConnectionStatus.Connected)
            {
                this.OutputOptions[nIndex].Data = null;
            }
            else
            {
                this.OutputOptions[nIndex].Data = e.TargetOption.Data;
            }
            this.OutputOptions[nIndex].TransferData();
        }
Exemple #9
0
        private bool AddConnection(STNodeOption op, bool bSponsor)
        {
            if (this._DataType == null)
            {
                return(false);
            }
            bool b = m_hs_connected.Add(op);

            this.OnConnected(new STNodeOptionEventArgs(bSponsor, op, ConnectionStatus.Connected));
            if (this._IsInput)
            {
                this.OnDataTransfer(new STNodeOptionEventArgs(bSponsor, op, ConnectionStatus.Connected));
            }
            return(b);
        }
Exemple #10
0
            public override ConnectionStatus ConnectOption(STNodeOption op)
            {
                var t = typeof(object);

                if (this.DataType != t)
                {
                    return(base.ConnectOption(op));
                }
                this.DataType = op.DataType;
                var ret = base.ConnectOption(op);

                if (ret != ConnectionStatus.Connected)
                {
                    this.DataType = t;
                }
                return(ret);
            }
Exemple #11
0
        /// <summary>
        /// The current Option starts to disconnect the target Option
        /// </summary>
        /// <param name="op">Option to be disconnected</param>
        /// <returns>Are you allowed to continue the operation?</returns>
        protected virtual bool DisConnectingOption(STNodeOption op)
        {
            if (this._Owner == null)
            {
                return(false);
            }
            if (this._Owner.Owner == null)
            {
                return(false);
            }
            STNodeEditorOptionEventArgs e = new STNodeEditorOptionEventArgs(op, this, ConnectionStatus.DisConnecting);

            this._Owner.Owner.OnOptionDisConnecting(e);
            this.OnDisConnecting(new STNodeOptionEventArgs(true, op, ConnectionStatus.DisConnecting));
            op.OnDisConnecting(new STNodeOptionEventArgs(false, this, ConnectionStatus.DisConnecting));
            return(e.Continue);
        }
Exemple #12
0
        public int Add(STNodeOption option)
        {
            if (option == null)
            {
                throw new ArgumentNullException("Add object cannot be null");
            }
            this.EnsureSpace(1);
            int nIndex = option == STNodeOption.Empty ? -1 : this.IndexOf(option);

            if (-1 == nIndex)
            {
                nIndex                   = this._Count;
                option.Owner             = m_owner;
                option.IsInput           = m_isInput;
                m_options[this._Count++] = option;
                this.Invalidate();
            }
            return(nIndex);
        }
Exemple #13
0
        private bool RemoveConnection(STNodeOption op, bool bSponsor)
        {
            if (this._DataType == null)
            {
                return(false);
            }
            bool b = false;

            if (m_hs_connected.Contains(op))
            {
                b = m_hs_connected.Remove(op);
                if (this._IsInput)
                {
                    this.OnDataTransfer(new STNodeOptionEventArgs(bSponsor, op, ConnectionStatus.DisConnected));
                }
                this.OnDisConnected(new STNodeOptionEventArgs(bSponsor, op, ConnectionStatus.Connected));
            }
            return(b);
        }
Exemple #14
0
 public void Insert(int index, STNodeOption option)
 {
     if (index < 0 || index >= this._Count)
     {
         throw new IndexOutOfRangeException("Index out of bounds");
     }
     if (option == null)
     {
         throw new ArgumentNullException("Insert object cannot be null");
     }
     this.EnsureSpace(1);
     for (int i = this._Count; i > index; i--)
     {
         m_options[i] = m_options[i - 1];
     }
     option.Owner     = m_owner;
     m_options[index] = option;
     this._Count++;
     this.Invalidate();
 }
Exemple #15
0
 /// <summary>
 /// Check whether the current Option can connect to the target Option
 /// </summary>
 /// <param name="op">Option to connect</param>
 /// <returns>Test results</returns>
 public virtual ConnectionStatus CanConnect(STNodeOption op)
 {
     if (this == STNodeOption.Empty || op == STNodeOption.Empty)
     {
         return(ConnectionStatus.EmptyOption);
     }
     if (this._IsInput == op.IsInput)
     {
         return(ConnectionStatus.SameInputOrOutput);
     }
     if (op.Owner == null || this._Owner == null)
     {
         return(ConnectionStatus.NoOwner);
     }
     if (op.Owner == this._Owner)
     {
         return(ConnectionStatus.SameOwner);
     }
     if (this._Owner.LockOption || op._Owner.LockOption)
     {
         return(ConnectionStatus.Locked);
     }
     if (this._IsSingle && m_hs_connected.Count == 1)
     {
         return(ConnectionStatus.SingleOption);
     }
     if (op.IsInput && STNodeEditor.CanFindNodePath(op.Owner, this._Owner))
     {
         return(ConnectionStatus.Loop);
     }
     if (m_hs_connected.Contains(op))
     {
         return(ConnectionStatus.Exists);
     }
     if (this._IsInput && op._DataType != this._DataType && !op._DataType.IsSubclassOf(this._DataType))
     {
         return(ConnectionStatus.ErrorType);
     }
     return(ConnectionStatus.Connected);
 }
Exemple #16
0
        void output_DisConnected(object sender, STNodeOptionEventArgs e)
        {
            STNodeOption op = sender as STNodeOption;

            if (op.ConnectionCount != 0)
            {
                return;
            }
            int nIndex = this.OutputOptions.IndexOf(op);

            if (this.InputOptions[nIndex].ConnectionCount != 0)
            {
                return;
            }
            this.InputOptions.RemoveAt(nIndex);
            this.OutputOptions.RemoveAt(nIndex);
            if (this.Owner != null)
            {
                this.Owner.BuildLinePath();
            }
            this.Height -= 20;
        }
Exemple #17
0
 public bool Contains(STNodeOption option)
 {
     return(this.IndexOf(option) != -1);
 }
 public STNodeOptionEventArgs(bool isSponsor, STNodeOption opTarget, ConnectionStatus cr)
 {
     this._IsSponsor    = isSponsor;
     this._TargetOption = opTarget;
     this._Status       = cr;
 }
 public STNodeEditorOptionEventArgs(STNodeOption opTarget, STNodeOption opCurrent, ConnectionStatus cr)
     : base(false, opTarget, cr)
 {
     this._CurrentOption = opCurrent;
 }
Exemple #20
0
 public int IndexOf(STNodeOption option)
 {
     return(Array.IndexOf <STNodeOption>(m_options, option));
 }