Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Symbols/WindowedSymbolView.cs @ 18242

Last change on this file since 18242 was 17573, checked in by pfleck, 5 years ago

#3040 Added first draft for WindowedSymbol.

File size: 7.0 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.Windows.Forms;
24using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
25using HeuristicLab.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
27
28namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
29  [View("WindowedSymbol View")]
30  [Content(typeof(WindowedSymbol), true)]
31  public partial class WindowedSymbolView : SymbolView {
32    public new WindowedSymbol Content {
33      get { return (WindowedSymbol)base.Content; }
34      set { base.Content = value; }
35    }
36
37    public WindowedSymbolView() {
38      InitializeComponent();
39    }
40
41    protected override void RegisterContentEvents() {
42      base.RegisterContentEvents();
43      Content.Changed += new EventHandler(Content_Changed);
44    }
45
46    protected override void DeregisterContentEvents() {
47      base.DeregisterContentEvents();
48      Content.Changed -= new EventHandler(Content_Changed);
49    }
50
51    protected override void OnContentChanged() {
52      base.OnContentChanged();
53      UpdateControl();
54    }
55
56    protected override void SetEnabledStateOfControls() {
57      base.SetEnabledStateOfControls();
58
59      initializationGroupBox.Enabled = Content != null && Content.EnableWindowing;
60      mutationGroupBox.Enabled = Content != null && Content.EnableWindowing;
61
62      initOffsetMuTextBox.ReadOnly = ReadOnly;
63      initOffsetSigTextBox.ReadOnly = ReadOnly;
64      initLengthMuTextBox.ReadOnly = ReadOnly;
65      initLengthSigTextBox.ReadOnly = ReadOnly;
66      mutOffsetMuTextBox.ReadOnly = ReadOnly;
67      mutOffsetSigTextBox.ReadOnly = ReadOnly;
68      mutLengthMuTextBox.ReadOnly = ReadOnly;
69      mutLengthSigTextBox.ReadOnly = ReadOnly;
70    }
71
72    #region content event handlers
73    private void Content_Changed(object sender, EventArgs e) {
74      UpdateControl();
75    }
76    #endregion
77
78    #region control event handlers
79    private void enableWindowedCheckBox_CheckedChanged(object sender, EventArgs e) {
80      if (Content == null) return;
81      Content.EnableWindowing = enableWindowedCheckBox.Checked;
82    }
83
84    private void initOffsetMuTextBox_TextChanged(object sender, EventArgs e) {
85      if (Content == null) return;
86      if (double.TryParse(initOffsetMuTextBox.Text, out double initOffsetMu)) {
87        Content.OffsetMu = initOffsetMu;
88        errorProvider.SetError(initOffsetMuTextBox, string.Empty);
89      } else {
90        errorProvider.SetError(initOffsetMuTextBox, "Invalid value");
91      }
92    }
93    private void initOffsetSigTextBox_TextChanged(object sender, EventArgs e) {
94      if (Content == null) return;
95      if (double.TryParse(initOffsetSigTextBox.Text, out double initOffsetSig)) {
96        Content.OffsetSigma = initOffsetSig;
97        errorProvider.SetError(initOffsetSigTextBox, string.Empty);
98      } else {
99        errorProvider.SetError(initOffsetSigTextBox, "Invalid value");
100      }
101    }
102    private void initLengthMuTextBox_TextChanged(object sender, EventArgs e) {
103      if (Content == null) return;
104      if (double.TryParse(initLengthMuTextBox.Text, out double initLengthMu)) {
105        Content.LengthMu = initLengthMu;
106        errorProvider.SetError(initLengthMuTextBox, string.Empty);
107      } else {
108        errorProvider.SetError(initLengthMuTextBox, "Invalid value");
109      }
110    }
111    private void initLengthSigTextBox_TextChanged(object sender, EventArgs e) {
112      if (Content == null) return;
113      if (double.TryParse(initLengthSigTextBox.Text, out double initLengthSig)) {
114        Content.LengthSigma = initLengthSig;
115        errorProvider.SetError(initLengthSigTextBox, string.Empty);
116      } else {
117        errorProvider.SetError(initLengthSigTextBox, "Invalid value");
118      }
119    }
120
121    private void mutOffsetMuTextBox_TextChanged(object sender, EventArgs e) {
122      if (Content == null) return;
123      if (double.TryParse(mutOffsetMuTextBox.Text, out double mutOffsetMu)) {
124        Content.ManipulatorOffsetMu = mutOffsetMu;
125        errorProvider.SetError(mutOffsetMuTextBox, string.Empty);
126      } else {
127        errorProvider.SetError(mutOffsetMuTextBox, "Invalid value");
128      }
129    }
130    private void mutOffsetSigTextBox_TextChanged(object sender, EventArgs e) {
131      if (Content == null) return;
132      if (double.TryParse(mutOffsetSigTextBox.Text, out double mutOffsetSig)) {
133        Content.ManipulatorOffsetSigma = mutOffsetSig;
134        errorProvider.SetError(mutOffsetSigTextBox, string.Empty);
135      } else {
136        errorProvider.SetError(mutOffsetSigTextBox, "Invalid value");
137      }
138    }
139    private void mutLengthMuTextBox_TextChanged(object sender, EventArgs e) {
140      if (Content == null) return;
141      if (double.TryParse(mutLengthMuTextBox.Text, out double mutLengthMu)) {
142        Content.ManipulatorLengthMu = mutLengthMu;
143        errorProvider.SetError(mutLengthMuTextBox, string.Empty);
144      } else {
145        errorProvider.SetError(mutLengthMuTextBox, "Invalid value");
146      }
147    }
148    private void mutLengthSigTextBox_TextChanged(object sender, EventArgs e) {
149      if (Content == null) return;
150      if (double.TryParse(mutLengthSigTextBox.Text, out double mutLengthSig)) {
151        Content.ManipulatorLengthSigma = mutLengthSig;
152        errorProvider.SetError(mutLengthSigTextBox, string.Empty);
153      } else {
154        errorProvider.SetError(mutLengthSigTextBox, "Invalid value");
155      }
156    }
157    #endregion
158
159    #region helpers
160    private void UpdateControl() {
161      enableWindowedCheckBox.Checked = Content?.EnableWindowing ?? false;
162
163      initOffsetMuTextBox.Text = Content?.OffsetMu.ToString() ?? string.Empty;
164      initOffsetSigTextBox.Text = Content?.OffsetSigma.ToString() ?? string.Empty;
165      initLengthMuTextBox.Text = Content?.LengthMu.ToString() ?? string.Empty;
166      initLengthSigTextBox.Text = Content?.LengthSigma.ToString() ?? string.Empty;
167
168      mutOffsetMuTextBox.Text = Content?.ManipulatorOffsetMu.ToString() ?? string.Empty;
169      mutOffsetSigTextBox.Text = Content?.ManipulatorOffsetSigma.ToString() ?? string.Empty;
170      mutLengthMuTextBox.Text = Content?.ManipulatorLengthMu.ToString() ?? string.Empty;
171      mutLengthSigTextBox.Text = Content?.ManipulatorLengthSigma.ToString() ?? string.Empty;
172   
173      SetEnabledStateOfControls();
174    }
175    #endregion
176  }
177}
Note: See TracBrowser for help on using the repository browser.