예제 #1
0
        private void buttonLoadFromFile_Click(object sender, EventArgs e)
        {
            string         path = String.Empty;
            OpenFileDialog ofd  = new OpenFileDialog();

            ofd.Filter = "automatData Files (*.dat)|*.dat";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                path = ofd.FileName;
            }
            else
            {
                return;
            }

            Stream          stream = File.Open(path, FileMode.Open);
            BinaryFormatter bf     = new BinaryFormatter();

            automat = (Automat)bf.Deserialize(stream);
            stream.Close();

            Multiset  = automat.inputMultiset;
            States    = automat.states;
            Functions = automat.function;

            textBoxFunkce.Clear();
            textBoxPrvky.Clear();
            textBoxStavy.Clear();

            foreach (var v in Multiset)
            {
                textBoxPrvky.Text += v.Key + "\t" + "-" + "\t" + v.Value + Environment.NewLine;
                comboBoxFunctionSymbol.Items.Add(v.Key);
            }
            foreach (State state in States)
            {
                textBoxStavy.Text += state.ToString() + "\t";
                if (state.IsInitial())
                {
                    textBoxStavy.Text += "POČÁTEČNÍ" + "\t";
                }
                else
                {
                    textBoxStavy.Text += "\t" + "\t";
                }

                if (state.IsEnd())
                {
                    textBoxStavy.Text += "KONCOVÝ" + "\t";
                }
                else
                {
                    textBoxStavy.Text += "\t" + "\t";
                }

                textBoxStavy.Text += Environment.NewLine;
                comboBoxActualState.Items.Add(state);
                comboBoxNextState.Items.Add(state);
            }

            int i        = 0;
            int nejvyssi = 1;

            foreach (Transition function in Functions)
            {
                if (function.number > nejvyssi)
                {
                    nejvyssi = function.number;
                }
                textBoxFunkce.Text += function.ToString() + "\t" + "\t";
                i++;
                if (i == 3)
                {
                    textBoxFunkce.Text += Environment.NewLine;

                    i = 0;
                }
            }
            pocetPrechodu = nejvyssi + 1;
            SaveAutomat();
        }
예제 #2
0
        /// <summary>
        /// Save automat from input page into object
        /// </summary>
        private void SaveAutomat()
        {
            dataGridViewFunkce.Rows.Clear();
            dataGridViewStavy.Rows.Clear();
            dataGridViewMultiset.Rows.Clear();
            dataGridViewFunkce2.Rows.Clear();
            dataGridViewStavy2.Rows.Clear();
            dataGridViewMultiset2.Rows.Clear();

            State initialState = null;
            State endState     = null;

            foreach (State st in States)
            {
                if (st.IsInitial())
                {
                    initialState = st;
                }
                if (st.IsEnd())
                {
                    endState = st;
                }
            }

            if (initialState == null && endState == null)
            {
                MessageBox.Show("Automat nemá koncový, nebo počáteční stav");
                return;
            }

            if (Functions.Count == 0)
            {
                MessageBox.Show("Neni zadana zadna prechodova funkce");
                return;
            }
            automat = new Automat(Multiset, States, Functions);

            textBoxInputMultiset.Clear();
            textBoxInputMultiset2.Clear();
            int i = 0;

            foreach (var v in Multiset)
            {
                i++;
                textBoxInputMultiset.Text  += v.Key + "  " + "-" + "  " + v.Value + "\t";
                textBoxInputMultiset2.Text += v.Key + "  " + "-" + "  " + v.Value + "\t";
                if (i == 10)
                {
                    textBoxInputMultiset.Text  += Environment.NewLine;
                    textBoxInputMultiset2.Text += Environment.NewLine;
                    i = 0;
                }
                dataGridViewMultiset.Rows.Add(v.Key, v.Value);
                dataGridViewMultiset2.Rows.Add(v.Key, v.Value);
            }

            bool koncovy;
            int  radek = 0;

            foreach (State state in States)
            {
                koncovy = false;
                if (state.IsEnd())
                {
                    koncovy = true;
                }
                dataGridViewStavy.Rows.Add(state.ToString(), koncovy);
                dataGridViewStavy2.Rows.Add(state.ToString(), koncovy);

                if (state.IsInitial())
                {
                    dataGridViewStavy.Rows[radek].DefaultCellStyle.BackColor  = Color.LimeGreen;
                    dataGridViewStavy2.Rows[radek].DefaultCellStyle.BackColor = Color.LimeGreen;
                }
                radek++;
            }

            foreach (Transition function in Functions)
            {
                dataGridViewFunkce.Rows.Add(function.actualState.ToString(), function.symbol, function.nextState.ToString());
                dataGridViewFunkce2.Rows.Add(function.actualState.ToString(), function.symbol, function.nextState.ToString());
            }

            toolStripStatusLabelStateLine.Text = "Automat byl uložen!";
        }