Free cookie consent management tool by TermsFeed Policy Generator

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

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

Several GUI improvements (#47)

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