[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.Core.Views;
|
---|
| 24 | using HeuristicLab.MainForm;
|
---|
| 25 | using HeuristicLab.OptimizationExpertSystem.Common;
|
---|
| 26 | using System;
|
---|
[13720] | 27 | using System.ComponentModel;
|
---|
[13718] | 28 |
|
---|
| 29 | namespace HeuristicLab.OptimizationExpertSystem {
|
---|
| 30 | [View("Expert-System View")]
|
---|
| 31 | public partial class ExpertSystemViewBase : ItemView {
|
---|
| 32 | public OptimizationExpertSystem MainForm {
|
---|
| 33 | get { return (OptimizationExpertSystem)HeuristicLab.MainForm.MainFormManager.MainForm; }
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | public new ExpertSystem Content {
|
---|
| 37 | get { return (ExpertSystem)base.Content; }
|
---|
| 38 | set { base.Content = value; }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | protected ExpertSystemViewBase() {
|
---|
| 42 | InitializeComponent();
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[13720] | 45 | #region Event Registration
|
---|
[13718] | 46 | protected override void RegisterContentEvents() {
|
---|
| 47 | base.RegisterContentEvents();
|
---|
[13720] | 48 | Content.PropertyChanged += ContentOnPropertyChanged;
|
---|
[13718] | 49 | Content.DownloadStarted += ContentOnDownloadStarted;
|
---|
[13720] | 50 | RegisterContentProblemEvents();
|
---|
| 51 | RegisterContentProblemInstancesEvents();
|
---|
| 52 | RegisterContentSolutionSeedingPoolEvents();
|
---|
| 53 | RegisterContentSuggestedInstancesEvents();
|
---|
[13718] | 54 | }
|
---|
| 55 |
|
---|
[13720] | 56 | private void RegisterContentProblemEvents() {
|
---|
| 57 | Content.Problem.ProblemChanged += ContentOnProblemChanged;
|
---|
| 58 | Content.Problem.Solutions.CollectionReset += ContentOnProblemSolutionsChanged;
|
---|
| 59 | Content.Problem.Solutions.ItemsAdded += ContentOnProblemSolutionsChanged;
|
---|
| 60 | Content.Problem.Solutions.ItemsReplaced += ContentOnProblemSolutionsChanged;
|
---|
| 61 | Content.Problem.Solutions.ItemsRemoved += ContentOnProblemSolutionsChanged;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | private void RegisterContentProblemInstancesEvents() {
|
---|
| 65 | Content.ProblemInstances.UpdateOfRunsInProgressChanged += ContentOnProblemInstancesChanged;
|
---|
| 66 | Content.ProblemInstances.ItemsAdded += ContentOnProblemInstancesChanged;
|
---|
| 67 | Content.ProblemInstances.ItemsRemoved += ContentOnProblemInstancesChanged;
|
---|
| 68 | Content.ProblemInstances.CollectionReset += ContentOnProblemInstancesChanged;
|
---|
| 69 | Content.ProblemInstances.ItemChanged += ContentOnProblemInstancesChanged;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | private void RegisterContentSolutionSeedingPoolEvents() {
|
---|
| 73 | Content.SolutionSeedingPool.CheckedItemsChanged += ContentOnSolutionSeedingPoolChanged;
|
---|
| 74 | Content.SolutionSeedingPool.CollectionReset += ContentOnSolutionSeedingPoolChanged;
|
---|
| 75 | Content.SolutionSeedingPool.ItemsAdded += ContentOnSolutionSeedingPoolChanged;
|
---|
| 76 | Content.SolutionSeedingPool.ItemsRemoved += ContentOnSolutionSeedingPoolChanged;
|
---|
| 77 | Content.SolutionSeedingPool.ItemsReplaced += ContentOnSolutionSeedingPoolChanged;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | private void RegisterContentSuggestedInstancesEvents() {
|
---|
| 81 | Content.SuggestedInstances.CollectionReset += ContentOnSuggestedInstancesChanged;
|
---|
| 82 | Content.SuggestedInstances.ItemsAdded += ContentOnSuggestedInstancesChanged;
|
---|
| 83 | Content.SuggestedInstances.ItemsMoved += ContentOnSuggestedInstancesChanged;
|
---|
| 84 | Content.SuggestedInstances.ItemsRemoved += ContentOnSuggestedInstancesChanged;
|
---|
| 85 | Content.SuggestedInstances.ItemsReplaced += ContentOnSuggestedInstancesChanged;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[13718] | 88 | protected override void DeregisterContentEvents() {
|
---|
| 89 | base.DeregisterContentEvents();
|
---|
[13720] | 90 | Content.PropertyChanged -= ContentOnPropertyChanged;
|
---|
[13718] | 91 | Content.DownloadStarted -= ContentOnDownloadStarted;
|
---|
[13720] | 92 | DeregisterContentProblemEvents();
|
---|
| 93 | DeregisterContentProblemInstancesEvents();
|
---|
| 94 | DeregisterContentSolutionSeedingPoolEvents();
|
---|
| 95 | DeregisterContentSuggestedInstancesEvents();
|
---|
[13718] | 96 | }
|
---|
| 97 |
|
---|
[13720] | 98 | private void DeregisterContentProblemEvents() {
|
---|
| 99 | Content.Problem.ProblemChanged -= ContentOnProblemChanged;
|
---|
| 100 | Content.Problem.Solutions.CollectionReset -= ContentOnProblemSolutionsChanged;
|
---|
| 101 | Content.Problem.Solutions.ItemsAdded -= ContentOnProblemSolutionsChanged;
|
---|
| 102 | Content.Problem.Solutions.ItemsReplaced -= ContentOnProblemSolutionsChanged;
|
---|
| 103 | Content.Problem.Solutions.ItemsRemoved -= ContentOnProblemSolutionsChanged;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | private void DeregisterContentProblemInstancesEvents() {
|
---|
| 107 | Content.ProblemInstances.UpdateOfRunsInProgressChanged -= ContentOnProblemInstancesChanged;
|
---|
| 108 | Content.ProblemInstances.ItemsAdded -= ContentOnProblemInstancesChanged;
|
---|
| 109 | Content.ProblemInstances.ItemsRemoved -= ContentOnProblemInstancesChanged;
|
---|
| 110 | Content.ProblemInstances.CollectionReset -= ContentOnProblemInstancesChanged;
|
---|
| 111 | Content.ProblemInstances.ItemChanged -= ContentOnProblemInstancesChanged;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | private void DeregisterContentSolutionSeedingPoolEvents() {
|
---|
| 115 | Content.SolutionSeedingPool.CheckedItemsChanged -= ContentOnSolutionSeedingPoolChanged;
|
---|
| 116 | Content.SolutionSeedingPool.CollectionReset -= ContentOnSolutionSeedingPoolChanged;
|
---|
| 117 | Content.SolutionSeedingPool.ItemsAdded -= ContentOnSolutionSeedingPoolChanged;
|
---|
| 118 | Content.SolutionSeedingPool.ItemsRemoved -= ContentOnSolutionSeedingPoolChanged;
|
---|
| 119 | Content.SolutionSeedingPool.ItemsReplaced -= ContentOnSolutionSeedingPoolChanged;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | private void DeregisterContentSuggestedInstancesEvents() {
|
---|
| 123 | Content.SuggestedInstances.CollectionReset -= ContentOnSuggestedInstancesChanged;
|
---|
| 124 | Content.SuggestedInstances.ItemsAdded -= ContentOnSuggestedInstancesChanged;
|
---|
| 125 | Content.SuggestedInstances.ItemsMoved -= ContentOnSuggestedInstancesChanged;
|
---|
| 126 | Content.SuggestedInstances.ItemsRemoved -= ContentOnSuggestedInstancesChanged;
|
---|
| 127 | Content.SuggestedInstances.ItemsReplaced -= ContentOnSuggestedInstancesChanged;
|
---|
| 128 | }
|
---|
| 129 | #endregion
|
---|
| 130 |
|
---|
| 131 | private void ContentOnPropertyChanged(object sender, PropertyChangedEventArgs e) {
|
---|
| 132 | if (InvokeRequired) Invoke((Action<string>)OnPropertyChanged, e.PropertyName);
|
---|
| 133 | else {
|
---|
| 134 | switch (e.PropertyName) {
|
---|
| 135 | case "Problem": RegisterContentProblemEvents(); break;
|
---|
| 136 | case "ProblemInstances": RegisterContentProblemInstancesEvents(); break;
|
---|
| 137 | case "SolutionSeedingPool": RegisterContentSolutionSeedingPoolEvents(); break;
|
---|
| 138 | case "SuggestedInstances": RegisterContentSuggestedInstancesEvents(); break;
|
---|
| 139 | }
|
---|
| 140 | OnPropertyChanged(e.PropertyName);
|
---|
| 141 | }
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | protected virtual void OnDownloadStarted(IProgress progress) { }
|
---|
[13718] | 145 | protected virtual void OnDownloadEnded() { }
|
---|
[13720] | 146 | protected virtual void OnPropertyChanged(string propertyName) { }
|
---|
| 147 | protected virtual void OnProblemChanged() { }
|
---|
| 148 | protected virtual void OnProblemSolutionsChanged() { }
|
---|
| 149 | protected virtual void OnProblemInstancesChanged() { }
|
---|
| 150 | protected virtual void OnSolutionSeedingPoolChanged() { }
|
---|
| 151 | protected virtual void OnSuggestedInstancesChanged() { }
|
---|
[13718] | 152 |
|
---|
[13720] | 153 | #region Content Event Handlers
|
---|
[13718] | 154 | private void ContentOnDownloadStarted(object sender, EventArgs<IProgress> e) {
|
---|
| 155 | if (InvokeRequired) { Invoke((Action<object, EventArgs<IProgress>>)ContentOnDownloadStarted, sender, e); return; }
|
---|
| 156 | MainForm.AddOperationProgressToView(this, e.Value);
|
---|
| 157 | e.Value.ProgressStateChanged += ProgressOnStateChanged;
|
---|
[13720] | 158 | OnDownloadStarted(e.Value);
|
---|
[13718] | 159 | }
|
---|
| 160 |
|
---|
| 161 | private void ProgressOnStateChanged(object sender, EventArgs e) {
|
---|
| 162 | if (InvokeRequired) { Invoke((Action<object, EventArgs>)ProgressOnStateChanged, sender, e); return; }
|
---|
| 163 | var progress = (IProgress)sender;
|
---|
| 164 | if (progress == null || progress.ProgressState == ProgressState.Started) return;
|
---|
| 165 | OnDownloadEnded();
|
---|
| 166 | }
|
---|
[13720] | 167 |
|
---|
| 168 | private void ContentOnProblemChanged(object sender, EventArgs e) {
|
---|
| 169 | if (InvokeRequired) Invoke((Action)OnProblemChanged);
|
---|
| 170 | else OnProblemChanged();
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | private void ContentOnProblemSolutionsChanged(object sender, EventArgs e) {
|
---|
| 174 | if (InvokeRequired) Invoke((Action)OnProblemSolutionsChanged);
|
---|
| 175 | else OnProblemSolutionsChanged();
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | private void ContentOnProblemInstancesChanged(object sender, EventArgs e) {
|
---|
| 179 | if (InvokeRequired) Invoke((Action)OnProblemInstancesChanged);
|
---|
| 180 | else OnProblemInstancesChanged();
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | private void ContentOnSolutionSeedingPoolChanged(object sender, EventArgs e) {
|
---|
| 184 | if (InvokeRequired) Invoke((Action)OnSolutionSeedingPoolChanged);
|
---|
| 185 | else OnSolutionSeedingPoolChanged();
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | private void ContentOnSuggestedInstancesChanged(object sender, EventArgs e) {
|
---|
| 189 | if (InvokeRequired) Invoke((Action)OnSuggestedInstancesChanged);
|
---|
| 190 | else OnSuggestedInstancesChanged();
|
---|
| 191 | }
|
---|
| 192 | #endregion
|
---|
[13718] | 193 | }
|
---|
| 194 | }
|
---|