Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6622


Ignore:
Timestamp:
08/02/11 12:53:25 (13 years ago)
Author:
mkommend
Message:

#1479: Corrected merging errors in symbolic expression grammars.

Location:
branches/GP.Grammar.Editor
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarEditorView.cs

    r6497 r6622  
    5656    protected override void SetEnabledStateOfControls() {
    5757      base.SetEnabledStateOfControls();
    58       addButton.Enabled = Content != null;
    59       removeButton.Enabled = symbolsTreeView.SelectedNode != null && !(symbolsTreeView.SelectedNode.Tag is IReadOnlySymbol);
    60       copyButton.Enabled = symbolsTreeView.SelectedNode != null && !(symbolsTreeView.SelectedNode.Tag is IReadOnlySymbol);
     58      addButton.Enabled = Content != null && !Content.ReadOnly;
     59      removeButton.Enabled = Content != null && !Content.ReadOnly && symbolsTreeView.SelectedNode != null && !(symbolsTreeView.SelectedNode.Tag is IReadOnlySymbol);
     60      copyButton.Enabled = Content != null && !Content.ReadOnly && symbolsTreeView.SelectedNode != null && !(symbolsTreeView.SelectedNode.Tag is IReadOnlySymbol);
    6161    }
    6262
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammar.cs

    r6620 r6622  
    190190    void ISymbolicExpressionGrammar.AddSymbol(ISymbol symbol) {
    191191      if (ReadOnly) throw new InvalidOperationException();
    192       base.AddSymbol(symbol);
     192      AddSymbol(symbol);
    193193    }
    194194    void ISymbolicExpressionGrammar.RemoveSymbol(ISymbol symbol) {
    195195      if (ReadOnly) throw new InvalidOperationException();
    196       base.RemoveSymbol(symbol);
     196      RemoveSymbol(symbol);
    197197    }
    198198
     
    235235    #region symbol events
    236236    private void RegisterSymbolEvents(ISymbol symbol) {
    237       symbol.NameChanging += new EventHandler<CancelEventArgs<string>>(Symbol_NameChanging);
    238       symbol.NameChanged += new EventHandler(Symbol_NameChanged);
    239 
    240       var groupSymbol = symbol as GroupSymbol;
    241       if (groupSymbol != null) RegisterGroupSymbolEvents(groupSymbol);
    242       else symbol.Changed += new EventHandler(Symbol_Changed);
     237      foreach (var s in symbol.Flatten()) {
     238        s.NameChanging += new EventHandler<CancelEventArgs<string>>(Symbol_NameChanging);
     239        s.NameChanged += new EventHandler(Symbol_NameChanged);
     240
     241        var groupSymbol = s as GroupSymbol;
     242        if (groupSymbol != null) RegisterGroupSymbolEvents(groupSymbol);
     243        else symbol.Changed += new EventHandler(Symbol_Changed);
     244      }
    243245    }
    244246    private void DeregisterSymbolEvents(ISymbol symbol) {
    245       symbol.NameChanging -= new EventHandler<CancelEventArgs<string>>(Symbol_NameChanging);
    246       symbol.NameChanged -= new EventHandler(Symbol_NameChanged);
    247 
    248       var groupSymbol = symbol as GroupSymbol;
    249       if (groupSymbol != null) DeregisterGroupSymbolEvents(groupSymbol);
    250       else symbol.Changed -= new EventHandler(Symbol_Changed);
     247      foreach (var s in symbol.Flatten()) {
     248        s.NameChanging -= new EventHandler<CancelEventArgs<string>>(Symbol_NameChanging);
     249        s.NameChanged -= new EventHandler(Symbol_NameChanged);
     250
     251        var groupSymbol = s as GroupSymbol;
     252        if (groupSymbol != null) DeregisterGroupSymbolEvents(groupSymbol);
     253        else symbol.Changed -= new EventHandler(Symbol_Changed);
     254      }
    251255    }
    252256
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs

    r6620 r6622  
    123123    protected virtual void AddSymbol(ISymbol symbol) {
    124124      if (ContainsSymbol(symbol)) throw new ArgumentException("Symbol " + symbol + " is already defined.");
    125       symbols.Add(symbol.Name, symbol);
    126       symbolSubtreeCount.Add(symbol.Name, Tuple.Create(0, 0));
     125      foreach (var s in symbol.Flatten()) {
     126        symbols.Add(s.Name, s);
     127        symbolSubtreeCount.Add(s.Name, Tuple.Create(s.MinimumArity, s.MaximumArity));
     128      }
    127129      ClearCaches();
    128130    }
    129131
    130132    protected virtual void RemoveSymbol(ISymbol symbol) {
    131       symbols.Remove(symbol.Name);
    132       allowedChildSymbols.Remove(symbol.Name);
    133       for (int i = 0; i < GetMaximumSubtreeCount(symbol); i++)
    134         allowedChildSymbolsPerIndex.Remove(Tuple.Create(symbol.Name, i));
    135       symbolSubtreeCount.Remove(symbol.Name);
    136 
    137       foreach (var parent in Symbols) {
    138         List<string> allowedChilds;
    139         if (allowedChildSymbols.TryGetValue(parent.Name, out allowedChilds))
    140           allowedChilds.Remove(symbol.Name);
    141 
    142         for (int i = 0; i < GetMaximumSubtreeCount(parent); i++) {
    143           if (allowedChildSymbolsPerIndex.TryGetValue(Tuple.Create(parent.Name, i), out allowedChilds))
    144             allowedChilds.Remove(symbol.Name);
     133      foreach (var s in symbol.Flatten()) {
     134        symbols.Remove(s.Name);
     135        allowedChildSymbols.Remove(s.Name);
     136        for (int i = 0; i < GetMaximumSubtreeCount(s); i++)
     137          allowedChildSymbolsPerIndex.Remove(Tuple.Create(s.Name, i));
     138        symbolSubtreeCount.Remove(s.Name);
     139
     140        foreach (var parent in Symbols) {
     141          List<string> allowedChilds;
     142          if (allowedChildSymbols.TryGetValue(parent.Name, out allowedChilds))
     143            allowedChilds.Remove(s.Name);
     144
     145          for (int i = 0; i < GetMaximumSubtreeCount(parent); i++) {
     146            if (allowedChildSymbolsPerIndex.TryGetValue(Tuple.Create(parent.Name, i), out allowedChilds))
     147              allowedChilds.Remove(s.Name);
     148          }
    145149        }
    146150      }
     151      ClearCaches();
    147152    }
    148153
Note: See TracChangeset for help on using the changeset viewer.