#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;
Content.RecommendationModelChanged += ContentOnRecommendationModelChanged;
RegisterContentProblemEvents();
RegisterContentProblemInstancesEvents();
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 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.AlgorithmInstances.CollectionReset += ContentOnAlgorithmInstancesChanged;
Content.AlgorithmInstances.ItemsAdded += ContentOnAlgorithmInstancesChanged;
Content.AlgorithmInstances.ItemsMoved += ContentOnAlgorithmInstancesChanged;
Content.AlgorithmInstances.ItemsRemoved += ContentOnAlgorithmInstancesChanged;
Content.AlgorithmInstances.ItemsReplaced += ContentOnAlgorithmInstancesChanged;
}
protected override void DeregisterContentEvents() {
base.DeregisterContentEvents();
Content.DownloadStarted -= ContentOnDownloadStarted;
Content.AlgorithmInstanceStarted -= ContentOnAlgorithmInstanceStarted;
Content.RecommendationModelChanged -= ContentOnRecommendationModelChanged;
DeregisterContentProblemEvents();
DeregisterContentProblemInstancesEvents();
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 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.AlgorithmInstances.CollectionReset -= ContentOnAlgorithmInstancesChanged;
Content.AlgorithmInstances.ItemsAdded -= ContentOnAlgorithmInstancesChanged;
Content.AlgorithmInstances.ItemsMoved -= ContentOnAlgorithmInstancesChanged;
Content.AlgorithmInstances.ItemsRemoved -= ContentOnAlgorithmInstancesChanged;
Content.AlgorithmInstances.ItemsReplaced -= ContentOnAlgorithmInstancesChanged;
}
#endregion
protected virtual void OnDownloadStarted(IProgress progress) { }
protected virtual void OnDownloadEnded() { }
protected virtual void OnAlgorithmInstanceStarted(IAlgorithm algorithm) { }
protected virtual void OnRecommendationModelChanged() { }
protected virtual void OnPropertyChanged(string propertyName) { }
protected virtual void OnProblemChanged() { }
protected virtual void OnProblemSolutionsChanged() { }
protected virtual void OnProblemInstancesChanged() { }
protected virtual void OnSolutionSeedingPoolChanged() { }
protected virtual void OnAlgorithmInstancesChanged() { }
protected virtual void OnKnowledgeBaseChanged() { }
#region Content Event Handlers
private void ContentOnDownloadStarted(object sender, EventArgs e) {
if (InvokeRequired) { Invoke((Action