[3267] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17246] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3267] | 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 |
|
---|
[15408] | 22 | using System;
|
---|
[5419] | 23 | using System.Linq;
|
---|
[3267] | 24 | using System.Windows.Forms;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.MainForm;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Optimization.Views {
|
---|
| 29 | [View("Experiment View")]
|
---|
| 30 | [Content(typeof(Experiment), true)]
|
---|
[6425] | 31 | public sealed partial class ExperimentView : IOptimizerView {
|
---|
[3267] | 32 | public ExperimentView() {
|
---|
| 33 | InitializeComponent();
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[6425] | 36 | public new Experiment Content {
|
---|
| 37 | get { return (Experiment)base.Content; }
|
---|
| 38 | set { base.Content = value; }
|
---|
[3267] | 39 | }
|
---|
| 40 |
|
---|
| 41 | protected override void OnContentChanged() {
|
---|
| 42 | base.OnContentChanged();
|
---|
| 43 | if (Content == null) {
|
---|
[6471] | 44 | experimentTreeView.Content = null;
|
---|
[3329] | 45 | runsViewHost.Content = null;
|
---|
[15408] | 46 | workersNumericUpDown.Value = 1;
|
---|
[3267] | 47 | } else {
|
---|
[6471] | 48 | experimentTreeView.Content = Content;
|
---|
[3329] | 49 | runsViewHost.Content = Content.Runs;
|
---|
[15408] | 50 | workersNumericUpDown.Value = Content.NumberOfWorkers;
|
---|
[3267] | 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[3904] | 54 | protected override void SetEnabledStateOfControls() {
|
---|
| 55 | base.SetEnabledStateOfControls();
|
---|
[6471] | 56 | experimentTreeView.Enabled = Content != null;
|
---|
[3454] | 57 | runsViewHost.Enabled = Content != null;
|
---|
[15409] | 58 | workersNumericUpDown.Enabled = Content != null && Content.ExecutionState != ExecutionState.Started;
|
---|
[3367] | 59 | }
|
---|
| 60 |
|
---|
[3267] | 61 | protected override void OnClosed(FormClosedEventArgs e) {
|
---|
[5419] | 62 | if ((Content != null) && (Content.ExecutionState == ExecutionState.Started)) {
|
---|
| 63 | //The content must be stopped if no other view showing the content is available
|
---|
| 64 | var optimizers = MainFormManager.MainForm.Views.OfType<IContentView>().Where(v => v != this).Select(v => v.Content).OfType<IOptimizer>();
|
---|
[5420] | 65 | if (!optimizers.Contains(Content)) {
|
---|
| 66 | var nestedOptimizers = optimizers.SelectMany(opt => opt.NestedOptimizers);
|
---|
| 67 | if (!nestedOptimizers.Contains(Content)) Content.Stop();
|
---|
| 68 | }
|
---|
[5419] | 69 | }
|
---|
[3267] | 70 | base.OnClosed(e);
|
---|
| 71 | }
|
---|
[15408] | 72 |
|
---|
| 73 | protected override void Content_ExecutionStateChanged(object sender, EventArgs e) {
|
---|
| 74 | base.Content_ExecutionStateChanged(sender, e);
|
---|
| 75 | workersNumericUpDown.Enabled = Content.ExecutionState != ExecutionState.Started;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | #region Events
|
---|
| 79 | private void workersNumericUpDown_ValueChanged(object sender, System.EventArgs e) {
|
---|
[15452] | 80 | if (Content != null)
|
---|
| 81 | Content.NumberOfWorkers = (int)workersNumericUpDown.Value;
|
---|
[15408] | 82 | }
|
---|
| 83 | #endregion
|
---|
[3267] | 84 | }
|
---|
| 85 | }
|
---|