Exemplo n.º 1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            //myAutomaton.stateList.RemoveAt(selectedState.uniqueID);
            //newState = new List<State>(myAutomaton.stateList);
            //newState.RemoveAt(selectedState.uniqueID);

            selectedState.alive = false;
                myAutomaton = new Automaton();
            myAutomaton.build(newState);
            drawDiagram();
        }
Exemplo n.º 2
0
 private void saveToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (tbxFile.Text != "")
     {
         myParser.stateList = myAutomaton.stateList;
         myParser.saveXML(tbxFile.Text);
         myAutomaton = new Automaton();
         myAutomaton.build(newState);
         btnRun.Enabled = true;
     }
 }
Exemplo n.º 3
0
 private void save()
 {
     tbxFile.Text = saveFileDialog1.FileName;
     myParser.stateList = myAutomaton.stateList;
     myParser.saveXML(tbxFile.Text);
     myAutomaton = new Automaton();
     myAutomaton.build(newState);
     btnRun.Enabled = true;
 }
Exemplo n.º 4
0
        private void reset()
        {
            g = Graphics.FromImage(bmp);

            myAutomaton = new Automaton();
            myAutomaton.build(newState);

            c = myAutomaton.stateList.Count;
            wid = (pbxDraw.Width - 170) / (c) + 10;

            setStatePoints();
            drawDiagram();

            tbxID.Clear();
            tbxConnectTo.Clear();
            tbxConnectWith.Clear();
            showSelectedStateInfo();
        }
Exemplo n.º 5
0
        private void pbxDraw_MouseUp(object sender, MouseEventArgs e)
        {
            drag = -1;
            if (doubleClick)
            {
                tbxName.Enabled = true;
                tbxID.Enabled = true;
                tbxConnectTo.Enabled = true;
                tbxConnectWith.Enabled = true;

                //radiobtnOpen.Enabled = false;
                //radioButton2.Enabled = false;
                //radioButton3.Enabled = false;
                int m = findStatePoint(new Point(e.X, e.Y));
                if (m < myAutomaton.stateList.Count && m > -1)
                {
                    selectedState = myAutomaton.stateList[m];

                }

                showSelectedStateInfo();
                doubleClick = false;
                setComboBox();
                comboBox1.SelectedText = selectedState.name;
                drawDiagram();

            }
            else if (cbxDraw.Checked)
            {
                int n = findStatePoint(new Point(e.X, e.Y));
                if (n >= 0)
                {
                    if (newState[mdState].connect.Length > 0)
                    {
                        newState[mdState].connect += "_";
                    }
                    newState[mdState].connect += newState[n].name;//n.ToString();

                    tbxDraw.Size = new Size(20, 20);
                    tbxDraw.Visible = true;
                    tbxDraw.Focus();
                    Point p = new Point((statePoints[mdState].X+statePoints[n].X)/2 + pbxDraw.Location.X, (statePoints[mdState].Y + statePoints[n].Y)/2+pbxDraw.Location.Y);
                    tbxDraw.Location = p;
                    selectedState = newState[mdState];

                    if (selectedState.category == "Initial")
                    {
                        radioInitial.Checked = true;
                    }
                    if (selectedState.category == "Intermediate")
                    {
                        radioInter.Checked = true;
                    }
                    if (selectedState.category.Contains("Final"))
                    {
                        cbxFinal.Checked = true;
                    }
                    myAutomaton = new Automaton();
                    myAutomaton.build(newState);

                }
                drawDiagram();
                tbxID.Text = selectedState.uniqueID.ToString();
                tbxConnectTo.Text = selectedState.connect.ToString();
                tbxConnectWith.Text = selectedState.connectsWith;

            }
        }
Exemplo n.º 6
0
        private void pbxDraw_MouseDown(object sender, MouseEventArgs e)
        {
            if (!cbxDraw.Checked)
            {
                drag = findStatePoint(new Point(e.X, e.Y));

            }
            if (!btnAdd.Enabled)
            {
                tbxID.Enabled = true;
                tbxName.Enabled = true;
                tbxConnectTo.Enabled = true;
                tbxConnectWith.Enabled = true;
                tbxDrawName.Clear();
                tbxDrawName.Focus();
                tbxDrawName.Visible = true;
                tbxDrawName.Location = new Point(e.X+pbxDraw.Location.X, e.Y);

                myAutomaton = new Automaton();
                myAutomaton.intermediateStates = new List<State>();
                myAutomaton.finalStates = new List<State>();
                myAutomaton.stateList = new List<State>();
                myAutomaton.startState = new State();
                myAutomaton.currentState = new State();

                State st = new State();
                //if (myAutomaton.currentState == null) { myAutomaton.currentState = myAutomaton.stateList[0]; }
                if (statePoints == null)
                //if(myAutomaton.stateList.Count == 0)
                {
                    //myAutomaton
                    st.category = "Initial";
                    myAutomaton.startState = st;
                    //myAutomaton.currentState = st;
                    statePoints = new List<Point>();
                }
                else
                {
                    st.category = "Intermediate";
                    //myAutomaton.intermediateStates.Add(st);
                }

                btnAdd.Enabled = true;
                //statePoints.Insert(statePoints.Count,
                statePoints.Add(new Point(e.X - wid / 4, e.Y - wid / 4));
                c = statePoints.Count;
                wid = (pbxDraw.Height-170) / (c);

                if (c > 1)
                {
                    st.category = "Intermediate";
                    radioInitial.Enabled = true;
                    radioInter.Enabled = true;

                }
                st.uniqueID = c - 1;
                st.transition = 1;
                //st.connect = textBox4.Text;
                //st.connectsWith = textBox5.Text;

                //myAutomaton.startState = new State();

                newState.Add(st);

                selectedState = st;
                myAutomaton.build(newState);
                //myAutomaton.currentState = newState[0];
                //setStatePoints();
                drawDiagram();
                tbxID.Text = st.uniqueID.ToString();
                //drawStatePoints();
                tbxDrawName.Focus();
            }
            else
            {
                int n = findStatePoint(new Point(e.X, e.Y));
                if (n >= 0)
                {
                    mdState = n;
                    drawDiagram();
                }
            }
        }
Exemplo n.º 7
0
        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            showSelectedStateInfo();
            tbxFile.Text = openFileDialog1.FileName;
            //myParser.loadXML(openFileDialog1.FileName);
            //drawDiagram();

            cbxDraw.Enabled = true;
            btnReset.Enabled = true;
            g = pbxDraw.CreateGraphics();
            btnRun.Enabled = true;
            g.Clear(Color.White);
            myParser = new Parser();
            myAutomaton = new Automaton();

            string inputFile = tbxFile.Text;
            //myParser.loadXML("../../SampleFormat.xml");
            if (cbxRegEx.Checked)
            {
                myParser.loadRegEx(inputFile);
                myParser.stateList = new List<State>(myParser.buildFromRegEx(myParser.stateList, 0, myParser.regex));
            }
            else
            {
                myParser.loadXML(inputFile);
            }
            newState = new List<State>(myParser.stateList);

            myAutomaton.build(myParser.stateList);
            c = myAutomaton.stateList.Count;
            wid = (pbxDraw.Width - 170) / (c) + 10;
            setStatePoints();
            drawDiagram();
            setComboBox();
        }
Exemplo n.º 8
0
        private void drawDiagram()
        {
            setComboBox();
            if (!selectedState.alive) { selectedState = myAutomaton.stateList[0]; }
            current = myAutomaton.currentState;
            myAutomaton = new Automaton();
            myAutomaton.build(newState);
            myAutomaton.currentState = current;
            wid = Math.Max(wid, 80);
            wid = Math.Min(wid, 200);
            //using (g = Graphics.FromImage(bmp))
            using (g = pbxDraw.CreateGraphics())
            {
                g.Clear(Color.CornflowerBlue);
                drawConnections();

                drawStatePoints();
                drawCurrentState();
                drawStateIDs();
            }
            //pbxDraw.Image = bmp;
            //bmp = new Bitmap(pbxDraw.Width, pbxDraw.Height);
            //pbxDraw.DrawToBitmap(bmp, pbxDraw.ClientRectangle);
            //pbxDraw.BackgroundImage = bmp;
        }
Exemplo n.º 9
0
        private void tests()
        {
            string str = "\t DFA \t NFA \n\n";
            string [,]DFA = new string[5,5];
            string[,] NFA = new string[5, 5];
            //List<List<string>> DFA = new List<List<string>>(5);
            //DFA.Add(new List<string>(5));
            DFA[0,0] = "aa";
            DFA[0,1] = "babababb";
            DFA[0,2] = "abbaab";
            DFA[0,3] = "bb";
            DFA[0,4] = "bbaaaabbbab";
            DFA[1, 0] = "rgy";
            DFA[1, 1] = "rgyrgy";
            DFA[1, 2] = "rgyrgyrgy";
            DFA[1, 3] = "rgyrgyrgyrgy";
            DFA[1, 4] = "rgyrgyrgyrgyrgy";
            DFA[2,0] = "101100111110";
            DFA[2,1] = "01001001111";
            DFA[2,2] = "010101110101";
            DFA[2,3] = "101111111110";
            DFA[2,4] = "0011101110";
            DFA[3,0] = "000001111110";
            DFA[3,1] = "00000000";
            DFA[3,2] = "11111111111";
            DFA[3,3] = "01100000000";
            DFA[3,4] = "1001111001";
            DFA[4,0] = "1111111111";
            DFA[4,1] = "000000000111111111";
            DFA[4,2] = "0101010101010101";
            DFA[4,3] = "001001001001";
            DFA[4,4] = "0010011111";

            NFA[0,0] = "abbbababb";
            NFA[0,1] = "aaaaaaaab";
            NFA[0,2] = "aabaabbbbab";
            NFA[0,3] = "abaabaabbaabab";
            NFA[0,4] = "aaaabbbbaaab";
            NFA[1,0] = "11111011011111";
            NFA[1,1] = "0110";
            NFA[1,2] = "1001";
            NFA[1,3] = "111110011111";
            NFA[1,4] = "00110001001111";
            NFA[2,0] = "&";
            NFA[2,1] = "ab";
            NFA[2,2] = "ababababab";
            NFA[2,3] = "abaab";
            NFA[2,4] = "aabaabaab";
            NFA[3,0] = "aaabbbbbaba";
            NFA[3,1] = "cccaaaaacca";
            NFA[3,2] = "bbccbcbbb";
            NFA[3,3] = "accacccc";
            NFA[3,4] = "cbbbbbcbb";
            NFA[4,0] = "aaaaabbbbbb";
            NFA[4,1] = "aa";
            NFA[4,2] = "bbbbaabaaba";
            NFA[4,3] = "bababaababa";
            NFA[4,4] = "baabaaaab";

            for (int i = 0; i < 5; i++)
            {
                myAutomaton = new Automaton();
                myParser.loadXML("../../testDFA" + (i+1).ToString() + ".xml");
                myAutomaton.build(myParser.stateList);

                Automaton auto = new Automaton();
                Parser nParser = new Parser();
                nParser.loadXML("../../testNFA" + (i + 1).ToString() + ".xml");
                auto.build(nParser.stateList);

                for (int j = 0; j < 5; j++)
                {
                    myAutomaton.mExpression = DFA[i,j];
                    bool test = myAutomaton.solve(myAutomaton.currentState, myAutomaton.mExpression);
                    str += "(" + (i+1).ToString() + "," + (j+1).ToString() + ")\t" + test.ToString() + "\t";

                    auto.mExpression = NFA[i, j];
                    test = auto.solve(auto.currentState, auto.mExpression);
                    str += test.ToString() + "\n";

                }

            }
            MessageBox.Show(str);
        }
Exemplo n.º 10
0
        private void tbxRegEx_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                myParser = new Parser();
                myParser.regex = tbxRegEx.Text;
                myParser.stateList = new List<State>(myParser.buildFromRegEx(myParser.stateList, 0, myParser.regex));
                myAutomaton = new Automaton();
                myAutomaton.stateList = new List<State>();
                myAutomaton.build(myParser.stateList);

                cbxDraw.Enabled = true;
                btnReset.Enabled = true;
                g = pbxDraw.CreateGraphics();
                btnRun.Enabled = true;
                g.Clear(Color.White);

                newState = new List<State>(myParser.stateList);

                //myAutomaton.build(myParser.stateList);
                c = myParser.stateList.Count;
                wid = (pbxDraw.Width - 170) / (c+1) + 10;
                statePoints = new List<Point>(myParser.stateList.Count);
                setStatePoints();
                drawDiagram();
            }
        }
Exemplo n.º 11
0
 private void tbxDraw_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         if (tbxDraw.Text != "")
         {
             if (newState[mdState].connectsWith.Length > 0)
             {
                 newState[mdState].connectsWith += "_";
             }
             newState[mdState].connectsWith += tbxDraw.Text;
             selectedState = newState[mdState];
             myAutomaton = new Automaton();
             myAutomaton.build(newState);
             tbxDraw.Clear();
             tbxDraw.Visible = false;
             drawDiagram();
             showSelectedStateInfo();
         }
     }
 }
Exemplo n.º 12
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            tbxDraw.Visible = false;
            tbxDrawName.Visible = false;
            drawDiagram();

            if (tbxName.Text != "")
            { selectedState.name = tbxName.Text; }
            if(tbxID.Text != "")
            {selectedState.uniqueID = System.Convert.ToInt32(tbxID.Text);}
            if(tbxConnectTo.Text != "")
            {selectedState.connect = tbxConnectTo.Text;}
            if(tbxConnectWith.Text != "")
            {selectedState.connectsWith = tbxConnectWith.Text;}

            if (radioInter.Checked)
            { selectedState.category = "Intermediate"; }
            if (cbxFinal.Checked)
            { selectedState.category += "_Final"; }
            if(selectedState.uniqueID < newState.Count)
            {newState[selectedState.uniqueID] = selectedState;}

            if (tbxDraw.Text != "")
            {

                if (newState[mdState].connectsWith.Length > 0)
                {
                    newState[mdState].connectsWith += "_";
                }
                newState[mdState].connectsWith += tbxDraw.Text;
                selectedState = newState[mdState];
                myAutomaton = new Automaton();
                myAutomaton.build(newState);
                tbxDraw.Clear();
            }
            //myAutomaton = new Automaton();
            //myAutomaton.build(newState);
            /*if (selectedState.uniqueID == 0)
            {
                myAutomaton.startState = selectedState;
            }
            else
            {
                myAutomaton.intermediateStates[selectedState.uniqueID - 1] = selectedState;
            }*/
            tbxID.Text = selectedState.uniqueID.ToString();
            tbxConnectTo.Text = selectedState.connect.ToString();
            tbxConnectWith.Text = selectedState.connectsWith;

            //myAutomaton.currentState = newState[0];
            drawDiagram();
        }