1 | #region License Information
|
---|
2 |
|
---|
3 | /* HeuristicLab
|
---|
4 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
5 | *
|
---|
6 | * This file is part of HeuristicLab.
|
---|
7 | *
|
---|
8 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
9 | * it under the terms of the GNU General Public License as published by
|
---|
10 | * the Free Software Foundation, either version 3 of the License, or
|
---|
11 | * (at your option) any later version.
|
---|
12 | *
|
---|
13 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | * GNU General Public License for more details.
|
---|
17 | *
|
---|
18 | * You should have received a copy of the GNU General Public License
|
---|
19 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #endregion
|
---|
23 |
|
---|
24 | using System;
|
---|
25 | using System.Collections.Generic;
|
---|
26 | using System.Linq;
|
---|
27 | using System.Windows.Forms;
|
---|
28 | using HeuristicLab.Core;
|
---|
29 | using HeuristicLab.MainForm;
|
---|
30 | using HeuristicLab.Optimization;
|
---|
31 | using HeuristicLab.Optimization.Views;
|
---|
32 | using HeuristicLab.Problems.DataAnalysis;
|
---|
33 |
|
---|
34 | namespace HeuristicLab.DatastreamAnalysis {
|
---|
35 | [View("DatastreamAnalysisOptimizer View", "")]
|
---|
36 | [Content(typeof(DatastreamAnalysisOptimizer), true)]
|
---|
37 | public partial class DatastreamAnalysisOptimizerView : IOptimizerView {
|
---|
38 | public DatastreamAnalysisOptimizerView() {
|
---|
39 | InitializeComponent();
|
---|
40 | Content = new DatastreamAnalysisOptimizer();
|
---|
41 | }
|
---|
42 |
|
---|
43 | public new DatastreamAnalysisOptimizer Content {
|
---|
44 | get { return (DatastreamAnalysisOptimizer) base.Content; }
|
---|
45 | set { base.Content = value; }
|
---|
46 | }
|
---|
47 |
|
---|
48 | //protected override void Dispose(bool disposing) {
|
---|
49 | // if (disposing) {
|
---|
50 | // if (components != null) components.Dispose();
|
---|
51 | // }
|
---|
52 | // base.Dispose(disposing);
|
---|
53 | //}
|
---|
54 |
|
---|
55 | protected override void OnInitialized(EventArgs e) {
|
---|
56 | // set order of tab pages according to z order.
|
---|
57 | // NOTE: this is required due to a bug in the VS designer.
|
---|
58 | List<Control> tabPages = new List<Control>();
|
---|
59 | for (int i = 0; i < tabControl.Controls.Count; i++) {
|
---|
60 | tabPages.Add(tabControl.Controls[i]);
|
---|
61 | }
|
---|
62 | tabControl.Controls.Clear();
|
---|
63 | foreach(Control control in tabPages)
|
---|
64 | tabControl.Controls.Add(control);
|
---|
65 |
|
---|
66 | base.OnInitialized(e);
|
---|
67 | }
|
---|
68 |
|
---|
69 | protected override void OnContentChanged() {
|
---|
70 | base.OnContentChanged();
|
---|
71 | if (Content == null) {
|
---|
72 | ensemblesViewHost.Content = null;
|
---|
73 | datastreamViewHost.Content = null;
|
---|
74 | resultsView.Content = null;
|
---|
75 | runsView.Content = null;
|
---|
76 | } else {
|
---|
77 | ensemblesViewHost.ViewType = null;
|
---|
78 | ensemblesViewHost.Content = Content.Ensembles;
|
---|
79 | datastreamViewHost.ViewType = null;
|
---|
80 | datastreamViewHost.Content = Content.Datastream;
|
---|
81 | resultsView.Content = Content.Results.AsReadOnly();
|
---|
82 | runsView.Content = Content.Runs;
|
---|
83 | }
|
---|
84 | }
|
---|
85 |
|
---|
86 | protected override void SetEnabledStateOfControls() {
|
---|
87 | base.SetEnabledStateOfControls();
|
---|
88 |
|
---|
89 | resultsView.Enabled = Content != null;
|
---|
90 | runsView.Enabled = Content != null;
|
---|
91 | }
|
---|
92 |
|
---|
93 | protected override void OnClosed(FormClosedEventArgs e) {
|
---|
94 | if ((Content != null) && (Content.ExecutionState == ExecutionState.Started)) {
|
---|
95 | //The content must be stopped if no other view showing the content is available
|
---|
96 | var optimizers =
|
---|
97 | MainFormManager.MainForm.Views.OfType<IContentView>()
|
---|
98 | .Where(v => v != this)
|
---|
99 | .Select(v => v.Content)
|
---|
100 | .OfType<IOptimizer>();
|
---|
101 | if (!optimizers.Contains(Content)) {
|
---|
102 | var nestedOptimizers = optimizers.SelectMany(opt => opt.NestedOptimizers);
|
---|
103 | if (!nestedOptimizers.Contains(Content)) Content.Stop();
|
---|
104 | }
|
---|
105 | }
|
---|
106 | base.OnClosed(e);
|
---|
107 | }
|
---|
108 |
|
---|
109 | protected override void RegisterContentEvents() {
|
---|
110 | base.RegisterContentEvents();
|
---|
111 |
|
---|
112 | Content.EnsemblesChanged += new EventHandler(Content_EnsemblesChanged);
|
---|
113 | Content.DatastreamChanged += new EventHandler(Content_DatastreamChanged);
|
---|
114 | }
|
---|
115 |
|
---|
116 | protected override void DeregisterContentEvents() {
|
---|
117 | Content.EnsemblesChanged -= new EventHandler(Content_EnsemblesChanged);
|
---|
118 | Content.DatastreamChanged -= new EventHandler(Content_DatastreamChanged);
|
---|
119 |
|
---|
120 | base.DeregisterContentEvents();
|
---|
121 | }
|
---|
122 |
|
---|
123 | #region content events
|
---|
124 | protected override void Content_Prepared(object sender, EventArgs e) {
|
---|
125 | if (InvokeRequired)
|
---|
126 | Invoke(new EventHandler(Content_Prepared), sender, e);
|
---|
127 | else {
|
---|
128 | base.Content_Prepared(sender,e);
|
---|
129 | resultsView.Content = Content.Results.AsReadOnly();
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | protected void Content_EnsemblesChanged(object sender, EventArgs e) {
|
---|
134 | if (InvokeRequired)
|
---|
135 | Invoke(new EventHandler(Content_EnsemblesChanged), sender, e);
|
---|
136 | else {
|
---|
137 | ensemblesViewHost.ViewType = null;
|
---|
138 | ensemblesViewHost.Content = Content.Ensembles;
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 | protected void Content_DatastreamChanged(object sender, EventArgs e) {
|
---|
143 | if (InvokeRequired)
|
---|
144 | Invoke(new EventHandler(Content_DatastreamChanged), sender, e);
|
---|
145 | else {
|
---|
146 | if (datastreamViewHost.Content != null && Content.Datastream != null &&
|
---|
147 | datastreamViewHost.Content.GetType() != Content.Datastream.GetType())
|
---|
148 | datastreamViewHost.ViewType = null;
|
---|
149 | datastreamViewHost.Content = Content.Datastream;
|
---|
150 | }
|
---|
151 | }
|
---|
152 | #endregion
|
---|
153 |
|
---|
154 | #region event handlers
|
---|
155 | private void ensemblesTab_DragDrop(object sender, DragEventArgs e) {
|
---|
156 | if (e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) {
|
---|
157 | try {
|
---|
158 | var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
159 | if (data is IRatedEnsembleModel) {
|
---|
160 | data = (IRatedEnsembleModel) data;
|
---|
161 | Content.Ensembles.Add((RatedEnsembleModel) data);
|
---|
162 | }
|
---|
163 | }
|
---|
164 | catch (Exception ex) {
|
---|
165 | MessageBox.Show(ex.Message, "Set ensembles", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
166 | }
|
---|
167 | }
|
---|
168 | }
|
---|
169 |
|
---|
170 | private void ensemblesTab_DragEnterOver(object sender, DragEventArgs e) {
|
---|
171 | e.Effect = DragDropEffects.None;
|
---|
172 | if (ReadOnly || !e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat))
|
---|
173 | return;
|
---|
174 |
|
---|
175 | var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
176 |
|
---|
177 | if (data is IRatedEnsembleModel) {
|
---|
178 | if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key
|
---|
179 | else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move; // SHIFT key
|
---|
180 | else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
|
---|
181 | else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
|
---|
182 | else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
|
---|
183 | }
|
---|
184 | }
|
---|
185 |
|
---|
186 | private void datastreamTab_DragDrop(object sender, DragEventArgs e) {
|
---|
187 | if (e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) {
|
---|
188 | try {
|
---|
189 | var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
190 | if (data is IValueParameter) data = ((IValueParameter) data).Value;
|
---|
191 | if (data is IRegressionProblemData)
|
---|
192 | Content.Datastream.ProblemData = (RegressionProblemData) data;
|
---|
193 | }
|
---|
194 | catch (Exception ex) {
|
---|
195 | MessageBox.Show(ex.Message, "Set datastream", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
196 | }
|
---|
197 | }
|
---|
198 | }
|
---|
199 |
|
---|
200 | private void datastreamTab_DragEnterOver(object sender, DragEventArgs e) {
|
---|
201 | e.Effect = DragDropEffects.None;
|
---|
202 |
|
---|
203 | if (ReadOnly || !e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat))
|
---|
204 | return;
|
---|
205 |
|
---|
206 | var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
207 | if (data is IValueParameter) data = ((IValueParameter) data).Value;
|
---|
208 | if (data is IRegressionProblemData) {
|
---|
209 | if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key
|
---|
210 | else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move; // SHIFT key
|
---|
211 | else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
|
---|
212 | else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
|
---|
213 | else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 | #endregion event handlers
|
---|
218 | }
|
---|
219 | } |
---|