Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/OptimizableView.cs @ 5653

Last change on this file since 5653 was 5653, checked in by cneumuel, 12 years ago

#1215

  • evaluation operator returns operatorgraph which creates a scope and an operation for each algorithm execution (each repetition and problem)
  • split ValueConfiguration into ParameterizedValueConfiguration and RangeValueConfiguration
File size: 3.9 KB
Line 
1using System;
2using HeuristicLab.Core.Views;
3using HeuristicLab.Data;
4using HeuristicLab.MainForm;
5
6namespace HeuristicLab.Problems.MetaOptimization.Views.ValueConfigurationViews {
7  [View("IOptimizable View")]
8  [Content(typeof(IOptimizable), IsDefaultView = false)]
9  [Content(typeof(ParameterConfiguration), IsDefaultView = true)]
10  [Content(typeof(ValueConfiguration), IsDefaultView = true)]
11  public sealed partial class OptimizableView : ItemView {
12    public new IOptimizable Content {
13      get { return (IOptimizable)base.Content; }
14      set { base.Content = value; }
15    }
16
17    public OptimizableView() {
18      InitializeComponent();
19    }
20
21    protected override void DeregisterContentEvents() {
22      Content.OptimizeChanged -= new EventHandler(Content_OptimizeChanged);
23      Content.IsOptimizableChanged -= new EventHandler(Content_IsOptimizabeChanged);
24      base.DeregisterContentEvents();
25    }
26
27    protected override void RegisterContentEvents() {
28      base.RegisterContentEvents();
29      Content.IsOptimizableChanged += new EventHandler(Content_IsOptimizabeChanged);
30      Content.OptimizeChanged += new EventHandler(Content_OptimizeChanged);
31    }
32
33    #region Event Handlers (Content)
34    void Content_OptimizeChanged(object sender, EventArgs e) {
35      if (InvokeRequired) {
36        Invoke(new EventHandler(Content_OptimizeChanged), sender, e);
37      } else {
38        this.optimizeCheckBox.Checked = Content.Optimize;
39        if (Content.Optimize) {
40          this.viewHost.ViewType = null;
41
42          var pc = Content as IParameterConfiguration;
43          var vc = Content as IValueConfiguration;
44
45          if (pc != null) {
46            this.viewHost.Content = ((IParameterConfiguration)Content).ValueConfigurations;
47          } else if(vc != null) {
48            var rvc = Content as RangeValueConfiguration;
49            if (rvc != null) {
50              if (Content.ActualValue.ValueDataType == typeof(IntValue) ||
51                Content.ActualValue.ValueDataType == typeof(DoubleValue) ||
52                Content.ActualValue.ValueDataType == typeof(PercentValue)) {
53                this.viewHost.ViewsLabelVisible = true;
54                this.viewHost.Content = rvc.RangeConstraint;
55              } else if (Content.ActualValue.ValueDataType == typeof(BoolValue)) {
56                this.viewHost.Content = null; // no configuration required
57              }
58            }
59
60            var pvc = Content as ParameterizedValueConfiguration;
61            if (pvc != null) {
62              this.viewHost.ViewsLabelVisible = false;
63              this.viewHost.Content = pvc.ParameterConfigurations;
64            }
65          } else {
66            throw new NotSupportedException("Only IParameterConfiguration and IValueConfiguration types are allowed.");
67          }
68        } else {
69          this.viewHost.ViewsLabelVisible = false;
70          this.viewHost.Content = Content.ActualValue;
71        }
72      }
73      SetEnabledStateOfControls();
74    }
75    void Content_IsOptimizabeChanged(object sender, EventArgs e) {
76      if (InvokeRequired) {
77        Invoke(new EventHandler(Content_IsOptimizabeChanged), sender, e);
78      } else {
79        SetEnabledStateOfControls();
80      }
81    }
82    #endregion
83
84    protected override void OnContentChanged() {
85      base.OnContentChanged();
86      if (Content != null) {
87        Content_OptimizeChanged(this, EventArgs.Empty);
88      } else {
89        this.viewHost.Content = null;
90      }
91    }
92
93    protected override void SetEnabledStateOfControls() {
94      base.SetEnabledStateOfControls();
95      if (Content != null) {
96        this.optimizeCheckBox.Enabled = !this.ReadOnly && Content.IsOptimizable;
97      }
98    }
99
100    #region Event Handlers (child controls)
101    private void optimizeCheckBox_CheckedChanged(object sender, EventArgs e) {
102      Content.Optimize = optimizeCheckBox.Checked;
103    }
104    #endregion
105  }
106}
Note: See TracBrowser for help on using the repository browser.