Changeset 15017 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/PushDebuggerView.cs
- Timestamp:
- 06/01/17 09:28:34 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/PushDebuggerView.cs
r14952 r15017 15 15 16 16 public partial class PushDebuggerView : ItemView { 17 private readonly IDictionary<StackTypes, ListBox> debugControlDict = new Dictionary<StackTypes, ListBox>(); 17 private readonly IDictionary<StackTypes, ListBox> debugListDict = new Dictionary<StackTypes, ListBox>(); 18 private readonly IDictionary<StackTypes, PushProgramTreeView> debugPushProgramDict = new Dictionary<StackTypes, PushProgramTreeView>(); 18 19 19 20 private PooledPushInterpreter interpreter; … … 157 158 158 159 private void ClearDebugLists() { 159 foreach (var list in debug ControlDict.Values) {160 foreach (var list in debugListDict.Values) { 160 161 list.Items.Clear(); 161 162 } 163 164 foreach (var treeView in debugPushProgramDict.Values) { 165 treeView.Nodes.Clear(); 166 } 162 167 } 163 168 164 169 private void UpdateExecList() { 165 execList.Items.Clear(); 166 var expressions = interpreter.ExecStack.AsEnumerable() 167 .Reverse() 168 .Select(e => e.StringRepresentation) 169 .ToArray(); 170 171 execList.Items.AddRange(expressions); 172 execGroupBox.Text = string.Format(GROUP_BOX_TEXT_STRING_FORMAT, Enum.GetName(typeof(StackTypes), StackTypes.Exec), interpreter.ExecStack.Count); 170 execTreeView.LoadExpressions(interpreter.ExecStack.Reverse()); 171 exec2GroupBox.Text = string.Format(GROUP_BOX_TEXT_STRING_FORMAT, Enum.GetName(typeof(StackTypes), StackTypes.Exec), interpreter.ExecStack.Count); 173 172 } 174 173 175 174 private void InitDebugLists(IReadOnlyPushConfiguration config) { 176 debugControlDict.Clear(); 175 debugListDict.Clear(); 176 debugPushProgramDict.Clear(); 177 177 178 178 // 2 = ExecList + EmptyColumn which is required to fill empty space … … 185 185 if (stackType != StackTypes.Exec && 186 186 ExpressionTable.GetExpressionsByStackTypes(stackType).Intersect(config.EnabledExpressions).Any()) { 187 var list = CreateDebugList(stackType); 188 debugControlDict.Add(stackType, list); 187 188 switch (stackType) { 189 case StackTypes.Code: 190 var treeView = CreatePushProgramTreeView(stackType); 191 debugPushProgramDict.Add(stackType, treeView); 192 break; 193 default: 194 var list = CreateDebugList(stackType); 195 debugListDict.Add(stackType, list); 196 break; 197 } 189 198 } 190 199 } 191 200 } 192 201 202 private PushProgramTreeView CreatePushProgramTreeView(StackTypes type) { 203 204 var treeView = new PushProgramTreeView { 205 Dock = DockStyle.Fill 206 }; 207 208 AddStackControlToTableLayout(type, treeView, 400); 209 210 return treeView; 211 } 212 213 private void AddStackControlToTableLayout(StackTypes type, Control control, int width) { 214 var groupBox = CreateStackGroupBox(type); 215 groupBox.Controls.Add(control); 216 217 debugTableLayout.ColumnCount++; 218 debugTableLayout.ColumnStyles.Insert(1, new ColumnStyle(SizeType.Absolute, width)); 219 debugTableLayout.Controls.Add(groupBox); 220 debugTableLayout.Controls.SetChildIndex(groupBox, 1); 221 } 222 193 223 private ListBox CreateDebugList(StackTypes type) { 194 var groupBox = new GroupBox {195 Anchor = AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top,196 AutoSize = true,197 AutoSizeMode = AutoSizeMode.GrowAndShrink,198 Text = Enum.GetName(typeof(StackTypes), type)199 };200 201 224 var list = new ListBox { 202 225 Dock = DockStyle.Fill … … 227 250 } 228 251 229 groupBox.Controls.Add(list); 230 231 var columnWidth = stackEntryType == typeof(Expression) ? 250 : 150; 232 233 debugTableLayout.ColumnCount++; 234 debugTableLayout.ColumnStyles.Insert(1, new ColumnStyle(SizeType.Absolute, columnWidth)); 235 debugTableLayout.Controls.Add(groupBox); 236 debugTableLayout.Controls.SetChildIndex(groupBox, 1); 252 AddStackControlToTableLayout(type, list, 150); 237 253 238 254 return list; 239 255 } 240 256 257 private static GroupBox CreateStackGroupBox(StackTypes type) { 258 return new GroupBox { 259 Anchor = AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top, 260 AutoSize = true, 261 AutoSizeMode = AutoSizeMode.GrowAndShrink, 262 Text = Enum.GetName(typeof(StackTypes), type) 263 }; 264 } 241 265 242 266 private void UpdateDebugLists() { … … 246 270 return; 247 271 248 foreach (var pair in debug ControlDict) {272 foreach (var pair in debugPushProgramDict) { 249 273 var name = Enum.GetName(typeof(StackTypes), pair.Key); 250 var items = InterpreterStackStringifier.StringifyStack(interpreter, pair.Key).ToArray(); 274 var stack = (IPushStack<Expression>)interpreter.Stacks[pair.Key]; 275 276 pair.Value.AddExpressions(stack); 277 ((GroupBox)pair.Value.Parent).Text = string.Format(GROUP_BOX_TEXT_STRING_FORMAT, name, pair.Value.Nodes.Count); 278 } 279 280 foreach (var pair in debugListDict) { 281 var name = Enum.GetName(typeof(StackTypes), pair.Key); 282 var items = interpreter.StringifyStack(pair.Key).ToArray(); 251 283 252 284 pair.Value.Items.AddRange(items);
Note: See TracChangeset
for help on using the changeset viewer.