コード例 #1
0
        private ModelSystemDisplayStructure GetParent(ModelSystemDisplayStructure current, ModelSystemDisplayStructure lookingFor)
        {
            var children = current.Children;

            if (children == null)
            {
                return(null);
            }
            for (int i = 0; i < children.Length; i++)
            {
                if (children[i] == lookingFor)
                {
                    return(current);
                }
            }
            for (int i = 0; i < children.Length; i++)
            {
                var res = GetParent(children[i], lookingFor);
                if (res != null)
                {
                    return(res);
                }
            }
            return(null);
        }
コード例 #2
0
        private static ModelSystemDisplayStructure FindElement(ModelSystemDisplayStructure root, IModelSystemStructure toFind)
        {
            var stack = new Stack <ModelSystemDisplayStructure>();

            stack.Push(root);
            while (stack.Count > 0)
            {
                var current = stack.Pop();
                // if this is the right one, success
                if (current.Structure == toFind)
                {
                    return(current);
                }
                var children = current.Children;
                if (children != null)
                {
                    // if not, add our children to the stack and continue on
                    for (int i = 0; i < children.Length; i++)
                    {
                        stack.Push(children[i]);
                    }
                }
            }
            return(null);
        }
コード例 #3
0
        internal int IndexOf(ModelSystemDisplayStructure modelSystemStructure)
        {
            var children = this._Children;

            if (children == null)
            {
                return(-1);
            }
            for (int i = 0; i < children.Length; i++)
            {
                if (children[i] == modelSystemStructure)
                {
                    return(i);
                }
            }
            return(-1);
        }
コード例 #4
0
 private bool BuildChildren()
 {
     var anyChanges = false;
     var children = this.Structure.Children;
     if ( children != null )
     {
         var oldChildren = this._Children;
         if ( oldChildren == null || oldChildren.Length != children.Count )
         {
             var newChildren = new ModelSystemDisplayStructure[children.Count];
             if ( oldChildren == null )
             {
                 for ( int i = 0; i < newChildren.Length; i++ )
                 {
                     newChildren[i] = new ModelSystemDisplayStructure( children[i] );
                 }
                 anyChanges = true;
             }
             else
             {
                 int index;
                 for ( int i = 0; i < children.Count; i++ )
                 {
                     var child = children[i];
                     if ( ( index = IndexOf( oldChildren, children[i] ) ) >= 0 )
                     {
                         newChildren[i] = oldChildren[index];
                         if ( index != i )
                         {
                             anyChanges = true;
                         }
                     }
                     else
                     {
                         newChildren[i] = new ModelSystemDisplayStructure( children[i] );
                         anyChanges = true;
                     }
                 }
             }
             this._Children = newChildren;
         }
         else
         {
             int index;
             for ( int i = 0; i < children.Count; i++ )
             {
                 var child = children[i];
                 index = IndexOf( oldChildren, children[i] );
                 if ( index != i )
                 {
                     anyChanges = true;
                     break;
                 }
             }
             if ( anyChanges )
             {
                 var newChildren = new ModelSystemDisplayStructure[children.Count];
                 for ( int i = 0; i < children.Count; i++ )
                 {
                     var child = children[i];
                     if ( ( index = IndexOf( oldChildren, children[i] ) ) >= 0 )
                     {
                         newChildren[i] = oldChildren[index];
                         if ( index != i )
                         {
                             anyChanges = true;
                         }
                     }
                     else
                     {
                         newChildren[i] = new ModelSystemDisplayStructure( children[i] );
                         anyChanges = true;
                     }
                 }
                 this._Children = newChildren;
             }
         }
     }
     return anyChanges;
 }
コード例 #5
0
 internal int IndexOf(ModelSystemDisplayStructure modelSystemStructure)
 {
     var children = this._Children;
     if ( children == null )
     {
         return -1;
     }
     for ( int i = 0; i < children.Length; i++ )
     {
         if ( children[i] == modelSystemStructure )
         {
             return i;
         }
     }
     return -1;
 }
コード例 #6
0
 internal int IndexOf(ModelSystemDisplayStructure[] oldChildren, IModelSystemStructure modelSystemStructure)
 {
     for ( int i = 0; i < oldChildren.Length; i++ )
     {
         if ( oldChildren[i].Structure == modelSystemStructure )
         {
             return i;
         }
     }
     return -1;
 }
コード例 #7
0
        private bool BuildChildren()
        {
            var anyChanges = false;
            var children   = this.Structure.Children;

            if (children != null)
            {
                var oldChildren = this._Children;
                if (oldChildren == null || oldChildren.Length != children.Count)
                {
                    var newChildren = new ModelSystemDisplayStructure[children.Count];
                    if (oldChildren == null)
                    {
                        for (int i = 0; i < newChildren.Length; i++)
                        {
                            newChildren[i] = new ModelSystemDisplayStructure(children[i]);
                        }
                        anyChanges = true;
                    }
                    else
                    {
                        int index;
                        for (int i = 0; i < children.Count; i++)
                        {
                            var child = children[i];
                            if ((index = IndexOf(oldChildren, children[i])) >= 0)
                            {
                                newChildren[i] = oldChildren[index];
                                if (index != i)
                                {
                                    anyChanges = true;
                                }
                            }
                            else
                            {
                                newChildren[i] = new ModelSystemDisplayStructure(children[i]);
                                anyChanges     = true;
                            }
                        }
                    }
                    this._Children = newChildren;
                }
                else
                {
                    int index;
                    for (int i = 0; i < children.Count; i++)
                    {
                        var child = children[i];
                        index = IndexOf(oldChildren, children[i]);
                        if (index != i)
                        {
                            anyChanges = true;
                            break;
                        }
                    }
                    if (anyChanges)
                    {
                        var newChildren = new ModelSystemDisplayStructure[children.Count];
                        for (int i = 0; i < children.Count; i++)
                        {
                            var child = children[i];
                            if ((index = IndexOf(oldChildren, children[i])) >= 0)
                            {
                                newChildren[i] = oldChildren[index];
                                if (index != i)
                                {
                                    anyChanges = true;
                                }
                            }
                            else
                            {
                                newChildren[i] = new ModelSystemDisplayStructure(children[i]);
                                anyChanges     = true;
                            }
                        }
                        this._Children = newChildren;
                    }
                }
            }
            return(anyChanges);
        }