#region License Information /* HeuristicLab * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using HeuristicLab.Common.Resources; using HeuristicLab.Core; using HeuristicLab.Core.Views; using HeuristicLab.MainForm; using HeuristicLab.Persistence.Auxiliary; namespace HeuristicLab.DebugEngine { /// /// Engine espcially for debugging /// [View("DebugEngine View")] [Content(typeof(DebugEngine), true)] public partial class DebugEngineView : ItemView { #region Basics /// /// Gets or sets the current engine. /// /// Uses property of base class . public new DebugEngine Content { get { return (DebugEngine)base.Content; } set { base.Content = value; } } /// /// Initializes a new instance of . /// public DebugEngineView() { InitializeComponent(); } /// /// Removes the event handlers from the underlying . /// /// Calls of base class . protected override void DeregisterContentEvents() { Content.CurrentOperationChanged -= new EventHandler(Content_CurrentOperationChanged); Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged); Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged); base.DeregisterContentEvents(); } /// /// Adds event handlers to the underlying . /// /// Calls of base class . protected override void RegisterContentEvents() { base.RegisterContentEvents(); Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged); Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged); Content.CurrentOperationChanged += new EventHandler(Content_CurrentOperationChanged); } /// /// Updates all controls with the latest data of the model. /// /// Calls of base class . protected override void OnContentChanged() { base.OnContentChanged(); if (Content == null) { logView.Content = null; executionTimeTextBox.Text = "-"; executionStackView.Content = null; operationContentView.Content = null; } else { logView.Content = Content.Log; executionTimeTextBox.Text = Content.ExecutionTime.ToString(); executionStackView.Content = Content.ExecutionStack; operationContentView.Content = new OperationContent(Content.CurrentOperation); } } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); if (Content == null) { logView.Enabled = false; executionTimeTextBox.Enabled = false; stepButton.Enabled = false; } else { logView.Enabled = true; executionTimeTextBox.Enabled = true; stepButton.Enabled = Content.CanContinue; } } #endregion protected virtual void Content_ExecutionTimeChanged(object sender, EventArgs e) { if (InvokeRequired) Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e); else executionTimeTextBox.Text = Content == null ? "-" : Content.ExecutionTime.ToString(); } void Content_ExecutionStateChanged(object sender, EventArgs e) { if (InvokeRequired) Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e); else { switch (Content.ExecutionState) { case ExecutionState.Started: executionStackView.SuspendUpdate(); break; default: executionStackView.ResumeUpdate(); operationContentView.Content = new OperationContent(Content.CurrentOperation); break; } SetEnabledStateOfControls(); } } void Content_CurrentOperationChanged(object sender, OperationChangedEventArgs e) { if (InvokeRequired) { Invoke(new EventHandler(Content_CurrentOperationChanged), sender, e); } else { if (Content.ExecutionState != ExecutionState.Started) operationContentView.Content = new OperationContent(Content.CurrentOperation); } } private void stepButton_Click(object sender, EventArgs e) { Content.Step(); } } }