Exemplo n.º 1
0
        private void btnPdaClear_Click(object sender, RoutedEventArgs e)
        {
            if (canvasMain.Children.Count == 0)
            {
                return;
            }
            else
            {
                if (MessageBox.Show("Are you sure to clear the Page", "Clear?", MessageBoxButton.YesNo) == MessageBoxResult.No)
                {
                    return;
                }
            }

            grpPdaStateOptions.IsEnabled = false;
            btnPdaInitial.IsChecked      = btnPdaFinal.IsChecked = false;

            Pda newPda = null;

            switch (pdaType)
            {
            case pdaTypes.DPDA:
                newPda = new DPda();
                break;

            case pdaTypes.NDPDA:
                newPda = new NDPda();
                break;
            }

            if (newPda != null)
            {
                newPda.inputs       = pda.inputs;
                newPda.stackSymbols = pda.stackSymbols;

                canvasMain.Children.Clear();
                newPda.setCanvas(canvasMain, btnDelSelection, btnInitial, btnFinal);
                pda = newPda;
                pda.addNewRow();
            }
        }
Exemplo n.º 2
0
        public void newMachine(machines type, TransitionDiagram newDiagram = null)
        {
            if (newDiagram != null) // don't clear the canvas, i.e. we are only updating the interface on conversions etc
            {
                ;
            }
            else
            {
                if (saveOnNewOrExit() == MessageBoxResult.Cancel)
                {
                    return;
                }

                fileStatus.isEdited = false;
                loadedFilePath      = "";

                grammar = null;
                pda     = null;

                mode = modes.Machines;
                GrammarTab.Visibility = pdaTab.Visibility = Visibility.Collapsed;

                transitionDiagramTab.Visibility = Visibility.Visible;
                ExecuteTab.Visibility           = Visibility.Visible;
                ribbonMain.Visibility           = Visibility.Visible;
                transitionDiagramTab.IsSelected = true;

                clearAllTextBoxes();
            }

            //restore original settings

            btnFinal.IsChecked    = btnInitial.IsChecked = false;
            btnAddState.IsChecked = btnAddTrans.IsChecked = btnSelect.IsChecked = false;
            btnNull.IsChecked     = false;

            grpSymbols.IsEnabled   = false;
            grpToolbox.IsEnabled   = false;
            grpSelection.IsEnabled = false;

            btnStatistics.IsEnabled = false;

            grpStateOptions.IsEnabled = false;
            btnFinal.IsEnabled        = true;// disabled in turing, moore, mealy

            grpTransOptions.IsEnabled = false;

            grpStringAcceptance.Visibility = Visibility.Collapsed;
            grpOutputProducer.Visibility   = Visibility.Collapsed;

            btnNull.IsEnabled = false;


            //because they are changed in turing machine interface
            txtInput.Width = txtOutput.Width = 155;

            lblInput.Content  = "Input   "; //changed to input tape in turnig
            lblOutput.Content = "Output";   //changed to output tape in turnig

            grpDfaOptions.Visibility = grpNfaOptions.Visibility = grpMooreMealyOptions.Visibility = Visibility.Collapsed;

            switch (type)
            {
            case machines.Dfa:

                machine = machines.Dfa;
                if (newDiagram == null)
                {
                    newDiagram = new DfaTransitionDiagram();
                }

                diagram = newDiagram;

                spInputSymbols.IsEnabled  = true;
                spOutputSymbols.IsEnabled = false;

                grpDfaOptions.Visibility             = Visibility.Visible;
                grpStringAcceptance.Visibility       = Visibility.Visible;
                Application.Current.MainWindow.Title = "DFA";
                break;

            case machines.Nfa:
                machine = machines.Nfa;

                if (newDiagram == null)
                {
                    newDiagram = new NfaTransitionDiagram();
                }

                diagram = newDiagram;

                btnNullClosure.IsEnabled = false;    // to be enabled on state selection

                spInputSymbols.IsEnabled  = true;
                spOutputSymbols.IsEnabled = false;
                btnNull.IsEnabled         = true;


                grpNfaOptions.Visibility             = Visibility.Visible;
                grpStringAcceptance.Visibility       = Visibility.Visible;
                Application.Current.MainWindow.Title = "NFA";
                break;

            case machines.Moore:
                machine = machines.Moore;

                if (newDiagram == null)
                {
                    newDiagram = new MooreTransitionDiagram();
                }

                diagram = newDiagram;

                spInputSymbols.IsEnabled  = true;
                spOutputSymbols.IsEnabled = true;
                btnFinal.IsEnabled        = false;

                grpMooreMealyOptions.Visibility = Visibility.Visible;
                btnConvertToMoore.Visibility    = Visibility.Collapsed;
                btnConvertToMealy.Visibility    = Visibility.Visible;

                grpMooreMealyOptions.Header = "Moore Options";

                grpOutputProducer.Visibility         = Visibility.Visible;
                Application.Current.MainWindow.Title = "Moore Machine";
                break;

            case machines.Mealy:
                machine = machines.Mealy;

                if (newDiagram == null)
                {
                    newDiagram = new MealyTransitionDiagram();
                }

                diagram = newDiagram;

                spInputSymbols.IsEnabled  = true;
                spOutputSymbols.IsEnabled = true;
                btnFinal.IsEnabled        = false;

                grpMooreMealyOptions.Visibility = Visibility.Visible;
                btnConvertToMoore.Visibility    = Visibility.Visible;
                btnConvertToMealy.Visibility    = Visibility.Collapsed;
                grpMooreMealyOptions.Header     = "Mealy Options";

                grpOutputProducer.Visibility         = Visibility.Visible;
                Application.Current.MainWindow.Title = "Mealy Machine";
                break;

            case machines.Turing:
                machine = machines.Turing;

                if (newDiagram == null)
                {
                    newDiagram = new TuringTransitionDiagram();
                }

                diagram = newDiagram;

                lblInput.Content  = "Input Tape   ";
                lblOutput.Content = "Output Tape";

                spInputSymbols.IsEnabled  = true;
                spOutputSymbols.IsEnabled = false;
                btnFinal.IsEnabled        = false;

                grpOutputProducer.Visibility = Visibility.Visible;
                txtInput.Width = txtOutput.Width = 500;
                Application.Current.MainWindow.Title = "Turing Machine";
                break;

            case machines.None:
                return;     // deselected above
            }



            //enable common options
            grpSymbols.IsEnabled    = true;
            grpToolbox.IsEnabled    = true;
            grpSelection.IsEnabled  = true;
            btnStatistics.IsEnabled = true;
            btnAddTrans.IsEnabled   = false;

            State.resetLabels();

            btnOk.IsEnabled = true;
            diagram.setCanvas(canvasMain);

            btnAddState.IsChecked = true;
            btnAddState_Click(btnAddState, null); // to set the mode as addState
        }