コード例 #1
0
        public override StackPanel generateLabel(Point p, TransitionDiagram d)
        {
            StackPanel s = new StackPanel();
            ComboBox   cb1 = new ComboBox(), cb2 = new ComboBox(), cb3 = new ComboBox();

            cb1.ItemsSource = d.inputs;
            cb2.ItemsSource = d.inputs;
            cb3.ItemsSource = new string[3] {
                "R", "L", "S"
            };

            cb1.Tag = cb2.Tag = cb3.Tag = this;
            cb1.SelectionChanged += d.onInputChange;
            cb2.SelectionChanged += isEdited;
            cb3.SelectionChanged += isEdited;

            Label lbl1 = new Label(), lbl2 = new Label();

            lbl1.Content = lbl2.Content = "/";

            s.Orientation = Orientation.Horizontal;
            s.Children.Add(cb1);
            s.Children.Add(lbl1);
            s.Children.Add(cb2);
            s.Children.Add(lbl2);
            s.Children.Add(cb3);

            s.SetValue(Canvas.LeftProperty, p.X);
            s.SetValue(Canvas.TopProperty, p.Y);

            return(s);
        }
コード例 #2
0
        private State getStateByToolTip(TransitionDiagram newDiagram, string tip)
        {
            foreach (State s in newDiagram.states)
            {
                if (s.figure.ToolTip.ToString() == tip)
                {
                    return(s);
                }
            }

            return(null);
        }
コード例 #3
0
        private void btnRemoveNullMoves_Click(object sender, RoutedEventArgs e)
        {
            //save a temporary file of the original one and then create a button to view converted one (which is another temp file) and original one

            //string temp = "D:/" + "__temp_" + System.DateTime.Now.Ticks.ToString()+".nfa";

            //diagram.saveToFile(name: temp);

            diagram = ((NfaTransitionDiagram)diagram).removeNullMoves();
            setInterfaceOnMachineLoad();
            fileStatus.isEdited = true;
        }
コード例 #4
0
        private void btnClear_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;
                }
            }

            grpStateOptions.IsEnabled = false;
            grpTransOptions.IsEnabled = false;
            btnInitial.IsChecked      = btnFinal.IsChecked = false;

            TransitionDiagram newDiag = null;

            switch (machine)
            {
            case machines.Dfa:
                newDiag = new DfaTransitionDiagram();
                break;

            case machines.Nfa:
                newDiag = new NfaTransitionDiagram();
                break;

            case machines.Moore:
                newDiag = new MooreTransitionDiagram();
                break;

            case machines.Mealy:
                newDiag = new MealyTransitionDiagram();
                break;

            case machines.Turing:
                newDiag = new TuringTransitionDiagram();
                break;
            }

            if (newDiag != null)
            {
                newDiag.inputs     = diagram.inputs;
                newDiag.noOfInputs = diagram.noOfInputs;
                newDiag.outputs    = diagram.outputs;
                canvasMain.Children.Clear();
                newDiag.setCanvas(canvasMain);
                diagram = newDiag;
            }
        }
コード例 #5
0
        private void btnNfaToDfa_Click(object sender, RoutedEventArgs e)
        {
            if (diagram.isErroneous())
            {
                return;
            }

            canvasMain.Children.Clear(); // to supress the message: canvas not empty

            diagram = ((NfaTransitionDiagram)diagram).convertToDfa();
            newMachine(machines.Dfa, diagram);//update the interface according to DFA
            setInterfaceOnMachineLoad();
            loadedFilePath = "";
        }
コード例 #6
0
        public override StackPanel generateLabel(Point p, TransitionDiagram d)
        {
            StackPanel s  = new StackPanel();
            ComboBox   cb = new ComboBox();

            cb.ItemsSource       = d.inputs;
            cb.Tag               = this;
            cb.SelectionChanged += d.onInputChange;
            s.Children.Add(cb);

            s.SetValue(Canvas.LeftProperty, p.X);
            s.SetValue(Canvas.TopProperty, p.Y);

            return(s);
        }
コード例 #7
0
        private void btnMinimizeDfa_Click(object sender, RoutedEventArgs e)
        {
            if (diagram.isErroneous())
            {
                return;
            }

            DfaTransitionDiagram diagTemp = ((DfaTransitionDiagram)diagram).minimizeStates();

            if (diagTemp != null)//is null on errors
            {
                diagram = diagTemp;
                setInterfaceOnMachineLoad();
                fileStatus.isEdited = true;
            }
        }
コード例 #8
0
        public override StackPanel generateLabel(Point p, TransitionDiagram d)
        {
            StackPanel s     = new StackPanel();
            ComboBox   cb1   = new ComboBox();
            ComboBox   cb2   = new ComboBox();
            Label      slash = new Label();

            //cb1.ItemsSource = d.inputs;
            foreach (string str in d.inputs)
            {
                cb1.Items.Add(str);
            }

            cb1.Tag = this;
            cb1.SelectionChanged += d.onInputChange;
            cb2.SelectionChanged += d.onOutputChange;
            // cb2.ItemsSource = d.outputs;
            foreach (string str in d.outputs)
            {
                cb2.Items.Add(str);
            }
            cb2.Tag       = this;
            cb2.IsEnabled = false;

            slash.Content = "/";



            s.Orientation = Orientation.Horizontal;
            s.Children.Add(cb1);
            s.Children.Add(slash);
            s.Children.Add(cb2);


            s.SetValue(Canvas.LeftProperty, p.X);
            s.SetValue(Canvas.TopProperty, p.Y);

            return(s);
        }
コード例 #9
0
        public override StackPanel generateLabel(Point p, TransitionDiagram d)
        {
            StackPanel s  = new StackPanel();
            ComboBox   cb = new ComboBox();

            //cb.ItemsSource = d.inputs;
            foreach (string str in d.inputs)
            {
                cb.Items.Add(str);
            }

            cb.Tag = this;
            cb.SelectionChanged += d.onInputChange;

            s.Orientation = Orientation.Horizontal;
            s.Children.Add(cb);

            s.SetValue(Canvas.LeftProperty, p.X);
            s.SetValue(Canvas.TopProperty, p.Y);

            return(s);
        }
コード例 #10
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
        }
コード例 #11
0
 public abstract StackPanel generateLabel(Point p, TransitionDiagram d);