Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 5757 was 5665, checked in by cneumuel, 14 years ago

#1215

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