#region License Information
/* HeuristicLab
* Copyright (C) 2002-2015 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.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using HeuristicLab.Analysis;
using HeuristicLab.Collections;
using HeuristicLab.Common;
using HeuristicLab.Core.Views;
using HeuristicLab.Data;
using HeuristicLab.MainForm;
using HeuristicLab.MainForm.WindowsForms;
namespace HeuristicLab.Optimization.Views {
[View("Run-length Distribution View")]
[Content(typeof(RunCollection), false)]
public partial class RunCollectionRLDView : ItemView {
private const string AllRuns = "All Runs";
public new RunCollection Content {
get { return (RunCollection)base.Content; }
set { base.Content = value; }
}
private double[] levels;
private bool suppressUpdates;
private readonly IndexedDataTable combinedDataTable;
public IndexedDataTable CombinedDataTable {
get { return combinedDataTable; }
}
public RunCollectionRLDView() {
InitializeComponent();
combinedDataTable = new IndexedDataTable("Combined DataTable", "A data table containing the ECDF of each of a number of groups.") {
VisualProperties = { YAxisTitle = "Proportion of reached targets" }
};
viewHost.Content = combinedDataTable;
suppressUpdates = false;
}
#region Content events
protected override void RegisterContentEvents() {
base.RegisterContentEvents();
Content.ItemsAdded += Content_ItemsAdded;
Content.ItemsRemoved += Content_ItemsRemoved;
Content.CollectionReset += Content_CollectionReset;
Content.UpdateOfRunsInProgressChanged += Content_UpdateOfRunsInProgressChanged;
Content.OptimizerNameChanged += Content_AlgorithmNameChanged;
}
protected override void DeregisterContentEvents() {
Content.ItemsAdded -= Content_ItemsAdded;
Content.ItemsRemoved -= Content_ItemsRemoved;
Content.CollectionReset -= Content_CollectionReset;
Content.UpdateOfRunsInProgressChanged -= Content_UpdateOfRunsInProgressChanged;
Content.OptimizerNameChanged -= Content_AlgorithmNameChanged;
base.DeregisterContentEvents();
}
private void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs e) {
if (suppressUpdates) return;
if (InvokeRequired) {
Invoke(new CollectionItemsChangedEventHandler(Content_ItemsAdded), sender, e);
return;
}
UpdateGroupComboBox();
UpdateDataTableComboBox();
foreach (var run in e.Items)
RegisterRunEvents(run);
}
private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs e) {
if (suppressUpdates) return;
if (InvokeRequired) {
Invoke(new CollectionItemsChangedEventHandler(Content_ItemsRemoved), sender, e);
return;
}
UpdateGroupComboBox();
UpdateDataTableComboBox();
foreach (var run in e.Items)
DeregisterRunEvents(run);
}
private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs e) {
if (suppressUpdates) return;
if (InvokeRequired) {
Invoke(new CollectionItemsChangedEventHandler(Content_CollectionReset), sender, e);
return;
}
UpdateGroupComboBox();
UpdateDataTableComboBox();
foreach (var run in e.OldItems)
DeregisterRunEvents(run);
}
private void Content_AlgorithmNameChanged(object sender, EventArgs e) {
if (InvokeRequired)
Invoke(new EventHandler(Content_AlgorithmNameChanged), sender, e);
else UpdateCaption();
}
private void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
if (InvokeRequired) {
Invoke(new EventHandler(Content_UpdateOfRunsInProgressChanged), sender, e);
return;
}
suppressUpdates = Content.UpdateOfRunsInProgress;
if (!suppressUpdates) {
UpdateDataTableComboBox();
UpdateGroupComboBox();
UpdateRuns();
}
}
private void RegisterRunEvents(IRun run) {
run.PropertyChanged += run_PropertyChanged;
}
private void DeregisterRunEvents(IRun run) {
run.PropertyChanged -= run_PropertyChanged;
}
private void run_PropertyChanged(object sender, PropertyChangedEventArgs e) {
if (suppressUpdates) return;
if (InvokeRequired) {
Invoke((Action