[4747] | 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 |
|
---|
[4743] | 22 | using System;
|
---|
| 23 | using System.Windows.Forms;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Core.Views;
|
---|
| 26 | using HeuristicLab.MainForm;
|
---|
| 27 | namespace HeuristicLab.DebugEngine {
|
---|
[4871] | 28 |
|
---|
[4743] | 29 | /// <summary>
|
---|
[4871] | 30 | /// Engine espcially for debugging
|
---|
[4743] | 31 | /// </summary>
|
---|
| 32 | [View("DebugEngine View")]
|
---|
| 33 | [Content(typeof(DebugEngine), true)]
|
---|
| 34 | public partial class DebugEngineView : ItemView {
|
---|
[4871] | 35 |
|
---|
| 36 | #region Basics
|
---|
| 37 |
|
---|
[4743] | 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>
|
---|
[4871] | 48 | /// Initializes a new instance of <see cref="DebugEngineView"/>.
|
---|
[4743] | 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() {
|
---|
[4871] | 59 | Content.CurrentOperationChanged -= new EventHandler<OperationChangedEventArgs>(Content_CurrentOperationChanged);
|
---|
[4743] | 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);
|
---|
[4871] | 71 | Content.CurrentOperationChanged += new EventHandler<OperationChangedEventArgs>(Content_CurrentOperationChanged);
|
---|
[4743] | 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) {
|
---|
[4871] | 81 | executionStackView.Content = null;
|
---|
[4909] | 82 | operatorTraceView.Content = null;
|
---|
[4876] | 83 | operationContentView.Content = null;
|
---|
[4743] | 84 | } else {
|
---|
[4871] | 85 | executionStackView.Content = Content.ExecutionStack;
|
---|
[4909] | 86 | operatorTraceView.Content = Content.OperatorTrace;
|
---|
[4876] | 87 | operationContentView.Content = new OperationContent(Content.CurrentOperation);
|
---|
[4743] | 88 | }
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | protected override void SetEnabledStateOfControls() {
|
---|
| 92 | base.SetEnabledStateOfControls();
|
---|
| 93 | if (Content == null) {
|
---|
[4876] | 94 | stepButton.Enabled = false;
|
---|
[4909] | 95 | refreshButton.Enabled = false;
|
---|
[4743] | 96 | } else {
|
---|
[4876] | 97 | stepButton.Enabled = Content.CanContinue;
|
---|
[4909] | 98 | refreshButton.Enabled = Content.CurrentAtomicOperation != null;
|
---|
[4743] | 99 | }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[4871] | 102 | #endregion
|
---|
| 103 |
|
---|
[4743] | 104 | void Content_ExecutionStateChanged(object sender, EventArgs e) {
|
---|
[4909] | 105 | if (InvokeRequired) {
|
---|
[4871] | 106 | Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
|
---|
[4909] | 107 | } else {
|
---|
[4871] | 108 | switch (Content.ExecutionState) {
|
---|
[4903] | 109 | case ExecutionState.Started:
|
---|
| 110 | executionStackView.SuspendUpdate();
|
---|
[4909] | 111 | operatorTraceView.SuspendUpdate();
|
---|
[4903] | 112 | break;
|
---|
[4876] | 113 | default:
|
---|
| 114 | executionStackView.ResumeUpdate();
|
---|
| 115 | operationContentView.Content = new OperationContent(Content.CurrentOperation);
|
---|
[4909] | 116 | operatorTraceView.ResumeUpdate();
|
---|
[4876] | 117 | break;
|
---|
[4871] | 118 | }
|
---|
[4876] | 119 | SetEnabledStateOfControls();
|
---|
[4743] | 120 | }
|
---|
| 121 | }
|
---|
| 122 |
|
---|
[4871] | 123 | void Content_CurrentOperationChanged(object sender, OperationChangedEventArgs e) {
|
---|
[4876] | 124 | if (InvokeRequired) {
|
---|
[4871] | 125 | Invoke(new EventHandler<OperationChangedEventArgs>(Content_CurrentOperationChanged), sender, e);
|
---|
| 126 | } else {
|
---|
[4909] | 127 |
|
---|
[4871] | 128 | }
|
---|
| 129 | }
|
---|
| 130 |
|
---|
[4743] | 131 | private void stepButton_Click(object sender, EventArgs e) {
|
---|
[4909] | 132 | Content.Step(skipStackOpsCheckBox.Checked);
|
---|
[4743] | 133 | }
|
---|
| 134 |
|
---|
[4903] | 135 | private void refreshButton_Click(object sender, EventArgs e) {
|
---|
| 136 | var content = Content;
|
---|
| 137 | Content = null;
|
---|
| 138 | Content = content;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
[4743] | 141 | }
|
---|
| 142 | }
|
---|