[4747] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7259] | 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[4747] | 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 |
|
---|
[4743] | 22 | using System;
|
---|
| 23 | using System.Windows.Forms;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Core.Views;
|
---|
| 26 | using HeuristicLab.MainForm;
|
---|
[5222] | 27 | using System.ComponentModel;
|
---|
[4743] | 28 | namespace HeuristicLab.DebugEngine {
|
---|
[4871] | 29 |
|
---|
[4743] | 30 | /// <summary>
|
---|
[4871] | 31 | /// Engine espcially for debugging
|
---|
[4743] | 32 | /// </summary>
|
---|
| 33 | [View("DebugEngine View")]
|
---|
| 34 | [Content(typeof(DebugEngine), true)]
|
---|
| 35 | public partial class DebugEngineView : ItemView {
|
---|
[4871] | 36 |
|
---|
| 37 | #region Basics
|
---|
| 38 |
|
---|
[4743] | 39 | /// <summary>
|
---|
| 40 | /// Gets or sets the current engine.
|
---|
| 41 | /// </summary>
|
---|
| 42 | /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="EditorBase"/>.</remarks>
|
---|
| 43 | public new DebugEngine Content {
|
---|
| 44 | get { return (DebugEngine)base.Content; }
|
---|
| 45 | set { base.Content = value; }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | /// <summary>
|
---|
[4871] | 49 | /// Initializes a new instance of <see cref="DebugEngineView"/>.
|
---|
[4743] | 50 | /// </summary>
|
---|
| 51 | public DebugEngineView() {
|
---|
| 52 | InitializeComponent();
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | /// <summary>
|
---|
| 56 | /// Removes the event handlers from the underlying <see cref="IEngine"/>.
|
---|
| 57 | /// </summary>
|
---|
| 58 | /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
| 59 | protected override void DeregisterContentEvents() {
|
---|
| 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 | }
|
---|
| 72 |
|
---|
| 73 | /// <summary>
|
---|
| 74 | /// Updates all controls with the latest data of the model.
|
---|
| 75 | /// </summary>
|
---|
| 76 | /// <remarks>Calls <see cref="EditorBase.UpdateControls"/> of base class <see cref="EditorBase"/>.</remarks>
|
---|
| 77 | protected override void OnContentChanged() {
|
---|
| 78 | base.OnContentChanged();
|
---|
| 79 | if (Content == null) {
|
---|
[4871] | 80 | executionStackView.Content = null;
|
---|
[4909] | 81 | operatorTraceView.Content = null;
|
---|
[4876] | 82 | operationContentView.Content = null;
|
---|
[4743] | 83 | } else {
|
---|
[4871] | 84 | executionStackView.Content = Content.ExecutionStack;
|
---|
[4909] | 85 | operatorTraceView.Content = Content.OperatorTrace;
|
---|
[4876] | 86 | operationContentView.Content = new OperationContent(Content.CurrentOperation);
|
---|
[4743] | 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | protected override void SetEnabledStateOfControls() {
|
---|
| 91 | base.SetEnabledStateOfControls();
|
---|
| 92 | if (Content == null) {
|
---|
[4876] | 93 | stepButton.Enabled = false;
|
---|
[4909] | 94 | refreshButton.Enabled = false;
|
---|
[4743] | 95 | } else {
|
---|
[4947] | 96 | stepButton.Enabled = Content.CanContinue && Content.ExecutionState != ExecutionState.Started;
|
---|
| 97 | refreshButton.Enabled = Content.CurrentAtomicOperation != null && Content.ExecutionState != ExecutionState.Started;
|
---|
[4743] | 98 | }
|
---|
| 99 | }
|
---|
| 100 |
|
---|
[4871] | 101 | #endregion
|
---|
| 102 |
|
---|
[4743] | 103 | void Content_ExecutionStateChanged(object sender, EventArgs e) {
|
---|
[4909] | 104 | if (InvokeRequired) {
|
---|
[4871] | 105 | Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
|
---|
[4909] | 106 | } else {
|
---|
[4993] | 107 | SetEnabledStateOfControls();
|
---|
[4871] | 108 | switch (Content.ExecutionState) {
|
---|
[4903] | 109 | case ExecutionState.Started:
|
---|
[4993] | 110 | if (!stepping) {
|
---|
| 111 | executionStackView.Content = null;
|
---|
| 112 | operatorTraceView.Content = null;
|
---|
| 113 | operationContentView.Content = null;
|
---|
| 114 | }
|
---|
[4903] | 115 | break;
|
---|
[4876] | 116 | default:
|
---|
[4993] | 117 | executionStackView.Content = Content.ExecutionStack;
|
---|
| 118 | operatorTraceView.Content = Content.OperatorTrace;
|
---|
[4876] | 119 | operationContentView.Content = new OperationContent(Content.CurrentOperation);
|
---|
| 120 | break;
|
---|
[4871] | 121 | }
|
---|
[4743] | 122 | }
|
---|
| 123 | }
|
---|
| 124 |
|
---|
[4993] | 125 | private bool stepping = false;
|
---|
[4743] | 126 | private void stepButton_Click(object sender, EventArgs e) {
|
---|
[5222] | 127 | BackgroundWorker worker = new BackgroundWorker();
|
---|
| 128 | bool skipStackops = skipStackOpsCheckBox.Checked;
|
---|
| 129 | worker.DoWork += (s, a) => {
|
---|
| 130 | Content.Step(skipStackops);
|
---|
| 131 | };
|
---|
| 132 | worker.RunWorkerCompleted += (s, a) => {
|
---|
| 133 | stepping = false;
|
---|
| 134 | SetEnabledStateOfControls();
|
---|
| 135 | };
|
---|
[4993] | 136 | stepping = true;
|
---|
[5222] | 137 | stepButton.Enabled = false;
|
---|
| 138 | worker.RunWorkerAsync();
|
---|
[4743] | 139 | }
|
---|
| 140 |
|
---|
[4903] | 141 | private void refreshButton_Click(object sender, EventArgs e) {
|
---|
| 142 | var content = Content;
|
---|
| 143 | Content = null;
|
---|
| 144 | Content = content;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
[4743] | 147 | }
|
---|
| 148 | }
|
---|