Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/09/10 15:58:12 (13 years ago)
Author:
epitzer
Message:

navigate execution contexts show active scopes (#47)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.DebugEngine/DebugEngineView.cs

    r4753 r4759  
    2424using System.Drawing;
    2525using System.Windows.Forms;
     26using HeuristicLab.Common.Resources;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Core.Views;
     
    4950    public DebugEngineView() {
    5051      InitializeComponent();
     52      updateButton.Image = VS2008ImageLibrary.Refresh;
     53      stepButton.Image = VS2008ImageLibrary.MoveNext;
     54      parentButton.Image = VS2008ImageLibrary.ArrowUp;
    5155    }
    5256
     
    117121        Invoke(new Action(UpdateView));
    118122      } else {
    119         executionStackTreeView.BeginUpdate();
    120         executionStackTreeView.Nodes.Clear();
    121         AddOperations(executionStackTreeView.Nodes, Content.ExecutionStack.ToArray());
    122         executionStackTreeView.ExpandAll();
    123         if (executionStackTreeView.Nodes.Count > 0)
    124           executionStackTreeView.TopNode = executionStackTreeView.Nodes[0];
    125         executionStackTreeView.EndUpdate();
    126 
    127 
    128         scopeTreeView.BeginUpdate();
    129         scopeTreeView.Nodes.Clear();
    130         if (Content.CurrentOperation != null) {
    131           AddScope(scopeTreeView.Nodes, Content.CurrentOperation.Scope);
    132         }
    133         scopeTreeView.ExpandAll();
    134         if (scopeTreeView.Nodes.Count > 0)
    135           scopeTreeView.TopNode = scopeTreeView.Nodes[0];
    136         scopeTreeView.EndUpdate();
    137       }
     123        UpdateExecutionStack();
     124        SetOperation(Content.CurrentOperation);
     125      }
     126    }
     127
     128    private void SetOperation(IOperation operation) {
     129      IAtomicOperation atomicOperation = operation as IAtomicOperation;
     130      operationTextBox.Text = "<none>";
     131      toolTip.SetToolTip(operationTextBox, null);
     132      if (atomicOperation != null && atomicOperation.Operator != null) {
     133        operationTextBox.Text = string.Format("Atomic {0}", atomicOperation.Operator.Name);
     134        toolTip.SetToolTip(operationTextBox, TypeName(atomicOperation.Operator));
     135      }
     136      OperationCollection operationCollection = operation as OperationCollection;
     137      if (operationCollection != null)
     138        operationTextBox.Text = string.Format("Collection {0}", operationCollection.Count);
     139      IExecutionContext context = operation as IExecutionContext;
     140      IScope scope = null;
     141      if (context != null) {
     142        scope = context.Scope;
     143        while (scope != null && scope.Parent != null)
     144          scope = scope.Parent;
     145      }
     146      UpdateScope(scope);
     147      if (context != null)
     148        parentButton.Enabled = context.Parent != null;
     149      scopeTreeView.Tag = context;
     150    }
     151
     152    private void UpdateExecutionStack() {
     153      executionStackTreeView.BeginUpdate();
     154      executionStackTreeView.Nodes.Clear();
     155      AddOperations(executionStackTreeView.Nodes, Content.ExecutionStack.ToArray());
     156      executionStackTreeView.ExpandAll();
     157      if (executionStackTreeView.Nodes.Count > 0)
     158        executionStackTreeView.TopNode = executionStackTreeView.Nodes[0];
     159      executionStackTreeView.EndUpdate();
     160    }
     161
     162    private void UpdateScope(IScope scope) {
     163      scopeTreeView.BeginUpdate();
     164      scopeTreeView.Nodes.Clear();
     165      if (scope != null) {
     166        AddScope(scopeTreeView.Nodes, scope);
     167      }
     168      scopeTreeView.ExpandAll();
     169      if (scopeTreeView.Nodes.Count > 0)
     170        scopeTreeView.TopNode = scopeTreeView.Nodes[0];
     171      scopeTreeView.EndUpdate();
    138172    }
    139173
     
    151185          node.Tag = atom;
    152186          node.ToolTipText = TypeName(atom);
     187          node.ImageKey = "AtomicOperation";
    153188          if (atom.Operator.Breakpoint)
    154189            node.ForeColor = Color.Red;
     
    158193            paramNode.Tag = param;
    159194            paramNode.ToolTipText = string.Format("{0} = {1}", TypeName(param), typeName);
     195            paramNode.ImageKey = "Parameter";
    160196          }
    161197        } else if (op is OperationCollection) {
     
    164200          node.Tag = op;
    165201          node.ToolTipText = TypeName(ops);
     202          node.ImageKey = "OperationCollection";
    166203          AddOperations(node.Nodes, ops);
    167204        }
     
    170207
    171208    private string GetApproximateValue(IParameter param, ref string typeName) {
    172       string value = "<none>";
     209      string valueString = "<none>";
     210      IExecutionContext context = Content.CurrentOperation as IExecutionContext;
     211      IExecutionContext originalContext = param.ExecutionContext;
     212      object value = null;
    173213      try {
    174         IExecutionContext context = Content.CurrentOperation as IExecutionContext;
    175         IExecutionContext oldContext = param.ExecutionContext;
    176         if (context != null) {
     214        try {
    177215          param.ExecutionContext = context;
    178         }
    179         value = param.ActualValue.ToString();
    180         typeName = TypeName(param.ActualValue);
    181         if (context != oldContext) {
    182           param.ExecutionContext = oldContext;
    183           value = string.Format("~ {0}", value);
     216          value = param.ActualValue;
     217        } finally {
     218          param.ExecutionContext = originalContext;
    184219        }
    185220      } catch (Exception) { }
    186       return value;
     221      if (value != null) {
     222        valueString = value.ToString();
     223        if (context != originalContext)
     224          valueString = " ~ " + valueString;
     225        typeName = TypeName(value);
     226      }
     227      return valueString;
    187228    }
    188229
    189230    private void AddScope(TreeNodeCollection nodes, IScope scope) {
    190231      TreeNode node = nodes.Add(scope.Name);
     232      if (Content.CurrentOperation != null && Content.CurrentOperation.Scope == scope) {
     233        node.ForeColor = Color.Red;
     234        node.BackColor = Color.LightGray;
     235      }
    191236      foreach (var var in scope.Variables) {
    192237        TreeNode varNode = node.Nodes.Add(string.Format("{0}={1}", var.Name, var.Value.ToString()));
     
    230275        MainFormManager.MainForm.ShowContent((IItem)e.Node.Tag);
    231276    }
     277
     278    private void parentButton_Click(object sender, EventArgs e) {
     279      IExecutionContext context = scopeTreeView.Tag as IExecutionContext;
     280      if (context != null) {
     281        SetOperation(context.Parent as IOperation);
     282      }
     283    }
    232284  }
    233285}
Note: See TracChangeset for help on using the changeset viewer.