Changeset 6299
- Timestamp:
- 05/26/11 15:11:48 (14 years ago)
- Location:
- branches/GP.Grammar.Editor
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolView.Designer.cs
r6109 r6299 47 47 this.initialFrequencyLabel = new System.Windows.Forms.Label(); 48 48 this.initialFrequencyTextBox = new System.Windows.Forms.TextBox(); 49 this.checkBoxEnabled = new System.Windows.Forms.CheckBox(); 49 50 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 50 51 this.SuspendLayout(); … … 73 74 // initialFrequencyTextBox 74 75 // 75 this.initialFrequencyTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 76 76 this.initialFrequencyTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 77 | System.Windows.Forms.AnchorStyles.Right))); 77 78 this.errorProvider.SetIconAlignment(this.initialFrequencyTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft); 78 79 this.initialFrequencyTextBox.Location = new System.Drawing.Point(93, 26); … … 84 85 this.initialFrequencyTextBox.Validated += new System.EventHandler(this.initialFrequencyTextBox_Validated); 85 86 // 87 // checkBoxEnabled 88 // 89 this.checkBoxEnabled.AutoSize = true; 90 this.checkBoxEnabled.Location = new System.Drawing.Point(93, 52); 91 this.checkBoxEnabled.Name = "checkBoxEnabled"; 92 this.checkBoxEnabled.Size = new System.Drawing.Size(65, 17); 93 this.checkBoxEnabled.TabIndex = 5; 94 this.checkBoxEnabled.Text = "Enabled"; 95 this.checkBoxEnabled.UseVisualStyleBackColor = true; 96 this.checkBoxEnabled.CheckedChanged += new System.EventHandler(this.checkBoxEnabled_CheckedChanged); 97 // 86 98 // SymbolView 87 99 // … … 90 102 this.Controls.Add(this.initialFrequencyTextBox); 91 103 this.Controls.Add(this.initialFrequencyLabel); 104 this.Controls.Add(this.checkBoxEnabled); 92 105 this.Name = "SymbolView"; 93 this.Size = new System.Drawing.Size(320, 51); 106 this.Size = new System.Drawing.Size(320, 75); 107 this.Controls.SetChildIndex(this.checkBoxEnabled, 0); 94 108 this.Controls.SetChildIndex(this.initialFrequencyLabel, 0); 95 109 this.Controls.SetChildIndex(this.initialFrequencyTextBox, 0); … … 107 121 protected System.Windows.Forms.Label initialFrequencyLabel; 108 122 protected System.Windows.Forms.TextBox initialFrequencyTextBox; 123 private System.Windows.Forms.CheckBox checkBoxEnabled; 109 124 110 125 } -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolView.cs
r6233 r6299 57 57 protected override void SetEnabledStateOfControls() { 58 58 base.SetEnabledStateOfControls(); 59 initialFrequencyTextBox.Enabled = Content != null ;59 initialFrequencyTextBox.Enabled = Content != null || Locked; 60 60 initialFrequencyTextBox.ReadOnly = ReadOnly; 61 checkBoxEnabled.Enabled = Content != null || Locked || ReadOnly; 61 62 } 62 63 … … 93 94 } 94 95 } 96 97 private void checkBoxEnabled_CheckedChanged(object sender, EventArgs e) { 98 Content.Enabled = checkBoxEnabled.Checked; 99 } 95 100 #endregion 96 101 … … 99 104 if (Content == null) { 100 105 initialFrequencyTextBox.Text = string.Empty; 106 checkBoxEnabled.Checked = false; 101 107 } else { 102 108 initialFrequencyTextBox.Text = Content.InitialFrequency.ToString(); 109 checkBoxEnabled.Checked = Content.Enabled; 103 110 } 104 111 SetEnabledStateOfControls(); 105 112 } 106 113 #endregion 114 107 115 } 108 116 } -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarEditorView.cs
r6285 r6299 100 100 private void RebuildSymbolsTreeView() { 101 101 symbolsTreeView.Nodes.Clear(); 102 var start = new TreeNode(); 103 var symbols = new DummySymbol("Symbols"); 104 start.Name = "Symbols"; 105 start.Text = "Symbols"; 106 start.Tag = symbols; 107 start.Checked = true; 108 symbolsTreeView.Nodes.Add(start); 102 var symbols = Content.Symbols.ToList(); 103 var groupSymbols = symbols.OfType<GroupSymbol>().ToList(); 104 var topLevelSymbols = Content.Symbols.Where(s => !groupSymbols.Any(g => g.Symbols.Contains(s))); 105 AddChildTreeNodes(symbolsTreeView.Nodes, topLevelSymbols); 109 106 110 foreach (ISymbol symbol in Content.Symbols.Where(s => !(s is IReadOnlySymbol))) { 107 RebuildImageList(); 108 symbolsTreeView.ExpandAll(); 109 } 110 111 private void AddChildTreeNodes(TreeNodeCollection collection, IEnumerable<ISymbol> symbols) { 112 foreach (ISymbol symbol in symbols) { 111 113 var node = new TreeNode(); 112 114 node.Name = symbol.Name; 113 115 node.Text = symbol.Name; 114 116 node.Tag = symbol; 115 node.Checked = !symbol.InitialFrequency.IsAlmost(0.0); 116 start.Nodes.Add(node); 117 node.Checked = symbol.Enabled; 118 collection.Add(node); 119 var groupSymbol = symbol as GroupSymbol; 120 if (groupSymbol != null) AddChildTreeNodes(node.Nodes, groupSymbol.Symbols); 117 121 } 118 RebuildImageList();119 symbolsTreeView.ExpandAll();120 122 } 121 123 … … 134 136 if (e.Action != TreeViewAction.Unknown) { 135 137 DeregisterContentEvents(); 136 foreach (var symbol in IterateTreeNodes(e.Node).Select(n => n.Tag).OfType<ISymbol>()) { 137 if (e.Node.Checked) symbol.InitialFrequency = 1.0; 138 else symbol.InitialFrequency = 0.0; 139 } 138 var symbol = (ISymbol)e.Node.Tag; 139 symbol.Enabled = e.Node.Checked; 140 140 RegisterContentEvents(); 141 141 Content_Changed(Content, EventArgs.Empty); … … 176 176 protected virtual void RebuildImageList() { 177 177 symbolsTreeView.ImageList.Images.Clear(); 178 foreach (TreeNode treeNode in symbolsTreeView.Nodes) {178 foreach (TreeNode treeNode in IterateTreeNodes()) { 179 179 var symbol = (ISymbol)treeNode.Tag; 180 180 symbolsTreeView.ImageList.Images.Add(symbol == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : symbol.ItemImage); … … 183 183 } 184 184 } 185 #endregion 185 186 186 187 [NonDiscoverableType] … … 190 191 public override IDeepCloneable Clone(Cloner cloner) { return new DummySymbol(this, cloner); } 191 192 } 192 193 #endregion194 193 } -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarView.cs
r6233 r6299 90 90 if (!(symbol is IReadOnlySymbol)) { 91 91 symbol.Changed += new EventHandler(symbol_Changed); 92 symbols.Add(symbol, symbol. InitialFrequency > 0.0);92 symbols.Add(symbol, symbol.Enabled); 93 93 } 94 94 } … … 101 101 private void symbol_Changed(object sender, EventArgs e) { 102 102 ISymbol symbol = (ISymbol)sender; 103 symbols.SetItemCheckedState(symbol, symbol. InitialFrequency > 0.0);103 symbols.SetItemCheckedState(symbol, symbol.Enabled); 104 104 } 105 105 106 106 private void symbols_CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbol>> e) { 107 107 ICheckedItemList<ISymbol> checkedItemList = (ICheckedItemList<ISymbol>)sender; 108 foreach (var indexedItem in e.Items) { 109 if (checkedItemList.ItemChecked(indexedItem.Value)) { 110 indexedItem.Value.InitialFrequency = 1.0; 111 } else { 112 indexedItem.Value.InitialFrequency = 0.0; 113 } 114 } 108 foreach (var indexedItem in e.Items) 109 indexedItem.Value.Enabled = checkedItemList.ItemChecked(indexedItem.Value); 115 110 } 116 111 private void ClearSymbols() { -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs
r6296 r6299 130 130 #region protected grammar manipulation methods 131 131 protected void AddSymbol(ISymbol symbol) { 132 AddSymbolToDictionaries(symbol); 133 var groupSymbol = symbol as GroupSymbol; 134 if (groupSymbol != null) { 135 foreach (ISymbol s in groupSymbol.Flatten()) 136 AddSymbolToDictionaries(s); 137 } 138 139 ClearCaches(); 140 OnChanged(); 141 } 142 private void AddSymbolToDictionaries(ISymbol symbol) { 132 143 symbols.Add(symbol.Name, symbol); 133 144 symbolSubtreeCount.Add(symbol.Name, Tuple.Create(0, 0)); 134 145 RegisterSymbolEvents(symbol); 135 146 } 147 148 protected void RemoveSymbol(ISymbol symbol) { 149 RemoveSymbolFromDictionaries(symbol); 136 150 var groupSymbol = symbol as GroupSymbol; 137 if (groupSymbol != null) AddSymbol(groupSymbol); 151 if (groupSymbol != null) { 152 foreach (ISymbol s in groupSymbol.Flatten()) 153 RemoveSymbolFromDictionaries(s); 154 } 138 155 139 156 ClearCaches(); 140 157 OnChanged(); 141 158 } 142 143 private void AddSymbol(GroupSymbol groupSymbol) { 144 foreach (ISymbol symbol in groupSymbol.Symbols) { 145 symbols.Add(symbol.Name, symbol); 146 symbolSubtreeCount.Add(symbol.Name, Tuple.Create(0, 0)); 147 RegisterSymbolEvents(symbol); 148 149 var childGroup = symbol as GroupSymbol; 150 if (childGroup != null) AddSymbol(childGroup); 151 } 152 } 153 154 protected void RemoveSymbol(ISymbol symbol) { 159 private void RemoveSymbolFromDictionaries(ISymbol symbol) { 155 160 symbols.Remove(symbol.Name); 156 161 allowedChildSymbols.Remove(symbol.Name); … … 170 175 } 171 176 DeregisterSymbolEvents(symbol); 172 ClearCaches();173 OnChanged();174 177 } 175 178 … … 181 184 182 185 protected void AddAllowedChildSymbol(ISymbol parent, ISymbol child) { 186 List<ISymbol> parents; 187 List<ISymbol> childs; 188 bool changed = false; 189 190 var parentGroup = parent as GroupSymbol; 191 if (parentGroup != null) parents = parentGroup.Flatten().Where(p => !(p is GroupSymbol)).ToList(); 192 else parents = new List<ISymbol>() { parent }; 193 var childGroup = child as GroupSymbol; 194 if (childGroup != null) childs = childGroup.Flatten().Where(c => !(c is GroupSymbol)).ToList(); 195 else childs = new List<ISymbol>() { child }; 196 197 foreach (ISymbol p in parents) { 198 foreach (ISymbol c in childs) { 199 changed |= AddAllowedChildSymbolToDictionaries(p, c); 200 } 201 } 202 203 if (changed) { 204 ClearCaches(); 205 OnChanged(); 206 } 207 } 208 209 private bool AddAllowedChildSymbolToDictionaries(ISymbol parent, ISymbol child) { 210 List<string> childSymbols; 211 if (!allowedChildSymbols.TryGetValue(parent.Name, out childSymbols)) { 212 childSymbols = new List<string>(); 213 allowedChildSymbols.Add(parent.Name, childSymbols); 214 } 215 if (childSymbols.Contains(child.Name)) return false; 216 183 217 suppressEvents = true; 184 218 for (int argumentIndex = 0; argumentIndex < GetMaximumSubtreeCount(parent); argumentIndex++) … … 186 220 suppressEvents = false; 187 221 188 List<string> childSymbols; 189 if (!allowedChildSymbols.TryGetValue(parent.Name, out childSymbols)) { 190 childSymbols = new List<string>(); 191 allowedChildSymbols.Add(parent.Name, childSymbols); 192 } 193 194 if (!childSymbols.Contains(child.Name)) { 195 childSymbols.Add(child.Name); 222 childSymbols.Add(child.Name); 223 return true; 224 } 225 226 protected void AddAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) { 227 List<ISymbol> parents; 228 List<ISymbol> childs; 229 bool changed = false; 230 231 var parentGroup = parent as GroupSymbol; 232 if (parentGroup != null) parents = parentGroup.Flatten().Where(p => !(p is GroupSymbol)).ToList(); 233 else parents = new List<ISymbol>() { parent }; 234 var childGroup = child as GroupSymbol; 235 if (childGroup != null) childs = childGroup.Flatten().Where(c => !(c is GroupSymbol)).ToList(); 236 else childs = new List<ISymbol>() { child }; 237 238 foreach (ISymbol p in parents) { 239 foreach (ISymbol c in childs) { 240 changed |= AddAllowedChildSymbolToDictionaries(p, c, argumentIndex); 241 } 242 } 243 244 if (changed) { 196 245 ClearCaches(); 197 246 OnChanged(); … … 199 248 } 200 249 201 protected void AddAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) { 250 251 private bool AddAllowedChildSymbolToDictionaries(ISymbol parent, ISymbol child, int argumentIndex) { 202 252 List<string> childSymbols; 203 253 if (allowedChildSymbols.TryGetValue(parent.Name, out childSymbols)) 204 if (childSymbols.Contains(child.Name)) return ;254 if (childSymbols.Contains(child.Name)) return false; 205 255 206 256 var key = Tuple.Create(parent.Name, argumentIndex); … … 209 259 allowedChildSymbolsPerIndex.Add(key, childSymbols); 210 260 } 211 212 if (!childSymbols.Contains(child.Name)) { 213 childSymbols.Add(child.Name); 214 ClearCaches(); 215 OnChanged(); 216 } 261 if (childSymbols.Contains(child.Name)) return false; 262 263 childSymbols.Add(child.Name); 264 return true; 217 265 } 218 266 … … 221 269 List<string> childSymbols; 222 270 if (allowedChildSymbols.TryGetValue(child.Name, out childSymbols)) { 223 if (allowedChildSymbols[parent.Name].Remove(child.Name)) changed = true;271 changed |= childSymbols.Remove(child.Name); 224 272 } 225 273 226 274 for (int argumentIndex = 0; argumentIndex < GetMaximumSubtreeCount(parent); argumentIndex++) { 227 275 var key = Tuple.Create(parent.Name, argumentIndex); 228 if (allowedChildSymbolsPerIndex.TryGetValue(key, out childSymbols)) { 229 if (allowedChildSymbolsPerIndex[key].Remove(child.Name)) changed = true; 230 } 276 if (allowedChildSymbolsPerIndex.TryGetValue(key, out childSymbols)) 277 changed |= childSymbols.Remove(child.Name); 231 278 } 232 279 … … 240 287 bool changed = false; 241 288 289 suppressEvents = true; 242 290 List<string> childSymbols; 243 291 if (allowedChildSymbols.TryGetValue(parent.Name, out childSymbols)) { 244 292 if (childSymbols.Remove(child.Name)) { 245 suppressEvents = true;246 293 for (int i = 0; i < GetMaximumSubtreeCount(parent); i++) { 247 294 if (i != argumentIndex) AddAllowedChildSymbol(parent, child, i); 248 295 } 249 suppressEvents = false;250 296 changed = true; 251 297 } 252 298 } 299 suppressEvents = false; 253 300 254 301 var key = Tuple.Create(parent.Name, argumentIndex); 255 if (allowedChildSymbolsPerIndex.TryGetValue(key, out childSymbols)) { 256 if (allowedChildSymbolsPerIndex[key].Remove(child.Name)) 257 changed = true; 258 } 302 if (allowedChildSymbolsPerIndex.TryGetValue(key, out childSymbols)) 303 changed |= childSymbols.Remove(child.Name); 259 304 260 305 if (changed) { … … 265 310 266 311 protected void SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount) { 312 var groupSymbol = symbol as GroupSymbol; 313 if (groupSymbol != null) 314 foreach (ISymbol s in groupSymbol.Flatten().Where(s => !(s is GroupSymbol))) 315 SetSubTreeCountInDictionaries(s, minimumSubtreeCount, maximumSubtreeCount); 316 else 317 SetSubTreeCountInDictionaries(symbol, minimumSubtreeCount, maximumSubtreeCount); 318 319 ClearCaches(); 320 OnChanged(); 321 } 322 323 private void SetSubTreeCountInDictionaries(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount) { 267 324 for (int i = GetMaximumSubtreeCount(symbol) - 1; i >= maximumSubtreeCount; i--) { 268 325 var key = Tuple.Create(symbol.Name, i); … … 271 328 272 329 symbolSubtreeCount[symbol.Name] = Tuple.Create(minimumSubtreeCount, maximumSubtreeCount); 273 ClearCaches();274 OnChanged();275 330 } 276 331 #endregion … … 291 346 List<string> temp; 292 347 if (allowedChildSymbols.TryGetValue(parent.Name, out temp)) 293 if (temp.Contains(child.Name)) return true;348 return temp.Contains(child.Name); 294 349 return false; 295 350 } -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/GroupSymbol.cs
r6296 r6299 59 59 InitialFrequency = 0.0; 60 60 } 61 62 public IEnumerable<ISymbol> Flatten() { 63 return symbols.Union(symbols.OfType<GroupSymbol>().SelectMany(g => g.Flatten())); 64 } 61 65 } 62 66 } -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/Symbol.cs
r6296 r6299 38 38 if (value != initialFrequency) { 39 39 initialFrequency = value; 40 if (initialFrequency.IsAlmost(0.0)) enabled = false;41 40 OnChanged(EventArgs.Empty); 42 41 }
Note: See TracChangeset
for help on using the changeset viewer.