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