Exemplo n.º 1
0
 /// <summary>
 /// Добавляет все узлы декартового дерева в списки
 /// </summary>
 private void AddedAllNodes()
 {
     if (!Treap.IsEmpty())
     {
         Nodes.Add(Treap.Root);
         NodeDrawers.Add(GetNodeDrawer(Treap.Root, Backslash, 0, MaxWidth));
     }
     for (int i = 0; i < Nodes.Count; ++i)
     {
         int mid = (NodeDrawers[i].EndX + NodeDrawers[i].StartX) / 2;
         if (Nodes[i].Left != null)
         {
             Nodes.Add(Nodes[i].Left);
             NodeDrawers.Add(GetNodeDrawer(Nodes[i].Left, NodeDrawers[i].StartY + NodeDrawers[i].Size + DistanseHeight, NodeDrawers[i].StartX, mid));
             NodeDrawers.Last().Arrow =
                 new ArrowDrawer(mid, NodeDrawers[i].StartY + NodeDrawers[i].Size + 2, (NodeDrawers[i].StartX + mid) / 2, NodeDrawers[i].StartY + NodeDrawers[i].Size + DistanseHeight - 2)
             {
                 Pen           = (Pen)PenArrow.Clone(),
                 LengthPointer = NodeDrawers[i].Size / 3,
             };
         }
         if (Nodes[i].Right != null)
         {
             Nodes.Add(Nodes[i].Right);
             NodeDrawers.Add(GetNodeDrawer(Nodes[i].Right, NodeDrawers[i].StartY + NodeDrawers[i].Size + DistanseHeight, mid + 1, NodeDrawers[i].EndX));
             NodeDrawers.Last().Arrow =
                 new ArrowDrawer(mid, NodeDrawers[i].StartY + NodeDrawers[i].Size + 2, (NodeDrawers[i].EndX + mid) / 2, NodeDrawers[i].StartY + NodeDrawers[i].Size + DistanseHeight - 2)
             {
                 Pen           = (Pen)PenArrow.Clone(),
                 LengthPointer = NodeDrawers[i].Size / 3,
             };
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Отрисовывает следующее изменение
        /// </summary>
        public void NextEventInLog()
        {
            if (indexLogs >= Logs.Count)
            {
                return;
            }
            else
            {
                switch (Logs[indexLogs].LogEvent)
                {
                case LogTreapEvent.StartSplite:
                {
                    ClearActive();
                    NodeDrawer nodeDrawer = FindNodeDrawer(Logs[indexLogs].Nodes[0]);
                    nodeDrawer.PenBorder.Color = activeColor;
                    prevActive.Enqueue(nodeDrawer);
                    break;
                }

                case LogTreapEvent.EndSplite:
                {
                    prevActive.Clear();
                    NodeDrawer nodeDrawer = FindNodeDrawer(Logs[indexLogs].Nodes[0]);
                    nodeDrawer.PenBorder.Color = PenBorder.Color;
                    break;
                }

                case LogTreapEvent.RemoveEdge:
                {
                    NodeDrawer nodeDrawer = FindNodeDrawer(Logs[indexLogs].Nodes[0]);
                    nodeDrawer.Arrow = null;
                    break;
                }

                case LogTreapEvent.AddedEdge:
                {
                    NodeDrawer nodeFrom = FindNodeDrawer(Logs[indexLogs].Nodes[0]);
                    NodeDrawer nodeTo   = FindNodeDrawer(Logs[indexLogs].Nodes[1]);
                    nodeFrom.PenBorder.Color = activeColor;
                    nodeTo.Arrow             = new ArrowDrawer(nodeFrom.Rect, nodeTo.Rect)
                    {
                        Pen           = (Pen)PenArrow.Clone(),
                        LengthPointer = nodeTo.Size / 3,
                    };
                    break;
                }

                case LogTreapEvent.StartMerge:
                {
                    ClearActive();
                    NodeDrawer nodeLeft  = FindNodeDrawer(Logs[indexLogs].Nodes[0]);
                    NodeDrawer nodeRight = FindNodeDrawer(Logs[indexLogs].Nodes[1]);
                    nodeLeft.PenBorder.Color  = activeColor;
                    nodeRight.PenBorder.Color = activeColor;
                    prevActive.Enqueue(nodeLeft);
                    prevActive.Enqueue(nodeRight);
                    break;
                }

                case LogTreapEvent.EndMerge:
                {
                    prevActive.Clear();
                    NodeDrawer nodeLeft  = FindNodeDrawer(Logs[indexLogs].Nodes[0]);
                    NodeDrawer nodeRight = FindNodeDrawer(Logs[indexLogs].Nodes[1]);
                    nodeLeft.PenBorder.Color  = PenBorder.Color;
                    nodeRight.PenBorder.Color = PenBorder.Color;
                    break;
                }
                }
                Draw();
                indexLogs++;
            }
        }