Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7148


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

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

Location:
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4
Files:
3 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
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarEditorView.Designer.cs

    r6803 r7148  
    162162      this.symbolsTreeView.TabIndex = 0;
    163163      this.symbolsTreeView.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.symbolsTreeView_AfterCheck);
     164      this.symbolsTreeView.BeforeCheck += new System.Windows.Forms.TreeViewCancelEventHandler(symbolsTreeView_BeforeCheck);
    164165      this.symbolsTreeView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.symbolsTreeView_ItemDrag);
    165166      this.symbolsTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.symbolsTreeView_AfterSelect);
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarEditorView.cs

    r7018 r7148  
    5454    }
    5555
     56    private Color treeViewBackColor = Color.Empty;
    5657    protected override void SetEnabledStateOfControls() {
    5758      base.SetEnabledStateOfControls();
    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);
     59      if (Content == null || Content.ReadOnly || ReadOnly || Locked) {
     60        addButton.Enabled = false;
     61        removeButton.Enabled = false;
     62        copyButton.Enabled = false;
     63        treeViewBackColor = symbolsTreeView.BackColor;
     64        symbolsTreeView.BackColor = Color.FromArgb(255,240,240,240);
     65      } else {
     66        addButton.Enabled = true;
     67        if (symbolsTreeView.SelectedNode != null && !(symbolsTreeView.SelectedNode.Tag is IReadOnlySymbol)) {
     68          removeButton.Enabled = true;
     69          copyButton.Enabled = true;
     70        }
     71        treeViewBackColor = Color.Empty;
     72        symbolsTreeView.BackColor = treeViewBackColor;
     73      }
    6174    }
    6275
     
    112125    #endregion
    113126
     127    private bool internalTreeViewUpdateInProgress = false;
    114128    private void UpdateSymbolsTreeView() {
     129      internalTreeViewUpdateInProgress = true;
    115130      var symbols = Content.Symbols.ToList();
    116131      foreach (var treeNode in IterateTreeNodes().ToList()) {
     
    125140
    126141      RebuildImageList();
     142      internalTreeViewUpdateInProgress = false;
    127143    }
    128144
     
    148164    private void symbolsTreeView_AfterSelect(object sender, TreeViewEventArgs e) {
    149165      if (e.Action != TreeViewAction.Unknown) UpdateSymbolDetailsViews();
    150 
    151       removeButton.Enabled = symbolsTreeView.SelectedNode != null && !(symbolsTreeView.SelectedNode.Tag is IReadOnlySymbol);
    152       copyButton.Enabled = symbolsTreeView.SelectedNode != null && !(symbolsTreeView.SelectedNode.Tag is IReadOnlySymbol);
     166      SetEnabledStateOfControls();
    153167    }
    154168
     
    164178        Content.FinishedGrammarManipulation();
    165179      }
     180    }
     181
     182    private void symbolsTreeView_BeforeCheck(object sender, TreeViewCancelEventArgs e) {
     183      if (internalTreeViewUpdateInProgress) return;     
     184      if (Content == null || Content.ReadOnly) e.Cancel = true;
     185      if (ReadOnly || Locked) e.Cancel = true;
    166186    }
    167187
     
    183203    private void symbolsTreeView_DragEnter(object sender, DragEventArgs e) {
    184204      validDragOperation = false;
    185       if (Content == null) return;
     205      if (Content == null || Content.ReadOnly || ReadOnly || Locked) return;
    186206
    187207      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     
    230250      Point coordinates = new Point(e.X, e.Y);
    231251      TreeNode node = symbolsTreeView.GetNodeAt(coordinates);
    232       if (e.Button == System.Windows.Forms.MouseButtons.Left && node == null) {
     252      if (e.Button == MouseButtons.Left && node == null) {
    233253        symbolsTreeView.SelectedNode = null;
    234254        symbolDetailsViewHost.Content = null;
     
    238258
    239259    private void symbolsTreeView_KeyDown(object sender, KeyEventArgs e) {
    240       if (ReadOnly) return;
     260      if (Content == null || Content.ReadOnly || ReadOnly || Locked) return;
    241261      if (symbolsTreeView.SelectedNode == null) return;
    242262      if (e.KeyCode != Keys.Delete) return;
Note: See TracChangeset for help on using the changeset viewer.