[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;
|
---|
[6233] | 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);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | private void DeregisterVariableNamesViewContentEvents() {
|
---|
| 63 | variableNamesView.Content.ItemsAdded -= new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
|
---|
| 64 | variableNamesView.Content.ItemsRemoved -= new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
|
---|
| 65 | variableNamesView.Content.CheckedItemsChanged -= new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
|
---|
| 66 | variableNamesView.Content.CollectionReset -= new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 |
|
---|
[3824] | 70 | protected override void RegisterContentEvents() {
|
---|
| 71 | base.RegisterContentEvents();
|
---|
| 72 | Content.Changed += new EventHandler(Content_Changed);
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | protected override void DeregisterContentEvents() {
|
---|
| 76 | base.DeregisterContentEvents();
|
---|
| 77 | Content.Changed -= new EventHandler(Content_Changed);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | protected override void OnContentChanged() {
|
---|
| 81 | base.OnContentChanged();
|
---|
[6233] | 82 | variableNamesView.Content.Clear();
|
---|
[3824] | 83 | UpdateControl();
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[3904] | 86 | protected override void SetEnabledStateOfControls() {
|
---|
| 87 | base.SetEnabledStateOfControls();
|
---|
[5326] | 88 | weightInitializationMuTextBox.Enabled = Content != null;
|
---|
| 89 | weightInitializationMuTextBox.ReadOnly = ReadOnly;
|
---|
| 90 | weightInitializationSigmaTextBox.Enabled = Content != null;
|
---|
| 91 | weightInitializationSigmaTextBox.ReadOnly = ReadOnly;
|
---|
| 92 | additiveWeightChangeSigmaTextBox.Enabled = Content != null;
|
---|
| 93 | additiveWeightChangeSigmaTextBox.ReadOnly = ReadOnly;
|
---|
| 94 | multiplicativeWeightChangeSigmaTextBox.Enabled = Content != null;
|
---|
| 95 | multiplicativeWeightChangeSigmaTextBox.ReadOnly = ReadOnly;
|
---|
[3824] | 96 | }
|
---|
| 97 |
|
---|
| 98 | #region content event handlers
|
---|
| 99 | private void Content_Changed(object sender, EventArgs e) {
|
---|
| 100 | UpdateControl();
|
---|
| 101 | }
|
---|
| 102 | #endregion
|
---|
| 103 |
|
---|
| 104 | #region control event handlers
|
---|
[5750] | 105 | private void variableNames_Changed(object sender, CollectionItemsChangedEventArgs<StringValue> args) {
|
---|
| 106 | if (Content != null) {
|
---|
[6236] | 107 | Content.Changed -= new EventHandler(Content_Changed);
|
---|
[5750] | 108 | Content.VariableNames = variableNamesView.Content.CheckedItems.Select(x => x.Value).ToList();
|
---|
[6236] | 109 | Content.Changed += new EventHandler(Content_Changed);
|
---|
[5750] | 110 | }
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[4990] | 113 | private void weightMuTextBox_TextChanged(object sender, EventArgs e) {
|
---|
[3824] | 114 | double nu;
|
---|
[5326] | 115 | if (double.TryParse(weightInitializationMuTextBox.Text, out nu)) {
|
---|
[4989] | 116 | Content.WeightMu = nu;
|
---|
[5326] | 117 | errorProvider.SetError(weightInitializationMuTextBox, string.Empty);
|
---|
[3824] | 118 | } else {
|
---|
[5326] | 119 | errorProvider.SetError(weightInitializationMuTextBox, "Invalid value");
|
---|
[3824] | 120 | }
|
---|
| 121 | }
|
---|
| 122 | private void weightSigmaTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 123 | double sigma;
|
---|
[5326] | 124 | if (double.TryParse(weightInitializationSigmaTextBox.Text, out sigma) && sigma >= 0.0) {
|
---|
[3824] | 125 | Content.WeightSigma = sigma;
|
---|
[5326] | 126 | errorProvider.SetError(weightInitializationSigmaTextBox, string.Empty);
|
---|
[3824] | 127 | } else {
|
---|
[5326] | 128 | errorProvider.SetError(weightInitializationSigmaTextBox, "Invalid value");
|
---|
[3824] | 129 | }
|
---|
| 130 | }
|
---|
| 131 |
|
---|
[5326] | 132 | private void additiveWeightChangeSigmaTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 133 | double sigma;
|
---|
| 134 | if (double.TryParse(additiveWeightChangeSigmaTextBox.Text, out sigma) && sigma >= 0.0) {
|
---|
| 135 | Content.WeightManipulatorSigma = sigma;
|
---|
| 136 | errorProvider.SetError(additiveWeightChangeSigmaTextBox, string.Empty);
|
---|
[3824] | 137 | } else {
|
---|
[5326] | 138 | errorProvider.SetError(additiveWeightChangeSigmaTextBox, "Invalid value");
|
---|
[3824] | 139 | }
|
---|
| 140 | }
|
---|
[5326] | 141 | private void multiplicativeWeightChangeSigmaTextBox_TextChanged(object sender, EventArgs e) {
|
---|
[3824] | 142 | double sigma;
|
---|
[5326] | 143 | if (double.TryParse(multiplicativeWeightChangeSigmaTextBox.Text, out sigma) && sigma >= 0.0) {
|
---|
| 144 | Content.MultiplicativeWeightManipulatorSigma = sigma;
|
---|
| 145 | errorProvider.SetError(multiplicativeWeightChangeSigmaTextBox, string.Empty);
|
---|
[3824] | 146 | } else {
|
---|
[5326] | 147 | errorProvider.SetError(multiplicativeWeightChangeSigmaTextBox, "Invalid value");
|
---|
[3824] | 148 | }
|
---|
| 149 | }
|
---|
| 150 | #endregion
|
---|
| 151 |
|
---|
| 152 | #region helpers
|
---|
| 153 | private void UpdateControl() {
|
---|
| 154 | if (Content == null) {
|
---|
[5326] | 155 | weightInitializationMuTextBox.Text = string.Empty;
|
---|
| 156 | weightInitializationSigmaTextBox.Text = string.Empty;
|
---|
| 157 | additiveWeightChangeSigmaTextBox.Text = string.Empty;
|
---|
| 158 | multiplicativeWeightChangeSigmaTextBox.Text = string.Empty;
|
---|
[5750] | 159 | // temporarily deregister to prevent circular calling of events
|
---|
| 160 | DeregisterVariableNamesViewContentEvents();
|
---|
| 161 | variableNamesView.Content.Clear();
|
---|
| 162 | RegisterVariableNamesViewContentEvents();
|
---|
[3824] | 163 | } else {
|
---|
[6235] | 164 | var existingEntries = variableNamesView.Content.ToList();
|
---|
[6233] | 165 |
|
---|
[5750] | 166 | // temporarily deregister to prevent circular calling of events
|
---|
| 167 | DeregisterVariableNamesViewContentEvents();
|
---|
| 168 | // add additional entries
|
---|
[6235] | 169 | foreach (var variableName in Content.VariableNames.Except(existingEntries.Select(x => x.Value)))
|
---|
[5750] | 170 | variableNamesView.Content.Add(new StringValue(variableName), true);
|
---|
[6235] | 171 | foreach (var oldEntry in existingEntries.Where(x => !Content.VariableNames.Contains(x.Value)))
|
---|
| 172 | variableNamesView.Content.Remove(oldEntry);
|
---|
[5750] | 173 | RegisterVariableNamesViewContentEvents();
|
---|
| 174 |
|
---|
[5326] | 175 | weightInitializationMuTextBox.Text = Content.WeightMu.ToString();
|
---|
| 176 | weightInitializationSigmaTextBox.Text = Content.WeightSigma.ToString();
|
---|
| 177 | additiveWeightChangeSigmaTextBox.Text = Content.WeightManipulatorSigma.ToString();
|
---|
| 178 | multiplicativeWeightChangeSigmaTextBox.Text = Content.MultiplicativeWeightManipulatorSigma.ToString();
|
---|
[3824] | 179 | }
|
---|
| 180 | SetEnabledStateOfControls();
|
---|
| 181 | }
|
---|
| 182 | #endregion
|
---|
| 183 | }
|
---|
| 184 | }
|
---|