Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 7887 was 6489, checked in by cneumuel, 13 years ago

#1215

  • fixed issue with multiple problems (by introducing valuesReadOnly to IOptimizable)
  • fixed error message when removing last problem instance
  • made quality measure name configurable
File size: 4.6 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
71            //var symbolicVc = Content as SymbolicExpressionGrammarValueConfiguration;
72            //if (symbolicVc != null) {
73            //  this.viewHost.ViewsLabelVisible = false;
74            //  this.viewHost.Content = symbolicVc.ParameterConfigurations;
75            //}
76          } else {
77            throw new NotSupportedException("Only IParameterConfiguration and IValueConfiguration types are allowed.");
78          }
79        } else {
80          this.viewHost.ViewsLabelVisible = false;
81          if (Content.ValuesReadOnly) {
82            this.viewHost.Content = new MessageItem("Cannot modify value directly. Please modify the value in the list of problems.");
83          } else {
84            this.viewHost.Content = Content.ActualValue;
85          }
86        }
87      }
88      SetEnabledStateOfControls();
89    }
90    void Content_IsOptimizabeChanged(object sender, EventArgs e) {
91      if (InvokeRequired) {
92        Invoke(new EventHandler(Content_IsOptimizabeChanged), sender, e);
93      } else {
94        SetEnabledStateOfControls();
95      }
96    }
97    #endregion
98
99    protected override void OnContentChanged() {
100      base.OnContentChanged();
101      if (Content != null) {
102        Content_OptimizeChanged(this, EventArgs.Empty);
103      } else {
104        this.viewHost.Content = null;
105      }
106    }
107
108    protected override void SetEnabledStateOfControls() {
109      base.SetEnabledStateOfControls();
110      if (Content != null) {
111        this.optimizeCheckBox.Enabled = !this.ReadOnly && Content.IsOptimizable;
112      }
113    }
114
115    #region Event Handlers (child controls)
116    private void optimizeCheckBox_CheckedChanged(object sender, EventArgs e) {
117      Content.Optimize = optimizeCheckBox.Checked;
118    }
119    #endregion
120  }
121}
Note: See TracBrowser for help on using the repository browser.