#region License Information
/* HeuristicLab
* Copyright (C) 2002-2016 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 HeuristicLab.Common;
using HeuristicLab.MainForm;
using HeuristicLab.MainForm.WindowsForms;
using HeuristicLab.Optimization;
using HeuristicLab.OptimizationExpertSystem.Common;
using System;
namespace HeuristicLab.OptimizationExpertSystem {
[View("Expert-System View")]
public partial class KnowledgeCenterViewBase : AsynchronousContentView {
public OptimizationKnowledgeCenter MainForm {
get { return (OptimizationKnowledgeCenter)HeuristicLab.MainForm.MainFormManager.MainForm; }
}
public new KnowledgeCenter Content {
get { return (KnowledgeCenter)base.Content; }
set { base.Content = value; }
}
protected KnowledgeCenterViewBase() {
InitializeComponent();
}
#region Event Registration
protected override void RegisterContentEvents() {
base.RegisterContentEvents();
Content.DownloadStarted += ContentOnDownloadStarted;
Content.AlgorithmInstanceStarted += ContentOnAlgorithmInstanceStarted;
RegisterContentProblemEvents();
RegisterContentProblemInstancesEvents();
RegisterContentProblemCharacteristicsEvents();
RegisterContentSolutionSeedingPoolEvents();
RegisterContentSuggestedInstancesEvents();
}
private void RegisterContentProblemEvents() {
Content.Problem.ProblemChanged += ContentOnProblemChanged;
Content.Problem.Solutions.CollectionReset += ContentOnProblemSolutionsChanged;
Content.Problem.Solutions.ItemsAdded += ContentOnProblemSolutionsChanged;
Content.Problem.Solutions.ItemsReplaced += ContentOnProblemSolutionsChanged;
Content.Problem.Solutions.ItemsRemoved += ContentOnProblemSolutionsChanged;
}
private void RegisterContentProblemInstancesEvents() {
Content.ProblemInstances.UpdateOfRunsInProgressChanged += ContentOnProblemInstancesChanged;
Content.ProblemInstances.ItemsAdded += ContentOnProblemInstancesChanged;
Content.ProblemInstances.ItemsRemoved += ContentOnProblemInstancesChanged;
Content.ProblemInstances.CollectionReset += ContentOnProblemInstancesChanged;
Content.ProblemInstances.ItemChanged += ContentOnProblemInstancesChanged;
}
private void RegisterContentProblemCharacteristicsEvents() {
Content.ProblemCharacteristics.ItemsAdded += ContentOnProblemCharacteristicsChanged;
Content.ProblemCharacteristics.ItemsReplaced += ContentOnProblemCharacteristicsChanged;
Content.ProblemCharacteristics.ItemsRemoved += ContentOnProblemCharacteristicsChanged;
Content.ProblemCharacteristics.CheckedItemsChanged += ContentOnProblemCharacteristicsChanged;
Content.ProblemCharacteristics.CollectionReset += ContentOnProblemCharacteristicsChanged;
}
private void RegisterContentSolutionSeedingPoolEvents() {
Content.SolutionSeedingPool.CheckedItemsChanged += ContentOnSolutionSeedingPoolChanged;
Content.SolutionSeedingPool.CollectionReset += ContentOnSolutionSeedingPoolChanged;
Content.SolutionSeedingPool.ItemsAdded += ContentOnSolutionSeedingPoolChanged;
Content.SolutionSeedingPool.ItemsRemoved += ContentOnSolutionSeedingPoolChanged;
Content.SolutionSeedingPool.ItemsReplaced += ContentOnSolutionSeedingPoolChanged;
}
private void RegisterContentSuggestedInstancesEvents() {
Content.SuggestedInstances.CollectionReset += ContentOnSuggestedInstancesChanged;
Content.SuggestedInstances.ItemsAdded += ContentOnSuggestedInstancesChanged;
Content.SuggestedInstances.ItemsMoved += ContentOnSuggestedInstancesChanged;
Content.SuggestedInstances.ItemsRemoved += ContentOnSuggestedInstancesChanged;
Content.SuggestedInstances.ItemsReplaced += ContentOnSuggestedInstancesChanged;
}
protected override void DeregisterContentEvents() {
base.DeregisterContentEvents();
Content.DownloadStarted -= ContentOnDownloadStarted;
Content.AlgorithmInstanceStarted -= ContentOnAlgorithmInstanceStarted;
DeregisterContentProblemEvents();
DeregisterContentProblemInstancesEvents();
DeregisterContentProblemCharacteristicsEvents();
DeregisterContentSolutionSeedingPoolEvents();
DeregisterContentSuggestedInstancesEvents();
}
private void DeregisterContentProblemEvents() {
Content.Problem.ProblemChanged -= ContentOnProblemChanged;
Content.Problem.Solutions.CollectionReset -= ContentOnProblemSolutionsChanged;
Content.Problem.Solutions.ItemsAdded -= ContentOnProblemSolutionsChanged;
Content.Problem.Solutions.ItemsReplaced -= ContentOnProblemSolutionsChanged;
Content.Problem.Solutions.ItemsRemoved -= ContentOnProblemSolutionsChanged;
}
private void DeregisterContentProblemInstancesEvents() {
Content.ProblemInstances.UpdateOfRunsInProgressChanged -= ContentOnProblemInstancesChanged;
Content.ProblemInstances.ItemsAdded -= ContentOnProblemInstancesChanged;
Content.ProblemInstances.ItemsRemoved -= ContentOnProblemInstancesChanged;
Content.ProblemInstances.CollectionReset -= ContentOnProblemInstancesChanged;
Content.ProblemInstances.ItemChanged -= ContentOnProblemInstancesChanged;
}
private void DeregisterContentProblemCharacteristicsEvents() {
Content.ProblemCharacteristics.ItemsAdded -= ContentOnProblemCharacteristicsChanged;
Content.ProblemCharacteristics.ItemsReplaced -= ContentOnProblemCharacteristicsChanged;
Content.ProblemCharacteristics.ItemsRemoved -= ContentOnProblemCharacteristicsChanged;
Content.ProblemCharacteristics.CheckedItemsChanged -= ContentOnProblemCharacteristicsChanged;
Content.ProblemCharacteristics.CollectionReset -= ContentOnProblemCharacteristicsChanged;
}
private void DeregisterContentSolutionSeedingPoolEvents() {
Content.SolutionSeedingPool.CheckedItemsChanged -= ContentOnSolutionSeedingPoolChanged;
Content.SolutionSeedingPool.CollectionReset -= ContentOnSolutionSeedingPoolChanged;
Content.SolutionSeedingPool.ItemsAdded -= ContentOnSolutionSeedingPoolChanged;
Content.SolutionSeedingPool.ItemsRemoved -= ContentOnSolutionSeedingPoolChanged;
Content.SolutionSeedingPool.ItemsReplaced -= ContentOnSolutionSeedingPoolChanged;
}
private void DeregisterContentSuggestedInstancesEvents() {
Content.SuggestedInstances.CollectionReset -= ContentOnSuggestedInstancesChanged;
Content.SuggestedInstances.ItemsAdded -= ContentOnSuggestedInstancesChanged;
Content.SuggestedInstances.ItemsMoved -= ContentOnSuggestedInstancesChanged;
Content.SuggestedInstances.ItemsRemoved -= ContentOnSuggestedInstancesChanged;
Content.SuggestedInstances.ItemsReplaced -= ContentOnSuggestedInstancesChanged;
}
#endregion
protected virtual void OnDownloadStarted(IProgress progress) { }
protected virtual void OnDownloadEnded() { }
protected virtual void OnAlgorithmInstanceStarted(IAlgorithm algorithm) { }
protected virtual void OnPropertyChanged(string propertyName) { }
protected virtual void OnProblemChanged() { }
protected virtual void OnProblemSolutionsChanged() { }
protected virtual void OnProblemInstancesChanged() { }
protected virtual void OnProblemCharacteristicsChanged() { }
protected virtual void OnSolutionSeedingPoolChanged() { }
protected virtual void OnSuggestedInstancesChanged() { }
protected virtual void OnKnowledgeBaseChanged() { }
#region Content Event Handlers
private void ContentOnDownloadStarted(object sender, EventArgs e) {
if (InvokeRequired) { Invoke((Action