[17607] | 1 | #region License Information
|
---|
| 2 |
|
---|
| 3 | /* HeuristicLab
|
---|
[17896] | 4 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[17607] | 5 | *
|
---|
| 6 | * This file is part of HeuristicLab.
|
---|
| 7 | *
|
---|
| 8 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 9 | * it under the terms of the GNU General Public License as published by
|
---|
| 10 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 11 | * (at your option) any later version.
|
---|
| 12 | *
|
---|
| 13 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 16 | * GNU General Public License for more details.
|
---|
| 17 | *
|
---|
| 18 | * You should have received a copy of the GNU General Public License
|
---|
| 19 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | #endregion
|
---|
| 23 |
|
---|
| 24 | using System;
|
---|
| 25 | using System.ComponentModel;
|
---|
| 26 | using System.Windows.Forms;
|
---|
| 27 | using HeuristicLab.Core.Views;
|
---|
| 28 | using HeuristicLab.MainForm;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.DataAnalysis.Views {
|
---|
[17896] | 31 | [View("Shape Constraint View")]
|
---|
[17887] | 32 | [Content(typeof(ShapeConstraint), true)]
|
---|
[17896] | 33 | public sealed partial class ShapeConstraintView : ItemView {
|
---|
[17887] | 34 | public new ShapeConstraint Content {
|
---|
[17891] | 35 | get => (ShapeConstraint)base.Content;
|
---|
[17607] | 36 | set => base.Content = value;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
[17896] | 39 | public ShapeConstraintView() {
|
---|
[17607] | 40 | InitializeComponent();
|
---|
[17891] | 41 | int[] items = { 1, 2, 3 };
|
---|
[17896] | 42 | numberOfDerivationsComboBox.DataSource = items;
|
---|
[17607] | 43 | }
|
---|
| 44 |
|
---|
| 45 | protected override void OnContentChanged() {
|
---|
| 46 | base.OnContentChanged();
|
---|
[17907] | 47 | if (Content == null) {
|
---|
| 48 | this.regionView.Content = null;
|
---|
| 49 | } else {
|
---|
| 50 | this.regionView.Content = Content.Regions;
|
---|
| 51 | UpdateControls();
|
---|
| 52 | }
|
---|
[17607] | 53 | }
|
---|
| 54 |
|
---|
| 55 | protected override void RegisterContentEvents() {
|
---|
| 56 | base.RegisterContentEvents();
|
---|
| 57 | Content.Changed += Content_Changed;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | protected override void DeregisterContentEvents() {
|
---|
| 61 | Content.Changed -= Content_Changed;
|
---|
| 62 | base.DeregisterContentEvents();
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | protected override void SetEnabledStateOfControls() {
|
---|
| 66 | base.SetEnabledStateOfControls();
|
---|
[17937] | 67 | variableInput.Enabled = Content != null && !Locked && !ReadOnly && Content.Variable != String.Empty;
|
---|
[17896] | 68 | numberOfDerivationsComboBox.Enabled = Content != null && !Locked && !ReadOnly;
|
---|
[17891] | 69 | lowerboundInput.Enabled = Content != null && !Locked && !ReadOnly;
|
---|
| 70 | upperboundInput.Enabled = Content != null && !Locked && !ReadOnly;
|
---|
[17896] | 71 | weightTextBox.Enabled = Content != null && !Locked && !ReadOnly;
|
---|
[17607] | 72 | }
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | #region helpers
|
---|
| 76 |
|
---|
| 77 | private static double ParseDoubleValue(string input, Control control, ErrorProvider errorProvider) {
|
---|
| 78 | input = input.ToLower();
|
---|
| 79 | switch (input) {
|
---|
| 80 | case "inf.":
|
---|
| 81 | case "+inf.":
|
---|
| 82 | case "Infinity":
|
---|
| 83 | return double.PositiveInfinity;
|
---|
| 84 | case "-inf.":
|
---|
| 85 | case "-Infinity":
|
---|
| 86 | return double.NegativeInfinity;
|
---|
| 87 | default: {
|
---|
[17891] | 88 | if (double.TryParse(input, out var value)) {
|
---|
| 89 | return value;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | errorProvider.SetError(control, "Invalid input: value must be a double.");
|
---|
| 93 | return double.NaN;
|
---|
[17607] | 94 | }
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | private void UpdateControls() {
|
---|
| 99 | if (Content == null) {
|
---|
| 100 | lowerboundInput.Text = string.Empty;
|
---|
| 101 | upperboundInput.Text = string.Empty;
|
---|
[17896] | 102 | weightTextBox.Text = string.Empty;
|
---|
[17607] | 103 | return;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | lowerboundInput.Text = Content.Interval.LowerBound.ToString();
|
---|
| 107 | upperboundInput.Text = Content.Interval.UpperBound.ToString();
|
---|
[17896] | 108 | weightTextBox.Text = Content.Weight.ToString();
|
---|
[17607] | 109 |
|
---|
| 110 | variableInput.Text = Content.Variable;
|
---|
| 111 | if (!Content.IsDerivative) {
|
---|
[17896] | 112 | numberOfDerivationsComboBox.Enabled = false;
|
---|
| 113 | numberOfDerivationsComboBox.SelectedItem = null;
|
---|
[17891] | 114 | } else {
|
---|
[17896] | 115 | numberOfDerivationsComboBox.Enabled = true;
|
---|
| 116 | numberOfDerivationsComboBox.SelectedItem = Content.NumberOfDerivations;
|
---|
[17607] | 117 | }
|
---|
[17893] | 118 |
|
---|
[17937] | 119 | if (Content.Regions.Count > 0) {
|
---|
| 120 | regionView.Content = Content.Regions;
|
---|
| 121 | regionLabel.Visible = true;
|
---|
| 122 | regionView.Visible = true;
|
---|
| 123 | } else {
|
---|
| 124 | regionLabel.Visible = false;
|
---|
| 125 | regionView.Visible = false;
|
---|
| 126 | }
|
---|
[17607] | 127 | }
|
---|
| 128 |
|
---|
| 129 | #endregion
|
---|
| 130 |
|
---|
| 131 | #region control event handlers
|
---|
| 132 |
|
---|
| 133 | private void lowerboundInput_Validating(object sender, CancelEventArgs e) {
|
---|
| 134 | var value = ParseDoubleValue(lowerboundInput.Text, lowerboundInput, errorProvider);
|
---|
| 135 | if (double.IsNaN(value)) {
|
---|
[17891] | 136 | errorProvider.SetError(lowerboundInput, "Invalid input: lower bound must be a double value.");
|
---|
[17607] | 137 | e.Cancel = true;
|
---|
| 138 | return;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | if (value > Content.Interval.UpperBound) {
|
---|
[17891] | 142 | errorProvider.SetError(lowerboundInput, "Invalid input: lower bound must be smaller than upper bound.");
|
---|
[17607] | 143 | e.Cancel = true;
|
---|
| 144 | return;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | errorProvider.SetError(lowerboundInput, string.Empty);
|
---|
| 148 | e.Cancel = false;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | private void lowerboundInput_Validated(object sender, EventArgs e) {
|
---|
| 152 | var value =
|
---|
| 153 | ParseDoubleValue(lowerboundInput.Text, lowerboundInput, errorProvider);
|
---|
| 154 | if (!double.IsNaN(value)) Content.Interval = new Interval(value, Content.Interval.UpperBound);
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | private void upperboundInput_Validating(object sender, CancelEventArgs e) {
|
---|
| 158 | var value = ParseDoubleValue(upperboundInput.Text, upperboundInput, errorProvider);
|
---|
| 159 | if (double.IsNaN(value)) {
|
---|
[17891] | 160 | errorProvider.SetError(upperboundInput, "Invalid Input: upper bound must be a double value.");
|
---|
[17607] | 161 | e.Cancel = true;
|
---|
| 162 | return;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | if (value < Content.Interval.LowerBound) {
|
---|
[17891] | 166 | errorProvider.SetError(upperboundInput, "Invalid input: upper bound must be bigger than lower bound.");
|
---|
[17607] | 167 | e.Cancel = true;
|
---|
| 168 | return;
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | errorProvider.SetError(upperboundInput, string.Empty);
|
---|
| 172 | e.Cancel = false;
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | private void upperboundInput_Validated(object sender, EventArgs e) {
|
---|
| 176 | var value =
|
---|
| 177 | ParseDoubleValue(upperboundInput.Text, upperboundInput, errorProvider);
|
---|
| 178 | if (!double.IsNaN(value)) Content.Interval = new Interval(Content.Interval.LowerBound, value);
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | private void numberderivationInput_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
[17896] | 182 | if (numberOfDerivationsComboBox.SelectedItem == null) {
|
---|
[17891] | 183 | Content.NumberOfDerivations = 0;
|
---|
[17896] | 184 | numberOfDerivationsComboBox.Enabled = false;
|
---|
[17607] | 185 | return;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
[17907] | 188 | if (Content != null) {
|
---|
| 189 | if ((int)numberOfDerivationsComboBox.SelectedItem == 1)
|
---|
| 190 | Content.NumberOfDerivations = 1;
|
---|
| 191 | else if ((int)numberOfDerivationsComboBox.SelectedItem == 2)
|
---|
| 192 | Content.NumberOfDerivations = 2;
|
---|
| 193 | else if ((int)numberOfDerivationsComboBox.SelectedItem == 3)
|
---|
| 194 | Content.NumberOfDerivations = 3;
|
---|
| 195 | }
|
---|
[17607] | 196 | }
|
---|
| 197 |
|
---|
[17893] | 198 | private void weightInput_TextChanged(object sender, EventArgs e) {
|
---|
[17896] | 199 | var value = ParseDoubleValue(weightTextBox.Text, weightTextBox, errorProvider);
|
---|
[17893] | 200 | if (!double.IsNaN(value)) Content.Weight = value;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
[17937] | 203 | private void variableInput_TextChanged(object sender, EventArgs e) {
|
---|
| 204 | var value = variableInput.Text;
|
---|
| 205 | if (!String.IsNullOrEmpty(value)) Content.Variable = value;
|
---|
| 206 | }
|
---|
[17893] | 207 |
|
---|
[17607] | 208 | #endregion
|
---|
| 209 |
|
---|
| 210 | #region content event handlers
|
---|
| 211 |
|
---|
| 212 | private void Content_Changed(object sender, EventArgs e) {
|
---|
| 213 | UpdateControls();
|
---|
| 214 | }
|
---|
| 215 |
|
---|
[17937] | 216 |
|
---|
| 217 | #endregion
|
---|
[17607] | 218 | }
|
---|
| 219 | } |
---|