Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.DebugEngine/3.3/DebugEngineView.cs @ 5114

Last change on this file since 5114 was 5114, checked in by swagner, 13 years ago

Integrated DebugEngine into trunk (#47).

File size: 4.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.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);
60      base.DeregisterContentEvents();
61    }
62
63    /// <summary>
64    /// Adds event handlers to the underlying <see cref="IEngine"/>.
65    /// </summary>
66    /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
67    protected override void RegisterContentEvents() {
68      base.RegisterContentEvents();
69      Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
70    }
71
72    /// <summary>
73    /// Updates all controls with the latest data of the model.
74    /// </summary>
75    /// <remarks>Calls <see cref="EditorBase.UpdateControls"/> of base class <see cref="EditorBase"/>.</remarks>
76    protected override void OnContentChanged() {
77      base.OnContentChanged();
78      if (Content == null) {
79        executionStackView.Content = null;
80        operatorTraceView.Content = null;
81        operationContentView.Content = null;
82      } else {
83        executionStackView.Content = Content.ExecutionStack;
84        operatorTraceView.Content = Content.OperatorTrace;
85        operationContentView.Content = new OperationContent(Content.CurrentOperation);
86      }
87    }
88
89    protected override void SetEnabledStateOfControls() {
90      base.SetEnabledStateOfControls();
91      if (Content == null) {
92        stepButton.Enabled = false;
93        refreshButton.Enabled = false;
94      } else {
95        stepButton.Enabled = Content.CanContinue && Content.ExecutionState != ExecutionState.Started;
96        refreshButton.Enabled = Content.CurrentAtomicOperation != null && Content.ExecutionState != ExecutionState.Started;
97      }
98    }
99
100    #endregion
101
102    void Content_ExecutionStateChanged(object sender, EventArgs e) {
103      if (InvokeRequired) {
104        Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
105      } else {
106        SetEnabledStateOfControls();
107        switch (Content.ExecutionState) {
108          case ExecutionState.Started:
109            if (!stepping) {
110              executionStackView.Content = null;
111              operatorTraceView.Content = null;
112              operationContentView.Content = null;
113            }
114            break;
115          default:
116            executionStackView.Content = Content.ExecutionStack;
117            operatorTraceView.Content = Content.OperatorTrace;
118            operationContentView.Content = new OperationContent(Content.CurrentOperation);
119            break;
120        }
121      }
122    }
123
124    private bool stepping = false;
125    private void stepButton_Click(object sender, EventArgs e) {
126      stepping = true;
127      Content.Step(skipStackOpsCheckBox.Checked);
128      stepping = false;
129    }
130
131    private void refreshButton_Click(object sender, EventArgs e) {
132      var content = Content;
133      Content = null;
134      Content = content;
135    }
136
137  }
138}
Note: See TracBrowser for help on using the repository browser.