Example #1
0
 private void SetParentTree(SortedTree <T> tree)
 {
     foreach (SortedTreeNode node in m_Roots)
     {
         node.SetParentTree(tree);
     }
     RaiseTreeHasChangedEvent();
 }
Example #2
0
 internal void SetParentTree(SortedTree <T> tree)
 {
     foreach (KeyValuePair <int, SortedTreeNode> kvp_childnode in mChildNodes)
     {
         kvp_childnode.Value.SetParentTree(tree);
     }
     MyParentTree = tree;
 }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SortedTree&lt;T&gt;.SortedTreeNode"/> class.
 /// </summary>
 /// <param name="ParentElementValue">The parent element value.</param>
 /// <param name="ParentTree">The parent tree.</param>
 /// <param name="ParentNode">The parent node.</param>
 /// <param name="ParentConnectorNumber">The parent connector number.</param>
 internal SortedTreeNode(T ParentElementValue, SortedTree <T> ParentTree, SortedTreeNode ParentNode, int ParentConnectorNumber)
 {
     MyParentTree = ParentTree;
     Value        = ParentElementValue;
     if (ParentNode != null)
     {
         ParentNodes.Add(ParentConnectorNumber, ParentNode);
     }
 }
Example #4
0
 /// <summary>
 /// Adds the this node to another tree.
 /// </summary>
 /// <param name="tree">The tree.</param>
 public void AddThisNodeToAnotherTree(ref SortedTree <T> tree)
 {
     if (ParentNodes.Count == 0)
     {
         tree.AddNode(Value);
     }
     else
     {
         foreach (KeyValuePair <int, SortedTreeNode> kvpnode in ParentNodes)
         {
             int ParentConnector = kvpnode.Value.GetConnectorNumberOfSpecifiedNode(this);
             //zanim dodamy nowy element musimy sprawdzic czy juz jest dodany jego parent
             if (tree.GetNode(kvpnode.Value.Value) != null)
             {
                 tree.AddNode(kvpnode.Value.Value, ParentConnector, Value, kvpnode.Key);
             }
         }
     }
 }
Example #5
0
        /// <summary>
        /// Connects the tree to the node.
        /// </summary>
        /// <param name="NodeToWhichWeConnectsTheTreeValue">The node to which we connects the tree value.</param>
        /// <param name="NodeToWhichWeConnectsTheTreeConnectorNumer">The node to which we connects the tree connector numer.</param>
        /// <param name="TreeToBeConnected">The tree to be connected.</param>
        /// <param name="TreeToBeConnectedConnectorNumer">The tree to be connected connector numer.</param>
        public void ConnectTheTreeToTheNode(T NodeToWhichWeConnectsTheTreeValue, int NodeToWhichWeConnectsTheTreeConnectorNumer, SortedTree <T> TreeToBeConnected, int TreeToBeConnectedConnectorNumer)
        {
            //sprawdzamy czy polaczenie moze nastapic
            if (!TestTreeIfCanBeConnected(NodeToWhichWeConnectsTheTreeValue, NodeToWhichWeConnectsTheTreeConnectorNumer, TreeToBeConnected, TreeToBeConnectedConnectorNumer))
            {
                throw new SortedTreeNodeException("Cannot connect such tree");
            }
            //wyszukujemy node do ktorego chcemy podlaczyc drzewo
            SortedTreeNode NodeToWhichWeConnectsTheTree = GetNode(NodeToWhichWeConnectsTheTreeValue);

            if (NodeToWhichWeConnectsTheTree == null)
            {
                throw new SortedTreeNodeException("Cannot find parent node");
            }
            //klonujemy drzewo ktore dolaczamy aby uniknac ew. zmian w tym drzewie (chcemy miec pewnosc ze ktos zmieniajac oryginal to drzewo (this) pozostanie nie zmienione)
            SortedTree <T> clonnedtree = (SortedTree <T>)((ICloneable)TreeToBeConnected).Clone();

            clonnedtree.SetParentTree(this);
            NodeToWhichWeConnectsTheTree.AddNode(clonnedtree.GetRoots()[0], NodeToWhichWeConnectsTheTreeConnectorNumer, TreeToBeConnectedConnectorNumer);
            ParentCleanup();
        }
Example #6
0
        /// <summary>
        /// Gets the subtree from node.
        /// </summary>
        /// <param name="StartValue">The start value.</param>
        public SortedTree <T> GetSubtreeFromNode(T StartValue)
        {
            SortedTree <T> TreeToBeReturned = (SortedTree <T>)((ICloneable)this).Clone();

            TreeToBeReturned.MoveNodeToRoots(StartValue);
            // no we have to remove other roots
            int idx = 0;
            SortedTreeNodeList nodelist = TreeToBeReturned.GetRoots();

            while (nodelist.Count > 1)
            {
                if (!nodelist[idx].Value.Equals(StartValue))
                {
                    TreeToBeReturned.RemoveValue(nodelist[idx].Value, false);
                }
                else
                {
                    idx++;
                }
                nodelist = TreeToBeReturned.GetRoots();
            }
            return(TreeToBeReturned);
        }
Example #7
0
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        object ICloneable.Clone()
        {
            SortedTree <T> newtree = new SortedTree <T>();

            SortedTreeNodeList currentelementlist   = null; // lista elementow z aktualnej warstwy
            SortedTreeNodeList nextlevelelementlist = null; // lista elementow z nastepnej warstwy

            // kopiujemy najpierw roots elements
            currentelementlist = new SortedTree <T> .SortedTreeNodeList(m_Roots);

            //a teraz w petli
            while (currentelementlist.Count > 0)
            {
                nextlevelelementlist = new SortedTree <T> .SortedTreeNodeList();

                foreach (SortedTreeNode node in currentelementlist)
                {
                    nextlevelelementlist.Add(node.GetChildNodes());
                    node.AddThisNodeToAnotherTree(ref newtree);
                }
                currentelementlist = new SortedTree <T> .SortedTreeNodeList(nextlevelelementlist);
            }
            return(newtree);
        }
Example #8
0
        /// <summary>
        /// Tests the tree if can be connected.
        /// </summary>
        /// <param name="NodeToWhichWeConnectsTheTreeValue">The node to which we connects the tree value.</param>
        /// <param name="NodeToWhichWeConnectsTheTreeConnectorNumer">The node to which we connects the tree connector numer.</param>
        /// <param name="TreeToBeConnected">The tree to be connected.</param>
        /// <param name="TreeToBeConnectedConnectorNumer">The tree to be connected connector numer.</param>
        /// <returns></returns>
        public bool TestTreeIfCanBeConnected(T NodeToWhichWeConnectsTheTreeValue, int NodeToWhichWeConnectsTheTreeConnectorNumer, SortedTree <T> TreeToBeConnected, int TreeToBeConnectedConnectorNumer)
        {
            SortedTreeNode NodeToWhichWeConnects = GetNode(NodeToWhichWeConnectsTheTreeValue);

            if (NodeToWhichWeConnects == null)
            {
                return(false);
            }
            if (NodeToWhichWeConnects.GetChildNodes().ContainsKey(NodeToWhichWeConnectsTheTreeConnectorNumer))
            {
                return(false);
            }
            if (TreeToBeConnected.GetRoots().Count > 1)
            {
                return(false);
            }
            foreach (T nodevalue in TreeToBeConnected)
            {
                if (GetNode(nodevalue) != null)
                {
                    return(false);
                }
            }
            return(true);
        }