public void AddElement(StateCharPair k, StateFiniteAutomata v)
        {
            List<StateFiniteAutomata> s = null;
            if (functionData.Count > 0)
            {

                if(functionData.ContainsKey(k) )
                {
                    s = functionData[k];
                    s.Add(v);
                }
                else
                {
                    s = new List<StateFiniteAutomata>();
                    s.Add(v);
                    functionData.Add(k, s);
                }
            }
            else
            {
                 s = new List<StateFiniteAutomata>();
                 s.Add(v);
                 functionData.Add(k, s);

            }
        }
 public StateFiniteAutomata GetNextState(StateFiniteAutomata currentS,char c)
 {
     if (functionData.ContainsKey(new StateCharPair(currentS, c)))
     {
         StateFiniteAutomata res = functionData[new StateCharPair(currentS, c)][0];
         return res;
     }
     return null;
 }
 public bool DeleteRow(StateCharPair sp, StateFiniteAutomata s)
 {
     if (functionData.Count > 0)
     {
         List<StateFiniteAutomata> nStates = functionData[sp];
         if (nStates != null) { return nStates.Remove(s); }
     }
     return false;
 }
        public bool SetDirectState(StateCharPair sp, StateFiniteAutomata s)
        {
            if (functionData.Count > 0)
            {
                List<StateFiniteAutomata> nStates = null;
                if(functionData.ContainsKey(sp))
                {
                    nStates=functionData[sp];

                    if (!nStates.Contains(s)) { nStates.Add(s); return true; }
                }
                else
                {
                    nStates = new List<StateFiniteAutomata>();
                    nStates.Add(s);
                    functionData.Add(sp, nStates);
                    return true;
                }

            }
            return false;
        }
        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            int createOption = tbox.PressedButton;
            if (selectState == 4)
            {
                removeTextTempBox();
                selectState = 0;
            }
            switch (createOption)
            {
                case 0:   break; //here edditing current item
                case 1:
                    {
                        if (graph.HasStartNode == false)
                        {
                            string newName = default_state_name + currentStateNumber;
                            currentStateNumber++;
                            Node tempNode=graph.AddStartNode(e.X, e.Y,newName);
                            StateFiniteAutomata state1 = new StateFiniteAutomata(tempNode);
                            tempNode.NodeState = state1;
                            mainAutomate.AddStartState(state1);
                            listView2.Items.Insert(0, "->" + state1.Name);
                            tbox.FreezeStartNode();
                            graph.HasStartNode = true;
                        }
                    }
                    break;
                case 2:
                    {
                        string newName = default_state_name + currentStateNumber;
                        currentStateNumber++;
                        Node tempNode = graph.AddCommonNode(e.X, e.Y, newName);
                        StateFiniteAutomata state1 = new StateFiniteAutomata(tempNode);
                        tempNode.NodeState = state1;
                        mainAutomate.AddState(state1);
                        listView2.Items.Add(state1.Name);

                    }
                    break;
                case 3:
                    {
                        string newName = default_state_name + currentStateNumber;
                        currentStateNumber++;
                        Node tempNode = graph.AddAcceptNode(e.X, e.Y, newName);
                        StateFiniteAutomata state1 = new StateFiniteAutomata(tempNode);
                        tempNode.NodeState=state1;
                        mainAutomate.AddAcceptState(state1);
                        listView2.Items.Add("("+state1.Name+")");
                    }
                    break;
                case 4:
                    {
                        if (selectState == 0)
                        {
                            if(graph.SelectBeginNode(e.X, e.Y))
                                selectState = 1;
                        }
                        else if(selectState==1)
                        {
                            Node [] twoNodes=graph.AddEdgeToPosition(e.X, e.Y,DEFAULT_CHAR);
                            if (twoNodes!=null)
                            {
                                if (mainAutomate.InnerAlphabet.AddToAlphabet(DEFAULT_CHAR))
                                    listView1.Items.Add(DEFAULT_CHAR.ToString());
                                StateCharPair spair = new StateCharPair(twoNodes[0].NodeState, DEFAULT_CHAR);
                                mainAutomate.OpFunction.AddElement(spair, twoNodes[1].NodeState);
                                addToFunctionView(twoNodes[0].Name, DEFAULT_CHAR, twoNodes[1].Name);
                                graph.ClearSelection();
                                selectState = 0;
                            }
                        }

                    }
                    break;

            }
            this.listView2.Refresh();
            this.pictureBox1.Refresh();
        }
 public bool InnerSimulation(string nap)
 {
     this.ActivateAutomate();
        StateFiniteAutomata nextSt;
        StringBuilder sBuild=new StringBuilder(nap);
        char nextChar = 'a';
        while (sBuild.Length > 0)
        {
        nextChar = sBuild[0];
        sBuild.Remove(0, 1);
        nextSt = operationFunction.GetNextState(currentState, nextChar);
        if (nextSt == null) return false;
        currentState = nextSt;
        }
        if (this.IsInAcceptedState()) return true;
        return false;
 }
 public StateCharPair(StateFiniteAutomata state, Char c)
 {
     singleChar = c;
     currentState = state;
 }
 public void AddState(StateFiniteAutomata s)
 {
     states.Add(s);
 }
 public void AddStartState(StateFiniteAutomata s)
 {
     this.startState = s;
        this.AddState(s);
 }
 public void AddAcceptState(StateFiniteAutomata s)
 {
     this.acceptStates.Add(s.Name,s);
        this.AddState(s);
 }
 public void ActivateAutomate()
 {
     currentState = startState;
 }
 public StateFiniteAutomata NextOperation(char c)
 {
     StateFiniteAutomata nextSt = operationFunction.GetNextState(currentState,c);
        currentState = nextSt;
        return nextSt;
 }