Ejemplo n.º 1
0
        }                                                                   // проверка ввода в textbox

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e) // клик по picturebox
        {
            if (Draw == true)
            {
                Bitmap btm = new Bitmap(pictureBox1.Width, pictureBox1.Height);
                Peak   point = new Peak();
                int    X = e.X - 13; int Y = e.Y - 13;
                if (point.match(array_of_peak, X, Y) >= 0)
                {
                    return;
                }
                point.peak(array_of_peak.Count, X, Y, i);
                array_of_peak.Add(point);
                pictureBox1.Image = btm;
                draw();
                pictureBox1.Invalidate();
                if (i == 6)
                {
                    i = -1;
                }
                i++;
            }       // задаем точки
            if (Clear == true)
            {
                Bitmap btm = new Bitmap(pictureBox1.Width, pictureBox1.Height);
                Peak   point = new Peak();
                Arc    line = new Arc();
                int    X = e.X - 13; int Y = e.Y - 13;
                int    index          = point.match(array_of_peak, X, Y);         // мы кликнули по точке?
                int    index_road_del = line.match(array_of_arc, X, Y);           // мы кликнули по прямой?
                int    loop           = line.search_for_loop(array_of_arc, X, Y); // мы кликнули по петле?
                int    arc            = line.search_for_arc(array_of_arc, X, Y);
                if (index >= 0)
                {
                    for (int j = 0; j < array_of_arc.Count; j++)
                    {
                        if (array_of_arc[j].peak1.number_peak == array_of_peak[index].number_peak ||
                            array_of_arc[j].peak2.number_peak == array_of_peak[index].number_peak)
                        {
                            array_of_arc.RemoveAt(j);
                            j--;
                        }
                    }
                    array_of_peak.RemoveAt(index);
                    pictureBox1.Image = btm;
                    draw();
                    pictureBox1.Invalidate();
                    return;
                }
                if (arc >= 0)
                {
                    array_of_arc.RemoveAt(arc);
                    pictureBox1.Image = btm;
                    draw();
                    pictureBox1.Invalidate();
                    return;
                }
                if (loop >= 0)
                {
                    array_of_arc.RemoveAt(loop);
                    pictureBox1.Image = btm;
                    draw();
                    pictureBox1.Invalidate();
                    return;
                }
                if (index_road_del >= 0)
                {
                    array_of_arc.RemoveAt(index_road_del);
                    pictureBox1.Image = btm;
                    draw();
                    pictureBox1.Invalidate();
                    return;
                }
            }       // удаляем
            if (Line == true)
            {
                Bitmap btm = new Bitmap(pictureBox1.Width, pictureBox1.Height);
                Peak   point = new Peak();
                Arc    line = new Arc();
                int    X = e.X - 13; int Y = e.Y - 13;
                int    index = point.match(array_of_peak, X, Y);
                if (index >= 0)
                {
                    road.Add(index);
                }
                if (road.Count == 2)
                {
                    bool arc = false;
                    if (!line.search_for_matches(array_of_arc, array_of_peak, road, ref arc))
                    {
                        line.Box(array_of_peak, road, 0, arc);
                        array_of_arc.Add(line);
                        pictureBox1.Image = btm;
                        draw();
                        pictureBox1.Invalidate();
                    }
                    road.Clear();
                }
            }       // задаеем дуги
            if (Weight == true)
            {
                Bitmap btm = new Bitmap(pictureBox1.Width, pictureBox1.Height);
                Peak   point = new Peak();
                Arc    line = new Arc();
                int    X = e.X - 13; int Y = e.Y - 13;
                int    index_road_del = line.match(array_of_arc, X, Y);
                int    loop           = line.search_for_loop(array_of_arc, X, Y);
                int    arc            = line.search_for_arc(array_of_arc, X, Y);
                if (arc >= 0)
                {
                    CreatWeight newForm = new CreatWeight();
                    newForm.Owner = this;
                    newForm.ShowDialog();
                    array_of_arc[arc].weight = ix;
                    pictureBox1.Image        = btm;
                    draw();
                    pictureBox1.Invalidate();
                    return;
                }
                if (loop >= 0)      // клик по петле
                {
                    CreatWeight newForm = new CreatWeight();
                    newForm.Owner = this;
                    newForm.ShowDialog();
                    array_of_arc[loop].weight = ix;
                    pictureBox1.Image         = btm;
                    draw();
                    pictureBox1.Invalidate();
                    return;
                }
                if (index_road_del >= 0)    // клик по дуге
                {
                    CreatWeight newForm = new CreatWeight();
                    newForm.Owner = this;
                    newForm.ShowDialog();
                    array_of_arc[index_road_del].weight = ix;
                    pictureBox1.Image = btm;
                    draw();
                    pictureBox1.Invalidate();
                    return;
                }
                ix = 0;
            }       // задаем вес
        }