[13718] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.MainForm;
|
---|
[13722] | 24 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 25 | using HeuristicLab.Optimization;
|
---|
[13718] | 26 | using HeuristicLab.OptimizationExpertSystem.Common;
|
---|
| 27 | using System;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.OptimizationExpertSystem {
|
---|
| 30 | [View("Expert-System View")]
|
---|
[13722] | 31 | public partial class KnowledgeCenterViewBase : AsynchronousContentView {
|
---|
| 32 | public OptimizationKnowledgeCenter MainForm {
|
---|
| 33 | get { return (OptimizationKnowledgeCenter)HeuristicLab.MainForm.MainFormManager.MainForm; }
|
---|
[13718] | 34 | }
|
---|
| 35 |
|
---|
[13722] | 36 | public new KnowledgeCenter Content {
|
---|
| 37 | get { return (KnowledgeCenter)base.Content; }
|
---|
[13718] | 38 | set { base.Content = value; }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
[13722] | 41 | protected KnowledgeCenterViewBase() {
|
---|
[13718] | 42 | InitializeComponent();
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[13720] | 45 | #region Event Registration
|
---|
[13718] | 46 | protected override void RegisterContentEvents() {
|
---|
| 47 | base.RegisterContentEvents();
|
---|
| 48 | Content.DownloadStarted += ContentOnDownloadStarted;
|
---|
[13722] | 49 | Content.AlgorithmInstanceStarted += ContentOnAlgorithmInstanceStarted;
|
---|
[13720] | 50 | RegisterContentProblemEvents();
|
---|
| 51 | RegisterContentProblemInstancesEvents();
|
---|
[13752] | 52 | RegisterContentProblemCharacteristicsEvents();
|
---|
[13720] | 53 | RegisterContentSolutionSeedingPoolEvents();
|
---|
| 54 | RegisterContentSuggestedInstancesEvents();
|
---|
[13718] | 55 | }
|
---|
| 56 |
|
---|
[13720] | 57 | private void RegisterContentProblemEvents() {
|
---|
| 58 | Content.Problem.ProblemChanged += ContentOnProblemChanged;
|
---|
| 59 | Content.Problem.Solutions.CollectionReset += ContentOnProblemSolutionsChanged;
|
---|
| 60 | Content.Problem.Solutions.ItemsAdded += ContentOnProblemSolutionsChanged;
|
---|
| 61 | Content.Problem.Solutions.ItemsReplaced += ContentOnProblemSolutionsChanged;
|
---|
| 62 | Content.Problem.Solutions.ItemsRemoved += ContentOnProblemSolutionsChanged;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | private void RegisterContentProblemInstancesEvents() {
|
---|
| 66 | Content.ProblemInstances.UpdateOfRunsInProgressChanged += ContentOnProblemInstancesChanged;
|
---|
| 67 | Content.ProblemInstances.ItemsAdded += ContentOnProblemInstancesChanged;
|
---|
| 68 | Content.ProblemInstances.ItemsRemoved += ContentOnProblemInstancesChanged;
|
---|
| 69 | Content.ProblemInstances.CollectionReset += ContentOnProblemInstancesChanged;
|
---|
| 70 | Content.ProblemInstances.ItemChanged += ContentOnProblemInstancesChanged;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[13752] | 73 | private void RegisterContentProblemCharacteristicsEvents() {
|
---|
| 74 | Content.ProblemCharacteristics.ItemsAdded += ContentOnProblemCharacteristicsChanged;
|
---|
| 75 | Content.ProblemCharacteristics.ItemsReplaced += ContentOnProblemCharacteristicsChanged;
|
---|
| 76 | Content.ProblemCharacteristics.ItemsRemoved += ContentOnProblemCharacteristicsChanged;
|
---|
| 77 | Content.ProblemCharacteristics.CheckedItemsChanged += ContentOnProblemCharacteristicsChanged;
|
---|
| 78 | Content.ProblemCharacteristics.CollectionReset += ContentOnProblemCharacteristicsChanged;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
[13720] | 81 | private void RegisterContentSolutionSeedingPoolEvents() {
|
---|
| 82 | Content.SolutionSeedingPool.CheckedItemsChanged += ContentOnSolutionSeedingPoolChanged;
|
---|
| 83 | Content.SolutionSeedingPool.CollectionReset += ContentOnSolutionSeedingPoolChanged;
|
---|
| 84 | Content.SolutionSeedingPool.ItemsAdded += ContentOnSolutionSeedingPoolChanged;
|
---|
| 85 | Content.SolutionSeedingPool.ItemsRemoved += ContentOnSolutionSeedingPoolChanged;
|
---|
| 86 | Content.SolutionSeedingPool.ItemsReplaced += ContentOnSolutionSeedingPoolChanged;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | private void RegisterContentSuggestedInstancesEvents() {
|
---|
| 90 | Content.SuggestedInstances.CollectionReset += ContentOnSuggestedInstancesChanged;
|
---|
| 91 | Content.SuggestedInstances.ItemsAdded += ContentOnSuggestedInstancesChanged;
|
---|
| 92 | Content.SuggestedInstances.ItemsMoved += ContentOnSuggestedInstancesChanged;
|
---|
| 93 | Content.SuggestedInstances.ItemsRemoved += ContentOnSuggestedInstancesChanged;
|
---|
| 94 | Content.SuggestedInstances.ItemsReplaced += ContentOnSuggestedInstancesChanged;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[13718] | 97 | protected override void DeregisterContentEvents() {
|
---|
| 98 | base.DeregisterContentEvents();
|
---|
| 99 | Content.DownloadStarted -= ContentOnDownloadStarted;
|
---|
[13722] | 100 | Content.AlgorithmInstanceStarted -= ContentOnAlgorithmInstanceStarted;
|
---|
[13720] | 101 | DeregisterContentProblemEvents();
|
---|
| 102 | DeregisterContentProblemInstancesEvents();
|
---|
[13752] | 103 | DeregisterContentProblemCharacteristicsEvents();
|
---|
[13720] | 104 | DeregisterContentSolutionSeedingPoolEvents();
|
---|
| 105 | DeregisterContentSuggestedInstancesEvents();
|
---|
[13718] | 106 | }
|
---|
| 107 |
|
---|
[13720] | 108 | private void DeregisterContentProblemEvents() {
|
---|
| 109 | Content.Problem.ProblemChanged -= ContentOnProblemChanged;
|
---|
| 110 | Content.Problem.Solutions.CollectionReset -= ContentOnProblemSolutionsChanged;
|
---|
| 111 | Content.Problem.Solutions.ItemsAdded -= ContentOnProblemSolutionsChanged;
|
---|
| 112 | Content.Problem.Solutions.ItemsReplaced -= ContentOnProblemSolutionsChanged;
|
---|
| 113 | Content.Problem.Solutions.ItemsRemoved -= ContentOnProblemSolutionsChanged;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | private void DeregisterContentProblemInstancesEvents() {
|
---|
| 117 | Content.ProblemInstances.UpdateOfRunsInProgressChanged -= ContentOnProblemInstancesChanged;
|
---|
| 118 | Content.ProblemInstances.ItemsAdded -= ContentOnProblemInstancesChanged;
|
---|
| 119 | Content.ProblemInstances.ItemsRemoved -= ContentOnProblemInstancesChanged;
|
---|
| 120 | Content.ProblemInstances.CollectionReset -= ContentOnProblemInstancesChanged;
|
---|
| 121 | Content.ProblemInstances.ItemChanged -= ContentOnProblemInstancesChanged;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[13752] | 124 | private void DeregisterContentProblemCharacteristicsEvents() {
|
---|
| 125 | Content.ProblemCharacteristics.ItemsAdded -= ContentOnProblemCharacteristicsChanged;
|
---|
| 126 | Content.ProblemCharacteristics.ItemsReplaced -= ContentOnProblemCharacteristicsChanged;
|
---|
| 127 | Content.ProblemCharacteristics.ItemsRemoved -= ContentOnProblemCharacteristicsChanged;
|
---|
| 128 | Content.ProblemCharacteristics.CheckedItemsChanged -= ContentOnProblemCharacteristicsChanged;
|
---|
| 129 | Content.ProblemCharacteristics.CollectionReset -= ContentOnProblemCharacteristicsChanged;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
[13720] | 132 | private void DeregisterContentSolutionSeedingPoolEvents() {
|
---|
| 133 | Content.SolutionSeedingPool.CheckedItemsChanged -= ContentOnSolutionSeedingPoolChanged;
|
---|
| 134 | Content.SolutionSeedingPool.CollectionReset -= ContentOnSolutionSeedingPoolChanged;
|
---|
| 135 | Content.SolutionSeedingPool.ItemsAdded -= ContentOnSolutionSeedingPoolChanged;
|
---|
| 136 | Content.SolutionSeedingPool.ItemsRemoved -= ContentOnSolutionSeedingPoolChanged;
|
---|
| 137 | Content.SolutionSeedingPool.ItemsReplaced -= ContentOnSolutionSeedingPoolChanged;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | private void DeregisterContentSuggestedInstancesEvents() {
|
---|
| 141 | Content.SuggestedInstances.CollectionReset -= ContentOnSuggestedInstancesChanged;
|
---|
| 142 | Content.SuggestedInstances.ItemsAdded -= ContentOnSuggestedInstancesChanged;
|
---|
| 143 | Content.SuggestedInstances.ItemsMoved -= ContentOnSuggestedInstancesChanged;
|
---|
| 144 | Content.SuggestedInstances.ItemsRemoved -= ContentOnSuggestedInstancesChanged;
|
---|
| 145 | Content.SuggestedInstances.ItemsReplaced -= ContentOnSuggestedInstancesChanged;
|
---|
| 146 | }
|
---|
| 147 | #endregion
|
---|
| 148 |
|
---|
| 149 | protected virtual void OnDownloadStarted(IProgress progress) { }
|
---|
[13718] | 150 | protected virtual void OnDownloadEnded() { }
|
---|
[13722] | 151 | protected virtual void OnAlgorithmInstanceStarted(IAlgorithm algorithm) { }
|
---|
[13720] | 152 | protected virtual void OnPropertyChanged(string propertyName) { }
|
---|
| 153 | protected virtual void OnProblemChanged() { }
|
---|
| 154 | protected virtual void OnProblemSolutionsChanged() { }
|
---|
| 155 | protected virtual void OnProblemInstancesChanged() { }
|
---|
[13752] | 156 | protected virtual void OnProblemCharacteristicsChanged() { }
|
---|
[13720] | 157 | protected virtual void OnSolutionSeedingPoolChanged() { }
|
---|
| 158 | protected virtual void OnSuggestedInstancesChanged() { }
|
---|
[13722] | 159 | protected virtual void OnKnowledgeBaseChanged() { }
|
---|
[13718] | 160 |
|
---|
[13720] | 161 | #region Content Event Handlers
|
---|
[13718] | 162 | private void ContentOnDownloadStarted(object sender, EventArgs<IProgress> e) {
|
---|
| 163 | if (InvokeRequired) { Invoke((Action<object, EventArgs<IProgress>>)ContentOnDownloadStarted, sender, e); return; }
|
---|
| 164 | MainForm.AddOperationProgressToView(this, e.Value);
|
---|
| 165 | e.Value.ProgressStateChanged += ProgressOnStateChanged;
|
---|
[13720] | 166 | OnDownloadStarted(e.Value);
|
---|
[13718] | 167 | }
|
---|
| 168 |
|
---|
[13722] | 169 | private void ContentOnAlgorithmInstanceStarted(object sender, EventArgs<IAlgorithm> e) {
|
---|
| 170 | if (InvokeRequired) { Invoke((Action<object, EventArgs<IAlgorithm>>)ContentOnAlgorithmInstanceStarted, sender, e); return; }
|
---|
| 171 | OnAlgorithmInstanceStarted(e.Value);
|
---|
| 172 | }
|
---|
| 173 |
|
---|
[13718] | 174 | private void ProgressOnStateChanged(object sender, EventArgs e) {
|
---|
| 175 | if (InvokeRequired) { Invoke((Action<object, EventArgs>)ProgressOnStateChanged, sender, e); return; }
|
---|
| 176 | var progress = (IProgress)sender;
|
---|
| 177 | if (progress == null || progress.ProgressState == ProgressState.Started) return;
|
---|
| 178 | OnDownloadEnded();
|
---|
| 179 | }
|
---|
[13720] | 180 |
|
---|
| 181 | private void ContentOnProblemChanged(object sender, EventArgs e) {
|
---|
| 182 | if (InvokeRequired) Invoke((Action)OnProblemChanged);
|
---|
| 183 | else OnProblemChanged();
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | private void ContentOnProblemSolutionsChanged(object sender, EventArgs e) {
|
---|
| 187 | if (InvokeRequired) Invoke((Action)OnProblemSolutionsChanged);
|
---|
| 188 | else OnProblemSolutionsChanged();
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | private void ContentOnProblemInstancesChanged(object sender, EventArgs e) {
|
---|
| 192 | if (InvokeRequired) Invoke((Action)OnProblemInstancesChanged);
|
---|
| 193 | else OnProblemInstancesChanged();
|
---|
| 194 | }
|
---|
| 195 |
|
---|
[13752] | 196 | private void ContentOnProblemCharacteristicsChanged(object sender, EventArgs e) {
|
---|
| 197 | if (InvokeRequired) Invoke((Action)OnProblemCharacteristicsChanged);
|
---|
| 198 | else OnProblemCharacteristicsChanged();
|
---|
| 199 | }
|
---|
| 200 |
|
---|
[13720] | 201 | private void ContentOnSolutionSeedingPoolChanged(object sender, EventArgs e) {
|
---|
| 202 | if (InvokeRequired) Invoke((Action)OnSolutionSeedingPoolChanged);
|
---|
| 203 | else OnSolutionSeedingPoolChanged();
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | private void ContentOnSuggestedInstancesChanged(object sender, EventArgs e) {
|
---|
| 207 | if (InvokeRequired) Invoke((Action)OnSuggestedInstancesChanged);
|
---|
| 208 | else OnSuggestedInstancesChanged();
|
---|
| 209 | }
|
---|
| 210 | #endregion
|
---|
[13718] | 211 | }
|
---|
| 212 | }
|
---|