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 | RegisterContentSolutionSeedingPoolEvents();
|
---|
53 | RegisterContentSuggestedInstancesEvents();
|
---|
54 | }
|
---|
55 |
|
---|
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 |
|
---|
88 | protected override void DeregisterContentEvents() {
|
---|
89 | base.DeregisterContentEvents();
|
---|
90 | Content.DownloadStarted -= ContentOnDownloadStarted;
|
---|
91 | Content.AlgorithmInstanceStarted -= ContentOnAlgorithmInstanceStarted;
|
---|
92 | DeregisterContentProblemEvents();
|
---|
93 | DeregisterContentProblemInstancesEvents();
|
---|
94 | DeregisterContentSolutionSeedingPoolEvents();
|
---|
95 | DeregisterContentSuggestedInstancesEvents();
|
---|
96 | }
|
---|
97 |
|
---|
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 | protected virtual void OnDownloadStarted(IProgress progress) { }
|
---|
132 | protected virtual void OnDownloadEnded() { }
|
---|
133 | protected virtual void OnAlgorithmInstanceStarted(IAlgorithm algorithm) { }
|
---|
134 | protected virtual void OnPropertyChanged(string propertyName) { }
|
---|
135 | protected virtual void OnProblemChanged() { }
|
---|
136 | protected virtual void OnProblemSolutionsChanged() { }
|
---|
137 | protected virtual void OnProblemInstancesChanged() { }
|
---|
138 | protected virtual void OnSolutionSeedingPoolChanged() { }
|
---|
139 | protected virtual void OnSuggestedInstancesChanged() { }
|
---|
140 | protected virtual void OnKnowledgeBaseChanged() { }
|
---|
141 |
|
---|
142 | #region Content Event Handlers
|
---|
143 | private void ContentOnDownloadStarted(object sender, EventArgs<IProgress> e) {
|
---|
144 | if (InvokeRequired) { Invoke((Action<object, EventArgs<IProgress>>)ContentOnDownloadStarted, sender, e); return; }
|
---|
145 | MainForm.AddOperationProgressToView(this, e.Value);
|
---|
146 | e.Value.ProgressStateChanged += ProgressOnStateChanged;
|
---|
147 | OnDownloadStarted(e.Value);
|
---|
148 | }
|
---|
149 |
|
---|
150 | private void ContentOnAlgorithmInstanceStarted(object sender, EventArgs<IAlgorithm> e) {
|
---|
151 | if (InvokeRequired) { Invoke((Action<object, EventArgs<IAlgorithm>>)ContentOnAlgorithmInstanceStarted, sender, e); return; }
|
---|
152 | OnAlgorithmInstanceStarted(e.Value);
|
---|
153 | }
|
---|
154 |
|
---|
155 | private void ProgressOnStateChanged(object sender, EventArgs e) {
|
---|
156 | if (InvokeRequired) { Invoke((Action<object, EventArgs>)ProgressOnStateChanged, sender, e); return; }
|
---|
157 | var progress = (IProgress)sender;
|
---|
158 | if (progress == null || progress.ProgressState == ProgressState.Started) return;
|
---|
159 | OnDownloadEnded();
|
---|
160 | }
|
---|
161 |
|
---|
162 | private void ContentOnProblemChanged(object sender, EventArgs e) {
|
---|
163 | if (InvokeRequired) Invoke((Action)OnProblemChanged);
|
---|
164 | else OnProblemChanged();
|
---|
165 | }
|
---|
166 |
|
---|
167 | private void ContentOnProblemSolutionsChanged(object sender, EventArgs e) {
|
---|
168 | if (InvokeRequired) Invoke((Action)OnProblemSolutionsChanged);
|
---|
169 | else OnProblemSolutionsChanged();
|
---|
170 | }
|
---|
171 |
|
---|
172 | private void ContentOnProblemInstancesChanged(object sender, EventArgs e) {
|
---|
173 | if (InvokeRequired) Invoke((Action)OnProblemInstancesChanged);
|
---|
174 | else OnProblemInstancesChanged();
|
---|
175 | }
|
---|
176 |
|
---|
177 | private void ContentOnSolutionSeedingPoolChanged(object sender, EventArgs e) {
|
---|
178 | if (InvokeRequired) Invoke((Action)OnSolutionSeedingPoolChanged);
|
---|
179 | else OnSolutionSeedingPoolChanged();
|
---|
180 | }
|
---|
181 |
|
---|
182 | private void ContentOnSuggestedInstancesChanged(object sender, EventArgs e) {
|
---|
183 | if (InvokeRequired) Invoke((Action)OnSuggestedInstancesChanged);
|
---|
184 | else OnSuggestedInstancesChanged();
|
---|
185 | }
|
---|
186 | #endregion
|
---|
187 | }
|
---|
188 | }
|
---|