Ejemplo n.º 1
0
        public RuleControl(Rule aRule)
            : this()
        {
            _rule            = aRule;
            leftName.Content = _rule.Name;

            ControlFactory.CurrentRule = _rule.Name;
            UIElement control = ControlFactory.CreateControl(_rule.RightSide, new List <string>());

            rightPanel.Children.Add(control);
        }
Ejemplo n.º 2
0
        public SeqenceControl(Seqence aSeqence, List <string> aOuterSymbols)
            : this()
        {
            _seqence = aSeqence;

            foreach (IPhrase phrase in _seqence.Phrases)
            {
                UIElement control = ControlFactory.CreateControl(phrase, aOuterSymbols);
                Border    brd     = new Border();
                brd.Child           = control;
                brd.BorderThickness = t;
                brd.BorderBrush     = Brushes.Magenta;
                stackPanel1.Children.Add(brd);
            }
        }
Ejemplo n.º 3
0
        public AlternativeControl(AlternativeSet aAlternativeSet, List <string> aOuterSymbols)
            : this()
        {
            _alternativeSet = aAlternativeSet;

            foreach (IPhrase phrase in _alternativeSet.Phrases)
            {
                Border    brd     = new Border();
                UIElement control = ControlFactory.CreateControl(phrase, aOuterSymbols);
                brd.Child           = control;
                brd.BorderThickness = new Thickness(5);
                if (phrase.IsCyclic)
                {
                    brd.BorderBrush = Brushes.Blue;
                }
                else
                {
                    brd.BorderBrush = Brushes.YellowGreen;
                }
                stackPanel1.Children.Add(brd);
            }
        }
Ejemplo n.º 4
0
        public QuantifierControl(QuantifiedPhrase aQuantifiedPhrase, List <string> aOuterSymbols)
            : this()
        {
            _quantifiedPhrase = aQuantifiedPhrase;

            UIElement control = ControlFactory.CreateControl(_quantifiedPhrase.Phrase, aOuterSymbols);

            quantPanel.Children.Add(control);

            quantLabel.Content = _quantifiedPhrase.QuantSign;
            //if (_quantifiedPhrase.Min == _quantifiedPhrase.Max)
            //{
            //  quantLabel.Content = "{" + _quantifiedPhrase.Max + "}";
            //}
            ////else if (_quantifiedPhrase.Max == Int32.MaxValue)
            ////{
            ////  quantLabel.Content = (_quantifiedPhrase.Min == 1) ? "+" : "*";
            ////}
            //else
            //{
            //  string max = (_quantifiedPhrase.Max == Int32.MaxValue) ? "*" : _quantifiedPhrase.Max.ToString();
            //  quantLabel.Content = "{" + _quantifiedPhrase.Min + ".." + max + "}";
            //}
        }
Ejemplo n.º 5
0
        public NonTerminalControl(NonTerminal aSymbol, List <string> aOuterSymbols)
            : this()
        {
            mDispatcher   = this.Dispatcher;
            _symbol       = aSymbol;
            _outerSymbols = new List <string>(aOuterSymbols);
            if (_outerSymbols.Count > maxDeep)
            {
                maxDeep = _outerSymbols.Count;
                ControlFactory.MainWindow.MaxDeep = maxDeep;
            }

            bool isUsed = ControlFactory.AllUsedSymbols.Contains(aSymbol.Text);

            ControlFactory.AllUsedSymbols.Add(aSymbol.Text);

            ThreadStart nextDelegate = (ThreadStart) delegate()
            {
                MainWindow.AllTrees.Add(treeView);

                TreeViewItem tvi = new TreeViewItem();
                tvi.IsExpanded = MainWindow.DefaultExpand;
                treeView.Items.Add(tvi);


                Button b = new Button();
                b.Content  = _symbol.Text;
                tvi.Header = b;
                if ((_symbol.CycicKind & CycicKind.CyclicPropagated) > 0)
                {
                    b.Foreground = Brushes.Magenta;
                }
                if (_symbol.IsCyclic)
                {
                    b.Foreground = Brushes.Blue;
                }

                if (!_outerSymbols.Contains(_symbol.Text) && _symbol.Text != ControlFactory.CurrentRule)
                {
                    if (isUsed)
                    {
                        // as cycle

                        b.Template = (ControlTemplate)Application.Current.Resources["secondTemplate"];
                        b.Content  = _symbol.Text + " *";
                        b.Click   += new RoutedEventHandler(b_Click);
                    }
                    else
                    {
                        _outerSymbols.Add(_symbol.Text);

                        //No cycle
                        UIElement ui;
                        Dictionary <string, Rule> rules = _symbol.Grammar.Rules;
                        if (rules.ContainsKey(_symbol.Text))
                        {
                            Rule r = rules[_symbol.Text];
                            ui = ControlFactory.CreateControl(r.RightSide, _outerSymbols);
                        }
                        else
                        {
                            Label l = new Label();
                            l.Content = "rule not found!";
                            ui        = l;
                        }
                        TreeViewItem new_tvi = new TreeViewItem();
                        new_tvi.Header = ui;
                        tvi.Items.Add(new_tvi);
                    }
                }
                else
                {
                    //cycle
                    ControlFactory.MainWindow.AllCycles++;
                    if (!diffCycles.Contains(_symbol.Text))
                    {
                        diffCycles.Add(_symbol.Text);
                        ControlFactory.MainWindow.AllDiffCycles = diffCycles.Count;
                    }

                    if (_symbol.Text != ControlFactory.CurrentRule)
                    {
                        b.Template = (ControlTemplate)Application.Current.Resources["cycleTemplate"];
                    }
                    else
                    {
                        b.Template = (ControlTemplate)Application.Current.Resources["selfCycleTemplate"];
                    }
                    b.Content = _symbol.Text + " ^";
                    b.Click  += new RoutedEventHandler(b_Click);
                }
            };

            nextDelegateList.Add(nextDelegate);

            if (!mPause)
            {
                ExecuteDelegates();
            }
        }