Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.DebugEngine/3.3/ExecutionStackView.cs @ 5187

Last change on this file since 5187 was 5146, checked in by epitzer, 14 years ago

(#47)

  • Show a different icon for breakpoints
  • Show an icon for the active operation
File size: 6.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Drawing;
25using System.Linq;
26using System.Windows.Forms;
27using HeuristicLab.Collections;
28using HeuristicLab.Common.Resources;
29using HeuristicLab.Core;
30using HeuristicLab.MainForm;
31using HeuristicLab.MainForm.WindowsForms;
32
33namespace HeuristicLab.DebugEngine {
34
35  [View("Execution Stack View")]
36  [Content(typeof(ExecutionStack), IsDefaultView = true)]
37  public partial class ExecutionStackView : AsynchronousContentView {
38    public new ExecutionStack Content {
39      get { return (ExecutionStack)base.Content; }
40      set { base.Content = value; }
41    }
42
43    public ExecutionStackView() {
44      InitializeComponent();
45    }
46
47    protected override void DeregisterContentEvents() {
48      Content.CollectionReset -= Content_Changed;
49      Content.ItemsAdded -= Content_Changed;
50      Content.ItemsRemoved -= Content_Changed;
51      Content.ItemsMoved -= Content_Changed;
52      Content.ItemsReplaced -= Content_Changed;
53      base.DeregisterContentEvents();
54    }
55
56    protected override void RegisterContentEvents() {
57      base.RegisterContentEvents();
58      Content.CollectionReset += Content_Changed;
59      Content.ItemsAdded += Content_Changed;
60      Content.ItemsRemoved += Content_Changed;
61      Content.ItemsMoved += Content_Changed;
62      Content.ItemsReplaced += Content_Changed;
63    }
64
65    #region Event Handlers (Content)
66    void Content_Changed(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOperation>> e) {
67      if (InvokeRequired)
68        Invoke(new EventHandler<CollectionItemsChangedEventArgs<IndexedItem<IOperation>>>(Content_Changed), sender, e);
69      else
70        UpdateExecutionStack();
71    }
72
73
74    private void UpdateExecutionStack() {
75      if (suspended) {
76        groupBox.Text = string.Format("Execution Stack ({0})", CountOperations(Content));
77      } else {
78        treeView.BeginUpdate();
79        treeView.Nodes.Clear();
80        treeView.ImageList.Images.Clear();
81        treeView.ImageList.Images.Add(VS2008ImageLibrary.Method);
82        treeView.ImageList.Images.Add(VS2008ImageLibrary.Module);
83        treeView.ImageList.Images.Add(VS2008ImageLibrary.BreakpointActive);
84        int totalNodes = AddStackOperations(treeView.Nodes, ((IEnumerable<IOperation>)Content).Reverse());
85        if (treeView.Nodes.Count > 0)
86          treeView.TopNode = treeView.Nodes[0];
87        treeView.ExpandAll();
88        treeView.EndUpdate();
89        groupBox.Text = string.Format("Execution Stack ({0})", totalNodes);
90      }
91    }
92
93    private int CountOperations(IEnumerable<IOperation> operations) {
94      int count = 0;
95      foreach (IOperation op in operations) {
96        count++;
97        OperationCollection ops = op as OperationCollection;
98        if (ops != null)
99          count += CountOperations(ops);
100      }
101      return count;
102    }
103
104    private int AddStackOperations(TreeNodeCollection nodes, IEnumerable<IOperation> operations) {
105      int count = 0;
106      foreach (IOperation op in operations) {
107        if (op is IAtomicOperation) {
108          IAtomicOperation atom = op as IAtomicOperation;
109          TreeNode node = nodes.Add(atom.Operator.Name ?? atom.Operator.ItemName);
110          node.Tag = atom;
111          node.ToolTipText = string.Format("{0}{1}{1}{2}",
112            Utils.TypeName(atom.Operator), Environment.NewLine,
113            Utils.Wrap(atom.Operator.Description ?? atom.Operator.ItemDescription, 60));
114          if (atom.Operator.Breakpoint) {
115            node.ForeColor = Color.Red;
116            node.ImageIndex = 2;
117            node.SelectedImageIndex = 2;
118          } else {
119            node.ImageIndex = 0;
120            node.SelectedImageIndex = 0;
121          }
122          count++;
123        } else if (op is OperationCollection) {
124          OperationCollection ops = op as OperationCollection;
125          TreeNode node = treeView.Nodes.Add(
126            string.Format("{0} Operation{1}", ops.Count, ops.Count == 1 ? string.Empty : "s"));
127          node.Tag = op;
128          node.ToolTipText = Utils.TypeName(ops);
129          node.ImageIndex = 1;
130          node.SelectedImageIndex = 1;
131          count += AddStackOperations(node.Nodes, ops);
132        }
133      }
134      return count;
135    }
136    #endregion
137
138    protected override void OnContentChanged() {
139      base.OnContentChanged();
140      if (Content == null) {
141        treeView.Nodes.Clear();
142      } else {
143        UpdateExecutionStack();
144      }
145    }
146
147
148    protected override void SetEnabledStateOfControls() {
149      base.SetEnabledStateOfControls();
150    }
151
152    #region Event Handlers (child controls)
153    private void treeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) {
154      if (e.Node != null) {
155        IAtomicOperation op = e.Node.Tag as IAtomicOperation;
156        if (op != null)
157          MainFormManager.MainForm.ShowContent(op.Operator);
158      }
159    }
160    #endregion
161
162    #region Suspension
163    private bool suspended = false;
164    public virtual void SuspendUpdate() {
165      suspended = true;
166      treeView.Nodes.Clear();
167    }
168
169    public virtual void ResumeUpdate() {
170      suspended = false;
171      if (Content != null)
172        UpdateExecutionStack();
173    }
174    #endregion
175  }
176}
Note: See TracBrowser for help on using the repository browser.