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;
|
---|
24 | using HeuristicLab.MainForm.WindowsForms;
|
---|
25 | using HeuristicLab.Optimization;
|
---|
26 | using HeuristicLab.OptimizationExpertSystem.Common;
|
---|
27 | using System;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.OptimizationExpertSystem {
|
---|
30 | [View("Expert-System View")]
|
---|
31 | public partial class KnowledgeCenterViewBase : AsynchronousContentView {
|
---|
32 | public OptimizationKnowledgeCenter MainForm {
|
---|
33 | get { return (OptimizationKnowledgeCenter)HeuristicLab.MainForm.MainFormManager.MainForm; }
|
---|
34 | }
|
---|
35 |
|
---|
36 | public new KnowledgeCenter Content {
|
---|
37 | get { return (KnowledgeCenter)base.Content; }
|
---|
38 | set { base.Content = value; }
|
---|
39 | }
|
---|
40 |
|
---|
41 | protected KnowledgeCenterViewBase() {
|
---|
42 | InitializeComponent();
|
---|
43 | }
|
---|
44 |
|
---|
45 | #region Event Registration
|
---|
46 | protected override void RegisterContentEvents() {
|
---|
47 | base.RegisterContentEvents();
|
---|
48 | Content.DownloadStarted += ContentOnDownloadStarted;
|
---|
49 | Content.AlgorithmInstanceStarted += ContentOnAlgorithmInstanceStarted;
|
---|
50 | RegisterContentProblemEvents();
|
---|
51 | RegisterContentProblemInstancesEvents();
|
---|
52 | RegisterContentProblemCharacteristicsEvents();
|
---|
53 | RegisterContentSolutionSeedingPoolEvents();
|
---|
54 | RegisterContentSuggestedInstancesEvents();
|
---|
55 | }
|
---|
56 |
|
---|
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 |
|
---|
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 |
|
---|
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 |
|
---|
97 | protected override void DeregisterContentEvents() {
|
---|
98 | base.DeregisterContentEvents();
|
---|
99 | Content.DownloadStarted -= ContentOnDownloadStarted;
|
---|
100 | Content.AlgorithmInstanceStarted -= ContentOnAlgorithmInstanceStarted;
|
---|
101 | DeregisterContentProblemEvents();
|
---|
102 | DeregisterContentProblemInstancesEvents();
|
---|
103 | DeregisterContentProblemCharacteristicsEvents();
|
---|
104 | DeregisterContentSolutionSeedingPoolEvents();
|
---|
105 | DeregisterContentSuggestedInstancesEvents();
|
---|
106 | }
|
---|
107 |
|
---|
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 |
|
---|
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 |
|
---|
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) { }
|
---|
150 | protected virtual void OnDownloadEnded() { }
|
---|
151 | protected virtual void OnAlgorithmInstanceStarted(IAlgorithm algorithm) { }
|
---|
152 | protected virtual void OnPropertyChanged(string propertyName) { }
|
---|
153 | protected virtual void OnProblemChanged() { }
|
---|
154 | protected virtual void OnProblemSolutionsChanged() { }
|
---|
155 | protected virtual void OnProblemInstancesChanged() { }
|
---|
156 | protected virtual void OnProblemCharacteristicsChanged() { }
|
---|
157 | protected virtual void OnSolutionSeedingPoolChanged() { }
|
---|
158 | protected virtual void OnSuggestedInstancesChanged() { }
|
---|
159 | protected virtual void OnKnowledgeBaseChanged() { }
|
---|
160 |
|
---|
161 | #region Content Event Handlers
|
---|
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;
|
---|
166 | OnDownloadStarted(e.Value);
|
---|
167 | }
|
---|
168 |
|
---|
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 |
|
---|
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 | }
|
---|
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 |
|
---|
196 | private void ContentOnProblemCharacteristicsChanged(object sender, EventArgs e) {
|
---|
197 | if (InvokeRequired) Invoke((Action)OnProblemCharacteristicsChanged);
|
---|
198 | else OnProblemCharacteristicsChanged();
|
---|
199 | }
|
---|
200 |
|
---|
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
|
---|
211 | }
|
---|
212 | }
|
---|