[3824] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[5445] | 3 | * Copyright (C) 2002-2011 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;
|
---|
[5750] | 23 | using System.Linq;
|
---|
[3824] | 24 | using System.Windows.Forms;
|
---|
[6760] | 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 |
|
---|
| 34 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
|
---|
[3824] | 35 | [View("Variable View")]
|
---|
| 36 | [Content(typeof(Variable), true)]
|
---|
| 37 | public partial class VariableView : SymbolView {
|
---|
[5750] | 38 | private CheckedItemCollectionView<StringValue> variableNamesView;
|
---|
| 39 |
|
---|
[3824] | 40 | public new Variable Content {
|
---|
| 41 | get { return (Variable)base.Content; }
|
---|
| 42 | set { base.Content = value; }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | public VariableView() {
|
---|
| 46 | InitializeComponent();
|
---|
[5750] | 47 | variableNamesView = new CheckedItemCollectionView<StringValue>();
|
---|
| 48 | variableNamesView.Dock = DockStyle.Fill;
|
---|
| 49 | variableNamesTabPage.Controls.Add(variableNamesView);
|
---|
| 50 | variableNamesView.Content = new CheckedItemCollection<StringValue>();
|
---|
| 51 |
|
---|
| 52 | RegisterVariableNamesViewContentEvents();
|
---|
[3824] | 53 | }
|
---|
| 54 |
|
---|
[5750] | 55 | private void RegisterVariableNamesViewContentEvents() {
|
---|
| 56 | variableNamesView.Content.ItemsAdded += new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
|
---|
| 57 | variableNamesView.Content.ItemsRemoved += new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
|
---|
| 58 | variableNamesView.Content.CheckedItemsChanged += new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
|
---|
| 59 | variableNamesView.Content.CollectionReset += new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
|
---|
[6760] | 60 | foreach (var variable in variableNamesView.Content) {
|
---|
| 61 | variable.ValueChanged += new EventHandler(variable_ValueChanged);
|
---|
| 62 | }
|
---|
[5750] | 63 | }
|
---|
| 64 |
|
---|
[6760] | 65 |
|
---|
[5750] | 66 | private void DeregisterVariableNamesViewContentEvents() {
|
---|
| 67 | variableNamesView.Content.ItemsAdded -= new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
|
---|
| 68 | variableNamesView.Content.ItemsRemoved -= new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
|
---|
| 69 | variableNamesView.Content.CheckedItemsChanged -= new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
|
---|
| 70 | variableNamesView.Content.CollectionReset -= new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
|
---|
[6760] | 71 | foreach (var variable in variableNamesView.Content) {
|
---|
| 72 | variable.ValueChanged -= new EventHandler(variable_ValueChanged);
|
---|
| 73 | }
|
---|
[5750] | 74 | }
|
---|
| 75 |
|
---|
| 76 |
|
---|
[3824] | 77 | protected override void RegisterContentEvents() {
|
---|
| 78 | base.RegisterContentEvents();
|
---|
| 79 | Content.Changed += new EventHandler(Content_Changed);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | protected override void DeregisterContentEvents() {
|
---|
| 83 | base.DeregisterContentEvents();
|
---|
| 84 | Content.Changed -= new EventHandler(Content_Changed);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | protected override void OnContentChanged() {
|
---|
| 88 | base.OnContentChanged();
|
---|
[6760] | 89 | variableNamesView.Content.Clear();
|
---|
[3824] | 90 | UpdateControl();
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[3904] | 93 | protected override void SetEnabledStateOfControls() {
|
---|
| 94 | base.SetEnabledStateOfControls();
|
---|
[5326] | 95 | weightInitializationMuTextBox.Enabled = Content != null;
|
---|
| 96 | weightInitializationMuTextBox.ReadOnly = ReadOnly;
|
---|
| 97 | weightInitializationSigmaTextBox.Enabled = Content != null;
|
---|
| 98 | weightInitializationSigmaTextBox.ReadOnly = ReadOnly;
|
---|
| 99 | additiveWeightChangeSigmaTextBox.Enabled = Content != null;
|
---|
| 100 | additiveWeightChangeSigmaTextBox.ReadOnly = ReadOnly;
|
---|
| 101 | multiplicativeWeightChangeSigmaTextBox.Enabled = Content != null;
|
---|
| 102 | multiplicativeWeightChangeSigmaTextBox.ReadOnly = ReadOnly;
|
---|
[3824] | 103 | }
|
---|
| 104 |
|
---|
| 105 | #region content event handlers
|
---|
| 106 | private void Content_Changed(object sender, EventArgs e) {
|
---|
| 107 | UpdateControl();
|
---|
| 108 | }
|
---|
| 109 | #endregion
|
---|
| 110 |
|
---|
| 111 | #region control event handlers
|
---|
[5750] | 112 | private void variableNames_Changed(object sender, CollectionItemsChangedEventArgs<StringValue> args) {
|
---|
[6760] | 113 | if (args.Items != null)
|
---|
| 114 | foreach (var newVar in args.Items)
|
---|
| 115 | newVar.ValueChanged += new EventHandler(variable_ValueChanged);
|
---|
| 116 | if (args.OldItems != null)
|
---|
| 117 | foreach (var oldVar in args.OldItems)
|
---|
| 118 | oldVar.ValueChanged -= new EventHandler(variable_ValueChanged);
|
---|
| 119 | UpdateContent();
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | private void variable_ValueChanged(object sender, EventArgs e) {
|
---|
| 123 | UpdateContent();
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | private void UpdateContent() {
|
---|
[5750] | 127 | if (Content != null) {
|
---|
[6760] | 128 | Content.Changed -= new EventHandler(Content_Changed);
|
---|
[5750] | 129 | Content.VariableNames = variableNamesView.Content.CheckedItems.Select(x => x.Value).ToList();
|
---|
[6760] | 130 | Content.Changed += new EventHandler(Content_Changed);
|
---|
[5750] | 131 | }
|
---|
| 132 | }
|
---|
| 133 |
|
---|
[6760] | 134 |
|
---|
[4990] | 135 | private void weightMuTextBox_TextChanged(object sender, EventArgs e) {
|
---|
[3824] | 136 | double nu;
|
---|
[5326] | 137 | if (double.TryParse(weightInitializationMuTextBox.Text, out nu)) {
|
---|
[4989] | 138 | Content.WeightMu = nu;
|
---|
[5326] | 139 | errorProvider.SetError(weightInitializationMuTextBox, string.Empty);
|
---|
[3824] | 140 | } else {
|
---|
[5326] | 141 | errorProvider.SetError(weightInitializationMuTextBox, "Invalid value");
|
---|
[3824] | 142 | }
|
---|
| 143 | }
|
---|
| 144 | private void weightSigmaTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 145 | double sigma;
|
---|
[5326] | 146 | if (double.TryParse(weightInitializationSigmaTextBox.Text, out sigma) && sigma >= 0.0) {
|
---|
[3824] | 147 | Content.WeightSigma = sigma;
|
---|
[5326] | 148 | errorProvider.SetError(weightInitializationSigmaTextBox, string.Empty);
|
---|
[3824] | 149 | } else {
|
---|
[5326] | 150 | errorProvider.SetError(weightInitializationSigmaTextBox, "Invalid value");
|
---|
[3824] | 151 | }
|
---|
| 152 | }
|
---|
| 153 |
|
---|
[5326] | 154 | private void additiveWeightChangeSigmaTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 155 | double sigma;
|
---|
| 156 | if (double.TryParse(additiveWeightChangeSigmaTextBox.Text, out sigma) && sigma >= 0.0) {
|
---|
| 157 | Content.WeightManipulatorSigma = sigma;
|
---|
| 158 | errorProvider.SetError(additiveWeightChangeSigmaTextBox, string.Empty);
|
---|
[3824] | 159 | } else {
|
---|
[5326] | 160 | errorProvider.SetError(additiveWeightChangeSigmaTextBox, "Invalid value");
|
---|
[3824] | 161 | }
|
---|
| 162 | }
|
---|
[5326] | 163 | private void multiplicativeWeightChangeSigmaTextBox_TextChanged(object sender, EventArgs e) {
|
---|
[3824] | 164 | double sigma;
|
---|
[5326] | 165 | if (double.TryParse(multiplicativeWeightChangeSigmaTextBox.Text, out sigma) && sigma >= 0.0) {
|
---|
| 166 | Content.MultiplicativeWeightManipulatorSigma = sigma;
|
---|
| 167 | errorProvider.SetError(multiplicativeWeightChangeSigmaTextBox, string.Empty);
|
---|
[3824] | 168 | } else {
|
---|
[5326] | 169 | errorProvider.SetError(multiplicativeWeightChangeSigmaTextBox, "Invalid value");
|
---|
[3824] | 170 | }
|
---|
| 171 | }
|
---|
| 172 | #endregion
|
---|
| 173 |
|
---|
| 174 | #region helpers
|
---|
| 175 | private void UpdateControl() {
|
---|
| 176 | if (Content == null) {
|
---|
[5326] | 177 | weightInitializationMuTextBox.Text = string.Empty;
|
---|
| 178 | weightInitializationSigmaTextBox.Text = string.Empty;
|
---|
| 179 | additiveWeightChangeSigmaTextBox.Text = string.Empty;
|
---|
| 180 | multiplicativeWeightChangeSigmaTextBox.Text = string.Empty;
|
---|
[5750] | 181 | // temporarily deregister to prevent circular calling of events
|
---|
| 182 | DeregisterVariableNamesViewContentEvents();
|
---|
| 183 | variableNamesView.Content.Clear();
|
---|
| 184 | RegisterVariableNamesViewContentEvents();
|
---|
[3824] | 185 | } else {
|
---|
[6760] | 186 | var existingEntries = variableNamesView.Content.ToList();
|
---|
| 187 |
|
---|
[5750] | 188 | // temporarily deregister to prevent circular calling of events
|
---|
| 189 | DeregisterVariableNamesViewContentEvents();
|
---|
| 190 | // add additional entries
|
---|
[6760] | 191 | foreach (var variableName in Content.VariableNames.Except(existingEntries.Select(x => x.Value)))
|
---|
[5750] | 192 | variableNamesView.Content.Add(new StringValue(variableName), true);
|
---|
[6760] | 193 | foreach (var oldEntry in existingEntries.Where(x => !Content.VariableNames.Contains(x.Value)))
|
---|
| 194 | variableNamesView.Content.Remove(oldEntry);
|
---|
[5750] | 195 | RegisterVariableNamesViewContentEvents();
|
---|
| 196 |
|
---|
[5326] | 197 | weightInitializationMuTextBox.Text = Content.WeightMu.ToString();
|
---|
| 198 | weightInitializationSigmaTextBox.Text = Content.WeightSigma.ToString();
|
---|
| 199 | additiveWeightChangeSigmaTextBox.Text = Content.WeightManipulatorSigma.ToString();
|
---|
| 200 | multiplicativeWeightChangeSigmaTextBox.Text = Content.MultiplicativeWeightManipulatorSigma.ToString();
|
---|
[3824] | 201 | }
|
---|
| 202 | SetEnabledStateOfControls();
|
---|
| 203 | }
|
---|
| 204 | #endregion
|
---|
| 205 | }
|
---|
| 206 | }
|
---|