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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Drawing;
|
---|
25 | using System.Windows.Forms;
|
---|
26 | using HeuristicLab.Common.Resources;
|
---|
27 | using HeuristicLab.Core;
|
---|
28 | using HeuristicLab.Core.Views;
|
---|
29 | using HeuristicLab.MainForm;
|
---|
30 | using HeuristicLab.Persistence.Auxiliary;
|
---|
31 | namespace HeuristicLab.DebugEngine {
|
---|
32 |
|
---|
33 | /// <summary>
|
---|
34 | /// Engine espcially for debugging
|
---|
35 | /// </summary>
|
---|
36 | [View("DebugEngine View")]
|
---|
37 | [Content(typeof(DebugEngine), true)]
|
---|
38 | public partial class DebugEngineView : ItemView {
|
---|
39 |
|
---|
40 | #region Basics
|
---|
41 |
|
---|
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>
|
---|
52 | /// Initializes a new instance of <see cref="DebugEngineView"/>.
|
---|
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() {
|
---|
63 | Content.CurrentOperationChanged -= new EventHandler<OperationChangedEventArgs>(Content_CurrentOperationChanged);
|
---|
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);
|
---|
77 | Content.CurrentOperationChanged += new EventHandler<OperationChangedEventArgs>(Content_CurrentOperationChanged);
|
---|
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 = "-";
|
---|
89 | executionStackView.Content = null;
|
---|
90 | operationContentView.Content = null;
|
---|
91 | } else {
|
---|
92 | logView.Content = Content.Log;
|
---|
93 | executionTimeTextBox.Text = Content.ExecutionTime.ToString();
|
---|
94 | executionStackView.Content = Content.ExecutionStack;
|
---|
95 | operationContentView.Content = new OperationContent(Content.CurrentOperation);
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | protected override void SetEnabledStateOfControls() {
|
---|
100 | base.SetEnabledStateOfControls();
|
---|
101 | if (Content == null) {
|
---|
102 | logView.Enabled = false;
|
---|
103 | executionTimeTextBox.Enabled = false;
|
---|
104 | stepButton.Enabled = false;
|
---|
105 | } else {
|
---|
106 | logView.Enabled = true;
|
---|
107 | executionTimeTextBox.Enabled = true;
|
---|
108 | stepButton.Enabled = Content.CanContinue;
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | #endregion
|
---|
113 |
|
---|
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) {
|
---|
122 | if (InvokeRequired)
|
---|
123 | Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
|
---|
124 | else {
|
---|
125 | switch (Content.ExecutionState) {
|
---|
126 | case ExecutionState.Started: executionStackView.SuspendUpdate(); break;
|
---|
127 | default:
|
---|
128 | executionStackView.ResumeUpdate();
|
---|
129 | operationContentView.Content = new OperationContent(Content.CurrentOperation);
|
---|
130 | break;
|
---|
131 | }
|
---|
132 | SetEnabledStateOfControls();
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 | void Content_CurrentOperationChanged(object sender, OperationChangedEventArgs e) {
|
---|
137 | if (InvokeRequired) {
|
---|
138 | Invoke(new EventHandler<OperationChangedEventArgs>(Content_CurrentOperationChanged), sender, e);
|
---|
139 | } else {
|
---|
140 | if (Content.ExecutionState != ExecutionState.Started)
|
---|
141 | operationContentView.Content = new OperationContent(Content.CurrentOperation);
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|
145 | private void stepButton_Click(object sender, EventArgs e) {
|
---|
146 | Content.Step();
|
---|
147 | }
|
---|
148 |
|
---|
149 | }
|
---|
150 | }
|
---|