Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/20/10 14:13:32 (13 years ago)
Author:
epitzer
Message:

Refactoring and modularization of DebugEngine (#47)

File:
1 edited

Legend:

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

    r4765 r4871  
    3030using HeuristicLab.Persistence.Auxiliary;
    3131namespace HeuristicLab.DebugEngine {
     32
    3233  /// <summary>
    33   /// Base class for editors of engines.
     34  /// Engine espcially for debugging
    3435  /// </summary>
    3536  [View("DebugEngine View")]
    3637  [Content(typeof(DebugEngine), true)]
    3738  public partial class DebugEngineView : ItemView {
     39
     40    #region Basics
     41
    3842    /// <summary>
    3943    /// Gets or sets the current engine.
     
    4650
    4751    /// <summary>
    48     /// Initializes a new instance of <see cref="EngineBaseEditor"/>.
     52    /// Initializes a new instance of <see cref="DebugEngineView"/>.
    4953    /// </summary>
    5054    public DebugEngineView() {
     
    6064    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
    6165    protected override void DeregisterContentEvents() {
     66      Content.CurrentOperationChanged -= new EventHandler<OperationChangedEventArgs>(Content_CurrentOperationChanged);
    6267      Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
    6368      Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);
     
    7378      Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
    7479      Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
     80      Content.CurrentOperationChanged += new EventHandler<OperationChangedEventArgs>(Content_CurrentOperationChanged);
    7581    }
    7682
     
    8490        logView.Content = null;
    8591        executionTimeTextBox.Text = "-";
     92        executionStackView.Content = null;
    8693      } else {
    8794        logView.Content = Content.Log;
    8895        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
     96        executionStackView.Content = Content.ExecutionStack;
    8997      }
    9098    }
     
    101109    }
    102110
     111    #endregion
     112
    103113    protected virtual void Content_ExecutionTimeChanged(object sender, EventArgs e) {
    104114      if (InvokeRequired)
     
    109119
    110120    void Content_ExecutionStateChanged(object sender, EventArgs e) {
    111       switch (Content.ExecutionState) {
    112         case ExecutionState.Paused:
    113         case ExecutionState.Stopped:
    114         case ExecutionState.Prepared:
    115           UpdateView(); break;
    116       }
    117     }
    118 
    119     protected virtual void UpdateView() {
    120       if (InvokeRequired) {
    121         Invoke(new Action(UpdateView));
    122       } else {
    123         UpdateExecutionStack();
     121      if (InvokeRequired)
     122        Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
     123      else {
     124        switch (Content.ExecutionState) {
     125          case ExecutionState.Started: executionStackView.SuspendUpdate(); break;
     126          default: executionStackView.ResumeUpdate(); break;
     127        }
     128      }
     129    }
     130
     131    #region Current Operation
     132
     133    void Content_CurrentOperationChanged(object sender, OperationChangedEventArgs e) {
     134      if (InvokeRequired)
     135        Invoke(new EventHandler<OperationChangedEventArgs>(Content_CurrentOperationChanged), sender, e);
     136      else
    124137        SetOperation(Content.CurrentOperation);
    125       }
    126138    }
    127139
     
    133145      if (atomicOperation != null && atomicOperation.Operator != null) {
    134146        operationTextBox.Text = string.Format("Atomic {0}", atomicOperation.Operator.Name);
    135         toolTip.SetToolTip(operationTextBox, TypeName(atomicOperation.Operator));
     147        toolTip.SetToolTip(operationTextBox, Utils.TypeName(atomicOperation.Operator));
    136148      }
    137149      OperationCollection operationCollection = operation as OperationCollection;
     
    152164    }
    153165
    154     private void UpdateExecutionStack() {
    155       executionStackTreeView.BeginUpdate();
    156       executionStackTreeView.Nodes.Clear();
    157       AddOperations(executionStackTreeView.Nodes, Content.ExecutionStack.ToArray());
    158       executionStackTreeView.ExpandAll();
    159       if (executionStackTreeView.Nodes.Count > 0)
    160         executionStackTreeView.TopNode = executionStackTreeView.Nodes[0];
    161       executionStackTreeView.EndUpdate();
    162     }
    163 
    164166    private void UpdateScope(IScope scope) {
    165167      scopeTreeView.BeginUpdate();
     
    174176    }
    175177
    176     private string TypeName(object obj) {
    177       if (obj == null)
    178         return "null";
    179       return TypeNameParser.Parse(obj.GetType().ToString()).GetTypeNameInCode(true);
    180     }
    181 
    182     private void AddOperations(TreeNodeCollection nodes, IEnumerable<IOperation> operations) {
    183       foreach (IOperation op in operations) {
    184         if (op is IAtomicOperation) {
    185           IAtomicOperation atom = op as IAtomicOperation;
    186           TreeNode node = nodes.Add(atom.Operator.Name);
    187           node.Tag = atom;
    188           node.ToolTipText = TypeName(atom);
    189           node.ImageKey = "AtomicOperation";
    190           if (atom.Operator.Breakpoint)
    191             node.ForeColor = Color.Red;
    192           foreach (var param in atom.Operator.Parameters) {
    193             string typeName = "null";
    194             TreeNode paramNode = node.Nodes.Add(string.Format("Param {0} = {1}", param.Name, GetApproximateValue(param, ref typeName)));
    195             paramNode.Tag = param;
    196             paramNode.ToolTipText = string.Format("{0} = {1}", TypeName(param), typeName);
    197             paramNode.ImageKey = "Parameter";
    198           }
    199         } else if (op is OperationCollection) {
    200           OperationCollection ops = op as OperationCollection;
    201           TreeNode node = executionStackTreeView.Nodes.Add(string.Format("{0} Operations", ops.Count));
    202           node.Tag = op;
    203           node.ToolTipText = TypeName(ops);
    204           node.ImageKey = "OperationCollection";
    205           AddOperations(node.Nodes, ops);
    206         }
    207       }
    208     }
    209 
     178   
     179
     180    /*
    210181    private string GetApproximateValue(IParameter param, ref string typeName) {
    211182      string valueString = "<none>";
     
    229200      return valueString;
    230201    }
     202     */
    231203
    232204    private void AddScope(TreeNodeCollection nodes, IScope scope) {
    233205      TreeNode node = nodes.Add(scope.Name);
    234       if (Content.CurrentOperation != null && Content.CurrentOperation.Scope == scope) {
     206      if (Content.CurrentAtomicOperation != null && Content.CurrentAtomicOperation.Scope == scope) {
    235207        node.ForeColor = Color.Red;
    236208        node.BackColor = Color.LightGray;
     
    239211        TreeNode varNode = node.Nodes.Add(string.Format("{0}={1}", var.Name, var.Value.ToString()));
    240212        varNode.Tag = var.Value;
    241         varNode.ToolTipText = TypeName(var.Value);
     213        varNode.ToolTipText = Utils.TypeName(var.Value);
    242214      }
    243215      foreach (var subScope in scope.SubScopes) {
    244216        AddScope(node.Nodes, subScope);
     217      }
     218    }
     219
     220    #endregion
     221
     222    protected virtual void UpdateView() {
     223      if (InvokeRequired) {
     224        Invoke(new Action(UpdateView));
     225      } else {
     226        SetOperation(Content.CurrentOperation);
    245227      }
    246228    }
     
    249231      Content.Step();
    250232      UpdateView();
    251     }
    252 
    253     private void executionStackTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) {
    254       if (e.Node != null) {
    255         IAtomicOperation op = e.Node.Tag as IAtomicOperation;
    256         if (op != null) {
    257           op.Operator.Breakpoint = !op.Operator.Breakpoint;
    258           if (op.Operator.Breakpoint) {
    259             e.Node.ForeColor = Color.Red;
    260           } else {
    261             e.Node.ForeColor = Color.Black;
    262           }
    263           executionStackTreeView.SelectedNode = null;
    264         }
    265         IParameter param = e.Node.Tag as IParameter;
    266         if (param != null)
    267           MainFormManager.MainForm.ShowContent(param);
    268       }
    269233    }
    270234
Note: See TracChangeset for help on using the changeset viewer.