[17607] | 1 | #region License Information
|
---|
| 2 |
|
---|
| 3 | /* HeuristicLab
|
---|
| 4 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 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 {
|
---|
| 31 | [View("Interval Constraint Detail View")]
|
---|
[17887] | 32 | [Content(typeof(ShapeConstraint), true)]
|
---|
[17607] | 33 | public sealed partial class IntervalConstraintView : ItemView {
|
---|
[17887] | 34 | public new ShapeConstraint Content {
|
---|
[17891] | 35 | get => (ShapeConstraint)base.Content;
|
---|
[17607] | 36 | set => base.Content = value;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | public IntervalConstraintView() {
|
---|
| 40 | InitializeComponent();
|
---|
[17891] | 41 | int[] items = { 1, 2, 3 };
|
---|
[17607] | 42 | numberderivationInput.DataSource = items;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | protected override void OnContentChanged() {
|
---|
| 46 | base.OnContentChanged();
|
---|
[17893] | 47 | this.regionView.Content = Content.Regions;
|
---|
[17607] | 48 | UpdateControls();
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | protected override void RegisterContentEvents() {
|
---|
| 52 | base.RegisterContentEvents();
|
---|
| 53 | Content.Changed += Content_Changed;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | protected override void DeregisterContentEvents() {
|
---|
| 57 | Content.Changed -= Content_Changed;
|
---|
| 58 | base.DeregisterContentEvents();
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | protected override void SetEnabledStateOfControls() {
|
---|
| 62 | base.SetEnabledStateOfControls();
|
---|
[17891] | 63 | variableInput.Enabled = Content != null && !Locked && !ReadOnly;
|
---|
[17607] | 64 | numberderivationInput.Enabled = Content != null && !Locked && !ReadOnly;
|
---|
[17891] | 65 | lowerboundInput.Enabled = Content != null && !Locked && !ReadOnly;
|
---|
| 66 | upperboundInput.Enabled = Content != null && !Locked && !ReadOnly;
|
---|
[17893] | 67 | weightInput.Enabled = Content != null && !Locked && !ReadOnly;
|
---|
[17607] | 68 | }
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 | #region helpers
|
---|
| 72 |
|
---|
| 73 | private static double ParseDoubleValue(string input, Control control, ErrorProvider errorProvider) {
|
---|
| 74 | input = input.ToLower();
|
---|
| 75 | switch (input) {
|
---|
| 76 | case "inf.":
|
---|
| 77 | case "+inf.":
|
---|
| 78 | case "Infinity":
|
---|
| 79 | return double.PositiveInfinity;
|
---|
| 80 | case "-inf.":
|
---|
| 81 | case "-Infinity":
|
---|
| 82 | return double.NegativeInfinity;
|
---|
| 83 | default: {
|
---|
[17891] | 84 | if (double.TryParse(input, out var value)) {
|
---|
| 85 | return value;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | errorProvider.SetError(control, "Invalid input: value must be a double.");
|
---|
| 89 | return double.NaN;
|
---|
[17607] | 90 | }
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | private void UpdateControls() {
|
---|
| 95 | if (Content == null) {
|
---|
| 96 | lowerboundInput.Text = string.Empty;
|
---|
| 97 | upperboundInput.Text = string.Empty;
|
---|
[17893] | 98 | weightInput.Text = string.Empty;
|
---|
[17607] | 99 | return;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | lowerboundInput.Text = Content.Interval.LowerBound.ToString();
|
---|
| 103 | upperboundInput.Text = Content.Interval.UpperBound.ToString();
|
---|
[17893] | 104 | weightInput.Text = Content.Weight.ToString();
|
---|
[17607] | 105 |
|
---|
| 106 | variableInput.Text = Content.Variable;
|
---|
| 107 | if (!Content.IsDerivative) {
|
---|
[17891] | 108 | numberderivationInput.Enabled = false;
|
---|
[17607] | 109 | numberderivationInput.SelectedItem = null;
|
---|
[17891] | 110 | numberderivationInput.Text = "0";
|
---|
| 111 | } else {
|
---|
| 112 | numberderivationLabel.Visible = true;
|
---|
| 113 | numberderivationInput.Visible = true;
|
---|
| 114 | numberderivationInput.Enabled = true;
|
---|
[17607] | 115 | numberderivationInput.SelectedItem = Content.NumberOfDerivations;
|
---|
| 116 | }
|
---|
[17893] | 117 |
|
---|
| 118 | regionView.Content = Content.Regions;
|
---|
[17607] | 119 | }
|
---|
| 120 |
|
---|
| 121 | #endregion
|
---|
| 122 |
|
---|
| 123 | #region control event handlers
|
---|
| 124 |
|
---|
| 125 | private void lowerboundInput_Validating(object sender, CancelEventArgs e) {
|
---|
| 126 | var value = ParseDoubleValue(lowerboundInput.Text, lowerboundInput, errorProvider);
|
---|
| 127 | if (double.IsNaN(value)) {
|
---|
[17891] | 128 | errorProvider.SetError(lowerboundInput, "Invalid input: lower bound must be a double value.");
|
---|
[17607] | 129 | e.Cancel = true;
|
---|
| 130 | return;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | if (value > Content.Interval.UpperBound) {
|
---|
[17891] | 134 | errorProvider.SetError(lowerboundInput, "Invalid input: lower bound must be smaller than upper bound.");
|
---|
[17607] | 135 | e.Cancel = true;
|
---|
| 136 | return;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | errorProvider.SetError(lowerboundInput, string.Empty);
|
---|
| 140 | e.Cancel = false;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | private void lowerboundInput_Validated(object sender, EventArgs e) {
|
---|
| 144 | var value =
|
---|
| 145 | ParseDoubleValue(lowerboundInput.Text, lowerboundInput, errorProvider);
|
---|
| 146 | if (!double.IsNaN(value)) Content.Interval = new Interval(value, Content.Interval.UpperBound);
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | private void upperboundInput_Validating(object sender, CancelEventArgs e) {
|
---|
| 150 | var value = ParseDoubleValue(upperboundInput.Text, upperboundInput, errorProvider);
|
---|
| 151 | if (double.IsNaN(value)) {
|
---|
[17891] | 152 | errorProvider.SetError(upperboundInput, "Invalid Input: upper bound must be a double value.");
|
---|
[17607] | 153 | e.Cancel = true;
|
---|
| 154 | return;
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | if (value < Content.Interval.LowerBound) {
|
---|
[17891] | 158 | errorProvider.SetError(upperboundInput, "Invalid input: upper bound must be bigger than lower bound.");
|
---|
[17607] | 159 | e.Cancel = true;
|
---|
| 160 | return;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | errorProvider.SetError(upperboundInput, string.Empty);
|
---|
| 164 | e.Cancel = false;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | private void upperboundInput_Validated(object sender, EventArgs e) {
|
---|
| 168 | var value =
|
---|
| 169 | ParseDoubleValue(upperboundInput.Text, upperboundInput, errorProvider);
|
---|
| 170 | if (!double.IsNaN(value)) Content.Interval = new Interval(Content.Interval.LowerBound, value);
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | private void numberderivationInput_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 174 | if (numberderivationInput.SelectedItem == null) {
|
---|
[17891] | 175 | Content.NumberOfDerivations = 0;
|
---|
[17607] | 176 | numberderivationInput.Enabled = false;
|
---|
| 177 | return;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
[17891] | 180 | if ((int)numberderivationInput.SelectedItem == 1)
|
---|
[17607] | 181 | Content.NumberOfDerivations = 1;
|
---|
[17891] | 182 | else if ((int)numberderivationInput.SelectedItem == 2)
|
---|
[17607] | 183 | Content.NumberOfDerivations = 2;
|
---|
[17891] | 184 | else if ((int)numberderivationInput.SelectedItem == 3)
|
---|
[17607] | 185 | Content.NumberOfDerivations = 3;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
[17893] | 188 | private void weightInput_TextChanged(object sender, EventArgs e) {
|
---|
| 189 | var value = ParseDoubleValue(weightInput.Text, weightInput, errorProvider);
|
---|
| 190 | if (!double.IsNaN(value)) Content.Weight = value;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 |
|
---|
[17607] | 194 | #endregion
|
---|
| 195 |
|
---|
| 196 | #region content event handlers
|
---|
| 197 |
|
---|
| 198 | private void Content_Changed(object sender, EventArgs e) {
|
---|
| 199 | UpdateControls();
|
---|
| 200 | }
|
---|
| 201 |
|
---|
[17893] | 202 | #endregion
|
---|
[17607] | 203 | }
|
---|
| 204 | } |
---|