[14488] | 1 | #region License Information
|
---|
[14536] | 2 |
|
---|
[14488] | 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 | */
|
---|
[14536] | 21 |
|
---|
[14488] | 22 | #endregion
|
---|
| 23 |
|
---|
| 24 | using System;
|
---|
[14536] | 25 | using System.Collections.Generic;
|
---|
| 26 | using System.Linq;
|
---|
[14488] | 27 | using System.Windows.Forms;
|
---|
[14536] | 28 | using HeuristicLab.Core;
|
---|
[14488] | 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 {
|
---|
[14536] | 44 | get { return (DatastreamAnalysisOptimizer) base.Content; }
|
---|
[14488] | 45 | set { base.Content = value; }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[14536] | 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 |
|
---|
[14488] | 69 | protected override void OnContentChanged() {
|
---|
| 70 | base.OnContentChanged();
|
---|
[14536] | 71 | if (Content == null) {
|
---|
| 72 | ensemblesViewHost.Content = null;
|
---|
| 73 | datastreamViewHost.Content = null;
|
---|
| 74 | resultsView.Content = null;
|
---|
| 75 | runsView.Content = null;
|
---|
| 76 | } else {
|
---|
[14538] | 77 | ensemblesViewHost.ViewType = null;
|
---|
[14536] | 78 | ensemblesViewHost.Content = Content.Ensembles;
|
---|
[14538] | 79 | datastreamViewHost.ViewType = null;
|
---|
[14536] | 80 | datastreamViewHost.Content = Content.Datastream;
|
---|
| 81 | resultsView.Content = Content.Results.AsReadOnly();
|
---|
| 82 | runsView.Content = Content.Runs;
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
[14488] | 85 |
|
---|
[14536] | 86 | protected override void SetEnabledStateOfControls() {
|
---|
| 87 | base.SetEnabledStateOfControls();
|
---|
[14538] | 88 |
|
---|
[14536] | 89 | resultsView.Enabled = Content != null;
|
---|
| 90 | runsView.Enabled = Content != null;
|
---|
[14488] | 91 | }
|
---|
| 92 |
|
---|
[14536] | 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 |
|
---|
[14488] | 109 | protected override void RegisterContentEvents() {
|
---|
| 110 | base.RegisterContentEvents();
|
---|
| 111 |
|
---|
[14536] | 112 | Content.EnsemblesChanged += new EventHandler(Content_EnsemblesChanged);
|
---|
| 113 | Content.DatastreamChanged += new EventHandler(Content_DatastreamChanged);
|
---|
[14488] | 114 | }
|
---|
| 115 |
|
---|
| 116 | protected override void DeregisterContentEvents() {
|
---|
[14536] | 117 | Content.EnsemblesChanged -= new EventHandler(Content_EnsemblesChanged);
|
---|
| 118 | Content.DatastreamChanged -= new EventHandler(Content_DatastreamChanged);
|
---|
| 119 |
|
---|
[14488] | 120 | base.DeregisterContentEvents();
|
---|
| 121 | }
|
---|
| 122 |
|
---|
[14538] | 123 | #region content events
|
---|
[14536] | 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 {
|
---|
[14538] | 137 | ensemblesViewHost.ViewType = null;
|
---|
[14536] | 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 |
|
---|
[14488] | 154 | #region event handlers
|
---|
| 155 | private void ensemblesTab_DragDrop(object sender, DragEventArgs e) {
|
---|
| 156 | if (e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) {
|
---|
| 157 | try {
|
---|
[14536] | 158 | var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
[14710] | 159 | if (data is IRatedEnsembleModel) {
|
---|
| 160 | data = (IRatedEnsembleModel) data;
|
---|
| 161 | Content.Ensembles.Add((RatedEnsembleModel) data);
|
---|
[14536] | 162 | }
|
---|
[14488] | 163 | }
|
---|
| 164 | catch (Exception ex) {
|
---|
| 165 | MessageBox.Show(ex.Message, "Set ensembles", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 166 | }
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
| 169 |
|
---|
[14536] | 170 | private void ensemblesTab_DragEnterOver(object sender, DragEventArgs e) {
|
---|
[14488] | 171 | e.Effect = DragDropEffects.None;
|
---|
[14536] | 172 | if (ReadOnly || !e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat))
|
---|
[14488] | 173 | return;
|
---|
| 174 |
|
---|
| 175 | var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
| 176 |
|
---|
[14710] | 177 | if (data is IRatedEnsembleModel) {
|
---|
[14536] | 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 | }
|
---|
[14488] | 184 | }
|
---|
| 185 |
|
---|
| 186 | private void datastreamTab_DragDrop(object sender, DragEventArgs e) {
|
---|
| 187 | if (e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) {
|
---|
| 188 | try {
|
---|
[14536] | 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;
|
---|
[14488] | 193 | }
|
---|
| 194 | catch (Exception ex) {
|
---|
| 195 | MessageBox.Show(ex.Message, "Set datastream", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 196 | }
|
---|
| 197 | }
|
---|
| 198 | }
|
---|
| 199 |
|
---|
[14536] | 200 | private void datastreamTab_DragEnterOver(object sender, DragEventArgs e) {
|
---|
[14488] | 201 | e.Effect = DragDropEffects.None;
|
---|
[14536] | 202 |
|
---|
| 203 | if (ReadOnly || !e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat))
|
---|
[14488] | 204 | return;
|
---|
| 205 |
|
---|
| 206 | var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
[14536] | 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 | }
|
---|
[14488] | 215 | }
|
---|
| 216 |
|
---|
| 217 | #endregion event handlers
|
---|
| 218 | }
|
---|
[14536] | 219 | } |
---|