[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();
|
---|
[4759] | 56 | updateButton.Image = VS2008ImageLibrary.Refresh;
|
---|
| 57 | stepButton.Image = VS2008ImageLibrary.MoveNext;
|
---|
| 58 | parentButton.Image = VS2008ImageLibrary.ArrowUp;
|
---|
[4743] | 59 | }
|
---|
| 60 |
|
---|
| 61 | /// <summary>
|
---|
| 62 | /// Removes the event handlers from the underlying <see cref="IEngine"/>.
|
---|
| 63 | /// </summary>
|
---|
| 64 | /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
| 65 | protected override void DeregisterContentEvents() {
|
---|
[4871] | 66 | Content.CurrentOperationChanged -= new EventHandler<OperationChangedEventArgs>(Content_CurrentOperationChanged);
|
---|
[4743] | 67 | Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
|
---|
| 68 | Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);
|
---|
| 69 | base.DeregisterContentEvents();
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | /// <summary>
|
---|
| 73 | /// Adds event handlers to the underlying <see cref="IEngine"/>.
|
---|
| 74 | /// </summary>
|
---|
| 75 | /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
| 76 | protected override void RegisterContentEvents() {
|
---|
| 77 | base.RegisterContentEvents();
|
---|
| 78 | Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
|
---|
| 79 | Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
|
---|
[4871] | 80 | Content.CurrentOperationChanged += new EventHandler<OperationChangedEventArgs>(Content_CurrentOperationChanged);
|
---|
[4743] | 81 | }
|
---|
| 82 |
|
---|
| 83 | /// <summary>
|
---|
| 84 | /// Updates all controls with the latest data of the model.
|
---|
| 85 | /// </summary>
|
---|
| 86 | /// <remarks>Calls <see cref="EditorBase.UpdateControls"/> of base class <see cref="EditorBase"/>.</remarks>
|
---|
| 87 | protected override void OnContentChanged() {
|
---|
| 88 | base.OnContentChanged();
|
---|
| 89 | if (Content == null) {
|
---|
| 90 | logView.Content = null;
|
---|
| 91 | executionTimeTextBox.Text = "-";
|
---|
[4871] | 92 | executionStackView.Content = null;
|
---|
[4743] | 93 | } else {
|
---|
| 94 | logView.Content = Content.Log;
|
---|
| 95 | executionTimeTextBox.Text = Content.ExecutionTime.ToString();
|
---|
[4871] | 96 | executionStackView.Content = Content.ExecutionStack;
|
---|
[4743] | 97 | }
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | protected override void SetEnabledStateOfControls() {
|
---|
| 101 | base.SetEnabledStateOfControls();
|
---|
| 102 | if (Content == null) {
|
---|
| 103 | logView.Enabled = false;
|
---|
| 104 | executionTimeTextBox.Enabled = false;
|
---|
| 105 | } else {
|
---|
| 106 | logView.Enabled = true;
|
---|
| 107 | executionTimeTextBox.Enabled = true;
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[4871] | 111 | #endregion
|
---|
| 112 |
|
---|
[4743] | 113 | protected virtual void Content_ExecutionTimeChanged(object sender, EventArgs e) {
|
---|
| 114 | if (InvokeRequired)
|
---|
| 115 | Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
|
---|
| 116 | else
|
---|
| 117 | executionTimeTextBox.Text = Content == null ? "-" : Content.ExecutionTime.ToString();
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | void Content_ExecutionStateChanged(object sender, EventArgs e) {
|
---|
[4871] | 121 | if (InvokeRequired)
|
---|
| 122 | Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
|
---|
| 123 | else {
|
---|
| 124 | switch (Content.ExecutionState) {
|
---|
| 125 | case ExecutionState.Started: executionStackView.SuspendUpdate(); break;
|
---|
| 126 | default: executionStackView.ResumeUpdate(); break;
|
---|
| 127 | }
|
---|
[4743] | 128 | }
|
---|
| 129 | }
|
---|
| 130 |
|
---|
[4871] | 131 | #region Current Operation
|
---|
| 132 |
|
---|
| 133 | void Content_CurrentOperationChanged(object sender, OperationChangedEventArgs e) {
|
---|
| 134 | if (InvokeRequired)
|
---|
| 135 | Invoke(new EventHandler<OperationChangedEventArgs>(Content_CurrentOperationChanged), sender, e);
|
---|
| 136 | else
|
---|
[4759] | 137 | SetOperation(Content.CurrentOperation);
|
---|
| 138 | }
|
---|
[4743] | 139 |
|
---|
[4759] | 140 | private void SetOperation(IOperation operation) {
|
---|
| 141 | IAtomicOperation atomicOperation = operation as IAtomicOperation;
|
---|
| 142 | operationTextBox.Text = "<none>";
|
---|
[4765] | 143 | parameterCollectionView.Content = null;
|
---|
[4759] | 144 | toolTip.SetToolTip(operationTextBox, null);
|
---|
| 145 | if (atomicOperation != null && atomicOperation.Operator != null) {
|
---|
| 146 | operationTextBox.Text = string.Format("Atomic {0}", atomicOperation.Operator.Name);
|
---|
[4871] | 147 | toolTip.SetToolTip(operationTextBox, Utils.TypeName(atomicOperation.Operator));
|
---|
[4759] | 148 | }
|
---|
| 149 | OperationCollection operationCollection = operation as OperationCollection;
|
---|
| 150 | if (operationCollection != null)
|
---|
| 151 | operationTextBox.Text = string.Format("Collection {0}", operationCollection.Count);
|
---|
| 152 | IExecutionContext context = operation as IExecutionContext;
|
---|
| 153 | IScope scope = null;
|
---|
| 154 | if (context != null) {
|
---|
[4765] | 155 | parameterCollectionView.Content = context.Parameters;
|
---|
[4759] | 156 | scope = context.Scope;
|
---|
| 157 | while (scope != null && scope.Parent != null)
|
---|
| 158 | scope = scope.Parent;
|
---|
| 159 | }
|
---|
| 160 | UpdateScope(scope);
|
---|
| 161 | if (context != null)
|
---|
| 162 | parentButton.Enabled = context.Parent != null;
|
---|
| 163 | scopeTreeView.Tag = context;
|
---|
| 164 | }
|
---|
[4753] | 165 |
|
---|
[4759] | 166 | private void UpdateScope(IScope scope) {
|
---|
| 167 | scopeTreeView.BeginUpdate();
|
---|
| 168 | scopeTreeView.Nodes.Clear();
|
---|
| 169 | if (scope != null) {
|
---|
| 170 | AddScope(scopeTreeView.Nodes, scope);
|
---|
[4743] | 171 | }
|
---|
[4759] | 172 | scopeTreeView.ExpandAll();
|
---|
| 173 | if (scopeTreeView.Nodes.Count > 0)
|
---|
| 174 | scopeTreeView.TopNode = scopeTreeView.Nodes[0];
|
---|
| 175 | scopeTreeView.EndUpdate();
|
---|
[4743] | 176 | }
|
---|
| 177 |
|
---|
[4871] | 178 |
|
---|
[4753] | 179 |
|
---|
[4871] | 180 | /*
|
---|
[4753] | 181 | private string GetApproximateValue(IParameter param, ref string typeName) {
|
---|
[4759] | 182 | string valueString = "<none>";
|
---|
| 183 | IExecutionContext context = Content.CurrentOperation as IExecutionContext;
|
---|
| 184 | IExecutionContext originalContext = param.ExecutionContext;
|
---|
| 185 | object value = null;
|
---|
[4753] | 186 | try {
|
---|
[4759] | 187 | try {
|
---|
[4753] | 188 | param.ExecutionContext = context;
|
---|
[4759] | 189 | value = param.ActualValue;
|
---|
| 190 | } finally {
|
---|
| 191 | param.ExecutionContext = originalContext;
|
---|
[4753] | 192 | }
|
---|
| 193 | } catch (Exception) { }
|
---|
[4759] | 194 | if (value != null) {
|
---|
| 195 | valueString = value.ToString();
|
---|
| 196 | if (context != originalContext)
|
---|
| 197 | valueString = " ~ " + valueString;
|
---|
| 198 | typeName = TypeName(value);
|
---|
| 199 | }
|
---|
| 200 | return valueString;
|
---|
[4753] | 201 | }
|
---|
[4871] | 202 | */
|
---|
[4753] | 203 |
|
---|
[4743] | 204 | private void AddScope(TreeNodeCollection nodes, IScope scope) {
|
---|
| 205 | TreeNode node = nodes.Add(scope.Name);
|
---|
[4871] | 206 | if (Content.CurrentAtomicOperation != null && Content.CurrentAtomicOperation.Scope == scope) {
|
---|
[4759] | 207 | node.ForeColor = Color.Red;
|
---|
| 208 | node.BackColor = Color.LightGray;
|
---|
| 209 | }
|
---|
[4743] | 210 | foreach (var var in scope.Variables) {
|
---|
[4746] | 211 | TreeNode varNode = node.Nodes.Add(string.Format("{0}={1}", var.Name, var.Value.ToString()));
|
---|
| 212 | varNode.Tag = var.Value;
|
---|
[4871] | 213 | varNode.ToolTipText = Utils.TypeName(var.Value);
|
---|
[4743] | 214 | }
|
---|
| 215 | foreach (var subScope in scope.SubScopes) {
|
---|
| 216 | AddScope(node.Nodes, subScope);
|
---|
| 217 | }
|
---|
| 218 | }
|
---|
| 219 |
|
---|
[4871] | 220 | #endregion
|
---|
| 221 |
|
---|
| 222 | protected virtual void UpdateView() {
|
---|
| 223 | if (InvokeRequired) {
|
---|
| 224 | Invoke(new Action(UpdateView));
|
---|
| 225 | } else {
|
---|
| 226 | SetOperation(Content.CurrentOperation);
|
---|
| 227 | }
|
---|
| 228 | }
|
---|
| 229 |
|
---|
[4743] | 230 | private void stepButton_Click(object sender, EventArgs e) {
|
---|
| 231 | Content.Step();
|
---|
| 232 | UpdateView();
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | private void updateButton_Click(object sender, EventArgs e) {
|
---|
| 236 | UpdateView();
|
---|
| 237 | }
|
---|
[4746] | 238 |
|
---|
| 239 | private void scopeTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) {
|
---|
| 240 | if (e.Node.Tag != null)
|
---|
| 241 | MainFormManager.MainForm.ShowContent((IItem)e.Node.Tag);
|
---|
| 242 | }
|
---|
[4759] | 243 |
|
---|
| 244 | private void parentButton_Click(object sender, EventArgs e) {
|
---|
| 245 | IExecutionContext context = scopeTreeView.Tag as IExecutionContext;
|
---|
| 246 | if (context != null) {
|
---|
| 247 | SetOperation(context.Parent as IOperation);
|
---|
| 248 | }
|
---|
| 249 | }
|
---|
[4743] | 250 | }
|
---|
| 251 | }
|
---|