Esempio n. 1
0
        /// <summary>
        /// Handles index change by user. Those changes may need change in other indices.
        /// </summary>
        /// <param name="sender">element whose index was changed</param>
        /// <param name="e">EventArgs containing further information</param>
        private void UpdateIndexChangedEventHandler(object sender, UpdateIndexChangedEventArgs e)
        {
            if (m_IgnoreEvents)
            {
                return;
            }
            InputOutputElement senderio = sender as InputOutputElement;

            #region Old > New
            if (e.OldIndex > e.NewIndex)
            {
                //increase all indices between the new and the old value
                m_IgnoreEvents = true;
                foreach (BaseElement be in m_Elements)
                {
                    if (be is InputOutputElement)
                    {
                        InputOutputElement beio = be as InputOutputElement;
                        if (!beio.Equals(senderio) && beio.UpdateIndex >= e.NewIndex && beio.UpdateIndex < e.OldIndex)
                        {
                            beio.UpdateIndex++;
                        }
                    }
                }
                m_IgnoreEvents = false;
            }
            #endregion
            #region New > Old
            if (e.OldIndex < e.NewIndex)
            {
                //decrease all indices between the new and the old value
                m_IgnoreEvents = true;
                foreach (BaseElement be in m_Elements)
                {
                    if (be is InputOutputElement)
                    {
                        InputOutputElement beio = be as InputOutputElement;
                        if (!beio.Equals(senderio) && beio.UpdateIndex > e.OldIndex && beio.UpdateIndex <= e.NewIndex)
                        {
                            beio.UpdateIndex--;
                        }
                    }
                }
                m_IgnoreEvents = false;
            }
            #endregion
            SortElements();
        }
Esempio n. 2
0
        /// <summary>
        /// Find corresponding Terminal in reverse direction
        /// </summary>
        /// <param name="ioElement">IO to find Terminal for</param>
        /// <returns>Corresponsing Terminal or null if not found</returns>
        public Terminal FindTerminal(InputOutputElement ioElement)
        {
            InputOutputElement[] ioArray = new InputOutputElement[m_MatchingDict.Values.Count];
            m_MatchingDict.Values.CopyTo(ioArray, 0);
            Terminal[] termArray = new Terminal[m_MatchingDict.Keys.Count];
            m_MatchingDict.Keys.CopyTo(termArray, 0);

            if (m_MatchingDict.ContainsValue(ioElement))
            {
                for (int i = 0; i < m_MatchingDict.Values.Count; i++)
                {
                    if (ioElement.Equals(ioArray[i]))
                    {
                        return(termArray[i]);
                    }
                }
            }
            return(null);
        }