Changeset 14834 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/ExpressionSelectionView.cs
- Timestamp:
- 04/10/17 00:27:31 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/ExpressionSelectionView.cs
r14777 r14834 19 19 public ExpressionSelectionView() { 20 20 InitializeComponent(); 21 21 22 InitEvents(); 22 23 Name = "Push Expression Selection Editor"; … … 28 29 set 29 30 { 31 if (Content != null) Content.EnabledExpressionsChanged -= EnabledExpressionsChanged; 30 32 base.Content = value; 31 33 } … … 35 37 base.OnReadOnlyChanged(); 36 38 37 this.expressionsTreeView.Enabled = !ReadOnly;39 expressionsTreeView.Enabled = !ReadOnly; 38 40 } 39 41 40 42 private void InitEvents() { 41 this.expressionsTreeView.AfterCheck += ExpressionsTreeViewAfterCheck;43 expressionsTreeView.AfterCheck += ExpressionsTreeViewAfterCheck; 42 44 } 43 45 44 46 private void ExpressionsTreeViewAfterCheck(object sender, TreeViewEventArgs e) { 45 var isStackNode = e.Node.Tag is StackTypes; 47 if (e.Action == TreeViewAction.Unknown) 48 return; 46 49 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; 57 58 } 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; 63 65 } 66 67 Content.EnabledExpressionsChanged += EnabledExpressionsChanged; 64 68 } 65 69 66 70 protected override void OnContentChanged() { 67 71 expressionsTreeView.Nodes.Clear(); 72 nameTextBox.Text = "Push Expression Selection"; 68 73 69 74 if (Content == null) { … … 71 76 } 72 77 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(); 74 90 75 91 var treeNodes = GetTreeNodes(Content.EnabledExpressions).ToArray(); … … 80 96 foreach (var stackType in ExpressionTable.StackTypeToNamesTable.Keys) { 81 97 var stackTreeNode = new TreeNode { 82 Tag = stackType, 83 Text = Enum.GetName(typeof(StackTypes), stackType), 98 Tag = stackType 84 99 }; 85 100 86 101 var stackExpressions = ExpressionTable.StackTypeToNamesTable[stackType]; 87 var enabledStackExpressions = enabledExpressions.Intersect( ExpressionTable.StackTypeToNamesTable[stackType]);102 var enabledStackExpressions = enabledExpressions.Intersect(stackExpressions).ToList(); 88 103 104 SetStackNodeText(stackTreeNode); 89 105 stackTreeNode.Checked = enabledStackExpressions.Any(); 90 106 … … 93 109 .Select(name => new TreeNode { 94 110 Text = name, 111 Tag = stackType, 95 112 Checked = enabledStackExpressions.Contains(name), 96 113 }).ToArray(); … … 101 118 } 102 119 } 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 } 103 132 } 104 133 }
Note: See TracChangeset
for help on using the changeset viewer.