[16772] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.ComponentModel;
|
---|
| 4 | using System.Drawing;
|
---|
| 5 | using System.Data;
|
---|
| 6 | using System.Globalization;
|
---|
| 7 | using System.Linq;
|
---|
| 8 | using System.Text;
|
---|
| 9 | using System.Threading.Tasks;
|
---|
| 10 | using System.Windows.Forms;
|
---|
| 11 | using HeuristicLab.Core.Views;
|
---|
| 12 | using HeuristicLab.MainForm;
|
---|
| 13 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 14 |
|
---|
| 15 | namespace HeuristicLab.Problems.DataAnalysis.Views {
|
---|
| 16 | [View("Interval Constraint Detail View")]
|
---|
| 17 | [Content(typeof(IntervalConstraint), true)]
|
---|
| 18 | public partial class IntervalConstraintView : ItemView {
|
---|
| 19 |
|
---|
| 20 | public new IntervalConstraint Content {
|
---|
| 21 | get { return (IntervalConstraint)base.Content; }
|
---|
| 22 | set { base.Content = value; }
|
---|
| 23 | }
|
---|
[16774] | 24 |
|
---|
[16772] | 25 | public IntervalConstraintView() {
|
---|
| 26 | InitializeComponent();
|
---|
| 27 | expressionInput.ReadOnly = true;
|
---|
| 28 | definitionInput.ReadOnly = true;
|
---|
| 29 | derivationInput.ReadOnly = true;
|
---|
[16774] | 30 | if (derivationInput.Text == "False")
|
---|
| 31 | numberderivationInput.ReadOnly = true;
|
---|
[16772] | 32 | }
|
---|
| 33 |
|
---|
| 34 | protected override void RegisterContentEvents() {
|
---|
| 35 | base.RegisterContentEvents();
|
---|
| 36 | Content.Changed += new EventHandler(Content_Changed);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | protected override void DeregisterContentEvents() {
|
---|
| 40 | base.DeregisterContentEvents();
|
---|
| 41 | Content.Changed -= new EventHandler(Content_Changed);
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | private void Content_Changed(object sender, EventArgs e) {
|
---|
| 45 | UpdateControls();
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | protected override void OnContentChanged() {
|
---|
| 49 | base.OnContentChanged();
|
---|
| 50 | UpdateControls();
|
---|
| 51 | }
|
---|
| 52 |
|
---|
[16774] | 53 |
|
---|
[16772] | 54 | protected override void SetEnabledStateOfControls() {
|
---|
| 55 | base.SetEnabledStateOfControls();
|
---|
| 56 | lowerboundInput.Enabled = Content != null && !Locked;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | private void UpdateControls() {
|
---|
| 60 | if (Content == null) {
|
---|
| 61 | expressionInput.Text = string.Empty;
|
---|
| 62 | definitionInput.Text = string.Empty;
|
---|
| 63 | lowerboundInput.Text = string.Empty;
|
---|
| 64 | upperboundInput.Text = string.Empty;
|
---|
| 65 | lowerCombo.SelectedItem = null;
|
---|
| 66 | lowerCombo.SelectedText = "--Nothing set--";
|
---|
| 67 | upperCombo.SelectedItem = null;
|
---|
| 68 | upperCombo.SelectedText = "--Nothing set--";
|
---|
| 69 | } else {
|
---|
| 70 | expressionInput.Text = Content.Expression;
|
---|
| 71 | definitionInput.Text = Content.Definition;
|
---|
| 72 | lowerboundInput.Text = Content.Interval.LowerBound.ToString(CultureInfo.InvariantCulture);
|
---|
| 73 | upperboundInput.Text = Content.Interval.UpperBound.ToString(CultureInfo.InvariantCulture);
|
---|
| 74 | lowerCombo.SelectedIndex = lowerCombo.FindString(Content.InclusiveLowerBound ? "True" : "False");
|
---|
| 75 | upperCombo.SelectedIndex = upperCombo.FindString(Content.InclusiveUpperBound ? "True" : "False");
|
---|
| 76 | derivationInput.Text = Content.IsDerivation ? "True" : "False";
|
---|
| 77 | variableInput.Text = Content.Variable;
|
---|
| 78 | numberderivationInput.Text = Content.NumberOfDerivation.ToString();
|
---|
| 79 | }
|
---|
| 80 | SetEnabledStateOfControls();
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[16774] | 83 | private void expressionInput_TextChanged(object sender, EventArgs e) {
|
---|
[16772] | 84 |
|
---|
| 85 | }
|
---|
[16774] | 86 |
|
---|
| 87 | private void variableInput_TextChanged(object sender, EventArgs e) {
|
---|
| 88 |
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | private void numberderivationInput_TextChanged(object sender, EventArgs e) {
|
---|
| 92 | if (int.TryParse(numberderivationInput.Text, out var derivation)) {
|
---|
| 93 | if (derivation >= 0) {
|
---|
| 94 | Content.NumberOfDerivation = derivation;
|
---|
| 95 | errorProvider.SetError(numberderivationInput, string.Empty);
|
---|
| 96 | } else {
|
---|
| 97 | errorProvider.SetError(numberderivationInput, "Invalid Input: Derivation must be positive!");
|
---|
| 98 | }
|
---|
| 99 | } else {
|
---|
| 100 | errorProvider.SetError(numberderivationInput, "Invalid Input: Derivation must be an integer!");
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | private void lowerboundInput_TextChanged(object sender, EventArgs e) {
|
---|
| 105 | var value = ParseDoubleValue(lowerboundInput.Text, lowerboundInput);
|
---|
| 106 | if (!double.IsNaN(value)) {
|
---|
| 107 | if (value <= Content.Interval.UpperBound) {
|
---|
| 108 | Content.Interval = new Interval(value, Content.Interval.UpperBound);
|
---|
| 109 | errorProvider.SetError(lowerboundInput, string.Empty);
|
---|
| 110 | } else {
|
---|
| 111 | errorProvider.SetError(lowerboundInput, "Invalid Input: Lowerbound must be smaller than Upperbound!");
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | private double ParseDoubleValue(string input, Control control) {
|
---|
| 117 | input = input.ToLower();
|
---|
| 118 | switch (input) {
|
---|
| 119 | case "inf.":
|
---|
| 120 | case "+inf.":
|
---|
| 121 | return double.PositiveInfinity;
|
---|
| 122 | case "-inf.":
|
---|
| 123 | return double.NegativeInfinity;
|
---|
| 124 | default: {
|
---|
| 125 | if (double.TryParse(input, out var value))
|
---|
| 126 | return value;
|
---|
| 127 | else {
|
---|
| 128 | errorProvider.SetError(control, "Invalid Input: Value must be a double!");
|
---|
| 129 | return double.NaN;
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
[16772] | 134 | }
|
---|
| 135 | }
|
---|