Free cookie consent management tool by TermsFeed Policy Generator

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

Refactoring and modularization of DebugEngine (#47)

Location:
branches/HeuristicLab.DebugEngine
Files:
6 added
5 edited

Legend:

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

    r4827 r4871  
    2121
    2222using System;
     23using System.Linq;
    2324using System.Collections.Generic;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HeuristicLab.Collections;
     29using System.Threading;
    2730
    2831namespace HeuristicLab.DebugEngine {
     
    3033  [StorableClass]
    3134  [Item("Debug Engine", "Engine for debugging algorithms.")]
    32   public class DebugEngine : Engine {
    33     private IOperator currentOperator;
    34 
     35  public class DebugEngine : Executable, IEngine {
     36
     37
     38    #region Construction and Cloning
     39   
    3540    [StorableConstructor]
    36     protected DebugEngine(bool deserializing) : base(deserializing) { }
    37     protected DebugEngine(DebugEngine original, Cloner cloner) : base(original, cloner) { }
     41    protected DebugEngine(bool deserializing) : base(deserializing) {
     42      pausePending = stopPending = false;
     43      timer = new System.Timers.Timer(100);
     44      timer.AutoReset = true;
     45      timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
     46    }
     47    protected DebugEngine(DebugEngine original, Cloner cloner) : base(original, cloner) {
     48      if (original.ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState));
     49      Log = cloner.Clone(original.Log);
     50      ExecutionStack = cloner.Clone(original.ExecutionStack);
     51      pausePending = original.pausePending;
     52      stopPending = original.stopPending;
     53      timer = new System.Timers.Timer(100);
     54      timer.AutoReset = true;
     55      timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
     56      this.currentOperation = cloner.Clone(original.currentOperation);
     57      this.currentOperator = cloner.Clone(original.currentOperator);
     58    }
    3859    public DebugEngine()
    3960      : base() {
    40     }
    41 
    42     public new Stack<IOperation> ExecutionStack {
    43       get { return base.ExecutionStack; }
    44     }
    45 
    46     public IAtomicOperation CurrentOperation { get; private set; }
     61      Log = new Log();
     62      ExecutionStack = new ExecutionStack();
     63      pausePending = stopPending = false;
     64      timer = new System.Timers.Timer(100);
     65      timer.AutoReset = true;
     66      timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
     67    }
    4768
    4869    public override IDeepCloneable Clone(Cloner cloner) {
    4970      return new DebugEngine(this, cloner);
     71    }
     72
     73    #endregion
     74
     75    #region Fields and Properties
     76
     77    [Storable]
     78    public ILog Log { get; protected set; }
     79
     80    [Storable]
     81    public ExecutionStack ExecutionStack { get; protected set; }
     82
     83    private bool pausePending, stopPending;
     84    private DateTime lastUpdateTime;
     85    private System.Timers.Timer timer;
     86     
     87    [Storable]
     88    private IOperator currentOperator;
     89
     90    [Storable]
     91    private bool ignoreNextBreakpoint;
     92
     93    [Storable]
     94    private IOperation currentOperation;
     95    public virtual IOperation CurrentOperation {
     96      get { return currentOperation; }
     97      private set {
     98        if (value == currentOperation)
     99          return;
     100        currentOperation = value;
     101        OnOperationChanged(value);
     102      }
     103    }
     104
     105    public virtual IAtomicOperation CurrentAtomicOperation {
     106      get { return CurrentOperation as IAtomicOperation; }
     107    }
     108
     109    public virtual IExecutionContext CurrentExecutionContext {
     110      get { return CurrentOperation as IExecutionContext;  }
     111    }
     112
     113    #endregion
     114
     115    #region Events
     116
     117    public event EventHandler<OperationChangedEventArgs> CurrentOperationChanged;
     118
     119    protected virtual void OnOperationChanged(IOperation newOperation) {
     120      EventHandler<OperationChangedEventArgs> handler = CurrentOperationChanged;
     121      if (handler != null) {
     122        handler(this, new OperationChangedEventArgs(newOperation));
     123      }
     124    }
     125
     126    #endregion
     127
     128    #region Std Methods
     129    public sealed override void Prepare() {
     130      base.Prepare();
     131      ExecutionStack.Clear();
     132      ignoreNextBreakpoint = false;
     133      CurrentOperation = null;
     134      OnPrepared();
     135    }
     136    public void Prepare(IOperation initialOperation) {
     137      base.Prepare();
     138      ExecutionStack.Clear();
     139      if (initialOperation != null)
     140        ExecutionStack.Add(initialOperation);
     141      ignoreNextBreakpoint = false;
     142      CurrentOperation = null;
     143      OnPrepared();
     144    }
     145    protected override void OnPrepared() {
     146      Log.LogMessage("Engine prepared");
     147      base.OnPrepared();
     148    }
     149
     150    public virtual void Step() {
     151      OnStarted();
     152      lastUpdateTime = DateTime.Now;
     153      ignoreNextBreakpoint = true;
     154      timer.Start();
     155      ProcessNextOperation();     
     156      timer.Stop();
     157      ExecutionTime += DateTime.Now - lastUpdateTime;
     158      ignoreNextBreakpoint = false;
     159      OnPaused();
     160    }
     161
     162    public override void Start() {
     163      base.Start();
     164      CurrentOperation = null;
     165      ThreadPool.QueueUserWorkItem(new WaitCallback(Run), null);
     166    }
     167   
     168    protected override void OnStarted() {
     169      Log.LogMessage("Engine started");
     170      base.OnStarted();
     171    }
     172
     173    public override void Pause() {
     174      base.Pause();
     175      pausePending = true;
     176      if (currentOperator != null) currentOperator.Abort();
     177    }
     178
     179    protected override void OnPaused() {
     180      Log.LogMessage("Engine paused");
     181      base.OnPaused();
     182    }
     183
     184    public override void Stop() {
     185      CurrentOperation = null;
     186      base.Stop();
     187      stopPending = true;
     188      if (currentOperator != null) currentOperator.Abort();
     189      ignoreNextBreakpoint = false;
     190      if (ExecutionState == ExecutionState.Paused) OnStopped();
     191    }
     192   
     193    protected override void OnStopped() {
     194      Log.LogMessage("Engine stopped");
     195      base.OnStopped();
     196    }
     197
     198    protected override void OnExceptionOccurred(Exception exception) {
     199      Log.LogException(exception);
     200      base.OnExceptionOccurred(exception);
     201    }
     202
     203    private void Run(object state) {
     204      OnStarted();
     205      pausePending = stopPending = false;
     206
     207      lastUpdateTime = DateTime.Now;
     208      timer.Start();
     209      while (!pausePending && !stopPending && CanContinue) {
     210        ProcessNextOperation();
     211      }
     212      timer.Stop();
     213      ExecutionTime += DateTime.Now - lastUpdateTime;
     214
     215      if (pausePending) OnPaused();
     216      else OnStopped();
     217    }
     218
     219    private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
     220      DateTime now = DateTime.Now;
     221      ExecutionTime += now - lastUpdateTime;
     222      lastUpdateTime = now;
     223    }
     224    #endregion
     225
     226    #region Methods
     227
     228    public virtual bool CanContinue {
     229      get { return CurrentOperation != null || ExecutionStack.Count > 0; }
    50230    }
    51231
     
    57237    /// is pushed on the stack again.<br/>
    58238    /// If the execution was successful <see cref="EngineBase.OnOperationExecuted"/> is called.</remarks>
    59     protected override void ProcessNextOperation() {
    60       currentOperator = null;
    61       IOperation next = ExecutionStack.Pop();
    62       OperationCollection coll = next as OperationCollection;
    63       while (coll != null) {
    64         Log.LogMessage("Expanding OperationCollection");
    65         for (int i = coll.Count - 1; i >= 0; i--) {
    66           ExecutionStack.Push(coll[i]);
     239    protected virtual void ProcessNextOperation() {
     240      try {
     241        IAtomicOperation atomicOperation = CurrentOperation as IAtomicOperation;
     242        OperationCollection operations = CurrentOperation as OperationCollection;
     243        if (atomicOperation != null && operations != null)
     244          throw new InvalidOperationException("Current operation is both atomic and an operation collection");
     245
     246        if (atomicOperation != null) {
     247          Log.LogMessage(string.Format("Performing atomic operation {0}", Name(atomicOperation)));
     248          PerformAtomicOperation(atomicOperation);
     249        } else if (operations != null) {
     250          Log.LogMessage("Expanding operation collection");
     251          ExpandOperationCollection(operations);
     252        } else if (ExecutionStack.Count > 0) {
     253          Log.LogMessage("Poping execution stack");
     254          CurrentOperation = ExecutionStack.Last();
     255          ExecutionStack.RemoveAt(ExecutionStack.Count - 1);
     256        } else {
     257          Log.LogMessage("Nothing to do");
    67258        }
    68         next = ExecutionStack.Count > 0 ? ExecutionStack.Pop() : null;
    69         coll = next as OperationCollection;
    70       }
    71       IAtomicOperation operation = next as IAtomicOperation;
     259      } catch (Exception x) {
     260        OnExceptionOccurred(x);
     261      }
     262    }
     263
     264    protected virtual void PerformAtomicOperation(IAtomicOperation operation) {
    72265      if (operation != null) {
    73         Log.LogMessage("Preparing IAtomicOperation");
     266        if (operation.Operator.Breakpoint) {
     267          if (ignoreNextBreakpoint) {
     268            ignoreNextBreakpoint = false;
     269          } else {
     270            ignoreNextBreakpoint = true;
     271            Log.LogMessage(string.Format("Breaking before: {0}", Name(operation)));
     272            Pause();
     273            return;
     274          }
     275        }
    74276        try {
    75277          currentOperator = operation.Operator;
    76           CurrentOperation = operation;
    77           if (operation.Operator.Breakpoint) {
    78             Log.LogMessage(string.Format("Breakpoint: Before {0}", operation.Operator.Name != string.Empty ? operation.Operator.Name : operation.Operator.ItemName));
    79             Pause();
     278          IOperation successor = operation.Operator.Execute((IExecutionContext)operation);
     279          CurrentOperation = null;
     280          currentOperator = null;
     281          if (successor != null) {
     282            ExecutionStack.Add(successor);
    80283          }
    81           Log.LogMessage("Executing IAtomicOperation");
    82           ExecutionStack.Push(operation.Operator.Execute((IExecutionContext)operation));
    83284        } catch (Exception ex) {
    84285          OnExceptionOccurred(new OperatorExecutionException(operation.Operator, ex));
    85286          Pause();
    86287        }
    87       } else {
    88         Log.LogMessage("Nothing to do");
    89         CurrentOperation = null;
    90       }
    91     }
    92 
    93     public override void Pause() {
    94       base.Pause();
    95       if (currentOperator != null) currentOperator.Abort();
    96     }
    97     public override void Stop() {
    98       base.Stop();
    99       if (currentOperator != null) currentOperator.Abort();
    100     }
    101 
    102     public virtual void Step() {
    103       OnStarted();
    104       var lastUpdateTime = DateTime.Now;
    105       if (ExecutionStack.Count > 0) {
    106         while (ExecutionStack.Count > 0 && ExecutionStack.Peek() == null)
    107           ExecutionStack.Pop();
    108         if (ExecutionStack.Count > 0)
    109           ProcessNextOperation();
    110       }
    111       ExecutionTime += DateTime.Now - lastUpdateTime;
    112       OnPaused();
    113     }
     288      }
     289    }
     290
     291    protected virtual void ExpandOperationCollection(OperationCollection operations) {
     292      ExecutionStack.AddRange(operations.Reverse());
     293      CurrentOperation = null;
     294    }
     295
     296    protected virtual string Name(IAtomicOperation operation) {
     297      return string.IsNullOrEmpty(operation.Operator.Name) ? operation.Operator.ItemName : operation.Operator.Name;
     298    }
     299
     300    #endregion
    114301  }
    115302}
  • branches/HeuristicLab.DebugEngine/DebugEngineView.Designer.cs

    r4765 r4871  
    4949      this.label1 = new System.Windows.Forms.Label();
    5050      this.executionTimeTextBox = new System.Windows.Forms.TextBox();
     51      this.executionStackView = new HeuristicLab.DebugEngine.ExecutionStackView();
    5152      this.logView = new HeuristicLab.Core.Views.LogView();
    5253      this.splitContainer1 = new System.Windows.Forms.SplitContainer();
    53       this.executionStackTreeView = new System.Windows.Forms.TreeView();
    54       this.label2 = new System.Windows.Forms.Label();
    5554      this.splitContainer2 = new System.Windows.Forms.SplitContainer();
     55      this.splitContainer3 = new System.Windows.Forms.SplitContainer();
     56      this.parameterCollectionView = new HeuristicLab.Core.Views.ParameterCollectionView();
     57      this.label3 = new System.Windows.Forms.Label();
     58      this.scopeTreeView = new System.Windows.Forms.TreeView();
    5659      this.label4 = new System.Windows.Forms.Label();
    5760      this.operationTextBox = new System.Windows.Forms.TextBox();
    58       this.label3 = new System.Windows.Forms.Label();
    59       this.scopeTreeView = new System.Windows.Forms.TreeView();
    6061      this.stepButton = new System.Windows.Forms.Button();
    6162      this.updateButton = new System.Windows.Forms.Button();
    6263      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    6364      this.parentButton = new System.Windows.Forms.Button();
    64       this.splitContainer3 = new System.Windows.Forms.SplitContainer();
    65       this.parameterCollectionView = new HeuristicLab.Core.Views.ParameterCollectionView();
    6665      this.splitContainer1.Panel1.SuspendLayout();
    6766      this.splitContainer1.Panel2.SuspendLayout();
     
    9493      this.executionTimeTextBox.TabIndex = 1;
    9594      //
     95      // executionStackView
     96      //
     97      this.executionStackView.Caption = "Execution Stack View";
     98      this.executionStackView.Content = null;
     99      this.executionStackView.Dock = System.Windows.Forms.DockStyle.Fill;
     100      this.executionStackView.Location = new System.Drawing.Point(0, 0);
     101      this.executionStackView.Name = "executionStackView";
     102      this.executionStackView.ReadOnly = false;
     103      this.executionStackView.Size = new System.Drawing.Size(433, 262);
     104      this.executionStackView.TabIndex = 0;
     105      //
    96106      // logView
    97107      //
     
    114124      // splitContainer1.Panel1
    115125      //
    116       this.splitContainer1.Panel1.Controls.Add(this.executionStackTreeView);
    117       this.splitContainer1.Panel1.Controls.Add(this.label2);
     126      this.splitContainer1.Panel1.Controls.Add(this.executionStackView);
    118127      //
    119128      // splitContainer1.Panel2
     
    123132      this.splitContainer1.SplitterDistance = 262;
    124133      this.splitContainer1.TabIndex = 3;
    125       //
    126       // executionStackTreeView
    127       //
    128       this.executionStackTreeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    129                   | System.Windows.Forms.AnchorStyles.Left)
    130                   | System.Windows.Forms.AnchorStyles.Right)));
    131       this.executionStackTreeView.Location = new System.Drawing.Point(3, 16);
    132       this.executionStackTreeView.Name = "executionStackTreeView";
    133       this.executionStackTreeView.ShowNodeToolTips = true;
    134       this.executionStackTreeView.Size = new System.Drawing.Size(427, 243);
    135       this.executionStackTreeView.TabIndex = 2;
    136       this.executionStackTreeView.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.executionStackTreeView_NodeMouseDoubleClick);
    137       //
    138       // label2
    139       //
    140       this.label2.AutoSize = true;
    141       this.label2.Location = new System.Drawing.Point(3, 0);
    142       this.label2.Name = "label2";
    143       this.label2.Size = new System.Drawing.Size(85, 13);
    144       this.label2.TabIndex = 1;
    145       this.label2.Text = "Execution Stack";
    146134      //
    147135      // splitContainer2
     
    166154      this.splitContainer2.TabIndex = 0;
    167155      //
    168       // label4
    169       //
    170       this.label4.AutoSize = true;
    171       this.label4.Location = new System.Drawing.Point(3, 6);
    172       this.label4.Name = "label4";
    173       this.label4.Size = new System.Drawing.Size(56, 13);
    174       this.label4.TabIndex = 3;
    175       this.label4.Text = "Operation:";
    176       //
    177       // operationTextBox
    178       //
    179       this.operationTextBox.Location = new System.Drawing.Point(65, 3);
    180       this.operationTextBox.Name = "operationTextBox";
    181       this.operationTextBox.ReadOnly = true;
    182       this.operationTextBox.Size = new System.Drawing.Size(267, 20);
    183       this.operationTextBox.TabIndex = 2;
     156      // splitContainer3
     157      //
     158      this.splitContainer3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     159                  | System.Windows.Forms.AnchorStyles.Left)
     160                  | System.Windows.Forms.AnchorStyles.Right)));
     161      this.splitContainer3.Location = new System.Drawing.Point(3, 29);
     162      this.splitContainer3.Name = "splitContainer3";
     163      this.splitContainer3.Orientation = System.Windows.Forms.Orientation.Horizontal;
     164      //
     165      // splitContainer3.Panel1
     166      //
     167      this.splitContainer3.Panel1.Controls.Add(this.parameterCollectionView);
     168      //
     169      // splitContainer3.Panel2
     170      //
     171      this.splitContainer3.Panel2.Controls.Add(this.label3);
     172      this.splitContainer3.Panel2.Controls.Add(this.scopeTreeView);
     173      this.splitContainer3.Size = new System.Drawing.Size(423, 471);
     174      this.splitContainer3.SplitterDistance = 235;
     175      this.splitContainer3.TabIndex = 4;
     176      //
     177      // parameterCollectionView
     178      //
     179      this.parameterCollectionView.Caption = "ParameterCollection View";
     180      this.parameterCollectionView.Content = null;
     181      this.parameterCollectionView.Dock = System.Windows.Forms.DockStyle.Fill;
     182      this.parameterCollectionView.Location = new System.Drawing.Point(0, 0);
     183      this.parameterCollectionView.Name = "parameterCollectionView";
     184      this.parameterCollectionView.ReadOnly = false;
     185      this.parameterCollectionView.Size = new System.Drawing.Size(423, 235);
     186      this.parameterCollectionView.TabIndex = 0;
    184187      //
    185188      // label3
     
    204207      this.scopeTreeView.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.scopeTreeView_NodeMouseDoubleClick);
    205208      //
     209      // label4
     210      //
     211      this.label4.AutoSize = true;
     212      this.label4.Location = new System.Drawing.Point(3, 6);
     213      this.label4.Name = "label4";
     214      this.label4.Size = new System.Drawing.Size(56, 13);
     215      this.label4.TabIndex = 3;
     216      this.label4.Text = "Operation:";
     217      //
     218      // operationTextBox
     219      //
     220      this.operationTextBox.Location = new System.Drawing.Point(65, 3);
     221      this.operationTextBox.Name = "operationTextBox";
     222      this.operationTextBox.ReadOnly = true;
     223      this.operationTextBox.Size = new System.Drawing.Size(267, 20);
     224      this.operationTextBox.TabIndex = 2;
     225      //
    206226      // stepButton
    207227      //
     
    239259      this.parentButton.UseVisualStyleBackColor = true;
    240260      this.parentButton.Click += new System.EventHandler(this.parentButton_Click);
    241       //
    242       // splitContainer3
    243       //
    244       this.splitContainer3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    245                   | System.Windows.Forms.AnchorStyles.Left)
    246                   | System.Windows.Forms.AnchorStyles.Right)));
    247       this.splitContainer3.Location = new System.Drawing.Point(3, 29);
    248       this.splitContainer3.Name = "splitContainer3";
    249       this.splitContainer3.Orientation = System.Windows.Forms.Orientation.Horizontal;
    250       //
    251       // splitContainer3.Panel1
    252       //
    253       this.splitContainer3.Panel1.Controls.Add(this.parameterCollectionView);
    254       //
    255       // splitContainer3.Panel2
    256       //
    257       this.splitContainer3.Panel2.Controls.Add(this.label3);
    258       this.splitContainer3.Panel2.Controls.Add(this.scopeTreeView);
    259       this.splitContainer3.Size = new System.Drawing.Size(423, 471);
    260       this.splitContainer3.SplitterDistance = 235;
    261       this.splitContainer3.TabIndex = 4;
    262       //
    263       // parameterCollectionView
    264       //
    265       this.parameterCollectionView.Caption = "ParameterCollection View";
    266       this.parameterCollectionView.Content = null;
    267       this.parameterCollectionView.Dock = System.Windows.Forms.DockStyle.Fill;
    268       this.parameterCollectionView.Location = new System.Drawing.Point(0, 0);
    269       this.parameterCollectionView.Name = "parameterCollectionView";
    270       this.parameterCollectionView.ReadOnly = false;
    271       this.parameterCollectionView.Size = new System.Drawing.Size(423, 235);
    272       this.parameterCollectionView.TabIndex = 0;
    273261      //
    274262      // DebugEngineView
     
    284272      this.Size = new System.Drawing.Size(872, 538);
    285273      this.splitContainer1.Panel1.ResumeLayout(false);
    286       this.splitContainer1.Panel1.PerformLayout();
    287274      this.splitContainer1.Panel2.ResumeLayout(false);
    288275      this.splitContainer1.ResumeLayout(false);
     
    307294    private System.Windows.Forms.SplitContainer splitContainer1;
    308295    private System.Windows.Forms.SplitContainer splitContainer2;
    309     private System.Windows.Forms.Label label2;
    310296    private System.Windows.Forms.Label label3;
    311297    private System.Windows.Forms.TreeView scopeTreeView;
    312     private System.Windows.Forms.TreeView executionStackTreeView;
    313298    private System.Windows.Forms.Button stepButton;
    314299    private System.Windows.Forms.Button updateButton;
     
    319304    private System.Windows.Forms.SplitContainer splitContainer3;
    320305    private Core.Views.ParameterCollectionView parameterCollectionView;
     306    private HeuristicLab.DebugEngine.ExecutionStackView executionStackView;
    321307
    322308  }
  • 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
  • branches/HeuristicLab.DebugEngine/DebugEngineView.resx

    r4765 r4871  
    122122    <value>
    123123        iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
    124         YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAALEAAA
    125         CxABrSO9dQAAARBJREFUOE9j+P//PwM6Tuh5woxNHJsYhmaQIqABMkDMRIwhWA0onPX8f/zkt0rEGILV
     124        YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAALDgAA
     125        Cw4BQL7hQQAAARBJREFUOE9j+P//PwM6Tuh5woxNHJsYhmaQIqABMkDMRIwhWA0onPX8f/zkt0rEGILV
    126126        gNyZz/4ndN/7HzfhtQYh72A1IGPK0//z9v/+H9Rw8zXQAFt8huAKg/+z9/3637n173+30sv/gQbY4zIE
    127127        qwGRXY/+T9n263/J0r//E6b//W+TexanIVgNCGx++L917XuwZuOSL/+lo6/9N45c9t+h6Gw8ukuwGuBR
     
    137137    <value>
    138138        iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
    139         YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAALDwAA
    140         Cw8BkvkDpQAAAmFJREFUOE+dk21IU1EYx3cVVzkhaLCy+UaY0xwlZkYRmiGR7oMEUlAGfRGKvkRFVOQ0
    141         DddsVmtbvpQWhCFBSvaCUcRAk0gGm8SGM7JtrU1nzYFvu3P33znDRcLpSxceDvdefr/zv+d5Lidaufjg
    142         QKKIWwNSUo4Tz4u4RAl5xYsgJIuEcADCYlS8oQKLvvvKdam1n+PcqjUyN5ox7PyIVrMB1U9PoKxThZI7
    143         h3C1vwk2l2OWD40c15nbwITD/h5p/9hrVL2sgXpSA43bgGsOHeodLTj16QJK71XCOmlH3u1dbIHDOxGk
    144         8PXJW1D1HYWsfgs2NW3FSfOZmKjBcTMmydLmswWXnjegZvg0dusPoHXQiDH3OJw+F9IaFbFU8UptymYL
    145         DncdQ0lHBfosrxBZFvL5ZUEyFfgFm2d8lURal8kWFHeU4eIzNYULSHF8ROB6LQPI1CiRrskF3ZnC6y/L
    146         2YIdxr0Y/WqDf/pnEj1lry+Q5vkxlfTdN73W6w+IyX2Cy+PfOP7FxRaQHbFSB8maGOaFfR7vFLcYjiYs
    147         LEW5eVJzC1GJekjLFhR2lWJ72x7k3i0KZrUoQ/JmBdpHHmOJj0ppIiIpbx96iDzjP9q4s6sEWrcp1rJs
    148         XQEsLjv9HJAE6TSF1eVE5ZNqbK7LYSfYZir+I6AShb4Ilm92MoET6BzuiU0lbWXto7NsAYmNnBuFq3pO
    149         oThIYblagQfve9mCjOZ8vLC+hZwMzt9QfIAorHljQGA2sp/5L7S96wY5KHxwWHCltxEq0xGknJch5ZwM
    150         5foqGAe7MROKJHtn+ASm4H8f/gZt6J11yfCrBQAAAABJRU5ErkJggg==
     139        YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAALDQAA
     140        Cw0B7QfALAAAAmJJREFUOE+dk21IU1Ecxt3MCBX8MLRsvhHmtI0SM6OImSFR+kECKSiDvgRFX6IiKnKa
     141        C9dsVmtbU2sWhCFBSvamFDFwrRcZbH7YmEZ2t9Y2Z24zU3ev29M9w0XS9UsXHg6Hc5/fec75/09S0tJH
     142        BweS6dAQnw4bM5kZcyrz82Mmqwxm5n02EzKuoqdf8civ8967koTnn5GZHckzjX1Au1GD+sdHUdVVC+mt
     143        fbjcL4eNcoTosPmIyqgHJyDi6xH0j75E3fMGyCYUULg0uOJQocnRhhOfzqHyTg2sE3aU3NzGDXB4xoPE
     144        fHXiBmr7DiGraQPWyTfimPFUHNTsuB6HFCjF3IALT5vRYDqJ7eo9aB/UYtTlxJiXQk6LKJ4qoWx5ITfg
     145        gOEwpJ370Wd5AWYxJqYXY2n+wDRsbucyiKAxnxtQ0VmF809kxFzKikczMV6vZQD5CglyFcUgOxNzxkUh
     146        N2CLdidGvtjgm/yRQm7Z4w3kuL/7U755J9d4fIHV7JxPuX1rnZ8pbgC7I5a0lx2TI3Rsl9vj581Hovy5
     147        hSjvF6vZuWiabFjJDSgzVGKzfgeKb5cHC9okYWGrCB3mh1igowKSiIVUdwzfR4l2hTJuNUihdOniJStU
     148        lcJC2clxwCbIJSms1BhqHtVjfWMRd4JNuoo/AAIRqcth+WpnO3AcXaaeeFeSUh5/cJobwMZG0bWyZTUn
     149        poSRmIUyEe697eUG5LWK8cz6GkK2cf42JRqImBVDGgRCzG7Ot6B/0w32ovDOYcGl3hbU6g4i/WwW0s9k
     150        oVpdB+1gN6bCTKpniuav+Br/Z+E3/RykhyEkCzoAAAAASUVORK5CYII=
    151151</value>
    152152  </data>
     
    154154    <value>
    155155        iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
    156         YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAALEQAA
    157         CxEBf2RfkQAAAN5JREFUOE9j/P//PwNFAGQALuxeeskYnzzYclwKVH3nSpXNefEfaEgEPkOwGgDTPG/f
    158         3/+GYYv+G8ds8MVlCIYByJrz5/7475R35L9WwAKchqAYgKy5dd2//5E9n/57lF38b5+1/7+G31yshqAY
    159         APJz8cyn/0F07Yr//+Mm//nvX3/vv2bI6v9Aw/+reE4D+gQ10LGGAcgAkAtgBqj7L8LQCDMIpwGTt//9
    160         nzvvL9gFqt6zSDcAFAMVSwfSgGWHf1PmApABoCgEYWX3SaSHAUgTMiY6JRLKPESlA1IMAQAvnrIcTgHP
    161         egAAAABJRU5ErkJggg==
     156        YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAALDwAA
     157        Cw8BkvkDpQAAANpJREFUOE9j+P//PwMlGK9m99JLxoQMx2mAqu9cqbI5L/4DDYnAZwhWA2Ca5+37+98w
     158        bNF/45gNvrgMwTAAWXP+3B//nfKO/NcKWIDTEBQDkDW3rvv3P7Ln03+Psov/7bP2/9fwm4vVEBQDQH4u
     159        nvn0P4iuXfH/f9zkP//96+/91wxZ/R9o+H8Vz2lAn6DGGtYwABkAcgHMAHX/RRgaYQbhNGDy9r//c+f9
     160        BbtA1XsW6QaAYqBi6UAasOzwb8pcADIAFIUgrOw+ifQwAGlCxkSnREKZh6h0QIohAFsI3u6Zj7KhAAAA
     161        AElFTkSuQmCC
    162162</value>
    163163  </data>
  • branches/HeuristicLab.DebugEngine/HeuristicLab.DebugEngine.csproj

    r4759 r4871  
    125125      <DependentUpon>DebugEngineView.cs</DependentUpon>
    126126    </Compile>
     127    <Compile Include="ExecutionStack.cs" />
     128    <Compile Include="ExecutionStackView.cs">
     129      <SubType>UserControl</SubType>
     130    </Compile>
     131    <Compile Include="ExecutionStackView.Designer.cs">
     132      <DependentUpon>ExecutionStackView.cs</DependentUpon>
     133    </Compile>
     134    <Compile Include="OperationChangedEventArgs.cs" />
    127135    <Compile Include="Properties\AssemblyInfo.cs" />
     136    <Compile Include="Utils.cs" />
    128137  </ItemGroup>
    129138  <ItemGroup>
    130139    <EmbeddedResource Include="DebugEngineView.resx">
    131140      <DependentUpon>DebugEngineView.cs</DependentUpon>
     141    </EmbeddedResource>
     142    <EmbeddedResource Include="ExecutionStackView.resx">
     143      <DependentUpon>ExecutionStackView.cs</DependentUpon>
    132144    </EmbeddedResource>
    133145  </ItemGroup>
Note: See TracChangeset for help on using the changeset viewer.