Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2457_ExpertSystem/HeuristicLab.OptimizationExpertSystem/3.3/Views/KnowledgeCenterViewBase.cs @ 16300

Last change on this file since 16300 was 13787, checked in by abeham, 9 years ago

#2457: worked on performance modeling

File size: 9.4 KB
Line 
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
22using HeuristicLab.Common;
23using HeuristicLab.MainForm;
24using HeuristicLab.MainForm.WindowsForms;
25using HeuristicLab.Optimization;
26using HeuristicLab.OptimizationExpertSystem.Common;
27using System;
28
29namespace 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      Content.RecommendationModelChanged += ContentOnRecommendationModelChanged;
51      RegisterContentProblemEvents();
52      RegisterContentProblemInstancesEvents();
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 RegisterContentSolutionSeedingPoolEvents() {
74      Content.SolutionSeedingPool.CheckedItemsChanged += ContentOnSolutionSeedingPoolChanged;
75      Content.SolutionSeedingPool.CollectionReset += ContentOnSolutionSeedingPoolChanged;
76      Content.SolutionSeedingPool.ItemsAdded += ContentOnSolutionSeedingPoolChanged;
77      Content.SolutionSeedingPool.ItemsRemoved += ContentOnSolutionSeedingPoolChanged;
78      Content.SolutionSeedingPool.ItemsReplaced += ContentOnSolutionSeedingPoolChanged;
79    }
80
81    private void RegisterContentSuggestedInstancesEvents() {
82      Content.AlgorithmInstances.CollectionReset += ContentOnAlgorithmInstancesChanged;
83      Content.AlgorithmInstances.ItemsAdded += ContentOnAlgorithmInstancesChanged;
84      Content.AlgorithmInstances.ItemsMoved += ContentOnAlgorithmInstancesChanged;
85      Content.AlgorithmInstances.ItemsRemoved += ContentOnAlgorithmInstancesChanged;
86      Content.AlgorithmInstances.ItemsReplaced += ContentOnAlgorithmInstancesChanged;
87    }
88
89    protected override void DeregisterContentEvents() {
90      base.DeregisterContentEvents();
91      Content.DownloadStarted -= ContentOnDownloadStarted;
92      Content.AlgorithmInstanceStarted -= ContentOnAlgorithmInstanceStarted;
93      Content.RecommendationModelChanged -= ContentOnRecommendationModelChanged;
94      DeregisterContentProblemEvents();
95      DeregisterContentProblemInstancesEvents();
96      DeregisterContentSolutionSeedingPoolEvents();
97      DeregisterContentSuggestedInstancesEvents();
98    }
99
100    private void DeregisterContentProblemEvents() {
101      Content.Problem.ProblemChanged -= ContentOnProblemChanged;
102      Content.Problem.Solutions.CollectionReset -= ContentOnProblemSolutionsChanged;
103      Content.Problem.Solutions.ItemsAdded -= ContentOnProblemSolutionsChanged;
104      Content.Problem.Solutions.ItemsReplaced -= ContentOnProblemSolutionsChanged;
105      Content.Problem.Solutions.ItemsRemoved -= ContentOnProblemSolutionsChanged;
106    }
107
108    private void DeregisterContentProblemInstancesEvents() {
109      Content.ProblemInstances.UpdateOfRunsInProgressChanged -= ContentOnProblemInstancesChanged;
110      Content.ProblemInstances.ItemsAdded -= ContentOnProblemInstancesChanged;
111      Content.ProblemInstances.ItemsRemoved -= ContentOnProblemInstancesChanged;
112      Content.ProblemInstances.CollectionReset -= ContentOnProblemInstancesChanged;
113      Content.ProblemInstances.ItemChanged -= ContentOnProblemInstancesChanged;
114    }
115
116    private void DeregisterContentSolutionSeedingPoolEvents() {
117      Content.SolutionSeedingPool.CheckedItemsChanged -= ContentOnSolutionSeedingPoolChanged;
118      Content.SolutionSeedingPool.CollectionReset -= ContentOnSolutionSeedingPoolChanged;
119      Content.SolutionSeedingPool.ItemsAdded -= ContentOnSolutionSeedingPoolChanged;
120      Content.SolutionSeedingPool.ItemsRemoved -= ContentOnSolutionSeedingPoolChanged;
121      Content.SolutionSeedingPool.ItemsReplaced -= ContentOnSolutionSeedingPoolChanged;
122    }
123
124    private void DeregisterContentSuggestedInstancesEvents() {
125      Content.AlgorithmInstances.CollectionReset -= ContentOnAlgorithmInstancesChanged;
126      Content.AlgorithmInstances.ItemsAdded -= ContentOnAlgorithmInstancesChanged;
127      Content.AlgorithmInstances.ItemsMoved -= ContentOnAlgorithmInstancesChanged;
128      Content.AlgorithmInstances.ItemsRemoved -= ContentOnAlgorithmInstancesChanged;
129      Content.AlgorithmInstances.ItemsReplaced -= ContentOnAlgorithmInstancesChanged;
130    }
131    #endregion
132
133    protected virtual void OnDownloadStarted(IProgress progress) { }
134    protected virtual void OnDownloadEnded() { }
135    protected virtual void OnAlgorithmInstanceStarted(IAlgorithm algorithm) { }
136    protected virtual void OnRecommendationModelChanged() { }
137    protected virtual void OnPropertyChanged(string propertyName) { }
138    protected virtual void OnProblemChanged() { }
139    protected virtual void OnProblemSolutionsChanged() { }
140    protected virtual void OnProblemInstancesChanged() { }
141    protected virtual void OnSolutionSeedingPoolChanged() { }
142    protected virtual void OnAlgorithmInstancesChanged() { }
143    protected virtual void OnKnowledgeBaseChanged() { }
144
145    #region Content Event Handlers
146    private void ContentOnDownloadStarted(object sender, EventArgs<IProgress> e) {
147      if (InvokeRequired) { Invoke((Action<object, EventArgs<IProgress>>)ContentOnDownloadStarted, sender, e); return; }
148      MainForm.AddOperationProgressToView(this, e.Value);
149      e.Value.ProgressStateChanged += ProgressOnStateChanged;
150      OnDownloadStarted(e.Value);
151    }
152
153    private void ContentOnAlgorithmInstanceStarted(object sender, EventArgs<IAlgorithm> e) {
154      if (InvokeRequired) { Invoke((Action<object, EventArgs<IAlgorithm>>)ContentOnAlgorithmInstanceStarted, sender, e); return; }
155      OnAlgorithmInstanceStarted(e.Value);
156    }
157
158    private void ContentOnRecommendationModelChanged(object sender, EventArgs e) {
159      if (InvokeRequired) { Invoke((Action<object, EventArgs<IAlgorithm>>)ContentOnRecommendationModelChanged, sender, e); return; }
160      OnRecommendationModelChanged();
161    }
162
163    private void ProgressOnStateChanged(object sender, EventArgs e) {
164      if (InvokeRequired) { Invoke((Action<object, EventArgs>)ProgressOnStateChanged, sender, e); return; }
165      var progress = (IProgress)sender;
166      if (progress == null || progress.ProgressState == ProgressState.Started) return;
167      OnDownloadEnded();
168    }
169
170    private void ContentOnProblemChanged(object sender, EventArgs e) {
171      if (InvokeRequired) Invoke((Action)OnProblemChanged);
172      else OnProblemChanged();
173    }
174
175    private void ContentOnProblemSolutionsChanged(object sender, EventArgs e) {
176      if (InvokeRequired) Invoke((Action)OnProblemSolutionsChanged);
177      else OnProblemSolutionsChanged();
178    }
179
180    private void ContentOnProblemInstancesChanged(object sender, EventArgs e) {
181      if (InvokeRequired) Invoke((Action)OnProblemInstancesChanged);
182      else OnProblemInstancesChanged();
183    }
184
185    private void ContentOnSolutionSeedingPoolChanged(object sender, EventArgs e) {
186      if (InvokeRequired) Invoke((Action)OnSolutionSeedingPoolChanged);
187      else OnSolutionSeedingPoolChanged();
188    }
189
190    private void ContentOnAlgorithmInstancesChanged(object sender, EventArgs e) {
191      if (InvokeRequired) Invoke((Action)OnAlgorithmInstancesChanged);
192      else OnAlgorithmInstancesChanged();
193    }
194    #endregion
195  }
196}
Note: See TracBrowser for help on using the repository browser.