Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Optimization.Views/3.3/ExperimentView.cs @ 17550

Last change on this file since 17550 was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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 System;
23using System.Linq;
24using System.Windows.Forms;
25using HeuristicLab.Core;
26using HeuristicLab.MainForm;
27
28namespace HeuristicLab.Optimization.Views {
29  [View("Experiment View")]
30  [Content(typeof(Experiment), true)]
31  public sealed partial class ExperimentView : IOptimizerView {
32    public ExperimentView() {
33      InitializeComponent();
34    }
35
36    public new Experiment Content {
37      get { return (Experiment)base.Content; }
38      set { base.Content = value; }
39    }
40
41    protected override void OnContentChanged() {
42      base.OnContentChanged();
43      if (Content == null) {
44        experimentTreeView.Content = null;
45        runsViewHost.Content = null;
46        workersNumericUpDown.Value = 1;
47      } else {
48        experimentTreeView.Content = Content;
49        runsViewHost.Content = Content.Runs;
50        workersNumericUpDown.Value = Content.NumberOfWorkers;
51      }
52    }
53
54    protected override void SetEnabledStateOfControls() {
55      base.SetEnabledStateOfControls();
56      experimentTreeView.Enabled = Content != null;
57      runsViewHost.Enabled = Content != null;
58      workersNumericUpDown.Enabled = Content != null && Content.ExecutionState != ExecutionState.Started;
59    }
60
61    protected override void OnClosed(FormClosedEventArgs e) {
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>();
65        if (!optimizers.Contains(Content)) {
66          var nestedOptimizers = optimizers.SelectMany(opt => opt.NestedOptimizers);
67          if (!nestedOptimizers.Contains(Content)) Content.Stop();
68        }
69      }
70      base.OnClosed(e);
71    }
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) {
80      if (Content != null)
81        Content.NumberOfWorkers = (int)workersNumericUpDown.Value;
82    }
83    #endregion
84  }
85}
Note: See TracBrowser for help on using the repository browser.