[4548] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 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 |
|
---|
[4549] | 22 | using System;
|
---|
| 23 | using System.Linq;
|
---|
[4548] | 24 | using System.Windows.Forms;
|
---|
[4549] | 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
[4548] | 27 | using HeuristicLab.Core.Views;
|
---|
| 28 | using HeuristicLab.MainForm;
|
---|
| 29 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[4549] | 30 | using HeuristicLab.PluginInfrastructure;
|
---|
[4548] | 31 |
|
---|
| 32 | namespace HeuristicLab.Clients.OKB {
|
---|
| 33 | [View("OKBItem View")]
|
---|
| 34 | [Content(typeof(OKBExperiment), true)]
|
---|
[4549] | 35 | public sealed partial class OKBExperimentView : NamedItemView {
|
---|
[4548] | 36 | public new OKBExperiment Content {
|
---|
| 37 | get { return (OKBExperiment)base.Content; }
|
---|
| 38 | set { base.Content = value; }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | public OKBExperimentView() {
|
---|
| 42 | InitializeComponent();
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[4549] | 45 | protected override void OnInitialized(System.EventArgs e) {
|
---|
| 46 | base.OnInitialized(e);
|
---|
| 47 | OKBClient.Instance.Refreshing += new EventHandler(OKBClient_Refreshing);
|
---|
| 48 | OKBClient.Instance.Refreshed += new EventHandler(OKBClient_Refreshed);
|
---|
| 49 | PopulateComboBoxes();
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[4548] | 52 | protected override void DeregisterContentEvents() {
|
---|
[4558] | 53 | Content.AlgorithmIdChanged -= new EventHandler(Content_AlgorithmIdChanged);
|
---|
| 54 | Content.ProblemIdChanged -= new EventHandler(Content_ProblemIdChanged);
|
---|
[4549] | 55 | Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
|
---|
| 56 | Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);
|
---|
| 57 | Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
|
---|
| 58 | Content.Prepared -= new EventHandler(Content_Prepared);
|
---|
| 59 | Content.Started -= new EventHandler(Content_Started);
|
---|
| 60 | Content.Paused -= new EventHandler(Content_Paused);
|
---|
| 61 | Content.Stopped -= new EventHandler(Content_Stopped);
|
---|
[4548] | 62 | base.DeregisterContentEvents();
|
---|
| 63 | }
|
---|
| 64 | protected override void RegisterContentEvents() {
|
---|
| 65 | base.RegisterContentEvents();
|
---|
[4558] | 66 | Content.AlgorithmIdChanged += new EventHandler(Content_AlgorithmIdChanged);
|
---|
| 67 | Content.ProblemIdChanged += new EventHandler(Content_ProblemIdChanged);
|
---|
[4549] | 68 | Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
|
---|
| 69 | Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
|
---|
| 70 | Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
|
---|
| 71 | Content.Prepared += new EventHandler(Content_Prepared);
|
---|
| 72 | Content.Started += new EventHandler(Content_Started);
|
---|
| 73 | Content.Paused += new EventHandler(Content_Paused);
|
---|
| 74 | Content.Stopped += new EventHandler(Content_Stopped);
|
---|
[4548] | 75 | }
|
---|
| 76 |
|
---|
[4549] | 77 | protected override void OnContentChanged() {
|
---|
| 78 | base.OnContentChanged();
|
---|
| 79 | if (Content == null) {
|
---|
[4558] | 80 | algorithmComboBox.SelectedIndex = -1;
|
---|
| 81 | problemComboBox.SelectedIndex = -1;
|
---|
| 82 | problemParametersViewHost.Content = null;
|
---|
| 83 | algorithmParametersViewHost.Content = null;
|
---|
[4549] | 84 | resultsViewHost.Content = null;
|
---|
| 85 | runsViewHost.Content = null;
|
---|
| 86 | executionTimeTextBox.Text = "-";
|
---|
| 87 | } else {
|
---|
[4558] | 88 | algorithmComboBox.SelectedItem = OKBClient.Instance.Algorithms.FirstOrDefault(x => x.Id == Content.AlgorithmId);
|
---|
| 89 | problemComboBox.SelectedItem = OKBClient.Instance.Problems.FirstOrDefault(x => x.Id == Content.ProblemId);
|
---|
| 90 | problemParametersViewHost.Content = Content.ProblemParameters;
|
---|
| 91 | algorithmParametersViewHost.Content = Content.AlgorithmParameters;
|
---|
[4549] | 92 | resultsViewHost.Content = Content.Results;
|
---|
| 93 | runsViewHost.Content = Content.Runs;
|
---|
| 94 | executionTimeTextBox.Text = Content.ExecutionTime.ToString();
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
[4548] | 97 | protected override void SetEnabledStateOfControls() {
|
---|
| 98 | base.SetEnabledStateOfControls();
|
---|
[4553] | 99 | algorithmComboBox.Enabled = (Content != null) && !ReadOnly && !Locked && (algorithmComboBox.Items.Count > 0);
|
---|
| 100 | problemComboBox.Enabled = (Content != null) && !ReadOnly && !Locked && (problemComboBox.Items.Count > 0);
|
---|
| 101 | tabControl.Enabled = Content != null;
|
---|
[4549] | 102 | executionTimeTextBox.Enabled = Content != null;
|
---|
| 103 | SetEnabledStateOfExecutableButtons();
|
---|
[4548] | 104 | }
|
---|
[4549] | 105 |
|
---|
| 106 | private void PopulateComboBoxes() {
|
---|
[4558] | 107 | algorithmComboBox.DataSource = null;
|
---|
| 108 | problemComboBox.DataSource = null;
|
---|
[4549] | 109 | Platform platform = OKBClient.Instance.Platforms.FirstOrDefault(x => x.Name == "HeuristicLab 3.3");
|
---|
| 110 | if (platform != null) {
|
---|
| 111 | algorithmComboBox.DataSource = OKBClient.Instance.Algorithms.Where(x => x.PlatformId == platform.Id).ToList();
|
---|
| 112 | algorithmComboBox.DisplayMember = "Name";
|
---|
| 113 | problemComboBox.DataSource = OKBClient.Instance.Problems.Where(x => x.PlatformId == platform.Id).ToList();
|
---|
| 114 | problemComboBox.DisplayMember = "Name";
|
---|
| 115 | }
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | protected override void OnClosed(FormClosedEventArgs e) {
|
---|
| 119 | if ((Content != null) && (Content.ExecutionState == ExecutionState.Started)) Content.Stop();
|
---|
[4943] | 120 | OKBClient.Instance.Refreshing -= new EventHandler(OKBClient_Refreshing);
|
---|
| 121 | OKBClient.Instance.Refreshed -= new EventHandler(OKBClient_Refreshed);
|
---|
[4549] | 122 | base.OnClosed(e);
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | private void OKBClient_Refreshing(object sender, EventArgs e) {
|
---|
| 126 | if (InvokeRequired) {
|
---|
| 127 | Invoke(new EventHandler(OKBClient_Refreshing), sender, e);
|
---|
| 128 | } else {
|
---|
| 129 | Cursor = Cursors.AppStarting;
|
---|
[4558] | 130 | algorithmComboBox.Enabled = problemComboBox.Enabled = tabControl.Enabled = prepareButton.Enabled = startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = executionTimeTextBox.Enabled = false;
|
---|
[4549] | 131 | }
|
---|
| 132 | }
|
---|
| 133 | private void OKBClient_Refreshed(object sender, EventArgs e) {
|
---|
| 134 | if (InvokeRequired) {
|
---|
| 135 | Invoke(new EventHandler(OKBClient_Refreshed), sender, e);
|
---|
| 136 | } else {
|
---|
| 137 | PopulateComboBoxes();
|
---|
[4558] | 138 | SetEnabledStateOfControls();
|
---|
[4549] | 139 | Cursor = Cursors.Default;
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | #region Content Events
|
---|
[4558] | 144 | private void Content_AlgorithmIdChanged(object sender, EventArgs e) {
|
---|
| 145 | if (InvokeRequired)
|
---|
| 146 | Invoke(new EventHandler(Content_AlgorithmIdChanged), sender, e);
|
---|
| 147 | else {
|
---|
| 148 | algorithmComboBox.SelectedItem = OKBClient.Instance.Algorithms.FirstOrDefault(x => x.Id == Content.AlgorithmId);
|
---|
| 149 | algorithmParametersViewHost.Content = Content.AlgorithmParameters;
|
---|
| 150 | resultsViewHost.Content = Content.Results;
|
---|
| 151 | runsViewHost.Content = Content.Runs;
|
---|
| 152 | executionTimeTextBox.Text = Content.ExecutionTime.ToString();
|
---|
| 153 | SetEnabledStateOfExecutableButtons();
|
---|
| 154 | }
|
---|
[4549] | 155 | }
|
---|
[4558] | 156 | private void Content_ProblemIdChanged(object sender, EventArgs e) {
|
---|
| 157 | if (InvokeRequired)
|
---|
| 158 | Invoke(new EventHandler(Content_ProblemIdChanged), sender, e);
|
---|
| 159 | else {
|
---|
| 160 | problemComboBox.SelectedItem = OKBClient.Instance.Problems.FirstOrDefault(x => x.Id == Content.ProblemId);
|
---|
| 161 | problemParametersViewHost.Content = Content.ProblemParameters;
|
---|
| 162 | SetEnabledStateOfExecutableButtons();
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
[4549] | 165 | private void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {
|
---|
| 166 | if (InvokeRequired)
|
---|
| 167 | Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e);
|
---|
| 168 | else
|
---|
| 169 | ErrorHandling.ShowErrorDialog(this, e.Value);
|
---|
| 170 | }
|
---|
| 171 | private void Content_ExecutionStateChanged(object sender, EventArgs e) {
|
---|
| 172 | if (InvokeRequired)
|
---|
| 173 | Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
|
---|
| 174 | else
|
---|
| 175 | startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = prepareButton.Enabled = false;
|
---|
| 176 | }
|
---|
| 177 | private void Content_ExecutionTimeChanged(object sender, EventArgs e) {
|
---|
| 178 | if (InvokeRequired)
|
---|
| 179 | Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
|
---|
| 180 | else
|
---|
| 181 | executionTimeTextBox.Text = Content == null ? "-" : Content.ExecutionTime.ToString();
|
---|
| 182 | }
|
---|
| 183 | private void Content_Prepared(object sender, EventArgs e) {
|
---|
| 184 | if (InvokeRequired)
|
---|
| 185 | Invoke(new EventHandler(Content_Prepared), sender, e);
|
---|
| 186 | else {
|
---|
[4553] | 187 | resultsViewHost.Content = Content.Results;
|
---|
[4549] | 188 | ReadOnly = Locked = false;
|
---|
| 189 | SetEnabledStateOfExecutableButtons();
|
---|
| 190 | }
|
---|
| 191 | }
|
---|
| 192 | private void Content_Started(object sender, EventArgs e) {
|
---|
| 193 | if (InvokeRequired)
|
---|
| 194 | Invoke(new EventHandler(Content_Started), sender, e);
|
---|
| 195 | else {
|
---|
| 196 | ReadOnly = Locked = true;
|
---|
| 197 | SetEnabledStateOfExecutableButtons();
|
---|
| 198 | }
|
---|
| 199 | }
|
---|
| 200 | private void Content_Paused(object sender, EventArgs e) {
|
---|
| 201 | if (InvokeRequired)
|
---|
| 202 | Invoke(new EventHandler(Content_Paused), sender, e);
|
---|
| 203 | else {
|
---|
| 204 | ReadOnly = Locked = false;
|
---|
| 205 | SetEnabledStateOfExecutableButtons();
|
---|
| 206 | }
|
---|
| 207 | }
|
---|
| 208 | private void Content_Stopped(object sender, EventArgs e) {
|
---|
| 209 | if (InvokeRequired)
|
---|
| 210 | Invoke(new EventHandler(Content_Stopped), sender, e);
|
---|
| 211 | else {
|
---|
| 212 | ReadOnly = Locked = false;
|
---|
| 213 | SetEnabledStateOfExecutableButtons();
|
---|
| 214 | }
|
---|
| 215 | }
|
---|
| 216 | #endregion
|
---|
| 217 |
|
---|
| 218 | #region Control Events
|
---|
| 219 | private void refreshButton_Click(object sender, System.EventArgs e) {
|
---|
| 220 | OKBClient.Instance.Refresh();
|
---|
| 221 | }
|
---|
| 222 | private void algorithmComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
|
---|
| 223 | Algorithm algorithm = algorithmComboBox.SelectedValue as Algorithm;
|
---|
[4553] | 224 | if (Content != null) Content.Load(algorithm);
|
---|
[4549] | 225 | }
|
---|
| 226 | private void problemComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
|
---|
| 227 | Problem problem = problemComboBox.SelectedValue as Problem;
|
---|
[4553] | 228 | if (Content != null) Content.Load(problem);
|
---|
[4549] | 229 | }
|
---|
| 230 | private void prepareButton_Click(object sender, EventArgs e) {
|
---|
| 231 | Content.Prepare(false);
|
---|
| 232 | }
|
---|
| 233 | private void startButton_Click(object sender, EventArgs e) {
|
---|
| 234 | Content.Start();
|
---|
| 235 | }
|
---|
| 236 | private void pauseButton_Click(object sender, EventArgs e) {
|
---|
| 237 | Content.Pause();
|
---|
| 238 | }
|
---|
| 239 | private void stopButton_Click(object sender, EventArgs e) {
|
---|
| 240 | Content.Stop();
|
---|
| 241 | }
|
---|
| 242 | #endregion
|
---|
| 243 |
|
---|
| 244 | #region Helpers
|
---|
| 245 | private void SetEnabledStateOfExecutableButtons() {
|
---|
[4558] | 246 | if ((Content == null) || (Content.AlgorithmId == 0) || (Content.ProblemId == 0)) {
|
---|
[4549] | 247 | startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = prepareButton.Enabled = false;
|
---|
| 248 | } else {
|
---|
| 249 | startButton.Enabled = (Content.ExecutionState == ExecutionState.Prepared) || (Content.ExecutionState == ExecutionState.Paused);
|
---|
| 250 | pauseButton.Enabled = Content.ExecutionState == ExecutionState.Started;
|
---|
| 251 | stopButton.Enabled = (Content.ExecutionState == ExecutionState.Started) || (Content.ExecutionState == ExecutionState.Paused);
|
---|
| 252 | prepareButton.Enabled = Content.ExecutionState != ExecutionState.Started;
|
---|
| 253 | }
|
---|
| 254 | }
|
---|
| 255 | #endregion
|
---|
[4548] | 256 | }
|
---|
| 257 | }
|
---|