[3824] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15583] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3824] | 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 |
|
---|
| 22 | using System;
|
---|
[7869] | 23 | using System.Linq;
|
---|
[3824] | 24 | using System.Windows.Forms;
|
---|
[7869] | 25 | using HeuristicLab.Collections;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Core.Views;
|
---|
| 28 | using HeuristicLab.Data;
|
---|
[4068] | 29 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
|
---|
[3824] | 30 | using HeuristicLab.MainForm;
|
---|
| 31 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 32 |
|
---|
[5693] | 33 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
|
---|
[3824] | 34 | [View("Variable View")]
|
---|
[5060] | 35 | [Content(typeof(VariableCondition), true)]
|
---|
| 36 | public partial class VariableConditionView : SymbolView {
|
---|
[8099] | 37 | private readonly CheckedItemCollectionView<StringValue> variableNamesView;
|
---|
[7869] | 38 |
|
---|
[5060] | 39 | public new VariableCondition Content {
|
---|
| 40 | get { return (VariableCondition)base.Content; }
|
---|
[3824] | 41 | set { base.Content = value; }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[5060] | 44 | public VariableConditionView() {
|
---|
[3824] | 45 | InitializeComponent();
|
---|
[7869] | 46 | variableNamesView = new CheckedItemCollectionView<StringValue>();
|
---|
| 47 | variableNamesView.Dock = DockStyle.Fill;
|
---|
| 48 | variableNamesTabPage.Controls.Add(variableNamesView);
|
---|
| 49 | variableNamesView.Content = new CheckedItemCollection<StringValue>();
|
---|
| 50 |
|
---|
| 51 | RegisterVariableNamesViewContentEvents();
|
---|
[3824] | 52 | }
|
---|
| 53 |
|
---|
[7869] | 54 | private void RegisterVariableNamesViewContentEvents() {
|
---|
[8103] | 55 | variableNamesView.Content.ItemsAdded += new CollectionItemsChangedEventHandler<StringValue>(VariableNames_Changed);
|
---|
[11346] | 56 | variableNamesView.Content.ItemsRemoved += new CollectionItemsChangedEventHandler<StringValue>(VariableNames_Removed);
|
---|
[8103] | 57 | variableNamesView.Content.CheckedItemsChanged += new CollectionItemsChangedEventHandler<StringValue>(VariableNames_Changed);
|
---|
| 58 | variableNamesView.Content.CollectionReset += new CollectionItemsChangedEventHandler<StringValue>(VariableNames_Changed);
|
---|
[7869] | 59 | foreach (var variable in variableNamesView.Content) {
|
---|
[8103] | 60 | variable.ValueChanged += new EventHandler(Variable_ValueChanged);
|
---|
[7869] | 61 | }
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | private void DeregisterVariableNamesViewContentEvents() {
|
---|
[8103] | 65 | variableNamesView.Content.ItemsAdded -= new CollectionItemsChangedEventHandler<StringValue>(VariableNames_Changed);
|
---|
[11346] | 66 | variableNamesView.Content.ItemsRemoved -= new CollectionItemsChangedEventHandler<StringValue>(VariableNames_Removed);
|
---|
[8103] | 67 | variableNamesView.Content.CheckedItemsChanged -= new CollectionItemsChangedEventHandler<StringValue>(VariableNames_Changed);
|
---|
| 68 | variableNamesView.Content.CollectionReset -= new CollectionItemsChangedEventHandler<StringValue>(VariableNames_Changed);
|
---|
[7869] | 69 | foreach (var variable in variableNamesView.Content) {
|
---|
[8103] | 70 | variable.ValueChanged -= new EventHandler(Variable_ValueChanged);
|
---|
[7869] | 71 | }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[3824] | 74 | protected override void RegisterContentEvents() {
|
---|
| 75 | base.RegisterContentEvents();
|
---|
| 76 | Content.Changed += new EventHandler(Content_Changed);
|
---|
| 77 | }
|
---|
| 78 | protected override void DeregisterContentEvents() {
|
---|
| 79 | base.DeregisterContentEvents();
|
---|
| 80 | Content.Changed -= new EventHandler(Content_Changed);
|
---|
| 81 | }
|
---|
| 82 | protected override void OnContentChanged() {
|
---|
| 83 | base.OnContentChanged();
|
---|
| 84 | UpdateControl();
|
---|
| 85 | }
|
---|
[5060] | 86 | private void Content_Changed(object sender, EventArgs e) {
|
---|
| 87 | UpdateControl();
|
---|
| 88 | }
|
---|
[3824] | 89 |
|
---|
[3904] | 90 | protected override void SetEnabledStateOfControls() {
|
---|
| 91 | base.SetEnabledStateOfControls();
|
---|
[5060] | 92 | thresholdInitializationMuTextBox.Enabled = Content != null;
|
---|
| 93 | thresholdInitializationMuTextBox.ReadOnly = ReadOnly;
|
---|
| 94 | thresholdInitializationSigmaTextBox.Enabled = Content != null;
|
---|
| 95 | thresholdInitializationSigmaTextBox.ReadOnly = ReadOnly;
|
---|
| 96 | slopeInitializationMuTextBox.Enabled = Content != null;
|
---|
| 97 | slopeInitializationMuTextBox.ReadOnly = ReadOnly;
|
---|
| 98 | slopeInitializationSigmaTextBox.Enabled = Content != null;
|
---|
| 99 | slopeInitializationSigmaTextBox.ReadOnly = ReadOnly;
|
---|
[3824] | 100 |
|
---|
[5060] | 101 | thresholdChangeMuTextBox.Enabled = Content != null;
|
---|
| 102 | thresholdChangeMuTextBox.ReadOnly = ReadOnly;
|
---|
| 103 | thresholdChangeSigmaTextBox.Enabled = Content != null;
|
---|
| 104 | thresholdChangeSigmaTextBox.ReadOnly = ReadOnly;
|
---|
| 105 | slopeChangeMuTextBox.Enabled = Content != null;
|
---|
| 106 | slopeChangeMuTextBox.ReadOnly = ReadOnly;
|
---|
| 107 | slopeChangeSigmaTextBox.Enabled = Content != null;
|
---|
| 108 | slopeChangeSigmaTextBox.ReadOnly = ReadOnly;
|
---|
[3824] | 109 | }
|
---|
| 110 |
|
---|
[5060] | 111 | private void UpdateControl() {
|
---|
| 112 | if (Content == null) {
|
---|
| 113 | thresholdInitializationMuTextBox.Text = string.Empty;
|
---|
| 114 | thresholdInitializationSigmaTextBox.Text = string.Empty;
|
---|
| 115 | slopeInitializationMuTextBox.Text = string.Empty;
|
---|
| 116 | slopeInitializationSigmaTextBox.Text = string.Empty;
|
---|
| 117 | thresholdChangeMuTextBox.Text = string.Empty;
|
---|
| 118 | thresholdChangeSigmaTextBox.Text = string.Empty;
|
---|
| 119 | slopeChangeMuTextBox.Text = string.Empty;
|
---|
| 120 | slopeChangeSigmaTextBox.Text = string.Empty;
|
---|
[7869] | 121 | // temporarily deregister to prevent circular calling of events
|
---|
| 122 | DeregisterVariableNamesViewContentEvents();
|
---|
| 123 | variableNamesView.Content.Clear();
|
---|
| 124 | RegisterVariableNamesViewContentEvents();
|
---|
[3824] | 125 | } else {
|
---|
[7869] | 126 | // temporarily deregister to prevent circular calling of events
|
---|
| 127 | DeregisterVariableNamesViewContentEvents();
|
---|
[8853] | 128 | variableNamesView.Content.Clear();
|
---|
| 129 | foreach (var variableName in Content.AllVariableNames) {
|
---|
| 130 | variableNamesView.Content.Add(new StringValue(variableName), Content.VariableNames.Contains(variableName));
|
---|
| 131 | }
|
---|
[7869] | 132 | RegisterVariableNamesViewContentEvents();
|
---|
| 133 |
|
---|
[5060] | 134 | thresholdInitializationMuTextBox.Text = Content.ThresholdInitializerMu.ToString();
|
---|
| 135 | thresholdInitializationSigmaTextBox.Text = Content.ThresholdInitializerSigma.ToString();
|
---|
| 136 | slopeInitializationMuTextBox.Text = Content.SlopeInitializerMu.ToString();
|
---|
| 137 | slopeInitializationSigmaTextBox.Text = Content.SlopeInitializerSigma.ToString();
|
---|
| 138 | thresholdChangeMuTextBox.Text = Content.ThresholdManipulatorMu.ToString();
|
---|
| 139 | thresholdChangeSigmaTextBox.Text = Content.ThresholdManipulatorSigma.ToString();
|
---|
| 140 | slopeChangeMuTextBox.Text = Content.SlopeManipulatorMu.ToString();
|
---|
| 141 | slopeChangeSigmaTextBox.Text = Content.SlopeManipulatorSigma.ToString();
|
---|
[3824] | 142 | }
|
---|
[5060] | 143 | SetEnabledStateOfControls();
|
---|
[3824] | 144 | }
|
---|
[5060] | 145 |
|
---|
| 146 | #region control events
|
---|
[8103] | 147 | private void VariableNames_Changed(object sender, CollectionItemsChangedEventArgs<StringValue> e) {
|
---|
| 148 | foreach (var newVar in e.Items)
|
---|
| 149 | newVar.ValueChanged += new EventHandler(Variable_ValueChanged);
|
---|
| 150 | foreach (var oldVar in e.OldItems)
|
---|
| 151 | oldVar.ValueChanged -= new EventHandler(Variable_ValueChanged);
|
---|
[7869] | 152 | UpdateContent();
|
---|
| 153 | }
|
---|
| 154 |
|
---|
[11346] | 155 | private void VariableNames_Removed(object sender, CollectionItemsChangedEventArgs<StringValue> e) {
|
---|
| 156 | foreach (var newVar in e.Items)
|
---|
| 157 | newVar.ValueChanged -= new EventHandler(Variable_ValueChanged);
|
---|
| 158 | UpdateContent();
|
---|
| 159 | }
|
---|
| 160 |
|
---|
[8103] | 161 | private void Variable_ValueChanged(object sender, EventArgs e) {
|
---|
[7869] | 162 | UpdateContent();
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | private void UpdateContent() {
|
---|
| 166 | if (Content != null) {
|
---|
| 167 | DeregisterContentEvents();
|
---|
| 168 | Content.VariableNames = variableNamesView.Content.CheckedItems.Select(x => x.Value).ToList();
|
---|
| 169 | RegisterContentEvents();
|
---|
| 170 | }
|
---|
| 171 | }
|
---|
| 172 |
|
---|
[8103] | 173 | private void ThresholdInitializationMuTextBox_TextChanged(object sender, EventArgs e) {
|
---|
[5060] | 174 | double value;
|
---|
| 175 | if (double.TryParse(thresholdInitializationMuTextBox.Text, out value)) {
|
---|
| 176 | Content.ThresholdInitializerMu = value;
|
---|
| 177 | errorProvider.SetError(thresholdInitializationMuTextBox, string.Empty);
|
---|
| 178 | } else errorProvider.SetError(thresholdInitializationMuTextBox, "Invalid value");
|
---|
[3824] | 179 | }
|
---|
[8103] | 180 | private void ThresholdInitializationSigmaTextBox_TextChanged(object sender, EventArgs e) {
|
---|
[5060] | 181 | double value;
|
---|
| 182 | if (double.TryParse(thresholdInitializationSigmaTextBox.Text, out value)) {
|
---|
| 183 | Content.ThresholdInitializerSigma = value;
|
---|
| 184 | errorProvider.SetError(thresholdInitializationSigmaTextBox, string.Empty);
|
---|
| 185 | } else errorProvider.SetError(thresholdInitializationSigmaTextBox, "Invalid value");
|
---|
| 186 | }
|
---|
[8103] | 187 | private void SlopeInitializationMuTextBox_TextChanged(object sender, EventArgs e) {
|
---|
[5060] | 188 | double value;
|
---|
| 189 | if (double.TryParse(slopeInitializationMuTextBox.Text, out value)) {
|
---|
| 190 | Content.SlopeInitializerMu = value;
|
---|
| 191 | errorProvider.SetError(slopeInitializationMuTextBox, string.Empty);
|
---|
| 192 | } else errorProvider.SetError(slopeInitializationMuTextBox, "Invalid value");
|
---|
| 193 | }
|
---|
[8103] | 194 | private void SlopeInitializationSigmaTextBox_TextChanged(object sender, EventArgs e) {
|
---|
[5060] | 195 | double value;
|
---|
| 196 | if (double.TryParse(slopeInitializationSigmaTextBox.Text, out value)) {
|
---|
| 197 | Content.SlopeInitializerSigma = value;
|
---|
| 198 | errorProvider.SetError(slopeInitializationSigmaTextBox, string.Empty);
|
---|
| 199 | } else errorProvider.SetError(slopeInitializationSigmaTextBox, "Invalid value");
|
---|
| 200 | }
|
---|
[3824] | 201 |
|
---|
[8103] | 202 | private void ThresholdChangeMuTextBox_TextChanged(object sender, EventArgs e) {
|
---|
[5060] | 203 | double value;
|
---|
| 204 | if (double.TryParse(thresholdChangeMuTextBox.Text, out value)) {
|
---|
| 205 | Content.ThresholdManipulatorMu = value;
|
---|
| 206 | errorProvider.SetError(thresholdChangeMuTextBox, string.Empty);
|
---|
| 207 | } else errorProvider.SetError(thresholdChangeMuTextBox, "Invalid value");
|
---|
[3824] | 208 | }
|
---|
| 209 |
|
---|
[8103] | 210 | private void ThresholdChangeSigmaTextBox_TextChanged(object sender, EventArgs e) {
|
---|
[5060] | 211 | double value;
|
---|
| 212 | if (double.TryParse(thresholdChangeSigmaTextBox.Text, out value)) {
|
---|
| 213 | Content.ThresholdManipulatorSigma = value;
|
---|
| 214 | errorProvider.SetError(thresholdChangeSigmaTextBox, string.Empty);
|
---|
| 215 | } else errorProvider.SetError(thresholdChangeSigmaTextBox, "Invalid value");
|
---|
[3824] | 216 | }
|
---|
[8103] | 217 | private void SlopeChangeMuTextBox_TextChanged(object sender, EventArgs e) {
|
---|
[5060] | 218 | double value;
|
---|
| 219 | if (double.TryParse(slopeChangeMuTextBox.Text, out value)) {
|
---|
| 220 | Content.SlopeManipulatorMu = value;
|
---|
| 221 | errorProvider.SetError(slopeChangeMuTextBox, string.Empty);
|
---|
| 222 | } else errorProvider.SetError(slopeChangeMuTextBox, "Invalid value");
|
---|
| 223 | }
|
---|
[3824] | 224 |
|
---|
[8103] | 225 | private void SlopeChangeSigmaTextBox_TextChanged(object sender, EventArgs e) {
|
---|
[5060] | 226 | double value;
|
---|
| 227 | if (double.TryParse(slopeChangeSigmaTextBox.Text, out value)) {
|
---|
| 228 | Content.SlopeManipulatorSigma = value;
|
---|
| 229 | errorProvider.SetError(slopeChangeSigmaTextBox, string.Empty);
|
---|
| 230 | } else errorProvider.SetError(slopeChangeSigmaTextBox, "Invalid value");
|
---|
[3824] | 231 | }
|
---|
| 232 | #endregion
|
---|
| 233 | }
|
---|
[5060] | 234 | } |
---|