Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/07/11 13:31:42 (12 years ago)
Author:
mkommend
Message:

#1479: Corrected behavior of the grammar editor during the execution of algorithm.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarAllowedChildSymbolsControl.cs

    r7018 r7148  
    6666    private void RegisterGrammarEvents() {
    6767      grammar.Changed += new EventHandler(Grammar_Changed);
     68      grammar.ReadOnlyChanged += new EventHandler(Grammar_ReadOnlyChanged);
    6869    }
    6970    private void DeregisterGrammarEvents() {
    7071      grammar.Changed -= new EventHandler(Grammar_Changed);
     72      grammar.ReadOnlyChanged -= new EventHandler(Grammar_ReadOnlyChanged);
    7173    }
    7274
     
    7880    }
    7981
     82    private void Grammar_ReadOnlyChanged(object sender, EventArgs e) {
     83      if (InvokeRequired) Invoke((MethodInvoker)BuildAllowedChildSymbolsTree);
     84      else BuildAllowedChildSymbolsTree();
     85    }
     86
    8087    private void OnGrammarChanged() {
    8188      if (Grammar == null) {
     
    9097
    9198    private void BuildAllowedChildSymbolsTree() {
     99      if (Symbol == null) {
     100        symbolicExpressionTreeChart.Tree = null;
     101        return;
     102      }
     103
    92104      var tree = new SymbolicExpressionTree(new SymbolicExpressionTreeNode(Symbol));
    93 
    94105      symbolicExpressionTreeChart.SuspendRepaint = true;
    95106      if (Grammar.GetMaximumSubtreeCount(Symbol) > 0) {
     
    146157
    147158    private void symbolicExpressionTreeChart_SymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
     159      if (Grammar.ReadOnly) return;
    148160      if ((Control.ModifierKeys & Keys.Control) == 0)
    149161        selectedSymbolicExpressionTreeNodes.Clear();
     
    162174
    163175    private void symbolicExpressionTreeChart_KeyDown(object sender, KeyEventArgs e) {
     176      if (Grammar.ReadOnly) return;
    164177      if (e.KeyCode == Keys.Delete) {
    165178        var root = symbolicExpressionTreeChart.Tree.Root;
     
    179192    private void symbolicExpressionTreeChart_DragEnter(object sender, DragEventArgs e) {
    180193      validDragOperation = false;
     194      if (Grammar.ReadOnly) return;
     195
    181196      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
    182197      var symbol = data as ISymbol;
     
    258273          decreaseMaximumSubtreeCountRectangle = new RectangleF(visualRootNode.X + visualRootNode.Width + spacing, visualRootNode.Y + size + 2 * spacing, size, size);
    259274
    260           pen.Color = Grammar.GetMaximumSubtreeCount(rootNode.Symbol) == Grammar.GetMinimumSubtreeCount(rootNode.Symbol) ? Color.LightGray : Color.Black;
     275          pen.Color = Grammar.ReadOnly || Grammar.GetMaximumSubtreeCount(rootNode.Symbol) == Grammar.GetMinimumSubtreeCount(rootNode.Symbol) ? Color.LightGray : Color.Black;
    261276          graphics.DrawString("+", font, pen.Brush, increaseMinimumSubtreeCountRectangle, stringFormat);
    262277          graphics.DrawRectangle(pen, Rectangle.Round(increaseMinimumSubtreeCountRectangle));
    263278          if (pen.Color == Color.LightGray) increaseMinimumSubtreeCountRectangle = RectangleF.Empty;
    264279
    265           pen.Color = Grammar.GetMinimumSubtreeCount(rootNode.Symbol) == rootNode.Symbol.MinimumArity ? Color.LightGray : Color.Black;
     280          pen.Color = Grammar.ReadOnly || Grammar.GetMinimumSubtreeCount(rootNode.Symbol) == rootNode.Symbol.MinimumArity ? Color.LightGray : Color.Black;
    266281          graphics.DrawString("-", font, pen.Brush, decreaseMinimumSubtreeCountRectangle, stringFormat);
    267282          graphics.DrawRectangle(pen, Rectangle.Round(decreaseMinimumSubtreeCountRectangle));
    268283          if (pen.Color == Color.LightGray) decreaseMinimumSubtreeCountRectangle = RectangleF.Empty;
    269284
    270           pen.Color = Grammar.GetMaximumSubtreeCount(rootNode.Symbol) == rootNode.Symbol.MaximumArity ? Color.LightGray : Color.Black;
     285          pen.Color = Grammar.ReadOnly || Grammar.GetMaximumSubtreeCount(rootNode.Symbol) == rootNode.Symbol.MaximumArity ? Color.LightGray : Color.Black;
    271286          graphics.DrawRectangle(pen, Rectangle.Round(increaseMaximumSubtreeCountRectangle));
    272287          graphics.DrawString("+", font, pen.Brush, increaseMaximumSubtreeCountRectangle, stringFormat);
    273288          if (pen.Color == Color.LightGray) increaseMaximumSubtreeCountRectangle = RectangleF.Empty;
    274289
    275           pen.Color = Grammar.GetMaximumSubtreeCount(rootNode.Symbol) == Grammar.GetMinimumSubtreeCount(rootNode.Symbol) ? Color.LightGray : Color.Black;
     290          pen.Color = Grammar.ReadOnly || Grammar.GetMaximumSubtreeCount(rootNode.Symbol) == Grammar.GetMinimumSubtreeCount(rootNode.Symbol) ? Color.LightGray : Color.Black;
    276291          graphics.DrawRectangle(pen, Rectangle.Round(decreaseMaximumSubtreeCountRectangle));
    277292          graphics.DrawString("-", font, pen.Brush, decreaseMaximumSubtreeCountRectangle, stringFormat);
     
    282297
    283298    private void allowedChildSymbolsControl_MouseDown(object sender, MouseEventArgs e) {
    284       if (Grammar == null) return;
     299      if (Grammar == null || Grammar.ReadOnly) return;
    285300      if (symbolicExpressionTreeChart.Tree == null) return;
    286301
Note: See TracChangeset for help on using the changeset viewer.