コード例 #1
0
        public void StartDFA()
        {
            foreach (VertexView v in canvasView1.Views.OfType <VertexView>())
            {
                if (v.Vertex.IsStart)
                {
                    currentVV = v;
                }
                v.IsHighLighted = false;
            }
            if (currentVV != null)
            {
                strip.Clear();
                foreach (char c in tbPath.Text)
                {
                    strip.Add(c.ToString());
                }
                stripPointer = 0;

                currentVV.IsHighLighted = true;

                canvasView1.Refresh();
                timer1.Start();
                btnStart.Visible = false;
                btnPause.Visible = true;
            }
            else
            {
                //ERROR
            }
        }
コード例 #2
0
        private void BtnStep_Click(object sender, EventArgs e)
        {
            if (isPause)
            {
                StepDFA();
            }
            else
            {
                foreach (VertexView v in canvasView1.Views.OfType <VertexView>())
                {
                    if (v.Vertex.IsStart)
                    {
                        currentVV = v;
                    }
                    v.IsHighLighted = false;
                }
                if (currentVV != null)
                {
                    strip.Clear();
                    foreach (char c in tbPath.Text)
                    {
                        strip.Add(c.ToString());
                    }
                    stripPointer = 0;

                    currentVV.IsHighLighted = true;

                    canvasView1.Refresh();
                }
                else
                {
                    //ERROR
                }
            }
        }
コード例 #3
0
        private void On_MouseUp(IView sender)
        {
            if (moving != null)
            {
                moving = null;
            }
            if (isAdding)
            {
                isAdding = false;

                if (Over != null)
                {
                    if (Equals(EPreview.Edge.Vertex1, Over.Vertex))
                    {
                        this.Text = "";
                    }
                    graph.AddEdge(EPreview.Edge.Vertex1, Over.Vertex);
                }
                else
                {
                    graph.AddVertex();
                    (canvasView1.Views[canvasView1.Views.Count - 1] as VertexView).Location = VPreview.Location;
                    graph.AddEdge(EPreview.Edge.Vertex1, (canvasView1.Views[canvasView1.Views.Count - 1] as VertexView).Vertex);
                }
                canvasView1.Views.Remove(VPreview);
                canvasView1.Views.Remove(EPreview);
            }
            canvasView1.Refresh();
        }
コード例 #4
0
        private void On_Mouse_Move(Object sender, MouseEventArgs e)
        {
            VertexView v_on_over = VertexHitTest(new Point(e.X, e.Y));
            EdgeView   e_on_over = EdgeHitTest(new Point(e.X, e.Y));

            foreach (VertexView v in Views.OfType <VertexView>())
            {
                if (v_on_over != null && v == v_on_over)
                {
                    v_on_over.Raise_MouseEnter();
                    v_on_over.Raise_MouseMove();
                }
                else
                {
                    v.Raise_MouseLeave();
                }
            }

            foreach (EdgeView v in Views.OfType <EdgeView>())
            {
                if (e_on_over != null && v == e_on_over)
                {
                    e_on_over.Raise_MouseEnter();
                }
                else
                {
                    v.Raise_MouseLeave();
                }
            }



            Refresh();
        }
コード例 #5
0
        private VertexView VertexAdd(Vertex vertex, Point location)
        {
            VertexView v = new VertexView();

            v.Vertex      = vertex;
            v.Location    = location;
            v.MouseDown  += On_MouseDown;
            v.MouseUp    += On_MouseUp;
            v.MouseLeave += On_MouseLeave;
            v.MouseEnter += On_MouseEnter;
            return(v);
        }
コード例 #6
0
        private VertexView VertexAdd(Vertex vertex)
        {
            VertexView v = new VertexView();

            v.Vertex      = vertex;
            v.Location    = new Point(r.Next(v.Radius, canvasView1.Width - v.Radius), r.Next(v.Radius, canvasView1.Height - v.Radius));
            v.MouseDown  += On_MouseDown;
            v.MouseUp    += On_MouseUp;
            v.MouseLeave += On_MouseLeave;
            v.MouseEnter += On_MouseEnter;
            return(v);
        }
コード例 #7
0
        public void On_VertexRemoved(Graph sender, Vertex vertex)
        {
            VertexView v = canvasView1.FindViewByVertex(vertex);

            if (v != null)
            {
                v.MouseDown  -= On_MouseDown;
                v.MouseUp    -= On_MouseUp;
                v.MouseLeave -= On_MouseLeave;
                v.MouseEnter -= On_MouseEnter;
                canvasView1.Views.Remove(v);
            }
            v = null;
            canvasView1.Refresh();
        }
コード例 #8
0
 private void On_MouseMove(Object sender, MouseEventArgs e)
 {
     if (moving != null)
     {
         moving.Location = new Point(OldPoint.X + (MousePosition.X - StartPoint.X), OldPoint.Y + (MousePosition.Y - StartPoint.Y));
         foreach (Edge ed in graph.NeihbourEdges(moving.Vertex))
         {
             if (canvasView1.FindViewByEdge(ed).Edge.Vertex1 == moving.Vertex)
             {
                 if (canvasView1.FindViewByEdge(ed).Edge.Vertex2 == moving.Vertex)
                 {
                     canvasView1.FindViewByEdge(ed).Point1 = moving.Location;
                     canvasView1.FindViewByEdge(ed).Point2 = moving.Location;
                 }
                 else
                 {
                     canvasView1.FindViewByEdge(ed).Point1 = moving.Location;
                 }
             }
             else
             {
                 canvasView1.FindViewByEdge(ed).Point2 = moving.Location;
             }
         }
     }
     if (isAdding)
     {
         VertexView hitTest = canvasView1.VertexHitTest(new Point(e.X, e.Y), VPreview);//, VPreview);
         if (hitTest != null)
         {
             VPreview.Location = hitTest.Location;
             Over = hitTest;
         }
         else
         {
             VPreview.Location = new Point(OldPoint.X + (MousePosition.X - StartPoint.X), OldPoint.Y + (MousePosition.Y - StartPoint.Y));
             Over = null;
         }
         EPreview.Point2 = canvasView1.FindViewByVertex(EPreview.Edge.Vertex2).Location;
     }
 }
コード例 #9
0
        private void On_MouseDown(IView sender)
        {
            if (MouseButtons == MouseButtons.Left)
            {
                foreach (VertexView v in canvasView1.Views.OfType <VertexView>())
                {
                    v.IsSelected = false;
                }
                (sender as VertexView).IsSelected = true;


                tbNameNode.Text = (sender as VertexView).Vertex.Value;
                tbNameNode.Focus();
                tbNameNode.SelectAll();
                cbStartState.Checked = (sender as VertexView).Vertex.IsStart;
                cbFinalState.Checked = (sender as VertexView).Vertex.IsFinish;

                if (OnSelectedChange != null)
                {
                    OnSelectedChange(sender as VertexView);
                }
                canvasView1.BringToFront(sender);
                moving = (VertexView)sender;
            }
            else
            {
                VPreview.Location = (sender as VertexView).Location;
                VPreview.Vertex   = new Vertex("");
                canvasView1.Views.Add(VPreview);

                EPreview.Edge   = new Edge((sender as VertexView).Vertex, VPreview.Vertex);
                EPreview.Point1 = canvasView1.FindViewByVertex(EPreview.Edge.Vertex1).Location;
                EPreview.Point2 = canvasView1.FindViewByVertex(EPreview.Edge.Vertex2).Location;
                canvasView1.Views.Add(EPreview);
                canvasView1.BringToFront(VPreview);
                isAdding = true;
                Over     = (sender as VertexView);
            }
            OldPoint   = (sender as VertexView).Location;
            StartPoint = MousePosition;
        }
コード例 #10
0
 public void StepDFA()
 {
     if (stripPointer < strip.Count)
     {
         foreach (Edge e in graph.IncidentedEdges(currentVV.Vertex))
         {
             if (e.Value.Contains(strip[stripPointer]))
             {
                 currentVV.IsHighLighted = false;
                 currentVV = canvasView1.FindViewByVertex(e.Vertex2);
                 currentVV.IsHighLighted = true;
                 break;
             }
         }
         stripPointer += 1;
         canvasView1.Refresh();
         StripRedraw();
     }
     else
     {
         timer1.Stop();
         stripPointer            = 0;
         isPause                 = false;
         currentVV.IsHighLighted = false;
         if (currentVV.Vertex.IsFinish)
         {
             lbResult.ForeColor = Color.GreenYellow;
             lbResult.Text      = "Accepted";
         }
         else
         {
             lbResult.ForeColor = Color.Tomato;
             lbResult.Text      = "Rejected";
         }
         btnStart.Visible = true;
         btnPause.Visible = false;
         StripRedraw();
     }
 }
コード例 #11
0
        private void On_Mouse_Down(Object sender, MouseEventArgs e)
        {
            foreach (VertexView v in Views.OfType <VertexView>())
            {
                v.IsSelected = false;
            }
            VertexView on_down = VertexHitTest(new Point(e.X, e.Y));

            if (on_down != null)
            {
                on_down.Raise_MouseDown();
            }

            EdgeView on_click = EdgeHitTest(new Point(e.X, e.Y));

            if (on_click != null)
            {
                on_click.Raise_MouseClick();
            }

            Refresh();
        }
コード例 #12
0
 void GraphForm_OnSelectedChange(VertexView v)
 {
     Selected = v;
 }