private void ClearButton_Click(object sender, EventArgs e)
 {
     DrawingPanel.CreateGraphics().Clear(Color.White);
     Edges = new EList();
     Vert  = new EList();
     //string a = "1\n2\n3\n4\n5";
     //if (SFD.ShowDialog() == DialogResult.OK)
     //    File.WriteAllText(SFD.FileName, a);
 }
Beispiel #2
0
        //вычислить координаты для каждого узла и записать в 2 разных списка либо точку самого узла (V), либо пару точек, задающую ребро (E)
        public void GetPoints(TNode t, int canvasWidth, int canvasHeight, EList E, EList V)
        {
            if (t.level > 0)
            {
                int   step = canvasWidth / (SizeOfLevel(root, t.level) + 1);
                TNode prev = null;
                bool  f1   = false;
                GetPrev(root, t, ref prev, ref f1);
                Point current;
                if (prev == null)
                {
                    current = new Point(step, t.level * canvasHeight / MainForm.MaxDEPTH - 15);
                }
                else
                {
                    current = new Point(prev.tPoint.X + step, t.level * canvasHeight / MainForm.MaxDEPTH - 15);
                }

                t.tPoint = current;
                V.Add(current, t.index); E.Add(current, t.Parent.tPoint);

                if (t.Branches != null && t.Branches.Length != 0)
                {
                    for (int i = 0; i < t.Branches.Length; i++)
                    {
                        GetPoints(t.Branches[i], canvasWidth, canvasHeight, E, V);
                    }
                }
            }
            else
            {
                V.Add(t.tPoint, t.index);
                if (t.Branches != null && t.Branches.Length != 0)
                {
                    for (int i = 0; i < t.Branches.Length; i++)
                    {
                        GetPoints(t.Branches[i], canvasWidth, canvasHeight, E, V);
                    }
                }
            }
        }
Beispiel #3
0
        private void GenerateButton_Click(object sender, EventArgs e)
        {
            //очистка панели рисования
            DrawingPanel.CreateGraphics().Clear(Color.White);

            //очистка списков (узлы/рёбра), если до этого момента кнопка "сгенерировать" уже была нажата
            Edges = new EList();
            Vert  = new EList();

            //генерация дерева
            TNode.GenerateBranches(bakaut.root, MaxDEPTH, BRANCHES);

            //инициализация точки корня для правильной работы алгоритма по нахождению остальных точек
            bakaut.root.tPoint = new Point(DrawingPanel.Width / 2, 15);

            //получение списков точек узлов/рёбер
            bakaut.GetPoints(bakaut.root, DrawingPanel.Width, DrawingPanel.Height, Edges, Vert);

            //рисование элементов
            DrawingPanel.CreateGraphics().DrawImage(DrawTree(DrawingPanel.Width, DrawingPanel.Height), new Point(0, 0));
        }
Beispiel #4
0
        public static void GenerateBranches

            (TNode curRoot, int maxDepth, int maxBranches, int canvasWidth, int canvasHeight, ref EList E, ref EList V, int ind)

        {
            Random r = new Random();

            if (maxDepth == MainForm.MaxDEPTH)
            {
                curRoot.tPoint = new Point(canvasWidth / 2, 15);
                V.Add(curRoot.tPoint, new Point(0, 0));

                curRoot.Branches = new TNode[r.Next(maxBranches)];


                for (int p = 0; p < curRoot.Branches.Length; p++)
                {
                    curRoot.Branches[p] = new TNode()
                    {
                        index      = p + 1,
                        level      = MainForm.MaxDEPTH - maxDepth + 1,
                        notVisited = true,
                        Parent     = curRoot
                    };

                    //if (ind < V.indicator.Length)
                    //    V.indicator[ind]++;
                    //ind++;


                    GenerateBranches(curRoot.Branches[p], maxDepth - 1, maxBranches, canvasWidth, canvasHeight, ref E, ref V, ind);
                }
            }
            else
            if
            (maxDepth != 0)
            {
                curRoot.Branches = new TNode[r.Next(maxBranches)];



                //запись координат точки текущего узла и запись пары точек для последующего рисования ребра
                int x = (curRoot.index + ind) * canvasWidth / (curRoot.Parent.Branches.Length + 1),

                    y = curRoot.level * canvasHeight / MainForm.MaxDEPTH + 15;

                curRoot.tPoint = new Point(x, y);

                V.Add(new Point(x, y), new Point(0, 0)); E.Add(new Point(x, y), curRoot.Parent.tPoint);


                for (int p = 0; p < curRoot.Branches.Length; p++)
                {
                    curRoot.Branches[p] = new TNode()
                    {
                        index      = p + 1,
                        level      = MainForm.MaxDEPTH - maxDepth + 1,
                        notVisited = true,
                        Parent     = curRoot
                    };

                    //if (ind < V.indicator.Length)
                    //    V.indicator[ind]++;
                    //ind++;


                    GenerateBranches(curRoot.Branches[p], maxDepth - 1, maxBranches, canvasWidth, canvasHeight, ref E, ref V, ind);
                }
            }
            else
            {
                int x = (curRoot.index + ind) * canvasWidth / (curRoot.Parent.Branches.Length + 1),

                    y = curRoot.level * canvasHeight / MainForm.MaxDEPTH + 15;

                curRoot.tPoint = new Point(x, y);

                V.Add(new Point(x, y), new Point(0, 0)); E.Add(new Point(x, y), curRoot.Parent.tPoint);
            }
        }
Beispiel #5
0
 //очистка
 private void ClearButton_Click(object sender, EventArgs e)
 {
     DrawingPanel.CreateGraphics().Clear(Color.White);
     Edges = new EList();
     Vert  = new EList();
 }