#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>)ContentOnDownloadStarted, sender, e); return; } MainForm.AddOperationProgressToView(this, e.Value); e.Value.ProgressStateChanged += ProgressOnStateChanged; OnDownloadStarted(e.Value); } private void ContentOnAlgorithmInstanceStarted(object sender, EventArgs e) { if (InvokeRequired) { Invoke((Action>)ContentOnAlgorithmInstanceStarted, sender, e); return; } OnAlgorithmInstanceStarted(e.Value); } private void ProgressOnStateChanged(object sender, EventArgs e) { if (InvokeRequired) { Invoke((Action)ProgressOnStateChanged, sender, e); return; } var progress = (IProgress)sender; if (progress == null || progress.ProgressState == ProgressState.Started) return; OnDownloadEnded(); } private void ContentOnProblemChanged(object sender, EventArgs e) { if (InvokeRequired) Invoke((Action)OnProblemChanged); else OnProblemChanged(); } private void ContentOnProblemSolutionsChanged(object sender, EventArgs e) { if (InvokeRequired) Invoke((Action)OnProblemSolutionsChanged); else OnProblemSolutionsChanged(); } private void ContentOnProblemInstancesChanged(object sender, EventArgs e) { if (InvokeRequired) Invoke((Action)OnProblemInstancesChanged); else OnProblemInstancesChanged(); } private void ContentOnProblemCharacteristicsChanged(object sender, EventArgs e) { if (InvokeRequired) Invoke((Action)OnProblemCharacteristicsChanged); else OnProblemCharacteristicsChanged(); } private void ContentOnSolutionSeedingPoolChanged(object sender, EventArgs e) { if (InvokeRequired) Invoke((Action)OnSolutionSeedingPoolChanged); else OnSolutionSeedingPoolChanged(); } private void ContentOnSuggestedInstancesChanged(object sender, EventArgs e) { if (InvokeRequired) Invoke((Action)OnSuggestedInstancesChanged); else OnSuggestedInstancesChanged(); } #endregion } }