Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Metric m = new Metric();

            if (!GlobalVisual.BuildMatrix())
            {
                return;
            }

            m = GlobalVisual.da.GetMetric(GlobalVisual.VertexA, GlobalVisual.VertexB);
            foreach (VisualLink l in GlobalVisual.Links)
            {
                l.C = Color.Silver;
                bool mustPaint = false;
                for (int i = 0; i < m.intPath.Count - 1; i++)
                {
                    if ((m.intPath.GetVertex(i) + 1 == l.v1.VertexNumber &&
                         m.intPath.GetVertex(i + 1) + 1 == l.v2.VertexNumber) ||
                        (m.intPath.GetVertex(i + 1) + 1 == l.v1.VertexNumber &&
                         m.intPath.GetVertex(i) + 1 == l.v2.VertexNumber))
                    {
                        mustPaint = true;
                    }
                }
                if (mustPaint)
                {
                    l.C = Color.Orange;
                }
                mustPaint = false;
            }

            GlobalVisual.Path = "";
            for (int i = 0; i < m.intPath.Count; i++)
            {
                GlobalVisual.Path += (m.intPath.GetVertex(i) + 1).ToString();
                if (i != m.intPath.Count - 1)
                {
                    GlobalVisual.Path += "->";
                }
            }
            if (m.metric == MathConsts.INFINITE)
            {
                GlobalVisual.Path = "Path not found! m=INF";
            }
            else
            {
                GlobalVisual.Path += " m=" + m.metric.ToString();
            }
            GlobalVisual.DrawMetrics = true;

            Invalidate();

            if (!timer1.Enabled)
            {
                //Sound.Play();
                timer1.Enabled = true;
            }
        }
Exemple #2
0
 private void MainForm_MouseDown(object sender, MouseEventArgs e)
 {
     isDragging = true;
     if (e.Clicks == 2)
     {
         isDragging       = false;
         box              = new VisualVertex(e.X - VisualVertex.VisualSize / 2, e.Y - VisualVertex.VisualSize / 2);
         box.VertexNumber = (GlobalVisual.vertCount++) + 1;
         GlobalVisual.Vertexes.Add(box);
         Controls.Add(box);
         GlobalVisual.BuildMatrix();
     }
 }
Exemple #3
0
        private void VisualVertex_MouseUp(object sender, MouseEventArgs e)
        {
            Point p         = new Point(this.Left + e.X, this.Top + e.Y);
            bool  duplicate = false;
            int   m;

            isDragging = false;
            try
            {
                m = Convert.ToInt32(GlobalVisual.text.Text);
            }
            catch
            {
                m = 1;
            }
            if (GlobalVisual.isConnecting)
            {
                foreach (VisualVertex v in GlobalVisual.Vertexes)
                {
                    Rectangle r = new Rectangle(v.Left, v.Top, v.Width, v.Height);
                    if (r.Contains(p) && !this.Equals(v))
                    {
                        foreach (VisualLink vl in GlobalVisual.Links)
                        {
                            if ((this.Equals(vl.v1) || this.Equals(vl.v2)) &&
                                (v.Equals(vl.v1) || v.Equals(vl.v2)))
                            {
                                duplicate = true;
                                if (m <= 0)
                                {
                                    GlobalVisual.Links.Remove(vl);
                                }
                                else
                                {
                                    vl.Weight = m;
                                }
                                break;
                            }
                        }
                        if (!duplicate)
                        {
                            VisualLink l = new VisualLink(this, v);
                            l.Weight = m;
                            if (l.Weight > 0)
                            {
                                GlobalVisual.Links.Add(l);
                            }
                        }
                        break;
                    }
                }
            }
            //else
            //	;
            if (this.C != Color.Firebrick && this.C != Color.ForestGreen)
            {
                this.C = Color.White;
            }
            GlobalVisual.isConnecting      = false;
            GlobalVisual.isCreateLink      = false;
            GlobalVisual.isSelect1         = false;
            GlobalVisual.isSelect2         = false;
            GlobalVisual.button3.BackColor = Color.SteelBlue;
            GlobalVisual.button4.BackColor = Color.SteelBlue;
            GlobalVisual.BuildMatrix();

            Invalidate();
            Parent.Invalidate();
        }