Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/10/17 00:27:31 (8 years ago)
Author:
pkimmesw
Message:

#2665 LexicaseSelector, Performance improvements, UI Fixes, Debugger only shows used stacks, fixed Debugger stepping, Added vector expressions, ERCOptions,

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/ExpressionSelectionView.cs

    r14777 r14834  
    1919    public ExpressionSelectionView() {
    2020      InitializeComponent();
     21
    2122      InitEvents();
    2223      Name = "Push Expression Selection Editor";
     
    2829      set
    2930      {
     31        if (Content != null) Content.EnabledExpressionsChanged -= EnabledExpressionsChanged;
    3032        base.Content = value;
    3133      }
     
    3537      base.OnReadOnlyChanged();
    3638
    37       this.expressionsTreeView.Enabled = !ReadOnly;
     39      expressionsTreeView.Enabled = !ReadOnly;
    3840    }
    3941
    4042    private void InitEvents() {
    41       this.expressionsTreeView.AfterCheck += ExpressionsTreeViewAfterCheck;
     43      expressionsTreeView.AfterCheck += ExpressionsTreeViewAfterCheck;
    4244    }
    4345
    4446    private void ExpressionsTreeViewAfterCheck(object sender, TreeViewEventArgs e) {
    45       var isStackNode = e.Node.Tag is StackTypes;
     47      if (e.Action == TreeViewAction.Unknown)
     48        return;
    4649
    47       if (isStackNode) {
    48         if (e.Node.Checked) {
    49           Content.EnableStack((StackTypes)e.Node.Tag);
    50           foreach (var subNode in e.Node.Nodes.Cast<TreeNode>())
    51             subNode.Checked = true;
    52         } else {
    53           Content.DisableStack((StackTypes)e.Node.Tag);
    54           foreach (var subNode in e.Node.Nodes.Cast<TreeNode>())
    55             subNode.Checked = false;
    56         }
     50      Content.EnabledExpressionsChanged -= EnabledExpressionsChanged;
     51      var stackType = (StackTypes)e.Node.Tag;
     52
     53      if (e.Node.Parent == null) {
     54        Content.SetStack(stackType, e.Node.Checked, true);
     55        SetStackNodeText(e.Node);
     56        foreach (var subNode in e.Node.Nodes.OfType<TreeNode>().Where(n => n.Checked != e.Node.Checked))
     57          subNode.Checked = e.Node.Checked;
    5758      } else {
    58         if (e.Node.Checked) {
    59           Content.EnableExpression(e.Node.Text);
    60         } else {
    61           Content.DisableExpression(e.Node.Text);
    62         }
     59        Content.SetExpression(e.Node.Text, e.Node.Checked, true);
     60        SetStackNodeText(e.Node.Parent);
     61
     62        if ((e.Node.Checked && !e.Node.Parent.Checked) ||
     63            (!e.Node.Checked && !e.Node.Parent.Nodes.OfType<TreeNode>().Any(n => n.Checked)))
     64          e.Node.Parent.Checked = e.Node.Checked;
    6365      }
     66
     67      Content.EnabledExpressionsChanged += EnabledExpressionsChanged;
    6468    }
    6569
    6670    protected override void OnContentChanged() {
    6771      expressionsTreeView.Nodes.Clear();
     72      nameTextBox.Text = "Push Expression Selection";
    6873
    6974      if (Content == null) {
     
    7176      }
    7277
    73       this.nameTextBox.Text = "Push Expression Selection";
     78      Content.EnabledExpressionsChanged += EnabledExpressionsChanged;
     79      var treeNodes = GetTreeNodes(Content.EnabledExpressions).ToArray();
     80      expressionsTreeView.Nodes.AddRange(treeNodes);
     81    }
     82
     83    private void EnabledExpressionsChanged(object sender, EnabledExpressionsChangedEventArgs e) {
     84      if (InvokeRequired) Invoke(new MethodInvoker(UpdateNodes));
     85      else UpdateNodes();
     86    }
     87
     88    private void UpdateNodes() {
     89      expressionsTreeView.Nodes.Clear();
    7490
    7591      var treeNodes = GetTreeNodes(Content.EnabledExpressions).ToArray();
     
    8096      foreach (var stackType in ExpressionTable.StackTypeToNamesTable.Keys) {
    8197        var stackTreeNode = new TreeNode {
    82           Tag = stackType,
    83           Text = Enum.GetName(typeof(StackTypes), stackType),
     98          Tag = stackType
    8499        };
    85100
    86101        var stackExpressions = ExpressionTable.StackTypeToNamesTable[stackType];
    87         var enabledStackExpressions = enabledExpressions.Intersect(ExpressionTable.StackTypeToNamesTable[stackType]);
     102        var enabledStackExpressions = enabledExpressions.Intersect(stackExpressions).ToList();
    88103
     104        SetStackNodeText(stackTreeNode);
    89105        stackTreeNode.Checked = enabledStackExpressions.Any();
    90106
     
    93109          .Select(name => new TreeNode {
    94110            Text = name,
     111            Tag = stackType,
    95112            Checked = enabledStackExpressions.Contains(name),
    96113          }).ToArray();
     
    101118      }
    102119    }
     120
     121    private void SetStackNodeText(TreeNode node) {
     122      var stackType = (StackTypes)node.Tag;
     123      var stackExpressions = ExpressionTable.StackTypeToNamesTable[stackType];
     124      var enabledStackExpressions = Content.EnabledExpressions.Intersect(stackExpressions).ToList();
     125
     126      node.Text = string.Format(
     127                "{0} ({1}/{2})",
     128                Enum.GetName(typeof(StackTypes), stackType),
     129                enabledStackExpressions.Count,
     130                ExpressionTable.StackTypeToNamesTable[stackType].Count);
     131    }
    103132  }
    104133}
Note: See TracChangeset for help on using the changeset viewer.