Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DebugEngine/DebugEngineView.cs @ 4903

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

Many small improvements to DebugEngine (#47)

  • suppress logging during execution
  • add refresh button
  • optionally skip over execution stack operators
  • expand all tree views and scroll to top node
  • show operator on click on atomic operation
  • add build.cmd
File size: 5.9 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.Windows.Forms;
24using HeuristicLab.Core;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27namespace HeuristicLab.DebugEngine {
28
29  /// <summary>
30  /// Engine espcially for debugging
31  /// </summary>
32  [View("DebugEngine View")]
33  [Content(typeof(DebugEngine), true)]
34  public partial class DebugEngineView : ItemView {
35
36    #region Basics
37
38    /// <summary>
39    /// Gets or sets the current engine.
40    /// </summary>
41    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="EditorBase"/>.</remarks>
42    public new DebugEngine Content {
43      get { return (DebugEngine)base.Content; }
44      set { base.Content = value; }
45    }
46
47    /// <summary>
48    /// Initializes a new instance of <see cref="DebugEngineView"/>.
49    /// </summary>
50    public DebugEngineView() {
51      InitializeComponent();
52    }
53
54    /// <summary>
55    /// Removes the event handlers from the underlying <see cref="IEngine"/>.
56    /// </summary>
57    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
58    protected override void DeregisterContentEvents() {
59      Content.CurrentOperationChanged -= new EventHandler<OperationChangedEventArgs>(Content_CurrentOperationChanged);
60      Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
61      Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);
62      base.DeregisterContentEvents();
63    }
64
65    /// <summary>
66    /// Adds event handlers to the underlying <see cref="IEngine"/>.
67    /// </summary>
68    /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
69    protected override void RegisterContentEvents() {
70      base.RegisterContentEvents();
71      Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
72      Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
73      Content.CurrentOperationChanged += new EventHandler<OperationChangedEventArgs>(Content_CurrentOperationChanged);
74    }
75
76    /// <summary>
77    /// Updates all controls with the latest data of the model.
78    /// </summary>
79    /// <remarks>Calls <see cref="EditorBase.UpdateControls"/> of base class <see cref="EditorBase"/>.</remarks>
80    protected override void OnContentChanged() {
81      base.OnContentChanged();
82      if (Content == null) {
83        logView.Content = null;
84        executionTimeTextBox.Text = "-";
85        executionStackView.Content = null;
86        operationContentView.Content = null;
87      } else {
88        logView.Content = Content.Log;
89        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
90        executionStackView.Content = Content.ExecutionStack;
91        operationContentView.Content = new OperationContent(Content.CurrentOperation);
92      }
93    }
94
95    protected override void SetEnabledStateOfControls() {
96      base.SetEnabledStateOfControls();
97      if (Content == null) {
98        logView.Enabled = false;
99        executionTimeTextBox.Enabled = false;
100        stepButton.Enabled = false;
101      } else {
102        logView.Enabled = true;
103        executionTimeTextBox.Enabled = true;
104        stepButton.Enabled = Content.CanContinue;
105      }
106    }
107
108    #endregion
109
110    protected virtual void Content_ExecutionTimeChanged(object sender, EventArgs e) {
111      if (InvokeRequired)
112        Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
113      else
114        executionTimeTextBox.Text = Content == null ? "-" : Content.ExecutionTime.ToString();
115    }
116
117    void Content_ExecutionStateChanged(object sender, EventArgs e) {
118      if (InvokeRequired)
119        Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
120      else {
121        switch (Content.ExecutionState) {
122          case ExecutionState.Started:
123            executionStackView.SuspendUpdate();
124            logView.Content = null;
125            break;
126          default:
127            logView.Content = Content.Log;
128            executionStackView.ResumeUpdate();
129            operationContentView.Content = new OperationContent(Content.CurrentOperation);
130            break;
131        }
132        SetEnabledStateOfControls();
133      }
134    }
135
136    void Content_CurrentOperationChanged(object sender, OperationChangedEventArgs e) {
137      if (InvokeRequired) {
138        Invoke(new EventHandler<OperationChangedEventArgs>(Content_CurrentOperationChanged), sender, e);
139      } else {
140        if (Content.ExecutionState != ExecutionState.Started)
141          operationContentView.Content = new OperationContent(Content.CurrentOperation);
142      }
143    }
144
145    private void stepButton_Click(object sender, EventArgs e) {
146      Content.Step();
147      while (skipStackOpsCheckBox.Checked && !(Content.CurrentOperation is IAtomicOperation) && Content.CanContinue)
148        Content.Step();
149    }
150
151    private void refreshButton_Click(object sender, EventArgs e) {
152      var content = Content;
153      Content = null;
154      Content = content;
155    }
156
157  }
158}
Note: See TracBrowser for help on using the repository browser.